:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --surface-2: #f4f3f0;
  --page: #f2f1ee;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.09);
  --border-strong: rgba(11, 11, 11, 0.16);
  --series-1: #2a78d6;
  --series-1-wash: rgba(42, 120, 214, 0.10);
  --series-2: #eb6834;
  --series-2-wash: rgba(235, 104, 52, 0.12);
  --good: #0ca30c;
  --warning: #fab219;
  --critical: #d03b3b;
  --critical-wash: rgba(208, 59, 59, 0.08);
  --radius-lg: 14px;
  --radius-md: 10px;
  --radius-sm: 7px;
  --shadow-card: 0 1px 2px rgba(11, 11, 11, 0.04), 0 6px 20px -8px rgba(11, 11, 11, 0.10);
  --shadow-pop: 0 8px 30px -10px rgba(11, 11, 11, 0.22);
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-1: #18181a;
    --surface-2: #1f1f21;
    --page: #101012;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #8b8a86;
    --gridline: #2c2c2e;
    --baseline: #3a3a3d;
    --border: rgba(255, 255, 255, 0.09);
    --border-strong: rgba(255, 255, 255, 0.16);
    --series-1: #3987e5;
    --series-1-wash: rgba(57, 135, 229, 0.14);
    --series-2: #d95926;
    --series-2-wash: rgba(217, 89, 38, 0.16);
    --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px -10px rgba(0, 0, 0, 0.55);
    --shadow-pop: 0 10px 34px -10px rgba(0, 0, 0, 0.6);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #18181a;
  --surface-2: #1f1f21;
  --page: #101012;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #8b8a86;
  --gridline: #2c2c2e;
  --baseline: #3a3a3d;
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.16);
  --series-1: #3987e5;
  --series-1-wash: rgba(57, 135, 229, 0.14);
  --series-2: #d95926;
  --series-2-wash: rgba(217, 89, 38, 0.16);
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px -10px rgba(0, 0, 0, 0.55);
  --shadow-pop: 0 10px 34px -10px rgba(0, 0, 0, 0.6);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-feature-settings: "cv11", "ss01", "tnum" 0;
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  position: relative;
}

.bg-illustration {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  object-fit: fit;
  object-position: center bottom;
  opacity: 0.5;
  z-index: 0;
  pointer-events: none;
}

.topbar,
.wrap {
  position: relative;
  z-index: 1;
}

/* ---------------------------------------------------------------- header */

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: blur(5px) saturate(1.4);
  background: color-mix(in srgb, var(--surface-1) 48%, transparent);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1600px;
  margin: 0 auto;
  padding: 14px 28px;
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.01em;
}

.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

.station-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

.station-chip .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
}

.station-chip.live .dot {
  background: var(--good);
  box-shadow: 0 0 0 3px rgba(12, 163, 12, 0.18);
}

/* ---------------------------------------------------------------- layout */

.wrap {
  max-width: 1600px;
  margin: 0 auto;
  padding: 28px 28px 90px;
}

.page-intro {
  margin-bottom: 22px;
}

.page-intro h1 {
  font-size: 22px;
  margin: 0;
  letter-spacing: -0.015em;
}

.card {
  background: color-mix(in srgb, var(--surface-1) 80%, transparent);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-card);
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.card-head h2 {
  font-size: 14.5px;
  margin: 0;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 9px;
}

.card-head .step-no {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 21px;
  height: 21px;
  border-radius: 50%;
  background: var(--series-1);
  color: white;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
}

.card-head-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* ---------------------------------------------------------------- upload */

.upload-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.file-field {
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-md);
  padding: 14px 14px 12px;
  background: var(--surface-2);
  transition: border-color 0.15s, background 0.15s;
}

.file-field:has(input:focus) {
  border-color: var(--series-1);
}

.file-field.filled {
  border-style: solid;
  border-color: color-mix(in srgb, var(--good) 45%, var(--border-strong));
}

.file-field label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.file-field input[type="file"] {
  width: 100%;
  font-size: 12px;
  color: var(--text-secondary);
}

.file-field input[type="file"]::file-selector-button {
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 12px;
  margin-right: 10px;
  border-radius: 7px;
  border: 1px solid var(--border-strong);
  background: var(--surface-1);
  color: var(--text-primary);
  cursor: pointer;
}

.file-field input[type="file"]::file-selector-button:hover {
  background: var(--surface-2);
}

.file-field .hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 6px;
  line-height: 1.4;
}

/* ---------------------------------------------------------------- buttons */

button {
  font-family: inherit;
  cursor: pointer;
}

button.primary {
  background: var(--series-1);
  color: white;
  border: none;
  border-radius: 9px;
  padding: 11px 20px;
  font-size: 14px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: transform 0.08s, box-shadow 0.15s, opacity 0.15s;
  box-shadow: 0 4px 14px -4px color-mix(in srgb, var(--series-1) 65%, transparent);
}

button.primary:hover:not(:disabled) {
  transform: translateY(-1px);
}

button.primary:active:not(:disabled) {
  transform: translateY(0);
}

button.primary:disabled {
  opacity: 0.5;
  cursor: default;
  box-shadow: none;
}

button.secondary {
  background: var(--surface-1);
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 7px 13px;
  font-size: 12.5px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.12s, border-color 0.12s;
}

button.secondary:hover:not(:disabled) {
  background: var(--surface-2);
  border-color: var(--border-strong);
}

button.secondary:disabled {
  opacity: 0.45;
  cursor: default;
}

button.secondary.active {
  background: var(--series-1);
  border-color: var(--series-1);
  color: white;
}

button.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 7px;
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
}

button.icon-btn:hover {
  background: var(--surface-2);
  color: var(--text-primary);
}

.spinner {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: white;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---------------------------------------------------------------- steps */

.steps {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
}

.step-row {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 12.5px;
  color: var(--text-muted);
  padding: 10px 12px;
  border-radius: var(--radius-md);
  background: var(--surface-2);
  border: 1px solid transparent;
  transition: all 0.2s;
}

.step-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--baseline);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.step-row.running {
  color: var(--text-primary);
  border-color: color-mix(in srgb, var(--series-1) 35%, transparent);
  background: var(--series-1-wash);
}

.step-row.running .step-dot {
  border-color: var(--series-1);
  animation: pulse 1s infinite ease-in-out;
}

.step-row.done {
  color: var(--text-primary);
  background: transparent;
}

.step-row.done .step-dot {
  border-color: var(--good);
  background: var(--good);
}

.step-row.done .step-dot::after {
  content: "";
  width: 5px;
  height: 8px;
  border-right: 2px solid white;
  border-bottom: 2px solid white;
  transform: rotate(45deg) translate(-1px, -1px);
}

.step-row.error {
  color: var(--critical);
  border-color: color-mix(in srgb, var(--critical) 35%, transparent);
  background: var(--critical-wash);
}

.step-row.error .step-dot {
  border-color: var(--critical);
  background: var(--critical);
}

.step-row.error .step-dot::after {
  content: "!";
  color: white;
  font-size: 11px;
  font-weight: 800;
}

@keyframes pulse {

  0%,
  100% {
    box-shadow: 0 0 0 0 color-mix(in srgb, var(--series-1) 35%, transparent);
  }

  50% {
    box-shadow: 0 0 0 5px color-mix(in srgb, var(--series-1) 12%, transparent);
  }
}

.error-banner {
  background: var(--critical-wash);
  border: 1px solid var(--critical);
  color: var(--critical);
  padding: 11px 14px;
  border-radius: var(--radius-md);
  font-size: 13px;
  margin-top: 12px;
  line-height: 1.5;
}

.badge {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--series-1-wash);
  color: var(--series-1);
}

/* ---------------------------------------------------------------- KPIs */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}

.kpi-tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  box-shadow: var(--shadow-card);
}

.kpi-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.kpi-value {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.kpi-value .unit {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-left: 3px;
}

.kpi-sub {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ---------------------------------------------------------------- filters */

.filter-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 12px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 22px;
}

.filter-bar .filter-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
  margin-right: 4px;
}

.preset-pills {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.custom-range {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: 4px;
  padding-left: 10px;
  border-left: 1px solid var(--border-strong);
}

.custom-range input[type="date"] {
  font-size: 12.5px;
  padding: 6px 8px;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  background: var(--surface-1);
  color: var(--text-primary);
}

.custom-range span {
  color: var(--text-muted);
  font-size: 12px;
}

/* ---------------------------------------------------------------- charts */

.chart-block {
  margin-bottom: 8px;
}

.chart-block+.chart-block {
  margin-top: 22px;
}

.chart-block-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 10px;
}

.chart-block h3 {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.chart-block h3 .legend-swatch {
  width: 12px;
  height: 3px;
  border-radius: 2px;
  display: inline-block;
}

.chart-block .chart-meta {
  font-size: 11.5px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.chart-svg {
  width: 100%;
  height: 220px;
  display: block;
  overflow: visible;
  cursor: crosshair;
}

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

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

.chart-svg .axis-label {
  fill: var(--text-muted);
  font-size: 10.5px;
}

.chart-svg .series-line {
  fill: none;
  stroke: var(--series-1);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.chart-svg .series-area {
  fill: url(#gwlGradient);
  opacity: 1;
}

.chart-svg .series-bar {
  fill: var(--series-2);
}

.chart-svg .series-bar:hover {
  fill: color-mix(in srgb, var(--series-2) 80%, black);
}

.chart-svg .crosshair {
  stroke: var(--text-muted);
  stroke-width: 1;
  stroke-dasharray: 3 3;
}

.chart-svg .hover-dot {
  fill: var(--series-1);
  stroke: var(--surface-1);
  stroke-width: 2;
}

.tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--text-primary);
  color: var(--surface-1);
  font-size: 11.5px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 7px;
  white-space: nowrap;
  transform: translate(-50%, -135%);
  opacity: 0;
  transition: opacity 0.1s;
  box-shadow: var(--shadow-pop);
  z-index: 10;
}

.tooltip .tt-value {
  font-size: 12.5px;
}

.tooltip .tt-date {
  opacity: 0.7;
  font-weight: 500;
  margin-left: 6px;
}

.chart-wrap {
  position: relative;
}

/* ---------------------------------------------------------------- table */

.table-scroll {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}

table.data-table th,
table.data-table td {
  padding: 9px 12px;
  text-align: right;
  border-bottom: 1px solid var(--gridline);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

table.data-table th:first-child,
table.data-table td:first-child {
  text-align: left;
  font-variant-numeric: normal;
  font-weight: 600;
}

table.data-table th {
  color: var(--text-secondary);
  font-weight: 700;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  background: var(--surface-2);
  position: sticky;
  top: 0;
}

table.data-table tbody tr:hover {
  background: var(--surface-2);
}

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

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 14px;
  font-size: 12.5px;
  color: var(--text-secondary);
}

.pagination .page-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.hidden {
  display: none !important;
}

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

footer.app-footer {
  margin-top: 34px;
  padding: 16px 0 4px;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 11.5px;
  text-align: center;
}

@media (max-width: 720px) {

  .wrap,
  .topbar-inner {
    padding-left: 16px;
    padding-right: 16px;
  }

  .card {
    padding: 16px;
  }
}