/* UI font: IBM Plex Sans Thai (Thai + Latin), self-hosted from @fontsource via /fonts */
@font-face { font-family: 'IBM Plex Sans Thai'; font-style: normal; font-weight: 400; font-display: swap;
  src: url(/fonts/ibm-plex-sans-thai-thai-400-normal.woff2) format('woff2'); unicode-range: U+02D7,U+0303,U+0331,U+0E01-0E5B,U+200C-200D,U+25CC; }
@font-face { font-family: 'IBM Plex Sans Thai'; font-style: normal; font-weight: 500; font-display: swap;
  src: url(/fonts/ibm-plex-sans-thai-thai-500-normal.woff2) format('woff2'); unicode-range: U+02D7,U+0303,U+0331,U+0E01-0E5B,U+200C-200D,U+25CC; }
@font-face { font-family: 'IBM Plex Sans Thai'; font-style: normal; font-weight: 600; font-display: swap;
  src: url(/fonts/ibm-plex-sans-thai-thai-600-normal.woff2) format('woff2'); unicode-range: U+02D7,U+0303,U+0331,U+0E01-0E5B,U+200C-200D,U+25CC; }
@font-face { font-family: 'IBM Plex Sans Thai'; font-style: normal; font-weight: 700; font-display: swap;
  src: url(/fonts/ibm-plex-sans-thai-thai-700-normal.woff2) format('woff2'); unicode-range: U+02D7,U+0303,U+0331,U+0E01-0E5B,U+200C-200D,U+25CC; }
@font-face { font-family: 'IBM Plex Sans Thai'; font-style: normal; font-weight: 400; font-display: swap;
  src: url(/fonts/ibm-plex-sans-thai-latin-400-normal.woff2) format('woff2'); unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD; }
@font-face { font-family: 'IBM Plex Sans Thai'; font-style: normal; font-weight: 500; font-display: swap;
  src: url(/fonts/ibm-plex-sans-thai-latin-500-normal.woff2) format('woff2'); unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD; }
@font-face { font-family: 'IBM Plex Sans Thai'; font-style: normal; font-weight: 600; font-display: swap;
  src: url(/fonts/ibm-plex-sans-thai-latin-600-normal.woff2) format('woff2'); unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD; }
@font-face { font-family: 'IBM Plex Sans Thai'; font-style: normal; font-weight: 700; font-display: swap;
  src: url(/fonts/ibm-plex-sans-thai-latin-700-normal.woff2) format('woff2'); unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD; }

:root {
  --bg: #f4f4f4;
  --surface: #ffffff;
  --raised: #f6f7fa; /* between white and the canvas: opened rows, nested panels */
  --text: #16181d;
  --muted: #5d626b;
  --line: #e1e3e8;
  --accent: #1f4fd6;
  /* Shell: ink top bar */
  --ink: #121722; --ink-text: #eef1f6; --ink-muted: #a3acbb; --ink-line: rgba(255, 255, 255, .16);
  /* Heat ramp for "× normal" (1 = around normal … 5 = 30× or more) */
  --heat-0: #8a8f98; --heat-1: #ffc4bc; --heat-2: #ff8878; --heat-3: #ff3a1f;
  /* Type scale (fixed, ~1.2 ratio) */
  --fs-xs: 12px; --fs-sm: 13px; --fs-meta: 14px; --fs-body: 15px; --fs-lead: 17px; --fs-headline: 19px; --fs-h2: 22px; --fs-h1: 28px;
  --hot-bg: #fde8e3;
  --hot-text: #a3341b;
  --ok-bg: #e5f4e4;
  --error-bg: #fbebeb;
  --info-bg: #e7f1fb;
  /* Media groups */
  --g-own: #2470ff;       --g-own-bg: #e8f0ff;
  --g-mass: #d9682b;      --g-mass-bg: #fbeee5;
  --g-credibility: #6b4fc8; --g-credibility-bg: #efebfa;
  --g-business: #1f8f63;  --g-business-bg: #e4f3ec;
  --g-other: #8f8f88;     --g-other-bg: #eeeeea;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: var(--fs-body)/1.6 "IBM Plex Sans Thai", -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans Thai", sans-serif;
  -webkit-font-smoothing: antialiased;
}
html { accent-color: var(--accent); scroll-behavior: smooth; }
a { color: var(--accent); text-underline-offset: .2em; text-decoration-thickness: 1px; }
::selection { background: #cfdafc; color: var(--text); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
h1 { font-size: var(--fs-h1); line-height: 1.25; font-weight: 700; letter-spacing: -0.015em; margin: 20px 0 4px; }
h2 { font-size: var(--fs-h2); line-height: 1.3; font-weight: 600; margin: 40px 0 12px; }
h1, h2, h3 { text-wrap: balance; }
main > h1 + .muted { font-size: var(--fs-lead); margin: 0 0 16px; max-width: 70ch; }
.muted { color: var(--muted); }
.small { font-size: var(--fs-sm); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
table, .chip, .chip-btn, .run-chip, .window-range, .rank { font-variant-numeric: tabular-nums; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px;
  padding: 0 24px; min-height: 56px; background: var(--ink); color: var(--ink-text);
}
.brand { font-weight: 700; text-decoration: none; color: var(--ink-text); font-size: var(--fs-lead); letter-spacing: -0.01em; }
.brand span { font-weight: 400; color: var(--ink-muted); font-size: var(--fs-meta); letter-spacing: 0; }
.topbar .main-nav { display: flex; gap: 24px; flex: 1; margin-left: 32px; align-self: stretch; }
.topbar .main-nav a { display: flex; align-items: center; text-decoration: none; color: var(--ink-muted);
  font-size: var(--fs-meta); font-weight: 500; box-shadow: inset 0 -2px 0 transparent; transition: color .15s, box-shadow .15s; }
.topbar .main-nav a:hover { color: var(--ink-text); }
.topbar .main-nav a.active { color: var(--ink-text); box-shadow: inset 0 -2px 0 var(--ink-text); }
.topbar :focus-visible { outline-color: var(--ink-text); }

/* Account menu: name, role, Users (admins) and Log out behind one button */
.account { position: relative; }
.account summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: 6px;
  padding: 3px 10px 3px 3px; border: 1px solid var(--ink-line); border-radius: 999px; color: var(--ink-text); font-size: 14px;
}
.account summary::-webkit-details-marker { display: none; }
.account summary:hover, .account[open] summary { background: rgba(255, 255, 255, .08); }
.account summary.active { border-color: var(--ink-muted); }
.account summary .account-caret { color: var(--ink-muted); }
.account-menu { color: var(--text); }
.account-initial {
  width: 24px; height: 24px; border-radius: 50%; background: var(--info-bg); color: var(--accent);
  display: inline-flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 600;
}
.account-caret { color: var(--muted); font-size: 11px; }
.account-menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 50; min-width: 210px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.08); padding: 4px 0; display: flex; flex-direction: column;
}
.account-who { padding: 8px 14px 10px; border-bottom: 1px solid var(--line); margin-bottom: 4px; display: flex; flex-direction: column; }
.account-role { color: var(--muted); font-size: 13px; }
.account-menu a { padding: 7px 14px; text-decoration: none; color: var(--text); font-size: 14px; }
.account-menu a:hover { background: var(--bg); }
.account-menu a.active { font-weight: 600; }

/* Settings: topic model picker */
.model-picker { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; margin: 12px 0; }
form .model-option {
  flex-direction: row; margin: 0; font-size: 15px; color: var(--text);
  display: flex; gap: 10px; align-items: flex-start; width: 100%; max-width: 520px; cursor: pointer;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px;
}
form .model-option:has(input:checked) { border-color: var(--accent); background: var(--info-bg); }
.model-option input { margin: 4px 0 0; padding: 0; flex: none; accent-color: var(--accent); }
.badge { font-size: 12px; font-weight: 500; color: var(--accent); background: var(--surface); border: 1px solid var(--accent); border-radius: 999px; padding: 0 7px; }

main { max-width: 1120px; margin: 0 auto; padding: 16px 24px 40px; }
footer { max-width: 1120px; margin: 0 auto; padding: 0 24px 32px; color: var(--muted); font-size: 13px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; margin: 12px 0; }
.card.narrow { max-width: 420px; margin: 48px auto; }

form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
form.inline { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; }
form.inline label { margin: 0; }
form.inline input[name="page_url"] { flex: 1; min-width: 260px; }
input, select { font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; color: var(--text); }
button {
  font: inherit; font-weight: 600; padding: 8px 16px; border-radius: 6px; border: 0;
  background: var(--accent); color: #fff; cursor: pointer;
}
button.secondary { background: var(--surface); color: #3d4149; border: 1px solid #cdd1d8; font-weight: 500; }
/* Hover and press make every button feel clickable, also on the grey Edit panel */
button:not([class]), button[class=""], button.secondary, button.danger {
  transition: background-color .15s ease-out, border-color .15s ease-out, color .15s ease-out, box-shadow .15s ease-out; }
button:is(:not([class]), [class=""]):hover:not(:disabled) { background: #1a43b8; box-shadow: 0 1px 3px rgba(31, 79, 214, .35); }
button.secondary:hover:not(:disabled) { background: #eef2fd; border-color: var(--accent); color: var(--accent); }
button:is(:not([class]), [class=""], .secondary, .danger):active:not(:disabled) { transform: translateY(1px); box-shadow: none; }
.confirm-dialog { width: min(440px, calc(100vw - 32px)); padding: 20px 22px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface); color: var(--text); box-shadow: 0 12px 32px rgba(18, 23, 34, .18); }
.confirm-dialog::backdrop { background: rgba(18, 23, 34, .4); }
.confirm-dialog h2 { margin: 0 0 8px; font-size: var(--fs-headline); }
.confirm-dialog p { margin: 0 0 10px; line-height: 1.55; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
button.link { background: none; color: var(--accent); padding: 0; font-weight: 400; font-size: 13px; }
/* Own chevron instead of the browser's, inset 10px from the right to match the 10px text inset on the left */
select { appearance: none; -webkit-appearance: none; cursor: pointer; padding-right: 32px;
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12' fill='none' stroke='%235d626b' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M2.5 4.5 6 8l3.5-3.5'/%3E%3C/svg%3E") no-repeat right 10px center / 12px 12px; }
.import-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
code { font-size: 12px; background: var(--bg); padding: 1px 4px; border-radius: 4px; }
.nowrap { white-space: nowrap; }
[hidden] { display: none !important; }
button:disabled { opacity: .5; cursor: not-allowed; }

.flash { padding: 10px 14px; border-radius: 8px; margin: 10px 0; }
.flash.ok { background: var(--ok-bg); }
.flash.error { background: var(--error-bg); }
.flash.info { background: var(--info-bg); }

.page-list { list-style: none; margin: 0; padding: 0; }
.page-list li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.page-list li:last-child { border-bottom: 0; }
.page-list li > div { flex: 1; display: flex; flex-direction: column; }
.page-list li form select { font-size: 13px; }

/* Group colour keys */
.g-own { --g: var(--g-own); --g-bg: var(--g-own-bg); }
.g-mass { --g: var(--g-mass); --g-bg: var(--g-mass-bg); }
.g-credibility { --g: var(--g-credibility); --g-bg: var(--g-credibility-bg); }
.g-business { --g: var(--g-business); --g-bg: var(--g-business-bg); }
.g-other { --g: var(--g-other); --g-bg: var(--g-other-bg); }
.group-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--g, var(--g-other));
  margin-right: 6px; vertical-align: 0; flex: none; }
.group-dot.small { width: 7px; height: 7px; margin: 0 0 0 4px; }
.group-title { display: flex; align-items: center; margin-top: 0; }
.group-title .muted { font-weight: 400; margin-left: 6px; }

/* Page avatar: initial underneath, picture on top when it loads */
.avatar-wrap { position: relative; display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 40px; height: 40px; border-radius: 50%; overflow: hidden; background: var(--g-bg, var(--line));
  color: var(--g, var(--muted)); font-weight: 700; box-shadow: 0 0 0 2px var(--surface), 0 0 0 3px var(--g, var(--line)); }
.avatar-wrap img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.avatar-wrap.large { width: 56px; height: 56px; font-size: 22px; }
.avatar-row { display: inline-flex; flex-wrap: wrap; gap: 4px; }
.avatar-row .avatar-wrap { width: 26px; height: 26px; font-size: 12px; }

/* Overview by media group */
/* One surface split into columns by 1px rules, not four floating cards. Each card draws its own right and bottom
   rule into the 1px gap, so a cell left empty in the last row stays white instead of showing the line colour.
   Square top corners: each group's colour bar runs edge to edge instead of being clipped by a curve.
   Columns step 4 → 2 → 1 so four groups never wrap as 3 + 1. */
.group-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 0 0 12px 12px; overflow: hidden; }
@media (max-width: 1100px) { .group-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 640px) { .group-grid { grid-template-columns: minmax(0, 1fr); } }
.group-card { margin: 0; border: 0; border-radius: 0; padding: 18px 18px 16px;
  box-shadow: inset 0 3px 0 var(--g), 1px 0 0 var(--line), 0 1px 0 var(--line), 1px 1px 0 var(--line);
  display: flex; flex-direction: column; gap: 12px; }
.group-card header { display: flex; flex-direction: column; gap: 2px; }
.group-card h3 { margin: 0; font-size: var(--fs-body); font-weight: 600; display: flex; align-items: center; }
.group-topics { margin: 0; padding-left: 22px; display: flex; flex-direction: column; gap: 10px; }
.group-topics li::marker { color: var(--g); font-weight: 700; font-variant-numeric: tabular-nums; }
.group-topics a { color: var(--text); text-decoration: none; font-weight: 500; font-size: var(--fs-body); line-height: 1.45;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.group-topics a:hover { color: var(--accent); }
.group-topics .small { display: flex; align-items: center; flex-wrap: wrap; }

.filter-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 32px 0 0; position: sticky; top: 0; z-index: 2;
  background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: saturate(1.4) blur(8px); padding: 10px 0;
  box-shadow: 0 1px 0 var(--line); }
.chip-btn { display: inline-flex; white-space: nowrap; align-items: center; background: var(--surface); color: var(--text);
  border: 1px solid var(--line); font-weight: 500; font-size: var(--fs-sm); padding: 6px 12px; border-radius: 999px;
  transition: background-color .15s ease-out, border-color .15s ease-out, color .15s ease-out; }
.chip-btn:hover { border-color: var(--muted); }
.chip-btn.active { background: var(--ink); color: var(--ink-text); border-color: var(--ink); }

/* Signals: one ruled list. Columns: rank · story · how unusual (× normal) */
.topics { list-style: none; padding: 0; margin: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.topic { display: grid; grid-template-columns: 44px minmax(0, 1fr); gap: 0 16px; padding: 20px 24px 18px;
  border-top: 1px solid var(--line); scroll-margin-top: 72px; transition: background-color .2s ease-out; }
.topic:first-child { border-top: 0; }
.topic:target { background: #f3f6ff; box-shadow: inset 0 0 0 2px var(--accent); border-radius: 12px; }
.topic .rank { font-size: var(--fs-h2); font-weight: 600; line-height: 1.1; color: var(--text); letter-spacing: -0.02em; }
.topic-body { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.topic-head { display: flex; gap: 20px; justify-content: space-between; align-items: flex-start; }
.topic .label { margin: 0; font-weight: 600; font-size: var(--fs-headline); line-height: 1.5; }
.topic-thumb { flex: none; width: 120px; aspect-ratio: 3 / 2; border-radius: 8px; overflow: hidden; background: var(--bg); }
.topic-thumb > img { display: block; width: 100%; height: 100%; object-fit: cover; }
.covered { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.covered-names { flex: 1; min-width: 200px; line-height: 1.5;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.topic details summary { cursor: pointer; color: var(--accent); width: fit-content; }
.topic.non-news { opacity: .85; }
.topic.non-news .rank { color: var(--muted); }

/* The heat reading: "× normal" as the first chip, coloured by how unusual the topic is for its Page */
/* The orange steps are too light for text, so the chip text stays ink; the tint and the bar carry the heat */
.chip.heat { --heat: var(--heat-1); display: inline-flex; align-items: center; gap: 4px; color: var(--text);
  background: color-mix(in srgb, var(--heat) 16%, var(--surface)); }
.chip.heat.heat-0 { --heat: var(--heat-0); color: var(--muted); }
.chip.heat strong { font-weight: 700; }
.chip.heat.heat-2 { --heat: var(--heat-2); } .chip.heat.heat-3 { --heat: var(--heat-3); }
.heat-bar { display: inline-block; width: 32px; height: 4px; margin-left: 4px; border-radius: 2px;
  background: color-mix(in srgb, var(--heat) 20%, var(--surface)); overflow: hidden; }
.heat-bar > span { display: block; height: 100%; border-radius: 2px; background: var(--heat); }
/* Source articles in a topic card */
.sources { border-top: 1px solid var(--line); padding-top: 8px; }
.source-list { list-style: none; padding: 0; margin: 6px 0 0; display: flex; flex-direction: column; gap: 10px; }
.source-list > li { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--raised); }
.source-title { font-weight: 600; line-height: 1.4; }
.source-meta { display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 2px; }
.method { border-radius: 999px; padding: 0 7px; font-size: 12px; }
.method-link { background: var(--ok-bg); color: #24622a; }
.method-rss { background: var(--info-bg); color: #1d4d86; }
.source-body { margin-top: 6px; }
.article-text { max-height: 420px; overflow-y: auto; margin: 6px 0; padding: 4px 12px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 6px; font-size: 14px; line-height: 1.65; }
.article-text p { margin: 8px 0; }
.source-none { margin: 6px 0 0; }
.chip.muted-chip { background: var(--g-other-bg); color: var(--muted); border-color: transparent; }
.non-news-section { margin-top: 16px; }
.non-news-section > summary { cursor: pointer; padding: 8px 0; }

/* Media ranking */
.ranking td { vertical-align: middle; }
.ranking .page-cell { display: flex; align-items: center; gap: 10px; }
.ranking .page-cell .avatar-wrap { width: 30px; height: 30px; font-size: 13px; }
.ranking tr.quiet { color: var(--muted); }
.ranking tr.quiet .avatar-wrap { opacity: .5; }
.ranking .share-cell { min-width: 170px; }
/* Sticky # and Page columns, so a narrow screen can scroll the numbers and still see whose row it is */
.ranking .sticky-1, .ranking .sticky-2 { position: sticky; background: var(--surface); z-index: 1; }
.ranking .sticky-1 { left: 0; width: 56px; min-width: 56px; }
.ranking .sticky-2 { left: 56px; box-shadow: inset -1px 0 0 var(--line); }
.ranking .rank-cell { white-space: nowrap; }
.ranking tbody.rank-row:not(.quiet) tr.main { cursor: pointer; }
.ranking tbody.rank-row:not(.quiet) tr.main:hover td { background: var(--raised); }
.ranking tbody.rank-row.open tr.main td { border-bottom-color: transparent; background: var(--raised); }
.row-toggle { background: none; color: var(--muted); padding: 0 4px 0 0; font-weight: 400; font-size: 12px; }
.row-toggle::before { content: "▸"; display: inline-block; transition: transform .15s; }
.row-toggle[aria-expanded="true"]::before { transform: rotate(90deg); }
.ranking tr.detail td { background: var(--raised); padding: 4px 16px 14px 56px; }
.detail-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; max-width: 980px;
  position: sticky; left: 56px; }
.detail-label { font-weight: 600; font-size: 13px; margin-bottom: 4px; }
.detail-topics { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
.detail-topics a { color: var(--text); text-decoration: none; }
.detail-topics a:hover { color: var(--accent); text-decoration: underline; }
.share-bar { display: block; height: 8px; background: var(--bg); border-radius: 999px; overflow: hidden; margin-bottom: 4px; }
.share-bar span { display: block; height: 100%; background: var(--g); border-radius: 999px; }
th .sort { background: none; color: var(--muted); padding: 0; font: inherit; font-weight: 600; font-size: 12px; }
th .sort.active { color: var(--text); }
th .sort.active::after { content: " ↓"; }
th .sort:hover { color: var(--text); }

/* Section heads with a hidden note: hover on a mouse, tap anywhere */
.section-head { position: relative; display: flex; align-items: center; gap: 8px; margin: 44px 0 14px; scroll-margin-top: 64px; }
.section-head h2 { margin: 0; }
.section-head h2 .count { font-size: var(--fs-meta); font-weight: 400; }
.filter-bar + .section-head { margin-top: 24px; }
.info-btn { width: 20px; height: 20px; padding: 0; border-radius: 50%; font: italic 700 12px/1 Georgia, serif;
  background: var(--surface); color: var(--muted); border: 1px solid var(--line); }
.info-box.open .info-btn, .info-btn:hover { background: var(--text); color: var(--surface); border-color: var(--text); }
.info-pop { display: none; position: absolute; left: 0; top: calc(100% + 8px); z-index: 5; width: min(460px, 100%);
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, .12); font-size: 14px; line-height: 1.5; }
.info-pop.wide { width: min(620px, 100%); }
.info-pop::before { content: ""; position: absolute; left: 0; right: 0; top: -10px; height: 10px; } /* hover bridge */
.info-pop p { margin: 0 0 10px; }
.info-pop dl { margin: 0 0 10px; display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; }
.info-pop dt { font-weight: 600; font-size: 13px; }
.info-pop dd { margin: 0; color: var(--muted); font-size: 13px; }
.info-pop > :last-child { margin-bottom: 0; }
.info-box.open .info-pop { display: block; }
@media (hover: hover) { .info-box:hover .info-pop { display: block; } }
.ai-note { background: var(--g-credibility-bg); border-radius: 8px; padding: 8px 10px; font-size: 13px; }
.ai-badge { display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: .04em; padding: 1px 6px; margin-right: 4px;
  border-radius: 4px; background: var(--g-credibility); color: #fff; vertical-align: 1px; }

/* Showing window: the date and time are the heading */
.window-bar { display: flex; flex-direction: column; gap: 6px; scroll-margin-top: 64px; padding: 18px 22px; }
.window-time { display: flex; align-items: center; gap: 8px 16px; flex-wrap: wrap; font-size: var(--fs-h2); line-height: 1.3; }
.window-time strong { font-weight: 600; }
.window-range { font-weight: 700; letter-spacing: -0.01em; }
.window-range .small { letter-spacing: 0; }
/* Posts over time: inside the window bar, the window drawn as a chart */
.timeline { margin: 14px 0 2px; padding-top: 14px; border-top: 1px solid var(--line); }
.timeline-head { display: flex; align-items: baseline; justify-content: space-between; gap: 6px 20px; flex-wrap: wrap; margin-bottom: 4px; }
.timeline-head h3 { margin: 0; font-size: var(--fs-body); font-weight: 600; }
.timeline-legend { display: flex; flex-wrap: wrap; gap: 4px 16px; list-style: none; margin: 0; padding: 0; color: var(--muted); }
.timeline-legend li { display: inline-flex; align-items: center; gap: 6px; }
.key-dot { width: 8px; height: 8px; border-radius: 50%; background: #c3c7cf; }
.key-dot.own { width: 9px; height: 9px; background: var(--g-own); }
.key-ramp { display: inline-flex; gap: 2px; }
.key-dot.hot { width: 10px; height: 10px; box-shadow: inset 0 0 0 1px var(--heat-3); }
.key-dot.hot.heat-1 { background: var(--heat-1); } .key-dot.hot.heat-2 { background: var(--heat-2); }
.key-dot.hot.heat-3 { background: var(--heat-3); }
.key-rank { display: inline-flex; align-items: center; justify-content: center; width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid var(--heat-3); background: var(--surface); color: var(--text); font-size: 11px; font-weight: 700; }
.timeline-scroll { position: relative; overflow-x: auto; }
.timeline-chart { display: block; width: 100%; min-width: 640px; height: auto; overflow: visible; }
.timeline-grid line { stroke: var(--line); stroke-width: 1; }
.timeline-grid line.hour { stroke-dasharray: 2 4; }
.timeline-grid text { fill: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.timeline-grid text.unit { font-size: 11px; }
.timeline-chart .dot { fill: #c3c7cf; stroke: var(--surface); stroke-width: 1.5; transition: r .15s ease-out; }
.timeline-chart .dot.own { fill: var(--g-own); }
.timeline-chart .dot.hot { fill: var(--heat); stroke: var(--heat-3); stroke-width: 1; }
.timeline-chart .dot.hot.own { stroke: var(--g-own); stroke-width: 2; }
.timeline-chart .dot:hover { r: 7; }
.timeline-chart .heat-1 { --heat: var(--heat-1); } .timeline-chart .heat-2 { --heat: var(--heat-2); }
.timeline-chart .heat-3 { --heat: var(--heat-3); } .timeline-chart .heat-0 { --heat: var(--heat-0); }
.timeline-chart .lead { cursor: pointer; outline: none; }
.timeline-chart .lead .hit { fill: transparent; }
.timeline-chart .lead .leader { stroke: var(--heat); stroke-width: 1.5; }
.timeline-chart .lead .ring { fill: var(--surface); stroke: var(--heat); stroke-width: 2.5; transition: r .15s ease-out, fill .15s ease-out; }
.timeline-chart .lead text { fill: var(--text); font-size: 11px; font-weight: 700; pointer-events: none; font-variant-numeric: tabular-nums; }
.timeline-chart .lead:hover .ring, .timeline-chart .lead:focus-visible .ring { r: 11; fill: var(--heat); }
.timeline-tip { position: absolute; z-index: 3; pointer-events: none; max-width: 300px; padding: 8px 10px; border-radius: 8px;
  background: var(--ink); color: var(--ink-text); font-size: var(--fs-sm); line-height: 1.45; white-space: pre-line;
  box-shadow: 0 6px 20px rgba(18, 23, 34, .18); }
.timeline-tip strong { display: block; font-size: var(--fs-meta); }
.timeline figcaption { margin-top: 6px; }

/* Day navigation in the window bar */
.all-runs { margin-left: auto; font-size: var(--fs-sm); white-space: nowrap; align-self: center; }
.day-step { display: inline-flex; align-items: center; gap: 8px; }
.step-btn { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; border: 1px solid var(--line);
  border-radius: 8px; background: var(--surface); color: var(--text); text-decoration: none; font-size: 18px; line-height: 1; }
a.step-btn:hover { border-color: var(--accent); color: var(--accent); }
.step-btn.disabled { color: var(--line); }
.day-runs { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); }
.run-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.run-chip { display: inline-flex; align-items: center; padding: 3px 10px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); color: var(--text); font-size: 13px; text-decoration: none; white-space: nowrap; font-variant-numeric: tabular-nums; }
a.run-chip:hover { border-color: var(--accent); color: var(--accent); }
.run-chip.current { background: var(--text); border-color: var(--text); color: var(--surface); font-weight: 600; }

/* Run history */
.history-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.close-btn { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px; border: 1px solid var(--line);
  border-radius: 8px; background: var(--surface); color: var(--text); text-decoration: none; font-size: 14px; white-space: nowrap; }
.close-btn:hover { border-color: var(--accent); color: var(--accent); }
.showing-badge { display: inline-block; padding: 0 7px; border-radius: 999px; background: var(--accent); color: #fff;
  font-size: 11px; font-weight: 700; letter-spacing: .03em; vertical-align: 1px; }
.history-current { margin: 0 0 4px; color: var(--muted); }
.history-tools { display: flex; justify-content: space-between; gap: 8px 16px; flex-wrap: wrap; margin: 8px 0 4px; }
.history-month { margin: 24px 0 8px; }
.history-day { padding: 10px 14px; margin-bottom: 10px; }
.history-day h3 { margin: 0 0 4px; font-size: 15px; }
.run-list { list-style: none; margin: 0; padding: 0; }
.run-list > li + li { border-top: 1px solid var(--line); }
.run-row { display: grid; grid-template-columns: 110px 190px minmax(0, 1fr) auto 120px; gap: 4px 14px; align-items: baseline;
  padding: 8px 6px; margin: 0 -6px; border-radius: 6px; color: var(--text); text-decoration: none; }
.run-row:hover { background: var(--bg); }
.run-row:hover .run-top { color: var(--accent); }
.run-row.empty { opacity: .6; }
.run-row.current { background: var(--info-bg); box-shadow: inset 3px 0 0 var(--accent); }
.run-row { scroll-margin-top: 80px; }
.run-time { font-weight: 600; font-variant-numeric: tabular-nums; }
.run-stats { white-space: nowrap; }
.run-top { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.run-at { text-align: right; white-space: nowrap; }
.method-err { background: var(--error-bg); color: var(--hot-text); }
.earlier { margin: 0 0 6px 0; }
.earlier summary { color: var(--accent); cursor: pointer; padding: 0 0 4px; }
.run-list.nested { padding-left: 14px; border-left: 2px solid var(--line); }
.pager { display: flex; justify-content: space-between; align-items: center; margin: 16px 0; }
.form-hint { align-self: center; color: var(--hot-text); background: var(--hot-bg); padding: 4px 10px; border-radius: 6px; }

/* Jump links in the sticky filter bar */
.jump { margin-left: auto; display: flex; align-items: center; gap: 14px; font-size: 13px; white-space: nowrap; }
.jump a { color: var(--muted); text-decoration: none; }
.jump a:hover { color: var(--text); }
.jump .window-chip { color: var(--accent); font-weight: 600; font-variant-numeric: tabular-nums; }

.show-all { margin-top: 10px; }
.post-link { color: var(--text); text-decoration: none; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.post-link:hover { color: var(--accent); text-decoration: underline; }
.breakdown { border-bottom: 1px dotted var(--muted); cursor: help; }

/* Run Analysis progress */
.progress { display: flex; flex-direction: column; gap: 12px; }
.progress-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.steps li { display: grid; grid-template-columns: 22px auto 1fr; align-items: center; gap: 4px 10px; color: var(--muted); }
.steps li::before { content: ""; width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--line); box-sizing: border-box; }
.steps li.active { color: var(--text); font-weight: 600; }
.steps li.active::before { border-color: var(--accent); border-right-color: transparent; animation: spin .8s linear infinite; }
.steps li.done { color: var(--text); }
.steps li.done::before { content: "✓"; border: 0; color: var(--g-business); font-weight: 700; width: auto; height: auto; }
.steps li.failed::before { content: "✕"; border: 0; color: var(--hot-text); font-weight: 700; width: auto; height: auto; }
.steps .small { font-weight: 400; }
.steps .bar { grid-column: 2 / -1; height: 6px; background: var(--bg); border-radius: 999px; overflow: hidden; }
.steps .bar span { display: block; height: 100%; background: var(--accent); transition: width .3s; }
@keyframes spin { to { transform: rotate(360deg); } }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { font-size: var(--fs-sm); padding: 1px 9px; border-radius: 999px; background: var(--bg); border: 1px solid transparent; color: #3d4149; }
.chip.hot { background: var(--hot-bg); color: var(--hot-text); border-color: transparent; font-weight: 600; }
.topic-posts { list-style: none; padding: 0; margin: 8px 0 0; }
.topic-posts .page { display: flex; align-items: baseline; }
.topic-posts li { display: grid; grid-template-columns: 48px 160px 1fr auto; gap: 10px; padding: 6px 0; border-top: 1px solid var(--line); font-size: 14px; }
.topic-posts .time { color: var(--muted); }

.table-wrap { overflow-x: auto; padding: 0; }
.users-table form.inline { gap: 6px; }
.users-table td { vertical-align: middle; }
.row-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.row-actions form { margin: 0; }
/* Inline field check (Users page), replacing the browser's validation bubble */
input.is-invalid { border-color: #c4321c; box-shadow: 0 0 0 3px rgba(196, 50, 28, .12); }
input.is-invalid:focus-visible { outline-color: #c4321c; }
.field-error { display: flex; align-items: center; gap: 6px; color: var(--hot-text); font-size: 12px; font-weight: 500; line-height: 1.4; }
.field-error::before { content: "!"; flex: none; display: inline-flex; align-items: center; justify-content: center;
  width: 14px; height: 14px; border-radius: 50%; background: #c4321c; color: #fff; font-size: 10px; font-weight: 700; }
button.danger { background: #c4321c; color: #fff; }
button.danger:hover:not(:disabled) { background: #a3291a; box-shadow: 0 1px 3px rgba(196, 50, 28, .35); }
/* Status: a filled badge, so active and disabled read apart at a glance */
.status-badge { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.status-badge.active { background: var(--ok-bg); color: #24622a; }
.status-badge.disabled { background: #e6e7ea; color: #4a4e56; }
/* Disabled user: the row recedes and the role is struck through (it grants nothing until enabled); Enable stays full colour */
.is-disabled .user-row { background: var(--raised); }
.is-disabled .user-row td { color: var(--muted); }
.is-disabled .user-name { font-weight: 500; }
.is-disabled .user-role { text-decoration: line-through; }
/* Edit panel under its row */
.edit-row td { background: var(--raised); padding: 0; }
.edit-panel { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px 20px; padding: 14px 16px 16px; }
.edit-field { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; margin: 0; }
.edit-field label, .edit-field .field-label { display: flex; flex-direction: column; gap: 4px; margin: 0; font-size: 13px; font-weight: 600; width: 100%; }
.edit-field input, .edit-field select { width: 100%; max-width: 260px; font-weight: 400; }
.edit-field p { margin: 0; }
/* Delete sits apart, as a full-width strip at the bottom of the panel */
.edit-field.delete-form { grid-column: 1 / -1; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px 12px;
  border-top: 1px solid var(--line); padding-top: 12px; }
.delete-form .field-label { width: auto; }
/* Phone: each user is a stacked card instead of a table row, so Edit and Disable stay on screen */
@media (max-width: 640px) {
  .users-table thead { display: none; }
  .users-table, .users-table tbody, .users-table tr, .users-table td { display: block; }
  .users-table tbody.user-group { border-bottom: 1px solid var(--line); }
  .users-table tbody.user-group:last-child { border-bottom: 0; }
  .users-table tr:not(.edit-row) { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 12px 14px; }
  .users-table tr:not(.edit-row) td { border: 0; padding: 0; }
  .users-table tr:not(.edit-row) td:nth-child(1) { grid-column: 1; }
  .users-table tr:not(.edit-row) td:nth-child(2) { grid-column: 1; grid-row: 2; font-size: 13px; }
  .users-table tr:not(.edit-row) td:nth-child(3) { grid-column: 2; grid-row: 1; justify-self: end; }
  .users-table tr:not(.edit-row) td:nth-child(4) { grid-column: 2; grid-row: 2; justify-self: end; font-size: 12px; color: var(--muted); }
  .users-table tr:not(.edit-row) td:nth-child(5) { grid-column: 1 / -1; margin-top: 6px; }
  .users-table .edit-row[hidden] { display: none; }
  .users-table .edit-row td { border-bottom: 0; }
  .edit-panel { grid-template-columns: 1fr; }
  .edit-field input, .edit-field select { max-width: none; }
}
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12px; white-space: nowrap; }
td.num, th.num { text-align: right; white-space: nowrap; }
td.excerpt { max-width: 360px; }
.post-thumb { float: left; width: 48px; height: 48px; object-fit: cover; border-radius: 4px; margin: 2px 8px 2px 0; }

@media (max-width: 640px) {
  main, .topbar, footer { padding-left: 16px; padding-right: 16px; }
  .topbar .main-nav { order: 3; flex-basis: 100%; margin-left: 0; }
  .account { margin-left: auto; }
  .account-name { display: none; }
  .topic-posts li { grid-template-columns: auto minmax(0, 1fr); gap: 2px 10px; padding: 10px 0; }
  .topic-posts .excerpt, .topic-posts li > a { grid-column: 1 / -1; }
  .topic { grid-template-columns: 26px minmax(0, 1fr); gap: 0 12px; padding: 16px; }
  .topic .rank { font-size: var(--fs-headline); }
  .topic .label { font-size: var(--fs-lead); }
  .topic-thumb { width: 76px; }
  .window-bar { padding: 14px 16px; }
  .all-runs { margin-left: 0; }
  .filter-bar { flex-wrap: nowrap; overflow-x: auto; margin-left: -16px; margin-right: -16px; padding: 10px 16px; }
  .chip-btn { white-space: nowrap; flex: none; }
  .avatar-wrap.large { width: 40px; height: 40px; font-size: 16px; }
  .jump { margin-left: 8px; }
  /* Narrow sticky columns on a phone: the group shows as the avatar ring colour */
  .ranking .sticky-1 { width: 44px; min-width: 44px; padding-left: 6px; padding-right: 4px; }
  .ranking .sticky-2 { left: 44px; white-space: normal; min-width: 128px; max-width: 140px; padding-right: 8px; }
  .ranking .page-cell { gap: 8px; line-height: 1.3; }
  .ranking .page-cell .avatar-wrap { width: 24px; height: 24px; font-size: 11px; }
  .ranking .page-cell .muted.small { display: none; }
  .ranking .page-cell br { display: none; }
  .detail-grid { grid-template-columns: 1fr; max-width: calc(100vw - 100px); }
  .ranking tr.detail td { padding-left: 12px; }
  .detail-grid { left: 12px; }
  .info-pop dl { grid-template-columns: 1fr; gap: 2px; }
  .info-pop dd { margin-bottom: 6px; }
  .window-time { font-size: 18px; }
  .run-row { grid-template-columns: 1fr auto; }
  .close-btn span { display: none; }
  .run-time { order: 1; }
  .run-at { order: 2; }
  .run-top { order: 3; grid-column: 1 / -1; white-space: normal; }
  .run-stats { order: 4; }
  .run-sources { order: 5; text-align: right; }
}

/* Motion: state changes only, short and eased out */
details[open] > :not(summary) { animation: reveal .2s cubic-bezier(.16, 1, .3, 1); }
@keyframes reveal { from { opacity: 0; transform: translateY(-4px); } }
/* After the reader changes the group filter, rows that come back fade in (never on page load) */
.filtered .topic, .filtered tbody.rank-row { transition: opacity .22s cubic-bezier(.16, 1, .3, 1), background-color .2s ease-out; }
@starting-style { .filtered .topic, .filtered tbody.rank-row { opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
