:root {
  color-scheme: dark;
  --bg: #0b0e14;
  --bg-elevated: #131826;
  --bg-card: #171d2d;
  --border: #262e42;
  --text: #e7ebf3;
  --text-dim: #9aa4bd;
  --text-faint: #6b7591;
  --accent: #5b9dff;
  --green: #3ecf8e;
  --amber: #e8b93f;
  --amber-red: #e8863f;
  --red: #e5534b;
  --grey: #6b7591;
  --llm: #b98ef2;
  --radius: 12px;
  --gutter: 16px;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #f4f6fb;
    --bg-elevated: #ffffff;
    --bg-card: #ffffff;
    --border: #dbe1ee;
    --text: #171c2a;
    --text-dim: #4c5568;
    --text-faint: #7c869c;
  }
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f6fb;
  --bg-elevated: #ffffff;
  --bg-card: #ffffff;
  --border: #dbe1ee;
  --text: #171c2a;
  --text-dim: #4c5568;
  --text-faint: #7c869c;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}

body {
  min-height: 100vh;
  padding-bottom: 64px;
}

a { color: var(--accent); }

.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 var(--gutter);
}

/* ---- Freshness bar ---- */
.freshness-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  padding: 8px var(--gutter);
  display: flex;
  gap: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.chip {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  white-space: nowrap;
}

.dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; }
.dot.fresh { background: var(--green); }
.dot.aging { background: var(--amber); }
.dot.stale { background: var(--red); }
.dot.unknown { background: var(--grey); }

/* ---- header / top bar ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px var(--gutter) 6px;
  gap: 8px;
}

.topbar h1 { font-size: 18px; margin: 0; }
.topbar .meta { font-size: 12px; color: var(--text-faint); }

button.refresh-btn {
  background: var(--accent);
  color: #051021;
  border: none;
  border-radius: 999px;
  padding: 8px 14px;
  font-weight: 700;
  font-size: 13px;
}

button.refresh-btn:active { opacity: 0.8; }

/* ---- sections ---- */
section.card {
  margin: 12px var(--gutter);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

details.section > summary {
  list-style: none;
  cursor: pointer;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

details.section > summary::-webkit-details-marker { display: none; }

.section-title { display: flex; align-items: baseline; gap: 8px; font-weight: 700; font-size: 15px; }
.section-asof { font-size: 11px; color: var(--text-faint); font-weight: 500; }
.chevron { transition: transform 0.15s ease; color: var(--text-faint); }
details[open] > summary .chevron { transform: rotate(90deg); }

.section-body { padding: 0 16px 16px; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  border: 1px solid var(--border);
}
.badge.green, .badge.PASS, .badge.INTACT, .badge.STRENGTHENED { background: rgba(62,207,142,0.15); color: var(--green); }
.badge.amber, .badge.WARN, .badge.WEAKENED, .badge.aging { background: rgba(232,185,63,0.15); color: var(--amber); }
.badge.amber-red { background: rgba(232,134,63,0.15); color: var(--amber-red); }
.badge.red, .badge.VETO, .badge.INVALIDATED, .badge.stale { background: rgba(229,83,75,0.15); color: var(--red); }
.badge.grey, .badge.UNKNOWN, .badge.NOT_EVALUABLE, .badge.unknown { background: rgba(107,117,145,0.18); color: var(--grey); }
.badge.FIRED { background: rgba(229,83,75,0.15); color: var(--red); }
.badge.NOT_FIRED { background: rgba(107,117,145,0.18); color: var(--grey); }

.llm-block {
  border: 1px dashed var(--llm);
  border-radius: 10px;
  padding: 10px 12px;
  margin: 10px 0;
  background: rgba(185,142,242,0.06);
}
.llm-label {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: var(--llm);
  text-transform: uppercase;
  display: block;
  margin-bottom: 6px;
}
.llm-meta { font-size: 11px; color: var(--text-faint); margin-top: 6px; }

.empty-note { color: var(--text-faint); font-size: 13px; font-style: italic; }

.list-plain { margin: 6px 0; padding-left: 18px; }
.list-plain li { margin: 4px 0; font-size: 14px; }

.show-more { margin: 4px 0 10px; }
.show-more > summary {
  cursor: pointer;
  color: var(--accent, #6ea8fe);
  font-size: 13px;
  list-style: none;
}
.show-more > summary::-webkit-details-marker { display: none; }
.show-more[open] > summary { margin-bottom: 4px; }

.row { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; padding: 4px 0; border-bottom: 1px dashed var(--border); }
.row:last-child { border-bottom: none; }
.row .k { color: var(--text-dim); }

/* ---- horizon tabs ---- */
.tabs { display: flex; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; }
.tab-btn {
  flex: 1 1 auto;
  min-width: 64px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 8px 6px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 13px;
}
.tab-btn[aria-selected="true"] { background: var(--accent); color: #051021; border-color: var(--accent); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ---- toast ---- */
#toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
#toast.show { opacity: 1; }

/* ---- login page ---- */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: var(--gutter);
}
.login-card {
  width: 100%;
  max-width: 340px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}
.login-card h1 { font-size: 18px; margin: 0 0 16px; }
.login-card label { display: block; font-size: 13px; color: var(--text-dim); margin-bottom: 6px; }
.login-card input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 15px;
  margin-bottom: 14px;
}
.login-card button {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: #051021;
  font-weight: 700;
  font-size: 15px;
}
.login-card p.error { color: var(--red); font-size: 13px; margin: 0 0 12px; }

@media (max-width: 380px) {
  .topbar h1 { font-size: 16px; }
}
