/* ============================================================================
   PLUMB — design system (mobile-first)
   "Where the tape and the math agree."
   ============================================================================
   Default styles target mobile (320-768px). `@media (min-width: 769px)`
   enhances for tablet/desktop. Hand-rolled — no framework. Single CSS file,
   no build step.
   ============================================================================ */

@import url("https://rsms.me/inter/inter.css");

:root {
  /* ---- Palette ---------------------------------------------------------
     Warm-ink + cool-teal accent. Reads instrument-grade on warm neutrals. */
  --ink:        #1c1917;
  --ink-soft:   #292524;
  --slate:      #57534e;
  --slate-50:   #f5f5f4;
  --slate-200:  #e7e5e4;
  --border:     #e7e5e4;
  --surface:    #fafaf9;
  --card:       #ffffff;
  --card-alt:   #fafaf6;
  --brass:      #0d9488;
  --brass-soft: #ccfbf1;
  --verdant:    #15803d;
  --verdant-soft: #d1fae5;
  --garnet:     #be123c;
  --garnet-soft: #fee2e2;
  --indigo:     #1e3a8a;
  --indigo-soft: #dbeafe;

  --font-sans: "Inter", "Inter var", -apple-system, BlinkMacSystemFont,
               "Segoe UI", Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "JetBrains Mono", Menlo, monospace;

  --radius-sm: 4px;
  --radius:    8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px 0 rgba(15, 23, 42, 0.05);
  --shadow:    0 1px 3px 0 rgba(15, 23, 42, 0.08), 0 1px 2px -1px rgba(15, 23, 42, 0.04);

  /* Layout tokens for mobile chrome */
  --app-bar-h: 52px;
  --tab-bar-h: 56px;
}

/* ----------------------------------------------------------------------
   Resets / base
   ---------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html {
  font-family: var(--font-sans);
  font-size: 14px;
  font-feature-settings: "cv02", "cv03", "cv04", "cv11";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body.app {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  color: var(--ink);
  background: var(--surface);
  letter-spacing: -0.005em;
  /* Reserve space for the bottom tab bar + iPhone home-indicator safe area.
     The desktop media query below resets this to 0. */
  padding-bottom: calc(var(--tab-bar-h) + env(safe-area-inset-bottom, 0px));
}

a {
  color: var(--ink);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 120ms ease;
  -webkit-tap-highlight-color: transparent;
}
a:hover { border-bottom-color: var(--brass); }
a.plain { border-bottom: none; }

code, .num, .table .num {
  font-feature-settings: "tnum" on, "lnum" on;
}
code {
  font-family: var(--font-mono);
  font-size: 0.86em;
  background: var(--slate-50);
  padding: 1px 6px;
  border-radius: var(--radius-sm);
  color: var(--ink-soft);
  word-break: break-word;
}

h1, h2, h3, h4 {
  margin: 0;
  font-weight: 600;
  letter-spacing: -0.022em;
  color: var(--ink);
}
h1 { font-size: 1.35rem; line-height: 1.2; }
h2 { font-size: 0.98rem; }
h3 { font-size: 0.9rem; color: var(--ink-soft); }

/* ----------------------------------------------------------------------
   Top app bar (mobile + desktop both)
   ---------------------------------------------------------------------- */
.app-bar {
  background: rgba(255, 255, 255, 0.85);
  -webkit-backdrop-filter: blur(18px) saturate(150%);
  backdrop-filter: blur(18px) saturate(150%);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 30;
  padding-top: env(safe-area-inset-top, 0px);
}
.app-bar-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0.5rem 0.85rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-height: var(--app-bar-h);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink);
  border-bottom: none;
  flex-shrink: 0;
}
.brand:hover { border-bottom: none; }
.brand-mark {
  width: 22px;
  height: 22px;
  color: var(--ink);
  display: inline-block;
  flex-shrink: 0;
}
.brand-name { font-feature-settings: "ss01" on; }

/* Horizontal nav-links: hidden on mobile (the bottom tab bar takes its place),
   visible at >=769px. */
.nav-links {
  display: none;
}

.app-bar-user {
  margin-left: auto;
  display: flex;
  align-items: center;
}

/* User menu — pill that expands into a dropdown panel. <details>-based, so
   it works without JS and the click-outside behavior is JS-augmented. */
.user-menu { position: relative; }
.user-menu summary {
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  cursor: pointer;
  padding: 0.25rem 0.4rem 0.25rem 0.3rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--card);
  font-size: 0.82rem;
  color: var(--slate);
  min-height: 36px;
  -webkit-tap-highlight-color: transparent;
}
.user-menu summary::-webkit-details-marker { display: none; }
.user-menu summary::marker { content: ""; }
.user-menu[open] summary { background: var(--card-alt); }
.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--ink);
  color: var(--surface);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.78rem;
  flex-shrink: 0;
}
/* On mobile, hide the email text — the avatar pill is enough. Show email
   inline at >=769px. */
.user-email { display: none; }
.app-bar-user .badge { display: none; }

.user-menu-pane {
  position: absolute;
  top: calc(100% + 0.5rem);
  right: 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 12px 30px -12px rgba(15, 23, 42, 0.18);
  padding: 0.85rem;
  min-width: 240px;
  max-width: 90vw;
  z-index: 50;
}
.user-menu-email {
  font-size: 0.78rem;
  color: var(--slate);
  margin: 0;
  word-break: break-all;
}
.user-menu-role {
  margin: 0.5rem 0 0;
}
.user-menu-item {
  display: block;
  padding: 0.6rem 0;
  color: var(--ink);
  font-weight: 500;
  border-bottom: none;
  border-top: 1px solid var(--border);
  margin-top: 0.6rem;
  padding-top: 0.7rem;
  font-size: 0.9rem;
}

.signin {
  background: var(--ink);
  color: var(--surface);
  padding: 0.45rem 0.95rem;
  border-radius: var(--radius);
  font-weight: 500;
  border-bottom: none;
  font-size: 0.85rem;
  min-height: 36px;
  display: inline-flex;
  align-items: center;
}
.signin:hover { background: var(--ink-soft); border-bottom: none; }

/* ----------------------------------------------------------------------
   Bottom tab bar (mobile only — hidden at >=769px)
   ---------------------------------------------------------------------- */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: rgba(255, 255, 255, 0.92);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  backdrop-filter: blur(20px) saturate(180%);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  z-index: 40;
}
.tab-bar-item {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 0.45rem 0.25rem 0.4rem;
  color: var(--slate);
  font-size: 10.5px;
  font-weight: 500;
  text-decoration: none;
  border-bottom: none;
  min-height: var(--tab-bar-h);
  -webkit-tap-highlight-color: transparent;
  transition: color 120ms ease, transform 120ms ease;
}
.tab-bar-item:hover {
  border-bottom: none;
  color: var(--ink-soft);
}
.tab-bar-item.active {
  color: var(--brass);
}
.tab-bar-item:active {
  transform: scale(0.96);
}
.tab-bar-icon {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  stroke-width: 1.8;
}
.tab-bar-item.active .tab-bar-icon {
  stroke-width: 2.2;
}
.tab-bar-label {
  letter-spacing: 0.005em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

/* ----------------------------------------------------------------------
   Layout
   ---------------------------------------------------------------------- */
.main { flex: 1; }
.page {
  max-width: 1280px;
  margin: 0 auto;
  padding: 1rem 0.85rem 1.5rem;
}
.page-narrow { max-width: 640px; }

.page-header {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.65rem;
  margin-bottom: 1.25rem;
  padding-bottom: 0.95rem;
  border-bottom: 1px solid var(--border);
}
.page-header > div:first-child { min-width: 0; }
.page-header h1 { line-height: 1.15; }
.page-header p { margin: 0.3rem 0 0; word-wrap: break-word; }

.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: 1fr; }

/* ----------------------------------------------------------------------
   Cards
   ---------------------------------------------------------------------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow-sm);
}
.card h2 { margin-bottom: 0.85rem; }
.card h2 + p { margin-top: -0.3rem; }
.card-center { text-align: center; padding: 2.25rem 1rem; }
.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.85rem;
}

a.card-link {
  display: block;
  color: inherit;
  text-decoration: none;
  border: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  transition: border-color 120ms ease, box-shadow 120ms ease, transform 120ms ease;
}
a.card-link:hover {
  border-color: var(--ink);
  box-shadow: 0 4px 14px -4px rgba(15, 23, 42, 0.10);
  text-decoration: none;
  transform: translateY(-1px);
}
a.card-link:active { transform: translateY(0); }
.card-link-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.85rem;
  margin-bottom: 0.85rem;
}
.card-link-header .kicker { margin-bottom: 0.15rem; }
.card-link-arrow {
  font-size: 1.4rem;
  color: var(--brass);
  line-height: 1;
  flex-shrink: 0;
  transition: transform 120ms ease;
}
a.card-link:hover .card-link-arrow { transform: translateX(2px); }

/* ----------------------------------------------------------------------
   Buttons — 44px min-height on mobile (Apple HIG tap target)
   ---------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.7rem 1.1rem;
  background: var(--card);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: all 120ms ease;
  text-decoration: none;
  border-bottom: 1px solid var(--border);
  min-height: 44px;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover {
  background: var(--card-alt);
  border-color: var(--ink);
  color: var(--ink);
  border-bottom-color: var(--ink);
}
.btn:active { transform: scale(0.98); }
.btn-primary {
  background: var(--ink);
  color: var(--surface);
  border-color: var(--ink);
}
.btn-primary:hover {
  background: var(--ink-soft);
  border-color: var(--ink-soft);
  color: var(--surface);
  border-bottom-color: var(--ink-soft);
}
.btn-accent {
  background: var(--brass);
  color: #fff;
  border-color: var(--brass);
}
.btn-accent:hover { background: #0a7a70; border-color: #0a7a70; color: #fff; }
.btn-large { padding: 0.95rem 1.6rem; font-size: 1rem; min-height: 52px; }
.btn-xs    { padding: 0.45rem 0.75rem; font-size: 0.8rem; min-height: 36px; }

.row-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}
.row-toast {
  font-size: 0.78rem;
  margin-left: 0.4rem;
  color: var(--slate);
}
.row-toast .toast {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 500;
}
.row-toast .toast-good { background: var(--verdant-soft); color: var(--verdant); }
.row-toast .toast-bad  { background: var(--garnet-soft);  color: var(--garnet); }
.row-toast .toast-warn { background: var(--brass-soft);   color: var(--brass); }
button[hx-disabled-elt][disabled] { opacity: 0.6; cursor: wait; }
.actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.actions-inline { margin-top: 0.85rem; }
.actions-center { justify-content: center; margin-top: 1.5rem; }

/* ----------------------------------------------------------------------
   KPI block
   ---------------------------------------------------------------------- */
.kpi-row {
  display: flex;
  gap: 1.4rem;
  margin: 0.85rem 0 0.35rem;
  align-items: baseline;
  flex-wrap: wrap;
}
.kpi { display: flex; flex-direction: column; gap: 0.15rem; }
.kpi-num {
  font-size: 1.85rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--ink);
  line-height: 1;
  font-feature-settings: "tnum" on;
}
.kpi-label {
  font-size: 0.7rem;
  color: var(--slate);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}
.kicker {
  color: var(--slate);
  margin: 0 0 0.5rem;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
}

.funnel-line {
  margin-top: 0.5rem;
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  font-variant-numeric: tabular-nums;
}
.funnel-line strong { color: var(--ink-soft); font-weight: 600; }
.funnel-line .arrow {
  color: var(--brass);
  font-weight: 600;
  margin: 0 0.05rem;
}

/* ----------------------------------------------------------------------
   Tables — STACKED CARDS on mobile, traditional rows on desktop
   ---------------------------------------------------------------------- */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

/* Mobile defaults: hide thead, render each row as a card */
.table thead { display: none; }
.table tbody { display: block; }
.table tr {
  display: block;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.55rem;
  padding: 0.65rem 0.85rem;
  box-shadow: var(--shadow-sm);
}
.table tr:last-child { margin-bottom: 0; }
.table tr:hover { background: var(--card); }
.table tbody td {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.85rem;
  padding: 0.3rem 0;
  border-bottom: none;
  text-align: left;
  vertical-align: top;
  word-break: break-word;
}
.table tbody td::before {
  content: attr(data-label);
  flex-shrink: 0;
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--slate);
  font-weight: 600;
  min-width: 4.5rem;
}
.table tbody td:not([data-label])::before { content: none; }
/* The first cell in each row is the "title" of the card — full width, no
   left-side label, separator below. */
.table tbody td:first-child {
  display: block;
  padding: 0;
  margin-bottom: 0.5rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
  font-size: 1rem;
}
.table tbody td:first-child::before { content: none; }
/* Numeric cells right-align their value */
.table tbody td.num {
  font-variant-numeric: tabular-nums;
}

/* Empty-state row (single colspan="N") stays simple */
.table tbody tr.empty,
.table tbody tr:has(td[colspan]) {
  background: transparent;
  border: 1px dashed var(--border);
  box-shadow: none;
  text-align: center;
  padding: 1rem;
  color: var(--slate);
}
.table tbody tr:has(td[colspan]) td:first-child {
  border-bottom: none;
  padding: 0;
  margin: 0;
  font-size: 0.85rem;
}

/* ----------------------------------------------------------------------
   Ticker → Google Finance link
   ---------------------------------------------------------------------- */
.ticker-link {
  color: var(--ink);
  text-decoration: none;
  border-bottom: 1px dashed transparent;
  transition: color 120ms ease, border-color 120ms ease;
}
.ticker-link:hover {
  color: var(--brass);
  border-bottom-color: var(--brass);
}
.ticker-link-icon {
  font-size: 0.7em;
  margin-left: 0.15em;
  opacity: 0.45;
  vertical-align: super;
}
.ticker-link:hover .ticker-link-icon { opacity: 0.9; }
.table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ----------------------------------------------------------------------
   Badges
   ---------------------------------------------------------------------- */
.badge {
  display: inline-block;
  padding: 0.12rem 0.55rem;
  border-radius: 999px;
  font-size: 0.66rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border: 1px solid transparent;
}
.badge.admin           { background: var(--indigo-soft); color: var(--indigo); }
.badge.status-pending  { background: var(--brass-soft); color: var(--brass); }
.badge.status-running  { background: var(--indigo-soft); color: var(--indigo); }
.badge.status-done,
.badge.status-sent     { background: var(--verdant-soft); color: var(--verdant); }
.badge.status-failed   { background: var(--garnet-soft); color: var(--garnet); }
.badge.status-skipped  { background: var(--slate-50); color: var(--slate); }
.badge.sev-buy         { background: var(--verdant-soft); color: var(--verdant); }
.badge.sev-watch       { background: var(--brass-soft); color: var(--brass); }
.badge.sev-risk        { background: var(--garnet-soft); color: var(--garnet); }

/* ----------------------------------------------------------------------
   Misc utility
   ---------------------------------------------------------------------- */
.muted   { color: var(--slate); }
.small   { font-size: 0.85rem; }
.up      { color: var(--verdant); font-weight: 500; }
.down    { color: var(--garnet);  font-weight: 500; }
.tagline {
  color: var(--slate);
  font-style: italic;
  letter-spacing: -0.005em;
}

.logs {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  background: var(--ink);
  color: var(--slate-200);
  padding: 0.95rem;
  border-radius: var(--radius);
  max-height: 360px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.55;
  -webkit-overflow-scrolling: touch;
}

/* ----------------------------------------------------------------------
   PDF: hide iframe on mobile (iOS Safari renders it poorly), show CTA
   ---------------------------------------------------------------------- */
.pdf-frame { padding: 0.85rem; }
.pdf-iframe { display: none; }
.pdf-mobile-cta {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding: 0.4rem 0;
}
.pdf-mobile-cta .btn { width: 100%; }
.pdf-mobile-note {
  color: var(--slate);
  font-size: 0.82rem;
  margin: 0.3rem 0 0;
  line-height: 1.5;
}

/* ----------------------------------------------------------------------
   Research-template editor
   ---------------------------------------------------------------------- */
.kicker-inline {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  background: var(--slate-50);
  color: var(--slate);
  padding: 0.1rem 0.5rem;
  border-radius: var(--radius-sm);
  margin-left: 0.4rem;
  vertical-align: middle;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 500;
  word-break: break-all;
}
#prompt-body {
  font-family: var(--font-mono);
  /* 16px on mobile to prevent iOS Safari from auto-zooming on focus. */
  font-size: 16px;
  line-height: 1.55;
  min-height: 320px;
  white-space: pre;
  overflow-wrap: normal;
  overflow-x: auto;
  tab-size: 2;
}
.placeholder-checklist {
  list-style: none;
  padding: 0;
  margin: 0.5rem 0 0;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.placeholder-checklist li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.6rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
}
.placeholder-checklist li .check {
  display: inline-block;
  width: 1.1rem;
  text-align: center;
  font-weight: 700;
}
.placeholder-checklist li.present {
  background: var(--verdant-soft);
  color: var(--verdant);
}
.placeholder-checklist li.present .check { color: var(--verdant); }
.placeholder-checklist li.present code {
  background: rgba(255, 255, 255, 0.5);
  color: var(--verdant);
}
.placeholder-checklist li.missing { background: var(--garnet-soft); color: var(--garnet); }
.placeholder-checklist li.missing .check { color: var(--garnet); }
.placeholder-checklist li.missing code {
  background: rgba(255, 255, 255, 0.5);
  color: var(--garnet);
}
.validation-box {
  padding: 0.65rem 0.9rem;
  border-radius: var(--radius);
  font-size: 0.85rem;
  margin-top: 0.5rem;
}
.validation-ok  { background: var(--verdant-soft); color: var(--verdant); }
.validation-bad { background: var(--garnet-soft);  color: var(--garnet); }

/* Edit/Preview tab group */
.tab-group {
  display: flex;
  gap: 2px;
  align-items: flex-end;
  flex-wrap: wrap;
}
.tab-group .tab {
  background: transparent;
  border: 1px solid transparent;
  padding: 0.55rem 0.9rem;
  font-size: 0.85rem;
  font-family: inherit;
  cursor: pointer;
  border-radius: 6px 6px 0 0;
  color: var(--ink-soft);
  transition: background 120ms ease, color 120ms ease;
  min-height: 40px;
  -webkit-tap-highlight-color: transparent;
}
.tab-group .tab:hover {
  background: var(--slate-50);
  color: var(--ink);
}
.tab-group .tab-active {
  color: var(--ink);
  background: var(--card);
  border-color: var(--border);
  border-bottom-color: var(--card);
  font-weight: 500;
  position: relative;
  bottom: -1px;
}
.tab-pane { display: none; }
.tab-pane-active { display: block; }

/* Markdown preview */
.prompt-preview {
  font-size: 0.9rem;
  line-height: 1.55;
  color: var(--ink);
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-radius: 0 var(--radius) var(--radius) var(--radius);
  background: var(--card);
  min-height: 360px;
  max-height: 60vh;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
.prompt-preview > :first-child { margin-top: 0; }
.prompt-preview > :last-child  { margin-bottom: 0; }
.prompt-preview h1 {
  font-size: 1.25rem; margin: 0 0 .55rem; padding-bottom: .35rem;
  border-bottom: 1px solid var(--border);
}
.prompt-preview h2 {
  font-size: 1.05rem; margin: 1.4rem 0 .45rem; padding-bottom: .25rem;
  border-bottom: 1px solid var(--border);
}
.prompt-preview h3 { font-size: 0.95rem; margin: 1rem 0 .35rem; }
.prompt-preview p  { margin: 0.5rem 0; }
.prompt-preview ul, .prompt-preview ol { margin: .45rem 0; padding-left: 1.4rem; }
.prompt-preview li { margin: 0.18rem 0; }
.prompt-preview strong { color: var(--ink); }
.prompt-preview em { color: var(--ink-soft); }
.prompt-preview hr {
  border: 0; border-top: 1px solid var(--border); margin: 1rem 0;
}
.prompt-preview code {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  background: var(--slate-50);
  padding: 0.08rem 0.35rem;
  border-radius: 3px;
  color: var(--ink);
}
.prompt-preview pre {
  background: var(--slate-50);
  padding: 0.7rem 0.9rem;
  border-radius: var(--radius);
  overflow: auto;
  font-size: 0.78rem;
  -webkit-overflow-scrolling: touch;
}
.prompt-preview pre code { background: transparent; padding: 0; border-radius: 0; }
.prompt-preview code.placeholder-token {
  background: rgba(13, 148, 136, 0.10);
  color: var(--brass);
  border: 1px dashed rgba(13, 148, 136, 0.4);
  font-size: 0.78rem;
}

/* ----------------------------------------------------------------------
   Research-template version history
   ---------------------------------------------------------------------- */
.version-table { width: 100%; }
.version-table td, .version-table th { vertical-align: middle; }
.version-actions {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  flex-wrap: wrap;
}
.version-current { background: var(--verdant-soft) !important; }
.version-current td { font-weight: 500; }
.version-preview-body {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  white-space: pre-wrap;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  max-height: 60vh;
  background: var(--slate-50);
  border: 1px solid var(--border);
  border-radius: 0 var(--radius) var(--radius) var(--radius);
  padding: 0.75rem 0.9rem;
  margin: 0;
}
#version-preview .prompt-preview { margin: 0; }

/* ----------------------------------------------------------------------
   Forms — 16px font-size on mobile prevents iOS auto-zoom on focus
   ---------------------------------------------------------------------- */
form .field { margin-bottom: 1.1rem; }
form label {
  display: block;
  font-weight: 500;
  margin-bottom: 0.35rem;
  font-size: 0.9rem;
  color: var(--ink-soft);
}
form input[type=text], form input[type=email], form input[type=password],
form input[type=number], form select, form textarea {
  width: 100%;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 16px;
  font-family: inherit;
  background: var(--card);
  transition: border-color 120ms ease, box-shadow 120ms ease;
  min-height: 44px;
}
form input[type=checkbox] {
  width: 20px;
  height: 20px;
  vertical-align: middle;
  margin-right: 0.5rem;
}
form input:focus, form select:focus, form textarea:focus {
  outline: none;
  border-color: var(--ink);
  box-shadow: 0 0 0 3px rgba(15, 23, 42, 0.08);
}
form textarea {
  min-height: 110px;
  resize: vertical;
  font-family: var(--font-mono);
  font-size: 16px;
}
form .help {
  color: var(--slate);
  font-size: 0.8rem;
  margin-top: 0.35rem;
  line-height: 1.5;
}

/* ----------------------------------------------------------------------
   Sign-in landing
   ---------------------------------------------------------------------- */
.hero {
  text-align: center;
  padding: 2.5rem 1.25rem 3rem;
}
.hero-mark {
  width: 56px;
  height: 56px;
  margin: 0 auto 1.25rem;
  color: var(--ink);
}
.hero h1 {
  font-size: 1.6rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 0.45rem;
}
.hero .tagline {
  font-size: 1rem;
  margin-bottom: 1.5rem;
}
.hero-sub {
  max-width: 480px;
  margin: 0 auto 2rem;
  color: var(--slate);
  line-height: 1.6;
}
.hero-divider {
  width: 60px;
  height: 1px;
  background: var(--border);
  margin: 1.5rem auto;
}

/* ----------------------------------------------------------------------
   Worker-status block (pulse dot)
   ---------------------------------------------------------------------- */
.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 999px;
  margin-right: 0.5rem;
  vertical-align: middle;
}
.dot.online  { background: var(--verdant); box-shadow: 0 0 0 3px var(--verdant-soft); }
.dot.offline { background: var(--garnet);  box-shadow: 0 0 0 3px var(--garnet-soft); }

.runner-status { margin: 0.25rem 0 0.85rem; }
.runner-headline {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.95rem;
  margin-bottom: 0.6rem;
}
.runner-headline strong { font-weight: 600; }
.runner-status .runner-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.runner-status .runner-list li {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.55rem 0.75rem;
  background: var(--card-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.85rem;
  flex-wrap: wrap;
}
.runner-status .runner-id {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--ink);
  font-weight: 500;
}
.runner-status.runner-empty { padding: 0.85rem 0; }
.runner-status.runner-empty p { margin: 0.4rem 0 0; line-height: 1.5; }

/* ============================================================================
   DESKTOP — apply at >=769px
   ============================================================================ */
@media (min-width: 769px) {
  html { font-size: 14px; }

  body.app {
    padding-bottom: 0;  /* no bottom tab bar on desktop */
  }

  /* App bar fills the page width with more breathing room */
  .app-bar-inner {
    padding: 0.85rem 1.5rem;
    gap: 2.5rem;
    min-height: 64px;
  }
  .brand { font-size: 1.05rem; gap: 0.55rem; }
  .nav-links {
    display: flex;
    gap: 1.25rem;
    font-size: 0.875rem;
  }
  .nav-links a {
    color: var(--slate);
    font-weight: 500;
    border-bottom: 1px solid transparent;
    padding-bottom: 2px;
  }
  .nav-links a:hover { color: var(--ink); border-bottom-color: var(--brass); }
  .nav-links a.active { color: var(--ink); border-bottom-color: var(--ink); }

  .user-email { display: inline; }
  .app-bar-user .badge { display: inline-block; }

  .tab-bar { display: none; }

  /* Layout */
  .page { padding: 2rem 1.5rem 4rem; }
  .page-header {
    flex-direction: row;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1.5rem;
    margin-bottom: 2rem;
    padding-bottom: 1.25rem;
  }

  .grid-2 { grid-template-columns: 1fr 1fr; gap: 1.5rem; }
  .grid { gap: 1.5rem; }

  /* Cards */
  .card { padding: 1.5rem; margin-bottom: 1.5rem; }
  .card-center { padding: 3rem 1.5rem; }
  .card-header { flex-wrap: nowrap; }

  /* Buttons — desktop is finer-grained, less tap-heavy */
  .btn {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    min-height: 36px;
  }
  .btn-large { padding: 0.65rem 1.5rem; font-size: 0.95rem; min-height: 44px; }
  .btn-xs    { padding: 0.3rem 0.65rem; font-size: 0.78rem; min-height: 28px; }

  /* KPI scale up */
  .kpi-row { gap: 2rem; margin: 1rem 0 0.5rem; }
  .kpi-num { font-size: 2rem; }
  .kpi-label { font-size: 0.72rem; }

  h1 { font-size: 1.5rem; }
  h2 { font-size: 1rem; }
  h3 { font-size: 0.9rem; }

  /* Tables flip back to traditional rows */
  .table thead { display: table-header-group; }
  .table tbody { display: table-row-group; }
  .table tr {
    display: table-row;
    background: transparent;
    border: none;
    border-radius: 0;
    margin: 0;
    padding: 0;
    box-shadow: none;
  }
  .table tbody tr { border-bottom: 1px solid var(--border); }
  .table tbody tr:last-child { border-bottom: none; }
  .table tbody tr:hover { background: var(--card-alt); }
  .table thead th {
    text-align: left;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border);
    color: var(--slate);
    font-weight: 600;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    display: table-cell;
  }
  .table tbody td {
    display: table-cell;
    padding: 0.7rem 0.75rem;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: top;
    word-break: normal;
    gap: 0;
    align-items: initial;
  }
  .table tbody td::before { content: none; }
  .table tbody td:first-child {
    display: table-cell;
    padding: 0.7rem 0.75rem;
    border-bottom: 1px solid var(--border);
    margin: 0;
    font-size: 0.875rem;
  }
  .table-compact tbody td { padding: 0.45rem 0.55rem; }
  .table .num { text-align: right; font-variant-numeric: tabular-nums; }

  /* Empty-state row */
  .table tbody tr:has(td[colspan]) {
    border: none;
    background: transparent;
    box-shadow: none;
    padding: 0;
  }
  .table tbody tr:has(td[colspan]) td:first-child {
    border-bottom: 1px solid var(--border);
    padding: 0.7rem 0.75rem;
    text-align: left;
    font-size: 0.875rem;
  }

  /* PDF iframe shows inline */
  .pdf-iframe {
    display: block;
    width: 100%;
    height: 760px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--card-alt);
  }
  .pdf-mobile-cta { display: none; }

  /* Research editor — bigger textarea */
  #prompt-body {
    font-size: 0.78rem;
    min-height: 520px;
  }
  .prompt-preview {
    font-size: 0.9rem;
    min-height: 520px;
    max-height: 720px;
  }

  /* Forms back to compact desktop sizing */
  form input[type=text], form input[type=email], form input[type=password],
  form input[type=number], form select {
    padding: 0.55rem 0.8rem;
    font-size: 0.875rem;
    min-height: 36px;
  }
  form textarea {
    font-size: 0.82rem;
    min-height: 100px;
  }

  /* Hero */
  .hero h1 { font-size: 2rem; }
  .hero { padding: 3rem 1.5rem 4rem; }

  /* User menu */
  .user-menu summary {
    padding: 0.3rem 0.7rem 0.3rem 0.35rem;
    font-size: 0.85rem;
  }
  .user-menu-pane { min-width: 260px; }
}

/* ============================================================================
   PRINT
   ============================================================================ */
@media print {
  .app-bar, .tab-bar, .actions, .row-actions, button { display: none; }
  body.app { padding: 0; }
  .card { box-shadow: none; border: 1px solid var(--border); break-inside: avoid; }
}
