:root {
  color-scheme: light;
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f0f3f9;
  --border: #dde3ee;
  --grid: #e6eaf2;
  --text: #0e1630;
  --text-2: #4a5677;
  --text-3: #7a86a6;
  --brand: #0647b8;
  --brand-ink: #ffffff;
  --accent: #ffd21f;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --good: #12804f;
  --good-bg: #e3f6ec;
  --warn: #9a6400;
  --warn-bg: #fff3d6;
  --bad: #c02a3a;
  --bad-bg: #fde7ea;
  --shadow: 0 1px 2px rgb(14 22 48 / 6%), 0 4px 16px rgb(14 22 48 / 5%);
  --radius: 12px;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    color-scheme: dark;
    --bg: #070c1d;
    --surface: #0f1730;
    --surface-2: #16203f;
    --border: #233056;
    --grid: #1e2a4c;
    --text: #eef2ff;
    --text-2: #b4bfdd;
    --text-3: #8290b5;
    --brand: #3987e5;
    --series-1: #3987e5;
    --series-2: #d95926;
    --good: #4fd69a;
    --good-bg: #0f3324;
    --warn: #f2c14e;
    --warn-bg: #3a2c08;
    --bad: #ff7a88;
    --bad-bg: #3d1219;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%);
  }
}

:root[data-theme='dark'] {
  color-scheme: dark;
  --bg: #070c1d;
  --surface: #0f1730;
  --surface-2: #16203f;
  --border: #233056;
  --grid: #1e2a4c;
  --text: #eef2ff;
  --text-2: #b4bfdd;
  --text-3: #8290b5;
  --brand: #3987e5;
  --series-1: #3987e5;
  --series-2: #d95926;
  --good: #4fd69a;
  --good-bg: #0f3324;
  --warn: #f2c14e;
  --warn-bg: #3a2c08;
  --bad: #ff7a88;
  --bad-bg: #3d1219;
  --shadow: 0 1px 2px rgb(0 0 0 / 40%);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
}

a {
  color: var(--brand);
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

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

.shell {
  display: grid;
  grid-template-columns: 232px 1fr;
  min-height: 100vh;
}

.side {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 8px 18px;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: #0647b8;
  display: grid;
  place-items: center;
  color: #ffd21f;
  font-weight: 900;
}

.brand small {
  display: block;
  font-weight: 600;
  color: var(--text-3);
  font-size: 12px;
}

.nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 9px;
  color: var(--text-2);
  text-decoration: none;
  font-weight: 600;
}

.nav a:hover {
  background: var(--surface-2);
  color: var(--text);
}

.nav a[aria-current='page'] {
  background: var(--surface-2);
  color: var(--text);
  box-shadow: inset 3px 0 0 var(--brand);
}

.nav svg {
  width: 18px;
  height: 18px;
  flex: none;
}

.side-foot {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0 8px;
  color: var(--text-3);
  font-size: 12px;
}

main {
  padding: 28px 32px 48px;
  min-width: 0;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.page-head h1 {
  margin: 0;
  font-size: 24px;
  letter-spacing: -0.01em;
}

.page-head p {
  margin: 4px 0 0;
  color: var(--text-2);
}

.topbar {
  display: none;
}

@media (max-width: 860px) {
  .shell {
    grid-template-columns: 1fr;
  }
  .side {
    position: fixed;
    inset: 0 auto 0 0;
    width: 260px;
    z-index: 30;
    transform: translateX(-100%);
    transition: transform 0.2s;
  }
  .shell.nav-open .side {
    transform: none;
    box-shadow: var(--shadow);
  }
  .topbar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 20;
  }
  main {
    padding: 20px 16px 40px;
  }
}

/* ------------------------------------------------------------------ pieces */

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

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

.card .sub {
  color: var(--text-3);
  font-size: 12px;
  margin: 0 0 14px;
}

.grid {
  display: grid;
  gap: 16px;
}

.tiles {
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  margin-bottom: 16px;
}

.tile .label {
  color: var(--text-2);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.tile .value {
  font-size: 30px;
  font-weight: 750;
  margin-top: 4px;
  letter-spacing: -0.02em;
}

.tile .hint {
  color: var(--text-3);
  font-size: 12px;
}

.tile.hero .value {
  font-size: 48px;
  line-height: 1.05;
}

.live-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--good);
  margin-right: 6px;
  box-shadow: 0 0 0 3px var(--good-bg);
}

.charts {
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  margin-bottom: 16px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 9px;
  padding: 7px 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.btn:hover {
  background: var(--surface-2);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn.primary {
  background: var(--brand);
  color: var(--brand-ink);
  border-color: transparent;
}

.btn.primary:hover {
  filter: brightness(1.08);
}

.btn.danger {
  color: var(--bad);
  border-color: color-mix(in srgb, var(--bad) 35%, var(--border));
}

.btn.danger.solid {
  background: var(--bad);
  color: #fff;
  border-color: transparent;
}

.btn.sm {
  padding: 4px 9px;
  font-size: 12px;
}

.btn svg {
  width: 16px;
  height: 16px;
  flex: none;
}

.btn.icon svg {
  width: 20px;
  height: 20px;
}

.btn.icon {
  padding: 7px;
}

.toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 14px;
}

.input,
select.input,
textarea.input {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 9px;
  padding: 8px 11px;
  min-width: 0;
}

.input:focus,
.btn:focus-visible,
.nav a:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 1px;
}

.search {
  flex: 1 1 240px;
  max-width: 360px;
}

.seg {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 9px;
  overflow: hidden;
}

.seg button {
  border: 0;
  background: var(--surface);
  padding: 7px 12px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-2);
}

.seg button[aria-pressed='true'] {
  background: var(--surface-2);
  color: var(--text);
  box-shadow: inset 0 -2px 0 var(--brand);
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--grid);
  white-space: nowrap;
}

th {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-3);
  font-weight: 650;
  background: var(--surface-2);
}

tbody tr:last-child td {
  border-bottom: 0;
}

tbody tr.click {
  cursor: pointer;
}

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

td.num,
th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.muted {
  color: var(--text-3);
}

.empty {
  padding: 32px;
  text-align: center;
  color: var(--text-3);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 650;
  background: var(--surface-2);
  color: var(--text-2);
}

.badge.good {
  background: var(--good-bg);
  color: var(--good);
}

.badge.warn {
  background: var(--warn-bg);
  color: var(--warn);
}

.badge.bad {
  background: var(--bad-bg);
  color: var(--bad);
}

.badge svg {
  width: 12px;
  height: 12px;
}

.pager {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 12px;
  color: var(--text-2);
  gap: 10px;
  flex-wrap: wrap;
}

.pos {
  color: var(--good);
}

.neg {
  color: var(--bad);
}

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

.chart {
  position: relative;
}

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

.chart .axis {
  fill: var(--text-3);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

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

.chart .hit {
  fill: transparent;
  cursor: default;
}

.chart .hit:hover + .bar,
.chart .bar.active {
  filter: brightness(1.15);
}

.tip {
  position: absolute;
  pointer-events: none;
  background: var(--text);
  color: var(--bg);
  padding: 6px 9px;
  border-radius: 8px;
  font-size: 12px;
  white-space: nowrap;
  transform: translate(-50%, calc(-100% - 8px));
  opacity: 0;
  transition: opacity 0.1s;
  z-index: 5;
}

.tip strong {
  font-size: 14px;
}

.tip.show {
  opacity: 1;
}

details.data-table {
  margin-top: 10px;
}

details.data-table summary {
  cursor: pointer;
  color: var(--text-2);
  font-size: 12px;
  font-weight: 600;
}

details.data-table table {
  margin-top: 8px;
  font-size: 12px;
}

details.data-table td,
details.data-table th {
  padding: 4px 8px;
}

/* ------------------------------------------------------------------ drawer */

.drawer-back {
  position: fixed;
  inset: 0;
  background: rgb(3 8 22 / 45%);
  z-index: 40;
  display: flex;
  justify-content: flex-end;
}

.drawer {
  width: min(560px, 100%);
  height: 100%;
  background: var(--bg);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.drawer-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.drawer-head h2 {
  margin: 0;
  font-size: 22px;
}

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

.kv div span {
  display: block;
  color: var(--text-3);
  font-size: 12px;
}

.kv div b {
  font-size: 18px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.form {
  display: grid;
  gap: 14px;
}

.form .row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
}

.field label {
  display: block;
  font-weight: 650;
  margin-bottom: 5px;
}

.field .help {
  color: var(--text-3);
  font-size: 12px;
  margin-top: 4px;
}

.field .input {
  width: 100%;
}

.switch {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-weight: 650;
}

.switch input {
  width: 18px;
  height: 18px;
  accent-color: var(--brand);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip-toggle {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  padding: 5px 12px;
  cursor: pointer;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.chip-toggle[aria-pressed='true'] {
  background: var(--brand);
  color: var(--brand-ink);
  border-color: transparent;
}

/* ------------------------------------------------------------------ login */

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
  background: radial-gradient(circle at 30% 20%, #0c2f82, #020b2d 60%, #010720);
}

.login .card {
  width: min(380px, 100%);
  padding: 28px;
}

.login h1 {
  margin: 14px 0 4px;
  font-size: 22px;
}

.login p {
  margin: 0 0 20px;
  color: var(--text-2);
}

.error-text {
  color: var(--bad);
  font-weight: 600;
  min-height: 20px;
}

/* ------------------------------------------------------------------ toast */

#toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translate(-50%, 20px);
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 10px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 0.2s,
    transform 0.2s;
  z-index: 60;
  max-width: calc(100vw - 32px);
}

#toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

#toast.error {
  background: var(--bad);
  color: #fff;
}

.modal-back {
  position: fixed;
  inset: 0;
  background: rgb(3 8 22 / 50%);
  display: grid;
  place-items: center;
  z-index: 50;
  padding: 16px;
}

.modal {
  width: min(440px, 100%);
}

.modal h2 {
  margin-top: 0;
}

.modal .actions {
  justify-content: flex-end;
  margin-top: 16px;
}
