:root {
  color-scheme: light dark;
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #1a1d21;
  --muted: #6b7280;
  --border: #e2e5e9;
  --accent: #2563eb;
  --danger: #dc2626;
  --ok: #16a34a;

  /* categorical series palette (validated: see references/palette.md in the
     dataviz skill; fixed hue order, never cycle within the first 8 slots) */
  --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 */
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --card: #1d2025;
    --text: #eef0f2;
    --muted: #9aa1ab;
    --border: #2c3036;
    --accent: #4f8cff;
    --danger: #f87171;
    --ok: #4ade80;

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

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

#app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 16px 64px;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

header h1 { font-size: 1.25rem; margin: 0; }

h2 { font-size: 1rem; margin: 0 0 12px; }

button {
  font: inherit;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
}
button.primary { background: var(--accent); color: white; border-color: var(--accent); }
button.danger { color: var(--danger); border-color: var(--danger); }
button:disabled { opacity: 0.5; cursor: default; }

input {
  font: inherit;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  border-radius: 6px;
  padding: 8px 10px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 16px;
}

.login-card { max-width: 340px; margin: 80px auto; }
.login-card h1 { font-size: 1.1rem; margin-top: 0; }
.field { margin-bottom: 12px; display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 0.85rem; color: var(--muted); }
.field input { width: 100%; }
.error { color: var(--danger); font-size: 0.85rem; min-height: 1.2em; }
.hint { font-size: 0.8rem; color: var(--muted); }
.empty-state { text-align: center; color: var(--muted); padding: 24px 0; }

/* settings panel */
.settings-row { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.settings-row .field { margin-bottom: 0; min-width: 140px; }

/* rank tables */
.rank-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 720px) { .rank-grid { grid-template-columns: 1fr; } }
.rank-table { width: 100%; border-collapse: collapse; }
.rank-table th, .rank-table td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
.rank-table th { color: var(--muted); font-weight: 500; }
.rank-value { font-weight: 600; text-align: right; }

/* etf manager */
.etf-table { width: 100%; border-collapse: collapse; margin-bottom: 12px; }
.etf-table th, .etf-table td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); }
.etf-table th { color: var(--muted); font-weight: 500; font-size: 0.85rem; }
.etf-table input[type=text] { width: 100%; }
.add-etf-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.add-etf-row input { flex: 1; min-width: 140px; }

/* graphs */
.date-range-row { display: flex; align-items: flex-end; gap: 16px; margin-bottom: 16px; }

.overview-chart-card { padding-bottom: 8px; }
.graph-row { padding: 12px 0; border-bottom: 1px solid var(--border); }
.graph-row:last-child { border-bottom: none; }
.graph-row-title { font-weight: 600; margin-bottom: 8px; }
.graph-label { font-size: 0.8rem; color: var(--muted); margin-bottom: 4px; }
.chart-slot { min-height: 160px; position: relative; }
.chart-slot svg { display: block; width: 100%; }

.chart-line { fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.chart-line.dashed { stroke-dasharray: 6 4; }
.chart-end-marker-ring { fill: var(--card); }
.chart-grid { stroke: var(--border); stroke-width: 1; }
.chart-axis { font-size: 9px; fill: var(--muted); }
.chart-empty { font-size: 12px; fill: var(--muted); }
.chart-end-label { font-size: 9px; fill: var(--muted); }
.chart-crosshair { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; pointer-events: none; }
.chart-hover-point { pointer-events: none; }

.chart-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 4px 0 14px; font-size: 0.8rem; color: var(--muted); }
.chart-legend-item { display: flex; align-items: center; gap: 6px; }
.chart-legend-swatch { width: 12px; height: 3px; border-radius: 2px; flex: none; }
.chart-legend-swatch.dashed { background-image: linear-gradient(90deg, currentColor 50%, transparent 50%); background-size: 6px 3px; background-color: transparent !important; color: inherit; }

.chart-tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 0.78rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  white-space: nowrap;
  z-index: 5;
}
.chart-tooltip-date { color: var(--muted); margin-bottom: 3px; }
.chart-tooltip-row { display: flex; align-items: center; gap: 6px; }
.chart-tooltip-key { display: inline-block; width: 10px; height: 2px; flex: none; }
.chart-tooltip-label { color: var(--muted); }
.chart-tooltip-value { font-weight: 600; margin-left: auto; padding-left: 10px; }
