:root {
  color-scheme: light;
  --c-bg: #f4f5f7;
  --c-card: #ffffff;
  --c-ink: #0f172a;
  --c-muted: #64748b;
  --c-line: #e2e8f0;
  --c-grid: #e8edf3;
  --c-indigo: #4f46e5;
  --c-teal: #0d9488;
  --c-amber: #d97706;
  --c-red: #dc2626;
  --c-green: #16a34a;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.05), 0 8px 24px -18px rgba(15, 23, 42, 0.35);
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --c-bg: #0b1117;
    --c-card: #121a23;
    --c-ink: #e6edf5;
    --c-muted: #8fa1b3;
    --c-line: #1f2a37;
    --c-grid: #1c2733;
    --c-indigo: #8b93ff;
    --c-teal: #2dd4bf;
    --c-amber: #fbbf24;
    --c-red: #f87171;
    --c-green: #4ade80;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 30px -24px rgba(0, 0, 0, 0.9);
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(1200px 600px at 15% -10%, rgba(79, 70, 229, 0.07), transparent 60%),
    var(--c-bg);
  color: var(--c-ink);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, "Noto Sans", sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p { margin: 0; }

a { color: inherit; }

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
  background: color-mix(in srgb, var(--c-ink) 7%, transparent);
  padding: 1px 5px;
  border-radius: 5px;
}

.muted { color: var(--c-muted); }

/* ---------------------------------------------------------------- shell -- */

.shell {
  max-width: 1120px;
  margin: 0 auto;
  padding: 26px 20px 44px;
}

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

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  color: #fff;
  background: linear-gradient(145deg, #6366f1, #4338ca 70%);
  box-shadow: 0 6px 16px -8px rgba(79, 70, 229, 0.8);
  flex: none;
}

.brand-text h1 {
  font-size: 19px;
  font-weight: 650;
  letter-spacing: -0.015em;
}

.brand-text p {
  font-size: 12px;
  color: var(--c-muted);
}

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

.refresh-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--c-green);
  opacity: 0.7;
  transition: opacity 0.2s ease;
}

body.is-refreshing .refresh-dot { opacity: 1; animation: blink 0.9s ease-in-out infinite; }
body.is-stale .refresh-dot { background: var(--c-red); opacity: 1; animation: none; }

@keyframes blink { 50% { opacity: 0.2; } }

.seg {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  background: var(--c-card);
  border: 1px solid var(--c-line);
  border-radius: 999px;
  box-shadow: var(--shadow);
}

.seg a {
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
  color: var(--c-muted);
}

.seg a:hover { color: var(--c-ink); }

.seg a.is-active {
  background: var(--c-ink);
  color: var(--c-card);
}

.btn-ghost {
  border: 1px solid var(--c-line);
  background: var(--c-card);
  color: var(--c-muted);
  padding: 7px 13px;
  border-radius: 999px;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.btn-ghost:hover { color: var(--c-ink); }

/* ------------------------------------------------------------- rangebar -- */

.rangebar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px 16px;
  flex-wrap: wrap;
  margin: -4px 0 16px;
}

.range-summary {
  display: flex;
  align-items: baseline;
  gap: 4px 10px;
  flex-wrap: wrap;
  min-width: 0;
}

.range-label {
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.range-meta { font-size: 11.5px; color: var(--c-muted); }

.range-notice { font-size: 11.5px; color: var(--c-amber); }

.range-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.daterange { position: relative; }

.daterange > summary { list-style: none; }
.daterange > summary::-webkit-details-marker { display: none; }
.daterange > summary::marker { content: ""; }

.daterange[open] > summary {
  color: var(--c-ink);
  border-color: color-mix(in srgb, var(--c-indigo) 45%, var(--c-line));
}

.daterange > summary.is-on {
  color: var(--c-ink);
  border-color: color-mix(in srgb, var(--c-indigo) 55%, var(--c-line));
  background: color-mix(in srgb, var(--c-indigo) 8%, var(--c-card));
}

.daterange-form {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  z-index: 20;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  width: 300px;
  padding: 12px;
  background: var(--c-card);
  border: 1px solid var(--c-line);
  border-radius: 12px;
  box-shadow: 0 18px 44px -26px rgba(15, 23, 42, 0.55);
}

.daterange-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--c-muted);
}

input[type="date"] {
  padding: 8px 9px;
  font: inherit;
  font-size: 13px;
  color: var(--c-ink);
  background: var(--c-bg);
  border: 1px solid var(--c-line);
  border-radius: 9px;
  outline: none;
}

.daterange-form input[type="date"] { width: 100%; }

input[type="date"]:focus {
  border-color: var(--c-indigo);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--c-indigo) 22%, transparent);
}

.daterange-form .btn-primary {
  grid-column: 1 / -1;
  justify-self: end;
  margin: 0;
  padding: 9px 16px;
  font-size: 13px;
}

/* ---------------------------------------------------------------- cards -- */

.banner {
  border: 1px solid color-mix(in srgb, var(--c-indigo) 30%, var(--c-line));
  background: color-mix(in srgb, var(--c-indigo) 7%, var(--c-card));
  border-radius: var(--radius);
  padding: 13px 16px;
  margin-bottom: 14px;
  font-size: 13px;
}

.cards {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
}

@media (max-width: 1000px) {
  .cards { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 15px 16px 14px;
  background: var(--c-card);
  border: 1px solid var(--c-line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card::before {
  content: "";
  position: absolute;
  inset: 0 auto auto 0;
  width: 100%;
  height: 3px;
  background: var(--tone, transparent);
  opacity: 0.85;
}

.tone-indigo { --tone: var(--c-indigo); }
.tone-teal   { --tone: var(--c-teal); }
.tone-amber  { --tone: var(--c-amber); }
.tone-red    { --tone: var(--c-red); }
.tone-none   { --tone: var(--c-line); }

.card-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--c-muted);
}

.card-value {
  font-size: 30px;
  line-height: 1.1;
  font-weight: 650;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.card-value:empty::after { content: "0"; }

.card-hint {
  font-size: 11.5px;
  color: var(--c-muted);
  line-height: 1.35;
}

/* --------------------------------------------------------------- panels -- */

.panels {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-top: 14px;
}

@media (max-width: 980px) {
  .panels { grid-template-columns: 1fr; }
}

.panel {
  background: var(--c-card);
  border: 1px solid var(--c-line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 16px 12px;
  min-width: 0;
}

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

.panel-head h2 {
  font-size: 14px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.panel-sub {
  font-size: 11.5px;
  color: var(--c-muted);
}

.table-panel { margin-top: 14px; }

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

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  font-size: 11.5px;
  color: var(--c-muted);
  margin: 4px 0 2px;
}

.legend-item { display: inline-flex; align-items: center; }

.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
  flex: none;
}

.chart-svg { display: block; width: 100%; height: auto; }
.chart-wide { display: block; }
.chart-narrow { display: none; }

@media (max-width: 620px) {
  .chart-wide { display: none; }
  .chart-narrow { display: block; }
}

.chart-empty {
  display: grid;
  place-items: center;
  min-height: 170px;
  border: 1px dashed var(--c-line);
  border-radius: 10px;
  color: var(--c-muted);
  font-size: 12.5px;
  margin-top: 8px;
}

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

.table-wrap {
  margin-top: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

table {
  width: 100%;
  min-width: 600px;
  border-collapse: collapse;
  font-size: 12.5px;
  white-space: nowrap;
}

th, td {
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid var(--c-line);
}

thead th {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--c-muted);
  border-bottom: 1px solid var(--c-line);
  background: var(--c-card);
}

thead th:first-child {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--c-card);
}

tbody th {
  font-weight: 550;
  color: var(--c-ink);
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--c-card);
}

tbody tr:hover { background: color-mix(in srgb, var(--c-indigo) 4%, transparent); }
tbody tr:hover th { background: color-mix(in srgb, var(--c-indigo) 4%, var(--c-card)); }

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

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

.is-today {
  background: color-mix(in srgb, var(--c-indigo) 6%, transparent);
}

.is-today th {
  font-weight: 700;
  background: color-mix(in srgb, var(--c-indigo) 6%, var(--c-card));
}

.table-hint { display: none; }

@media (max-width: 900px) {
  th, td { padding: 7px 8px; }
  table { font-size: 12px; min-width: 0; }
  .col-optional { display: none; }
}

@media (max-width: 700px) {
  .col-extra { display: none; }
  .table-hint { display: inline; }
}

.tag {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--c-indigo);
  background: color-mix(in srgb, var(--c-indigo) 12%, transparent);
  vertical-align: 1px;
}

/* ---------------------------------------------------------------- foot --- */

.foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 16px;
  padding: 0 4px;
  font-size: 11.5px;
  color: var(--c-muted);
}

.foot-item { display: inline-flex; align-items: center; gap: 7px; flex-wrap: wrap; }

.foot strong { color: var(--c-ink); font-weight: 600; }

.pulse {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--c-muted);
  flex: none;
}

.pulse.live { background: var(--c-green); box-shadow: 0 0 0 3px color-mix(in srgb, var(--c-green) 18%, transparent); }
.pulse.delayed { background: var(--c-amber); box-shadow: 0 0 0 3px color-mix(in srgb, var(--c-amber) 18%, transparent); }
.pulse.stale { background: var(--c-red); box-shadow: 0 0 0 3px color-mix(in srgb, var(--c-red) 18%, transparent); }

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

.login-wrap {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 28px 18px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 26px;
  background: var(--c-card);
  border: 1px solid var(--c-line);
  border-radius: 18px;
  box-shadow: 0 20px 60px -40px rgba(15, 23, 42, 0.6);
}

.login-card .brand-mark { width: 44px; height: 44px; border-radius: 13px; }

.login-card h1 { font-size: 21px; letter-spacing: -0.02em; margin-top: 4px; }

.login-card > p.muted { font-size: 12.5px; }

.field { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }

.field > span {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--c-muted);
}

input[type="password"] {
  width: 100%;
  padding: 11px 12px;
  font: inherit;
  font-size: 14px;
  color: var(--c-ink);
  background: var(--c-bg);
  border: 1px solid var(--c-line);
  border-radius: 10px;
  outline: none;
}

input[type="password"]:focus {
  border-color: var(--c-indigo);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--c-indigo) 22%, transparent);
}

.btn-primary {
  margin-top: 2px;
  padding: 11px 14px;
  font: inherit;
  font-size: 13.5px;
  font-weight: 650;
  color: #fff;
  background: linear-gradient(145deg, #6366f1, #4338ca);
  border: 0;
  border-radius: 10px;
  cursor: pointer;
  box-shadow: 0 10px 22px -14px rgba(79, 70, 229, 0.9);
}

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

.btn-primary:disabled,
input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.error {
  padding: 9px 11px;
  border-radius: 9px;
  font-size: 12.5px;
  color: var(--c-red);
  background: color-mix(in srgb, var(--c-red) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--c-red) 24%, transparent);
}

.fine { font-size: 11px; color: var(--c-muted); line-height: 1.5; }

/* --------------------------------------------------------------- mobile -- */

@media (max-width: 720px) {
  .shell { padding: 18px 14px 34px; }
  .panels { grid-template-columns: 1fr; }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .card-value { font-size: 26px; }
  .topbar { align-items: flex-start; }
  .topbar-actions { width: 100%; justify-content: flex-end; }
  .rangebar { align-items: flex-start; }
  .range-controls { width: 100%; justify-content: space-between; }
  .daterange { position: static; }
  .daterange-form {
    position: static;
    margin-top: 8px;
    width: min(340px, calc(100vw - 44px));
    box-shadow: var(--shadow);
  }
  input[type="date"] { font-size: 16px; }
  .foot { flex-direction: column; align-items: flex-start; gap: 6px; }
}

@media (max-width: 400px) {
  .cards { grid-template-columns: 1fr 1fr; }
  .card { padding: 13px 12px; }
  .card-hint { font-size: 11px; }
}
