:root {
  --bg: #f6f5f1; --panel: #ffffff; --ink: #1d1d1b; --muted: #5f5d57; --line: #dcd9d0;
  --accent: #8a4b14; --accent-ink: #ffffff; --chip: #ecebe5; --chip-on: #1d1d1b; --chip-on-ink: #ffffff;
  --ok: #2f6b33; --warn: #8a5a00; --bad: #a12a1c; --heis: #23527c; --focus: #1a5fb4;
  --radius: 8px; --gap: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161614; --panel: #201f1c; --ink: #eeece6; --muted: #aba89f; --line: #3a3833;
    --accent: #e0a060; --accent-ink: #161614; --chip: #2c2b27; --chip-on: #eeece6; --chip-on-ink: #161614;
    --ok: #7fc185; --warn: #e3b552; --bad: #f08a7a; --heis: #8ab8e6; --focus: #8ab8e6;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 6px 12px; min-height: 36px; }
button:hover { border-color: var(--muted); }
input, select { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 6px 10px; min-height: 36px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.error { color: var(--bad); min-height: 1.5em; }

.sketch { background: #fff3cd; color: #5c4400; text-align: center; font-size: 12px; padding: 2px 16px; }
@media (prefers-color-scheme: dark) { .sketch { background: #3d3214; color: #f3dc9a; } }

.login { max-width: 360px; margin: 10vh auto; padding: 0 16px; }
.login form { display: grid; gap: 8px; }
.login button { background: var(--accent); color: var(--accent-ink); border: none; margin-top: 8px; }

.top { position: sticky; top: 0; z-index: 5; display: flex; gap: 8px; align-items: center;
  padding: 8px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; margin-right: 4px; white-space: nowrap; }
.health { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.health.ok { color: var(--ok); } .health.warn { color: var(--warn); } .health.bad { color: var(--bad); }
.menu { margin-left: auto; position: relative; }
.menu summary { list-style: none; cursor: pointer; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 6px 12px; min-height: 36px; display: flex; align-items: center; background: var(--panel); }
.menu summary::-webkit-details-marker { display: none; }
.menu summary::after { content: " ▾"; white-space: pre; }
.menu-body { position: absolute; right: 0; top: calc(100% + 6px); z-index: 6; display: grid; gap: 8px; width: 240px;
  padding: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 6px 24px rgba(0, 0, 0, .18); }
.menu-body p { margin: 0; font-size: 14px; }
.menu-body button { text-align: left; }
button.link { all: unset; cursor: pointer; color: var(--accent); font-size: 14px; }
button.link:focus-visible { outline: 3px solid var(--focus); }

.panel { margin: 12px 16px; padding: 12px 16px; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); }
.panel h2 { margin: 0 0 8px; font-size: 16px; }
.health-list, .paid-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.health-list li { display: grid; grid-template-columns: 160px 90px 1fr; gap: 8px; font-size: 14px; }
.state-ok { color: var(--ok); } .state-stale, .state-skipped, .state-not_run { color: var(--warn); }
.state-failing, .state-never_ok, .state-refused { color: var(--bad); }
.paid-list li { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.filters { display: grid; gap: 8px; padding: 12px 16px; }
.filters input[type=search] { width: 100%; }
.selects { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.field { display: grid; gap: 2px; font-size: 12px; color: var(--muted); }
.field select { width: 100%; color: var(--ink); font-size: 15px; }
.field select.on { border-color: var(--accent); }
#clear-btn { justify-self: start; }

.layout { display: grid; grid-template-columns: 1fr; gap: var(--gap); padding: 0 16px 16px; }
@media (min-width: 1000px) {
  .layout { grid-template-columns: minmax(0, 1fr) 320px; }
  .layout.with-detail { grid-template-columns: minmax(0, 1fr) 420px; }
  .layout.with-detail .context { display: none; }
  .context { position: sticky; top: 70px; max-height: calc(100vh - 90px); overflow: auto; }
}
@media (max-width: 999px) { .context { order: -1; } }
.context { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px;
  align-self: start; }
.context summary { font-weight: 600; cursor: pointer; }
.small { font-size: 13px; margin: 4px 0 8px; }
.context-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.context-list li { border-top: 1px solid var(--line); padding-top: 8px; }
.context-list .title-btn { font-size: 14px; line-height: 1.35; display: block; }
.feed { display: grid; gap: var(--gap); align-content: start; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.card.heis { border-left: 4px solid var(--heis); }
.card .meta { display: flex; flex-wrap: wrap; gap: 10px; font-size: 13px; color: var(--muted); }
.card .source { font-weight: 600; color: var(--ink); }
.badge { color: var(--heis); font-weight: 600; }
.card h3 { margin: 6px 0 4px; font-size: 16px; line-height: 1.35; }
.title-btn { all: unset; cursor: pointer; }
.title-btn:hover { text-decoration: underline; }
.title-btn:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.excerpt { margin: 0 0 6px; color: var(--ink); white-space: pre-line; overflow-wrap: anywhere; }
.tags { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 6px; }
.tag { font-size: 12px; background: var(--chip); border-radius: 999px; padding: 0 8px; }
.orig { font-size: 13px; color: var(--accent); }
.empty { padding: 24px; text-align: center; color: var(--muted); background: var(--panel); border-radius: var(--radius);
  border: 1px dashed var(--line); }
.more { display: block; margin: 0 auto 24px; }

.detail { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px;
  align-self: start; position: sticky; top: 70px; max-height: calc(100vh - 90px); overflow: auto; }
.detail h2 { font-size: 17px; margin: 4px 0 8px; }
.detail .body { white-space: pre-line; overflow-wrap: anywhere; }
.detail .caveat { font-size: 13px; color: var(--heis); }
.detail .sub { font-size: 14px; margin: 14px 0 4px; }
.detail .transcript { font-size: 14px; color: var(--muted); }
.detail .attribution { font-size: 12px; color: var(--muted); }
.detail form { display: grid; gap: 8px; margin-top: 12px; border-top: 1px solid var(--line); padding-top: 12px; }
.detail textarea { font: inherit; min-height: 80px; padding: 8px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--bg); color: var(--ink); }
.detail fieldset { border: 1px solid var(--line); border-radius: var(--radius); }
.detail .save { background: var(--accent); color: var(--accent-ink); border: none; }
.metrics { font-size: 13px; color: var(--muted); }

.picks { padding: 12px 16px 24px; }
.picks ul { list-style: none; padding: 0; display: grid; gap: var(--gap); }
.picks li { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.picks textarea { width: 100%; min-height: 60px; font: inherit; }

dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); color: var(--ink);
  max-width: 420px; }
dialog menu { display: flex; gap: 8px; justify-content: flex-end; padding: 0; }
#confirm-ok { background: var(--accent); color: var(--accent-ink); border: none; }

.detail-bar { display: flex; justify-content: flex-end; }
@media (max-width: 999px) {
  /* The detail covers the screen and scrolls on its own; the page behind it stays put. */
  .detail { position: fixed; inset: 0; height: 100vh; height: 100dvh; max-height: none; align-self: stretch;
    overflow-y: auto; overscroll-behavior: contain; border: 0; border-radius: 0; z-index: 10; padding-top: 0; }
  .detail-bar { position: sticky; top: 0; background: var(--panel); padding: 10px 0; margin: 0 -16px 0; padding-right: 16px;
    border-bottom: 1px solid var(--line); z-index: 1; }
  .detail .close { float: none; }
  body.detail-open { overflow: hidden; }
}
@media (max-width: 600px) {
  .top { padding: 8px 12px; }
  .filters { padding: 10px 12px; }
  .layout { padding: 0 12px 16px; }
  .selects { grid-template-columns: 1fr 1fr; }
  .health-list li { grid-template-columns: 1fr 80px; }
  .health-list li .msg { grid-column: 1 / -1; }
}
