:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #6f6d68;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --ring: rgba(11, 11, 11, 0.10);
  --wash: rgba(11, 11, 11, 0.04);
  --accent: #2a78d6;
  --s1: #2a78d6;
  --s2: #eb6834;
  --s3: #1baf7a;
  --s4: #eda100;
  --critical: #d03b3b;
  --serious: #ec835a;
  --warning: #fab219;
  --good: #006300;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #9a9890;
    --grid: #2c2c2a;
    --axis: #383835;
    --ring: rgba(255, 255, 255, 0.10);
    --wash: rgba(255, 255, 255, 0.05);
    --accent: #3987e5;
    --s1: #3987e5;
    --s2: #d95926;
    --s3: #199e70;
    --s4: #c98500;
    --good: #0ca30c;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --ink: #f0efec;
  --ink-2: #c3c2b7;
  --muted: #9a9890;
  --grid: #2c2c2a;
  --axis: #383835;
  --ring: rgba(255, 255, 255, 0.10);
  --wash: rgba(255, 255, 255, 0.05);
  --accent: #3987e5;
  --s1: #3987e5;
  --s2: #d95926;
  --s3: #199e70;
  --s4: #c98500;
  --good: #0ca30c;
}

:root { --low: #bdbcb4; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --low: #5a5954; }
}
:root[data-theme="dark"] { --low: #5a5954; }

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}
main { max-width: 1180px; margin: 0 auto; padding: 24px 16px 48px; }
h1 { font-size: 26px; line-height: 1.2; margin: 0 0 6px; }
h2 { font-size: 17px; margin: 0 0 12px; }
p { margin: 0 0 8px; }
a { color: var(--accent); }
.lede { color: var(--ink-2); max-width: 760px; }
.note { color: var(--muted); font-size: 13px; }
.panel {
  background: var(--surface);
  border: 1px solid var(--ring);
  border-radius: 10px;
  padding: 18px;
  margin-top: 16px;
  min-width: 0;
}
.panel-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 10px; }
.panel-head h2 { margin: 0; }

/* file input */
.drop {
  display: block;
  position: relative;
  border: 1.5px dashed var(--axis);
  border-radius: 10px;
  padding: 14px 16px;
  cursor: pointer;
  background: var(--surface);
}
.drop:hover, .drop.over { border-color: var(--accent); background: var(--wash); }
.drop:focus-within { border-color: var(--accent); }
.drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.drop strong { display: block; }
.drop .file { color: var(--ink-2); font-size: 13px; overflow-wrap: anywhere; }
.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; margin-top: 12px; }
.controls label { font-size: 14px; color: var(--ink-2); }
input[type="date"], input[type="text"], input[type="search"], select, textarea {
  font: inherit;
  font-size: 14px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--ring);
  border-radius: 6px;
  padding: 4px 8px;
  max-width: 100%;
}
.btn {
  font: inherit;
  font-size: 14px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--ring);
  border-radius: 6px;
  padding: 5px 12px;
  cursor: pointer;
}
.btn:hover { background: var(--wash); }
.errors { color: var(--critical); font-size: 14px; margin-top: 8px; }

/* tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-top: 20px; }
.tile { background: var(--surface); border: 1px solid var(--ring); border-radius: 10px; padding: 14px 16px; min-width: 0; }
.tile .label { color: var(--ink-2); font-size: 13px; display: flex; align-items: center; gap: 6px; }
.tile .value { font-size: 26px; font-weight: 650; line-height: 1.25; margin-top: 2px; font-variant-numeric: tabular-nums; }
.tile .sub { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* chart */
.legend { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 13px; color: var(--ink-2); margin-bottom: 8px; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.chart-wrap { position: relative; }
.chart-wrap svg { display: block; overflow: visible; }
.bars text { font-size: 13px; fill: var(--ink-2); font-variant-numeric: tabular-nums; }
.bars text.value { fill: var(--ink); font-weight: 600; }
.bars rect.hit { fill: transparent; cursor: pointer; }
.bars g { outline: none; }
.bars g:hover .bar, .bars g:focus-visible .bar { opacity: 0.8; }
.bars g:focus-visible text.cat, .bars g.on text.cat { fill: var(--ink); font-weight: 600; }
.bars g.on rect.hit { fill: var(--wash); }
.tooltip {
  position: absolute;
  top: 0;
  pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--ring);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  padding: 8px 10px;
  font-size: 13px;
  min-width: 150px;
  z-index: 2;
}
.tooltip .when { color: var(--ink-2); margin-bottom: 4px; font-weight: 600; }
.tooltip .row { display: flex; align-items: center; gap: 8px; }
.tooltip strong { font-variant-numeric: tabular-nums; min-width: 22px; text-align: right; }
.tooltip .name { color: var(--ink-2); }

/* queue and detail */
.work { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; margin-top: 16px; }
.work > .panel { margin-top: 0; }
@media (min-width: 900px) {
  .work { grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); align-items: start; }
  .detail { position: sticky; top: 12px; }
  .queue { max-height: 640px; overflow-y: auto; }
  .queue th { position: sticky; top: 0; background: var(--surface); z-index: 1; }
}
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 6px; }
.filters input[type="search"] { flex: 1 1 160px; min-width: 0; }
.seg { display: flex; flex-wrap: wrap; gap: 4px; }
.seg button {
  font: inherit;
  font-size: 13px;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--ring);
  border-radius: 999px;
  padding: 3px 10px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.seg button:hover { background: var(--wash); }
.seg button[aria-pressed="true"] { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); font-weight: 600; }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th { color: var(--ink-2); font-weight: 600; font-size: 13px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.subject { color: var(--ink-2); white-space: normal; min-width: 200px; }
tr.pick { cursor: pointer; }
tr.pick:hover td { background: var(--wash); }
tr.pick:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
tr.selected td { background: var(--wash); }
tr.selected td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; }
.status svg { flex: none; }
.badge { display: inline-block; font-size: 11px; font-weight: 600; letter-spacing: 0.02em; text-transform: uppercase; padding: 1px 6px; border-radius: 4px; border: 1px solid var(--ring); color: var(--ink-2); margin-left: 6px; vertical-align: 1px; }

.detail h2 { margin-bottom: 4px; overflow-wrap: anywhere; }
.detail .meta { color: var(--ink-2); font-size: 13px; overflow-wrap: anywhere; }
.verdict { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; }
.verdict .topic { font-size: 13px; color: var(--ink-2); }
.chips { list-style: none; padding: 0; margin: 0 0 10px; display: flex; flex-wrap: wrap; gap: 6px; }
.chips li { font-size: 12px; color: var(--ink-2); border: 1px solid var(--ring); border-radius: 999px; padding: 1px 8px; }
blockquote { margin: 0 0 14px; padding: 10px 12px; border-left: 3px solid var(--axis); background: var(--wash); border-radius: 0 6px 6px 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.reply-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 4px 12px; margin-bottom: 6px; }
textarea { display: block; width: 100%; line-height: 1.5; padding: 8px 10px; resize: vertical; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }

details summary { cursor: pointer; color: var(--ink-2); font-size: 14px; }
.rules { margin: 10px 0 0; padding-left: 18px; color: var(--ink-2); font-size: 14px; }
.rules li { margin-bottom: 4px; }
footer { margin-top: 28px; color: var(--muted); font-size: 13px; }

@media (max-width: 899px) {
  .queue { max-height: 70vh; overflow-y: auto; }
}
@media (max-width: 600px) {
  .queue thead { display: none; }
  .queue table, .queue tbody { display: block; }
  .queue tr { display: grid; grid-template-columns: auto auto minmax(0, 1fr); gap: 2px 12px; padding: 8px 8px; border-bottom: 1px solid var(--grid); }
  .queue td { border: 0; padding: 0; white-space: normal; }
  .queue td.num { text-align: left; }
  .queue td.customer, .queue td.subject { grid-column: 1 / -1; min-width: 0; }
  .queue tr.selected { background: var(--wash); box-shadow: inset 3px 0 0 var(--accent); }
  .queue tr.selected td, .queue tr.pick:hover td { background: transparent; }
  .queue tr.selected td:first-child { box-shadow: none; }
}
@media (max-width: 560px) {
  h1 { font-size: 22px; }
  .panel { padding: 14px; }
  .tile .value { font-size: 22px; }
}

/* reply templates */
.templates summary { cursor: pointer; }
.templates details[open] > summary { margin-bottom: 8px; }
.templates code { font-size: 13px; background: var(--wash); border-radius: 4px; padding: 0 4px; }
.tpl-bar { margin: 10px 0; font-size: 14px; color: var(--ink-2); }
.tpl-grid { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 16px; align-items: start; }
.tpl-fields { display: grid; gap: 10px; }
.tpl-fields label { display: grid; gap: 3px; font-size: 13px; color: var(--ink-2); }
.tpl-fields textarea { width: 100%; resize: vertical; line-height: 1.45; }
.tpl-preview { background: var(--page); border: 1px solid var(--ring); border-radius: 8px; padding: 10px 12px; position: sticky; top: 12px; }
.tpl-preview pre { white-space: pre-wrap; overflow-wrap: anywhere; font: 14px/1.5 inherit; font-family: inherit; margin: 6px 0 0; color: var(--ink); }
.btn.primary { background: var(--ink); color: var(--page); border-color: var(--ink); }
.btn.primary:hover { opacity: 0.9; background: var(--ink); }
.file-btn { position: relative; overflow: hidden; display: inline-block; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.reply-from { margin: 4px 0 0; }
@media (max-width: 760px) {
  .tpl-grid { grid-template-columns: 1fr; }
  .tpl-preview { position: static; }
}
