/**
 * Logan Reports — Shared Theme (Light + Dark)
 *
 * Include in any page:
 *   <link rel="stylesheet" href="/shared/theme.css">
 *
 * The theme is controlled by `<html data-theme="light|dark">`, which is set
 * by /shared/theme-mode.js (load that script BEFORE this stylesheet to
 * avoid a flash-of-wrong-theme).
 *
 * NOTE on report pages:
 *   /reports/* pages have heavy inline <style> blocks with hardcoded
 *   dark colors tuned for chart contrast. theme-mode.js force-sets
 *   data-theme="dark" on those URLs regardless of user preference,
 *   so this file's light-mode rules safely never activate there.
 *   Migrating per-report inline styles to CSS variables is future work.
 */

/* ──────────────────────────────────────────────────────────────────────
   COLOR TOKENS
   Default values are dark mode. Overridden below by [data-theme="light"].
   ────────────────────────────────────────────────────────────────────── */
:root {
  /* Surfaces */
  --bg-primary:    #0f172a; /* Page background */
  --bg-secondary:  #1e293b; /* Cards, panels */
  --bg-tertiary:   #334155; /* Subtle dividers, button bg */
  --bg-deeper:     #0b1120; /* "Deeper" surface (footer, inputs) */
  --bg-overlay:    rgba(15, 23, 42, 0.85);

  /* Text */
  --text-strong:    #f1f5f9; /* Headings */
  --text-primary:   #e2e8f0; /* Body */
  --text-emphasis:  #cbd5e1; /* Slightly softer than primary */
  --text-secondary: #94a3b8; /* Sub-text, labels */
  --text-tertiary:  #64748b; /* Muted */
  --text-muted:     #475569; /* Very muted (footer, deemphasized) */

  /* Borders */
  --border-default: #334155;
  --border-strong:  #475569;
  --border-subtle:  #1e293b;
  --border-table:   #263248;

  /* Accent */
  --accent:               #0ea5e9;
  --accent-hover:         #0284c7;
  --accent-text-on:       #ffffff;
  --accent-tint-bg:       rgba(14, 165, 233, 0.12);
  --accent-tint-border:   rgba(14, 165, 233, 0.25);

  /* Status */
  --success:        #10b981;
  --success-bg:     #064e3b;
  --success-text:   #34d399;
  --warning:        #f59e0b;
  --warning-bg:     #78350f;
  --warning-text:   #fcd34d;
  --error:          #ef4444;
  --error-bg:       #450a0a;
  --error-border:   #dc2626;
  --error-text:     #fca5a5;
  --info:           #8b5cf6;
  --info-bg:        #1e1b4b;
  --info-text:      #a5b4fc;

  /* Effects */
  --shadow-card:    0 8px 24px rgba(0, 0, 0, 0.3);
  --shadow-soft:    0 4px 12px rgba(0, 0, 0, 0.2);

  /* Per-row table hover */
  --row-hover-bg:   #263248;
}

/* ──────────────────────────────────────────────────────────────────────
   LIGHT MODE OVERRIDES
   Tuned for WCAG AA contrast against the new surface colors.
   ────────────────────────────────────────────────────────────────────── */
:root[data-theme="light"] {
  /* Surfaces */
  --bg-primary:    #f8fafc;
  --bg-secondary:  #ffffff;
  --bg-tertiary:   #e2e8f0;
  --bg-deeper:     #f1f5f9;
  --bg-overlay:    rgba(15, 23, 42, 0.45);

  /* Text — chosen so body text on bg-primary is ≥7:1 (AAA) */
  --text-strong:    #0f172a;
  --text-primary:   #1e293b;
  --text-emphasis:  #334155;
  --text-secondary: #475569;
  --text-tertiary:  #64748b;
  --text-muted:     #94a3b8;

  /* Borders */
  --border-default: #e2e8f0;
  --border-strong:  #cbd5e1;
  --border-subtle:  #f1f5f9;
  --border-table:   #f1f5f9;

  /* Accent — deeper blue for adequate contrast on light surfaces */
  --accent:               #0284c7;
  --accent-hover:         #0369a1;
  --accent-text-on:       #ffffff;
  --accent-tint-bg:       rgba(2, 132, 199, 0.08);
  --accent-tint-border:   rgba(2, 132, 199, 0.28);

  /* Status — pulled darker than dark-mode equivalents for contrast */
  --success:        #16a34a;
  --success-bg:     #dcfce7;
  --success-text:   #166534;
  --warning:        #d97706;
  --warning-bg:     #fef3c7;
  --warning-text:   #92400e;
  --error:          #dc2626;
  --error-bg:       #fee2e2;
  --error-border:   #fecaca;
  --error-text:     #991b1b;
  --info:           #7c3aed;
  --info-bg:        #ede9fe;
  --info-text:      #5b21b6;

  /* Effects */
  --shadow-card:    0 4px 12px rgba(15, 23, 42, 0.08);
  --shadow-soft:    0 2px 6px rgba(15, 23, 42, 0.06);

  --row-hover-bg:   #f1f5f9;
}

/* ── RESET ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── BASE ── */
body {
  font-family: 'Inter', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  /* Smooth swaps when the user toggles theme. */
  transition: background-color 0.18s ease, color 0.18s ease;
}

/* ── HEADER ── */
.header {
  background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-primary) 100%);
  border-bottom: 1px solid var(--border-default);
  padding: 20px 32px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 200;
}
.header-left h1 { font-size: 20px; font-weight: 800; color: var(--text-strong); }
.header-left p  { font-size: 12px; color: var(--text-tertiary); margin-top: 2px; }
.badge {
  background: var(--accent); color: var(--accent-text-on);
  padding: 4px 12px; border-radius: 20px;
  font-size: 11px; font-weight: 700;
}

/* ── CONTENT CONTAINER ── */
.content { max-width: 1280px; margin: 0 auto; padding: 24px 32px; }

/* ── KPI CARDS ── */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 24px; }
.kpi-card {
  background: var(--bg-secondary); border: 1px solid var(--border-default);
  border-radius: 12px; padding: 18px 22px;
  position: relative; overflow: hidden;
}
.kpi-card::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0;
  height: 3px; border-radius: 12px 12px 0 0;
}
.kpi-card.blue::before   { background: var(--accent); }
.kpi-card.green::before  { background: var(--success); }
.kpi-card.purple::before { background: var(--info); }
.kpi-card.orange::before { background: var(--warning); }
.kpi-card.red::before    { background: var(--error); }
.kpi-label {
  font-size: 10px; color: var(--text-tertiary); font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 6px;
}
.kpi-value { font-size: 30px; font-weight: 800; color: var(--text-strong); line-height: 1; }
.kpi-sub   { font-size: 11px; color: var(--text-tertiary); margin-top: 6px; }
.kpi-hi    { color: var(--success); font-weight: 600; }
.kpi-lo    { color: var(--error); font-weight: 600; }

/* ── CHART CARDS ── */
.chart-row { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; margin-bottom: 24px; }
.chart-card {
  background: var(--bg-secondary); border: 1px solid var(--border-default);
  border-radius: 12px; padding: 20px 22px;
}
.chart-title {
  font-size: 12px; font-weight: 700; color: var(--text-emphasis);
  margin-bottom: 16px; text-transform: uppercase; letter-spacing: 0.06em;
}
.chart-wrap  { position: relative; height: 220px; }
.chart-wrap.tall { height: 280px; }
.chart-wrap.short { height: 160px; }

/* ── TABLE ── */
.section-hdr {
  font-size: 10px; font-weight: 700; color: var(--text-tertiary);
  letter-spacing: 0.12em; text-transform: uppercase;
  margin-bottom: 12px; display: flex; align-items: center; gap: 8px;
}
.section-hdr::after { content: ''; flex: 1; height: 1px; background: var(--border-subtle); }
.table-wrap {
  background: var(--bg-secondary); border: 1px solid var(--border-default);
  border-radius: 12px; overflow: hidden; margin-bottom: 24px;
}
.table-wrap table { width: 100%; border-collapse: collapse; }
.table-wrap thead { background: var(--bg-primary); }
.table-wrap th {
  padding: 10px 14px; text-align: left;
  font-size: 10px; font-weight: 700; color: var(--text-tertiary);
  text-transform: uppercase; letter-spacing: 0.08em;
  cursor: pointer; user-select: none; white-space: nowrap;
}
.table-wrap th.r { text-align: right; }
.table-wrap th:hover { color: var(--accent); }
.table-wrap th.sort-asc::after  { content: ' \2191'; color: var(--accent); }
.table-wrap th.sort-desc::after { content: ' \2193'; color: var(--accent); }
.table-wrap td {
  padding: 10px 14px; border-top: 1px solid var(--border-table);
  font-size: 13px; color: var(--text-emphasis); white-space: nowrap;
}
.table-wrap td.r { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap tbody tr:hover { background: var(--row-hover-bg); }

/* ── FILTER PANEL ── */
.filter-panel {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-default);
  padding: 16px 32px;
  position: sticky;
  top: 73px; /* sits directly below the sticky header */
  z-index: 190;
}
.filter-top { display: flex; align-items: center; gap: 16px; margin-bottom: 14px; flex-wrap: wrap; }
.filter-label {
  font-size: 10px; font-weight: 700; color: var(--text-tertiary);
  text-transform: uppercase; letter-spacing: 0.1em; white-space: nowrap;
}
.date-inputs { display: flex; align-items: center; gap: 8px; }
.date-inputs input[type=date] {
  background: var(--bg-deeper); border: 1px solid var(--border-default); color: var(--text-primary);
  padding: 6px 12px; border-radius: 8px; font-size: 13px; font-family: inherit;
  cursor: pointer; outline: none; width: 130px;
}
.date-inputs input[type=date]:focus { border-color: var(--accent); }
/* In dark mode the native calendar icon is invisible against dark inputs; flip it.
   In light mode we leave it alone. */
:root:not([data-theme="light"]) .date-inputs input[type=date]::-webkit-calendar-picker-indicator {
  filter: invert(1); cursor: pointer;
}
.preset-btns { display: flex; gap: 6px; flex-wrap: wrap; }
.preset-btn {
  background: var(--bg-deeper); border: 1px solid var(--border-default); color: var(--text-secondary);
  padding: 5px 12px; border-radius: 8px;
  font-size: 11px; font-weight: 600; cursor: pointer; font-family: inherit;
  transition: all 0.15s; white-space: nowrap;
}
.preset-btn:hover, .preset-btn.active { background: var(--accent); border-color: var(--accent); color: var(--accent-text-on); }

/* ── LOADING STATE ── */
.loading-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: var(--bg-overlay);
  display: flex; align-items: center; justify-content: center;
  z-index: 9998; transition: opacity 0.3s;
}
.loading-spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--border-default); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── ERROR STATE ── */
.error-banner {
  background: var(--error-bg); border: 1px solid var(--error-border);
  color: var(--error-text); padding: 12px 20px; border-radius: 10px;
  margin-bottom: 16px; font-size: 13px;
}

/* ── EMPTY STATE ── */
.empty { text-align: center; padding: 48px; color: var(--text-muted); }
.empty-icon { font-size: 40px; margin-bottom: 12px; }

/* ── FOOTER ── */
.footer {
  text-align: center; padding: 20px; color: var(--text-muted);
  font-size: 11px; border-top: 1px solid var(--border-subtle);
}

/* ── UTILITIES ── */
.pct { display: inline-block; padding: 2px 7px; border-radius: 10px; font-size: 11px; font-weight: 700; }
.pct-hi { background: var(--success-bg); color: var(--success-text); }
.pct-md { background: var(--warning-bg); color: var(--warning-text); }
.pct-lo { background: var(--info-bg); color: var(--info-text); }

/* ── RESPONSIVE ── */
@media (max-width: 768px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .chart-row { grid-template-columns: 1fr; }
  .content { padding: 16px; }
}

/* ── PRINT ── */
@media print {
  body { background: white; color: #1e293b; }
  .logan-nav, .filter-panel { display: none; }
  .kpi-card, .chart-card, .table-wrap { border-color: #d1d5db; }
}
