:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f0f3f7;
  --border: #e1e6ed;
  --text: #142033;
  --muted: #5f6c7f;
  --grid: #e7ebf0;
  --accent: #1f6fd1;
  --accent-soft: #e3eefc;
  --good: #1a8f55;
  --good-soft: #e1f4ea;
  --warn: #b26a00;
  --warn-soft: #fff1d9;
  --bad: #c62e2e;
  --bad-soft: #fde5e5;
  --chart-1: #1f6fd1;
  --chart-2: #e3832b;
  --chart-3: #2a9d6f;
  --chart-4: #8e5bd8;
  --chart-5: #d14b7c;
  --chart-6: #5c6b80;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 32, 51, 0.06), 0 2px 8px rgba(20, 32, 51, 0.04);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220;
    --surface: #121b2c;
    --surface-2: #18233a;
    --border: #233049;
    --text: #e6ecf5;
    --muted: #93a1b6;
    --grid: #1f2a40;
    --accent: #5aa6ff;
    --accent-soft: #15284a;
    --good: #45c486;
    --good-soft: #10301f;
    --warn: #f0b14a;
    --warn-soft: #3a2a0c;
    --bad: #ff6b6b;
    --bad-soft: #3d1416;
    --chart-1: #5aa6ff;
    --chart-2: #f5a254;
    --chart-3: #45c486;
    --chart-4: #b48cf2;
    --chart-5: #f07aa6;
    --chart-6: #93a1b6;
    --shadow: none;
  }
}

* {
  box-sizing: border-box;
}

/* Author display rules (grid, flex) would otherwise beat the hidden attribute. */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

code {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.86em;
}

h1,
h2 {
  margin: 0;
  letter-spacing: -0.01em;
}

/* ---------- Layout ---------- */

.shell {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 20px 14px;
  border-right: 1px solid var(--border);
  background: var(--surface);
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 17px;
  margin: 0 8px 18px;
}
.brand span:last-child {
  color: var(--muted);
  font-weight: 500;
}
.brand-mark {
  color: var(--accent);
}

#nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
#nav a {
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--text);
  font-weight: 500;
}
#nav a:hover {
  background: var(--surface-2);
  text-decoration: none;
}
#nav a[aria-current] {
  background: var(--accent-soft);
  color: var(--accent);
}

.content {
  min-width: 0;
  padding: 0 28px 48px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 0 14px;
  background: var(--bg);
}
.topbar h1 {
  font-size: 22px;
}
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

@media (max-width: 900px) {
  .shell {
    grid-template-columns: minmax(0, 1fr);
  }
  .sidebar {
    position: sticky;
    z-index: 10;
    height: auto;
    padding: 10px 16px 8px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
  .brand {
    margin: 0 0 8px;
    font-size: 15px;
  }
  #nav {
    flex-direction: row;
    overflow-x: auto;
    scrollbar-width: none;
    margin: 0 -16px;
    padding: 0 16px;
  }
  #nav::-webkit-scrollbar {
    display: none;
  }
  #nav a {
    white-space: nowrap;
    padding: 6px 10px;
  }
  .content {
    padding: 0 16px 40px;
  }
  .topbar {
    position: static;
    flex-wrap: wrap;
  }
  .topbar h1 {
    font-size: 20px;
  }
  #updated {
    order: 3;
    flex-basis: 100%;
  }
}

/* ---------- Cards and grid ---------- */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 380px), 1fr));
  gap: 16px;
  margin-top: 16px;
}

.card {
  min-width: 0;
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.card.wide {
  grid-column: 1 / -1;
}
.card h2 {
  font-size: 14px;
  font-weight: 650;
  margin-bottom: 12px;
  color: var(--text);
}
.card > * + * {
  margin-top: 10px;
}
.card.profile h2 {
  font-size: 20px;
  margin-bottom: 4px;
}
.card h2,
.card.profile p,
.activity-meta,
.kpi-hint {
  overflow-wrap: anywhere;
}

.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 170px), 1fr));
  gap: 12px;
  margin-top: 16px;
}
.card .kpis {
  margin-top: 0;
}
.kpi {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}
.card .kpi {
  background: var(--surface-2);
  border-color: transparent;
}
.kpi-label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.kpi-value {
  font-size: 24px;
  font-weight: 700;
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}
.kpi-hint {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}
.kpi-good .kpi-value {
  color: var(--good);
}
.kpi-warn .kpi-value {
  color: var(--warn);
}
.kpi-bad .kpi-value {
  color: var(--bad);
}

/* ---------- Status strip ---------- */

.status-strip {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 220px), 1fr));
  gap: 12px;
}
.status-tile {
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
}
.status-head {
  display: flex;
  align-items: center;
  gap: 8px;
}
.status-detail {
  margin-top: 4px;
  font-weight: 600;
}
.status-meta {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}
.status-up .dot {
  background: var(--good);
}
.status-down {
  border-color: var(--bad);
  background: var(--bad-soft);
}
.status-down .dot {
  background: var(--bad);
}
.status-unknown .dot {
  background: var(--muted);
}

.dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--muted);
  flex: none;
}
.dot-live {
  background: var(--good);
  animation: pulse 1.6s ease-in-out infinite;
}
.dot-bad {
  background: var(--bad);
}
@keyframes pulse {
  50% {
    opacity: 0.35;
  }
}
@media (prefers-reduced-motion: reduce) {
  .dot-live {
    animation: none;
  }
}

/* ---------- Pills, notes ---------- */

.pill {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  background: var(--surface-2);
  color: var(--muted);
}
.pill + .pill {
  margin-left: 4px;
}
.pill-good {
  background: var(--good-soft);
  color: var(--good);
}
.pill-warn {
  background: var(--warn-soft);
  color: var(--warn);
}
.pill-bad {
  background: var(--bad-soft);
  color: var(--bad);
}
.pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.pills .pill + .pill {
  margin-left: 0;
}

.note {
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
}
.note-setup {
  background: var(--accent-soft);
}
.note-error {
  background: var(--bad-soft);
}
.muted,
.hint {
  color: var(--muted);
}
.hint {
  font-size: 13px;
}
.empty {
  color: var(--muted);
  font-size: 14px;
  margin: 4px 0;
}
.empty.good {
  color: var(--good);
}
.good {
  color: var(--good);
}
.bad {
  color: var(--bad);
}
.loading {
  color: var(--muted);
  padding: 24px 0;
}
.more {
  font-size: 13px;
  margin-bottom: 0;
}

/* ---------- Tables ---------- */

.table-wrap {
  overflow-x: auto;
  margin: 0 -18px;
  padding: 0 18px;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
th {
  text-align: left;
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  padding: 6px 10px 6px 0;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
td {
  padding: 8px 10px 8px 0;
  border-bottom: 1px solid var(--grid);
  vertical-align: top;
  white-space: nowrap;
}
td.wrap {
  white-space: normal;
  min-width: 200px;
}
td.num,
th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
tr:last-child td {
  border-bottom: 0;
}

/* ---------- Bars and meters ---------- */

.bars {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}
.bars li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 72px;
  grid-template-areas: "label value" "track track";
  gap: 3px 8px;
  font-size: 13.5px;
}
.bar-label {
  grid-area: label;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.bar-hint {
  color: var(--muted);
  margin-left: 6px;
  font-size: 12px;
}
.bar-value {
  grid-area: value;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}
.bar-track {
  grid-area: track;
  height: 6px;
  border-radius: 3px;
  background: var(--surface-2);
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  border-radius: 3px;
  background: var(--accent);
}

.meter + .meter {
  margin-top: 12px;
}
.meter-head {
  display: flex;
  justify-content: space-between;
  font-size: 13.5px;
  margin-bottom: 4px;
}
.meter-head span:last-child {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}
.meter-track {
  height: 8px;
  border-radius: 4px;
  background: var(--surface-2);
  overflow: hidden;
}
.meter-fill {
  height: 100%;
}
.meter-good {
  background: var(--good);
}
.meter-warn {
  background: var(--warn);
}
.meter-bad {
  background: var(--bad);
}

/* ---------- Charts ---------- */

/* Room for the plot and its legend before uPlot draws, so swaps keep the scroll position. */
.chart {
  width: 100%;
  min-height: 260px;
}
.chart-empty {
  min-height: 0;
}
.uplot {
  font-family: inherit;
  color: var(--text);
}
.u-legend {
  font-size: 12px;
  color: var(--muted);
}
.u-legend .u-marker {
  border-radius: 3px;
}
.u-select {
  background: var(--accent-soft);
}

/* ---------- Alerts ---------- */

.alerts {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}
.alert {
  padding: 10px 12px;
  border-radius: 8px;
  border-left: 3px solid var(--warn);
  background: var(--warn-soft);
}
.alert-critical {
  border-left-color: var(--bad);
  background: var(--bad-soft);
}
.alert-title {
  font-weight: 600;
}
.alert-detail {
  font-size: 13.5px;
  margin-top: 2px;
}
.alert-meta {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

/* ---------- Live feed ---------- */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}
.live-state {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
  margin-right: auto;
}
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.chip {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  border-radius: 999px;
  padding: 4px 10px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.chip.on {
  background: var(--accent-soft);
  border-color: transparent;
  color: var(--accent);
  font-weight: 600;
}
.feed {
  list-style: none;
  margin: 0;
  padding: 0;
}
.activity {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr);
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--grid);
}
.activity:last-child {
  border-bottom: 0;
}
.activity-icon {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--surface-2);
  font-size: 15px;
}
.activity-flights .activity-icon {
  background: var(--accent-soft);
  color: var(--accent);
}
.activity-purchases .activity-icon {
  background: var(--good-soft);
  color: var(--good);
}
.activity-journeys .activity-icon {
  background: var(--warn-soft);
  color: var(--warn);
}
.activity-line {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 8px;
}
.activity-label {
  font-weight: 600;
}
.activity-meta {
  font-size: 12.5px;
  color: var(--muted);
  margin-top: 2px;
}
.activity-fresh {
  animation: arrive 2.4s ease-out;
}
@keyframes arrive {
  from {
    background: var(--accent-soft);
  }
}
@media (prefers-reduced-motion: reduce) {
  .activity-fresh {
    animation: none;
  }
}
.compact-feed .activity {
  padding: 7px 0;
}
.route {
  font-variant-numeric: tabular-nums;
}

/* ---------- Controls ---------- */

.button {
  appearance: none;
  border: 0;
  border-radius: 8px;
  padding: 8px 14px;
  font: inherit;
  font-weight: 600;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}
.button:disabled {
  opacity: 0.55;
  cursor: default;
}
.button.secondary {
  background: var(--surface-2);
  color: var(--text);
}
.button.danger {
  background: var(--bad-soft);
  color: var(--bad);
}
.button.small {
  padding: 5px 10px;
  font-size: 13px;
}
.button.large {
  width: 100%;
  padding: 13px 16px;
  font-size: 16px;
}
.search {
  width: min(100%, 420px);
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
button:focus-visible,
a:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Sign-in ---------- */

.login-body {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 16px;
}
.login {
  width: min(100%, 380px);
  padding: 28px 24px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.login .brand {
  margin: 0 0 20px;
}
.login h1 {
  font-size: 22px;
}
.login p {
  margin: 8px 0 20px;
}
.status {
  min-height: 1.4em;
  font-size: 14px;
  margin: 14px 0 0 !important;
}
.status[data-tone="error"] {
  color: var(--bad);
}
