/* Prisma admin — single stylesheet.
   Structure: tokens → base → layout (shell) → components → charts → utilities.
   Colors are referenced only through tokens; dark mode redefines the tokens. */

/* ---------- Tokens ---------- */
:root {
  color-scheme: light;
  --bg: #f6f6f3;
  --surface: #ffffff;
  --surface-2: #f9f9f7;
  --surface-3: #f0efec;
  --border: rgba(11, 11, 11, 0.09);
  --border-strong: rgba(11, 11, 11, 0.16);
  --text: #121211;
  --text-2: #52514e;
  --text-3: #898781;
  --accent: #2a78d6;
  --accent-ink: #1c5cab;
  --accent-soft: #e6f0fc;
  --focus: rgba(42, 120, 214, 0.35);

  /* Chart series (validated categorical order) */
  --c1: #2a78d6; --c2: #eb6834; --c3: #1baf7a; --c4: #eda100;
  --c5: #e87ba4; --c6: #008300; --c7: #6250d6; --c8: #e34948;
  --neutral: #c3c2b7;
  --grid: #e9e8e2;
  --axis: #c3c2b7;

  /* Status (never used as series colors) */
  --good: #0ca30c; --good-ink: #006300; --good-soft: #e5f5e5;
  --warn: #fab219; --warn-ink: #8a5a00; --warn-soft: #fff4dc;
  --serious: #ec835a; --serious-ink: #a4421c; --serious-soft: #fdeee7;
  --bad: #d03b3b; --bad-ink: #a92424; --bad-soft: #fbeaea;

  /* Sequential blue ramp for heatmaps */
  --seq-0: #f0efec; --seq-1: #cde2fb; --seq-2: #9ec5f4; --seq-3: #6da7ec; --seq-4: #3987e5; --seq-5: #256abf; --seq-6: #184f95;

  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 2px 8px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.16);
  --sidebar: 236px;
  --topbar: 56px;
  --tabbar: 60px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f0f0e; --surface: #1a1a19; --surface-2: #20201f; --surface-3: #2a2a28;
    --border: rgba(255, 255, 255, 0.08); --border-strong: rgba(255, 255, 255, 0.16);
    --text: #f0efec; --text-2: #c3c2b7; --text-3: #898781;
    --accent: #3987e5; --accent-ink: #86b6ef; --accent-soft: #17283d; --focus: rgba(57, 135, 229, 0.45);
    --c1: #3987e5; --c2: #d95926; --c3: #199e70; --c4: #c98500; --c5: #d55181; --c6: #008300; --c7: #9085e9; --c8: #e66767;
    --neutral: #5a5a55; --grid: #2c2c2a; --axis: #45453f;
    --good-ink: #4cc74c; --good-soft: #10260f; --warn-ink: #fab219; --warn-soft: #2c2410;
    --serious-ink: #f09a77; --serious-soft: #2e1b13; --bad-ink: #ef7d7d; --bad-soft: #2f1515;
    --seq-0: #262624; --seq-1: #13253b; --seq-2: #184f95; --seq-3: #1c5cab; --seq-4: #2a78d6; --seq-5: #5598e7; --seq-6: #9ec5f4;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3); --shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.6);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f0f0e; --surface: #1a1a19; --surface-2: #20201f; --surface-3: #2a2a28;
  --border: rgba(255, 255, 255, 0.08); --border-strong: rgba(255, 255, 255, 0.16);
  --text: #f0efec; --text-2: #c3c2b7; --text-3: #898781;
  --accent: #3987e5; --accent-ink: #86b6ef; --accent-soft: #17283d; --focus: rgba(57, 135, 229, 0.45);
  --c1: #3987e5; --c2: #d95926; --c3: #199e70; --c4: #c98500; --c5: #d55181; --c6: #008300; --c7: #9085e9; --c8: #e66767;
  --neutral: #5a5a55; --grid: #2c2c2a; --axis: #45453f;
  --good-ink: #4cc74c; --good-soft: #10260f; --warn-ink: #fab219; --warn-soft: #2c2410;
  --serious-ink: #f09a77; --serious-soft: #2e1b13; --bad-ink: #ef7d7d; --bad-soft: #2f1515;
  --seq-0: #262624; --seq-1: #13253b; --seq-2: #184f95; --seq-3: #1c5cab; --seq-4: #2a78d6; --seq-5: #5598e7; --seq-6: #9ec5f4;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3); --shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.6);
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.45 var(--font); -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 22px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
p { margin: 0; }
code, pre, .mono { font-family: var(--mono); font-size: 12.5px; }
pre { white-space: pre-wrap; word-break: break-word; margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- Shell ---------- */
.shell { min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar); z-index: 30;
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 16px 18px 10px; font-weight: 700; font-size: 16px; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--c1), var(--c7)); color: #fff; font-size: 15px;
}
.brand small { display: block; font-weight: 500; font-size: 11px; color: var(--text-3); }
.nav { padding: 6px 10px 16px; flex: 1; }
.nav-group { margin-top: 14px; }
.nav-group-title { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-3); padding: 0 10px 6px; font-weight: 600; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 8px;
  color: var(--text-2); font-weight: 500; text-decoration: none; position: relative;
}
.nav a:hover { background: var(--surface-3); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent-ink); }
.nav a .icon { width: 18px; height: 18px; flex: none; }
.nav .count { margin-left: auto; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 99px; background: var(--bad-soft); color: var(--bad-ink); }
.sidebar-foot { border-top: 1px solid var(--border); padding: 12px 14px; display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: var(--surface-3); font-weight: 650; color: var(--text-2); text-transform: uppercase;
}
.main { margin-left: var(--sidebar); min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 20; height: var(--topbar);
  display: flex; align-items: center; gap: 12px; padding: 0 28px;
  background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(10px);
  border-bottom: 1px solid transparent;
}
.topbar.scrolled { border-bottom-color: var(--border); }
.topbar .title { font-weight: 650; font-size: 15px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .crumbs { color: var(--text-3); font-weight: 500; }
.topbar .spacer { flex: 1; }
.btn.menu-btn { display: none; }
.page { padding: 8px 28px 48px; max-width: 1400px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin: 6px 0 18px; }
.page-head .lead { color: var(--text-2); margin-top: 4px; max-width: 720px; }
.tabbar { display: none; }
.scrim { display: none; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }

@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); transition: transform 0.2s ease; box-shadow: var(--shadow-lg); width: 280px; }
  .shell.nav-open .sidebar { transform: none; }
  .shell.nav-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, 0.35); z-index: 25; }
  .main { margin-left: 0; }
  .btn.menu-btn { display: inline-flex; }
  .topbar { padding: 0 12px; }
  .page { padding: 4px 16px calc(var(--tabbar) + 28px + env(safe-area-inset-bottom)); }
  h1 { font-size: 20px; }
  .tabbar {
    display: flex; position: fixed; inset: auto 0 0 0; z-index: 20;
    height: calc(var(--tabbar) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
    background: var(--surface); border-top: 1px solid var(--border);
  }
  .tabbar a, .tabbar button {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    font-size: 10.5px; font-weight: 550; color: var(--text-3); text-decoration: none; background: none; border: 0;
  }
  .tabbar .icon { width: 22px; height: 22px; }
  .tabbar a.active { color: var(--accent-ink); }
}

/* ---------- Components ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 16px 0; flex-wrap: wrap; }
.card-head .hint { color: var(--text-3); font-size: 12px; }
.card-body { padding: 14px 16px 16px; }
.card-body.flush { padding: 0; }
.card + .card, .stack > * + * { margin-top: 16px; }
.grid { display: grid; gap: 16px; }
.grid > * { min-width: 0; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-main { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); }
.grid.cols-side { grid-template-columns: minmax(0, 1fr) 380px; align-items: start; }
@media (max-width: 1100px) { .grid.cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid.cols-side { grid-template-columns: 1fr; } }
@media (max-width: 760px) { .grid.cols-2, .grid.cols-3, .grid.cols-main { grid-template-columns: 1fr; } }
.sticky-side { position: sticky; top: calc(var(--topbar) + 8px); }
@media (max-width: 1100px) { .sticky-side { position: static; } }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap;
  height: 34px; padding: 0 13px; border-radius: 8px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); font-weight: 550; cursor: pointer; text-decoration: none;
  transition: background 0.12s, border-color 0.12s;
}
.btn:hover { background: var(--surface-3); text-decoration: none; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--bad-ink); }
.btn.danger.solid { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-3); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 13px; border-radius: 7px; }
.btn.icon-only { width: 34px; padding: 0; }
.btn.sm.icon-only { width: 28px; }
.btn .icon { width: 16px; height: 16px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
@media (max-width: 900px) { .btn { height: 38px; } .btn.sm { height: 32px; } }

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label, .label { font-size: 12px; font-weight: 600; color: var(--text-2); }
.field .help { font-size: 12px; color: var(--text-3); }
.input, .select, .textarea {
  width: 100%; height: 34px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--border-strong);
  background: var(--surface); outline: none; min-width: 0;
}
.textarea { height: auto; padding: 8px 10px; resize: vertical; line-height: 1.5; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus); }
.input.invalid { border-color: var(--bad); }
.select { padding-right: 28px; appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--text-3) 50%), linear-gradient(135deg, var(--text-3) 50%, transparent 50%); background-position: calc(100% - 15px) 15px, calc(100% - 10px) 15px; background-size: 5px 5px; background-repeat: no-repeat; }
@media (max-width: 900px) { .input, .select { height: 40px; font-size: 16px; } .textarea { font-size: 16px; } }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); margin: 0; }

.switch { position: relative; display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .track { width: 34px; height: 20px; border-radius: 99px; background: var(--neutral); position: relative; transition: background 0.15s; flex: none; }
.switch .track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform 0.15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + .track { background: var(--good); }
.switch input:checked + .track::after { transform: translateX(14px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 5px; height: 28px; padding: 0 11px; border-radius: 99px;
  border: 1px solid var(--border-strong); background: var(--surface); cursor: pointer; font-weight: 500; font-size: 13px; color: var(--text-2);
}
.chip:hover { background: var(--surface-3); }
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-ink); }
.chip .x { font-size: 15px; line-height: 1; opacity: 0.6; }
.tag {
  display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 6px;
  background: var(--surface-3); color: var(--text-2); font-size: 12px; font-weight: 550; white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis;
}
.tag.include { background: var(--good-soft); color: var(--good-ink); }
.tag.exclude { background: var(--bad-soft); color: var(--bad-ink); }

.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 99px;
  font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--surface-3); color: var(--text-2);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.85; }
.badge.plain::before { display: none; }
.badge.good { background: var(--good-soft); color: var(--good-ink); }
.badge.warn { background: var(--warn-soft); color: var(--warn-ink); }
.badge.serious { background: var(--serious-soft); color: var(--serious-ink); }
.badge.bad { background: var(--bad-soft); color: var(--bad-ink); }
.badge.info { background: var(--accent-soft); color: var(--accent-ink); }

.segmented { display: inline-flex; background: var(--surface-3); border-radius: 9px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.segmented button {
  border: 0; background: transparent; padding: 5px 11px; border-radius: 7px; cursor: pointer;
  font-weight: 550; font-size: 13px; color: var(--text-2); white-space: nowrap;
}
.segmented button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  border: 0; background: none; padding: 9px 12px; cursor: pointer; font-weight: 550; color: var(--text-2);
  border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap;
}
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); }
.tabs button .n { color: var(--text-3); font-weight: 500; margin-left: 4px; }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.toolbar .grow { flex: 1; min-width: 180px; }

/* Stat tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 13px 15px; box-shadow: var(--shadow); min-width: 0; display: block; color: inherit; }
a.tile:hover { text-decoration: none; border-color: var(--border-strong); }
.tile .k { color: var(--text-2); font-size: 12.5px; font-weight: 550; display: flex; align-items: center; gap: 6px; }
.tile .v { font-size: 25px; font-weight: 650; margin-top: 4px; letter-spacing: -0.02em; line-height: 1.15; }
.tile .s { color: var(--text-3); font-size: 12px; margin-top: 3px; }
@media (max-width: 520px) { .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; } .tile .v { font-size: 21px; } }

/* Tables */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th { text-align: left; font-weight: 600; color: var(--text-3); font-size: 12px; padding: 9px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; background: var(--surface); }
.table th.sortable { cursor: pointer; user-select: none; }
.table th.sortable:hover { color: var(--text); }
.table th.sorted::after { content: " ↓"; }
.table th.sorted.asc::after { content: " ↑"; }
.table td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table td.r, .table th.r { text-align: right; font-variant-numeric: tabular-nums; }
.table tr.click { cursor: pointer; }
.table tr.click:hover td { background: var(--surface-2); }
.table .muted { color: var(--text-3); }

/* Lists */
.list { display: flex; flex-direction: column; }
.list-item { display: flex; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); color: inherit; align-items: flex-start; min-width: 0; }
.list-item:last-child { border-bottom: 0; }
a.list-item:hover { background: var(--surface-2); text-decoration: none; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .meta { color: var(--text-3); font-size: 12px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.snippet { color: var(--text); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; white-space: pre-line; word-break: break-word; }
.facts { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12.5px; color: var(--text-2); margin-top: 4px; }
.facts b { color: var(--text); font-weight: 600; }

/* Key-value */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 7px 16px; font-size: 13.5px; }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; min-width: 0; word-break: break-word; }
@media (max-width: 520px) { .kv { grid-template-columns: 1fr; gap: 2px; } .kv dd { margin-bottom: 8px; } }

.muted { color: var(--text-3); }
.text-2 { color: var(--text-2); }
.small { font-size: 12.5px; }
.strong { font-weight: 650; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.row { display: flex; align-items: center; gap: 8px; min-width: 0; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.col { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.gap-lg { gap: 16px; }
.mt { margin-top: 12px; }
.mt-lg { margin-top: 20px; }
.hr { height: 1px; background: var(--border); margin: 14px 0; border: 0; }
.source-text { white-space: pre-wrap; word-break: break-word; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; font-size: 14px; line-height: 1.55; }
.code-block { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; max-height: 420px; overflow: auto; }

.callout { display: flex; gap: 10px; padding: 11px 14px; border-radius: 9px; background: var(--surface-3); color: var(--text-2); align-items: flex-start; }
.callout .icon { width: 18px; height: 18px; flex: none; margin-top: 1px; }
.callout.warn { background: var(--warn-soft); color: var(--warn-ink); }
.callout.bad { background: var(--bad-soft); color: var(--bad-ink); }
.callout.info { background: var(--accent-soft); color: var(--accent-ink); }
.callout.good { background: var(--good-soft); color: var(--good-ink); }
.callout b { color: inherit; }

.empty { text-align: center; padding: 36px 16px; color: var(--text-3); }
.empty .icon { width: 30px; height: 30px; margin-bottom: 8px; opacity: 0.7; }
.empty h3 { color: var(--text-2); margin-bottom: 4px; }

.spinner { width: 18px; height: 18px; border: 2px solid var(--border-strong); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { display: flex; justify-content: center; align-items: center; gap: 10px; padding: 40px; color: var(--text-3); }
.skeleton { background: linear-gradient(90deg, var(--surface-3), var(--surface-2), var(--surface-3)); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: 8px; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* Pipeline dots: compact per-post stage outcomes */
.pipe { display: inline-flex; gap: 3px; align-items: center; }
.pipe i { width: 9px; height: 9px; border-radius: 3px; background: var(--surface-3); border: 1px solid var(--border); }
.pipe i.passed { background: var(--c1); border-color: transparent; }
.pipe i.stopped { background: var(--text-3); border-color: transparent; }
.pipe i.waiting { background: var(--c4); border-color: transparent; }
.pipe i.partial { background: var(--c7); border-color: transparent; }
.pipe i.error { background: var(--bad); border-color: transparent; }

/* Timeline */
.timeline { position: relative; padding-left: 22px; }
.timeline::before { content: ""; position: absolute; left: 7px; top: 6px; bottom: 6px; width: 2px; background: var(--border); }
.tl-item { position: relative; padding: 0 0 14px; }
.tl-item:last-child { padding-bottom: 0; }
.tl-item::before { content: ""; position: absolute; left: -20px; top: 4px; width: 12px; height: 12px; border-radius: 50%; background: var(--surface); border: 2px solid var(--c1); }
.tl-item.stop::before { border-color: var(--text-3); }
.tl-item.bad::before { border-color: var(--bad); background: var(--bad); }
.tl-item.good::before { border-color: var(--good); background: var(--good); }
.tl-item.wait::before { border-color: var(--c4); }
.tl-item .when { color: var(--text-3); font-size: 12px; }
.tl-item .what { font-weight: 600; }
.tl-item .detail { color: var(--text-2); font-size: 13px; margin-top: 2px; word-break: break-word; }

/* Stage strip in post card */
.stages { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 4px; }
.stage { padding: 8px 6px; border-radius: 8px; background: var(--surface-3); text-align: center; font-size: 11.5px; color: var(--text-3); font-weight: 600; min-width: 0; }
.stage .s { display: block; font-size: 11px; font-weight: 500; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stage.passed { background: var(--accent-soft); color: var(--accent-ink); }
.stage.stopped { background: var(--surface-3); color: var(--text); box-shadow: inset 0 0 0 1.5px var(--text-3); }
.stage.waiting { background: var(--warn-soft); color: var(--warn-ink); }
.stage.partial { background: var(--serious-soft); color: var(--serious-ink); }
.stage.error { background: var(--bad-soft); color: var(--bad-ink); }
@media (max-width: 700px) { .stages { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

/* Modal & sheet */
.overlay { position: fixed; inset: 0; z-index: 100; background: rgba(0, 0, 0, 0.4); display: flex; align-items: center; justify-content: center; padding: 20px; animation: fade 0.12s; }
@keyframes fade { from { opacity: 0; } }
.modal { background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg); width: 100%; max-width: 520px; max-height: calc(100vh - 40px); display: flex; flex-direction: column; animation: pop 0.15s; }
.modal.wide { max-width: 860px; }
@keyframes pop { from { transform: translateY(8px) scale(0.98); opacity: 0; } }
.modal-head { padding: 16px 18px 6px; display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.modal-body { padding: 8px 18px 16px; overflow-y: auto; }
.modal-foot { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
@media (max-width: 640px) {
  .overlay { align-items: flex-end; padding: 0; }
  .modal { max-width: none; border-radius: 16px 16px 0 0; max-height: 92vh; padding-bottom: env(safe-area-inset-bottom); animation: slideup 0.2s; }
  @keyframes slideup { from { transform: translateY(40px); opacity: 0; } }
  .modal-foot .btn { flex: 1; }
}

.toasts { position: fixed; z-index: 200; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; max-width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow-lg); font-weight: 500; animation: pop 0.15s; display: flex; gap: 10px; align-items: flex-start; }
.toast.bad { background: var(--bad); color: #fff; }
.toast.good { background: var(--good-ink); color: #fff; }
@media (max-width: 900px) { .toasts { left: 16px; right: 16px; bottom: calc(var(--tabbar) + 14px + env(safe-area-inset-bottom)); max-width: none; } }

/* Period picker */
.period { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.period .custom { display: inline-flex; gap: 6px; align-items: center; }
.period .custom .input { width: 148px; height: 32px; }

/* Keyword editor */
.kw-box { border: 1px solid var(--border-strong); border-radius: 9px; background: var(--surface); }
.kw-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus); }
.kw-box .chips { padding: 8px; min-height: 44px; }
.kw-box .kw-input { border: 0; outline: none; background: transparent; flex: 1; min-width: 140px; height: 28px; }
.kw-chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 4px 2px 9px; border-radius: 6px; font-size: 13px; font-weight: 550; }
.kw-chip button { border: 0; background: transparent; color: inherit; cursor: pointer; width: 20px; height: 20px; border-radius: 4px; font-size: 15px; line-height: 1; opacity: 0.65; }
.kw-chip button:hover { opacity: 1; background: rgba(0,0,0,.06); }
.kw-chip .n { font-size: 11px; opacity: 0.75; font-weight: 500; }
.kw-chip.include { background: var(--good-soft); color: var(--good-ink); }
.kw-chip.exclude { background: var(--bad-soft); color: var(--bad-ink); }
.kw-chip.neutral { background: var(--surface-3); color: var(--text-2); }
.kw-chip.added { box-shadow: inset 0 0 0 1.5px currentColor; }

/* Diff */
.diff ins { background: var(--good-soft); color: var(--good-ink); text-decoration: none; border-radius: 3px; }
.diff del { background: var(--bad-soft); color: var(--bad-ink); border-radius: 3px; }
.json-diff { display: grid; grid-template-columns: max-content 1fr 1fr; gap: 4px 12px; font-size: 12.5px; }
.json-diff .h { color: var(--text-3); font-weight: 600; }
.json-diff .old { color: var(--bad-ink); word-break: break-word; }
.json-diff .new { color: var(--good-ink); word-break: break-word; }
@media (max-width: 600px) { .json-diff { grid-template-columns: 1fr; } .json-diff .h { display: none; } }

details.disclosure > summary { cursor: pointer; color: var(--text-2); font-weight: 550; list-style: none; display: flex; align-items: center; gap: 6px; }
details.disclosure > summary::-webkit-details-marker { display: none; }
details.disclosure > summary::before { content: "▸"; font-size: 11px; transition: transform 0.12s; }
details.disclosure[open] > summary::before { transform: rotate(90deg); }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(1200px 600px at 10% -10%, var(--accent-soft), transparent), var(--bg); }
.login .card { width: 100%; max-width: 380px; padding: 28px; }
.login .brand { padding: 0 0 18px; }
.login form { display: flex; flex-direction: column; gap: 14px; }
.login .error { color: var(--bad-ink); font-size: 13px; min-height: 18px; }

/* ---------- Charts ---------- */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--axis); stroke-width: 1; }
.chart .tick { fill: var(--text-3); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .hover-band { fill: var(--text); opacity: 0; }
.chart .hover-band.on { opacity: 0.05; }
.chart-tip {
  position: absolute; pointer-events: none; z-index: 5; min-width: 150px; max-width: 260px;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 9px; box-shadow: var(--shadow-lg);
  padding: 8px 10px; font-size: 12.5px; opacity: 0; transition: opacity 0.08s; transform: translateX(-50%);
}
.chart-tip.on { opacity: 1; }
.chart-tip .t { font-weight: 650; margin-bottom: 4px; }
.chart-tip .r { display: flex; align-items: center; gap: 6px; justify-content: space-between; }
.chart-tip .r span:first-child { display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); }
.chart-tip .r b { font-variant-numeric: tabular-nums; font-weight: 600; }
.swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12.5px; color: var(--text-2); margin-bottom: 10px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend button { border: 0; background: none; padding: 0; display: inline-flex; align-items: center; gap: 6px; cursor: pointer; color: inherit; font: inherit; }
.legend button.off { opacity: 0.4; }

/* Horizontal bar list */
.bars { display: flex; flex-direction: column; gap: 8px; }
.bar-row { display: grid; grid-template-columns: minmax(90px, 34%) 1fr auto; gap: 10px; align-items: center; color: inherit; min-width: 0; }
a.bar-row:hover { text-decoration: none; }
a.bar-row:hover .bar-label { color: var(--accent-ink); text-decoration: underline; }
.bar-label { font-size: 13px; overflow: hidden; color: var(--text-2); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; line-height: 1.25; word-break: break-word; }
.bar-track { height: 14px; display: flex; gap: 2px; min-width: 0; }
.bar-fill { height: 100%; border-radius: 0 4px 4px 0; min-width: 2px; background: var(--c1); }
.bar-fill + .bar-fill { border-radius: 0 4px 4px 0; }
.bar-track.stacked .bar-fill { border-radius: 0; }
.bar-track.stacked .bar-fill:last-child { border-radius: 0 4px 4px 0; }
.bar-value { font-size: 12.5px; font-variant-numeric: tabular-nums; color: var(--text); font-weight: 600; text-align: right; white-space: nowrap; }
.bar-value small { color: var(--text-3); font-weight: 500; margin-left: 4px; }
@media (max-width: 520px) { .bar-row { grid-template-columns: 1fr auto; } .bar-row .bar-track { grid-column: 1 / -1; grid-row: 2; } }

/* Proportion bar */
.prop { display: flex; height: 10px; gap: 2px; border-radius: 4px; overflow: hidden; background: var(--surface-3); }
.prop > span { height: 100%; min-width: 2px; }

/* Funnel */
.funnel { display: flex; flex-direction: column; gap: 6px; }
.funnel-row { display: grid; grid-template-columns: 170px 1fr 150px; gap: 14px; align-items: center; }
.funnel-name { font-weight: 600; font-size: 13.5px; }
.funnel-name small { display: block; color: var(--text-3); font-weight: 500; font-size: 11.5px; }
.funnel-track { display: flex; height: 26px; gap: 2px; min-width: 0; }
.funnel-seg { height: 100%; min-width: 3px; border: 0; padding: 0; cursor: pointer; transition: filter 0.1s; }
.funnel-seg:first-child { border-radius: 4px 0 0 4px; }
.funnel-seg:last-child { border-radius: 0 4px 4px 0; }
.funnel-seg:only-child { border-radius: 4px; }
.funnel-seg:hover { filter: brightness(1.12) saturate(1.1); outline: 2px solid var(--text); outline-offset: 1px; }
.funnel-seg.passed { background: var(--c1); }
.funnel-seg.stopped { background: var(--neutral); }
.funnel-seg.waiting { background: var(--c4); }
.funnel-seg.partial { background: var(--c7); }
.funnel-nums { font-size: 12.5px; color: var(--text-2); font-variant-numeric: tabular-nums; text-align: right; }
.funnel-nums b { color: var(--text); font-size: 14px; }
@media (max-width: 760px) {
  .funnel-row { grid-template-columns: 1fr auto; gap: 4px 10px; }
  .funnel-track { grid-column: 1 / -1; grid-row: 2; height: 20px; }
}

/* Heatmap */
.heat { display: grid; grid-template-columns: 26px repeat(24, minmax(0, 1fr)); gap: 2px; font-size: 10.5px; color: var(--text-3); }
.heat .cell { aspect-ratio: 1; border-radius: 3px; background: var(--seq-0); min-width: 0; }
.heat .lab { display: flex; align-items: center; }
.heat .hl { text-align: center; }

.sparkline { display: block; }
.delta-up { color: var(--good-ink); }
.delta-down { color: var(--bad-ink); }

/* Routing matrix */
.matrix td.cell { text-align: center; }
.matrix .dot-btn { width: 26px; height: 26px; border-radius: 7px; border: 1px solid var(--border-strong); background: var(--surface); cursor: pointer; display: inline-grid; place-items: center; }
.matrix .dot-btn.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.matrix .dot-btn:hover { border-color: var(--accent); }

/* Filter editor */
.range-row { display: grid; grid-template-columns: minmax(120px, 1fr) 1fr 1fr; gap: 8px; align-items: center; }
.range-row .label { font-weight: 550; color: var(--text); font-size: 13.5px; }
.range-row .label small { display: block; color: var(--text-3); font-weight: 500; font-size: 11.5px; }
.input-unit { position: relative; }
.input-unit .input { padding-right: 34px; }
.input-unit span { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); color: var(--text-3); font-size: 12px; pointer-events: none; }
@media (max-width: 520px) { .range-row { grid-template-columns: 1fr 1fr; } .range-row .label { grid-column: 1 / -1; } }
.district-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; }
.district-grid .chip { justify-content: flex-start; border-radius: 8px; }

.filter-card { display: flex; flex-direction: column; gap: 10px; }
.filter-card .cond { display: flex; flex-wrap: wrap; gap: 5px; }
.stat-inline { display: flex; gap: 18px; flex-wrap: wrap; }
.stat-inline > div { min-width: 0; }
.stat-inline .v { font-weight: 650; font-size: 17px; font-variant-numeric: tabular-nums; }
.stat-inline .k { color: var(--text-3); font-size: 11.5px; }

.channel-card { display: flex; flex-direction: column; gap: 10px; padding: 14px 16px; }
.channel-card .btn-row { gap: 4px; }
.channel-card .title { font-weight: 650; font-size: 15px; }
.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 14px; }
.cards-grid > .card { display: flex; flex-direction: column; }
@media (max-width: 520px) { .cards-grid { grid-template-columns: 1fr; } }

/* Phone: one-row scrollable period and segmented controls */
@media (max-width: 640px) {
  .period { max-width: 100%; flex-wrap: nowrap; }
  .period .segmented { min-width: 0; }
  .period .segmented, .page-head .segmented { flex-wrap: nowrap; overflow-x: auto; max-width: 100%; scrollbar-width: none; }
  .period .segmented::-webkit-scrollbar { display: none; }
  .page-head > .btn-row { width: 100%; }
  .topbar .badge { max-width: 46vw; overflow: hidden; text-overflow: ellipsis; }
}
.table td:first-child { min-width: 150px; }

/* ---------- Contextual help ---------- */
.with-hint { display: inline-flex; align-items: center; gap: 5px; }
.hint-btn {
  display: inline-grid; place-items: center; flex: none; width: 16px; height: 16px; padding: 0; margin: 0;
  border-radius: 50%; border: 1px solid var(--border-strong); background: transparent; color: var(--text-3);
  font: 600 10.5px/1 var(--font); cursor: help; vertical-align: middle; transition: color 0.12s, border-color 0.12s, background 0.12s;
  text-transform: none; letter-spacing: 0;
}
.hint-btn:hover, .hint-btn[aria-expanded="true"] { color: var(--accent-ink); border-color: var(--accent); background: var(--accent-soft); }
/* Larger invisible touch target on phones without changing the look */
@media (pointer: coarse) { .hint-btn { position: relative; } .hint-btn::after { content: ""; position: absolute; inset: -10px; } }
.help-pop {
  position: fixed; z-index: 300; max-width: min(320px, calc(100vw - 24px)); padding: 10px 12px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border-strong); border-radius: 10px;
  box-shadow: var(--shadow-lg); font-size: 13px; line-height: 1.5; font-weight: 400; text-align: left; animation: fade 0.1s;
}
.help-pop::before {
  content: ""; position: absolute; top: -6px; left: calc(var(--arrow-x, 50%) - 6px); width: 10px; height: 10px;
  background: var(--surface); border-left: 1px solid var(--border-strong); border-top: 1px solid var(--border-strong); transform: rotate(45deg);
}
.help-pop.above::before { top: auto; bottom: -6px; transform: rotate(225deg); }
.help-pop .help-title { font-weight: 650; margin-bottom: 3px; }
.help-pop p { margin: 0; color: var(--text-2); }
.help-pop p + p { margin-top: 6px; }
.table th .hint-btn { margin-left: 4px; }
.tile .k .hint-btn { margin-left: auto; }

/* Picker list in dialogs (e.g. add destination chat) */
.icon { width: 16px; height: 16px; flex: none; }
.pick-list { min-width: 0; list-style: none; margin: 0; padding: 0; border: 1px solid var(--border); border-radius: var(--radius, 10px); max-height: min(56vh, 460px); overflow-y: auto; }
.pick-item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-bottom: 1px solid var(--border); min-width: 0; }
.pick-item:last-child { border-bottom: 0; }
.pick-item:hover { background: var(--surface-2); }
.pick-item .grow { flex: 1; min-width: 0; }
.pick-title { font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pick-item .meta { color: var(--text-3); font-size: 12px; display: flex; gap: 4px 10px; flex-wrap: wrap; margin-top: 2px; }
.pick-item .btn { flex: none; }
.pick-none { padding: 16px; text-align: center; }
