:root {
  /* Spectrum — mark only. Never in UI, type, or layout. */
  --spec-cyan: #0996c3;
  --spec-green: #1aa121;
  --spec-yellow: #eab602;
  --spec-red: #e70101;
  --spec-magenta: #cf1173;
  --spec-indigo: #110978;

  /* Working palette — five tokens, one accent. */
  --cream: #f8f9f3;
  --ink: #0f0e0c;
  --deep: #1f1b17;
  --crimson: #a0182b;
  --bone: #ebe3d0;

  /* Type */
  --font-display: 'Inter', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

  /* Derived neutrals — ink at opacity, so the palette stays closed. */
  --muted: rgba(15, 14, 12, 0.56);
  --faint: rgba(15, 14, 12, 0.40);
  --line: rgba(15, 14, 12, 0.12);
  --line-strong: rgba(15, 14, 12, 0.24);
  --tint: rgba(15, 14, 12, 0.03);
  --tint-2: rgba(15, 14, 12, 0.06);
  --crimson-tint: rgba(160, 24, 43, 0.07);
  --crimson-line: rgba(160, 24, 43, 0.30);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--cream);
  color: var(--ink);
  font-family: var(--font-display);
  font-size: 16px;
  line-height: 1.6;
  letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--crimson); text-decoration: none; }
a:hover { text-decoration: underline; }

code {
  font-family: var(--font-mono);
  font-size: 0.82em;
  letter-spacing: 0.02em;
  background: var(--tint-2);
  padding: 1px 5px;
  border-radius: 4px;
}

/* ---- The mark: prismatic ring ----------------------------------------- */
/* Three overlaid primary circles (green/red/indigo), blended additively so
   the secondary stops fall on the overlaps — not a hue sweep. The geometry
   and blend live in orchard-mark.svg, the single source of truth for the
   mark (also the favicon). Never recolored, reordered, or rotated. */
.ring {
  --ring-size: 22px;
  width: var(--ring-size);
  height: var(--ring-size);
  flex: none;
  background: center / contain no-repeat url("/static/orchard-mark.svg");
}
.ring-hero { --ring-size: 60px; }

@media (prefers-reduced-motion: no-preference) {
  /* Hero only — the ring breathes, once, slowly. Static everywhere else. */
  .ring-hero { animation: breathe 6s ease-in-out infinite; }
}
@keyframes breathe {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.02); }
}

/* ---- Eyebrow / mono micro-labels -------------------------------------- */
.eyebrow {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ---- Top bar ---------------------------------------------------------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 22px;
  padding: 14px 24px;
  background: var(--cream);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: baseline; gap: 9px; color: var(--ink); }
.brand:hover { text-decoration: none; }
.brand .ring { align-self: center; --ring-size: 20px; }
.brand-name { font-weight: 800; font-size: 18px; letter-spacing: -0.022em; }
.brand-sub {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}
.topbar nav { display: flex; align-items: center; gap: 20px; flex: 1; }
.topbar nav a { color: var(--muted); font-size: 14px; font-weight: 500; }
.topbar nav a:hover { color: var(--ink); text-decoration: none; }
.topbar .spacer, .spacer { flex: 1; }
.who { color: var(--muted); font-size: 13px; }

.container { max-width: 980px; margin: 0 auto; padding: 32px 24px 64px; }
.footer {
  text-align: center;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  padding: 28px;
  border-top: 1px solid var(--line);
}

/* ---- Typography ------------------------------------------------------- */
h1 { font-size: 30px; font-weight: 800; letter-spacing: -0.026em; margin: 0 0 16px; }
h2 { font-size: 18px; font-weight: 700; letter-spacing: -0.012em; margin: 30px 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.right { text-align: right; }
.hidden { display: none; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
section { margin-bottom: 8px; }

/* ---- Buttons ---------------------------------------------------------- */
button, .btn {
  display: inline-block;
  cursor: pointer;
  font-family: var(--font-display);
  border: 1px solid var(--line-strong);
  background: var(--cream);
  color: var(--ink);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  letter-spacing: -0.01em;
  transition: background .15s, border-color .15s, color .15s;
}
.btn:hover, button:hover { background: var(--tint-2); border-color: var(--ink); text-decoration: none; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.primary, .btn.primary {
  background: var(--crimson);
  border-color: var(--crimson);
  color: var(--cream);
}
.primary:hover, .btn.primary:hover { filter: brightness(0.9); background: var(--crimson); border-color: var(--crimson); color: var(--cream); }
.danger, .btn.danger { color: var(--crimson); border-color: var(--crimson-line); background: var(--cream); }
.danger:hover, .btn.danger:hover { background: var(--crimson-tint); border-color: var(--crimson); }
.link { background: none; border: none; color: var(--crimson); padding: 0; font-weight: 500; }
.link:hover { background: none; text-decoration: underline; }
.inline { display: inline; }

/* ---- Tables ----------------------------------------------------------- */
.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--cream);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}
.table th, .table td { text-align: left; padding: 11px 13px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th {
  background: var(--tint);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
}
.table tr:last-child td { border-bottom: none; }

.badge {
  font-family: var(--font-mono);
  background: var(--tint);
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 6px;
  padding: 1px 8px;
  font-size: 11px;
  letter-spacing: 0.04em;
}

/* ---- Forms ------------------------------------------------------------ */
label { display: block; margin: 10px 0; font-size: 14px; font-weight: 500; }
input, select, textarea {
  width: 100%;
  margin-top: 5px;
  padding: 9px 11px;
  background: var(--cream);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  color: var(--ink);
  font-family: var(--font-display);
  font-size: 14px;
}
textarea { resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--crimson); }
.hint { color: var(--muted); font-size: 12px; font-weight: 400; }
.form-card { background: var(--cream); border: 1px solid var(--line); border-radius: 12px; padding: 20px; max-width: 560px; }
.filters { display: flex; align-items: flex-end; gap: 16px; margin: 12px 0; }
.filters label { margin: 0; }
.inline-check { display: inline-flex; align-items: center; gap: 6px; }
.inline-check input { width: auto; margin: 0; }

/* ---- Auth ------------------------------------------------------------- */
.auth-card { max-width: 400px; margin: 64px auto; background: var(--cream); border: 1px solid var(--line); border-radius: 14px; padding: 32px; }
.lockup { display: flex; align-items: center; gap: 16px; }
.wordmark { font-size: 38px; font-weight: 800; letter-spacing: -0.035em; line-height: 0.98; margin: 0; }
.auth-card .eyebrow { margin: 14px 0 2px; }
.lede { margin: 4px 0 0; font-size: 15px; }
.tabs { display: flex; gap: 8px; margin: 22px 0 8px; border-bottom: 1px solid var(--line); }
.tab { padding: 7px 12px; color: var(--muted); font-weight: 500; font-size: 14px; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab:hover { text-decoration: none; color: var(--ink); }
.tab.active { color: var(--ink); border-bottom-color: var(--crimson); }

/* ---- Flash ------------------------------------------------------------ */
.flash { padding: 11px 15px; border-radius: 8px; margin: 10px 0; background: var(--tint); border-left: 3px solid var(--line-strong); }
.flash-success { background: var(--tint); border-left-color: var(--ink); }
.flash-error { background: var(--crimson-tint); border-left-color: var(--crimson); }
.flash-info { background: var(--tint); border-left-color: var(--line-strong); }
.flash-message { font-weight: 600; }
.flash-hint { margin-top: 4px; color: var(--muted); }
.flash-detail { margin-top: 4px; font-family: var(--font-mono); font-size: 12px; color: var(--muted); white-space: pre-wrap; }
.flash-meta { margin-top: 6px; font-size: 11px; color: var(--faint); display: flex; gap: 12px; }
.flash-meta code { background: var(--tint-2); }

/* ---- Error page ------------------------------------------------------- */
.error-page { max-width: 640px; margin: 36px auto; background: var(--cream); border: 1px solid var(--line); border-radius: 14px; padding: 32px; }
.error-status { font-family: var(--font-mono); font-size: 44px; font-weight: 500; color: var(--crimson); line-height: 1; }
.error-page h1 { font-size: 22px; margin: 10px 0 12px; }
.error-hint { color: var(--muted); }
.error-meta { display: flex; gap: 28px; margin: 16px 0; }
.error-meta dt { font-family: var(--font-mono); font-size: 11px; text-transform: uppercase; letter-spacing: 0.12em; color: var(--muted); }
.error-meta dd { margin: 4px 0 0; }
.error-context { margin: 12px 0; }
.error-context summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.error-context .diff th { width: 30%; }
.error-actions { display: flex; gap: 10px; margin-top: 18px; }

/* ---- Stats ------------------------------------------------------------ */
.stats { display: flex; gap: 14px; margin-bottom: 26px; }
.stat { flex: 1; background: var(--cream); border: 1px solid var(--line); border-radius: 12px; padding: 18px; color: var(--muted); transition: border-color .15s; }
.stat:hover { border-color: var(--line-strong); text-decoration: none; }
.stat .num { display: block; font-size: 30px; font-weight: 800; letter-spacing: -0.03em; color: var(--ink); }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.card { background: var(--cream); border: 1px solid var(--line); border-radius: 10px; padding: 15px; }
.empty { background: var(--cream); border: 1px dashed var(--line-strong); border-radius: 12px; padding: 30px; text-align: center; color: var(--muted); }

.cleanup-bar { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; background: var(--cream); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin: 14px 0; }

/* ---- Proposals -------------------------------------------------------- */
.proposal { background: var(--cream); border: 1px solid var(--line); border-left-width: 3px; border-radius: 10px; padding: 15px 17px; margin-bottom: 14px; }
.proposal.status-pending { border-left-color: var(--crimson); }
.proposal.status-approved { border-left-color: var(--ink); }
.proposal.status-applied { border-left-color: var(--ink); }
.proposal.status-error { border-left-color: var(--crimson); }
.proposal.status-rejected { border-left-color: var(--line-strong); opacity: .62; }
.proposal-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.kind, .state {
  font-family: var(--font-mono);
  text-transform: uppercase;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.08em;
  padding: 2px 8px;
  border-radius: 5px;
}
.kind { background: var(--tint); border: 1px solid var(--line); color: var(--muted); }
.state { color: var(--muted); }
.state-pending { color: var(--crimson); }
.state-approved { color: var(--ink); }
.state-applied { color: var(--ink); }
.state-error { color: var(--crimson); }
.state-rejected { color: var(--faint); }
.proposal-body { margin: 11px 0; }
.diff { width: 100%; border-collapse: collapse; font-size: 13px; }
.diff th, .diff td { border: 1px solid var(--line); padding: 7px 10px; vertical-align: top; text-align: left; }
.diff th { background: var(--tint); font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); width: 14%; }
.diff .from { color: var(--muted); text-decoration: line-through; white-space: pre-wrap; }
.diff .to { color: var(--ink); font-weight: 500; white-space: pre-wrap; }
.rationale { font-style: italic; }
.apply-result { color: var(--ink); font-weight: 500; font-size: 13px; }
.proposal-actions { display: flex; gap: 8px; }

/* ======================================================================= */
/* Retro flair — carried by type, light and motion. No filters, no boxes.  */
/* ======================================================================= */

/* Terminal prompt + a live caret on the page title. Restrained: one heading. */
.prompt::before {
  content: "› ";
  font-family: var(--font-mono);
  color: var(--crimson);
  font-weight: 500;
  opacity: 0.7;
}
.cursor::after {
  content: "";
  display: inline-block;
  width: 0.5em;
  height: 1.05em;
  margin-left: 0.14em;
  vertical-align: -0.16em;
  background: var(--crimson);
  box-shadow: 0 0 10px var(--crimson);
  animation: caret 1.15s steps(1, end) infinite;
}
@keyframes caret { 50% { opacity: 0; } }

/* Phosphor: the wordmark and primary actions glow faintly, like lit pixels. */
.brand-name { text-shadow: 0 0 14px rgba(160, 24, 43, 0.22); }
.btn.primary, button.primary { text-shadow: 0 0 8px rgba(248, 249, 243, 0.4); }
.btn.primary:hover, button.primary:hover { box-shadow: 0 0 18px var(--crimson-line); }

/* Nav: active-ish hover lifts with a soft glow underline. */
.topbar nav a { position: relative; transition: color .15s, text-shadow .15s; }
.topbar nav a:hover { text-shadow: 0 0 7px var(--crimson-line); }
.topbar nav a::after {
  content: ""; position: absolute; left: 0; right: 100%; bottom: -6px; height: 1px;
  background: var(--crimson); box-shadow: 0 0 6px var(--crimson); transition: right .2s ease;
}
.topbar nav a:hover::after { right: 0; }

/* Numbers read like an instrument: monospaced, tabular, faint glow. */
.stat .num, .navcount, .error-status { font-variant-numeric: tabular-nums; }

/* Pending-count chip — arcade score tag. */
.navcount {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  background: var(--crimson);
  color: var(--cream);
  border-radius: 5px;
  padding: 0 6px;
  letter-spacing: 0.04em;
  box-shadow: 0 0 10px var(--crimson-line);
}

/* Buttons get a quick light-sweep on hover and a tactile press. */
.btn, button { position: relative; overflow: hidden; }
.btn::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(105deg, transparent 40%, rgba(248,249,243,0.18) 50%, transparent 60%);
  background-size: 220% 100%; background-position: 150% 0; transition: background-position .5s ease;
}
.btn:hover::before { background-position: -50% 0; }
button:active, .btn:active { transform: translateY(1px); }

/* Page title makes a tiny "boot" entrance — one beat, then still. */
@media (prefers-reduced-motion: no-preference) {
  h1.prompt { animation: boot .45s ease-out both; }
}
@keyframes boot { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* Inputs glow on focus — phosphor ring instead of a flat outline. */
input:focus, select:focus, textarea:focus { box-shadow: 0 0 0 3px var(--crimson-tint); }

/* Clean up screen: scope | ops, two-up. Borderless — separated by space and a
   hairline, with mono section legends. Not boxes. */
.clean-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 28px; margin: 8px 0 18px; }
@media (max-width: 720px) { .clean-grid { grid-template-columns: 1fr; gap: 18px; } }
.term-box { border: none; padding: 0; margin: 0; min-width: 0; }
.term-box legend { padding: 0; margin-bottom: 6px; }
.board-list { max-height: 230px; overflow-y: auto; padding: 2px 2px 2px 0; }
.op-row { display: flex; align-items: flex-start; gap: 9px; margin: 12px 0; font-weight: 400; }
.op-row input { margin-top: 3px; }

/* "Panel" = a soft readout surface, not a hard box: faint top-lit tint, hairline,
   generous radius. */
.term-panel {
  background: linear-gradient(180deg, var(--tint-2), transparent 60%);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px 18px;
}

/* Processing strip rows. */
.batch-row {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 0; border-bottom: 1px solid var(--line);
}
.batch-row:last-child { border-bottom: none; }

/* Live status dot — a slow phosphor pulse. */
.run-dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--crimson); box-shadow: 0 0 0 0 var(--crimson-line);
  vertical-align: middle; animation: pulse 1.4s ease-out infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(160,24,43,0.45); }
  70% { box-shadow: 0 0 0 7px rgba(160,24,43,0); }
  100% { box-shadow: 0 0 0 0 rgba(160,24,43,0); }
}

@media (prefers-reduced-motion: reduce) {
  .cursor::after, .run-dot, h1.prompt { animation: none; }
  .btn::after { display: none; }
}

/* Footer reads like a status line. */
.footer::before { content: "▌ "; color: var(--crimson); }

/* ---- Markdown builder (Setup → Cleanup format) ------------------------ */
.builder-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 6px; }
.md-toolbar { display: flex; gap: 6px; flex-wrap: wrap; }
.builder { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: stretch; }
@media (max-width: 720px) { .builder { grid-template-columns: 1fr; } }
.md-input { font-family: var(--font-mono); font-size: 13px; line-height: 1.55; margin-top: 0; }
.md-preview {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 16px;
  background: var(--cream);
  overflow: auto;
  font-size: 14px;
}
.md-preview > :first-child { margin-top: 0; }
.md-preview h1 { font-size: 18px; margin: 12px 0 4px; }
.md-preview h2 { font-size: 15px; font-weight: 700; margin: 12px 0 4px; }
.md-preview h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 10px 0 3px; }
.md-preview p { margin: 6px 0; }
.md-preview ul, .md-preview ol { margin: 6px 0; padding-left: 20px; }
.md-preview li { margin: 2px 0; }

/* ---- Pager ------------------------------------------------------------ */
.pager { display: flex; align-items: center; gap: 14px; justify-content: center; margin: 18px 0; }
.proposal-head .sel { width: auto; margin: 0; }

/* ---- Progress bar (background run) ------------------------------------ */
.progress {
  height: 6px;
  margin-top: 8px;
  background: var(--tint-2);
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--crimson);
  box-shadow: 0 0 8px var(--crimson-line);
  border-radius: 999px;
  transition: width .5s ease;
}

/* ---- Loading feedback ------------------------------------------------- */
/* Indeterminate top scan bar while a submit is in flight. */
body.working::after {
  content: "";
  position: fixed;
  top: 0; left: 0;
  height: 3px;
  width: 100%;
  z-index: 10000;
  background: linear-gradient(90deg, transparent, var(--crimson), transparent);
  background-size: 38% 100%;
  background-repeat: no-repeat;
  box-shadow: 0 0 8px var(--crimson-line);
  animation: loadbar 1.05s linear infinite;
}
@keyframes loadbar { 0% { background-position: -38% 0; } 100% { background-position: 138% 0; } }

/* Spinner on the clicked button; keeps its label. */
.btn.is-loading { opacity: 0.7; pointer-events: none; }
.btn.is-loading::after {
  content: "";
  display: inline-block;
  width: 0.7em; height: 0.7em;
  margin-left: 0.5em;
  vertical-align: -1px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  body.working::after { animation: none; background-position: 50% 0; }
  .btn.is-loading::after { animation: none; }
}

/* ===================================================================== */
/* Foreman components — built on the tokens above.                       */
/* ===================================================================== */

/* Button variants (aliases over the base .btn) */
.btn-primary { background: var(--crimson); border-color: var(--crimson); color: var(--cream); }
.btn-primary:hover { filter: brightness(0.92); background: var(--crimson); border-color: var(--crimson); color: var(--cream); }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-block { display: block; width: 100%; text-align: center; }
.btn-link { background: none; border-color: transparent; color: var(--muted); }
.btn-link:hover { background: none; color: var(--crimson); border-color: transparent; }
.btn-disabled { opacity: 0.4; pointer-events: none; }

/* Page header */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin: 8px 0 20px; }
.page-head h1 { margin: 0; }
.head-actions { display: flex; gap: 8px; flex-shrink: 0; }

/* Metric cards */
.metrics { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 18px; }
.metric { background: var(--cream); border: 1px solid var(--line); border-radius: 10px; padding: 16px; }
.metric-value { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; }
.metric-label { color: var(--muted); font-size: 12px; margin-top: 2px; }

/* Funnel */
.funnel { display: flex; align-items: stretch; gap: 4px; margin-bottom: 22px; }
.funnel-step { flex: 1; background: var(--cream); border: 1px solid var(--line); border-radius: 10px; padding: 14px; text-align: center; }
.funnel-step:hover { border-color: var(--ink); text-decoration: none; }
.funnel-count { font-size: 24px; font-weight: 800; }
.funnel-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; }
.funnel-arrow { align-self: center; color: var(--faint); font-size: 18px; }

/* Two-column panels */
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; align-items: start; }
.panel { background: var(--cream); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-bottom: 16px; }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 10px; }
.panel-head h2 { margin: 0; font-size: 15px; }

/* Generic list rows */
.list { list-style: none; margin: 0; padding: 0; }
.list-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.list-row:last-child { border-bottom: none; }
.sub { color: var(--muted); font-size: 12px; margin-top: 2px; }

/* Activity feed */
.feed { list-style: none; margin: 0; padding: 0; }
.feed-row { display: flex; align-items: center; gap: 8px; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.feed-row:last-child { border-bottom: none; }
.feed-row > span:nth-child(2), .feed-row > span:nth-child(3) { flex: 1; }
.feed-time { color: var(--faint); font-size: 11px; white-space: nowrap; }
.feed-actor { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; }
.feed-tight .feed-row { font-size: 12px; padding: 5px 0; }
.feed-page .feed-row { padding: 9px 0; }

/* Event kind chips */
.evkind { font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; padding: 2px 7px; border-radius: 999px; background: var(--tint-2); color: var(--muted); white-space: nowrap; }
.evkind-sent, .evkind-followup { background: rgba(9,150,195,0.12); color: var(--spec-cyan); }
.evkind-viewed { background: rgba(17,9,120,0.10); color: var(--spec-indigo); }
.evkind-accepted { background: rgba(26,161,33,0.13); color: var(--spec-green); }
.evkind-declined, .evkind-expired { background: var(--crimson-tint); color: var(--crimson); }
.evkind-ai { background: rgba(207,17,115,0.10); color: var(--spec-magenta); }

/* Status badges + chips */
.badge { text-transform: capitalize; }
.badge-draft { background: var(--tint-2); color: var(--muted); }
.badge-sent { background: rgba(9,150,195,0.14); color: var(--spec-cyan); }
.badge-viewed { background: rgba(17,9,120,0.12); color: var(--spec-indigo); }
.badge-accepted { background: rgba(26,161,33,0.16); color: var(--spec-green); }
.badge-declined { background: var(--crimson-tint); color: var(--crimson); }
.badge-expired { background: var(--tint-2); color: var(--faint); }

.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.chip { padding: 5px 12px; border: 1px solid var(--line); border-radius: 999px; font-size: 13px; text-transform: capitalize; color: var(--muted); }
.chip:hover { border-color: var(--ink); text-decoration: none; }
.chip-on { background: var(--ink); color: var(--cream); border-color: var(--ink); }

/* Callout */
.callout { display: flex; align-items: center; justify-content: space-between; gap: 16px; background: var(--crimson-tint); border: 1px solid var(--crimson-line); border-radius: 12px; padding: 14px 18px; margin-bottom: 18px; }

/* Forms */
.form label, .stack label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 12px; }
.form input, .form select, .form textarea,
.stack input, .stack select, .stack textarea,
.card input, .card select, .card textarea {
  width: 100%; padding: 9px 11px; margin-top: 4px; border: 1px solid var(--line-strong);
  border-radius: 8px; font: inherit; background: var(--cream); color: var(--ink);
}
.form textarea, .card textarea { resize: vertical; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 16px; }
.fset { border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; margin-bottom: 16px; }
.fset legend { font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); padding: 0 6px; }
.form-actions { display: flex; align-items: center; gap: 12px; margin-top: 14px; }
.form-actions.sticky { position: sticky; bottom: 0; background: var(--cream); padding: 12px 0; border-top: 1px solid var(--line); }
.section { font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); margin: 20px 0 8px; border-bottom: 1px solid var(--line); padding-bottom: 5px; }
.stack { margin-bottom: 12px; }
.stack > * + * { margin-top: 8px; }

/* Auth */
.auth { max-width: 380px; margin: 56px auto; text-align: center; }
.auth-mark { display: flex; justify-content: center; margin-bottom: 12px; }
.ring-lg { width: 56px; height: 56px; }
.auth-title { margin: 0; font-size: 28px; }
.auth-sub { color: var(--muted); margin: 4px 0 24px; }
.auth-form { text-align: left; }
.auth-form label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 14px; }
.auth-form input { width: 100%; padding: 10px 12px; margin-top: 4px; border: 1px solid var(--line-strong); border-radius: 8px; font: inherit; }
.auth-alt { margin-top: 18px; color: var(--muted); font-size: 13px; }

/* Error card */
.errorcard { max-width: 520px; margin: 48px auto; text-align: center; background: var(--cream); border: 1px solid var(--line); border-radius: 14px; padding: 36px; }
.errorcode { font-size: 40px; font-weight: 800; color: var(--crimson); }
.errorhint { color: var(--muted); }
.errormeta { font-size: 12px; color: var(--faint); margin: 14px 0; display: flex; gap: 12px; justify-content: center; }

/* Quote editor */
.quote-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin: 8px 0 18px; }
.quote-head h1 { margin: 4px 0 2px; }
.quote-number { font-family: var(--font-mono); font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.editor { display: grid; grid-template-columns: 1fr 320px; gap: 16px; align-items: start; }
.editor-main { min-width: 0; }
.editor-side { display: flex; flex-direction: column; gap: 14px; position: sticky; top: 16px; }
.editor-side h3 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.side-actions > * + * { margin-top: 10px; }

/* Line-item table */
table.items { width: 100%; border-collapse: collapse; margin-top: 6px; }
table.items th { text-align: left; font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); padding: 6px 6px; border-bottom: 1px solid var(--line-strong); }
table.items th.num, table.items td.num { text-align: right; }
table.items td { padding: 4px 6px; border-bottom: 1px solid var(--line); }
table.items input, table.items select { margin-top: 0; padding: 6px 7px; }
table.items .qty, table.items .price { text-align: right; }
table.items .amount { font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--muted); }
.rowx { background: none; border: none; color: var(--faint); font-size: 16px; cursor: pointer; padding: 2px 6px; }
.rowx:hover { color: var(--crimson); background: none; }

/* Totals */
.totals { width: 300px; margin-left: auto; margin-top: 12px; font-variant-numeric: tabular-nums; }
.totals > div { display: flex; align-items: center; justify-content: space-between; padding: 4px 6px; }
.totals .taxrate { width: 56px; display: inline-block; padding: 3px 6px; margin: 0 2px; text-align: right; }
.totals .grand { border-top: 2px solid var(--ink); margin-top: 4px; padding-top: 8px; font-size: 18px; font-weight: 800; }

/* Read-only quote view */
.readonly tfoot td { font-variant-numeric: tabular-nums; }
.grandrow td { font-weight: 800; border-top: 2px solid var(--ink); }
.prose p { margin: 8px 0; }
.prose ul { margin: 8px 0; padding-left: 18px; }

/* Side widgets */
.sharebox { margin-bottom: 8px; }
.shareurl { width: 100%; font-family: var(--font-mono); font-size: 11px; padding: 7px 9px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--tint); }
.closed-note { font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.assist { border-color: var(--crimson-line); }
.mini { list-style: none; margin: 0; padding: 0; }
.mini-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 12px; }
.mini-row:last-child { border-bottom: none; }
.fu-status { font-size: 10px; text-transform: uppercase; letter-spacing: 0.05em; padding: 2px 7px; border-radius: 999px; background: var(--tint-2); color: var(--muted); }
.fu-sent { background: rgba(26,161,33,0.14); color: var(--spec-green); }
.fu-ready { background: rgba(234,182,2,0.16); color: #8a6d00; }
.fu-pending { background: rgba(9,150,195,0.12); color: var(--spec-cyan); }
.fu-error { background: var(--crimson-tint); color: var(--crimson); }
.fu-body { flex-basis: 100%; color: var(--muted); margin-top: 2px; }
.card.danger { border-color: var(--crimson-line); }

/* Clickable table rows */
.table tr[onclick] { cursor: pointer; }
.table tr[onclick]:hover { background: var(--tint); }

@media (max-width: 900px) {
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .cols { grid-template-columns: 1fr; }
  .editor { grid-template-columns: 1fr; }
  .editor-side { position: static; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .funnel { flex-wrap: wrap; }
}

/* Price-book typeahead on the line-item description field */
table.items td { position: relative; }
.ac { position: absolute; left: 0; right: 0; top: 100%; z-index: 20; background: var(--cream);
      border: 1px solid var(--line-strong); border-radius: 8px; box-shadow: 0 8px 24px rgba(15,14,12,0.12);
      max-height: 240px; overflow-y: auto; margin-top: 2px; min-width: 240px; }
.ac-item { display: flex; justify-content: space-between; gap: 12px; padding: 7px 10px; cursor: pointer; font-size: 13px; }
.ac-item:hover { background: var(--tint-2); }
.ac-item .ac-price { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Price book add box */
.addbox summary { cursor: pointer; font-weight: 600; }
.addbox[open] summary { margin-bottom: 12px; }
.catitem .grid3 { gap: 0 12px; }
.rowedit summary { cursor: pointer; }
.rowedit[open] summary { font-weight: 600; margin-bottom: 8px; }

/* Import */
.filelabel { font-weight: 500; font-size: 13px; color: var(--muted); }
.filelabel input { display: inline-block; width: auto; margin-left: 6px; }

/* Invoice create row in the editor sidebar */
.invoice-create .row-inline { display: flex; gap: 8px; align-items: center; }
.invoice-create select { flex: 1; }
.invoice-create .pctwrap { white-space: nowrap; font-size: 13px; color: var(--muted); }
.invoice-create input { display: inline-block; }

/* ===================================================================== */
/* Mobile — contractors quote from the truck. Phone-first below 760px.   */
/* ===================================================================== */
.navtoggle { display: none; background: none; border: 1px solid var(--line-strong);
  border-radius: 8px; padding: 7px 14px; font: inherit; font-weight: 600; cursor: pointer; }

@media (max-width: 760px) {
  /* Nav: collapse to a tap-to-open panel */
  .topbar { position: relative; flex-wrap: wrap; }
  .navtoggle { display: inline-block; margin-left: auto; }
  .topbar nav { display: none; width: 100%; flex-direction: column; align-items: stretch; gap: 0; margin-top: 8px; }
  .topbar.nav-open nav { display: flex; }
  .topbar nav a, .topbar nav .who { padding: 13px 4px; border-top: 1px solid var(--line); }
  .topbar nav form.inline { padding: 13px 4px; border-top: 1px solid var(--line); }
  .topbar nav .spacer { display: none; }

  /* Touch targets */
  input, select, textarea, .btn, button { min-height: 44px; font-size: 16px; }
  .btn-sm, button.btn-sm { min-height: 36px; }
  .container { padding-left: 14px; padding-right: 14px; }
  .page-head { flex-direction: column; align-items: stretch; gap: 10px; }
  .head-actions { display: flex; gap: 8px; }
  .head-actions .btn { flex: 1; }

  /* Read-only data tables scroll sideways instead of crushing */
  .table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; white-space: nowrap; }

  /* The line-item editor: table -> stacked cards with labels */
  table.items thead { display: none; }
  table.items, table.items tbody, table.items tr.item-row, table.items td { display: block; width: 100%; }
  table.items tr.item-row { border: 1px solid var(--line-strong); border-radius: 10px;
    padding: 30px 12px 8px; margin-bottom: 12px; position: relative; }
  table.items td { border: none; padding: 5px 0; position: static; text-align: left; }
  table.items td::before { content: attr(data-label); display: block; font-size: 11px;
    text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin-bottom: 4px; }
  table.items td input, table.items td select { width: 100%; }
  table.items td.amount { font-weight: 700; font-size: 16px; }
  table.items .rowx-cell { position: absolute; top: 4px; right: 8px; padding: 0; width: auto; }
  table.items .rowx-cell::before { display: none; }
  table.items .rowx { min-height: 32px; }
  .totals { width: 100%; }

  /* The quote editor stacks (already), tighten the document preview iframe */
  .quote-head { flex-direction: column; align-items: stretch; }
  .quote-head .head-actions .btn { flex: 1; }
  .funnel { gap: 4px; }
  .funnel-arrow { display: none; }
}
