:root {
  color-scheme: light;
  --bg: #fafafa;
  --fg: #1a1a1a;
  --muted: #666;
  --border: #e5e5e5;
  --card: #ffffff;
  --surface-2: #f9fafb;  /* table header, alt rows */
  --surface-3: #f3f4f6;  /* disabled inputs, code bg */
  --hover: #f5f5f5;      /* button hover */
  --chip-bg: #f2f2f2;
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.08);

  --urgency-high: #dc2626;
  --urgency-medium: #eab308;
  --urgency-low: #22c55e;
  --approve: #16a34a;
  --reject: #dc2626;
  --noise: #6b7280;
  --warn-bg: #fef3c7;
  --warn-fg: #92400e;
  --link: #2563eb;

  --health-good: #15803d;
  --health-ok: #a16207;
  --health-bad: #c2410c;
  --health-critical: #991b1b;

  --pill-bg: #f3f4f6;
  --pill-fg: #374151;
  --pill-approved-bg: #dcfce7;
  --pill-approved-fg: #166534;
  --pill-rejected-bg: #fee2e2;
  --pill-rejected-fg: #991b1b;
  --pill-noise-bg: #e5e7eb;
  --pill-noise-fg: #4b5563;
  --pill-auto-archived-bg: #fef3c7;
  --pill-auto-archived-fg: #92400e;

  --toast-bg: #ecfdf5;
  --toast-fg: #065f46;
  --llm-bg: #ede9fe;
  --llm-fg: #5b21b6;
  --topic-bg: #eef2ff;
  --topic-fg: #3730a3;
  --key-banner-bg: #fef3c7;
  --key-banner-border: #facc15;
  --key-value-bg: #1f2937;
  --key-value-fg: #e5e7eb;
  --error-bg: #fee2e2;
  --error-fg: #991b1b;
  --badge-active-bg: #d1fae5;
  --badge-active-fg: #065f46;
  --badge-completed-bg: #e0e7ff;
  --badge-completed-fg: #3730a3;

  --radius: 6px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Kalpurush", "SolaimanLipi", sans-serif;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f172a;
  --fg: #e2e8f0;
  --muted: #94a3b8;
  --border: #334155;
  --card: #1e293b;
  --surface-2: #172033;
  --surface-3: #0b1223;
  --hover: #253549;
  --chip-bg: #334155;
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.5);

  --urgency-high: #f87171;
  --urgency-medium: #facc15;
  --urgency-low: #4ade80;
  --approve: #22c55e;
  --reject: #f87171;
  --noise: #94a3b8;
  --warn-bg: #422006;
  --warn-fg: #fcd34d;
  --link: #60a5fa;

  --health-good: #4ade80;
  --health-ok: #facc15;
  --health-bad: #fb923c;
  --health-critical: #f87171;

  --pill-bg: #334155;
  --pill-fg: #cbd5e1;
  --pill-approved-bg: #064e3b;
  --pill-approved-fg: #6ee7b7;
  --pill-rejected-bg: #450a0a;
  --pill-rejected-fg: #fca5a5;
  --pill-noise-bg: #334155;
  --pill-noise-fg: #cbd5e1;
  --pill-auto-archived-bg: #422006;
  --pill-auto-archived-fg: #fcd34d;

  --toast-bg: #064e3b;
  --toast-fg: #6ee7b7;
  --llm-bg: #3730a3;
  --llm-fg: #c7d2fe;
  --topic-bg: #1e3a8a;
  --topic-fg: #bfdbfe;
  --key-banner-bg: #422006;
  --key-banner-border: #a16207;
  --key-value-bg: #0b1223;
  --key-value-fg: #e5e7eb;
  --error-bg: #450a0a;
  --error-fg: #fca5a5;
  --badge-active-bg: #064e3b;
  --badge-active-fg: #6ee7b7;
  --badge-completed-bg: #1e3a8a;
  --badge-completed-fg: #bfdbfe;
}

* { box-sizing: border-box; }
[x-cloak] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
}

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- left sidebar (desktop) / drawer (mobile) ----------
   The sidebar is fixed-position so it doesn't take part in document
   flow; we shift `main` rightwards via padding on the body instead.
   On mobile (<=720px) the @media block hides it offscreen behind a
   transform and a hamburger in `.mobile-topbar` toggles it back in. */
:root { --sidebar-width: 220px; }
body { padding-left: var(--sidebar-width); }

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--card);
  border-right: 1px solid var(--border);
  padding: 1rem 0.85rem;
  overflow-y: auto;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.sidebar-brand h1 { font-size: 1.05rem; margin: 0; }
.sidebar-brand h1 a { color: var(--fg); }
.sidebar nav { display: flex; flex-direction: column; gap: 0.15rem; }
.sidebar nav a {
  color: var(--muted);
  font-weight: 500;
  padding: 0.45rem 0.7rem;
  border-radius: var(--radius);
  font-size: 0.92rem;
}
.sidebar nav a:hover { background: var(--hover); color: var(--fg); text-decoration: none; }
.sidebar nav a.active { background: var(--surface-2); color: var(--fg); }
.sidebar nav a.muted { opacity: 0.6; }
.sidebar-user {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  font-size: 0.85rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}
.sidebar-user .theme-toggle { align-self: flex-start; }

/* Mobile-only top bar with hamburger. CSS hides it on desktop. */
.mobile-topbar {
  display: none;
  align-items: center;
  gap: 0.75rem;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 0.55rem 0.9rem;
  position: sticky;
  top: 0;
  z-index: 40;
}
.mobile-topbar h1 { font-size: 1.05rem; margin: 0; }
.mobile-topbar h1 a { color: var(--fg); }
.hamburger {
  width: 38px;
  height: 38px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  padding: 0;
  display: inline-flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 4px;
}
.hamburger span {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--fg);
  border-radius: 1px;
}
.hamburger:hover { background: var(--hover); }

/* Translucent overlay behind the open drawer on mobile. */
.sidebar-backdrop {
  display: none;
}

main { max-width: 960px; margin: 1.5rem auto; padding: 0 1rem; }

/* ---------- inbox ---------- */
.inbox h2 { font-size: 1.25rem; margin: 0 0 1rem 0; }
.inbox h2 .count {
  background: var(--fg);
  color: var(--bg);
  border-radius: 999px;
  font-size: 0.8rem;
  padding: 0 0.6rem;
  margin-left: 0.4rem;
  vertical-align: middle;
}
.empty { color: var(--muted); font-style: italic; padding: 2rem 0; text-align: center; }
.item-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.75rem; }

/* ---------- item card ---------- */
.item-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-left: 4px solid var(--muted);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  transition: opacity 0.2s ease;
}
.item-card.htmx-swapping { opacity: 0; }

.item-card.urgency-high    { border-left-color: var(--urgency-high); }
.item-card.urgency-medium  { border-left-color: var(--urgency-medium); }
.item-card.urgency-low     { border-left-color: var(--urgency-low); }

.item-head { display: flex; align-items: center; gap: 0.5rem; font-size: 0.85rem; color: var(--muted); margin-bottom: 0.3rem; }
.item-head .urgency-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.urgency-high  .urgency-dot { background: var(--urgency-high); }
.urgency-medium .urgency-dot { background: var(--urgency-medium); }
.urgency-low   .urgency-dot { background: var(--urgency-low); }

.item-head .site { font-weight: 600; color: var(--fg); }
.item-head .sep { color: var(--border); }
.item-head .age { margin-left: auto; font-variant-numeric: tabular-nums; }
.item-head .pub-date { font-variant-numeric: tabular-nums; }
.item-head .source-link { color: var(--muted); font-size: 0.8rem; }
.item-head .source-link:hover { color: var(--link); }

.badge {
  font-size: 0.7rem;
  font-weight: 600;
  border-radius: 4px;
  padding: 0.1rem 0.45rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.badge-warn { background: var(--warn-bg); color: var(--warn-fg); }

.item-title { font-size: 1rem; line-height: 1.4; margin-bottom: 0.25rem; }
.item-title a { color: var(--fg); }
.item-summary {
  font-size: 0.88rem;
  line-height: 1.45;
  color: var(--muted);
  margin: 0 0 0.5rem 0;
}
.llm-tag {
  display: inline-block;
  background: var(--llm-bg);
  color: var(--llm-fg);
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.05rem 0.4rem;
  border-radius: 999px;
  letter-spacing: 0.02em;
  margin-right: 0.25rem;
  vertical-align: 0.05em;
}

.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 0.6rem; }
.chip { background: var(--chip-bg); border-radius: 4px; padding: 0.15rem 0.5rem; font-size: 0.8rem; color: var(--fg); }

/* ---------- actions ---------- */
.actions { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.btn {
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: var(--radius);
  padding: 0.35rem 0.75rem;
  font-size: 0.85rem;
  cursor: pointer;
  font: inherit;
}
.btn:hover { background: var(--hover); }
.btn-approve { border-color: var(--approve); color: var(--approve); }
.btn-reject  { border-color: var(--reject);  color: var(--reject); }
.btn-noise   { border-color: var(--noise);   color: var(--noise); }
.btn-lg { padding: 0.55rem 1rem; font-size: 0.95rem; }

/* reject dropdown */
.reject-group { position: relative; display: inline-block; }
.reject-menu {
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 0.3rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.25rem;
  display: flex;
  flex-direction: column;
  min-width: 10rem;
  z-index: 10;
}
/* When the Reject button is inside the sticky bottom action bar (item
   detail page), the menu would open downward and get clipped under the
   viewport edge. Flip it upward instead. */
.detail-actions .reject-menu {
  top: auto;
  bottom: 100%;
  margin-top: 0;
  margin-bottom: 0.3rem;
}
.reject-menu button {
  background: none;
  border: 0;
  text-align: left;
  padding: 0.4rem 0.6rem;
  font: inherit;
  cursor: pointer;
  border-radius: 4px;
}
.reject-menu button:hover { background: var(--hover); }

/* ack placeholder after an action removes a card */
.item-ack { padding: 0.5rem 1rem; color: var(--muted); font-style: italic; }
.ack-approve { color: var(--approve); }
.ack-reject  { color: var(--reject); }
.ack-noise   { color: var(--noise); }

/* ---------- detail ---------- */
.breadcrumb { margin-bottom: 0.5rem; }
.item-detail h2 { margin: 0 0 0.4rem 0; font-size: 1.4rem; line-height: 1.3; }
.item-detail .subhead { color: var(--muted); margin: 0 0 1rem 0; }
.urgency-label { text-transform: uppercase; font-weight: 600; font-size: 0.75rem; letter-spacing: 0.03em; }
.urgency-high  .urgency-label { color: var(--urgency-high); }
.urgency-medium .urgency-label { color: var(--urgency-medium); }
.urgency-low   .urgency-label { color: var(--urgency-low); }

.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
}
.panel h3 { margin: 0 0 0.5rem 0; font-size: 0.95rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.links { list-style: none; margin: 0; padding: 0; }
.links li { margin-bottom: 0.25rem; }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 0.3rem 1rem; margin: 0; }
.kv dt { font-weight: 600; color: var(--muted); }
.kv dd { margin: 0; }

.detail-actions .btn { margin-right: 0.5rem; }

/* ---------- topic panel (item detail) ---------- */
.topic-panel { }
.topic-linked, .topic-empty, .topic-suggestion { margin: 0 0 0.6rem 0; }
.topic-pill {
  display: inline-block;
  background: var(--topic-bg);
  color: var(--topic-fg);
  border-radius: 999px;
  padding: 0.15rem 0.6rem;
  font-size: 0.85rem;
  font-weight: 500;
}
.topic-pill-suggested { background: var(--warn-bg); color: var(--warn-fg); }
.topic-pickers { display: flex; gap: 1.25rem; flex-wrap: wrap; align-items: flex-end; }
.topic-pickers form { display: flex; gap: 0.4rem; align-items: center; }
.topic-pickers label { color: var(--muted); font-size: 0.85rem; }
.topic-pickers select, .topic-pickers input[type="text"] {
  padding: 0.3rem 0.5rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  font: inherit;
}
.btn-sm { padding: 0.2rem 0.55rem; font-size: 0.8rem; }
.btn-subtle {
  background: transparent;
  border-color: var(--border);
  color: var(--muted);
}

/* ---------- fill gaps form ---------- */
.fill-gaps-form {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.5rem 1rem;
  align-items: start;
}
.fill-gaps-form label { color: var(--muted); font-size: 0.85rem; padding-top: 0.35rem; }
.fill-gaps-form input[type="text"], .fill-gaps-form textarea {
  width: 100%;
  padding: 0.4rem 0.55rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  font: inherit;
  box-sizing: border-box;
}
.fill-gaps-form button { grid-column: 2; justify-self: start; }
.save-ack { color: var(--approve); font-size: 0.85rem; margin: 0 0 0.5rem 0; }

/* ---------- topics pages ---------- */
.topics-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.topic-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.6rem; }
.topic-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
}
.topic-card-head { display: flex; gap: 0.6rem; align-items: center; }
.topic-name { font-weight: 600; color: var(--fg); }
.topic-name:hover { text-decoration: underline; }
.linked-count { margin-left: auto; color: var(--muted); font-size: 0.85rem; }
.badge-active    { background: var(--badge-active-bg); color: var(--badge-active-fg); }
.badge-completed { background: var(--badge-completed-bg); color: var(--badge-completed-fg); }
.badge-archived  { background: var(--pill-noise-bg); color: var(--pill-noise-fg); }
.chip-muted { background: transparent; color: var(--muted); padding-left: 0; }

/* topic new / detail */
.topic-form { display: flex; flex-direction: column; gap: 0.6rem; max-width: 520px; }
.topic-form input[type="text"] {
  padding: 0.5rem 0.7rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  font: inherit;
}
.topic-form fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 0.6rem 1rem; }
.topic-form legend { color: var(--muted); font-size: 0.85rem; padding: 0 0.3rem; }
.checkbox-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.25rem 0.8rem; }
.checkbox-row { display: flex; gap: 0.4rem; align-items: center; font-size: 0.9rem; }
.form-actions { display: flex; gap: 0.5rem; margin-top: 0.25rem; }
.error-banner { background: var(--error-bg); color: var(--error-fg); padding: 0.5rem 0.75rem; border-radius: var(--radius); }
.linked-items { list-style: none; margin: 0; padding: 0; }
.linked-items li { padding: 0.25rem 0; border-bottom: 1px solid var(--border); }
.linked-items li:last-child { border-bottom: 0; }
.muted { color: var(--muted); font-size: 0.85rem; }

/* ---------- sidebar user + logout ---------- */
.user-label { color: var(--muted); }
.role-pill {
  background: var(--badge-completed-bg);
  color: var(--badge-completed-fg);
  border-radius: 999px;
  padding: 0.05rem 0.5rem;
  margin-left: 0.3rem;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.logout-form { margin: 0; display: inline; }

/* ---------- login ---------- */
.login-page { max-width: 360px; margin: 3rem auto; }
.login-form { display: flex; flex-direction: column; gap: 0.4rem; }
.login-form input {
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font: inherit;
}
.login-form button { align-self: flex-start; margin-top: 0.5rem; }

/* ---------- admin users table ---------- */
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.data-table th, .data-table td {
  padding: 0.55rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.data-table th { background: var(--surface-2); font-weight: 600; color: var(--muted); text-transform: uppercase; font-size: 0.75rem; letter-spacing: 0.04em; }
.data-table tr:last-child td { border-bottom: 0; }

/* ---------- user form ---------- */
.user-form { display: flex; flex-direction: column; gap: 0.4rem; max-width: 480px; }
.user-form input[type="email"], .user-form input[type="text"], .user-form input[type="password"], .user-form select {
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font: inherit;
}
.user-form input[disabled] { background: var(--surface-3); color: var(--muted); }

/* ---------- consumers admin ---------- */
.new-key-banner {
  background: var(--key-banner-bg);
  border: 1px solid var(--key-banner-border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
}
.new-key-value {
  background: var(--key-value-bg);
  color: var(--key-value-fg);
  padding: 0.55rem 0.75rem;
  border-radius: 4px;
  font-size: 0.85rem;
  overflow-x: auto;
  margin: 0.5rem 0 0 0;
}
.url { font-size: 0.8rem; word-break: break-all; }
.row-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.row-actions form { margin: 0; }

/* ---------- admin sites health ---------- */
.health-good     { color: var(--health-good); font-weight: 600; }
.health-ok       { color: var(--health-ok); font-weight: 600; }
.health-bad      { color: var(--health-bad); font-weight: 600; }
.health-critical { color: var(--health-critical); font-weight: 700; }

/* ---------- admin learning ---------- */
.inline-form { display: flex; gap: 0.4rem; align-items: center; }
.inline-form select {
  padding: 0.25rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font: inherit;
}
.admin-learning h3 {
  margin: 1.5rem 0 0.5rem;
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.admin-learning code {
  background: var(--surface-3);
  padding: 1px 6px;
  border-radius: 3px;
}
.admin-learning h4 { margin: 0 0 0.5rem; font-size: 0.95rem; }
.admin-learning .reason-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
  margin-top: 0.75rem;
}
.admin-learning .reason-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 0.85rem;
}
.admin-learning .reason-card .empty { margin: 0.25rem 0 0; font-size: 0.85rem; }

/* ---------- /sites/request + /admin/site-requests ---------- */
.page-actions { display: flex; gap: 0.5rem; align-items: center; }
.site-request .form-stack {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  max-width: 640px;
  margin: 1rem 0 1.5rem;
}
.site-request .form-stack label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.9rem;
}
.site-request .form-stack label > span:first-child {
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.04em;
}
.site-request .form-stack input,
.site-request .form-stack textarea {
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font: inherit;
  background: var(--surface-2);
  color: var(--fg);
}
.site-request .form-stack textarea { resize: vertical; min-height: 4em; }
.site-request .required { color: var(--health-bad, #c0392b); }
.site-request .form-actions { margin-top: 0.25rem; }
.flash {
  padding: 0.6rem 0.85rem;
  border-radius: var(--radius);
  margin: 0.5rem 0 1rem;
  font-size: 0.9rem;
}
.flash-good { background: var(--surface-2); border-left: 3px solid var(--approve, #2e7d32); }
.flash-bad  { background: var(--surface-2); border-left: 3px solid var(--reject, #c0392b); }
.admin-site-requests .site-request-card { display: flex; flex-direction: column; gap: 0.5rem; }
.admin-site-requests .site-request-actions {
  display: flex; gap: 0.4rem; align-items: stretch;
  margin-top: 0.25rem;
}
.admin-site-requests .site-request-note { flex: 1; min-width: 0; }

/* ---------- admin-sites extras ---------- */
.page-header-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.page-header-row h2 { margin: 0; }
.site-link { color: var(--fg); }
.site-link:hover code.url { text-decoration: underline; }
.site-meta { font-size: 0.78rem; color: var(--muted); margin-top: 0.15rem; }
.site-name { font-weight: 600; }
.site-host {
  display: inline-block;
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 0.1rem;
  word-break: break-all;
}
.site-host:hover { text-decoration: underline; }
.btn-primary { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.btn-success { background: var(--approve); color: #fff; border-color: var(--approve); }
.toast-slot { min-height: 1.5rem; margin: 0.25rem 0 0.75rem; }
.toast-ok {
  display: inline-block;
  background: var(--toast-bg); color: var(--toast-fg);
  padding: 0.25rem 0.6rem; border-radius: var(--radius);
  font-size: 0.85rem;
  animation: toast-fade 4s forwards;
}
@keyframes toast-fade {
  0% { opacity: 0; transform: translateY(-3px); }
  6% { opacity: 1; transform: none; }
  80% { opacity: 1; }
  100% { opacity: 0; }
}

/* ---------- history ---------- */
.history-filter { display: flex; gap: 0.5rem; align-items: center; }
.history-filter label { display: flex; gap: 0.4rem; align-items: center; font-size: 0.85rem; color: var(--muted); }
.history-filter select {
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  font: inherit;
}
.pill {
  display: inline-block;
  padding: 0.1rem 0.55rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 500;
  background: var(--pill-bg);
  color: var(--pill-fg);
}
.pill-approved     { background: var(--pill-approved-bg); color: var(--pill-approved-fg); }
.pill-rejected     { background: var(--pill-rejected-bg); color: var(--pill-rejected-fg); }
.pill-marked_noise { background: var(--pill-noise-bg); color: var(--pill-noise-fg); }
.pill-auto_archived { background: var(--pill-auto-archived-bg); color: var(--pill-auto-archived-fg); }
.pager { display: flex; gap: 0.75rem; align-items: center; margin: 1rem 0; }

/* ---------- analytics ---------- */
.analytics h3 { margin: 1.5rem 0 0.5rem; font-size: 1rem; }
.analytics-note { font-size: 0.85rem; margin: 0.25rem 0 1rem; }
.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.metric-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
}
.metric-card h3 {
  margin: 0 0 0.5rem 0;
  font-size: 0.85rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
.metric-dl { margin: 0; display: grid; grid-template-columns: max-content 1fr; gap: 0.25rem 0.75rem; }
.metric-dl dt { color: var(--muted); font-size: 0.8rem; }
.metric-dl dd { margin: 0; font-size: 0.92rem; font-variant-numeric: tabular-nums; }

.data-table.compact th, .data-table.compact td { padding: 0.35rem 0.6rem; font-size: 0.88rem; }

/* ---------- crawled ---------- */
.crawled-filter { display: flex; gap: 0.75rem; align-items: center; }
.crawled-filter label { display: flex; gap: 0.4rem; align-items: center; font-size: 0.85rem; color: var(--muted); }
.crawled-filter select {
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  font: inherit;
}

/* ---------- schedule edit inline form ---------- */
.schedule-edit-row > td { background: var(--surface-2); }
.schedule-form-head { margin-bottom: 0.75rem; }
.schedule-form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 0.5rem 1rem;
  margin-bottom: 0.75rem;
}
.schedule-form-grid label {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.8rem;
  color: var(--muted);
}
.schedule-form-grid select,
.schedule-form-grid input {
  padding: 0.3rem 0.5rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--fg);
  font: inherit;
}
.schedule-form-grid .form-hint { font-size: 0.72rem; }
.schedule-form-actions { display: flex; gap: 0.5rem; }

/* ---------- htmx spinner ---------- */
.spinner {
  display: none;
  width: 0.9em;
  height: 0.9em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  vertical-align: -0.15em;
  margin-left: 0.35rem;
  animation: spin 0.7s linear infinite;
}
.htmx-request .spinner,
.htmx-request.spinner { display: inline-block; }
.htmx-request .btn-label { opacity: 0.6; }
button[disabled], .btn[disabled] { opacity: 0.6; cursor: not-allowed; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- theme toggle ---------- */
.theme-toggle {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.25rem 0.55rem;
  cursor: pointer;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1;
}
.theme-toggle:hover { background: var(--hover); color: var(--fg); }
.theme-toggle .icon-sun  { display: inline; }
.theme-toggle .icon-moon { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun  { display: none; }
[data-theme="dark"] .theme-toggle .icon-moon { display: inline; }

/* ---------- responsive ---------- */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

@media (max-width: 720px) {
  /* Drop the desktop left-padding so content fills the viewport, and
     hide the sidebar offscreen until the hamburger pulls it in. */
  body { padding-left: 0; }
  .mobile-topbar { display: flex; }
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    width: 80%;
    max-width: 280px;
    box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 49;
  }
  main { margin: 1rem auto; padding: 0 0.75rem; }
  .page-header-row { flex-wrap: wrap; }
  .data-table { display: block; overflow-x: auto; white-space: nowrap; }
  .data-table th, .data-table td { white-space: nowrap; }
  .metric-dl { grid-template-columns: 1fr; gap: 0.1rem; }
  .metric-dl dt { margin-top: 0.4rem; }
  .actions .btn { flex: 1 1 auto; }
  .detail-actions { flex-direction: column; align-items: stretch; }
  .detail-actions .btn { margin-right: 0; margin-bottom: 0.4rem; }
  /* Drop the sticky bottom bar on mobile too — phones already have a
     soft keyboard / browser chrome eating bottom space. */
  .panel.detail-actions { position: static; box-shadow: none; }
}

/* ---------- sticky bottom action bar (item detail, desktop only) ---------- */
.panel.detail-actions {
  position: sticky;
  bottom: 0;
  /* Cancel the default 1rem panel margin so the sticky edge is flush. */
  margin-bottom: 0;
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.06);
  z-index: 40;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

/* ---------- undo toast ---------- */
.undo-toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 0.7rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-left: 4px solid var(--fg);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  padding: 0.7rem 0.9rem;
  max-width: 360px;
  font-size: 0.9rem;
}
.undo-toast.warn { border-left-color: var(--urgency-high, #c0392b); }
.undo-toast.restored { border-left-color: var(--urgency-low, #2f855a); }
.undo-toast .toast-text { display: flex; flex-direction: column; gap: 0.1rem; }
.undo-toast .toast-text small { color: var(--muted); font-size: 0.75rem; }
.undo-toast .btn-undo {
  background: var(--fg);
  color: var(--card);
  border: none;
  border-radius: 4px;
  padding: 0.35rem 0.7rem;
  cursor: pointer;
  font-weight: 600;
}
.undo-toast .toast-close {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 1.1rem;
  padding: 0 0.2rem;
}

/* ---------- /admin/sites counts banner ---------- */
.site-counts {
  list-style: none;
  margin: 0 0 1.25rem 0;
  padding: 0.7rem 0.9rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: 0.5rem 1.5rem;
}
.site-counts > li {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 90px;
  padding-right: 1.2rem;
  border-right: 1px solid var(--border);
}
.site-counts > li:last-child { border-right: none; padding-right: 0; }
.site-counts .num {
  font-size: 1.45rem;
  font-weight: 600;
  line-height: 1;
}
.site-counts .num.ok    { color: var(--urgency-low, #2f855a); }
.site-counts .num.warn  { color: var(--urgency-high, #c0392b); }
.site-counts .lbl {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}
.site-counts small { font-size: 0.78rem; color: var(--muted); }
.site-counts small .ok  { color: var(--urgency-low, #2f855a); font-weight: 600; }
.site-counts small .off { color: var(--muted); }
.site-counts .by-type { min-width: 0; flex: 1; }
.site-counts .type-pill {
  display: inline-block;
  margin-right: 0.4rem;
  padding: 0.1rem 0.45rem;
  background: var(--border);
  border-radius: 999px;
  font-size: 0.75rem;
}
.site-counts .type-gov    { background: rgba(47, 133, 90, 0.15); }
.site-counts .type-portal { background: rgba(31, 102, 192, 0.15); }
.site-counts .type-news   { background: rgba(192, 109, 31, 0.15); }

/* ---------- recently actioned panel ---------- */
.recent-actions-panel {
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}
.recent-actions-title { font-size: 0.95rem; margin: 0 0 0.6rem 0; color: var(--muted); }
.recent-actions-title small { font-weight: 400; opacity: 0.75; }
.recent-actions {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.recent-row {
  display: grid;
  grid-template-columns: minmax(120px, max-content) minmax(80px, max-content) 1fr max-content max-content;
  align-items: center;
  gap: 0.6rem;
  padding: 0.4rem 0.6rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.85rem;
}
.recent-row .recent-tag { color: var(--muted); text-transform: capitalize; }
.recent-row .recent-tag em { font-style: normal; opacity: 0.8; }
.recent-row .recent-site { color: var(--muted); font-size: 0.78rem; }
.recent-row .recent-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent-row .recent-actor { font-size: 0.75rem; color: var(--muted); }
.recent-row .btn-restore {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg);
  border-radius: 4px;
  padding: 0.25rem 0.55rem;
  cursor: pointer;
  font-size: 0.8rem;
}
.recent-row .btn-restore:hover { background: var(--border); }
.recent-empty { color: var(--muted); font-style: italic; font-size: 0.85rem; }

@media (max-width: 720px) {
  .recent-row {
    grid-template-columns: 1fr max-content;
    grid-template-areas:
      "tag      restore"
      "title    title"
      "site     actor";
    gap: 0.2rem 0.5rem;
  }
  .recent-row .recent-tag    { grid-area: tag; }
  .recent-row .recent-title  { grid-area: title; white-space: normal; }
  .recent-row .recent-site   { grid-area: site; }
  .recent-row .recent-actor  { grid-area: actor; text-align: right; }
  .recent-row .btn-restore   { grid-area: restore; }
}
