:root,
html[data-theme="classic"] {
  --ink: #1c2430;
  --muted: #5d6b7a;
  --paper: #f3f0e8;
  --card: #fffdf8;
  --line: #d9d2c5;
  --accent: #0f6e56;
  --accent-dark: #0b5644;
  --danger: #8d2f2f;
  --danger-bg: #8d2f2f;
  --on-accent: #fff;
  --topbar: #1c2430;
  --topbar-ink: #f7f4ee;
  --input: #fffdf8;
  --input-ink: #1c2430;
  --pop: #fff;
  --pop-ink: #1c2430;
  --row-hover: #f4efe4;
  --shadow: 0 12px 40px rgba(28, 36, 48, 0.16);
  --bar: #e7e1d6;
  --focus: rgba(15, 110, 86, 0.15);
  --ok: #0f6e56;
  --info: #1d4e89;
  --wait: #a15c07;
  --bad: #8d2f2f;
  --idle: #5d6b7a;
  --split: #b7ad9c;
  --row-pad: 8px 6px;
  color-scheme: light;
}

html[data-theme="dark"] {
  --ink: #e7edf5;
  --muted: #9aabbd;
  --paper: #0e1624;
  --card: #162033;
  --line: #2c3b52;
  --accent: #3b82f6;
  --accent-dark: #2563eb;
  --danger: #f0a0a0;
  --danger-bg: #8d2f2f;
  --on-accent: #fff;
  --topbar: #0b1220;
  --topbar-ink: #e7edf5;
  --input: #10192a;
  --input-ink: #e7edf5;
  --pop: #1b2740;
  --pop-ink: #e7edf5;
  --row-hover: #1d2b44;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  --bar: #243044;
  --focus: rgba(59, 130, 246, 0.28);
  --ok: #4ade80;
  --info: #60a5fa;
  --wait: #fbbf24;
  --bad: #f87171;
  --idle: #94a3b8;
  --split: #5d7594;
  color-scheme: dark;
}

html[data-theme="light"] {
  --ink: #1e293b;
  --muted: #64748b;
  --paper: #f4f6f8;
  --card: #ffffff;
  --line: #e2e8f0;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --danger: #b91c1c;
  --danger-bg: #b91c1c;
  --on-accent: #fff;
  --topbar: #ffffff;
  --topbar-ink: #1e293b;
  --input: #fff;
  --input-ink: #1e293b;
  --pop: #fff;
  --pop-ink: #1e293b;
  --row-hover: #f1f5f9;
  --shadow: 0 10px 28px rgba(15, 23, 42, 0.08);
  --bar: #e2e8f0;
  --focus: rgba(37, 99, 235, 0.16);
  --ok: #15803d;
  --info: #1d4ed8;
  --wait: #c2410c;
  --bad: #b91c1c;
  --idle: #64748b;
  --split: #94a3b8;
  color-scheme: light;
}

html[data-density="compact"] { --row-pad: 4px 6px; }
html[data-density="comfortable"] { --row-pad: 12px 8px; }

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--paper);
  font: 16px/1.45 "Segoe UI", sans-serif;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  background: var(--topbar);
  color: var(--topbar-ink);
  border-bottom: 1px solid var(--line);
}

.brand {
  color: inherit;
  font-weight: 700;
  text-decoration: none;
}

.userbox {
  display: flex;
  gap: 16px;
  align-items: center;
}

.userbox form { margin: 0; }

.linkish {
  border: 0;
  background: transparent;
  color: var(--topbar-ink);
  cursor: pointer;
  font: inherit;
  text-decoration: underline;
}

.part-remove {
  border: 0;
  background: transparent;
  color: var(--bad);
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  text-decoration: underline;
}

main {
  max-width: 880px;
  margin: 0 auto;
  padding: 32px 16px;
}

body.wide main {
  max-width: none;
  padding: 16px 20px 32px;
}

body.price-page main {
  max-width: 1190px;
}

.login-card, .panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 28px;
}

.login-card { max-width: 420px; margin: 8vh auto 0; }

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

h1 { margin: 0 0 18px; font-size: 28px; }

label { display: block; margin: 14px 0 6px; font-weight: 600; }

textarea,
input[type="text"],
input[type="password"],
input[type="search"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--input);
  color: var(--input-ink);
  font: inherit;
}

.check {
  display: flex;
  gap: 8px;
  align-items: center;
  font-weight: 500;
}

.primary {
  margin-top: 18px;
  width: 100%;
  padding: 11px 14px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: var(--on-accent);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.primary:hover { background: var(--accent-dark); }

.flash, .field-error { color: var(--danger); }

.muted, .empty { color: var(--muted); }

.userbox a { color: var(--topbar-ink); text-decoration: none; }
.userbox a:hover { text-decoration: underline; }

.flash-success { color: var(--accent); }

.panel + .panel { margin-top: 16px; }

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.narrow { max-width: 520px; }

.primary.inline {
  display: inline-block;
  width: auto;
  margin: 0;
  text-decoration: none;
  text-align: center;
}

table { width: 100%; border-collapse: collapse; }

th, td {
  padding: var(--row-pad);
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

fieldset {
  margin: 16px 0;
  border: 1px solid var(--line);
  border-radius: 8px;
}

select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  background: var(--input);
  color: var(--input-ink);
}

.facts {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 8px 16px;
  margin: 0 0 20px;
}

.facts dt { color: var(--muted); }
.facts dd { margin: 0; }

.inline-form, .actions form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: end;
  margin-bottom: 12px;
}

.inline-form select { width: auto; min-width: 220px; }

.zip-search { align-items: center; }

.zip-search input[type="search"],
.zip-search .primary.inline {
  box-sizing: border-box;
  height: 34px;
  margin: 0;
  padding: 0 12px;
}

.zip-search input[type="search"] {
  width: 280px;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
}

.actions .primary.inline, .danger {
  width: auto;
  margin-top: 0;
}

.danger {
  padding: 11px 14px;
  border: 0;
  border-radius: 8px;
  background: var(--danger-bg);
  color: #fff;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.table-wrap { overflow: auto; max-height: calc(100vh - 230px); }
.table-wrap thead th,
.grid thead th,
.parts thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--card);
}
tbody tr:hover td { background: var(--row-hover); }
.grid th.pin-col,
.grid td.pin-col {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--card);
  box-shadow: 1px 0 0 var(--split);
}
.grid thead th.pin-col { z-index: 4; background: var(--bar); }
.grid tbody tr:hover td.pin-col { background: var(--row-hover); }
.pin-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  margin-left: 4px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  vertical-align: middle;
}
.pin-btn svg { width: 14px; height: 14px; transform: rotate(-40deg); }
.pin-btn .pin-head, .pin-btn .pin-needle { fill: none; stroke: currentColor; stroke-width: 1.4; }
.pin-btn .pin-needle { stroke-linecap: round; }
.pin-btn.is-on {
  color: var(--accent);
  background: var(--focus);
  border-color: var(--accent);
}
.pin-btn.is-on svg { transform: none; }
.pin-btn.is-on .pin-head { fill: currentColor; }

.filter-head { white-space: nowrap; }
.filter-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  margin-left: 6px;
  border: 1px solid var(--split);
  border-radius: 6px;
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  line-height: 1;
}
.filter-head.is-on .filter-btn { color: var(--accent); font-weight: 700; }
.filter-pop {
  position: fixed;
  z-index: 30;
  width: 320px;
  max-width: calc(100vw - 16px);
  background: var(--pop);
  color: var(--pop-ink);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 12px;
}
.filter-pop[hidden] { display: none !important; }
.filter-sorts { display: flex; gap: 12px; margin-bottom: 8px; }
.filter-sorts a, .filter-actions a { color: var(--pop-ink); }
.filter-pop input[type="text"] {
  width: 100%;
  min-width: 0;
  margin: 8px 0;
  background: var(--input);
  color: var(--input-ink);
}
.filter-pop label.filter-all,
.filter-pop label.filter-option {
  display: grid;
  grid-template-columns: 16px minmax(0, 1fr) auto;
  column-gap: 8px;
  align-items: center;
  margin: 0;
  padding: 3px 0;
  font-weight: 500;
}
.filter-pop input[type="checkbox"] {
  width: 16px;
  min-width: 16px;
  height: 16px;
  margin: 0;
  padding: 0;
  justify-self: start;
  accent-color: var(--accent);
}
.filter-option.is-out { display: none !important; }
.filter-name { min-width: 0; white-space: normal; }
.filter-list { max-height: 240px; overflow: auto; margin-top: 8px; }
.filter-count { color: var(--muted); }
.filter-actions { display: flex; justify-content: flex-end; gap: 8px; align-items: center; margin-top: 12px; }
.quiet {
  border: 0;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  font: inherit;
}

.grid th,
.grid td {
  border-right: 1px solid var(--split);
}
.grid th:last-child,
.grid td:last-child { border-right: 0; }
.grid thead th {
  background: var(--bar);
  border-bottom: 2px solid var(--split);
}
.parts,
.parts th,
.parts td,
.parts a,
.parts input {
  color: var(--ink);
}

.parts input[type="text"] {
  background: var(--input);
  border: 1px solid var(--line);
}

.parts form { margin: 0; }

.parts .part-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.grid input,
.grid select,
.grid textarea {
  width: 100%;
  min-width: 7.5rem;
  margin: 0;
  padding: 5px 8px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: inherit;
  font: inherit;
  line-height: 1.35;
}

.grid textarea { resize: vertical; min-height: 2.2rem; }

.grid input:hover,
.grid select:hover,
.grid textarea:hover {
  border-color: var(--line);
  background: var(--input);
}

.grid input:focus,
.grid select:focus,
.grid textarea:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--input);
  box-shadow: 0 0 0 3px var(--focus);
}

.grid .primary.inline {
  padding: 6px 12px;
  font-size: 14px;
}

.columns-panel {
  margin: 0 0 16px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.checks { display: flex; flex-wrap: wrap; gap: 8px 16px; margin: 10px 0; }

.empty {
  margin-top: 20px;
  padding: 24px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  text-align: center;
}

.drop {
  margin: 12px 0;
  padding: 12px;
  border: 1px dashed var(--line);
  border-radius: 10px;
}
.drop.over { border-color: var(--accent); }
.upload-bar {
  height: 8px;
  background: var(--bar);
  border-radius: 99px;
  overflow: hidden;
}
.upload-bar span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
}
.preview-text { white-space: pre-wrap; overflow: auto; }
.conflict { margin: 12px 0; }
.part-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.journal h1 { margin: 0; font-size: 22px; }
.found { margin: 2px 0 0; font-size: 13px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 12px 0; }
.toolbar .inline-form { flex: 1 1 280px; margin: 0; }
.toolbar .inline-form input[type="text"] { width: min(420px, 100%); }
.columns-panel { margin: 0 0 12px; padding: 0; border: 0; }
.columns-panel summary {
  display: inline-block;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  cursor: pointer;
}
.columns-panel[open] { padding-bottom: 8px; }
.column-row .quiet { padding: 0 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 0 0 10px; }
.chip, .quiet-btn {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border: 1px solid var(--line);
  border-radius: 99px;
  background: var(--card);
  color: var(--ink);
  text-decoration: none;
  font-size: 13px;
}
.resize-handle {
  display: inline-block;
  width: 8px;
  margin-left: 4px;
  cursor: col-resize;
  color: var(--muted);
}
.resize-handle::after { content: ""; }
.theme-choices { display: grid; gap: 8px; }
.theme-card {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin: 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.theme-card span { display: block; font-weight: 500; }
.label { margin: 14px 0 6px; font-weight: 600; }
.tone-completed, .tone-done, .tone-closed { color: var(--ok); font-weight: 700; }
.tone-in_work, .tone-manager, .tone-diagnostics, .tone-rework { color: var(--info); font-weight: 700; }
.tone-waiting_parts, .tone-awaiting_repair, .tone-awaiting_reply { color: var(--wait); font-weight: 700; }
.tone-refused, .tone-cancelled { color: var(--bad); font-weight: 700; }
.tone-diagnosed, .tone-sent { color: var(--info); font-weight: 700; }
.tone-unset, .tone-new { color: var(--idle); font-weight: 700; }
.tone-pay-paid { color: var(--ok); font-weight: 700; }
.tone-pay-waiting { color: var(--wait); font-weight: 700; }
.tone-pay-not_required, .tone-pay-empty { color: var(--idle); }
.work-cell { white-space: pre-wrap; word-break: break-word; max-width: 640px; }
.report-table .num { text-align: right; white-space: nowrap; }
@media print {
  .topbar, .report-actions { display: none; }
  body { background: #fff; }
  .panel { box-shadow: none; }
}
.history-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; align-items: start; }
.history-layout.is-collapsed { grid-template-columns: minmax(0, 1fr); }
.grid-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 8px 12px; margin: 12px 0; }
.grid-form label { margin: 0; font-size: 13px; }
.grid-form input, .grid-form select { width: 100%; }
.recent-item { margin: 0 0 10px; }
@media (max-width: 960px) {
  .history-layout { grid-template-columns: 1fr; }
}
