:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --page: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --border: rgba(11, 11, 11, 0.10);
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --status-good: #0ca30c;
  --status-critical: #d03b3b;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --page: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --gridline: #2c2c2a;
    --border: rgba(255, 255, 255, 0.10);
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --status-good: #0ca30c;
    --status-critical: #e66767;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --page: #0d0d0d;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --gridline: #2c2c2a;
  --border: rgba(255, 255, 255, 0.10);
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --status-good: #0ca30c;
  --status-critical: #e66767;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page);
  color: var(--text-primary);
  min-height: 100vh;
}

.wrap {
  max-width: 1080px;
  margin: 0 auto;
  padding: 24px 20px 64px;
}

header.top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 0 24px;
  flex-wrap: wrap;
}

header.top h1 {
  font-size: 20px;
  font-weight: 700;
  margin: 0;
}

header.top .updated {
  font-size: 13px;
  color: var(--text-muted);
}

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

.logout-btn {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 10px;
  cursor: pointer;
}

.logout-btn:hover {
  color: var(--text-primary);
  border-color: var(--text-secondary);
}

/* --- gate --- */

#gate {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 70vh;
}

.gate-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  width: 100%;
  max-width: 340px;
  text-align: center;
}

.gate-card h2 {
  font-size: 16px;
  margin: 0 0 4px;
}

.gate-card p {
  font-size: 13px;
  color: var(--text-secondary);
  margin: 0 0 20px;
}

.gate-card input {
  width: 100%;
  padding: 10px 12px;
  font-size: 15px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--page);
  color: var(--text-primary);
  margin-bottom: 12px;
  text-align: center;
  letter-spacing: 0.04em;
}

.gate-card button {
  width: 100%;
  padding: 10px 12px;
  font-size: 14px;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  background: var(--series-1);
  color: #ffffff;
  cursor: pointer;
}

.gate-card button:hover {
  filter: brightness(1.08);
}

.gate-error {
  color: var(--status-critical);
  font-size: 13px;
  margin-top: 12px;
  min-height: 16px;
}

/* --- content --- */

#content {
  display: none;
}

.sheet-section {
  margin-bottom: 32px;
}

.sheet-section h2 {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 0 0 12px;
}

.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}

.tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
}

.tile .label {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.tile .value {
  font-size: 24px;
  font-weight: 700;
  font-variant-numeric: proportional-nums;
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  font-size: 13px;
}

table.data-table th,
table.data-table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--gridline);
}

table.data-table th {
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

table.data-table td {
  font-variant-numeric: tabular-nums;
}

table.data-table tr:last-child td {
  border-bottom: none;
}

#error-banner {
  display: none;
  background: var(--surface-1);
  border: 1px solid var(--status-critical);
  color: var(--status-critical);
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 13px;
  margin-bottom: 20px;
}

.loading {
  color: var(--text-muted);
  font-size: 13px;
  padding: 40px 0;
  text-align: center;
}

/* --- dashboard sections --- */

.dash-section {
  margin-bottom: 40px;
}

.dash-section h2 {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 0 0 14px;
}

/* --- hero KPI tiles --- */

.hero-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}

.hero-tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-top: 3px solid var(--accent, var(--border));
  border-radius: 14px;
  padding: 24px 22px;
}

.hero-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 10px;
}

.hero-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent, var(--text-muted));
  flex: none;
}

.hero-value {
  font-size: 44px;
  font-weight: 800;
  line-height: 1.1;
  font-variant-numeric: proportional-nums;
  letter-spacing: -0.01em;
}

/* --- evolution charts (small multiples) --- */

.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
}

.chart-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}

.chart-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.chart-svg {
  width: 100%;
  height: auto;
  display: block;
  overflow: visible;
}

.chart-gridline {
  stroke: var(--gridline);
  stroke-width: 1;
}

.chart-zeroline {
  stroke: var(--gridline);
  stroke-width: 1;
  stroke-dasharray: 2 2;
}

.chart-ytick,
.chart-xtick {
  font-size: 9px;
  fill: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.chart-endlabel {
  font-size: 11px;
  font-weight: 700;
  fill: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.chart-empty {
  color: var(--text-muted);
  font-size: 13px;
  padding: 30px 0;
  text-align: center;
}

/* --- debt summary --- */

.debt-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px 22px;
}

.debt-total {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding-bottom: 16px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--gridline);
}

.debt-total-label {
  font-size: 13px;
  color: var(--text-muted);
}

.debt-total-value {
  font-size: 28px;
  font-weight: 800;
  font-variant-numeric: proportional-nums;
}

.debt-row {
  margin-bottom: 14px;
}

.debt-row:last-child {
  margin-bottom: 0;
}

.debt-row-head {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  margin-bottom: 6px;
}

.debt-row-head span:first-child {
  color: var(--text-secondary);
}

.debt-row-head span:last-child {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.debt-bar-track {
  height: 8px;
  border-radius: 4px;
  background: var(--gridline);
  overflow: hidden;
}

.debt-bar-fill {
  height: 100%;
  border-radius: 4px;
}
