:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f3f2ee;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --bar: #2a78d6;
  --bar-soft: #86b6ef;
  --pos: #2a78d6;
  --neu: #b5b3ab;
  --neg: #e34948;
  --good-text: #006300;
  --bad-text: #b3261e;
  --warn-bg: #fff6e0;
  --warn-border: #f0cf7a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 4px 16px rgba(0, 0, 0, .04);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #242423;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5;
    --bar: #3987e5;
    --bar-soft: #256abf;
    --pos: #3987e5;
    --neu: #6b6a64;
    --neg: #e66767;
    --good-text: #0ca30c;
    --bad-text: #ff8a80;
    --warn-bg: #2b2412;
    --warn-border: #6b5520;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --surface-2: #242423; --ink: #ffffff; --ink-2: #c3c2b7;
  --muted: #898781; --grid: #2c2c2a; --axis: #383835; --border: rgba(255, 255, 255, 0.10);
  --accent: #3987e5; --bar: #3987e5; --bar-soft: #256abf; --pos: #3987e5; --neu: #6b6a64; --neg: #e66767;
  --good-text: #0ca30c; --bad-text: #ff8a80; --warn-bg: #2b2412; --warn-border: #6b5520; --shadow: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--page);
  color: var(--ink);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", "Noto Sans Thai", sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2 { margin: 0; font-weight: 600; }
h1 { font-size: 17px; }
h2 { font-size: 15px; }
code { font-size: 12px; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 14px 24px; border-bottom: 1px solid var(--border); background: var(--surface);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--accent); }
.brand h1 { color: var(--ink); }
.sub { margin: 0; color: var(--muted); font-size: 12px; }
.top-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.status { color: var(--ink-2); font-size: 12px; display: inline-flex; align-items: center; gap: 6px; }
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status .dot.ok { background: #0ca30c; }
.status .dot.off { background: #fab219; }
.status .dot.busy { background: var(--accent); animation: pulse 1s infinite alternate; }
@keyframes pulse { to { opacity: .3; } }

main { max-width: 1280px; margin: 0 auto; padding: 20px 24px 48px; display: flex; flex-direction: column; gap: 16px; }

/* ---------- controls ---------- */
.btn {
  font: inherit; font-size: 13px; padding: 7px 14px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--ink);
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .55; cursor: progress; }
.icon-btn { border: 0; background: none; color: var(--ink-2); font-size: 16px; cursor: pointer; padding: 4px 8px; border-radius: 6px; }
.icon-btn:hover { background: var(--surface-2); }

select, input[type=search], input[type=text], input[type=password], input[type=number], input:not([type]), textarea {
  font: inherit; font-size: 13px; color: var(--ink); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; min-width: 0;
}
textarea { width: 100%; resize: vertical; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filters input[type=search] { flex: 1 1 200px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface); }
.seg button { font: inherit; font-size: 13px; border: 0; background: none; color: var(--ink-2); padding: 7px 12px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button[aria-checked=true] { background: var(--surface-2); color: var(--ink); font-weight: 600; }

.notice {
  background: var(--warn-bg); border: 1px solid var(--warn-border); border-radius: 10px;
  padding: 10px 14px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; font-size: 13px;
}
.notice .grow { flex: 1 1 260px; }
.notice.error { background: color-mix(in srgb, var(--neg) 10%, var(--surface)); border-color: color-mix(in srgb, var(--neg) 40%, transparent); }

/* ---------- cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px 18px; box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.card-sub { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.head-actions { display: flex; gap: 8px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
@media (max-width: 980px) { .grid3 { grid-template-columns: 1fr; } }

/* ---------- KPI tiles ---------- */
.kpis { display: grid; grid-template-columns: 1.3fr 1fr 1fr 1.4fr; gap: 16px; }
@media (max-width: 980px) { .kpis { grid-template-columns: 1fr 1fr; } }
@media (max-width: 520px) { .kpis { grid-template-columns: 1fr; } }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 18px; box-shadow: var(--shadow); }
.kpi .label { color: var(--ink-2); font-size: 12px; }
.kpi .value { font-size: 28px; font-weight: 600; line-height: 1.2; margin-top: 4px; }
.kpi.hero .value { font-size: 48px; line-height: 1.05; }
.kpi .delta { font-size: 12px; color: var(--muted); margin-top: 4px; }
.delta .up { color: var(--good-text); font-weight: 600; }
.delta .down { color: var(--bad-text); font-weight: 600; }
.meter { display: flex; gap: 2px; height: 12px; margin: 12px 0 8px; }
.meter span { display: block; height: 100%; min-width: 0; }
.meter span:first-child { border-radius: 4px 0 0 4px; }
.meter span:last-child { border-radius: 0 4px 4px 0; }
.meter span:only-child { border-radius: 4px; }
.meter-legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--ink-2); }
.meter-legend b { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- legend / swatches ---------- */
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--ink-2); flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.sw.pos, .bg-pos { background: var(--pos); }
.sw.neu, .bg-neu { background: var(--neu); }
.sw.neg, .bg-neg { background: var(--neg); }

/* ---------- charts ---------- */
.chart { width: 100%; min-height: 240px; position: relative; }
.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(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:hover, .chart .hit.active { fill: var(--ink); fill-opacity: .04; }
.empty { color: var(--muted); font-size: 13px; padding: 28px 0; text-align: center; }

.bars { display: flex; flex-direction: column; gap: 4px; }
.bar-row {
  display: grid; grid-template-columns: minmax(70px, 34%) 1fr; gap: 10px; align-items: center;
  padding: 4px 6px; margin: 0 -6px; border-radius: 6px; cursor: pointer; border: 0; background: none;
  font: inherit; color: inherit; text-align: left; width: calc(100% + 12px);
}
.bar-row:hover, .bar-row.active { background: var(--surface-2); }
.bar-row .name { font-size: 13px; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .track { display: grid; grid-template-columns: minmax(0, 1fr) 34px; align-items: center; gap: 8px; min-width: 0; }
.bar-row .lane { display: block; min-width: 0; }
.bar-row .fill { display: block; height: 14px; border-radius: 0 4px 4px 0; background: var(--bar); min-width: 3px; }
.bar-row .stack { display: flex; gap: 2px; height: 14px; min-width: 3px; }
.bar-row .stack span { height: 100%; }
.bar-row .stack span:last-child { border-radius: 0 4px 4px 0; }
.bar-row .num { text-align: right; font-size: 12px; color: var(--ink-2); font-variant-numeric: tabular-nums; white-space: nowrap; }
.bars.terms .fill { background: var(--bar-soft); }

/* ---------- feed ---------- */
.feed { list-style: none; margin: 0; padding: 0; }
.feed li { display: grid; grid-template-columns: 36px 1fr; gap: 12px; padding: 12px 0; border-top: 1px solid var(--border); }
.feed li:first-child { border-top: 0; }
.pf { width: 36px; height: 36px; border-radius: 9px; display: grid; place-items: center; font-size: 12px; font-weight: 700; background: var(--surface-2); color: var(--ink-2); }
.feed .meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.feed .title { font-weight: 600; color: var(--ink); text-decoration: none; display: block; margin: 2px 0; overflow-wrap: anywhere; }
.feed .title:hover { text-decoration: underline; }
.feed .snippet { color: var(--ink-2); font-size: 13px; margin: 0; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.feed mark { background: color-mix(in srgb, var(--accent) 18%, transparent); color: inherit; border-radius: 3px; padding: 0 2px; }
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--border); color: var(--ink-2); font-size: 11.5px; }
.chip .sw { width: 8px; height: 8px; border-radius: 50%; }
.chip.kw { background: var(--surface-2); border-color: transparent; }
.feed-more { display: flex; justify-content: center; margin-top: 8px; }

/* ---------- tooltip ---------- */
.tooltip {
  position: fixed; z-index: 50; pointer-events: none; background: var(--surface); color: var(--ink);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 12px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .14); min-width: 140px;
}
.tooltip .t-head { font-weight: 600; margin-bottom: 4px; }
.tooltip .t-row { display: flex; align-items: center; gap: 6px; justify-content: space-between; }
.tooltip .t-row span:first-child { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); }
.tooltip .t-row b { font-variant-numeric: tabular-nums; font-weight: 600; }

/* ---------- settings dialog ---------- */
dialog {
  border: 1px solid var(--border); border-radius: 14px; padding: 0; width: min(640px, calc(100vw - 32px));
  background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(0, 0, 0, .25);
}
dialog::backdrop { background: rgba(0, 0, 0, .35); }
dialog form { padding: 18px 20px; display: flex; flex-direction: column; gap: 14px; max-height: calc(100vh - 64px); overflow: auto; }
.dlg-head { display: flex; justify-content: space-between; align-items: center; }
fieldset { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
legend { font-weight: 600; font-size: 13px; padding: 0; margin-bottom: 6px; }
fieldset.cols { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (max-width: 520px) { fieldset.cols { grid-template-columns: 1fr; } }
fieldset.cols label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--ink-2); }
.row { display: flex; gap: 8px; }
.row input { flex: 1; }
.hint { margin: 0; color: var(--muted); font-size: 12px; }
.checks { display: flex; flex-wrap: wrap; gap: 6px; }
.checks label { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); border-radius: 999px; padding: 4px 10px 4px 8px; font-size: 13px; cursor: pointer; }
.checks label:has(input:checked) { background: color-mix(in srgb, var(--accent) 12%, transparent); border-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.check-line { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; color: var(--ink-2); }
.estimate { margin: 0; font-size: 12px; color: var(--ink-2); background: var(--surface-2); padding: 8px 10px; border-radius: 8px; }
.dlg-foot { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; border-top: 1px solid var(--border); padding-top: 14px; }
.dlg-foot > div { display: flex; gap: 8px; flex-wrap: wrap; }

@media (max-width: 640px) {
  .topbar, main { padding-left: 16px; padding-right: 16px; }
  .kpi.hero .value { font-size: 40px; }
}

/* ---------- locked keywords / report ---------- */
.lock { font-size: 12px; opacity: .7; }
.locked-list { display: flex; flex-direction: column; gap: 6px; }
.locked-list .group { border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; background: var(--surface-2); }
.locked-list .group b { display: block; font-size: 13px; }
.locked-list .group span { font-size: 12px; color: var(--ink-2); }
.locked-list .empty-lock { color: var(--bad-text); font-size: 13px; }
.report-banner { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.report-banner h2 { font-size: 20px; }
.report-banner span { color: var(--muted); font-size: 13px; }
.chart .sel-band { fill: var(--ink); fill-opacity: .05; }

/* ---------- auth / roles ---------- */
body[data-auth="loading"] > header, body[data-auth="loading"] > main,
body[data-auth="out"] > header, body[data-auth="out"] > main { display: none; }
body:not([data-auth="out"]) .auth { display: none; }
body:not([data-role="admin"]) .admin-only { display: none !important; }
body[data-role="viewer"] .editor-only { display: none !important; }
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: min(400px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 24px; box-shadow: var(--shadow); }
.auth-card .brand { margin-bottom: 18px; }
.auth-card h2 { margin-bottom: 4px; }
.auth-card form, .dlg-body { display: flex; flex-direction: column; gap: 12px; }
.auth-card label, .dlg-body label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--ink-2); }
.auth-card input, .dlg-body input:not([type=checkbox]) { font-size: 14px; padding: 9px 11px; }
.form-error { margin: 0; color: var(--bad-text); font-size: 13px; min-height: 0; }
.form-error:empty { display: none; }
.dlg-body { padding: 18px 20px; max-height: calc(100vh - 64px); overflow: auto; }
.dlg-body h3 { margin: 0; font-size: 14px; }

.menu { position: relative; }
.menu summary { list-style: none; display: inline-flex; align-items: center; gap: 6px; }
.menu summary::-webkit-details-marker { display: none; }
.menu-pop { position: absolute; right: 0; top: calc(100% + 6px); background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 8px 28px rgba(0,0,0,.16); padding: 6px; min-width: 170px; z-index: 20; display: flex; flex-direction: column; }
.menu-pop button { font: inherit; font-size: 13px; text-align: left; background: none; border: 0; color: var(--ink); padding: 8px 10px; border-radius: 6px; cursor: pointer; }
.menu-pop button:hover { background: var(--surface-2); }
.role-badge { font-size: 11px; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--border); }
.role-badge.admin { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--ink); border-color: color-mix(in srgb, var(--accent) 40%, transparent); }

.kw-head, .kw-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr) 32px; gap: 8px; align-items: center; }
.kw-head { font-size: 11px; color: var(--muted); }
.kw-editor { display: flex; flex-direction: column; gap: 6px; }
@media (max-width: 520px) { .kw-head { display: none; } .kw-row { grid-template-columns: 1fr 32px; } .kw-row input:nth-child(2) { grid-column: 1; } }

table.users { width: 100%; border-collapse: collapse; font-size: 13px; }
table.users th { text-align: left; font-weight: 600; font-size: 12px; color: var(--muted); padding: 6px 8px; border-bottom: 1px solid var(--border); }
table.users td { padding: 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.users td small { display: block; color: var(--muted); }
table.users td:last-child { text-align: right; white-space: nowrap; }
table.users select { padding: 4px 8px; }
table.users .btn { padding: 4px 10px; font-size: 12px; }
.user-form { border-top: 1px solid var(--border); padding-top: 14px; display: flex; flex-direction: column; gap: 10px; }
.user-form .cols { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (max-width: 560px) { .user-form .cols { grid-template-columns: 1fr; } table.users th:nth-child(3), table.users td:nth-child(3) { display: none; } }
.user-form .row input { flex: 1; }
.report-banner .coverage { flex-basis: 100%; font-size: 12px; color: var(--ink-2); }
.estimate b { color: var(--ink); }

/* ---------- related keywords ---------- */
.related-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 24px; }
@media (max-width: 980px) { .related-grid { grid-template-columns: 1fr; } }
.related-grid h3 { margin: 0 0 8px; font-size: 13px; font-weight: 600; }
.cat-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
.cat-chips button { font: inherit; font-size: 11.5px; border: 1px solid var(--border); background: var(--surface); color: var(--ink-2); border-radius: 999px; padding: 2px 9px; cursor: pointer; }
.cat-chips button[aria-pressed=true] { background: var(--surface-2); color: var(--ink); border-color: var(--axis); font-weight: 600; }
.cat-chips button b { font-weight: 600; font-variant-numeric: tabular-nums; }
.rel-row { grid-template-columns: minmax(90px, 44%) 1fr; }
.rel-row .name { display: flex; flex-direction: column; line-height: 1.3; white-space: normal; }
.rel-row .name small { font-size: 11px; color: var(--muted); }
.rel-row .edit { visibility: hidden; font-size: 11px; color: var(--accent); margin-left: 4px; cursor: pointer; }
.rel-row:hover .edit { visibility: visible; }
body:not([data-role="admin"]) .rel-row .edit { display: none; }
.rel-foot { margin-top: 12px; }
.more-link { font: inherit; font-size: 12px; border: 0; background: none; color: var(--accent); cursor: pointer; padding: 6px 0; }

.hat-top { font-size: 20px; font-weight: 600; line-height: 1.3; }
.hat-sub { color: var(--ink-2); font-size: 12px; margin: 2px 0 10px; }
.hat-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.hat-list li { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; font-size: 13px; }
.hat-list .meter-line { grid-column: 1 / -1; height: 6px; border-radius: 3px; background: var(--grid); overflow: hidden; }
.hat-list .meter-line span { display: block; height: 100%; background: var(--bar); border-radius: 3px; }
.hat-list small { color: var(--muted); }
.hat-list b { font-variant-numeric: tabular-nums; font-weight: 600; }

.ent-head, .ent-row { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1.6fr) minmax(0, 1.2fr) 32px; gap: 8px; align-items: center; }
.ent-head { font-size: 11px; color: var(--muted); }
.ent-row.flash input { outline: 2px solid var(--accent); }
@media (max-width: 600px) { .ent-head { display: none; } .ent-row { grid-template-columns: 1fr 32px; } .ent-row > :nth-child(2), .ent-row > :nth-child(3) { grid-column: 1; } }
#entities-dlg { width: min(820px, calc(100vw - 32px)); }

/* clear-filters: stands out whenever a filter is active */
.btn.clear-filters {
  display: inline-flex; align-items: center; gap: 6px; font-weight: 600;
  /* blue step 500: white text clears 4.5:1 in both light and dark mode */
  background: #256abf; color: #ffffff; border-color: transparent;
  box-shadow: 0 0 0 3px color-mix(in srgb, #256abf 25%, transparent);
  animation: clear-in .25s ease-out;
}
.btn.clear-filters:hover { background: #1c5cab; }
.btn.clear-filters .count {
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; font-size: 11px; line-height: 18px; text-align: center;
  background: #ffffff; color: #256abf; font-variant-numeric: tabular-nums;
}
@keyframes clear-in { from { transform: scale(.9); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .btn.clear-filters { animation: none; } }
.filters .is-active { border-color: #256abf; box-shadow: 0 0 0 1px #256abf; font-weight: 600; }

/* ---------- welcome screen (after login) ---------- */
.welcome {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 24px 16px;
  background: radial-gradient(1200px 600px at 50% 35%, color-mix(in srgb, var(--accent) 14%, var(--page)), var(--page));
  animation: welcome-in .35s ease-out;
}
.welcome.leaving { opacity: 0; transform: scale(1.02); transition: opacity .45s ease, transform .45s ease; }
.welcome-card { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 6px; max-width: 520px; }
.welcome-logo { color: var(--accent); margin-bottom: 10px; }
.welcome-logo path { stroke-dasharray: 1; stroke-dashoffset: 1; animation: welcome-draw 1.1s ease-out .15s forwards; }
.welcome-hello { margin: 0; color: var(--ink-2); font-size: 15px; }
.welcome-name { margin: 0; font-size: 34px; line-height: 1.2; font-weight: 600; color: var(--ink); }
.welcome-date { margin: 6px 0 18px; color: var(--muted); font-size: 13px; }
.welcome-progress { width: min(260px, 70vw); height: 4px; border-radius: 2px; background: var(--grid); overflow: hidden; }
.welcome-progress span { display: block; height: 100%; width: 40%; border-radius: 2px; background: var(--accent); animation: welcome-bar 1.1s ease-in-out infinite; }
.welcome.done .welcome-progress span { width: 100%; animation: none; transition: width .3s ease; }
.welcome-status { margin: 12px 0 0; color: var(--ink-2); font-size: 13px; min-height: 1.5em; }
.welcome-status span { white-space: nowrap; }
.welcome-skip { margin-top: 18px; font: inherit; font-size: 13px; color: var(--accent); background: none; border: 0; cursor: pointer; padding: 6px 10px; border-radius: 6px; opacity: 0; animation: welcome-fade .3s ease 1s forwards; }
.welcome-skip:hover { background: var(--surface-2); }
@keyframes welcome-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes welcome-draw { to { stroke-dashoffset: 0; } }
@keyframes welcome-bar { 0% { transform: translateX(-100%); } 100% { transform: translateX(250%); } }
@keyframes welcome-fade { to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  .welcome, .welcome-logo path, .welcome-progress span, .welcome-skip { animation: none; }
  .welcome-logo path { stroke-dashoffset: 0; }
  .welcome-skip { opacity: 1; }
  .welcome.leaving { transition: none; }
}

/* ---------- issue tracking ---------- */
.topics-status { font-size: 12px; color: var(--ink-2); margin: -4px 0 10px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.topics-status .warn { color: var(--bad-text); }
.topics-list { display: flex; flex-direction: column; }
.topic-row {
  display: grid; grid-template-columns: minmax(0, 2.2fr) 64px 84px minmax(90px, 1.3fr) 120px 32px; gap: 12px; align-items: center;
  padding: 8px 6px; margin: 0 -6px; border-radius: 8px; border: 0; background: none; font: inherit; color: inherit; text-align: left; cursor: pointer; width: calc(100% + 12px);
}
.topic-row + .topic-row { border-top: 1px solid var(--border); border-radius: 0; }
.topic-row:hover, .topic-row.active { background: var(--surface-2); border-radius: 8px; }
.topic-row.head { cursor: default; font-size: 11px; color: var(--muted); padding-top: 0; }
.topic-row.head:hover { background: none; }
.topic-name { min-width: 0; }
.topic-name b { font-weight: 600; display: block; overflow-wrap: anywhere; }
.topic-name small { color: var(--muted); font-size: 11.5px; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topic-tag { display: inline-block; font-size: 10.5px; font-weight: 600; padding: 0 6px; border-radius: 999px; margin-left: 6px; vertical-align: 1px; border: 1px solid var(--border); color: var(--ink-2); }
.topic-tag.new { background: #256abf; color: #fff; border-color: transparent; }
.topic-num { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }
.topic-delta { font-size: 12px; font-variant-numeric: tabular-nums; }
.topic-delta.up { color: var(--good-text); } .topic-delta.down { color: var(--bad-text); } .topic-delta.flat { color: var(--muted); }
.topic-sent { display: flex; gap: 2px; height: 10px; }
.topic-sent span { height: 100%; }
.topic-sent span:first-child { border-radius: 3px 0 0 3px; } .topic-sent span:last-child { border-radius: 0 3px 3px 0; } .topic-sent span:only-child { border-radius: 3px; }
.topic-spark { display: block; }
.topic-spark rect { fill: var(--bar-soft); }
.topic-spark rect.cur { fill: var(--bar); }
.topic-edit { border: 0; background: none; color: var(--ink-2); cursor: pointer; font-size: 14px; padding: 4px; border-radius: 6px; }
.topic-edit:hover { background: var(--surface); color: var(--accent); }
@media (max-width: 760px) {
  .topic-row { grid-template-columns: minmax(0, 1fr) 48px 32px; }
  .topic-row > .topic-delta, .topic-row > .topic-sent, .topic-row > .topic-spark, .topic-row.head > :nth-child(3), .topic-row.head > :nth-child(4), .topic-row.head > :nth-child(5) { display: none; }
}
.chip.topic { cursor: pointer; border-style: dashed; }
.chip.topic:hover { border-color: var(--accent); color: var(--ink); }
.chip.topic.manual { border-style: solid; }
.topic-picker { font-size: 12px; padding: 2px 6px; border-radius: 999px; }
.chip .ai-mark { font-size: 9.5px; font-weight: 700; color: var(--muted); margin-left: 2px; }
.ai-cols { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (max-width: 520px) { .ai-cols { grid-template-columns: 1fr; } }
.topic-extra { display: flex; flex-direction: column; gap: 10px; border-top: 1px solid var(--border); padding-top: 12px; }

/* ---------- activity log (admin) ---------- */
#activity-dlg { width: min(1100px, calc(100vw - 32px)); }
#notice-dlg { width: min(560px, calc(100vw - 32px)); }
.notice-body p, .notice-body ul { margin: 0; font-size: 14px; line-height: 1.65; color: var(--ink); }
.notice-body ul { padding-left: 20px; }
.activity-filters { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; align-items: end;
  /* undo the generic "dialog form" scroll-box styling, which let this row get squashed */
  padding: 0; overflow: visible; max-height: none; flex-shrink: 0; }
.activity-filters > * { min-width: 0; }
.activity-filters label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--ink-2); }
.activity-filters input, .activity-filters select { width: 100%; }
.activity-filters label.grow { grid-column: span 2; }
.activity-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.activity-summary { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 8px; }
.activity-summary button { text-align: left; font: inherit; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; cursor: pointer; color: var(--ink); }
.activity-summary button[aria-pressed=true] { border-color: #256abf; box-shadow: 0 0 0 1px #256abf; }
.activity-summary b { display: block; font-size: 14px; }
.activity-summary small { display: block; color: var(--ink-2); font-size: 11.5px; line-height: 1.5; }
.activity-table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 10px; }
.activity-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.activity-table th { position: sticky; top: 0; background: var(--surface); text-align: left; font-weight: 600; font-size: 11.5px; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.activity-table td { padding: 7px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.activity-table tr:last-child td { border-bottom: 0; }
.activity-table td:first-child { white-space: nowrap; font-variant-numeric: tabular-nums; color: var(--ink-2); }
.activity-table td small { color: var(--muted); }
.activity-table .act { white-space: nowrap; }
.activity-table .act.edit { font-weight: 600; }
.activity-table .act.warn { color: var(--bad-text); font-weight: 600; }
.activity-table .detail { overflow-wrap: anywhere; max-width: 420px; }
.activity-table .detail a { color: var(--accent); }

.role-badge.viewer { background: transparent; border-style: dashed; }

/* ---------- theme switch (light / dark / auto) ---------- */
.theme-switch { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 6px 4px; margin: 4px 0; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.theme-switch .theme-label { grid-column: 1 / -1; font-size: 11px; color: var(--muted); padding: 0 6px 2px; }
.menu-pop .theme-switch button { text-align: center; font-size: 12px; padding: 6px 4px; border: 1px solid var(--border); border-radius: 6px; white-space: nowrap; }
.menu-pop .theme-switch button[aria-checked=true] { background: #256abf; color: #fff; border-color: transparent; font-weight: 600; }
.menu-pop { min-width: 240px; }

/* ---------- relevance: hide unrelated posts ---------- */
.chip.muted { color: var(--muted); border-style: dotted; }
.post-hide { font: inherit; font-size: 11px; color: var(--muted); background: none; border: 1px solid transparent; border-radius: 999px; padding: 1px 8px; cursor: pointer; margin-left: auto; }
.feed li:hover .post-hide { border-color: var(--border); }
.post-hide:hover { color: var(--bad-text); border-color: currentColor; }
.post-hide.restore { color: var(--accent); border-color: var(--border); margin-left: 0; }
.post-hide.restore:hover { color: var(--accent); }
#hidden-dlg { width: min(760px, calc(100vw - 32px)); }

.hide-title { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
#hide-dlg { width: min(560px, calc(100vw - 32px)); }
#hide-source { overflow-wrap: anywhere; font-weight: 600; }
.blocked-sources { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.blocked-sources:empty { display: none; }
.blocked-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 6px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); }
.blocked-row small { color: var(--muted); }

/* checkbox rows inside dialogs: box and text on one line */
.dlg-body label.check-line { flex-direction: row; align-items: flex-start; gap: 8px; font-size: 13px; color: var(--ink-2); }
.dlg-body label.check-line input { margin-top: 3px; flex: none; }
