: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.1);
  --series-blue: #2a78d6;
  --series-orange: #eb6834;
  --series-aqua: #1baf7a;
  --series-violet: #4a3aa7;
  --status-good: #0ca30c;
  --status-warning: #fab219;
  --status-serious: #ec835a;
  --status-critical: #d03b3b;
  --shadow-sm: 0 1px 2px rgba(11, 11, 11, 0.06);
  --shadow-md: 0 4px 16px rgba(11, 11, 11, 0.08);
}

@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.1);
    --series-blue: #3987e5;
    --series-orange: #d95926;
    --series-aqua: #199e70;
    --series-violet: #9085e9;
    --status-good: #0ca30c;
    --status-warning: #fab219;
    --status-serious: #ec835a;
    --status-critical: #e66767;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.4);
  }
}

: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.1);
  --series-blue: #3987e5;
  --series-orange: #d95926;
  --series-aqua: #199e70;
  --series-violet: #9085e9;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: var(--page);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: inherit; }

button, input { font-family: inherit; }

:focus-visible {
  outline: 2px solid var(--series-blue);
  outline-offset: 2px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  gap: 16px;
  flex-wrap: wrap;
}

.topbar h1 {
  font-size: 18px;
  margin: 0;
  background: linear-gradient(135deg, var(--series-blue), var(--series-violet));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.topbar .sub {
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 2px;
}

.topbar nav a {
  text-decoration: none;
  font-size: 14px;
  color: var(--text-secondary);
  margin-right: 16px;
}
.topbar nav a.active { color: var(--series-blue); font-weight: 600; }

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

.btn {
  font: inherit;
  font-size: 13px;
  padding: 7px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-primary);
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.05s ease, box-shadow 0.15s ease;
}
.btn:hover { border-color: var(--series-blue); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--series-blue); color: #fff; border-color: var(--series-blue); }
.btn-primary:hover { box-shadow: var(--shadow-sm); filter: brightness(1.05); }

.range-picker { display: flex; gap: 4px; background: var(--page); padding: 3px; border-radius: 8px; border: 1px solid var(--border); flex-wrap: wrap; }
.range-picker button {
  font: inherit; font-size: 13px; padding: 6px 12px; border: none; border-radius: 6px;
  background: transparent; color: var(--text-secondary); cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.range-picker button:hover { color: var(--text-primary); }
.range-picker button.active { background: var(--surface-1); color: var(--text-primary); font-weight: 600; box-shadow: 0 1px 2px var(--border); }

.custom-range { display: none; align-items: center; gap: 6px; margin-left: 6px; }
.custom-range.visible { display: flex; }
.custom-range input {
  font: inherit; font-size: 13px; padding: 5px 8px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--surface-1); color: var(--text-primary);
}

.subnav {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}
.subnav a {
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  padding: 10px 4px;
  margin-right: 16px;
  border-bottom: 2px solid transparent;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.subnav a:hover { color: var(--text-primary); }
.subnav a.active { color: var(--series-blue); border-bottom-color: var(--series-blue); }

main { max-width: 1280px; margin: 0 auto; padding: 24px; }

@media (max-width: 640px) {
  main { padding: 16px; }
  .topbar { padding: 12px 16px; }
  th, td { padding: 8px; }
}

.section { margin-bottom: 32px; }
.section h2 {
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-secondary);
  margin: 0 0 12px;
  display: flex; align-items: center; gap: 8px;
}
.section h2 .badge {
  font-size: 11px; text-transform: none; letter-spacing: 0; padding: 2px 8px;
  border-radius: 999px; background: var(--gridline); color: var(--text-muted);
}

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

.group-label {
  font-size: 12px;
  text-transform: uppercase;
  color: var(--text-secondary);
  font-weight: 600;
  margin-top: 20px;
  margin-bottom: 0;
}

.tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-left: 3px solid var(--gridline);
  border-radius: 8px;
  padding: 12px 14px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}
.tile:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.tile .label { font-size: 12px; color: var(--text-secondary); font-weight: 600; }
.tile .value { font-size: 22px; font-weight: 700; margin: 4px 0 2px; font-variant-numeric: tabular-nums; }
.tile .caption { font-size: 11px; color: var(--text-muted); }

.tile--blue { border-left-color: var(--series-blue); }
.tile--good { border-left-color: var(--status-good); }
.tile--warning { border-left-color: var(--status-warning); }
.tile--critical { border-left-color: var(--status-critical); }
.tile--violet { border-left-color: var(--series-violet); }
.tile--neutral { border-left-color: var(--gridline); }

.panel {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: auto;
  box-shadow: var(--shadow-sm);
}

.locked-panel {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  background: var(--surface-1);
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 18px 20px;
}
.locked-panel .locked-icon { font-size: 20px; opacity: 0.6; line-height: 1; }
.locked-panel strong { display: block; font-size: 13px; margin-bottom: 4px; }
.locked-panel p { margin: 0; font-size: 13px; color: var(--text-muted); line-height: 1.5; }
.locked-panel code { font-size: 12px; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 10px 12px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--gridline); }
th:first-child, td:first-child { text-align: left; }
th { color: var(--text-muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.02em; }
tbody tr { transition: background 0.1s ease; }
tbody tr:hover { background: var(--page); }
tbody tr:last-child td { border-bottom: none; }

tr.row-risk {
  background: color-mix(in srgb, var(--status-critical) 14%, var(--surface-1));
}
tr.row-risk:hover {
  background: color-mix(in srgb, var(--status-critical) 22%, var(--surface-1));
}
td.num, th.num { font-variant-numeric: tabular-nums; }

td input[type="text"], td input[type="number"] {
  width: 100%;
  min-width: 70px;
  font: inherit;
  font-size: 13px;
  padding: 5px 7px;
  border-radius: 5px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-primary);
  text-align: inherit;
}
td input[type="text"]:hover, td input[type="number"]:hover,
td input[type="text"]:focus, td input[type="number"]:focus {
  border-color: var(--border);
  background: var(--page);
}
td input[type="checkbox"] { width: 16px; height: 16px; cursor: pointer; }

.placeholder-panel {
  background: var(--surface-1);
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 24px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

.notice {
  background: var(--surface-1);
  border: 1px solid var(--status-warning);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 16px;
}
.notice strong { color: var(--text-primary); }

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 15% 15%, color-mix(in srgb, var(--series-blue) 12%, transparent), transparent 45%),
    radial-gradient(circle at 85% 85%, color-mix(in srgb, var(--series-violet) 12%, transparent), transparent 45%),
    var(--page);
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 340px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
  box-shadow: var(--shadow-md);
}
.login-card h1 { font-size: 18px; margin: 0 0 4px; }
.login-card p { font-size: 13px; color: var(--text-muted); margin: 0 0 20px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; color: var(--text-secondary); margin-bottom: 4px; }
.field input, .field select {
  width: 100%; font: inherit; font-size: 14px; padding: 9px 10px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--page); color: var(--text-primary);
  transition: border-color 0.15s ease;
}
.field input:focus, .field select:focus { border-color: var(--series-blue); }
.error-msg { color: var(--status-critical); font-size: 13px; margin-bottom: 12px; }

.form-inline { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; }
.form-inline .field { margin-bottom: 0; min-width: 120px; }

.text-muted { color: var(--text-muted); }
.text-good { color: var(--status-good); }
.text-critical { color: var(--status-critical); }

.icon-btn { background: none; border: none; cursor: pointer; color: var(--text-muted); font-size: 13px; }
.icon-btn:hover { color: var(--status-critical); }
