:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --accent: #0284c7;
  --ok: #15803d;
  --ok-bg: #dcfce7;
  --bad: #b91c1c;
  --bad-bg: #fee2e2;
  --warn: #a16207;
  --warn-bg: #fef9c3;
  --info-bg: #e0f2fe;
  --needs: #c2410c;
  --needs-bg: #fff7ed;
  --radius: 14px;
  --tap: 44px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120;
    --surface: #111a2e;
    --surface-2: #17223a;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --border: #1e2a44;
    --accent: #38bdf8;
    --ok: #4ade80;
    --ok-bg: #12301f;
    --bad: #f87171;
    --bad-bg: #3a1618;
    --warn: #facc15;
    --warn-bg: #3a3212;
    --info-bg: #0c2a3e;
    --needs: #fb923c;
    --needs-bg: #2e1a0c;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: var(--accent); text-decoration: none; }
button, input { font: inherit; }
h1 { font-size: 1.35rem; margin: 0.2rem 0 0.4rem; }
h2 { font-size: 1.05rem; margin: 1.4rem 0 0.6rem; }
h3 { font-size: 1rem; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.center { text-align: center; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.85em; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 0.5rem;
  padding: calc(0.5rem + env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) 0.5rem max(1rem, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 0.5rem; color: var(--text); font-weight: 650; min-height: var(--tap); }
.brand img { border-radius: 7px; }
.topbar-right { display: flex; align-items: center; gap: 0.4rem; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: var(--tap); min-height: var(--tap);
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface); color: var(--text); font-size: 1.15rem; cursor: pointer;
}
.pill { font-size: 0.8rem; padding: 0.25rem 0.6rem; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.pill.stale { background: var(--warn-bg); color: var(--warn); font-weight: 600; }

main { max-width: 1100px; margin: 0 auto; padding: 0.75rem max(1rem, env(safe-area-inset-left)) 3rem; }

.banner { padding: 0.7rem 1rem; border-radius: var(--radius); margin: 0.75rem 0; }
#offline { margin: 0.5rem 1rem; }
.banner.warn { background: var(--warn-bg); color: var(--warn); }
.banner.bad { background: var(--bad-bg); color: var(--bad); }
.banner.info { background: var(--info-bg); }

.headline { font-size: 1.05rem; margin: 0.5rem 0 0; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.9rem 1rem; }
.grid { display: grid; gap: 0.75rem; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }

.needs { border: 2px solid var(--needs); background: var(--needs-bg); border-radius: var(--radius); padding: 0.8rem 1rem; }
.needs h2 { margin-top: 0; color: var(--needs); display: flex; align-items: center; gap: 0.5rem; }
.needs.clear { border-color: var(--border); background: var(--surface); }
.needs.clear h2 { color: var(--ok); }
.needs ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.5rem; }
.needs li { background: var(--surface); border-radius: 10px; padding: 0.6rem 0.75rem; border: 1px solid var(--border); }
.needs li ol { margin: 0.3rem 0 0; padding-left: 1.2rem; display: block; }
.needs li ol li { background: none; border: 0; padding: 0.1rem 0; }
.count { display: inline-flex; min-width: 1.6rem; height: 1.6rem; align-items: center; justify-content: center; border-radius: 999px; background: var(--needs); color: #fff; font-size: 0.85rem; padding: 0 0.4rem; }

a.project { display: block; color: var(--text); min-height: var(--tap); transition: border-color 0.15s; }
a.project:hover, a.project:focus-visible { border-color: var(--accent); }
.project-head { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; margin-bottom: 0.4rem; }
.badge { font-size: 0.75rem; font-weight: 650; padding: 0.15rem 0.55rem; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.active { background: var(--ok-bg); color: var(--ok); }
.badge.paused { background: var(--warn-bg); color: var(--warn); }
.badge.needs { background: var(--needs-bg); color: var(--needs); border: 0; padding: 0.15rem 0.55rem; }
.badges { display: flex; gap: 0.3rem; flex-wrap: wrap; }
.stats { display: flex; flex-wrap: wrap; gap: 0.3rem 1rem; font-size: 0.85rem; color: var(--muted); margin: 0.4rem 0; }
.stats b { color: var(--text); font-weight: 650; }
.summary { margin: 0.4rem 0 0; font-size: 0.9rem; }
.progress { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin: 0.5rem 0 0.2rem; }
.progress > span { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.refs { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-top: 0.5rem; }
.ref { font-size: 0.75rem; padding: 0.1rem 0.45rem; border-radius: 6px; background: var(--surface-2); }
.ref.merged, .ref.ci_passed { color: var(--ok); }
.ref.ci_failed, .ref.refused, .ref.conflicting { color: var(--bad); }

.tiles { display: grid; gap: 0.6rem; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); margin: 0.75rem 0; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 0.6rem 0.8rem; }
.tile .v { font-size: 1.35rem; font-weight: 700; }
.tile .k { font-size: 0.8rem; color: var(--muted); }

.capacity { display: grid; gap: 0.5rem; }
.cap-row { display: grid; grid-template-columns: minmax(90px, 1fr) 2fr auto; gap: 0.75rem; align-items: center; }
.cap-row.disabled { opacity: 0.55; }
.meter { height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--ok); }
.meter.medium > span { background: var(--warn); }
.meter.high > span { background: var(--bad); }

.list { list-style: none; margin: 0; padding: 0; }
.list > li { padding: 0.6rem 0; border-bottom: 1px solid var(--border); }
.list > li:last-child { border-bottom: 0; }
.row { display: flex; gap: 0.5rem; align-items: baseline; justify-content: space-between; flex-wrap: wrap; }
.status { font-size: 0.72rem; font-weight: 700; padding: 0.1rem 0.45rem; border-radius: 6px; background: var(--surface-2); color: var(--muted); letter-spacing: 0.02em; }
.status.SUCCEEDED, .status.DONE { background: var(--ok-bg); color: var(--ok); }
.status.FAILED, .status.FAILED_ADMISSION { background: var(--bad-bg); color: var(--bad); }
.status.RUNNING, .status.VERIFYING, .status.FINALIZING, .status.LEASED, .status.PREFLIGHT, .status.ADMITTED { background: var(--info-bg); color: var(--accent); }
.status.AWAITING_APPROVAL, .status.WAITING_CAPACITY, .status.QUEUED, .status.PENDING, .status.READY, .status.PARKED_DECISION { background: var(--warn-bg); color: var(--warn); }
.untrusted { margin: 0.3rem 0 0; font-size: 0.85rem; color: var(--muted); border-left: 3px solid var(--border); padding-left: 0.6rem; overflow-wrap: anywhere; }

.timeline { list-style: none; margin: 0; padding: 0 0 0 1rem; border-left: 2px solid var(--border); }
.timeline li { position: relative; padding: 0.35rem 0 0.35rem 0.5rem; }
.timeline li::before { content: ""; position: absolute; left: -1.42rem; top: 0.75rem; width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.timeline li.tl-ok::before { background: var(--ok); }
.timeline li.tl-bad::before { background: var(--bad); }
.timeline li.tl-needs::before { background: var(--needs); }
.timeline li.tl-info::before { background: var(--accent); }

.spark { width: 100%; height: 70px; display: block; }
.spark path.line { fill: none; stroke: var(--accent); stroke-width: 2; vector-effect: non-scaling-stroke; }
.spark path.line2 { fill: none; stroke: var(--ok); stroke-width: 2; vector-effect: non-scaling-stroke; }
.legend { display: flex; gap: 1rem; font-size: 0.8rem; color: var(--muted); }
.legend .a::before, .legend .b::before { content: ""; display: inline-block; width: 10px; height: 3px; margin-right: 0.3rem; vertical-align: middle; background: var(--accent); }
.legend .b::before { background: var(--ok); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  min-height: var(--tap); padding: 0 1.1rem; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); cursor: pointer; font-weight: 600;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: 0.6; cursor: default; }
.auth { max-width: 420px; margin: 8vh auto 0; display: grid; gap: 1rem; }
.auth input { min-height: var(--tap); width: 100%; padding: 0 0.8rem; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.auth form { display: grid; gap: 0.6rem; }
.error { color: var(--bad); }
.back { display: inline-flex; align-items: center; min-height: var(--tap); }

@media (max-width: 520px) {
  .grid { grid-template-columns: 1fr; }
  .cap-row { grid-template-columns: 1fr auto; }
  .cap-row .meter { grid-column: 1 / -1; grid-row: 2; }
  .brand span { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
