:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --border: #dfe3e8;
  --text: #1b1f24;
  --muted: #5c6672;
  --accent: #2f5fd0;
  --accent-text: #ffffff;
  --ok: #1a7f4b;
  --ok-bg: #e6f4ec;
  --warn: #8a6100;
  --warn-bg: #fdf3e0;
  --bad: #b02a2a;
  --bad-bg: #fbeaea;
  --run: #2f5fd0;
  --run-bg: #e8eefb;
  --log-bg: #1b1f24;
  --log-text: #dfe3e8;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14171a;
    --surface: #1c2024;
    --border: #2d3339;
    --text: #e6e9ec;
    --muted: #97a1ac;
    --accent: #6f9bff;
    --accent-text: #0d1016;
    --ok: #57cf92;
    --ok-bg: #16301f;
    --warn: #e0b154;
    --warn-bg: #33280f;
    --bad: #f18b8b;
    --bad-bg: #331a1a;
    --run: #6f9bff;
    --run-bg: #17203a;
    --log-bg: #0e1116;
    --log-text: #c7ced6;
  }
}

:root[data-theme="dark"] {
  --bg: #14171a; --surface: #1c2024; --border: #2d3339; --text: #e6e9ec;
  --muted: #97a1ac; --accent: #6f9bff; --accent-text: #0d1016;
  --ok: #57cf92; --ok-bg: #16301f; --warn: #e0b154; --warn-bg: #33280f;
  --bad: #f18b8b; --bad-bg: #331a1a; --run: #6f9bff; --run-bg: #17203a;
  --log-bg: #0e1116; --log-text: #c7ced6;
}

* { box-sizing: border-box; }

/* Must outrank .stack/.project, which set display and would otherwise keep a
   hidden section visible: a class selector beats the UA's [hidden] rule. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

.bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 16px; padding-top: max(14px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--border); background: var(--surface);
  position: sticky; top: 0; z-index: 5;
}
.bar h1 { font-size: 16px; margin: 0; letter-spacing: -0.01em; }
.bar-actions { display: flex; gap: 8px; }

main { max-width: 860px; margin: 0 auto; padding: 16px; padding-bottom: 48px; }

h2 { font-size: 15px; margin: 0 0 4px; letter-spacing: -0.01em; }
h3 { font-size: 14px; margin: 0; font-weight: 600; }

.stack { display: flex; flex-direction: column; gap: 12px; margin-bottom: 24px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px;
}
/* Sign-in owns the viewport: nothing else is available until it succeeds. */
.gate-shell { min-height: calc(100dvh - 140px); display: grid; place-items: center; padding: 16px 0; }
.card.center { max-width: 400px; width: 100%; text-align: left; box-shadow: 0 6px 28px rgb(0 0 0 / 0.10); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .card.center { box-shadow: 0 6px 28px rgb(0 0 0 / 0.45); }
}
.card.center h2 { font-size: 18px; margin-bottom: 8px; }
.card.center .muted { margin-bottom: 4px; }
.empty { color: var(--muted); font-size: 13px; padding: 14px; border: 1px dashed var(--border); border-radius: var(--radius); }

.muted { color: var(--muted); font-size: 13px; margin: 4px 0; }
.error {
  color: var(--bad); background: var(--bad-bg); border: 1px solid var(--bad);
  border-radius: var(--radius); padding: 10px 12px; font-size: 13px; margin: 12px 0 0;
}

button {
  font: inherit; font-size: 14px; cursor: pointer; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 8px 14px; min-height: 38px;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: 0.5; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); width: 100%; margin-top: 14px; }
button.ghost { padding: 6px 10px; min-height: 32px; font-size: 13px; color: var(--muted); }
button.small { padding: 5px 10px; min-height: 30px; font-size: 13px; }

label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 4px; }
input {
  font: inherit; width: 100%; padding: 9px 11px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
}
input:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Status pills ---------------------------------------------------------- */
.pill {
  display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 9px;
  border-radius: 999px; white-space: nowrap;
}
.pill.ok      { color: var(--ok);   background: var(--ok-bg); }
.pill.running { color: var(--run);  background: var(--run-bg); }
.pill.bad     { color: var(--bad);  background: var(--bad-bg); }
.pill.warn    { color: var(--warn); background: var(--warn-bg); }
.pill.idle    { color: var(--muted); background: var(--bg); }

/* Project rows ---------------------------------------------------------- */
.project { display: flex; flex-direction: column; gap: 10px; }
.project .row-between { align-items: flex-start; }
.sha { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
.meta { font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 14px; }

/* Commits --------------------------------------------------------------- */
.commit { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.commit-main { min-width: 0; }
.commit-subject { font-size: 14px; overflow-wrap: anywhere; }
.commit-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* Stages ---------------------------------------------------------------- */
.stage { padding: 0; overflow: hidden; }
.stage-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 14px; cursor: pointer; width: 100%; text-align: left;
  border: 0; border-radius: 0; background: transparent; min-height: 0;
}
.stage-head:hover { background: var(--bg); }
.stage-name { display: flex; align-items: center; gap: 10px; min-width: 0; }
.stage-time { font-size: 12px; color: var(--muted); }
.log {
  margin: 0; padding: 12px 14px; background: var(--log-bg); color: var(--log-text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere;
  max-height: 420px; overflow-y: auto; border-top: 1px solid var(--border);
}
.log:empty::before { content: "No output recorded for this stage."; color: var(--muted); }

.spin { display: inline-block; width: 11px; height: 11px; border-radius: 50%;
  border: 2px solid var(--run); border-top-color: transparent; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spin { animation: none; } }

@media (max-width: 520px) {
  .commit { flex-direction: column; }
  .commit-actions { width: 100%; }
  .commit-actions button { flex: 1; }
}
