:root {
  color-scheme: light;
  --surface-1:      #fcfcfb;
  --surface-2:      #f9f9f7;
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #898781;
  --gridline:       #e1e0d9;
  --baseline:       #c3c2b7;
  --border:         rgba(11,11,11,0.10);
  --series-dl:       #2a78d6;
  --series-dl-soft:  rgba(42,120,214,0.14);
  --series-up:       #eb6834;
  --series-up-soft:  rgba(235,104,52,0.14);
  --status-good:     #0ca30c;
  --status-warning:  #fab219;
  --status-serious:  #ec835a;
  --status-critical: #d03b3b;
  --card-shadow: 0 1px 2px rgba(11,11,11,0.04), 0 1px 12px rgba(11,11,11,0.03);
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-1:      #1a1a19;
    --surface-2:      #0d0d0d;
    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #898781;
    --gridline:       #2c2c2a;
    --baseline:       #383835;
    --border:         rgba(255,255,255,0.10);
    --series-dl:       #3987e5;
    --series-dl-soft:  rgba(57,135,229,0.16);
    --series-up:       #d95926;
    --series-up-soft:  rgba(217,89,38,0.16);
    --card-shadow: 0 1px 2px rgba(0,0,0,0.3), 0 1px 12px rgba(0,0,0,0.25);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1:      #1a1a19;
  --surface-2:      #0d0d0d;
  --text-primary:   #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted:     #898781;
  --gridline:       #2c2c2a;
  --baseline:       #383835;
  --border:         rgba(255,255,255,0.10);
  --series-dl:       #3987e5;
  --series-dl-soft:  rgba(57,135,229,0.16);
  --series-up:       #d95926;
  --series-up-soft:  rgba(217,89,38,0.16);
  --card-shadow: 0 1px 2px rgba(0,0,0,0.3), 0 1px 12px rgba(0,0,0,0.25);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--surface-2);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

.app { max-width: 1100px; margin: 0 auto; padding: 0 20px 48px; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px 0 18px;
  gap: 12px;
}

.brand { display: flex; align-items: baseline; gap: 10px; }
.brand-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: linear-gradient(135deg, var(--series-dl), var(--series-up));
  display: inline-block;
}
.brand h1 { font-size: 18px; font-weight: 650; margin: 0; letter-spacing: -0.01em; }
.brand-sub { color: var(--text-muted); font-size: 13px; }

.topbar-actions { display: flex; align-items: center; gap: 10px; }

.status-pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 550; color: var(--text-secondary);
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 999px; padding: 5px 10px 5px 8px;
}
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-muted); }
.status-pill--ok .status-dot { background: var(--status-good); }
.status-pill--error .status-dot { background: var(--status-critical); }
.status-pill--error .status-label { color: var(--status-critical); }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 8px;
  background: var(--surface-1); border: 1px solid var(--border);
  color: var(--text-secondary); cursor: pointer;
}
.icon-btn:hover { color: var(--text-primary); }

.tiles {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}
.tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
  box-shadow: var(--card-shadow);
}
.tile-label {
  display: flex; align-items: center; gap: 7px;
  font-size: 12.5px; color: var(--text-secondary); font-weight: 560;
  margin-bottom: 8px;
}
.tile-value {
  font-size: 26px; font-weight: 650; letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}
.tile-sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; font-variant-numeric: tabular-nums; }

.swatch { width: 9px; height: 9px; border-radius: 2px; display: inline-block; }
.swatch--dl { background: var(--series-dl); }
.swatch--up { background: var(--series-up); }

.panel {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 18px 8px;
  box-shadow: var(--card-shadow);
  margin-bottom: 16px;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px; flex-wrap: wrap; gap: 8px;
}
.panel-head h2 { font-size: 14.5px; font-weight: 620; margin: 0; }
.panel-sub { font-size: 12px; color: var(--text-muted); }

.range-group { display: inline-flex; gap: 2px; background: var(--surface-2); border-radius: 8px; padding: 2px; }
.range-btn {
  border: none; background: transparent; color: var(--text-secondary);
  font-size: 12.5px; font-weight: 560; padding: 5px 10px; border-radius: 6px;
  cursor: pointer;
}
.range-btn.is-active { background: var(--surface-1); color: var(--text-primary); box-shadow: 0 1px 2px var(--border); }

.legend { display: flex; gap: 16px; font-size: 12.5px; color: var(--text-secondary); margin-bottom: 6px; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }

.chart-wrap { position: relative; width: 100%; }

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

.torrent-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 10px;
  padding-bottom: 14px;
}

.tcard {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
}

.tcard-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 8px;
  margin-bottom: 9px;
}
.tcard-name {
  font-size: 13.5px; font-weight: 570; color: var(--text-primary);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  min-width: 0;
}
.tcard-badges { display: flex; align-items: center; gap: 6px; flex: none; }
.tcard-tag {
  flex: none;
  font-size: 10.5px; font-weight: 650; color: var(--series-up);
  background: var(--series-up-soft);
  border-radius: 999px; padding: 2px 8px;
  text-transform: uppercase; letter-spacing: 0.03em;
  white-space: nowrap;
}

.ratio-badge {
  flex: none;
  font-size: 11px; font-weight: 650;
  border-radius: 999px; padding: 2px 8px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.ratio-badge--good { color: var(--status-good); background: rgba(12,163,12,0.14); }
.ratio-badge--warning { color: #a86a00; background: rgba(250,178,25,0.20); }
.ratio-badge--critical { color: var(--status-critical); background: rgba(208,59,59,0.14); }
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .ratio-badge--warning { color: var(--status-warning); }
}
:root[data-theme="dark"] .ratio-badge--warning { color: var(--status-warning); }

.segbar {
  position: relative;
  height: 9px;
  border-radius: 3px;
  overflow: hidden;
  background: repeating-linear-gradient(90deg, var(--gridline) 0 7px, var(--surface-1) 7px 9px);
  margin-bottom: 9px;
}
.segbar-fill {
  position: absolute; inset: 0; width: 0%;
  background: repeating-linear-gradient(90deg, var(--series-dl) 0 7px, var(--surface-2) 7px 9px);
  border-radius: 3px;
}
.segbar-fill.is-complete {
  background: repeating-linear-gradient(90deg, var(--series-up) 0 7px, var(--surface-2) 7px 9px);
}

.tcard-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  font-size: 12px; color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}
.tcard-row + .tcard-row { margin-top: 4px; }
.tcard-row .num { color: var(--text-primary); font-weight: 560; }

.state {
  display: inline-flex; align-items: center; gap: 6px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.state-dot { width: 6px; height: 6px; border-radius: 50%; flex: none; }
.state-dot--good { background: var(--status-good); }
.state-dot--warning { background: var(--status-warning); }
.state-dot--critical { background: var(--status-critical); }
.state-dot--muted { background: var(--text-muted); }

.tcard-up { color: var(--series-up); font-weight: 560; white-space: nowrap; }
.tcard-dl { color: var(--series-dl); font-weight: 560; white-space: nowrap; }

@media (max-width: 640px) {
  .tiles { grid-template-columns: 1fr; }
  .panel-head { align-items: flex-start; }
}
