:root {
  --bg: #0b0f17;
  --bg-soft: #0e131d;
  --card: #141a26;
  --card-hover: #182030;
  --border: #232c3d;
  --border-soft: #1b2331;
  --text: #e6e9ef;
  --muted: #8993a8;
  --faint: #5b6478;

  --ok: #00bb7f;
  --warn: #f99c00;
  --down: #fb2c36;
  --unknown: #5b6478;
  --accent: #00bb7f;

  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.28);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background:
    radial-gradient(1100px 520px at 78% -8%, rgba(0,187,127,.07), transparent 60%),
    var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
.muted { color: var(--muted); }
.muted.small { font-size: 12.5px; }
.faint { color: var(--faint); }
.center { text-align: center; }
.error { color: var(--down); }
.spacer { flex: 1; }
.warn-text { color: var(--warn); }
code {
  font-family: var(--mono); font-size: 12.5px; background: var(--bg-soft);
  border: 1px solid var(--border-soft); border-radius: 5px; padding: 1px 5px;
}

/* ---------- Top bar ---------- */
#topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 14px;
  padding: 12px 22px;
  background: rgba(11,15,23,.78);
  backdrop-filter: saturate(140%) blur(12px);
  border-bottom: 1px solid var(--border-soft);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); }
.logo { display: inline-flex; filter: drop-shadow(0 2px 6px rgba(0,187,127,.35)); }
.wordmark { font-weight: 700; font-size: 17px; letter-spacing: -.02em; }
.wordmark .sub {
  margin-left: 5px; font-weight: 600; font-size: 11.5px; color: var(--accent);
  letter-spacing: .12em; text-transform: uppercase; vertical-align: 2px;
}

.tabs { display: flex; gap: 4px; margin-left: 8px; }
.tabs a {
  color: var(--muted); text-decoration: none; font-size: 13.5px; font-weight: 600;
  padding: 7px 12px; border-radius: 8px; transition: .14s;
}
.tabs a:hover { color: var(--text); background: var(--card); }
.tabs a.active { color: var(--text); background: var(--card); border: 1px solid var(--border); }

.apps { display: flex; gap: 6px; align-items: center; margin-right: 6px; }
.app-link {
  font-size: 12.5px; font-weight: 600; color: var(--accent); text-decoration: none;
  padding: 6px 10px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--card); white-space: nowrap;
}
.app-link:hover { background: var(--card-hover); }
.app-link.disabled { color: var(--faint); cursor: default; opacity: .6; }

.pill {
  display: inline-flex; align-items: center; gap: 7px;
  font-weight: 600; font-size: 13px; padding: 5px 12px;
  border-radius: 999px; background: var(--card); border: 1px solid var(--border);
  color: var(--muted);
}
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--unknown); }
.pill.ok { color: #6df0c4; } .pill.ok::before { background: var(--ok); box-shadow: 0 0 0 4px rgba(0,187,127,.16); }
.pill.warn { color: #ffcb70; } .pill.warn::before { background: var(--warn); box-shadow: 0 0 0 4px rgba(249,156,0,.16); }
.pill.down { color: #ffa3a7; } .pill.down::before { background: var(--down); box-shadow: 0 0 0 4px rgba(251,44,54,.16); }

.clock { font-size: 12.5px; font-variant-numeric: tabular-nums; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 9px;
  background: var(--card); color: var(--muted);
  border: 1px solid var(--border); cursor: pointer; transition: .14s;
}
.icon-btn:hover { background: var(--card-hover); color: var(--text); }
.icon-btn.spin svg { animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

#pollbar { height: 2px; background: transparent; position: sticky; top: 59px; z-index: 19; }
#pollfill { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), #00a672); opacity: .7; }

/* ---------- Layout ---------- */
main { padding: 22px; max-width: 1280px; margin: 0 auto; }

/* ---------- Hero (status rollup, reused by cost hero) ---------- */
.hero {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 18px 20px; margin-bottom: 22px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(255,255,255,.02), transparent), var(--card);
  box-shadow: var(--shadow);
}
.cost-hero { gap: 30px; }
.hero-stat { min-width: 120px; }
.hero-stat-label { font-size: 11.5px; text-transform: uppercase; letter-spacing: .1em; color: var(--faint); font-weight: 700; }
.hero-stat-value { font-size: 26px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; margin-top: 2px; }
.hero-history { margin-left: auto; text-align: right; }
.hero-history .sparkline { display: block; margin-top: 4px; }

/* ---------- Sections ---------- */
.section { margin-bottom: 26px; }
.section-head {
  display: flex; align-items: center; gap: 10px;
  margin: 0 2px 12px; font-size: 12px; font-weight: 700;
  letter-spacing: .14em; text-transform: uppercase; color: var(--faint);
}
.section-head::after { content: ""; flex: 1; height: 1px; background: var(--border-soft); }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}
.analytics-grid { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }

/* ---------- Tile ---------- */
.tile {
  position: relative;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 15px 16px;
  cursor: pointer;
  transition: transform .12s ease, background .12s, border-color .12s;
  overflow: hidden;
}
.tile.static { cursor: default; }
.tile::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--unknown); opacity: .9;
}
.tile.ok::before { background: var(--ok); }
.tile.warn::before { background: var(--warn); }
.tile.down::before { background: var(--down); }
.tile:not(.static):hover { transform: translateY(-2px); background: var(--card-hover); border-color: #2c3547; }
.tile.stale { opacity: .5; }

.tile-head { display: flex; align-items: center; gap: 9px; }
.tile-icon {
  width: 30px; height: 30px; border-radius: 8px; flex: 0 0 auto;
  display: grid; place-items: center; font-size: 16px;
  background: var(--bg-soft); border: 1px solid var(--border-soft);
}
.tile-title { font-weight: 600; font-size: 14.5px; letter-spacing: -.01em; }
.tile-fresh { margin-left: auto; font-size: 11.5px; color: var(--faint); font-variant-numeric: tabular-nums; }

.tile-headline {
  margin-top: 11px; font-size: 19px; font-weight: 650; letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
}

/* ---------- Meters ---------- */
.meters { margin-top: 12px; display: grid; gap: 8px; }
.meter-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center; }
.meter-label { font-size: 12px; color: var(--muted); }
.meter-val { font-size: 12px; color: var(--text); font-variant-numeric: tabular-nums; }
.meter-track { grid-column: 1 / -1; height: 6px; border-radius: 999px; background: #1c2432; overflow: hidden; }
.meter-fill { height: 100%; border-radius: 999px; background: var(--ok); transition: width .4s ease; }
.meter-fill.warn { background: var(--warn); }
.meter-fill.down { background: var(--down); }

/* ---------- Expandable detail ---------- */
.tile-detail { margin-top: 13px; border-top: 1px solid var(--border-soft); padding-top: 11px; }
.tile-detail[hidden] { display: none; }
.tile-detail table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.tile-detail td { padding: 4px 6px; border-bottom: 1px solid var(--border-soft); vertical-align: top; }
.tile-detail tr:last-child td { border-bottom: 0; }
.tile-detail td:first-child { color: var(--muted); white-space: nowrap; width: 1%; padding-right: 16px; }
.tile-detail td:last-child { font-family: var(--mono); font-size: 12px; word-break: break-word; }
.tile-detail pre {
  margin: 8px 0 0; padding: 10px; background: #090c12; border: 1px solid var(--border-soft);
  border-radius: 9px; overflow: auto; font-size: 11.5px; max-height: 240px;
}
.tile-links { margin-top: 11px; display: flex; gap: 12px; flex-wrap: wrap; }
.tile-links a { color: var(--accent); text-decoration: none; font-size: 12.5px; font-weight: 500; }
.tile-links a:hover { text-decoration: underline; }

/* ---------- Analytics cards ---------- */
.analytics-card { cursor: default; }
.analytics-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 12px; }
.analytics-stats.muted-row { grid-template-columns: 1fr; margin-top: 8px; }
.stat-label { font-size: 11px; color: var(--faint); text-transform: uppercase; letter-spacing: .08em; font-weight: 700; }
.stat-value { font-size: 17px; font-weight: 650; margin-top: 2px; font-variant-numeric: tabular-nums; }
.chg { font-size: 12px; font-weight: 700; margin-left: 6px; }
.chg.up { color: var(--ok); }
.chg.down-text { color: var(--down); }
.sparkline { margin: 12px 0 4px; display: block; }
.analytics-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 10px; }
.mini-list { list-style: none; margin: 6px 0 0; padding: 0; font-size: 12.5px; display: grid; gap: 4px; }
.mini-list li { display: flex; justify-content: space-between; gap: 8px; }
.mini-list li > span { font-variant-numeric: tabular-nums; }

/* ---------- Login ---------- */
.login { display: grid; place-items: center; min-height: 70vh; }
.login-card {
  text-align: center; padding: 40px 44px; border-radius: 20px;
  background: var(--card); border: 1px solid var(--border); box-shadow: var(--shadow);
}
.login-card h1 { margin: 16px 0 4px; font-size: 26px; letter-spacing: -.02em; }
.login-card h1 span { color: var(--accent); font-weight: 600; font-size: 15px; letter-spacing: .12em; text-transform: uppercase; vertical-align: 4px; }
.login-card button {
  margin-top: 18px; background: #fff; color: #0b0f17; border: 0; border-radius: 10px;
  padding: 11px 22px; font-size: 14.5px; font-weight: 600; cursor: pointer; transition: .14s;
}
.login-card button:hover { transform: translateY(-1px); box-shadow: 0 6px 18px rgba(0,0,0,.4); }

/* ---------- Banner ---------- */
.banner {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  background: #2a1416; border: 1px solid #5a2a2e; color: #ffc2c2;
  padding: 9px 16px; border-radius: 10px; font-size: 13px; box-shadow: var(--shadow);
}
.banner[hidden] { display: none; }

@media (max-width: 780px) {
  .tabs { order: 3; width: 100%; margin: 6px 0 0; }
  .apps { order: 4; width: 100%; flex-wrap: wrap; margin: 4px 0 0; }
}
@media (max-width: 560px) {
  main { padding: 16px; }
  .hero-history { display: none; }
  .analytics-cols { grid-template-columns: 1fr; }
}
