:root {
  --bg: #0e1116;
  --bg-elev: #161b22;
  --bg-elev-2: #1c232c;
  --border: #2a313c;
  --border-soft: #222932;
  --text: #e6edf3;
  --text-dim: #9aa7b4;
  --text-faint: #6b7682;
  --accent: #3b82f6;
  --accent-hover: #2f6fe0;
  --green: #2ea043;
  --green-soft: #1c6b2c;
  --amber: #d29922;
  --red: #e5534b;
  --red-hover: #c93c34;
  --purple: #8957e5;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
  --mono: "Cascadia Code", "JetBrains Mono", Consolas, "Courier New", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
html { scroll-padding-top: 110px; }
:focus-visible { outline: 2px solid #8bb8ff; outline-offset: 3px; }
button, a, summary { touch-action: manipulation; }
body.modal-open { overflow: hidden; }

/* ---------- Buttons ---------- */
.btn {
  font: inherit;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--bg-elev-2);
  color: var(--text);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .15s, border-color .15s, opacity .15s, transform .05s;
  white-space: nowrap;
}
.btn:hover { background: #232c37; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: transparent; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { background: var(--red); border-color: transparent; color: #fff; }
.btn-danger:hover { background: var(--red-hover); }
.btn-ghost { background: transparent; }
.btn-ghost:hover { background: var(--bg-elev-2); }
.btn-block { width: 100%; display: block; }
.btn-sm { padding: 5px 10px; font-size: 13px; }

/* ---------- Overlays / modal ---------- */
.overlay {
  position: fixed; inset: 0;
  background: rgba(6, 9, 13, 0.72);
  backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
  z-index: 50; padding: 20px;
}
.login-card, .modal {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 100%; max-width: 360px;
  padding: 28px 26px;
}
.login-title { margin: 0 0 4px; font-size: 22px; }
.login-sub { margin: 0 0 18px; color: var(--text-dim); font-size: 14px; }
.login-card input {
  width: 100%; margin-bottom: 14px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 10px 12px; font: inherit;
}
.login-card input:focus { outline: none; border-color: var(--accent); }
.login-error { color: var(--red); font-size: 13px; margin: 12px 0 0; }

.modal { max-width: 440px; }
.modal h2 { margin: 0 0 10px; font-size: 18px; }
.modal p { color: var(--text-dim); margin: 0 0 20px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* ---------- File editor ---------- */
.editor-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 100%; max-width: 860px; height: 82vh;
  display: flex; flex-direction: column;
  padding: 20px 22px;
}
.editor-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.editor-head h2 { margin: 0; font-size: 18px; }
.editor-desc { color: var(--text-dim); font-size: 12.5px; margin: 6px 0 0; line-height: 1.45; }
.editor-text {
  flex: 1; margin: 14px 0;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-family: var(--mono); font-size: 13px; line-height: 1.55;
  padding: 12px 14px; resize: none; white-space: pre; overflow: auto;
  tab-size: 4;
}
.editor-text:focus { outline: none; border-color: var(--accent); }
.editor-head-actions { display: flex; gap: 8px; flex-shrink: 0; }

/* Structured (form) view of the search-terms file */
.editor-form { flex: 1; margin: 14px 0; display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.terms-scroll {
  flex: 1; overflow: auto;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg);
}
.terms-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.terms-table th {
  position: sticky; top: 0; z-index: 1;
  background: var(--bg-elev-2); text-align: left;
  color: var(--text-faint); font-weight: 600;
  text-transform: uppercase; letter-spacing: .05em; font-size: 11px;
  padding: 8px 10px; border-bottom: 1px solid var(--border);
}
.terms-table td { padding: 3px 6px; border-bottom: 1px solid var(--border-soft); }
.terms-table td:nth-child(1) { width: 30%; }
.terms-table td:nth-child(3) { width: 200px; }
.terms-table td:nth-child(4) { width: 76px; text-align: right; }
.terms-table input, .terms-table select {
  width: 100%; font: inherit; font-size: 13px;
  background: transparent; color: var(--text);
  border: 1px solid transparent; border-radius: 6px; padding: 6px 8px;
}
.terms-table select { background: var(--bg); }
.terms-table input:hover, .terms-table select:hover { border-color: var(--border); }
.terms-table input:focus, .terms-table select:focus {
  outline: none; border-color: var(--accent); background: var(--bg-elev);
}
.terms-remove {
  background: none; border: none; color: var(--red); cursor: pointer;
  font: inherit; font-size: 12px; padding: 4px 6px;
}
.terms-remove:hover { text-decoration: underline; }
#termsAdd { align-self: flex-start; }

.editor-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.editor-status { color: var(--text-dim); font-size: 13px; }
.editor-status.ok { color: #a6e3b4; }
.editor-status.err { color: #f0a8a3; }
.editor-actions { display: flex; gap: 10px; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 22px;
  background: rgba(14, 17, 22, 0.85);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border-soft);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; }
.brand-mark { font-size: 20px; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
/* Phones: the header's eight controls were 522 px wide on a 390 px screen, which made
   the browser lay EVERY page out wider than the screen (the review panel ended up
   offset and cut off on the right). Wrap them into compact rows instead. */
@media (max-width: 600px) {
  .topbar { padding: 8px 10px; gap: 6px; }
  .topbar-right { flex: 1; min-width: 0; flex-wrap: wrap; justify-content: flex-end; gap: 4px; }
  .topbar-right .btn { padding: 6px 9px; font-size: 13px; }
  .stash-link { padding: 5px 8px; font-size: 12.5px; }
}
.stash-link {
  color: var(--text-dim); text-decoration: none; font-size: 13px;
  padding: 6px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.stash-link:hover { color: var(--text); border-color: var(--accent); }

/* ---------- Layout ---------- */
.container { max-width: 1100px; margin: 0 auto; padding: 26px 22px 90px; }
.loading { color: var(--text-dim); padding: 40px 0; text-align: center; }

.group-title {
  font-size: 13px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--text-faint); margin: 26px 4px 12px;
}
.group-title:first-child { margin-top: 4px; }

.grid {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
}

/* ---------- Task card ---------- */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 18px;
  display: flex; flex-direction: column;
  transition: border-color .15s, transform .08s;
}
.card:hover { border-color: var(--border); }
.card.running { border-color: var(--accent); }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.card-name { font-size: 16px; font-weight: 700; margin: 0; }
.card-desc { color: var(--text-dim); font-size: 13.5px; margin: 8px 0 14px; flex: 1; }

.card-tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 14px; }
.tag {
  font-size: 11px; font-weight: 600; letter-spacing: .03em;
  padding: 3px 8px; border-radius: 999px;
  border: 1px solid var(--border); color: var(--text-dim);
}
.tag.danger { color: #f0a8a3; border-color: #5a2c2a; background: rgba(229, 83, 75, .08); }
.tag.long { color: #e9cf8d; border-color: #5a4a22; background: rgba(210, 153, 34, .08); }
.tag.info { color: #a9c6ff; border-color: #2c3f63; background: rgba(59, 130, 246, .08); }

.card-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: auto; }
.card-actions { display: flex; gap: 8px; }
.card-status { display: flex; align-items: center; gap: 8px; min-height: 24px; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600;
  padding: 4px 10px; border-radius: 999px;
  border: 1px solid var(--border); color: var(--text-dim);
  background: var(--bg-elev-2);
}
.badge::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-faint);
}
.badge.running { color: #bcd4ff; border-color: #2c3f63; }
.badge.running::before { background: var(--accent); animation: pulse 1.1s infinite; }
.badge.completed { color: #a6e3b4; border-color: var(--green-soft); }
.badge.completed::before { background: var(--green); }
.badge.failed, .badge.interrupted { color: #f0a8a3; border-color: #5a2c2a; }
.badge.failed::before, .badge.interrupted::before { background: var(--red); }
.badge.stopped { color: #e9cf8d; border-color: #5a4a22; }
.badge.stopped::before { background: var(--amber); }

@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }

.last-meta { font-size: 12px; color: var(--text-faint); }
.link-btn {
  background: none; border: none; color: var(--accent); cursor: pointer;
  font: inherit; font-size: 12px; padding: 0; text-decoration: underline;
}

/* ---------- Console drawer ---------- */
.console {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  height: 46vh; min-height: 240px;
  background: var(--bg-elev);
  border-top: 1px solid var(--border);
  box-shadow: 0 -10px 30px rgba(0,0,0,.45);
  display: flex; flex-direction: column;
  animation: slideUp .18s ease-out;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.console-head {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 16px; border-bottom: 1px solid var(--border-soft);
}
.console-title { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.console-progress { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 160px; max-width: 360px; }
.console-progress .bar { flex: 1; height: 7px; background: var(--bg); border-radius: 999px; overflow: hidden; }
.console-progress .bar-fill { height: 100%; width: 0; background: var(--accent); transition: width .3s; }
#consoleProgressPct { font-size: 12px; color: var(--text-dim); min-width: 38px; text-align: right; }
.console-actions { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.follow { font-size: 12px; color: var(--text-dim); display: flex; align-items: center; gap: 5px; cursor: pointer; }
.console-body {
  margin: 0; padding: 14px 16px; overflow: auto; flex: 1;
  font-family: var(--mono); font-size: 12.5px; line-height: 1.5;
  color: #cbd5e1; white-space: pre-wrap; word-break: break-word;
}
.console-body:empty::before { content: "Waiting for output\2026"; color: var(--text-faint); }

/* ---------- Health strip ---------- */
.health-strip {
  max-width: 1100px; margin: 0 auto; padding: 12px 22px 0;
  display: flex; flex-wrap: wrap; gap: 8px;
}
.health-chip {
  font-size: 12px; font-weight: 600;
  padding: 5px 12px; border-radius: 999px;
  border: 1px solid var(--border); color: var(--text-dim);
  background: var(--bg-elev-2);
  display: inline-flex; align-items: center; gap: 6px;
}
.health-chip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--text-faint); }
.health-chip.ok   { color: #a6e3b4; border-color: var(--green-soft); }
.health-chip.ok::before   { background: var(--green); }
.health-chip.warn { color: #e9cf8d; border-color: #5a4a22; }
.health-chip.warn::before { background: var(--amber); }
.health-chip.err  { color: #f0a8a3; border-color: #5a2c2a; }
.health-chip.err::before  { background: var(--red); }
/* Second chip row (archive inbox) sits tight under the health strip. */
.archive-strip { padding-top: 8px; }

/* ---------- Recent runs ---------- */
.history { max-width: 1100px; margin: 0 auto; padding: 0 22px 40px; }
.history-toggle {
  background: none; border: none; color: var(--text-dim); cursor: pointer;
  font: inherit; font-size: 13px; font-weight: 600; padding: 6px 0;
}
.history-toggle:hover { color: var(--text); }
.history-body { margin-top: 8px; overflow-x: auto; }
.history-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.history-table th {
  text-align: left; color: var(--text-faint); font-weight: 600;
  text-transform: uppercase; letter-spacing: .05em; font-size: 11px;
  padding: 6px 12px; border-bottom: 1px solid var(--border-soft);
}
.history-table td { padding: 8px 12px; border-bottom: 1px solid var(--border-soft); }
.history-table tbody tr { cursor: pointer; }
.history-table tbody tr:hover { background: var(--bg-elev); }
.muted { color: var(--text-faint); font-size: 13px; }

/* ---------- Docs ---------- */
.docs-card {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  width: 100%; max-width: 980px; height: 86vh;
  display: flex; flex-direction: column; overflow: hidden;
}
.docs-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px; border-bottom: 1px solid var(--border-soft);
}
.docs-title { margin: 0; font-size: 17px; }
.docs-body { flex: 1; display: flex; min-height: 0; }
.docs-nav {
  width: 220px; flex-shrink: 0; border-right: 1px solid var(--border-soft);
  padding: 12px 8px; overflow-y: auto; display: flex; flex-direction: column; gap: 2px;
}
.docs-nav-item {
  text-align: left; background: none; border: none; color: var(--text-dim);
  font: inherit; font-size: 13.5px; padding: 8px 12px; border-radius: var(--radius-sm); cursor: pointer;
}
.docs-nav-item:hover { background: var(--bg-elev-2); color: var(--text); }
.docs-nav-item.active { background: var(--bg-elev-2); color: var(--text); font-weight: 600; }
.docs-content { flex: 1; overflow-y: auto; padding: 8px 32px 40px; min-width: 0; }

/* rendered markdown */
.markdown { line-height: 1.65; }
.markdown h1 { font-size: 24px; margin: 22px 0 12px; }
.markdown h2 { font-size: 19px; margin: 26px 0 10px; padding-bottom: 6px; border-bottom: 1px solid var(--border-soft); }
.markdown h3 { font-size: 16px; margin: 20px 0 8px; }
.markdown h4 { font-size: 14px; margin: 16px 0 6px; color: var(--text-dim); }
.markdown p { margin: 10px 0; }
.markdown ul, .markdown ol { margin: 10px 0; padding-left: 24px; }
.markdown li { margin: 4px 0; }
.markdown a { color: var(--accent); text-decoration: none; }
.markdown a:hover { text-decoration: underline; }
.markdown strong { font-weight: 700; }
.markdown code {
  font-family: var(--mono); font-size: 12.5px;
  background: var(--bg); border: 1px solid var(--border-soft); border-radius: 5px; padding: 1px 5px;
}
.markdown pre {
  background: var(--bg); border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm); padding: 12px 14px; overflow-x: auto; margin: 12px 0;
}
.markdown pre code { background: none; border: none; padding: 0; line-height: 1.5; }
.markdown blockquote {
  margin: 12px 0; padding: 8px 14px; border-left: 3px solid var(--accent);
  background: rgba(59,130,246,.06); color: var(--text-dim);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.markdown hr { border: none; border-top: 1px solid var(--border-soft); margin: 22px 0; }
.markdown table { width: 100%; border-collapse: collapse; margin: 14px 0; font-size: 13.5px; display: block; overflow-x: auto; }
.markdown th { text-align: left; padding: 8px 10px; border-bottom: 2px solid var(--border); color: var(--text-dim); white-space: nowrap; }
.markdown td { padding: 8px 10px; border-bottom: 1px solid var(--border-soft); vertical-align: top; }
@media (max-width: 700px) {
  .docs-body { flex-direction: column; }
  .docs-nav { width: auto; flex-direction: row; flex-wrap: wrap; border-right: none; border-bottom: 1px solid var(--border-soft); }
  .docs-content { padding: 8px 16px 32px; }
}

/* ---------- Card schedule line ---------- */
.card-sched { margin: -6px 0 12px; font-size: 12px; color: var(--text-faint); }
.card-sched.warn { color: #e9cf8d; }
.card-extra { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Header count badge (doctor problems) ---------- */
.count-badge {
  display: inline-block; margin-left: 6px; min-width: 18px; padding: 0 5px;
  border-radius: 999px; background: var(--amber); color: #1b1404;
  font-size: 11px; line-height: 18px; text-align: center; font-weight: 700;
}
.count-badge.fail { background: var(--red); color: #fff; }

/* ---------- Health / Trends panels ---------- */
.panel-card {
  position: relative;
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  width: 100%; max-width: 1040px; height: 86vh;
  display: flex; flex-direction: column; overflow: hidden;
}
.panel-body { flex: 1; overflow-y: auto; padding: 16px 22px 28px; }
.panel-summary { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 8px; }
.panel-h { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--text-faint); margin: 22px 0 8px; }
.panel-details { margin-top: 14px; }
.panel-details summary { cursor: pointer; color: var(--text-dim); font-size: 13px; font-weight: 600; padding: 4px 0; }
.history-table tbody tr.no-click { cursor: default; }
.nowrap { white-space: nowrap; }
.select-sm {
  font: inherit; font-size: 13px; color: var(--text);
  background: var(--bg-elev-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 4px 8px;
}

.chart-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.chart-card {
  background: var(--bg); border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm); padding: 10px 12px 6px; min-width: 0;
}
.chart-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 4px; }
.chart-title { font-size: 12.5px; color: var(--text-dim); font-weight: 600; flex: 1; }
.chart-value { font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; }
.chart-delta { font-size: 12px; color: var(--text-faint); font-variant-numeric: tabular-nums; }
.chart-delta.good { color: #a6e3b4; }
.chart-delta.bad { color: #f0a8a3; }
.chart-plot { min-height: 132px; }
.chart-empty { padding: 44px 0; text-align: center; margin: 0; }
.chart-svg { display: block; max-width: 100%; overflow: visible; }
.chart-grid-line { stroke: var(--border-soft); stroke-width: 1; }
.chart-axis { fill: var(--text-faint); font-size: 10.5px; font-family: var(--sans); }
.chart-line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-area { fill: var(--accent); opacity: .10; stroke: none; }
.chart-dot { fill: var(--accent); stroke: var(--bg); stroke-width: 2; }
.chart-cross { stroke: var(--text-faint); stroke-width: 1; stroke-dasharray: 3 3; }
.chart-tip {
  position: absolute; z-index: 5; pointer-events: none;
  background: var(--bg-elev-2); border: 1px solid var(--border); border-radius: 6px;
  padding: 5px 8px; font-size: 12px; color: var(--text); box-shadow: var(--shadow); white-space: nowrap;
}
.run-tick.ok { fill: var(--green); }
.run-tick.warn { fill: var(--amber); }
.run-tick.err { fill: var(--red); }
.run-tick.na { fill: var(--text-faint); }

/* ---------- Local AI (Health panel section + Trends chart) ---------- */
.health-chip.click { cursor: pointer; }
button.health-chip { font-family: inherit; text-align: left; }
.ai-provider-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin: 12px 0; }
.ai-provider-card { display: flex; flex-direction: column; align-items: flex-start; min-width: 0; border: 1px solid var(--border-soft); border-radius: var(--radius-sm); padding: 16px; overflow-wrap: anywhere; }
.ai-provider-card > .panel-h { margin-top: 0; }
.ai-provider-card p { font-size: 12px; margin: 8px 0; }
.ai-provider-card .stat-grid { width: 100%; grid-template-columns: repeat(2, minmax(0, 1fr)); margin-top: auto; padding-top: 10px; }
.ai-provider-error { color: var(--amber); }
@media (max-width: 760px) { .ai-provider-grid { grid-template-columns: minmax(0, 1fr); } }
.panel-h-sm { margin-top: 18px; }
.stat-grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); margin: 10px 0 4px; }
.stat-tile { background: var(--bg); border: 1px solid var(--border-soft); border-radius: var(--radius-sm); padding: 10px 12px; min-width: 0; }
.stat-label { font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-faint); font-weight: 600; }
.stat-value { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px; overflow-wrap: anywhere; }
.stat-sub { font-size: 12px; color: var(--text-dim); margin-top: 2px; overflow-wrap: anywhere; }
.history-table th.num, .history-table td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--text-dim); margin: 2px 0 8px; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; flex: none; }
.legend-item .legend-swatch, .chart-tip .legend-swatch { margin-right: 4px; }
.bar-seg:hover { opacity: .85; }

/* ---------- Footer ---------- */
.footer { text-align: center; color: var(--text-faint); font-size: 12px; padding: 18px; }

/* ---------- Responsive ---------- */
@media (max-width: 600px) {
  .container { padding: 18px 14px 90px; }
  /* minmax(0, 1fr): a plain 1fr column never shrinks below its widest unbreakable
     line, which made every card 408 px on a 390 px phone. */
  .grid { grid-template-columns: minmax(0, 1fr); }
  .card { min-width: 0; overflow-wrap: anywhere; }
  .chart-grid { grid-template-columns: minmax(0, 1fr); }
  .console { height: 60vh; }
  .brand-text { display: none; }
  .editor-card { height: 88vh; max-width: 100%; padding: 16px; }
}

/* ---------- Review queue (identify lanes) ---------- */
.review-item { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; margin: 12px 0; background: var(--bg-elev); }
.review-item.review-done { opacity: .45; }
.review-head { display: flex; gap: 12px; align-items: flex-start; }
.review-thumb { width: 160px; height: 90px; object-fit: cover; border-radius: 6px; background: #111; flex: none; }
.review-info { min-width: 0; }
.review-name { font-weight: 600; word-break: break-all; }
.review-meta { font-size: 12px; margin-top: 2px; }
.review-link { font-size: 12px; }
.review-cands { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.review-cand { display: flex; gap: 10px; align-items: center; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; cursor: pointer; }
.review-cand-img { width: 54px; height: 76px; object-fit: cover; border-radius: 4px; background: #111; flex: none; }
.review-cand-text { min-width: 0; }
.review-cand-title { font-size: 14px; }
.review-cand-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; font-size: 12px; align-items: center; }
.tag.ok { color: #a6e3b4; border-color: var(--green-soft); }
.review-actions { display: flex; gap: 8px; align-items: center; margin-top: 10px; }
.review-tools { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; margin: 6px 0 12px; padding: 10px 12px; border: 1px dashed var(--border); border-radius: var(--radius); font-size: 13px; }
.review-tools label { display: inline-flex; align-items: center; gap: 4px; }
.review-tools input[type="number"] { width: 58px; }
.review-tools-stats { flex-basis: 100%; font-size: 12px; }
.review-cand input[type="radio"] { width: 18px; height: 18px; flex: none; margin: 0; }
.review-cand:has(input:checked) { border-color: var(--accent); }
.tag.bad { color: #f5a3a3; border-color: rgba(239, 68, 68, .55); }
.tag.warn { color: #e9cf8d; border-color: rgba(234, 179, 8, .5); }
.tag.purchased { color: #9fd3ff; border-color: rgba(56, 152, 236, .6); }
.lq-purchased { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.lq-purchased input { width: 16px; height: 16px; margin: 0; }
.review-cand-chips a { padding: 2px 0; }
/* Phones: the review panel takes the whole screen, every control is a thumb-sized
   target, and inputs are 16px so iOS does not zoom the page on focus. */
@media (max-width: 600px) {
  #reviewModal { padding: 0; }
  #reviewModal .panel-card { height: 100vh; height: 100dvh; max-width: 100%; border-radius: 0; border: none; }
  #reviewModal .docs-head { padding: 10px 12px; gap: 8px; }
  #reviewModal .panel-body { padding: 10px 12px calc(24px + env(safe-area-inset-bottom)); }
  .review-item { padding: 10px; margin: 10px 0; }
  .review-head { gap: 10px; }
  .review-thumb { width: 112px; height: 63px; }
  .review-name { font-size: 13.5px; line-height: 1.35; }
  .review-meta { overflow-wrap: anywhere; }
  .review-cand { padding: 8px; gap: 8px; align-items: flex-start; }
  .review-cand-img { width: 46px; height: 65px; }
  .review-cand-title { font-size: 13.5px; overflow-wrap: anywhere; }
  .review-actions { flex-wrap: wrap; }
  .review-actions .btn { flex: 1 1 40%; min-height: 42px; font-size: 14px; }
  .review-actions .review-status { flex-basis: 100%; }
  .review-tools { gap: 10px; padding: 10px; }
  .review-tools label { flex: 1 1 100%; justify-content: space-between; }
  .review-tools label:has(input[type="checkbox"]) { justify-content: flex-start; gap: 8px; }
  .review-tools input[type="checkbox"] { width: 20px; height: 20px; }
  .review-tools select, .review-tools input[type="number"] { font-size: 16px; min-height: 36px; }
  .review-tools input[type="number"] { width: 72px; }
  .review-tools .btn { flex: 1 1 100%; min-height: 42px; font-size: 14px; }
}

/* AI roadmap additions (2026-10-19): ask box, AI review badge, failure-explainer line */
.ask-box { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 0 0 12px; }
.ask-input { flex: 1 1 260px; min-width: 0; padding: 6px 10px; border: 1px solid var(--border); border-radius: var(--radius); background: transparent; color: inherit; font: inherit; }
.review-ai { margin-top: 4px; font-size: 12px; }
.run-why { font-size: 12px; margin-top: 4px; }
.review-similar { font-size: 12px; margin-top: 4px; }
/* ---------- Library & watch stats (2026-10-19): home row, fact ticker, Stats panel ---------- */
.stats-strip { max-width: 1100px; margin: 0 auto; padding: 12px 22px 0; display: flex; flex-direction: column; gap: 8px; }
.stats-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.stat-chip { display: inline-flex; align-items: baseline; gap: 6px; padding: 5px 11px; border-radius: 999px; border: 1px solid var(--border); background: var(--bg-elev); color: var(--text); font: inherit; font-size: 12.5px; cursor: pointer; transition: border-color .15s, background .15s; }
.stat-chip:hover { border-color: var(--accent); background: var(--bg-elev-2); }
.stat-chip-label { color: var(--text-faint); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.stat-chip-value { font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-chip.hot { border-color: rgba(234, 179, 8, .6); }
.stat-chip.hot .stat-chip-value::after { content: " \1F525"; }
.stat-chip.persona { border-color: rgba(137, 87, 229, .55); background: linear-gradient(90deg, rgba(137, 87, 229, .14), rgba(213, 81, 129, .10)); }
.fact-ticker { display: flex; align-items: center; gap: 10px; padding: 9px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border-soft);
  background: linear-gradient(90deg, rgba(59, 130, 246, .10), rgba(213, 81, 129, .08) 60%, transparent); cursor: pointer; user-select: none; min-height: 40px; }
.fact-ticker:hover, .fact-ticker:focus-visible { border-color: var(--border); outline: none; }
.fact-ticker .fact-emoji, .fact-ticker .fact-text, .fact-ticker .fact-ai { transition: opacity .22s ease, transform .22s ease; }
.fact-ticker.fade .fact-emoji, .fact-ticker.fade .fact-text, .fact-ticker.fade .fact-ai { opacity: 0; transform: translateY(4px); }
.fact-emoji { font-size: 18px; line-height: 1; flex: none; }
.fact-text { flex: 1 1 auto; min-width: 0; font-size: 13.5px; color: var(--text); }
.fact-ai { flex: none; font-size: 10px; font-weight: 700; letter-spacing: .06em; padding: 1px 6px; border-radius: 999px; color: #d8c8ff; border: 1px solid rgba(137, 87, 229, .6); background: rgba(137, 87, 229, .15); }
.fact-ai::before { content: "\2728 "; }

#statsModal .panel-card { max-width: 1100px; }
#statsModal .docs-head { flex-wrap: wrap; gap: 10px; }
.stats-tabs { display: inline-flex; gap: 2px; padding: 3px; border-radius: 999px; background: var(--bg); border: 1px solid var(--border-soft); margin-right: auto; }
.stats-tab { border: 0; background: transparent; color: var(--text-dim); font: inherit; font-size: 13px; padding: 4px 12px; border-radius: 999px; cursor: pointer; }
.stats-tab:hover { color: var(--text); }
.stats-tab.active { background: var(--accent); color: #fff; }
.stats-sub { margin: 2px 0 8px; font-size: 13px; }
.stats-meta { margin-top: 18px; font-size: 12px; }
.stats-gap { margin-top: 14px; }
.stats-2col { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; margin: 6px 0; }
.stats-2col .chart-title { margin: 4px 0 6px; }
.hbars { display: flex; flex-direction: column; gap: 5px; margin: 4px 0 8px; }
.hbar-row { display: grid; grid-template-columns: minmax(90px, 38%) 1fr auto; gap: 8px; align-items: center; font-size: 12.5px; }
.hbar-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
a.hbar-name:hover { color: var(--accent); }
.hbar-track { height: 10px; border-radius: 5px; background: var(--bg); overflow: hidden; }
.hbar-fill { height: 100%; border-radius: 5px; background: var(--accent); }
.hbar-val { font-variant-numeric: tabular-nums; color: var(--text-dim); min-width: 44px; text-align: right; }
.mix-bar { display: flex; height: 16px; border-radius: 6px; overflow: hidden; background: var(--bg); margin: 8px 0; }
.mix-seg { height: 100%; min-width: 2px; }
.mix-seg:hover { opacity: .8; }
.col-bar { fill: var(--accent); opacity: .85; }
.col-bar.hot { fill: #d55181; }
.col-bar:hover { opacity: 1; }
.heatmap { display: grid; grid-template-columns: 34px repeat(24, minmax(0, 1fr)); gap: 2px; font-size: 10.5px; color: var(--text-faint); }
.heat-h { text-align: left; }
.heat-d { align-self: center; }
.heat-c { aspect-ratio: 1.6; border-radius: 3px; background: var(--bg); min-height: 10px; }
.heat-c:hover { outline: 1px solid var(--text-dim); }
.scene-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 8px; margin: 6px 0 10px; }
.scene-item { display: flex; gap: 10px; padding: 6px; border-radius: var(--radius-sm); border: 1px solid var(--border-soft); background: var(--bg); color: inherit; text-decoration: none; min-width: 0; }
.scene-item:hover { border-color: var(--accent); }
.scene-thumb-link { flex: none; display: block; line-height: 0; }
.scene-thumb { width: 112px; height: 63px; object-fit: cover; border-radius: 5px; background: #111; flex: none; }
.scene-thumb.broken { visibility: hidden; }
.scene-info { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.scene-title { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: inherit; text-decoration: none; }
a.scene-title:hover { color: var(--accent); }
.scene-who { font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Names that open in Stash: look like text, reveal on hover. */
a.stash-link { color: inherit; text-decoration: underline dotted rgba(127, 127, 127, .55); text-underline-offset: 2px; }
a.stash-link:hover { color: var(--accent); text-decoration-color: currentColor; }
.fact-more { font-size: 12px; opacity: .8; white-space: nowrap; }
.scene-meta { font-size: 11.5px; color: var(--text-dim); }
.progress { height: 5px; border-radius: 3px; background: var(--bg-elev-2); overflow: hidden; margin-top: 4px; }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--accent), #d55181); border-radius: 3px; }
.persona-card { padding: 14px 16px; border-radius: var(--radius); margin: 4px 0 10px; border: 1px solid rgba(137, 87, 229, .45);
  background: linear-gradient(120deg, rgba(137, 87, 229, .18), rgba(213, 81, 129, .10) 55%, rgba(59, 130, 246, .08)); }
.persona-title { font-size: 20px; font-weight: 800; display: flex; align-items: center; gap: 8px; }
.persona-tag { color: var(--text-dim); margin-top: 3px; }
.persona-recap { margin-top: 10px; font-size: 13.5px; }
.badge-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
.badge-card { padding: 12px; border-radius: var(--radius); border: 1px solid var(--border-soft); background: var(--bg); display: flex; flex-direction: column; gap: 3px; filter: grayscale(.9); opacity: .6; }
.badge-card.earned { filter: none; opacity: 1; }
.badge-card.tier-1 { border-color: rgba(205, 127, 50, .6); }
.badge-card.tier-2 { border-color: rgba(192, 192, 192, .7); }
.badge-card.tier-3 { border-color: rgba(234, 179, 8, .8); box-shadow: 0 0 14px rgba(234, 179, 8, .15); }
.badge-emoji { font-size: 28px; line-height: 1.1; }
.badge-name { font-weight: 700; }
.badge-stars { color: #eab308; letter-spacing: 2px; font-size: 13px; }
.badge-value { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.badge-desc, .badge-next { font-size: 12px; }
.badge-next.done { color: var(--green); }
.fact-list { display: flex; flex-direction: column; gap: 6px; }
.fact-row { display: flex; gap: 10px; align-items: center; padding: 7px 10px; border-radius: var(--radius-sm); background: var(--bg); border: 1px solid var(--border-soft); font-size: 13.5px; }
.fact-row .fact-text { flex: 1 1 auto; }

@media (max-width: 760px) {
  .stats-2col { grid-template-columns: minmax(0, 1fr); }
  .scene-list { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 600px) {
  .stats-strip { padding: 10px 14px 0; }
  .stat-chip { padding: 5px 9px; font-size: 12px; }
  .fact-text { font-size: 13px; }
  #statsModal { padding: 0; }
  #statsModal .panel-card { height: 100vh; height: 100dvh; max-width: 100%; border-radius: 0; border: none; }
  #statsModal .docs-head { padding: 10px 12px; }
  #statsModal .panel-body { padding: 10px 12px calc(24px + env(safe-area-inset-bottom)); }
  .stats-tabs { order: 3; width: 100%; justify-content: space-between; margin-right: 0; }
  .stats-tab { flex: 1; padding: 7px 4px; font-size: 14px; }
  .hbar-row { grid-template-columns: minmax(80px, 42%) 1fr auto; }
  .heatmap { grid-template-columns: 26px repeat(24, minmax(0, 1fr)); gap: 1px; font-size: 9px; }
  .heat-h:nth-child(odd) { visibility: hidden; }
  .badge-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #statsBody .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .scene-thumb { width: 96px; height: 54px; }
}

/* Home hierarchy and mobile disclosures */
.nav-more { position: relative; }
.nav-more summary { list-style: none; }
.nav-more summary::-webkit-details-marker { display: none; }
.nav-toggle { display: flex; align-items: center; justify-content: center; gap: 10px; min-width: 48px; min-height: 48px; }
.hamburger { display: flex; flex-direction: column; justify-content: center; gap: 5px; width: 20px; height: 24px; }
.hamburger span { width: 20px; height: 2px; border-radius: 2px; background: currentColor; transition: transform .15s, opacity .15s; }
.nav-more[open] .hamburger span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.nav-more[open] .hamburger span:nth-child(2) { opacity: 0; }
.nav-more[open] .hamburger span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }
.nav-more[open] .nav-toggle { background: var(--bg-elev-2); border-color: #557764; }
.nav-menu {
  position: absolute; right: 0; top: calc(100% + 10px); width: 292px;
  max-width: calc(100vw - 32px); max-height: calc(100vh - 100px);
  max-height: calc(100dvh - 100px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  overflow-y: auto; overscroll-behavior: contain;
  padding: 8px; background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 4px;
}
.nav-menu .btn { display: flex; align-items: center; gap: 8px; text-align: left; min-height: 44px; border-color: transparent; text-decoration: none; white-space: normal; }
.nav-group { display: flex; flex-direction: column; gap: 2px; }
.nav-group + .nav-group { border-top: 1px solid var(--border); margin-top: 6px; padding-top: 6px; }
.nav-group-title { color: var(--text-dim); font-size: 11px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; margin: 6px 12px; }
.nav-menu .nav-greenhouse { color: #bce9c8; }
.nav-menu .count-badge { margin-left: auto; }
.btn-greenhouse { background: #285b3d; border-color: #44845b; color: #edfff2; }
.btn-greenhouse:hover { background: #326e4b; }
.home-feature {
  max-width: 1056px; margin: 22px auto 8px; padding: 24px;
  border: 1px solid #365d43; border-radius: 18px;
  background: radial-gradient(ellipse at top left, #254a35, transparent 70%), var(--bg-elev);
  display: flex; align-items: center; justify-content: space-between; gap: 24px;
}
.feature-eyebrow { color: #b4d9be; font-size: 12px; font-weight: 600; letter-spacing: .04em; }
.home-feature h1 { margin: 6px 0; font-size: 28px; letter-spacing: -.03em; }
.home-feature h1 .tag { display: inline-block; vertical-align: middle; font-size: 11px; letter-spacing: normal; white-space: nowrap; }
.home-feature p { margin: 0; max-width: 540px; color: #b6c5d7; font-size: 14px; }
.feature-entry { display: flex; flex-direction: column; align-items: flex-end; gap: 12px; flex-shrink: 0; }
.feature-entry a { text-decoration: none; text-align: center; }
.feature-links { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 10px; font-size: 13px; }
.feature-links a { color: #8ed8a0; text-decoration: none; }
.feature-links a:hover { text-decoration: underline; }
.automation-heading { display: flex; justify-content: space-between; align-items: center; gap: 20px; }
.automation-heading h2 { font-size: 22px; margin: 0; }
.mobile-hint { display: none; color: var(--text-dim); font-size: 13px; margin: 4px 0 0; }
.task-search { flex: 0 1 360px; }
.task-search label { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 4px; }
.task-search input {
  width: 100%; min-width: 0; min-height: 44px; font: inherit;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 10px 12px; background: var(--bg-elev); color: var(--text);
}
.task-group { margin-top: 24px; }
.task-group .group-title { margin: 0 0 12px; color: var(--text-dim); }
.group-count { color: var(--text-dim); background: var(--bg-elev-2); padding: 2px 7px; border-radius: 999px; margin-left: 6px; }
.task-more { display: none; }
.task-attention { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.task-attention .btn { white-space: normal; text-align: left; border-color: #5a4a22; color: #e9cf8d; }
.empty-state { padding: 24px 0; color: var(--text-dim); }
.load-error { border: 1px solid #5a2c2a; border-radius: var(--radius-sm); padding: 12px; color: #f0a8a3; }
.card-status { flex-wrap: wrap; min-width: 0; }
.card-actions { flex-shrink: 0; }
.card-extra { white-space: normal; overflow-wrap: anywhere; }
.run-why { flex-basis: 100%; }
.panel-body { min-height: 0; overflow-x: auto; overscroll-behavior: contain; }
.docs-nav { max-height: 35%; }
@media (min-width: 701px) { .docs-nav { max-height: none; } }

@media (max-width: 1100px) {
  .home-feature { margin-left: 22px; margin-right: 22px; }
}
@media (max-width: 700px) {
  html { scroll-padding-top: 100px; }
  .topbar {
    padding: calc(8px + env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left));
    gap: 8px;
  }
  .brand-text { display: inline; font-size: 16px; }
  .brand-mark { font-size: 24px; }
  .topbar-right { flex: 0 0 auto; min-width: 0; margin-left: auto; justify-content: flex-end; }
  .nav-toggle-label { display: none; }
  .topbar-right .btn { padding: 8px; font-size: 13px; min-height: 44px; }
  .topbar-right > .stash-link { font-size: 12px; padding: 10px 7px; min-height: 44px; display: inline-flex; align-items: center; }
  .count-badge { margin-left: 3px; }
  .nav-menu { max-width: calc(100vw - 24px); }
  .home-feature { margin: 16px max(14px, env(safe-area-inset-right)) 8px max(14px, env(safe-area-inset-left)); padding: 20px; gap: 16px; flex-direction: column; align-items: stretch; }
  .home-feature h1 { font-size: 26px; }
  .feature-entry { flex-direction: column; align-items: stretch; gap: 8px; }
  .feature-entry .btn { font-size: 13px; min-height: 44px; }
  .container { padding: 22px max(14px, env(safe-area-inset-right)) 32px max(14px, env(safe-area-inset-left)); }
  .automation-heading { flex-direction: column; align-items: stretch; gap: 14px; }
  .mobile-hint { display: block; }
  .task-search { flex: auto; }
  .grid { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .task-group:not(.expanded) .secondary-task { display: none; }
  .task-group .card:not(.secondary-task) { order: -1; }
  .task-more { display: block; width: 100%; min-height: 48px; margin-top: 10px; white-space: normal; }
  .card { min-width: 0; padding: 16px; overflow-wrap: anywhere; }
  .card-foot { flex-wrap: wrap; }
  .card-actions { margin-left: auto; }
  .btn, .btn-sm, .link-btn, .history-toggle, .docs-nav-item, .terms-remove, summary, .stat-chip, button.health-chip { min-height: 44px; }
  .link-btn { padding: 8px 4px; }
  input:not([type="checkbox"]):not([type="radio"]), select, textarea,
  .terms-table input, .terms-table select, .review-tools input[type="number"], .review-tools select { font-size: 16px; }
  .health-strip, .stats-strip { padding-left: max(14px, env(safe-area-inset-left)); padding-right: max(14px, env(safe-area-inset-right)); }
  .health-chip { white-space: normal; overflow-wrap: anywhere; }
  .overlay, #reviewModal, #statsModal { padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
  .overlay .panel-card, #reviewModal .panel-card, #statsModal .panel-card, .overlay .docs-card, .overlay .editor-card {
    height: 100vh; height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    width: 100%; max-width: none; border-radius: 0; border: none;
  }
  .overlay .docs-head { padding: 10px 12px; flex-wrap: wrap; gap: 8px; flex-shrink: 0; }
  .overlay .panel-body, #reviewModal .panel-body, #statsModal .panel-body { padding: 12px; }
  .overlay .modal, .login-card { max-height: 100%; overflow-y: auto; margin: 14px; }
  .editor-card { padding: 14px; min-height: 0; }
  .editor-head { flex-wrap: wrap; flex-shrink: 0; }
  .editor-head-actions { margin-left: auto; flex-wrap: wrap; gap: 6px; }
  .editor-text { min-height: 0; }
  .editor-foot { flex-wrap: wrap; flex-shrink: 0; }
  .editor-actions { margin-left: auto; }
  .docs-body { flex-direction: column; }
  .docs-nav { width: auto; flex-direction: row; flex-wrap: nowrap; overflow: auto; max-height: 70px; flex-shrink: 0; border-right: none; border-bottom: 1px solid var(--border-soft); }
  .docs-nav-item { white-space: nowrap; flex-shrink: 0; }
  .docs-content { padding: 8px 16px 24px; overflow-wrap: anywhere; }
  .terms-table, .terms-table tbody, .terms-table tr, .terms-table td { display: block; width: 100% !important; }
  .terms-table thead { display: none; }
  .terms-table tr { padding: 10px; border-bottom: 1px solid var(--border); }
  .terms-table td { padding: 3px 0; border: 0; }
  .terms-table td:nth-child(1)::before { content: "Search term"; }
  .terms-table td:nth-child(2)::before { content: "Keywords (any match; blank = everything)"; }
  .terms-table td:nth-child(3)::before { content: "Resolution"; }
  .terms-table td::before { color: var(--text-dim); font-size: 12px; }
  .terms-table input, .terms-table select { min-height: 44px; border-color: var(--border); background: var(--bg-elev); }
  .terms-remove-cell { text-align: right; }
  .console { height: 60vh; height: 60dvh; padding-bottom: env(safe-area-inset-bottom); padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }
  .console-title { flex-wrap: wrap; min-width: 0; overflow-wrap: anywhere; }
  .console-head { gap: 8px; }
  .chart-grid, .stat-grid { grid-template-columns: minmax(0, 1fr); }
  .history { padding: 0 14px 24px; }
  .footer { padding-bottom: calc(18px + env(safe-area-inset-bottom)); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

/* ---------- Low-quality cleanup queue (2026-10-19) ---------- */
.lq-protected { flex-basis: 100%; font-size: 12px; margin-top: 4px; }
.lq-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; margin: 8px 0 12px; }
.lq-tile { display: flex; flex-direction: column; border: 2px solid rgba(239, 68, 68, .55); border-radius: var(--radius); background: var(--bg-elev); overflow: hidden; cursor: pointer; transition: border-color .12s, opacity .12s; }
div.lq-tile { cursor: default; border-color: var(--border); }
.lq-tile.lq-keep { border-color: var(--border); opacity: .55; }
.lq-tile.lq-keep:hover { opacity: .8; }
.lq-shot { position: relative; aspect-ratio: 16 / 9; background: #111; }
.lq-shot img { width: 100%; height: 100%; object-fit: contain; display: block; }
.lq-shot.lq-noshot::after { content: attr(data-label); position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--text-faint); font-size: 12px; }
.lq-badge { position: absolute; bottom: 6px; padding: 1px 6px; border-radius: 4px; background: rgba(0, 0, 0, .72); color: #fff; font-size: 11.5px; font-variant-numeric: tabular-nums; }
.lq-res { left: 6px; }
.lq-dur { right: 6px; }
.lq-check { position: absolute; top: 8px; left: 8px; width: 22px; height: 22px; margin: 0; accent-color: #ef4444; cursor: pointer; }
.lq-info { padding: 8px 10px 10px; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.lq-name { font-weight: 600; font-size: 13.5px; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.lq-folder { font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; direction: rtl; text-align: left; }
.lq-chips { display: flex; flex-wrap: wrap; gap: 4px; margin: 2px 0; font-size: 11.5px; }
.lq-meta { font-size: 12px; }
.lq-foot { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; margin-top: 4px; }
.lq-status { font-size: 12px; flex-basis: 100%; }
.lq-pager { display: flex; gap: 12px; align-items: center; justify-content: center; margin: 4px 0 12px; font-size: 13px; }
.lq-actionbar { position: sticky; bottom: 0; display: flex; gap: 12px; align-items: center; justify-content: flex-end; padding: 10px 12px; margin: 0 -4px; border-top: 1px solid var(--border); background: var(--bg-elev); z-index: 2; }
.lq-action-text { font-size: 13px; color: var(--text-dim); margin-right: auto; }
@media (max-width: 600px) {
  #cleanupModal { padding: 0; }
  #cleanupModal .panel-card { height: 100vh; height: 100dvh; max-width: 100%; border-radius: 0; border: none; }
  #cleanupModal .docs-head { padding: 10px 12px; gap: 8px; }
  #cleanupModal .panel-body { padding: 10px 12px 0; }
  .lq-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .lq-info { padding: 6px 7px 8px; }
  .lq-name { font-size: 12.5px; }
  .lq-meta, .lq-folder { font-size: 11px; }
  .lq-check { width: 26px; height: 26px; }
  .lq-tools label { flex: 1 1 100%; justify-content: space-between; }
  .lq-tools select { font-size: 16px; min-height: 36px; }
  .lq-tools .btn { flex: 1 1 40%; min-height: 40px; }
  .lq-actionbar { padding: 10px 0 calc(10px + env(safe-area-inset-bottom)); margin: 0; }
  .lq-actionbar .btn { flex: 1 1 auto; min-height: 44px; font-size: 14px; }
  .lq-action-text { display: none; }
}
