/* Gorman invoice pipeline dashboard. Gorman Commercial's teal carries the chrome; data series use the validated
   categorical steps (dataviz reference palette, checked against these surfaces in both modes). */

:root {
  color-scheme: light;
  --brand: #10a89b;          /* Gorman teal: header block, accents */
  --brand-ink: #ffffff;
  --brand-deep: #0b7a71;     /* teal that reads as text/link on white (5:1) */
  --page: #f3f6f6;
  --surface: #ffffff;
  --surface-2: #f7f9f9;
  --ink: #0e1a19;
  --ink-2: #4a5654;
  --muted: #7d8886;
  --line: #e2e8e7;
  --line-strong: #c9d2d0;
  --hover: rgba(16, 168, 155, 0.08);
  --single: #0f9a8e;         /* single-series bars */
  --series-new: #2a78d6;
  --series-review: #eb6834;
  --series-duplicates: #1baf7a;
  --series-other: #eda100;
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --good-ink: #067006;
  --warning-ink: #8a5a00;
  --critical-ink: #b02a2a;
  --shadow: 0 1px 2px rgba(14, 26, 25, 0.06), 0 0 0 1px rgba(14, 26, 25, 0.06);
  --radius: 10px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --brand: #0e9c90;
    --brand-deep: #4fd1c5;
    --page: #0c1212;
    --surface: #151c1c;
    --surface-2: #1b2423;
    --ink: #eef3f2;
    --ink-2: #b9c4c2;
    --muted: #8a9593;
    --line: #26302f;
    --line-strong: #364241;
    --hover: rgba(79, 209, 197, 0.08);
    --single: #1fa89b;
    --series-new: #3987e5;
    --series-review: #d95926;
    --series-duplicates: #199e70;
    --series-other: #c98500;
    --good-ink: #3fcf3f;
    --warning-ink: #fab219;
    --critical-ink: #ef7272;
    --shadow: 0 0 0 1px rgba(255, 255, 255, 0.06);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --brand: #0e9c90;
  --brand-deep: #4fd1c5;
  --page: #0c1212;
  --surface: #151c1c;
  --surface-2: #1b2423;
  --ink: #eef3f2;
  --ink-2: #b9c4c2;
  --muted: #8a9593;
  --line: #26302f;
  --line-strong: #364241;
  --hover: rgba(79, 209, 197, 0.08);
  --single: #1fa89b;
  --series-new: #3987e5;
  --series-review: #d95926;
  --series-duplicates: #199e70;
  --series-other: #c98500;
  --good-ink: #3fcf3f;
  --warning-ink: #fab219;
  --critical-ink: #ef7272;
  --shadow: 0 0 0 1px rgba(255, 255, 255, 0.06);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--page);
  color: var(--ink);
  font: 14px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand-deep); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; font-weight: 600; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 15px; font-weight: 600; margin: 0 0 12px; }
h3 { font-size: 13px; font-weight: 600; margin: 16px 0 8px; color: var(--ink-2); }
code, .mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }

/* ---------- header ---------- */
.topbar { background: var(--brand); color: var(--brand-ink); }
.topbar-inner {
  max-width: 1320px; margin: 0 auto; padding: 0 16px; height: 68px;
  display: flex; align-items: center; gap: 16px;
}
.brand { display: flex; align-items: center; color: inherit; margin-left: -7px; }  /* the image has 7px of air */
.brand:hover { text-decoration: none; }
.brand img { display: block; height: 40px; width: auto; }
.app-title {
  font-size: 14px; font-weight: 500; padding-left: 16px; margin-left: 2px;
  border-left: 1px solid rgba(255, 255, 255, 0.35); white-space: nowrap;
}
.topbar .spacer { flex: 1; }
.env {
  font-size: 11px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
  background: rgba(255, 255, 255, 0.18); padding: 4px 8px; border-radius: 999px; white-space: nowrap;
}
.env.production { background: #ffffff; color: var(--critical); }
.toggle {
  color: inherit; font-size: 12px; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.toggle .box {
  width: 28px; height: 16px; border-radius: 999px; background: rgba(255, 255, 255, 0.3); position: relative;
}
.toggle .box::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 12px; height: 12px; border-radius: 50%;
  background: #fff; transition: left 0.15s;
}
.toggle.on .box { background: rgba(255, 255, 255, 0.55); }
.toggle.on .box::after { left: 14px; }
.toggle:hover { text-decoration: none; opacity: 0.9; }

.userbox { display: flex; align-items: center; gap: 10px; font-size: 13px; margin: 0; }
.userbox span { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.userbox button {
  font: inherit; font-size: 12px; font-weight: 600; color: inherit; background: rgba(255, 255, 255, 0.16);
  border: 0; border-radius: 7px; padding: 5px 10px; cursor: pointer;
}
.userbox button:hover { background: rgba(255, 255, 255, 0.28); }

/* ---------- sign-in ---------- */
.login { min-height: calc(100vh - 68px); display: grid; place-items: center; padding: 32px 16px; }
.login-card { width: 100%; max-width: 400px; }
.login-card h1 { margin-bottom: 4px; }
.login-card .sub { color: var(--muted); margin-bottom: 20px; }
.login-card label { display: block; font-size: 13px; font-weight: 500; color: var(--ink-2); margin: 14px 0 6px; }
.login-card input {
  width: 100%; font: inherit; color: var(--ink); background: var(--surface-2); border: 1px solid var(--line-strong);
  border-radius: 8px; padding: 10px 12px;
}
.login-card input:focus, .filters input:focus, .filters select:focus {
  outline: 2px solid var(--brand); outline-offset: 1px; border-color: transparent;
}
.login-card .btn { width: 100%; justify-content: center; margin-top: 20px; padding: 11px 14px; }
.login-card .error {
  background: rgba(208, 59, 59, 0.1); color: var(--critical-ink); border-radius: 8px; padding: 10px 12px;
  font-size: 13px;
}
.login-card .ms-btn {
  width: 100%; justify-content: center; gap: 10px; margin-top: 16px; padding: 11px 14px;
  background: var(--surface); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line-strong);
}
.login-card .ms-btn:hover { background: var(--surface-2); filter: none; }
.login-card .ms-btn svg { width: 18px; height: 18px; flex: none; }
.login-card .error + .ms-btn { margin-top: 16px; }
.alt-login { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
.alt-login summary { font-size: 13px; }
.login-card .help { color: var(--muted); font-size: 12px; margin-top: 16px; text-align: center; }

.nav { background: var(--surface); border-bottom: 1px solid var(--line); }
.nav-inner {
  max-width: 1320px; margin: 0 auto; padding: 0 16px; display: flex; gap: 2px; overflow-x: auto;
  scrollbar-width: none;
}
.nav a {
  color: var(--ink-2); padding: 12px 12px 10px; border-bottom: 2px solid transparent; white-space: nowrap;
  font-weight: 500;
}
.nav a:hover { color: var(--ink); text-decoration: none; background: var(--hover); }
.nav a.active { color: var(--ink); border-bottom-color: var(--brand); }

/* ---------- layout ---------- */
main { max-width: 1320px; margin: 0 auto; padding: 20px 16px 48px; }
.page-head { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head .sub { color: var(--muted); margin-top: 4px; }
.page-head .spacer { flex: 1; }
.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); }
.grid.three { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.stack { display: grid; gap: 16px; }
.card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px;
  min-width: 0;
}
.card.flush { padding: 0; }
.card.flush > h2 { padding: 16px 16px 0; }
.card-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 12px; }
.card-head h2 { margin: 0; }
.card-head .spacer { flex: 1; }

/* ---------- range picker & filters ---------- */
.segmented { display: inline-flex; background: var(--surface); border-radius: 8px; box-shadow: var(--shadow); }
.segmented a {
  padding: 6px 12px; color: var(--ink-2); font-size: 13px; white-space: nowrap; border-radius: 8px;
}
.segmented a:hover { text-decoration: none; background: var(--hover); }
.segmented a.on { background: var(--brand); color: #fff; font-weight: 600; }
.filters {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 16px;
  background: var(--surface); padding: 12px; border-radius: var(--radius); box-shadow: var(--shadow);
}
.filters input[type="search"], .filters select {
  font: inherit; color: var(--ink); background: var(--surface-2); border: 1px solid var(--line-strong);
  border-radius: 7px; padding: 7px 10px; min-width: 0;
}
.filters input[type="search"] { flex: 1 1 240px; }
.filters select { flex: 0 1 180px; }
.btn {
  font: inherit; font-weight: 600; border: 0; border-radius: 7px; padding: 8px 14px; cursor: pointer;
  background: var(--brand); color: #fff; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px;
}
.btn:hover { text-decoration: none; filter: brightness(1.05); }
.btn.ghost { background: transparent; color: var(--brand-deep); box-shadow: inset 0 0 0 1px var(--line-strong); }
.btn.small { padding: 5px 10px; font-size: 12px; }

/* ---------- stat tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; }
.tile .label { color: var(--ink-2); font-size: 12px; font-weight: 500; }
.tile .value { font-size: 28px; font-weight: 600; letter-spacing: -0.02em; margin-top: 4px; }
.tile .note { color: var(--muted); font-size: 12px; margin-top: 2px; }
.tile.hero .value { font-size: 40px; }
a.tile { color: inherit; display: block; }
a.tile:hover { text-decoration: none; box-shadow: var(--shadow), 0 0 0 2px var(--brand); }

/* ---------- status ---------- */
.status { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; white-space: nowrap; }
.status::before {
  content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none;
}
.status.good::before { background: var(--good); }
.status.warning::before { background: var(--warning); }
.status.critical::before { background: var(--critical); }
.status.good { color: var(--good-ink); }
.status.warning { color: var(--warning-ink); }
.status.critical { color: var(--critical-ink); }
.chip {
  display: inline-block; font-size: 12px; font-weight: 500; padding: 2px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--ink-2); box-shadow: inset 0 0 0 1px var(--line); white-space: nowrap;
}
.chip.brand { background: rgba(16, 168, 155, 0.12); color: var(--brand-deep); box-shadow: none; }
.chip.bad { background: rgba(208, 59, 59, 0.1); color: var(--critical-ink); box-shadow: none; }
.chip.warn { background: rgba(250, 178, 25, 0.16); color: var(--warning-ink); box-shadow: none; }
.chip.ok { background: rgba(12, 163, 12, 0.1); color: var(--good-ink); box-shadow: none; }
.health { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 0 24px; }
.health-row {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 7px 0;
  border-bottom: 1px solid var(--line);
}
.health-row .status { color: var(--ink); }
.health-row .when { color: var(--muted); font-size: 12px; white-space: nowrap; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th {
  font-size: 12px; font-weight: 600; color: var(--muted); background: var(--surface); position: sticky; top: 0;
  white-space: nowrap;
}
tbody tr:hover { background: var(--hover); }
td.wrap { max-width: 360px; overflow-wrap: anywhere; }
td .sub { color: var(--muted); font-size: 12px; }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); }
.pager { display: flex; align-items: center; gap: 12px; justify-content: flex-end; padding: 12px 16px; }

/* ---------- detail ---------- */
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px 24px; }
.field .k { color: var(--muted); font-size: 12px; }
.field .v { overflow-wrap: anywhere; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.votes td.chosen { color: var(--brand-deep); font-weight: 600; }
.votes td.chosen::before { content: "✓ "; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: grid; grid-template-columns: 150px 110px 1fr; gap: 12px; padding: 8px 0;
  border-bottom: 1px solid var(--line); }
.timeline .who { color: var(--ink-2); font-weight: 500; }
.timeline .bad { color: var(--critical-ink); }
pre.json {
  background: var(--surface-2); border-radius: 8px; padding: 12px; overflow: auto; max-height: 320px;
  font-size: 12px; margin: 8px 0 0;
}
details summary { cursor: pointer; color: var(--brand-deep); font-weight: 500; }

/* ---------- charts ---------- */
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-bottom: 8px; font-size: 12px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.key { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none; }
.s-new { fill: var(--series-new); background: var(--series-new); }
.s-review { fill: var(--series-review); background: var(--series-review); }
.s-duplicates { fill: var(--series-duplicates); background: var(--series-duplicates); }
.s-other { fill: var(--series-other); background: var(--series-other); }
.chart-scroll { overflow-x: auto; }
svg.chart { width: 100%; min-width: 560px; height: auto; display: block; }
svg.chart .grid { stroke: var(--line); stroke-width: 1; shape-rendering: crispEdges; }
svg.chart .grid.base { stroke: var(--line-strong); }
svg.chart .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
svg.chart .hit { fill: transparent; }
svg.chart .col:hover .hit { fill: var(--hover); }
.hbars { display: grid; gap: 6px; }
.hbar { display: grid; grid-template-columns: minmax(120px, 34%) 1fr; gap: 12px; align-items: center; }
.hbar-label { font-size: 13px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar-track { display: flex; align-items: center; gap: 8px; min-width: 0; }
.hbar-fill { height: 14px; border-radius: 0 4px 4px 0; background: var(--single); min-width: 2px; }
.hbar-value { font-size: 12px; color: var(--ink-2); font-variant-numeric: tabular-nums; white-space: nowrap; }
.hbar:hover .hbar-label { color: var(--ink); }

#tip {
  position: fixed; pointer-events: none; z-index: 10; background: var(--surface); color: var(--ink);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18), 0 0 0 1px var(--line); border-radius: 8px; padding: 8px 10px;
  font-size: 12px; line-height: 1.6; display: none; max-width: 280px;
}
#tip .key { margin-right: 6px; vertical-align: -1px; }

footer { max-width: 1320px; margin: 0 auto; padding: 0 16px 32px; color: var(--muted); font-size: 12px; }

@media (max-width: 720px) {
  .app-title, .userbox span, .env { display: none; }
  .grid.two { grid-template-columns: 1fr; }
  .timeline li { grid-template-columns: 1fr; gap: 2px; }
  .tile .value { font-size: 24px; }
  .tile.hero .value { font-size: 32px; }
}
