/* The Bridge — dark-first, phone-first.
   Token system per the design-system mockup (proposal §5): semantic color
   (--act = needs the founder), derived -bg mixes, 4-base spacing, type scale.
   Meaning stays stable across themes: --act always means "this needs you". */

:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-2: #1f2630;
  --border: #2d333b;
  --text: #e6edf3;
  --muted: #8b949e;
  --act: #2f81f7;
  --act-press: #1f6feb;
  --good: #3fb950;
  --warn: #d29922;
  --danger: #f85149;
  --info: #8b949e;
}

:root {
  /* derived semantic mixes — replace scattered per-site color-mix() calls */
  --act-bg: color-mix(in srgb, var(--act) 14%, var(--surface-2));
  --good-bg: color-mix(in srgb, var(--good) 16%, transparent);
  --warn-bg: color-mix(in srgb, var(--warn) 14%, transparent);
  --danger-bg: color-mix(in srgb, var(--danger) 14%, transparent);
  --act-border: color-mix(in srgb, var(--act) 45%, var(--border));
  --good-border: color-mix(in srgb, var(--good) 45%, var(--border));
  --warn-border: color-mix(in srgb, var(--warn) 45%, var(--border));
  --danger-border: color-mix(in srgb, var(--danger) 45%, var(--border));
  /* radii */
  --radius: 14px;      /* cards (alias of --r-card, kept for existing rules) */
  --r-card: 14px;
  --r-ctl: 10px;
  --r-pill: 999px;
  /* spacing — 4-base scale */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px;
  /* type scale (1.2 ratio, system stack) */
  --fs-caption: 12px;
  --fs-meta: 13px;
  --fs-body: 15px;
  --fs-title: 17px;
  --fs-screen: 20px;
  --fs-num: 28px;
  /* motion */
  --t-micro: 140ms ease-out;
  --t-slide: 240ms ease;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { margin: 0; font-size: 20px; font-weight: 700; }
.refresh {
  background: none; border: none; color: var(--muted);
  font-size: 22px; min-width: 44px; min-height: 44px; cursor: pointer;
}

main { padding: 12px 12px 24px; max-width: 640px; margin: 0 auto; }

.stack { display: flex; flex-direction: column; gap: 12px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.card h2 { font-size: 16px; margin: 0 0 8px; }
.card-meta {
  display: flex; justify-content: space-between;
  font-size: 13px; margin-bottom: 6px;
}
.question { font-size: 18px; font-weight: 700; margin: 2px 0 12px; line-height: 1.3; }
.muted { color: var(--muted); }

/* Decision options */
.options { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.option {
  display: flex; align-items: center; gap: 10px;
  min-height: 44px; padding: 8px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
}
.option input { accent-color: var(--act); width: 18px; height: 18px; flex: none; }
.option.recommended { border-color: var(--act); background: var(--act-bg); }
.rec-tag {
  margin-left: auto; flex: none;
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  color: var(--act);
}
.why, .impact, .excerpt { font-size: 14px; margin: 6px 0; color: var(--text); }
.unstructured-tag { font-size: 12px; color: var(--warn); margin: -6px 0 8px; }

.freeform summary { color: var(--muted); font-size: 14px; min-height: 32px; cursor: pointer; }
textarea {
  width: 100%; margin-top: 6px;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 10px; font: inherit;
}

.card-actions { display: flex; gap: 10px; margin-top: 12px; align-items: center; }
.card-actions form { display: contents; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 0 18px;
  border-radius: 12px; border: 1px solid var(--border);
  font: inherit; font-weight: 600; text-decoration: none;
  cursor: pointer; color: var(--text); background: var(--surface-2);
}
.btn-primary { background: var(--act); border-color: var(--act); color: #fff; }
.btn-primary:active { background: var(--act-press); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-lg { min-height: 52px; font-size: 17px; width: 100%; }
.btn[disabled] { opacity: .5; }

/* Evidence chips */
.evidence { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.chip {
  font-size: 12px; font-weight: 600;
  padding: 4px 10px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface-2);
}
.chip-good { color: var(--good); border-color: var(--good-border); background: var(--good-bg); }
.chip-warn { color: var(--warn); border-color: var(--warn-border); background: var(--warn-bg); }
.chip-danger { color: var(--danger); border-color: var(--danger-border); background: var(--danger-bg); }
.chip-act { color: var(--act); border-color: var(--act-border); background: var(--act-bg); }
.chip-neutral { color: var(--muted); }

/* Merge-call variant in the unified stack: READY = good spine, BLOCKED = warn.
   The chip carries the word; the spine makes it scannable at thumb speed. */
.pr-card { border-left: 3px solid var(--good); }
.pr-card.pr-blocked { border-left-color: var(--warn); }

.confirm-armed { animation: pulse .35s ease; }
@keyframes pulse { from { transform: scale(.97); } to { transform: scale(1); } }
.pulse { animation: pulse .35s ease; }

/* Optimistic answer (F4): the card starts leaving the moment the founder
   taps; the server response (answered / snoozed / error chip) swaps in. */
.card-leaving { opacity: .35; transform: translateX(24px); transition: opacity var(--t-slide), transform var(--t-slide); }

/* Snoozed (F3): moored, dimmed, undoable. */
.snoozed { opacity: .65; }
.snoozed .question { text-decoration: line-through; }

/* Swipe (F2): horizontal gestures on stack cards; vertical scroll stays native. */
.stack > .card { touch-action: pan-y; }
.card.swiping { transition: none; }
.swipe-hint { font-size: var(--fs-caption); color: var(--muted); margin: 8px 0 0; display: flex; align-items: center; gap: 6px; }
.swipe-hint .arrow { color: var(--act); animation: nudge 2.2s ease-in-out infinite; }
@keyframes nudge { 0%, 100% { transform: translateX(0); } 50% { transform: translateX(6px); } }
@media (hover: hover) and (pointer: fine) { .swipe-hint { display: none; } } /* no swipe on desktop */

.done-card { border-color: color-mix(in srgb, var(--good) 40%, var(--border)); }
.done-card p { margin: 4px 0; }
.error-chip { border-color: color-mix(in srgb, var(--danger) 50%, var(--border)); }
.error-chip p { margin: 4px 0 10px; }

/* Status */
.glance {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: baseline;
  padding: 4px 4px 12px; font-size: 15px; font-weight: 600;
}
.glance-sep { color: var(--muted); }
.glance-warn { color: var(--warn); }
.run-card { margin-bottom: 12px; }
.run-active { border-color: color-mix(in srgb, var(--good) 45%, var(--border)); }
.run-offline { border-color: color-mix(in srgb, var(--warn) 45%, var(--border)); }
.session { margin-top: 8px; }
.session-head { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.session details summary { color: var(--muted); min-height: 32px; cursor: pointer; font-size: 14px; }
.pane {
  background: #010409; border: 1px solid var(--border); border-radius: 10px;
  padding: 10px; font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
  overflow-x: auto; white-space: pre-wrap; word-break: break-word;
  max-height: 40vh; overflow-y: auto;
}
.schedule { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.schedule li { display: flex; flex-direction: column; }
.counts { display: flex; gap: 20px; margin: 8px 0; }
.count { display: flex; flex-direction: column; align-items: flex-start; }
.count-num { font-size: 24px; font-weight: 700; }

/* Settings */
.repo-list { display: flex; flex-direction: column; gap: 4px; margin: 10px 0 14px; }
.repo-row {
  display: flex; align-items: center; gap: 10px;
  min-height: 44px; padding: 4px 8px; border-radius: 10px; cursor: pointer;
}
.repo-row:active { background: var(--surface-2); }
.repo-row input { accent-color: var(--act); width: 18px; height: 18px; flex: none; }
.repo-name { font-weight: 600; }
.repo-row .muted { font-size: 12px; margin-left: auto; text-align: right; }

/* Empty states */
.empty-state { text-align: center; padding: 56px 20px; }
.empty-emoji { font-size: 44px; margin: 0 0 8px; }
.empty-state p { margin: 4px 0; font-size: 16px; }

/* Login */
.login-wrap { padding-top: 18vh; max-width: 360px; margin: 0 auto; text-align: center; }
.login-tagline { color: var(--muted); margin-bottom: 22px; }
.login-form { display: flex; flex-direction: column; gap: 12px; }
.input-lg {
  min-height: 52px; padding: 0 14px; font-size: 17px;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 12px;
}
.login-error { color: var(--danger); margin-top: 14px; }

/* Tab bar */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: flex;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0 6px; min-height: 56px;
  color: var(--muted); text-decoration: none; font-size: 11px;
  position: relative;
}
.tab.active { color: var(--act); }
.tab-icon { font-size: 20px; line-height: 1; }
.badge {
  position: absolute; top: 4px; right: calc(50% - 22px);
  background: var(--danger); color: #fff;
  font-size: 10px; font-weight: 700;
  min-width: 16px; height: 16px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center; padding: 0 4px;
}
/* Overlay filled by GET /badges; the one badge sits over the Review tab
   (first of four). Badge = things awaiting the founder, never info counts. */
.tab-badges { position: absolute; inset: 0; pointer-events: none; }
.badge-review { right: calc(87.5% - 22px); }

/* -- History (F8): the ship's log ----------------------------------------- */
.filters { display: flex; gap: 6px; padding: 2px 4px 10px; overflow-x: auto; }
.f-chip {
  font-size: var(--fs-caption); font-weight: 600; padding: 5px 12px;
  border-radius: var(--r-pill); border: 1px solid var(--border);
  background: var(--surface); color: var(--muted); cursor: pointer; white-space: nowrap;
  font-family: inherit;
}
.f-chip.on { color: var(--act); border-color: var(--act-border); background: var(--act-bg); }

.rollup { margin-bottom: 12px; }
.rollup h2 { font-size: var(--fs-title); }
.kpis { display: flex; justify-content: space-between; margin-bottom: 8px; }
.kpi { display: flex; flex-direction: column; }
.kpi-num { font-size: var(--fs-num); font-weight: 700; line-height: 1.1; }
.kpi-label { font-size: var(--fs-caption); color: var(--muted); }
.sparks { display: flex; align-items: flex-end; gap: 5px; height: 36px; margin-top: 8px; }
.spark { flex: 1; border-radius: 3px 3px 0 0; background: color-mix(in srgb, var(--act) 50%, var(--surface-2)); }
.spark-today { background: var(--act); }
.rollnote { font-size: var(--fs-caption); color: var(--muted); margin: 6px 0 0; }

.day {
  font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: var(--muted); margin: 14px 4px 8px;
}
.entry { position: relative; padding-left: 14px; margin-bottom: 12px; }
.entry::before { content: ""; position: absolute; left: 0; top: 18px; bottom: -14px; width: 2px; background: var(--border); }
.entry:last-of-type::before { display: none; }
.entry .card { border-left: 3px solid var(--border); }
.entry-decision .card { border-left-color: var(--act); }
.entry-merge .card { border-left-color: var(--good); }
.entry-run .card { border-left-color: var(--warn); }
.e-meta { display: flex; justify-content: space-between; font-size: var(--fs-meta); color: var(--muted); margin-bottom: 4px; gap: 8px; }
.e-title { font-size: var(--fs-body); font-weight: 700; margin: 0 0 6px; }
.e-title .q { color: var(--muted); font-weight: 500; }
.e-foot { margin: 0; font-size: var(--fs-meta); color: var(--muted); }
.e-foot a { color: var(--muted); }

details.cost summary { color: var(--muted); font-size: 13px; cursor: pointer; min-height: 28px; margin-top: 6px; }
.cost-table { width: 100%; border-collapse: collapse; font-size: var(--fs-caption); margin-top: 6px; }
.cost-table th { text-align: left; color: var(--muted); font-weight: 600; padding: 4px 6px; border-bottom: 1px solid var(--border); }
.cost-table td { padding: 4px 6px; border-bottom: 1px solid color-mix(in srgb, var(--border) 50%, transparent); }
.cost-table td:last-child, .cost-table th:last-child { text-align: right; }
.cost-table .tot td { font-weight: 700; color: var(--text); border-bottom: none; }

/* htmx request feedback */
.htmx-request .btn-primary, .btn-primary.htmx-request { opacity: .6; }

/* Light mode is total, not partial: every semantic token gets a light value
   (design-system mockup). Derived -bg/-border mixes recompute automatically. */
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f8fa; --surface: #ffffff; --surface-2: #f0f2f5;
    --border: #d0d7de; --text: #1f2328; --muted: #656d76;
    --act: #0969da; --act-press: #0550ae;
    --good: #1a7f37; --warn: #9a6700; --danger: #cf222e; --info: #656d76;
  }
  .pane { background: #101418; color: #e6edf3; }
}

/* Motion: 140ms micro, 240ms slide — and none at all when the OS says so. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

/* -- Executive brief ------------------------------------------------------ */
.brief {
  margin: 14px 16px 4px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.brief-headline { margin: 0 0 8px; font-size: 17px; font-weight: 700; }
.brief-group { margin-top: 10px; }
.brief-label {
  margin: 0 0 4px; font-size: 11px; font-weight: 700;
  letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted);
}
.brief-list { margin: 0; padding-left: 18px; }
.brief-item { margin: 4px 0; font-size: 14px; }
.brief-item a { color: var(--text); text-decoration: none; }
.brief-item a:active { color: var(--act); }
.brief-item .chip { margin-right: 6px; }
.brief-item.tone-warn a { color: var(--warn); }
.brief-item.tone-info a { color: var(--muted); }

/* -- Synthesized decision context ----------------------------------------- */
.context {
  margin: 10px 0;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
}
.context-loading { margin: 0; font-style: italic; }
.context-body p { margin: 6px 0; }
.context-body ul { margin: 6px 0; padding-left: 18px; }
.context-body strong { color: var(--act); font-weight: 600; }
.context-footnote, .context-fallback { margin: 8px 0 0; font-size: 12px; color: var(--muted); }
.context-footnote a, .context-fallback a { color: var(--muted); }

/* -- Quick replies + undo -------------------------------------------------- */
.quick-replies { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.quick-reply {
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--act);
  border-radius: 999px;
  color: var(--act);
  font-size: 13px;
  cursor: pointer;
}
.quick-reply:active { background: var(--act-press); color: var(--text); }
.done-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.done-text { margin: 0; }
.btn-undo { border: 1px solid var(--border); border-radius: 8px; padding: 6px 14px; }
