/* ==========================================================================
   INSIDER TRACKER: research-sheet design system.
   Flat, ruled, plain. No shadows, gradients or glow. Colour carries only
   side (green/red), warning (amber) and links (blue).
   ========================================================================== */

/* --- Design Tokens ---------------------------------------------------- */
:root, [data-theme="light"] {
  --bg:             #f6f6f4;
  --bg-panel:       #ffffff;
  --bg-card:        #ffffff;
  --bg-card-hover:  #efefec;
  --bg-card-subtle: #f1f1ee;
  --fg:             #1c1c1b;
  --fg-muted:       #4d4d4a;
  --fg-dim:         #6a6a66;
  --line:           #d6d6d1;
  --line-subtle:    #e6e6e2;
  --line-strong:    #a9a9a3;

  --masthead:       #202124;
  --masthead-fg:    #f2f2f0;
  --masthead-dim:   #b4b4b0;

  --accent:         #0b57b0;
  --accent-hover:   #083f82;
  --accent-text:    #0b57b0;
  --plan:           #5b3f94;
  --accent-subtle:  #e7eef7;
  --accent-border:  #b6cae3;

  --buy:            #17703f;
  --buy-subtle:     #e8f1eb;
  --buy-border:     #b7d3c1;

  --sell:           #b3261e;
  --sell-subtle:    #f6e9e8;
  --sell-border:    #e2bcb9;

  --mid:            #8a5300;
  --mid-subtle:     #f7efdc;
  --mid-border:     #e0cb9c;

  --good:           #17703f;
  --low:            #4d4d4a;

  --table-header-bg: #ecece8;
  --table-hover:     #f1f4f8;
  --table-stripe:    transparent;

  --radius-sm: 2px;
  --radius-md: 2px;
  --radius-lg: 2px;

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, "Noto Sans", sans-serif;
}

[data-theme="dark"] {
  --bg:             #161616;
  --bg-panel:       #1d1d1d;
  --bg-card:        #1d1d1d;
  --bg-card-hover:  #2a2a2a;
  --bg-card-subtle: #232323;
  --fg:             #ecece9;
  --fg-muted:       #b5b5b0;
  --fg-dim:         #909089;
  --line:           #333331;
  --line-subtle:    #2a2a28;
  --line-strong:    #54544f;

  --masthead:       #0e0e0e;
  --masthead-fg:    #f2f2f0;
  --masthead-dim:   #a3a39e;

  --accent:         #6aa6ea;
  --accent-hover:   #9cc4f2;
  --accent-text:    #7db2ee;
  --plan:           #b9a2ec;
  --accent-subtle:  #1d2733;
  --accent-border:  #34506f;

  --buy:            #4cc383;
  --buy-subtle:     #1a2a21;
  --buy-border:     #2f5a41;

  --sell:           #f0847c;
  --sell-subtle:    #301f1e;
  --sell-border:    #6a3b38;

  --mid:            #e0a54a;
  --mid-subtle:     #2e2616;
  --mid-border:     #66512a;

  --good:           #4cc383;
  --low:            #b5b5b0;

  --table-header-bg: #262625;
  --table-hover:     #252a30;
  --table-stripe:    transparent;
}

/* --- Reset & Base ----------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

html { color-scheme: light; }
html[data-theme="dark"] { color-scheme: dark; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Figures: tabular numerals in the same sans, not a monospace face. */
.font-mono, .mono, .num, .kpi-val, .score, .score-pill, .bigscore, .bigscore-val {
  font-variant-numeric: tabular-nums lining-nums;
}

::selection { background: var(--accent); color: #fff; }
input, select, button, textarea { font-family: inherit; }
input { caret-color: var(--accent); }

/* --- Scrollbars ------------------------------------------------------- */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--line-strong); border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--fg-dim); }
* { scrollbar-width: thin; scrollbar-color: var(--line-strong) var(--bg); }

/* --- HTMX Loading Bar ------------------------------------------------- */
.htmx-indicator-bar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: var(--accent);
  z-index: 9999;
  opacity: 0;
  transition: opacity 0.15s ease;
  pointer-events: none;
}
.htmx-request .htmx-indicator-bar,
.htmx-request.htmx-indicator-bar {
  opacity: 1;
  animation: htmx-loading 1.2s infinite ease-in-out;
}
@keyframes htmx-loading {
  0%   { transform: scaleX(0.1) translateX(-50%); }
  50%  { transform: scaleX(0.7) translateX(30%); }
  100% { transform: scaleX(1) translateX(100%); }
}

/* --- Links ------------------------------------------------------------ */
a {
  color: var(--accent-text);
  text-decoration: none;
}
a:hover { color: var(--accent-hover); text-decoration: underline; text-underline-offset: 2px; }

/* ==========================================================================
   MASTHEAD
   ========================================================================== */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 28px;
  height: 48px;
  background: var(--masthead);
  color: var(--masthead-fg);
  position: sticky;
  top: 0;
  z-index: 100;
  gap: 20px;
}

.topbar-left { display: flex; align-items: center; gap: 24px; }

.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
  color: var(--masthead-fg);
  text-decoration: none;
}
.brand:hover { color: var(--masthead-fg); text-decoration: none; }
.brand-icon { display: none; }
.brand-text { display: flex; align-items: baseline; gap: 10px; }
.brand-name { font-size: 16px; font-weight: 700; letter-spacing: -0.01em; }
.brand-sub { font-size: 12px; color: var(--masthead-dim); }

.live-pill { display: none; }

/* --- Nav Links -------------------------------------------------------- */
.topbar-nav { display: flex; align-items: stretch; align-self: stretch; gap: 2px; margin-right: auto; }

.nav-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 12px;
  color: var(--masthead-dim);
  font-size: 13.5px;
  font-weight: 500;
  border: 0;
  border-bottom: 2px solid transparent;
}
.nav-link:hover { color: var(--masthead-fg); background: rgba(255, 255, 255, 0.07); text-decoration: none; }
.nav-link.on { color: var(--masthead-fg); border-bottom-color: var(--masthead-fg); font-weight: 600; }

.topbar-right { display: flex; align-items: center; gap: 12px; }

.theme-toggle-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  border: 1px solid #55554f;
  background: transparent;
  color: var(--masthead-dim);
  cursor: pointer;
}
.theme-toggle-btn:hover { color: var(--masthead-fg); border-color: var(--masthead-dim); }

[data-theme="dark"] .sun-icon  { display: block; }
[data-theme="dark"] .moon-icon { display: none; }
[data-theme="light"] .sun-icon  { display: none; }
[data-theme="light"] .moon-icon { display: block; }

/* ==========================================================================
   LAYOUT
   ========================================================================== */
.main-container, main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px 28px 56px;
}

/* --- Page Header ------------------------------------------------------ */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 18px;
  flex-wrap: wrap;
  gap: 16px;
}

.page-title {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.015em;
  margin: 0 0 4px 0;
  color: var(--fg);
  line-height: 1.2;
}

.lede {
  color: var(--fg-muted);
  font-size: 14px;
  margin: 0;
  max-width: 72ch;
  line-height: 1.55;
}

.as-of-badge { color: var(--fg); font-weight: 600; font-variant-numeric: tabular-nums; }

/* ==========================================================================
   FILTERS: a ruled strip, not a card
   ========================================================================== */
.filters-card, form.filters {
  background: transparent;
  border: 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  padding: 12px 0;
  margin-bottom: 18px;
}

.filters-wrap {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px 16px;
}
form.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px 16px; }

.filter-group { display: flex; flex-direction: column; }
.filter-label { display: flex; flex-direction: column; gap: 4px; }

.label-text, form.filters label:not(.check):not(.check-label) {
  font-size: 12px;
  font-weight: 600;
  color: var(--fg-muted);
}

.select-wrapper { position: relative; display: inline-block; }
.select-wrapper::after {
  content: "";
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 0; height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid var(--fg-muted);
  pointer-events: none;
}

.filter-select, form.filters select {
  appearance: none;
  -webkit-appearance: none;
  background: var(--bg-panel);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  color: var(--fg);
  font-size: 13px;
  padding: 6px 28px 6px 9px;
  min-width: 120px;
  cursor: pointer;
}
.filter-select:hover { border-color: var(--fg-dim); }
.filter-select:focus { outline: none; border-color: var(--accent); }

.filter-group-check { margin-bottom: 5px; margin-left: auto; }

.check-label, form.filters label.check {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  font-size: 13px;
  font-weight: 400;
  color: var(--fg-muted);
}
form.filters label.check { margin-left: auto; margin-bottom: 5px; }
.check-label:hover { color: var(--fg); }

.custom-checkbox { position: absolute; opacity: 0; width: 0; height: 0; }

.checkbox-box {
  width: 16px;
  height: 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: var(--bg-panel);
  display: flex;
  align-items: center;
  justify-content: center;
}
.custom-checkbox:checked + .checkbox-box { background: var(--accent); border-color: var(--accent); }
.custom-checkbox:checked + .checkbox-box::after {
  content: "";
  width: 4px; height: 8px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg) translate(-1px, -1px);
}

/* --- Results Summary -------------------------------------------------- */
.results-summary {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 0;
  font-size: 13px;
  color: var(--fg-muted);
}
.results-summary b { color: var(--fg); font-weight: 600; }

/* ==========================================================================
   TABLES
   ========================================================================== */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  background: var(--bg-panel);
}

.grid { width: 100%; border-collapse: collapse; text-align: left; }

.grid th {
  padding: 8px 12px;
  background: var(--table-header-bg);
  border-bottom: 1px solid var(--line-strong);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--fg-muted);
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 5;
}

.grid td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--line-subtle);
  white-space: nowrap;
  font-size: 13.5px;
  color: var(--fg);
}
.grid tbody tr:last-child td { border-bottom: 0; }
.grid tbody tr:hover { background-color: var(--table-hover); }

.table-row-clickable { cursor: pointer; }

.grid .num { text-align: right; font-variant-numeric: tabular-nums lining-nums; }
.grid.compact td { padding: 6px 12px; }

/* --- Table Cells ------------------------------------------------------ */
.ticker-badge {
  display: inline-block;
  font-weight: 700;
  font-size: 13.5px;
  color: var(--accent-text);
}
.ticker-badge:hover { color: var(--accent-hover); text-decoration: underline; }

.company-cell { display: inline-flex; align-items: center; gap: 10px; }
.company-name {
  color: var(--fg-muted);
  font-size: 13px;
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sector-cell { color: var(--fg-muted); font-size: 13px; }

.insider-cell { display: flex; align-items: center; gap: 8px; }
.lead-name { font-weight: 600; color: var(--fg); }

.role-badge { font-size: 12px; color: var(--fg-muted); }
.role-badge::before { content: "· "; color: var(--fg-dim); }

.total-val { font-weight: 600; color: var(--fg); }
.date-cell { color: var(--fg-muted); font-size: 13px; }

.badge-count { font-size: 12.5px; color: var(--fg-muted); font-weight: 400; }

/* --- Score ------------------------------------------------------------- */
.score-pill, .score {
  display: inline-block;
  min-width: 34px;
  font-size: 14px;
  font-weight: 700;
  padding: 1px 6px;
  text-align: center;
  color: var(--low);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-panel);
}
.score-pill[data-band="high"], .score[data-band="high"] { color: var(--good); border-color: var(--buy-border); background: var(--buy-subtle); }
.score-pill[data-band="mid"], .score[data-band="mid"] { color: var(--mid); border-color: var(--mid-border); background: var(--mid-subtle); }

/* --- Side (Buy / Sell) ------------------------------------------------ */
.side { display: inline-block; font-size: 12.5px; font-weight: 700; }
.side-P { color: var(--buy); }
.side-S { color: var(--sell); }

/* --- Tags ------------------------------------------------------------- */
.tag {
  display: inline-block;
  font-size: 12px;
  padding: 0 6px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  color: var(--fg-muted);
  background: transparent;
  line-height: 1.5;
}
.tag-warning { color: var(--mid); border-color: var(--mid-border); background: var(--mid-subtle); font-weight: 600; }
.tag-routine { color: var(--fg-muted); }
.tag-offering { color: var(--accent-text); border-color: var(--accent-border); }
.tag-check { color: var(--sell); border-color: var(--sell-border); background: var(--sell-subtle); font-weight: 600; }
.tag-plan { color: var(--plan); border-color: var(--line-strong); }

.tags-group { display: flex; gap: 4px; flex-wrap: wrap; }

/* --- Empty State ------------------------------------------------------ */
.empty { text-align: center; color: var(--fg-muted); padding: 40px 16px; }
.empty-state { padding: 16px 0; color: var(--fg-muted); }
.empty-state p { margin: 0; font-size: 14px; color: var(--fg-muted); }

/* --- SEC Edgar Link --------------------------------------------------- */
.sec-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12.5px;
  color: var(--accent-text);
}

/* ==========================================================================
   DETAIL PAGES (Cluster & Stock)
   ========================================================================== */
.detail-nav { margin-bottom: 12px; }

.back-link, .back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--fg-muted);
}
.back-link:hover, .back:hover { color: var(--fg); }

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
  flex-wrap: wrap;
  padding: 0 0 18px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.ticker-title-row { display: flex; align-items: baseline; gap: 12px; margin-bottom: 8px; flex-wrap: wrap; }

.ticker-badge-lg { font-size: 24px; font-weight: 700; letter-spacing: -0.01em; color: var(--fg); }

.company-heading, h1 {
  font-size: 24px;
  font-weight: 400;
  margin: 0;
  color: var(--fg-muted);
  letter-spacing: -0.01em;
}

.meta-row {
  display: flex;
  align-items: center;
  gap: 6px 16px;
  flex-wrap: wrap;
  font-size: 13.5px;
  color: var(--fg-muted);
}
.meta-tag { font-size: 13.5px; color: var(--fg-muted); }
.meta-tag + .meta-tag::before { content: "/ "; color: var(--fg-dim); }
.action-link { font-weight: 600; color: var(--accent-text); }

/* --- Score block ------------------------------------------------------ */
.bigscore-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 16px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-panel);
}
.bigscore-card[data-band="high"] { border-color: var(--buy-border); background: var(--buy-subtle); }
.bigscore-card[data-band="mid"] { border-color: var(--mid-border); background: var(--mid-subtle); }

.bigscore-val, .bigscore { font-size: 40px; font-weight: 700; line-height: 1; color: var(--fg); letter-spacing: -0.02em; }
.bigscore-card[data-band="high"] .bigscore-val, .bigscore-card[data-band="high"] .bigscore { color: var(--good); }
.bigscore-card[data-band="mid"] .bigscore-val, .bigscore-card[data-band="mid"] .bigscore { color: var(--mid); }

.bigscore small { display: block; font-size: 12px; color: var(--fg-muted); margin-top: 4px; }
.bigscore-meta { display: flex; flex-direction: column; }
.bigscore-title { font-size: 13px; font-weight: 600; color: var(--fg); }
.bigscore-verdict { font-size: 12.5px; color: var(--fg-muted); }

/* --- Key figures: ruled strip ------------------------------------------ */
.stats-grid, .stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0;
  margin: 18px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.stat-card, .stats div { padding: 12px 16px 12px 0; display: flex; flex-direction: column; gap: 2px; }
.stat-label { font-size: 12.5px; color: var(--fg-muted); }
.stat-val, .stats b { font-size: 20px; font-weight: 700; color: var(--fg); line-height: 1.2; }
.stat-val-highlight { color: var(--buy); }
.stat-val-lead { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-val-date { font-size: 14px; }
.stat-sub, .stats span { font-size: 12.5px; color: var(--fg-muted); }

.status-pill { font-size: 12.5px; font-weight: 600; }
.status-active { color: var(--buy); }

/* --- Content Panels: rule above, no box -------------------------------- */
.content-panel {
  border-top: 2px solid var(--fg);
  padding: 12px 0 0;
  margin-bottom: 28px;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 12px;
  flex-wrap: wrap;
  gap: 12px;
}

.panel-title, h2 { font-size: 16px; font-weight: 700; margin: 0; color: var(--fg); letter-spacing: -0.005em; }
.panel-subtitle { font-size: 13px; color: var(--fg-muted); margin: 2px 0 0 0; }
.panel-divider { height: 1px; background: var(--line); margin: 8px 0; border: none; }

.badge-algo { display: none; }

/* --- Chart ------------------------------------------------------------- */
.chart-container, #chart { width: 100%; height: 340px; }

.ranges { display: flex; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); overflow: hidden; background: var(--bg-panel); }
.range-btn, .ranges button {
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  color: var(--fg-muted);
  padding: 4px 12px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}
.ranges button:last-child { border-right: 0; }
.range-btn:hover, .ranges button:hover { color: var(--fg); background: var(--bg-card-hover); }
.range-btn.on, .ranges button.on, .ranges button[aria-pressed="true"] { background: var(--fg); color: var(--bg-panel); }

/* --- Analysis Grid ---------------------------------------------------- */
.analysis-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 32px; margin-bottom: 8px; }
@media (max-width: 900px) { .analysis-grid { grid-template-columns: 1fr; gap: 0; } }

/* --- Factor Breakdown ------------------------------------------------- */
.factor-list { display: flex; flex-direction: column; gap: 12px; margin-bottom: 16px; }

.factor-row { display: grid; grid-template-columns: 150px 1fr 48px; align-items: center; gap: 12px; }
.factor-info { display: flex; flex-direction: column; }
.factor-name { font-size: 13.5px; font-weight: 600; color: var(--fg); }
.factor-desc { font-size: 12px; color: var(--fg-muted); line-height: 1.3; }

.factor-bar-wrap { width: 100%; }
.factor-bar-bg { width: 100%; height: 8px; background: var(--table-header-bg); }
.factor-bar-fill { height: 100%; background: var(--fg-muted); }
.factor-bar-fill.factor-low { background: var(--mid); }

.factor-val { text-align: right; font-size: 13.5px; font-weight: 700; color: var(--fg); font-variant-numeric: tabular-nums; }

/* --- Modifiers -------------------------------------------------------- */
.modifiers-table { border-top: 1px solid var(--line); padding-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.modifier-row { display: flex; justify-content: space-between; align-items: center; font-size: 13px; color: var(--fg-muted); }
.modifier-tag { font-size: 13px; font-weight: 600; color: var(--fg); font-variant-numeric: tabular-nums; }
.penalty-active { color: var(--sell); font-weight: 700; }

.warning-callout {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 9px 12px;
  background: var(--mid-subtle);
  border: 1px solid var(--mid-border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--fg);
  margin-top: 14px;
}

/* --- Why section ------------------------------------------------------ */
.why-body { display: flex; flex-direction: column; gap: 14px; }
.why-text { font-size: 14px; line-height: 1.65; color: var(--fg); margin: 0; max-width: 68ch; }

.confidence-badge { font-size: 12.5px; color: var(--fg-muted); }
.confidence-likely { color: var(--fg-muted); }

.sources-wrap { display: flex; flex-direction: column; gap: 6px; }
.sources-title { font-size: 13px; font-weight: 600; color: var(--fg-muted); margin: 0; }
.sources-list { list-style: none; padding: 0; margin: 0; }

.source-item {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding: 6px 0;
  border-bottom: 1px solid var(--line-subtle);
  font-size: 13px;
}
.source-link { display: inline-flex; align-items: baseline; gap: 6px; color: var(--accent-text); }
.source-link:hover { text-decoration: underline; }
.source-date { color: var(--fg-dim); font-size: 12.5px; }

/* --- Stock page header & inline filters -------------------------------- */
.activity-section-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin: 24px 0 10px 0;
  flex-wrap: wrap;
  gap: 12px;
}
.section-title { font-size: 16px; font-weight: 700; margin: 0; color: var(--fg); }

.filters-inline, form.filters.filters-inline {
  display: flex; align-items: center; gap: 10px;
  border: 0; padding: 0; margin: 0;
}
.filter-label-inline { flex-direction: row; align-items: center; gap: 8px; }

/* ==========================================================================
   UTILITY
   ========================================================================== */
.fade-in { animation: none; }

.shimmer { background: var(--table-header-bg); }

/* ==========================================================================
   FOOTER
   ========================================================================== */
.app-footer { border-top: 1px solid var(--line); padding: 18px 28px; margin-top: 40px; background: var(--bg-panel); }
.footer-content {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 12.5px;
  color: var(--fg-muted);
}
.footer-badge { font-size: 12.5px; color: var(--fg-muted); }

/* ==========================================================================
   RESPONSIVE
   ========================================================================== */
@media (max-width: 768px) {
  .topbar { padding: 0 16px; }
  .main-container, main { padding: 16px; }
  .bigscore-card { width: 100%; justify-content: space-between; }
  .stats-grid, .stats { grid-template-columns: 1fr 1fr; }
  .filter-group-check { margin-left: 0; }
  .page-title { font-size: 20px; }
  .factor-row { grid-template-columns: 110px 1fr 44px; }
}

@media (max-width: 480px) {
  .topbar { height: auto; flex-wrap: wrap; padding-top: 8px; padding-bottom: 0; row-gap: 4px; }
  .topbar-nav { order: 3; flex: 1 0 100%; }
  .nav-link { flex: 1 1 0; justify-content: center; white-space: nowrap; min-height: 40px; }
  .brand-sub { display: none; }
  .stats-grid, .stats { grid-template-columns: 1fr; }
  .analysis-grid { grid-template-columns: 1fr; }
}

/* --- Keyboard focus ----------------------------------------------------- */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.topbar :focus-visible { outline-color: #fff; }
.custom-checkbox:focus-visible + .checkbox-box { outline: 2px solid var(--accent); outline-offset: 2px; }
.grid tbody tr:focus-within { background-color: var(--table-hover); }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

@media (prefers-reduced-motion: reduce) {
  .htmx-request .htmx-indicator-bar, .htmx-request.htmx-indicator-bar { animation: none; transform: none; }
}

/* --- Touch: 44px targets on coarse pointers ---------------------------- */
@media (pointer: coarse) {
  .nav-link { min-height: 44px; }
  .theme-toggle-btn { width: 44px; height: 44px; }
  .range-btn, .ranges button { min-height: 44px; padding: 5px 16px; }
  .filter-select { min-height: 44px; font-size: 16px; }
  .check-label { min-height: 44px; }
  .checkbox-box { width: 22px; height: 22px; }
  .back-link, .back, .action-link, .sec-link { display: inline-flex; align-items: center; min-height: 44px; }
}


/* Previous / next page links of the cluster list */
.pager { display: flex; align-items: center; gap: 12px; margin-left: auto; }
.pager-link { color: var(--accent-text); }

/* Sortable column heads: a plain link, sorted column marked by aria-sort */
.sort-link { color: inherit; font-weight: inherit; }
.sort-link:hover { color: var(--fg); text-decoration: underline; }
th[aria-sort="descending"] .sort-link::after { content: " \2193"; }

.verdict-label { font-size: 12.5px; font-weight: 600; color: var(--fg-muted); margin-right: 6px; }

/* Filters collapse behind one button on phones */
.filters-toggle { display: none; }
@media (max-width: 720px) {
  .filters-toggle {
    display: inline-flex; align-items: center; margin: 0 0 10px; padding: 7px 14px; min-height: 40px;
    border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
    background: var(--bg-panel); color: var(--fg); font-size: 13.5px; font-weight: 600; cursor: pointer;
  }
  form.filters[data-collapsible] { display: none; }
  form.filters[data-collapsible].is-open { display: flex; }
}
