:root {
  color-scheme: light dark;
  --paper: #f5f6f8;
  --surface: #ffffff;
  --surface-sunken: #eef0f3;
  --ink: #1a2030;
  --ink-muted: #5c6572;
  --ink-faint: #8b93a1;
  --line: #dde1e7;
  --line-strong: #c5cbd4;
  --accent: #2f5f96;
  --accent-ink: #ffffff;
  --accent-soft: #e7edf5;
  --good: #1a7f52;
  --good-soft: #e5f3ec;
  --warning: #b8720a;
  --warning-soft: #f7ecdb;
  --critical: #b3261e;
  --critical-soft: #fbe9e8;
  --radius-control: 6px;
  --radius-card: 10px;
  --font-ui: "Segoe UI Variable", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-mono: "Cascadia Code", "Consolas", ui-monospace, monospace;
  --shadow-card: 0 1px 2px rgba(20, 24, 34, 0.04), 0 1px 8px rgba(20, 24, 34, 0.04);
}

/* Accent is a mid blue in the same cool-blue family as the navy (#1f2430)
   generate_report.py uses as the PDF report's brand color, lifted brighter so
   it works as an interactive/link color, which the darker navy itself can't. */

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #10141b;
    --surface: #1a2130;
    --surface-sunken: #0b0e14;
    --ink: #e7eaf0;
    --ink-muted: #97a1b0;
    --ink-faint: #626c7a;
    --line: #2c3444;
    --line-strong: #3a4457;
    --accent: #6fa3d8;
    --accent-ink: #0b1626;
    --accent-soft: #1c2c40;
    --good: #2fa868;
    --good-soft: #163527;
    --warning: #b38900;
    --warning-soft: #3a2e15;
    --critical: #d4534a;
    --critical-soft: #3a1e1c;
    --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.24);
  }
}

* { box-sizing: border-box; }

body {
  font-family: var(--font-ui);
  background: var(--paper);
  color: var(--ink);
  margin: 0;
  padding: 0;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }

/* ---------- topbar ---------- */

.topbar { border-bottom: 1px solid var(--line); background: var(--surface); }

.topbar-inner {
  display: flex;
  align-items: center;
  gap: 2.5rem;
  max-width: 78rem;
  margin: 0 auto;
  padding: 0.95rem 2rem;
}

.topbar .brand { display: flex; align-items: center; gap: 0.55rem; font-weight: 650; font-size: 1.05rem; letter-spacing: -0.01em; text-decoration: none; color: var(--ink); }
.brand-mark { color: var(--accent); flex: none; display: inline-flex; }

.topbar nav { display: flex; flex-wrap: wrap; gap: 0.25rem; }

.topbar nav a {
  padding: 0.45rem 0.85rem;
  border-radius: 999px;
  text-decoration: none;
  color: var(--ink-muted);
  font-size: 0.87rem;
  font-weight: 600;
}

.topbar nav a:hover { color: var(--ink); background: var(--surface-sunken); }
.topbar nav a.current { color: var(--accent-ink); background: var(--accent); }

.user-menu { display: flex; align-items: center; gap: 0.85rem; margin-left: auto; font-size: 0.87rem; }
.user-menu .user-name { color: var(--ink-muted); font-weight: 600; }
.user-menu a { color: var(--ink-muted); text-decoration: none; font-weight: 600; }
.user-menu a:hover { color: var(--ink); }

.content { padding: 1.75rem; max-width: 78rem; margin: 0 auto; }

.content h2 { font-size: 1.2rem; font-weight: 650; letter-spacing: -0.01em; margin: 2.5rem 0 0.2rem; }
.content h2:first-child { margin-top: 0; }
.content h3 { font-size: 0.98rem; font-weight: 650; margin: 1.25rem 0 0.2rem; }

/* ---------- KPI strip ---------- */

.stats-panel {
  display: flex;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow-card);
  margin-bottom: 2rem;
  overflow: hidden;
}

/* display:contents takes .stat-cluster out of the box tree so its .stat children
   become direct flex items of .stats-panel - two nested wrapping flex contexts
   (cluster-inside-panel) let the browser split a cluster across rows, which is
   exactly the "orphaned KPI on row two" bug this replaces. */
.stat-cluster { display: contents; }

.stat { padding: 1.1rem 1.4rem; min-width: 8.5rem; flex: 1 1 auto; border-left: 1px solid var(--line); }
.stats-panel > .stat-cluster:first-child > .stat:first-child { border-left: none; }
.stat-cluster + .stat-cluster > .stat:first-child { border-left: 2px solid var(--line-strong); }

.stat-value { display: block; font-size: 1.7rem; font-weight: 650; letter-spacing: -0.02em; line-height: 1.15; font-variant-numeric: tabular-nums; }
.stat-label { display: block; font-size: 0.72rem; font-weight: 600; letter-spacing: 0.03em; text-transform: uppercase; color: var(--ink-muted); margin-top: 0.3rem; }

/* ---------- cards / workflows ---------- */

.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(21rem, 1fr)); gap: 1.1rem; }

.card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  padding: 1.15rem 1.3rem 1.3rem;
  background: var(--surface);
  box-shadow: var(--shadow-card);
}

.card h3 { margin-top: 0; }
.description { color: var(--ink-muted); font-size: 0.88rem; }

.status-line {
  font-size: 0.82rem;
  margin: 0.9rem 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 0.8rem 0.9rem;
  background: var(--surface-sunken);
  border-radius: 8px;
}
.status-line > div { display: flex; align-items: center; gap: 0.45rem; flex-wrap: wrap; }
.status-label { color: var(--ink-muted); font-weight: 600; min-width: 8.2rem; }

/* Form controls are styled by element type, not a wrapper class, so every
   select/input/textarea in the app looks the same whether or not its parent
   happens to carry .workflow-form - a wrapper-class dependency is what left
   the RFI submit form and both status <select>s unstyled before this pass. */
select, input[type="text"], input[type="password"], textarea {
  font-family: inherit;
  font-size: 0.87rem;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-control);
  background: var(--surface);
  color: var(--ink);
}
select:focus, input:focus, textarea:focus { border-color: var(--accent); }

.workflow-form label { display: block; margin-bottom: 0.7rem; font-size: 0.8rem; font-weight: 600; color: var(--ink-muted); }
.workflow-form select, .workflow-form input, .workflow-form textarea {
  display: block;
  width: 100%;
  margin-top: 0.3rem;
  font-weight: 400;
  color: var(--ink);
}
.workflow-form textarea { resize: vertical; font-family: inherit; }

/* <option> doesn't reliably inherit color/background from its <select> in
   every browser's native dropdown-popup rendering, even with color-scheme
   set - explicit values here, not "inherit", are what actually fixes the
   "unreadable until hovered" symptom in dark mode across all selects. */
select option {
  background-color: var(--surface);
  color: var(--ink);
}

.actions { display: flex; gap: 0.55rem; margin-top: 1rem; flex-wrap: wrap; }

.btn {
  appearance: none;
  -webkit-appearance: none;
  font-family: inherit;
  padding: 0.5rem 0.95rem;
  border-radius: var(--radius-control);
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  font-size: 0.84rem;
  font-weight: 600;
}
.btn:hover { border-color: var(--ink-faint); background: var(--surface-sunken); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-small { padding: 0.28rem 0.6rem; font-size: 0.76rem; }

/* .btn-full already existed as a JS hook for the expensive/rare "full report"
   action; giving it the primary treatment needed no template or JS change.
   .btn-primary is the same look for buttons with no such hook (Submit RFI). */
.btn-full, .btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.btn-full:hover, .btn-primary:hover { filter: brightness(1.08); background: var(--accent); }

.login-card { max-width: 22rem; margin: 3rem auto 0; padding: 1.75rem; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.login-card h2 { margin-top: 0; }
.login-card button { width: 100%; margin-top: 1.1rem; }
.login-error { color: var(--critical); font-size: 0.85rem; margin: -0.4rem 0 1rem; }

.user-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; }
.reset-password-form {
  flex-basis: 100%;
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 0.5rem;
  margin-top: 0.5rem;
  padding: 0.65rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  background: var(--surface-sunken);
}
.reset-password-form label { font-size: 0.76rem; font-weight: 600; color: var(--ink-muted); }
.reset-password-form input { display: block; margin-top: 0.25rem; }

.feedback-controls { display: inline-flex; align-items: center; gap: 0.35rem; }
.feedback-btn-useful.btn-feedback-active { color: var(--good); border-color: var(--good); background: transparent; }
.feedback-btn-not-useful.btn-feedback-active { color: var(--critical); border-color: var(--critical); background: transparent; }

/* ---------- tables ---------- */

.table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.table th, .table td {
  text-align: left;
  padding: 0.55rem 0.65rem;
  border-bottom: 1px solid var(--line);
  font-size: 0.88rem;
  white-space: nowrap;
}
.table th {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--ink-muted);
  background: var(--surface-sunken);
}
.table tbody tr:hover td { background: var(--surface-sunken); }

.muted { color: var(--ink-muted); }

/* ---------- badges: color + shape + label, never color alone ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.16rem 0.6rem 0.16rem 0.5rem;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 650;
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }

.badge-succeeded, .badge-answered { color: var(--good); background: var(--good-soft); }
.badge-failed, .badge-locked { color: var(--critical); background: var(--critical-soft); }
.badge-running, .badge-open { color: var(--warning); background: var(--warning-soft); }
.badge-closed { color: var(--ink-muted); background: var(--surface-sunken); }

.badge-running::before { animation: badge-pulse 1.4s ease-in-out infinite; }
@media (prefers-reduced-motion: reduce) { .badge-running::before { animation: none; } }
@keyframes badge-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

/* ---------- watchlist confidence ---------- */

.confidence { display: inline-block; font-size: 0.76rem; font-weight: 650; padding: 0.16rem 0.55rem; border-radius: 999px; }
.confidence-high { color: var(--good); background: var(--good-soft); }
.confidence-medium { color: var(--warning); background: var(--warning-soft); }
.confidence-low { color: var(--ink-muted); background: var(--surface-sunken); }

/* ---------- TLP chip: dot uses the exact FIRST.org swatch hex already in
   generate_report.py's TLP_COLORS, so a marking reads identically on screen
   and on the PDF report legend it comes from. ---------- */

.tlp-chip { display: inline-flex; align-items: center; gap: 0.4rem; padding: 0.16rem 0.55rem 0.16rem 0.4rem; border-radius: 999px; border: 1px solid var(--line); font-size: 0.74rem; font-weight: 650; color: var(--ink); white-space: nowrap; }
.tlp-swatch { width: 11px; height: 11px; border-radius: 50%; border: 1.5px solid var(--ink-faint); flex: none; }

/* ---------- breadcrumbs ---------- */

.breadcrumbs { margin-bottom: 1rem; font-size: 0.88rem; color: var(--ink-muted); }
.breadcrumbs a { color: var(--ink); font-weight: 600; }

/* ---------- job console ---------- */

.jobs-panel { margin: 2rem 0; }

.job-entry {
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  padding: 0.95rem 1.1rem;
  margin-bottom: 0.75rem;
  background: var(--surface);
  box-shadow: var(--shadow-card);
}

.job-entry-head { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.job-entry-head .trigger { color: var(--ink-muted); font-size: 0.85rem; }

.job-log {
  background: var(--surface-sunken);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.65rem 0.85rem;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  line-height: 1.6;
  color: var(--ink-muted);
  max-height: 12rem;
  overflow-y: auto;
  white-space: pre-wrap;
  margin: 0.6rem 0 0;
}

.job-outputs a, .detection-content-outputs a { display: inline-block; margin-right: 0.75rem; font-size: 0.85rem; }

/* ---------- folders ---------- */

.folder-list { margin-bottom: 1.5rem; }

.folder {
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  margin-bottom: 0.6rem;
  padding: 0 0.9rem;
  background: var(--surface);
}

.folder summary {
  cursor: pointer;
  padding: 0.7rem 0.25rem;
  font-weight: 650;
  font-size: 0.9rem;
  list-style: none;
}
.folder summary::-webkit-details-marker { display: none; }
.folder summary::before { content: "\25b8"; display: inline-block; margin-right: 0.55rem; color: var(--ink-faint); transition: transform 0.15s; }
@media (prefers-reduced-motion: reduce) { .folder summary::before { transition: none; } }
.folder[open] summary::before { transform: rotate(90deg); }

/* .table-wrap already has its own border/radius; without this override a
   folder's own border nests a second bordered, rounded box directly inside
   it, showing as a double border/corner on the Documents page. */
.folder .table-wrap { margin-bottom: 0.75rem; border: none; border-radius: 0; }

.documents-columns {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(24rem, 1fr));
  gap: 0 2rem;
  align-items: start;
}
/* Belt-and-suspenders with .table-wrap's own min-width:0 below - this grid's
   tracks already have a fixed 24rem minimum (not the keyword `auto`), which
   per the CSS Grid automatic-minimum-size algorithm already makes each
   item's automatic minimum size 0, independent of anything set here. Kept
   anyway in case that track minimum is ever loosened (e.g. simplified to a
   bare 1fr, which desugars to minmax(auto, 1fr)) - at that point this
   becomes load-bearing again. */
.documents-columns > div { min-width: 0; }

/* min-width:0 here protects .table-wrap itself from being pushed wide by a
   table it can't shrink below. It does NOT protect ancestors further up the
   tree - per w3c/csswg-drafts#1865, the overflow/min-size exception does not
   propagate through intervening plain-block descendants, so don't rely on
   this alone to prevent a containing grid/flex track from blowing out; see
   .documents-columns > div and .card above for the actual grid-item-level
   guards. */
.table-wrap { overflow-x: auto; min-width: 0; margin-top: 0.5rem; border: 1px solid var(--line); border-radius: var(--radius-card); }
