/* ETF Dashboard — styling.
   Palette follows the dataviz skill's validated default (references/palette.md):
   fixed categorical hue order, status colors reserved for signal badges,
   light/dark via prefers-color-scheme + a future data-theme toggle hook. */

:root {
  color-scheme: light;
  --surface-0: #f9f9f7;   /* page plane */
  --surface-1: #fcfcfb;   /* card / chart surface */
  --surface-2: #f2f1ee;   /* subtle zebra / hover */
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --border: rgba(11, 11, 11, 0.10);
  --gridline: #e1e0d9;
  --baseline: #c3c2b7;

  /* categorical (fixed order — never cycle, never reassign per-filter) */
  --series-1: #2a78d6; /* blue */
  --series-2: #008300; /* green */
  --series-3: #e87ba4; /* magenta */
  --series-4: #eda100; /* yellow */
  --series-5: #1baf7a; /* aqua */
  --series-6: #eb6834; /* orange */
  --series-7: #4a3aa7; /* violet */
  --series-8: #e34948; /* red */

  /* status (reserved — never reused as series color) */
  --status-good: #0ca30c;
  --status-warning: #fab219;
  --status-serious: #ec835a;
  --status-critical: #d03b3b;
  --delta-good-text: #006300;
  --delta-bad-text: #b00020;

  --accent: var(--series-1);
  --focus-ring: #2a78d6;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-0: #0d0d0d;
    --surface-1: #1a1a19;
    --surface-2: #232322;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --border: rgba(255, 255, 255, 0.10);
    --gridline: #2c2c2a;
    --baseline: #383835;

    --series-1: #3987e5;
    --series-2: #008300;
    --series-3: #d55181;
    --series-4: #c98500;
    --series-5: #199e70;
    --series-6: #d95926;
    --series-7: #9085e9;
    --series-8: #e66767;

    --status-good: #0ca30c;
    --status-warning: #fab219;
    --status-serious: #ec835a;
    --status-critical: #d03b3b;
    --delta-good-text: #0ca30c;
    --delta-bad-text: #e66767;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-0: #0d0d0d;
  --surface-1: #1a1a19;
  --surface-2: #232322;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --border: rgba(255, 255, 255, 0.10);
  --gridline: #2c2c2a;
  --baseline: #383835;
  --series-1: #3987e5;
  --series-2: #008300;
  --series-3: #d55181;
  --series-4: #c98500;
  --series-5: #199e70;
  --series-6: #d95926;
  --series-7: #9085e9;
  --series-8: #e66767;
  --delta-good-text: #0ca30c;
  --delta-bad-text: #e66767;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text-primary);
  background: var(--surface-0);
  line-height: 1.45;
  font-size: 14px;
}

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

h1 { font-size: 1.4rem; margin: 0 0 0.75rem; }
h2 { font-size: 1.1rem; margin: 1.5rem 0 0.5rem; }
h3 { font-size: 1rem; margin: 1rem 0 0.4rem; color: var(--text-secondary); }

/* ---------------------------------------------------------------- topbar */
.topbar {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0.65rem 1.25rem;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { font-weight: 700; text-decoration: none; color: var(--text-primary); font-size: 1.02rem; }
.nav { display: flex; align-items: center; gap: 1.1rem; flex-wrap: wrap; margin-left: auto; }
.nav a { text-decoration: none; color: var(--text-secondary); font-weight: 500; padding: 0.2rem 0; }
.nav a:hover, .nav a.active { color: var(--accent); }
.logout-form { margin: 0; }
.logout-form button {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  padding: 0.3rem 0.7rem;
  font-size: 0.85rem;
}
.logout-form button:hover { color: var(--text-primary); border-color: var(--text-secondary); }

.content { max-width: 1180px; margin: 1.5rem auto 3rem; padding: 0 1.25rem; }
.content.narrow { max-width: 640px; }

/* ---------------------------------------------------------------- forms */
form.inline { display: inline; }
label { display: block; margin: 0.6rem 0; font-weight: 500; color: var(--text-secondary); font-size: 0.88rem; }
label input, label select, label textarea { font-weight: 400; }

input[type="text"], input[type="password"], input[type="number"],
input[type="email"], select, textarea {
  display: block;
  width: 100%;
  max-width: 340px;
  padding: 0.4rem 0.55rem;
  margin-top: 0.3rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  box-sizing: border-box;
  background: var(--surface-1);
  color: var(--text-primary);
  font-size: 0.92rem;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus, button:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 1px;
}
input[readonly] { background: var(--surface-2); color: var(--text-muted); }

button, .btn {
  padding: 0.45rem 0.9rem;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 600;
  font-family: inherit;
}
button:hover, .btn:hover { filter: brightness(1.08); }
button.secondary, .btn.secondary {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
button.danger, .btn.danger { background: var(--status-critical); }
button.small, .btn.small { padding: 0.25rem 0.55rem; font-size: 0.78rem; }

.error {
  color: var(--delta-bad-text);
  font-weight: 600;
  background: color-mix(in srgb, var(--status-critical) 12%, var(--surface-1));
  border: 1px solid color-mix(in srgb, var(--status-critical) 30%, var(--border));
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
}
.message, .flash {
  color: var(--delta-good-text);
  font-weight: 600;
  background: color-mix(in srgb, var(--status-good) 12%, var(--surface-1));
  border: 1px solid color-mix(in srgb, var(--status-good) 30%, var(--border));
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  margin-bottom: 1rem;
}
.recovery-codes { list-style: none; padding: 0; font-size: 1.1rem; }
.qr svg { width: 200px; height: 200px; }

/* ---------------------------------------------------------------- stat tiles */
.stat-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}
.stat-tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.9rem 1.05rem;
}
.stat-tile .label {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.stat-tile .value {
  font-size: 1.65rem;
  font-weight: 600;
  margin-top: 0.2rem;
  font-variant-numeric: proportional-nums;
}
.stat-tile .sub { font-size: 0.8rem; color: var(--text-secondary); margin-top: 0.15rem; }

/* ---------------------------------------------------------------- tables */
.table-scroll {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-1);
}
table {
  border-collapse: collapse;
  width: 100%;
  min-width: 720px;
  font-size: 0.88rem;
}
table.compact { min-width: 0; }
thead th {
  position: sticky;
  top: 0;
  background: var(--surface-1);
  text-align: left;
  padding: 0.55rem 0.7rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
tbody td {
  padding: 0.5rem 0.7rem;
  border-bottom: 1px solid var(--gridline);
  vertical-align: middle;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
tbody td.wrap { white-space: normal; font-variant-numeric: normal; }
tbody tr:nth-child(even) { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: none; }
tbody tr.row-warning { background: color-mix(in srgb, var(--status-warning) 14%, var(--surface-1)); }
tbody tr.row-error { background: color-mix(in srgb, var(--status-critical) 12%, var(--surface-1)); }

.num-pos { color: var(--delta-good-text); font-weight: 600; }
.num-neg { color: var(--delta-bad-text); font-weight: 600; }
.num-neutral { color: var(--text-secondary); }

.ok-flag { color: var(--status-good); font-weight: 700; }
.bad-flag { color: var(--text-muted); font-weight: 700; }

.warn-icon { color: var(--status-warning); font-weight: 700; margin-right: 0.25rem; }
.error-icon { color: var(--status-critical); font-weight: 700; margin-right: 0.25rem; }

/* ---------------------------------------------------------------- badges */
.badge {
  display: inline-block;
  padding: 0.18rem 0.55rem;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 700;
  white-space: nowrap;
  border: 1px solid transparent;
}
.badge-good {
  color: var(--delta-good-text);
  background: color-mix(in srgb, var(--status-good) 16%, var(--surface-1));
  border-color: color-mix(in srgb, var(--status-good) 35%, var(--border));
}
.badge-neutral {
  color: var(--text-secondary);
  background: var(--surface-2);
  border-color: var(--border);
}
.badge-bad {
  color: var(--delta-bad-text);
  background: color-mix(in srgb, var(--status-critical) 14%, var(--surface-1));
  border-color: color-mix(in srgb, var(--status-critical) 32%, var(--border));
}

/* ---------------------------------------------------------------- empty state */
.empty-state {
  padding: 2.5rem 1.5rem;
  text-align: center;
  color: var(--text-muted);
  background: var(--surface-1);
  border: 1px dashed var(--border);
  border-radius: 10px;
}

/* ---------------------------------------------------------------- charts */
.chart-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.1rem 1.3rem;
  margin-bottom: 1.5rem;
}
.chart-card h2 { margin-top: 0; }
.chart-card canvas { max-width: 100%; }
.chart-wrap { position: relative; height: 320px; }
.chart-legend-note { font-size: 0.78rem; color: var(--text-muted); margin-top: 0.4rem; }

.filter-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.filter-row .filter-label { color: var(--text-muted); font-size: 0.82rem; margin-right: 0.3rem; }
.filter-btn {
  background: var(--surface-1);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  padding: 0.32rem 0.75rem;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}
.filter-btn:hover { color: var(--text-primary); }
.filter-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ---------------------------------------------------------------- markdown report body */
.report-body {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.2rem 1.4rem;
}
.report-body table { min-width: 0; width: 100%; margin: 0.75rem 0; }
.report-body h1, .report-body h2, .report-body h3 { margin-top: 1.2rem; }
.report-body h1:first-child, .report-body h2:first-child, .report-body h3:first-child { margin-top: 0; }
.report-body code {
  background: var(--surface-2);
  padding: 0.1rem 0.3rem;
  border-radius: 4px;
  font-size: 0.85em;
}
.report-body pre {
  background: var(--surface-2);
  padding: 0.75rem 1rem;
  border-radius: 8px;
  overflow-x: auto;
}
.report-body pre code { background: none; padding: 0; }
.report-body blockquote {
  border-left: 3px solid var(--border);
  margin: 0.75rem 0;
  padding: 0.1rem 1rem;
  color: var(--text-secondary);
}

/* ---------------------------------------------------------------- misc */
.muted { color: var(--text-muted); }
.section { margin-bottom: 2rem; }
.actions-cell { white-space: nowrap; }
.weight-sum-warning { color: var(--status-warning); font-weight: 700; }
.weight-sum-ok { color: var(--delta-good-text); font-weight: 700; }
fieldset { border: 1px solid var(--border); border-radius: 10px; padding: 1rem 1.1rem; margin: 0 0 1.5rem; }
legend { padding: 0 0.4rem; font-weight: 600; color: var(--text-secondary); }
.checkbox-row { display: flex; align-items: center; gap: 0.4rem; }
.checkbox-row input { width: auto; margin: 0; }
.checkbox-row label { margin: 0; }
small.hint { display: block; color: var(--text-muted); font-weight: 400; margin-top: 0.15rem; }

@media (max-width: 640px) {
  .content { margin: 1rem auto 2rem; padding: 0 0.75rem; }
  .topbar { flex-wrap: wrap; gap: 0.5rem; }
  .nav { gap: 0.7rem; }
}
