:root {
  --bg: #f6f6f4;
  --card: #ffffff;
  --ink: #18181b;
  --muted: #6b6b73;
  --line: #e7e6e2;
  --accent: #3b4ce0;
  --accent-ink: #ffffff;
  --ok: #1f8a4c;
  --warn: #b26a00;
  --bad: #c2362f;
  --run: #3b4ce0;
  --chip: #efeeea;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121213; --card: #1c1c1f; --ink: #f2f2f3; --muted: #9b9ba3; --line: #2b2b30;
    --accent: #8b97ff; --accent-ink: #0d0d10; --ok: #4cc683; --warn: #f0a63a; --bad: #ff6b62; --run: #8b97ff; --chip: #26262b;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- layout ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  padding: calc(var(--safe-top) + 12px) 18px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(14px); -webkit-backdrop-filter: saturate(1.4) blur(14px);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.top h1 { font-size: 28px; line-height: 1.1; margin: 0; letter-spacing: -0.02em; }
main { padding: 4px 16px calc(var(--safe-bottom) + 96px); max-width: 720px; margin: 0 auto; }
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: grid; grid-template-columns: repeat(3, 1fr);
  padding: 6px 8px calc(var(--safe-bottom) + 6px);
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.tabs button {
  border: 0; background: none; padding: 6px 0 4px; border-radius: 10px;
  display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--muted);
  min-height: 48px;
}
.tabs button svg { width: 24px; height: 24px; }
.tabs button[aria-current="page"] { color: var(--accent); font-weight: 600; }

/* ---------- pieces ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 999px;
  background: var(--chip); font-size: 13px; color: var(--muted); white-space: nowrap;
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex: none; }
.pill.ok { color: var(--ok); } .pill.warn { color: var(--warn); } .pill.bad { color: var(--bad); }

.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 18px 4px 8px; }
.list { display: grid; gap: 10px; }
.card {
  background: var(--card); border-radius: var(--radius); padding: 14px 16px;
  border: 1px solid var(--line); text-align: left; width: 100%; display: block;
}
button.card:active { transform: scale(.99); }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.name { font-weight: 600; font-size: 17px; }
.desc { color: var(--muted); font-size: 14px; margin-top: 4px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.meta { color: var(--muted); font-size: 13px; margin-top: 8px; display: flex; flex-wrap: wrap; gap: 4px 12px; }
.state { font-size: 13px; font-weight: 600; display: inline-flex; align-items: center; gap: 6px; }
.state.running { color: var(--run); } .state.idle { color: var(--muted); font-weight: 500; }
.running .dot { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .25; } }
@media (prefers-reduced-motion: reduce) { .running .dot { animation: none; } }

.job .prompt { font-size: 15px; margin-top: 2px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.badge { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--chip); white-space: nowrap; }
.badge.done { color: var(--ok); } .badge.error { color: var(--bad); } .badge.running { color: var(--run); }
.badge.queued { color: var(--warn); } .badge.cancelled { color: var(--muted); }

.seg { display: inline-grid; grid-auto-flow: column; background: var(--chip); border-radius: 10px; padding: 2px; margin: 6px 0 4px; }
.seg button { border: 0; background: none; padding: 6px 14px; border-radius: 8px; font-size: 14px; color: var(--muted); min-height: 32px; }
.seg button[aria-pressed="true"] { background: var(--card); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgb(0 0 0 / .08); }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.stat b { display: block; font-size: 22px; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); }
.bar-row { display: grid; grid-template-columns: 110px 1fr auto; gap: 10px; align-items: center; font-size: 14px; padding: 6px 0; }
.bar { height: 8px; border-radius: 4px; background: var(--chip); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.num { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; text-align: right; }
.note { font-size: 13px; color: var(--muted); margin: 10px 4px; }
.empty { text-align: center; color: var(--muted); padding: 40px 12px; }

/* ---------- sheet ---------- */
.scrim { position: fixed; inset: 0; background: rgb(0 0 0 / .35); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  background: var(--bg); width: 100%; max-width: 720px; max-height: 92vh; overflow: auto;
  border-radius: 18px 18px 0 0; padding: 8px 18px calc(var(--safe-bottom) + 24px);
  animation: up .22s ease-out;
}
@keyframes up { from { transform: translateY(24px); opacity: .6; } }
@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } }
.grab { width: 38px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 10px; }
.sheet h2 { font-size: 22px; margin: 4px 0 2px; letter-spacing: -0.01em; }
.close { border: 0; background: var(--chip); border-radius: 999px; width: 32px; height: 32px; font-size: 18px; line-height: 1; color: var(--muted); }
.block { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-top: 12px; }
.block h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 6px; font-weight: 600; }
.pre { white-space: pre-wrap; word-break: break-word; font-size: 15px; }
.kv { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: 14px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; font-variant-numeric: tabular-nums; }
.files { margin: 0; padding-left: 18px; font-size: 13px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; word-break: break-all; }

/* ---------- forms ---------- */
label { display: block; font-size: 14px; color: var(--muted); margin: 12px 0 6px; }
input, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 12px 14px;
  font-size: 17px; /* 16+ keeps iOS from zooming */
}
textarea { min-height: 120px; resize: vertical; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; width: 100%;
  border: 0; border-radius: 12px; padding: 14px; min-height: 50px; font-weight: 600; font-size: 17px;
  background: var(--accent); color: var(--accent-ink); margin-top: 14px;
}
.btn.secondary { background: var(--chip); color: var(--ink); }
.btn.danger { background: var(--chip); color: var(--bad); }
.btn[disabled] { opacity: .55; }
.error { color: var(--bad); font-size: 14px; margin-top: 10px; }

.login { min-height: 100vh; display: grid; place-items: center; padding: calc(var(--safe-top) + 24px) 22px calc(var(--safe-bottom) + 24px); }
.login .box { width: 100%; max-width: 380px; }
.login .logo { width: 64px; height: 64px; border-radius: 16px; display: block; margin-bottom: 16px; }
.login h1 { font-size: 30px; margin: 0 0 6px; letter-spacing: -0.02em; }
.login p { color: var(--muted); margin: 0 0 8px; }
.link { border: 0; background: none; color: var(--accent); padding: 10px 0; font-size: 15px; }
.toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-bottom) + 84px); transform: translateX(-50%); z-index: 30;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: 90vw;
}
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
