:root {
  --paper: #fbf8f1;
  --surface: #ffffff;
  --ink: #1b1a17;
  --ink-2: #4a4740;
  --muted: #8a857a;
  --rule: #d9d3c4;
  --rule-strong: #1b1a17;
  --accent: #9b2b1f;
  --accent-soft: #f3e3df;
  --high: #1f6b3a;
  --high-soft: #e1efe5;
  --medium: #8a5a00;
  --medium-soft: #f6ead2;
  --low: #6b6b6b;
  --low-soft: #ececec;
  --bar: #3d5a80;
  --serif: "Newsreader", Georgia, serif;
  --sans: "Libre Franklin", system-ui, -apple-system, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #15140f;
    --surface: #1e1d18;
    --ink: #ece7db;
    --ink-2: #c3bdae;
    --muted: #8f897b;
    --rule: #3a372e;
    --rule-strong: #ece7db;
    --accent: #e0705f;
    --accent-soft: #3a211c;
    --high: #7fc795;
    --high-soft: #1d3324;
    --medium: #e3b25c;
    --medium-soft: #3a2e17;
    --low: #a7a7a7;
    --low-soft: #2c2c2c;
    --bar: #8fb0d9;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font: 14px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }

/* ---------------------------------------------------------------- masthead */
.masthead {
  padding: 14px 24px 0;
  border-bottom: 3px double var(--rule-strong);
  background: var(--paper);
  position: sticky; top: 0; z-index: 5;
}
.masthead-top {
  display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em;
  border-bottom: 1px solid var(--rule); padding-bottom: 6px;
}
.integrations { display: flex; gap: 10px; flex-wrap: wrap; }
.integrations .ok::before, .integrations .off::before { content: "●"; margin-right: 4px; }
.integrations .ok::before { color: var(--high); }
.integrations .off::before { color: var(--muted); }
.masthead h1 {
  font: 700 34px/1.1 var(--serif); margin: 10px 0 8px; text-align: center; letter-spacing: -.01em;
}
.masthead h1 span { font-weight: 500; font-style: italic; color: var(--accent); }
.tabs { display: flex; justify-content: center; gap: 4px; flex-wrap: wrap; border-top: 1px solid var(--rule); }
.tabs a {
  text-decoration: none; padding: 9px 14px; font-weight: 600; font-size: 13px; color: var(--ink-2);
  border-bottom: 2px solid transparent;
}
.tabs a.active { color: var(--ink); border-bottom-color: var(--accent); }
.platforms { display: flex; justify-content: center; gap: 6px; padding: 8px 0 10px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--rule); background: var(--surface); border-radius: 999px; padding: 4px 12px;
  font-size: 12px; font-weight: 600; cursor: pointer;
}
.chip.active { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.chip[disabled] { opacity: .5; cursor: not-allowed; }
.chip small { font-weight: 500; opacity: .75; }

/* ---------------------------------------------------------------- layout */
main { max-width: 1280px; margin: 0 auto; padding: 22px 24px 60px; }
h2 { font: 700 22px/1.2 var(--serif); margin: 0 0 4px; }
h3 {
  font: 700 12px/1.2 var(--sans); text-transform: uppercase; letter-spacing: .08em; color: var(--ink-2);
  margin: 0 0 10px; padding-bottom: 6px; border-bottom: 1px solid var(--rule);
}
.lede { color: var(--ink-2); margin: 0 0 18px; max-width: 70ch; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.grid { display: grid; gap: 18px; }
.grid.kpis { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin-bottom: 22px; }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); }
.card { background: var(--surface); border: 1px solid var(--rule); padding: 16px; min-width: 0; }
.kpi .label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; }
.kpi .value { font: 700 30px/1.1 var(--serif); margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: 12px; color: var(--muted); }
.empty { color: var(--muted); font-style: italic; padding: 14px 0; }

/* bars */
.bars { display: grid; gap: 7px; }
.bar-row { display: grid; grid-template-columns: minmax(90px, 40%) 1fr auto; gap: 8px; align-items: center; font-size: 13px; }
.bar-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); }
.bar-track { height: 8px; background: var(--paper); border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--bar); border-radius: 4px; }
.bar-row .n { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 28px; text-align: right; }

/* ---------------------------------------------------------------- buttons & forms */
.btn {
  border: 1px solid var(--ink); background: var(--ink); color: var(--paper); padding: 7px 14px;
  font-weight: 600; cursor: pointer; border-radius: 2px; text-decoration: none; display: inline-flex; gap: 6px; align-items: center;
}
.btn.ghost { background: transparent; color: var(--ink); }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn { border: 0; background: none; font-size: 26px; line-height: 1; cursor: pointer; color: var(--ink-2); }
input[type=text], input[type=number], input[type=search], select, textarea {
  border: 1px solid var(--rule); background: var(--surface); padding: 6px 9px; border-radius: 2px; min-width: 0;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible, .chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label.check { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; }
.filters { margin-bottom: 14px; }
.filters input[type=search] { width: 220px; }
textarea.code { width: 100%; min-height: 460px; font: 12.5px/1.5 ui-monospace, Consolas, monospace; }
.field { display: grid; gap: 4px; }
.field span { font-size: 12px; color: var(--muted); font-weight: 600; }
.form-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); margin: 12px 0; }

/* ---------------------------------------------------------------- table */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--rule); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--rule); white-space: nowrap; }
th { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; background: var(--surface); position: sticky; top: 0; }
th.sortable { cursor: pointer; }
th.sorted { color: var(--ink); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--paper); }
.who { display: flex; gap: 9px; align-items: center; min-width: 200px; }
.who img, .avatar { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; background: var(--rule); flex: none; }
.who .name { font-weight: 600; max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.who .handle { color: var(--muted); font-size: 12px; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.pill.High { background: var(--high-soft); color: var(--high); }
.pill.Medium { background: var(--medium-soft); color: var(--medium); }
.pill.Low { background: var(--low-soft); color: var(--low); }
.pill.status { background: var(--paper); border: 1px solid var(--rule); color: var(--ink-2); font-weight: 600; }
.pill.running { background: var(--medium-soft); color: var(--medium); }
.pill.done { background: var(--high-soft); color: var(--high); }
.pill.failed { background: var(--accent-soft); color: var(--accent); }
.score { font: 700 15px var(--serif); }
.pager { margin-top: 12px; }

/* ---------------------------------------------------------------- drawer */
.drawer { position: fixed; inset: 0; z-index: 20; display: none; }
.drawer.open { display: block; }
.drawer-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .35); }
.drawer-panel {
  position: absolute; right: 0; top: 0; bottom: 0; width: min(560px, 100%); background: var(--paper);
  border-left: 1px solid var(--rule); overflow-y: auto; padding: 22px;
}
.drawer-close { position: absolute; right: 14px; top: 10px; }
.drawer .head { display: flex; gap: 14px; align-items: center; margin-bottom: 14px; padding-right: 30px; }
.drawer .head img { width: 64px; height: 64px; }
.drawer .bio { white-space: pre-wrap; color: var(--ink-2); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px 0; }
.stats div { background: var(--surface); border: 1px solid var(--rule); padding: 8px; }
.stats b { display: block; font: 700 18px var(--serif); }
.stats span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.section { margin: 18px 0; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 4px 10px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.breakdown { display: grid; gap: 5px; }
.post { border-bottom: 1px solid var(--rule); padding: 8px 0; font-size: 13px; }
.post .meta { color: var(--muted); font-size: 12px; }
.post p { margin: 2px 0 0; color: var(--ink-2); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.flags { margin: 0; padding-left: 18px; color: var(--accent); }

/* ---------------------------------------------------------------- logs */
.log {
  background: var(--surface); border: 1px solid var(--rule); font: 12px/1.6 ui-monospace, Consolas, monospace;
  max-height: 420px; overflow-y: auto; padding: 10px 12px;
}
.log .line { white-space: pre-wrap; }
.log .ts { color: var(--muted); margin-right: 8px; }
.log .error { color: var(--accent); }
.log .debug { color: var(--muted); }
.stage-track { display: flex; gap: 4px; flex-wrap: wrap; margin: 10px 0; }
.stage-track span { font-size: 11px; padding: 3px 8px; border: 1px solid var(--rule); border-radius: 2px; color: var(--muted); }
.stage-track span.done { color: var(--high); border-color: var(--high); }
.stage-track span.now { color: var(--paper); background: var(--ink); border-color: var(--ink); }

.toast {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%) translateY(80px); background: var(--ink);
  color: var(--paper); padding: 10px 16px; border-radius: 3px; transition: transform .2s; z-index: 30; max-width: calc(100% - 32px);
}
.toast.show { transform: translateX(-50%) translateY(0); }
.notice { background: var(--medium-soft); color: var(--ink); border: 1px solid var(--rule); padding: 10px 14px; margin-bottom: 16px; }

@media (max-width: 640px) {
  .masthead { padding: 10px 16px 0; position: static; }
  .masthead h1 { font-size: 26px; }
  main { padding: 16px 16px 50px; }
  .grid.cols-2, .grid.cols-3 { grid-template-columns: 1fr; }
  .filters input[type=search] { width: 100%; }
  .kv { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
}

/* outreach */
.mini-btn {
  border: 1px solid var(--rule); background: var(--paper); color: var(--ink); border-radius: 2px;
  font-size: 11px; font-weight: 600; padding: 2px 7px; margin-left: 6px; cursor: pointer;
}
.mini-btn:hover { border-color: var(--ink); }
#msg-body { font: 13px/1.5 var(--sans); }
.tpl { border-top: 1px solid var(--rule); padding-top: 12px; margin-top: 12px; }
.tpl textarea { width: 100%; min-height: 140px; }
.hint code { background: var(--paper); padding: 0 3px; }

[hidden] { display: none !important; }
