:root {
  color-scheme: light dark;
  --bg: #f5f4ef;
  --surface: #ffffff;
  --surface-2: #edebe4;
  --line: #e0ddd3;
  --text: #1d1d1a;
  --muted: #6c6a62;
  --idle: #a09d93;
  --ok: #24764a;
  --ok-bg: #dcefe3;
  --deploy: #235fbd;
  --deploy-bg: #dfeafa;
  --warn: #935c00;
  --warn-bg: #faecd1;
  --bad: #b8322b;
  --bad-bg: #fae2df;
  --idle-bg: #e4e2da;
  --tab-h: 58px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151614;
    --surface: #1f201d;
    --surface-2: #2a2b27;
    --line: #33342f;
    --text: #edece6;
    --muted: #a3a197;
    --idle: #77756c;
    --ok: #62c48d;
    --ok-bg: #173325;
    --deploy: #7db0f5;
    --deploy-bg: #182b47;
    --warn: #e9b35a;
    --warn-bg: #3a2c12;
    --bad: #f08a82;
    --bad-bg: #421e1b;
    --idle-bg: #2a2b27;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

h1, h2, h3, p, ul { margin: 0; padding: 0; }
ul { list-style: none; }
button, select { font: inherit; color: inherit; }

.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }

/* Status band: the one thing to read at a glance. */
.status {
  padding: calc(env(safe-area-inset-top) + 14px) 16px 14px;
  transition: background-color .2s;
}
.status h1 { font-size: 21px; line-height: 1.25; font-weight: 600; letter-spacing: -.01em; }
.status p { font-size: 13px; margin-top: 2px; }
.status-ok { background: var(--ok-bg); color: var(--ok); }
.status-deploy { background: var(--deploy-bg); color: var(--deploy); }
.status-warn { background: var(--warn-bg); color: var(--warn); }
.status-bad { background: var(--bad-bg); color: var(--bad); }
.status-idle, .status-muted { background: var(--idle-bg); color: var(--muted); }

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 14px 16px calc(var(--tab-h) + env(safe-area-inset-bottom) + 20px);
  display: grid;
  gap: 14px;
}

.section-title {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  margin: 0 0 6px 2px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
}
.card-flush { padding: 2px 14px; }

/* Bottom tabs on a phone, a plain row on anything wider. */
.tabs {
  position: fixed;
  z-index: 5;
  left: 0; right: 0; bottom: 0;
  display: flex;
  height: calc(var(--tab-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.tabs a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 11.5px;
  color: var(--muted);
  text-decoration: none;
}
.tabs a[aria-current="page"] { color: var(--text); font-weight: 600; }
.i { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

@media (min-width: 820px) {
  .tabs {
    position: static;
    height: auto;
    padding: 0 max(16px, calc(50% - 344px));
    justify-content: flex-start;
    gap: 22px;
    border-top: 0;
    border-bottom: 1px solid var(--line);
  }
  .tabs a { flex: none; flex-direction: row; gap: 6px; padding: 10px 0; font-size: 14px; }
  .tabs .i { width: 17px; height: 17px; }
  .status { padding-left: max(16px, calc(50% - 344px)); padding-right: max(16px, calc(50% - 344px)); }
  main { padding-bottom: 32px; }
}

/* Running deploy */
.deploy-card { border-color: var(--deploy); }
.deploy-card.is-bad { border-color: var(--bad); }
.deploy-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; font-weight: 600; }
.deploy-who { color: var(--muted); font-size: 13.5px; overflow-wrap: anywhere; margin-top: 1px; }
.steps { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; margin: 10px 0 5px; }
.step { font-size: 10.5px; color: var(--muted); text-align: left; }
.step::before { content: ""; display: block; height: 4px; border-radius: 2px; background: var(--surface-2); margin-bottom: 4px; }
.step.done::before { background: var(--deploy); }
.step.now { color: var(--deploy); font-weight: 600; }
.step.now::before { background: var(--deploy); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .step.now::before { animation: none; } }
.deploy-stage { font-size: 13.5px; margin-top: 8px; }
.deploy-note { font-size: 13px; margin-top: 8px; color: var(--bad); }

/* Host tiles */
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 9px 12px; min-width: 0; }
.tile-label { font-size: 12px; color: var(--muted); }
.tile-value { font-size: 20px; font-weight: 600; letter-spacing: -.01em; line-height: 1.25; white-space: nowrap; }
.tile-sub { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar { height: 3px; border-radius: 2px; background: var(--surface-2); margin-top: 6px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--idle); }
.tile.is-warn { background: var(--warn-bg); border-color: transparent; }
.tile.is-warn .tile-value, .tile.is-warn .tile-label, .tile.is-warn .tile-sub { color: var(--warn); }
.tile.is-warn .bar i { background: var(--warn); }
.tile.is-bad { background: var(--bad-bg); border-color: transparent; }
.tile.is-bad .tile-value, .tile.is-bad .tile-label, .tile.is-bad .tile-sub { color: var(--bad); }
.tile.is-bad .bar i { background: var(--bad); }

/* Rows */
.row { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-top: 1px solid var(--line); min-width: 0; }
.row:first-child { border-top: 0; }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 500; overflow-wrap: anywhere; }
.row-sub { font-size: 12.5px; color: var(--muted); overflow-wrap: anywhere; }
.row-side { font-size: 12.5px; color: var(--muted); text-align: right; white-space: nowrap; }
.dot { flex: none; width: 9px; height: 9px; border-radius: 50%; background: var(--idle); }
.dot-ok { background: var(--ok); }
.dot-deploy { background: var(--deploy); }
.dot-warn { background: var(--warn); }
.dot-bad { background: var(--bad); }
.dot-muted { background: transparent; border: 1.5px solid var(--idle); }

.is-stale .dot:not(.dot-muted) { background: var(--idle); }
.is-stale .deploy-card { border-color: var(--line); }
.is-stale .step.done::before, .is-stale .step.now::before { background: var(--idle); animation: none; }

/* History */
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 9px; padding: 2px; }
.seg button { border: 0; background: none; padding: 5px 11px; border-radius: 7px; font-size: 13.5px; color: var(--muted); cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); font-weight: 600; }
.filters select { background: var(--surface-2); border: 0; border-radius: 9px; padding: 7px 10px; font-size: 13.5px; }
.chip-toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 13.5px; color: var(--muted); }

.day { font-size: 12.5px; font-weight: 600; color: var(--muted); padding: 12px 0 4px; border-top: 1px solid var(--line); }
.day:first-child { border-top: 0; padding-top: 8px; }

details.d { border-top: 1px solid var(--line); }
.day + details.d { border-top: 0; }
details.d summary { list-style: none; display: flex; align-items: center; gap: 10px; padding: 9px 0; cursor: pointer; min-width: 0; }
details.d summary::-webkit-details-marker { display: none; }
.badge { font-size: 11.5px; font-weight: 600; padding: 1px 7px; border-radius: 6px; white-space: nowrap; }
.badge-ok { color: var(--ok); background: var(--ok-bg); }
.badge-deploy { color: var(--deploy); background: var(--deploy-bg); }
.badge-warn { color: var(--warn); background: var(--warn-bg); }
.badge-bad { color: var(--bad); background: var(--bad-bg); }
.badge-idle { color: var(--muted); background: var(--surface-2); }
.d-more { padding: 0 0 12px 19px; font-size: 13px; display: grid; gap: 3px; }
.d-more dt { color: var(--muted); }
.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 2px 12px; margin: 0; }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 10px;
  padding: 9px 14px;
  font-weight: 500;
  cursor: pointer;
}
.btn:active { transform: scale(.985); }
.btn-primary { background: var(--text); color: var(--bg); border-color: var(--text); }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.center { text-align: center; }

.field { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.field:first-child { border-top: 0; }
.field-label { min-width: 0; }
.field-label small { display: block; color: var(--muted); font-size: 12.5px; }
.field select { background: var(--surface-2); border: 0; border-radius: 9px; padding: 7px 10px; font-size: 14px; }
.field input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--text); }
.note { font-size: 13.5px; color: var(--muted); }
.note-box { background: var(--warn-bg); color: var(--warn); border-radius: 10px; padding: 9px 12px; font-size: 13.5px; }

/* Login */
.gate {
  min-height: 100dvh;
  display: grid;
  place-content: center;
  padding: 24px;
  max-width: 400px;
  margin: 0 auto;
  gap: 14px;
  text-align: center;
}
.gate img { width: 72px; height: 72px; border-radius: 16px; margin: 0 auto; display: block; }
.gate h1 { font-size: 22px; font-weight: 600; }
.gate .btn { width: 100%; padding: 12px; }
.error { color: var(--bad); font-size: 14px; }

:focus-visible { outline: 2px solid var(--deploy); outline-offset: 2px; }
