:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #f0efe9;
  --text: #1d1f1e;
  --muted: #5d6360;
  --line: #e2e0d8;
  --accent: #1f6f5c;
  --accent-ink: #ffffff;
  --accent-soft: #e2f0eb;
  --bad: #9b3b2f;
  --bad-soft: #f6e6e2;
  --good-pill: #2e7d55;
  --mid-pill: #b7791f;
  --low-pill: #8a8f8c;
  --focus: #2f7fd1;
  --shadow: 0 1px 2px rgba(20, 24, 22, .06), 0 4px 14px rgba(20, 24, 22, .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141716;
    --surface: #1c201f;
    --surface-2: #232827;
    --text: #e8ebe9;
    --muted: #a3aba7;
    --line: #2e3432;
    --accent: #4fb596;
    --accent-ink: #0d1412;
    --accent-soft: #1d3530;
    --bad: #e08a7c;
    --bad-soft: #3a2420;
    --good-pill: #3e9e6c;
    --mid-pill: #c28a33;
    --low-pill: #6e7672;
    --focus: #6aaef0;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--accent); }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 6px; }

/* ---------- header ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--line);
}
.top-inner, .tabs, .wrap { max-width: 860px; margin: 0 auto; padding-left: 16px; padding-right: 16px; }
.top-inner { display: flex; align-items: center; justify-content: space-between; padding-top: 12px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; letter-spacing: -.01em; }
.brand-mark { width: 22px; height: 22px; fill: none; stroke: var(--accent); stroke-width: 1.8; stroke-linejoin: round; }
.brand-mark.big { width: 40px; height: 40px; }
.logout { margin: 0; }
.link { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 6px 4px; text-decoration: underline; text-underline-offset: 3px; }

.tabs { display: flex; gap: 4px; padding-top: 10px; overflow-x: auto; }
.tab {
  background: none; border: 0; border-bottom: 2px solid transparent;
  padding: 8px 12px 10px; cursor: pointer; color: var(--muted); font-weight: 560; white-space: nowrap;
}
.tab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.count {
  display: inline-block; min-width: 1.6em; padding: 0 6px; margin-left: 4px;
  border-radius: 999px; background: var(--surface-2); color: var(--muted);
  font-size: 12.5px; font-variant-numeric: tabular-nums; text-align: center;
}
.tab[aria-selected="true"] .count { background: var(--accent-soft); color: var(--accent); }

/* ---------- toolbar ---------- */
.wrap { padding-top: 16px; padding-bottom: 96px; }
.toolbar { display: flex; gap: 8px; }
.toolbar input, .toolbar select {
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; min-height: 42px;
}
.toolbar input { flex: 1; min-width: 0; }
.hint { color: var(--muted); font-size: 14px; margin: 10px 2px 14px; }

/* ---------- cards ---------- */
.group-title { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 26px 2px 10px; font-weight: 650; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow);
  padding: 16px; margin-bottom: 12px;
  transition: opacity .18s ease, transform .18s ease;
}
.card.leaving { opacity: 0; transform: translateX(16px); }
.card-head { display: flex; gap: 12px; align-items: flex-start; }
.fit {
  flex: none; width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center;
  color: #fff; font-weight: 700; font-size: 17px; font-variant-numeric: tabular-nums; background: var(--low-pill);
}
.fit.good { background: var(--good-pill); }
.fit.mid { background: var(--mid-pill); }
.fit.none { background: var(--surface-2); color: var(--muted); font-size: 13px; }
.title { margin: 0; font-size: 17px; line-height: 1.3; font-weight: 650; overflow-wrap: anywhere; }
.title a { color: var(--text); text-decoration: none; }
.title a:hover { text-decoration: underline; text-underline-offset: 3px; }
.meta { color: var(--muted); font-size: 14px; margin-top: 3px; overflow-wrap: anywhere; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0 0; padding: 0; list-style: none; }
.tag { font-size: 12.5px; padding: 2px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.tag.pick { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.tag.warn { background: var(--bad-soft); color: var(--bad); }
.summary { margin: 12px 0 0; }
details { margin-top: 10px; border-top: 1px solid var(--line); padding-top: 8px; }
summary { cursor: pointer; color: var(--accent); font-size: 14.5px; font-weight: 560; list-style: none; padding: 4px 0; }
summary::-webkit-details-marker { display: none; }
summary::before { content: "▸ "; display: inline-block; width: 1em; }
details[open] > summary::before { content: "▾ "; }
.why p { margin: 6px 0; font-size: 15px; }
.why .label { color: var(--muted); font-size: 13px; display: block; }
.kit { font-size: 15px; }
.kit h3, .kit h4 { margin: 14px 0 6px; font-size: 15.5px; }
.kit ul, .kit ol { padding-left: 20px; margin: 6px 0; }
.kit p { margin: 6px 0; }

.actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; align-items: center; }
.btn {
  border-radius: 10px; border: 1px solid var(--line); background: var(--surface); padding: 9px 18px;
  font-weight: 600; cursor: pointer; min-height: 42px; min-width: 96px;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--bad); }
.btn.danger:hover { background: var(--bad-soft); }
.btn.wide { width: 100%; }
.btn[disabled] { opacity: .55; cursor: default; }
.state { font-size: 14px; color: var(--muted); }
.state strong { color: var(--text); font-weight: 600; }

.empty { text-align: center; color: var(--muted); padding: 48px 16px; }
.empty strong { display: block; color: var(--text); font-size: 17px; margin-bottom: 4px; }

/* ---------- auto apply ---------- */
.btn.auto { border-color: var(--accent); color: var(--accent); }
.btn.auto:hover { background: var(--accent-soft); }
.btn.small { min-height: 34px; min-width: 0; padding: 5px 12px; font-size: 14px; text-decoration: none; display: inline-flex; align-items: center; color: inherit; }
.btn.small.primary { color: var(--accent-ink); }
.run-head .pill, .run-head .run-msg { margin-left: 8px; }
.run-head .pill { display: inline-block; }
.run-body { margin-top: 6px; border: 1px solid var(--line); border-radius: 12px; padding: 12px; background: var(--surface-2); }
.run-body > :first-child { margin-top: 0; }
.run.is-active > .run-body { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.pill { font-size: 12.5px; font-weight: 650; padding: 2px 10px; border-radius: 999px; background: var(--surface); color: var(--muted); }
.pill.running, .pill.starting, .pill.queued { background: var(--accent-soft); color: var(--accent); }
.pill.waiting, .pill.manual { background: #fbecc8; color: #7a5300; }
.pill.submitted { background: var(--good-pill); color: #fff; }
.pill.failed, .pill.cancelled { background: var(--bad-soft); color: var(--bad); }
.run-msg { color: var(--muted); font-size: 14px; font-weight: 400; }
.run-shot { display: block; margin-top: 10px; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); background: var(--surface); }
.run-shot img { display: block; width: 100%; height: auto; }
.run-q { margin-top: 10px; padding: 12px; border-radius: 10px; background: var(--surface); border: 2px solid #e2b13c; }
.run-q.approve { border-color: var(--accent); }
.q-title { margin: 0 0 4px; font-size: 13px; font-weight: 650; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.q-text { margin: 0 0 6px; font-weight: 600; white-space: pre-wrap; }
.q-context { margin: 0 0 8px; color: var(--muted); font-size: 14px; white-space: pre-wrap; }
.run-q textarea, .faq textarea, .faq input[type=text] {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; background: var(--surface); resize: vertical;
}
.q-row { display: flex; gap: 10px; align-items: center; justify-content: space-between; margin-top: 8px; flex-wrap: wrap; }
.q-save { font-size: 14px; color: var(--muted); display: inline-flex; gap: 6px; align-items: center; }
.run-log { list-style: none; margin: 10px 0 0; padding: 0; font-size: 13.5px; color: var(--muted); }
.run-log li { padding: 2px 0; overflow-wrap: anywhere; }
.run-log time { font-variant-numeric: tabular-nums; color: var(--text); opacity: .7; }
.run-ctrl { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; align-items: center; }
.run-note { flex-basis: 100%; margin: 4px 0 0; font-size: 14px; }
.banner {
  width: calc(100% - 32px); max-width: 828px; margin: 8px auto 0; padding: 10px 12px 10px 16px; display: flex; gap: 12px; align-items: center; justify-content: space-between;
  background: #fbecc8; color: #4d3500; border-radius: 12px; font-size: 14.5px;
}
.banner[hidden] { display: none; }
.banner .btn { flex-shrink: 0; }
.faq input[type=text] { font-weight: 600; margin-bottom: 8px; }
.faq-new { border-style: dashed; }
@media (prefers-color-scheme: dark) {
  .pill.waiting, .pill.manual { background: #4a3a12; color: #f3cf7a; }
  .banner { background: #4a3a12; color: #f8e2a8; }
}

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%);
  display: flex; gap: 14px; align-items: center;
  background: var(--text); color: var(--bg); border-radius: 12px; padding: 10px 10px 10px 16px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .25); max-width: calc(100% - 32px); z-index: 10;
}
.toast[hidden] { display: none; }
.toast button { background: none; border: 1px solid color-mix(in srgb, var(--bg) 40%, transparent); color: var(--bg); border-radius: 8px; padding: 6px 12px; font-weight: 650; cursor: pointer; }

/* ---------- login ---------- */
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card { width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 28px 24px; box-shadow: var(--shadow); text-align: center; }
.login-card h1 { margin: 10px 0 4px; font-size: 22px; }
.login-card form { text-align: left; margin-top: 20px; }
.login-card label { font-size: 14px; color: var(--muted); }
.login-card input { width: 100%; margin: 6px 0 14px; padding: 11px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); }
.muted { color: var(--muted); margin: 0; }
.error { color: var(--bad); margin: -6px 0 12px; font-size: 14px; }

@media (max-width: 520px) {
  .tabs { gap: 0; padding-left: 6px; padding-right: 6px; }
  .tab { padding: 8px 5px 10px; font-size: 13.5px; }
  .count { margin-left: 2px; padding: 0 4px; min-width: 1.3em; font-size: 11.5px; }
  .card { padding: 14px; }
  .actions .btn { flex: 1; }
  .toolbar select { max-width: 40%; }
}
@media (prefers-reduced-motion: reduce) {
  .card { transition: none; }
}
