/* ═══════════════════════════════════════════════════════════════════
   WP Site Beam — App shell styles
   Topbar, sidebar, page layout, cards, buttons, forms, tables.
   Works across dark + light via tokens.
   ═══════════════════════════════════════════════════════════════════ */

/* ── A11Y PRIMITIVES ──────────────────────────────────────────── */
/* Skip-link: bypass nav for keyboard users (WCAG 2.4.1) */
.skip-link {
  position: fixed; top: -100px; left: 8px;
  z-index: 9999;
  padding: 10px 16px;
  background: var(--beam);
  color: #000;
  font-weight: 700;
  border-radius: 6px;
  text-decoration: none;
  box-shadow: 0 4px 18px rgba(0,0,0,.4);
  transition: top .15s ease;
}
.skip-link:focus { top: 8px; outline: 2px solid var(--text); outline-offset: 2px; }

/* Universal focus-visible ring — consistent 2px beam ring with offset */
button:focus-visible,
a:focus-visible,
[role="tab"]:focus-visible,
[role="button"]:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--beam);
  outline-offset: 2px;
  border-radius: 6px;
}
.card:focus-visible { outline: 2px solid var(--beam); outline-offset: 2px; }
main:focus-visible { outline: none; } /* programmatic-focus only */

/* Reduced motion (WCAG 2.3.3) */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Accessible progress bar */
.progress {
  flex: 1;
  height: 6px;
  background: var(--surface-3);
  border-radius: 3px;
  overflow: hidden;
}
.progress-fill { height: 100%; background: var(--green); transition: width .3s ease; }
.progress-fill[data-tone="warn"] { background: var(--warn); }
.progress-fill[data-tone="bad"]  { background: var(--red); }
.progress-fill[data-tone="beam"] { background: var(--beam); }

/* Field helper: error + hint + required marker */
.field-hint { font-size: .72rem; color: var(--muted); margin-top: 4px; }
.field-err  { font-size: .72rem; color: var(--red); margin-top: 4px; font-weight: 500; }
.field-req  { color: var(--red); margin-left: 4px; }
.field.has-error input,
.field.has-error select,
.field.has-error textarea { border-color: var(--red); }

/* Visually hidden — for SR-only content (captions, labels) */
.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0);
  white-space: nowrap; border: 0;
}

/* ── SHELL ────────────────────────────────────────────────────── */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w, 240px) 1fr;
  grid-template-rows: 72px 1fr;
  grid-template-areas:
    "topbar topbar"
    "sidebar main";
  height: 100vh;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}
.app[data-nav="topbar"] {
  grid-template-columns: 1fr;
  grid-template-areas:
    "topbar"
    "main";
}
.app[data-density="compact"] { --sidebar-w: 232px; --row-pad: 6px 9px; }
.app[data-density="cozy"]    { --sidebar-w: 248px; --row-pad: 9px 11px; }
.app[data-density="roomy"]   { --sidebar-w: 268px; --row-pad: 12px 14px; }

/* ── SA MODE BAR ──────────────────────────────────────────────── */
.sa-bar {
  position: fixed; top:0; left:0; right:0; height:3px; z-index: 300;
  background: linear-gradient(90deg, var(--rose), var(--purple), var(--beam));
  display: none;
}
body[data-sa="on"] .sa-bar { display: block; }

/* ── TOPBAR ───────────────────────────────────────────────────── */
.topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 0 var(--sp-5);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 20;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  font-family: var(--font-brand);
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: .2px;
  text-transform: none;
  white-space: nowrap;
  text-decoration: none;
  padding: 4px 6px 4px 2px;
  border-radius: 8px;
  transition: background .15s;
}
.brand:hover { background: var(--surface-2); }
.brand:focus-visible { outline: 2px solid var(--beam); outline-offset: 2px; }
.brand-mark {
  width: 46px; height: 46px;
  display: block;
  border-radius: 10px;
  border: 1px solid var(--beam);
  box-shadow: 0 0 0 1px rgba(0,207,239,.12);
  flex-shrink: 0;
  background: #000;
}
.brand-word { font-size: 1.15rem; }
.brand-word {
  display: inline-flex;
  align-items: baseline;
  line-height: 1;
}
.brand-word-wp   { color: var(--text); font-weight: 700; }
.brand-word-beam { color: var(--beam); font-weight: 700; }
/* light-mode: keep wordmark legible */
.app[data-theme="light"] .brand-word-wp { color: var(--text); }
/* compact on narrow viewports */
@media (max-width: 720px) {
  .brand-word { display: none; }
}
.topbar-nav {
  flex: 1;
  display: flex;
  gap: 2px;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 0 var(--sp-3);
}
.topbar-nav::-webkit-scrollbar { display: none; }
.app[data-nav="sidebar"] .topbar-nav { display: none; }

/* Spacer that replaces the old topbar-nav on sidebar layouts
   so topbar-right stays pushed to the right. */
.topbar-nav-spacer { flex: 1; }

/* Hamburger toggle — visible only below 980px */
.sidebar-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 8px;
  cursor: pointer;
  flex-shrink: 0;
  transition: background .15s, border-color .15s;
}
.sidebar-toggle:hover { background: var(--surface-3); border-color: var(--border-strong); }

/* Scrim that appears behind the sidebar drawer on tablet/mobile */
.sidebar-scrim {
  display: none;
  position: fixed;
  inset: 72px 0 0 0;
  background: rgba(0,0,0,.45);
  border: none;
  z-index: 38;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease;
}

/* Legacy topbar-nav blocks (no longer used — kept as no-op stubs so
   stale class names still parse; the old compact hamburger is replaced
   by .sidebar-toggle + the slide-in sidebar drawer). */
.topbar-nav-wrap { display: none; }
.topbar-nav-trigger { display: none; }
.topbar-nav-menu { display: none; }

.nav-btn {
  padding: 6px 12px;
  border: none;
  background: none;
  border-radius: 8px;
  font-size: .78rem;
  font-weight: 500;
  color: var(--muted);
  transition: background .15s, color .15s;
  white-space: nowrap;
}
.nav-btn:hover { background: var(--surface-2); color: var(--text); }
.nav-btn.active { background: var(--orange-dim); color: var(--orange); }
.nav-btn.sa-nav { color: var(--rose); }
.nav-btn.sa-nav.active { background: var(--rose-dim); color: var(--rose); }

.topbar-right {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-left: auto;
}

/* Role switcher */
.role-switch {
  display: flex;
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px;
  gap: 2px;
  position: relative;
}
.role-switch-tabs { display: flex; gap: 2px; align-items: center; }
/* Compact dropdown trigger — hidden on desktop, shown on tablet/mobile */
.role-switch-trigger {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: .78rem;
  border-radius: 6px;
  cursor: pointer;
}
.role-switch-trigger strong { font-weight: 700; font-size: .82rem; }
.role-switch-trigger:hover { background: var(--surface-3); }
.role-switch-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 180px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px;
  box-shadow: 0 12px 36px rgba(0,0,0,.28);
  z-index: 40;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.role-switch-menu-head {
  font-size: .58rem;
  letter-spacing: 1.2px;
  color: var(--dim);
  text-transform: uppercase;
  padding: 6px 10px 4px;
}
.role-switch-menu-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border: none;
  background: transparent;
  color: var(--text);
  text-align: left;
  border-radius: 6px;
  font-size: .82rem;
  cursor: pointer;
}
.role-switch-menu-item:hover { background: var(--surface-2); }
.role-switch-menu-item.active { background: var(--orange-dim); color: var(--orange); font-weight: 600; }
.role-switch-menu-item.role-sa { color: var(--green); }
.role-switch-menu-item.role-sa.active { background: color-mix(in oklab, var(--green) 18%, transparent); color: var(--green); }

@media (max-width: 980px) {
  /* Collapse inline tabs into a dropdown */
  .role-switch { padding: 0; background: transparent; border: none; }
  .role-switch-tabs { display: none; }
  .role-switch-trigger { display: inline-flex; }
  .role-switch-lbl { display: none; }
}
.role-btn {
  padding: 4px 10px;
  border: none;
  background: none;
  border-radius: 6px;
  font-family: var(--font-mono);
  font-weight: var(--fw-mono-small);
  font-size: .62rem;
  letter-spacing: .5px;
  text-transform: uppercase;
  color: var(--muted);
  transition: background .15s, color .15s;
}
.role-btn.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.role-btn.role-sa.active { background: var(--rose-dim); color: var(--rose); }

/* Theme + tweaks buttons */
.icon-btn {
  width: 32px; height: 32px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: none;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: border-color .15s, color .15s, background .15s;
}
.icon-btn:hover { border-color: var(--orange); color: var(--orange); }

/* User chip */
.user-chip {
  display: flex; align-items: center; gap: var(--sp-2);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3px 12px 3px 3px;
  font-size: .75rem;
  color: var(--text-2);
  position: relative;
  transition: background .15s, border-color .15s;
}
.user-chip:hover { background: var(--surface-3); border-color: var(--border-strong); }
.user-menu {
  position: absolute;
  top: 100%;
  right: 0;
  min-width: 240px;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,.35);
  padding: 6px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-4px);
  transition: opacity .14s, transform .14s;
  z-index: 50;
  /* Invisible padding-top extends hover zone to cover any visual gap */
  padding-top: 14px;
  margin-top: -6px;
}
.user-chip:hover .user-menu,
.user-chip:focus-within .user-menu { opacity: 1; pointer-events: auto; transform: translateY(0); }
.user-menu-head {
  display: flex; gap: 10px; align-items: center;
  padding: 10px;
  border-radius: 8px;
  background: var(--surface-3);
  margin-bottom: 6px;
}
.user-menu-sect {
  font-family: var(--font-mono);
  font-weight: var(--fw-mono-small);
  font-size: .6rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--dim);
  padding: 8px 10px 4px;
}
.user-menu-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: none;
  border-radius: 6px;
  background: none;
  color: var(--text);
  font-size: .82rem;
  text-align: left;
  cursor: pointer;
  transition: background .12s;
}
.user-menu-item:hover { background: var(--surface-3); }
.user-menu-divider {
  height: 1px;
  background: var(--border);
  margin: 6px 4px;
}
.user-avatar {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--orange), var(--beam));
  display: flex; align-items: center; justify-content: center;
  font-size: .7rem;
  font-weight: 700;
  color: #0d1623;
  flex-shrink: 0;
}
.user-avatar.sa { background: linear-gradient(135deg, var(--rose), var(--purple)); }

.plan-pill {
  font-family: var(--font-mono);
  font-weight: var(--fw-mono-small);
  font-size: .58rem;
  padding: 2px 7px;
  border-radius: 10px;
  letter-spacing: .5px;
  text-transform: uppercase;
  background: var(--orange-dim);
  border: 1px solid var(--orange-soft);
  color: var(--orange);
}
.plan-pill.sa { background: var(--rose-dim); border-color: rgba(255,107,157,.3); color: var(--rose); }
.plan-pill.partner { background: var(--beam-dim); border-color: rgba(0,207,239,.3); color: var(--beam); }
.plan-pill.marketing { background: rgba(196,160,255,.12); border-color: rgba(196,160,255,.3); color: var(--purple); }
.plan-pill.dev { background: rgba(34,197,94,.10); border-color: rgba(34,197,94,.3); color: var(--green); }
.plan-pill.admin { background: rgba(240,168,48,.12); border-color: rgba(240,168,48,.3); color: var(--orange); }
.plan-pill.support { background: rgba(99,179,237,.12); border-color: rgba(99,179,237,.3); color: #63b3ed; }

/* ── SIDEBAR ──────────────────────────────────────────────────── */
.sidebar {
  grid-area: sidebar;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: var(--sp-4) var(--sp-3);
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}
.app[data-nav="topbar"] .sidebar { display: none; }

.sb-sect {
  font-family: var(--font-mono);
  font-weight: var(--fw-mono-small);
  font-size: .58rem;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--dim);
  padding: 10px 10px 4px;
}
.sb-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: var(--row-pad, 9px 12px);
  border: none;
  border-radius: 8px;
  background: none;
  color: var(--muted);
  font-size: .82rem;
  font-weight: 500;
  width: 100%;
  text-align: left;
  transition: background .15s, color .15s;
  position: relative;
}
.sb-item:hover { background: var(--surface-2); color: var(--text); }
.sb-item.active {
  background: var(--orange-dim);
  color: var(--orange);
  box-shadow: inset 2px 0 0 var(--orange);
}
.sb-item.sa { color: var(--dim); }
.sb-item.sa:hover { background: var(--rose-dim); color: var(--rose); }
.sb-item.sa.active { background: var(--rose-dim); color: var(--rose); box-shadow: inset 2px 0 0 var(--rose); }

.sb-icon {
  width: 18px; height: 18px;
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  color: currentColor;
}
.sb-icon svg { width: 16px; height: 16px; }
.sb-label {
  flex: 1 1 auto;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sb-badge {
  margin-left: auto;
  font-family: var(--font-mono);
  font-weight: var(--fw-mono-small);
  font-size: .58rem;
  padding: 1px 6px;
  border-radius: 5px;
  background: var(--surface-3);
  color: var(--dim);
  letter-spacing: .5px;
}
.sb-badge.sa { background: var(--rose-dim); color: var(--rose); }
.sb-badge.count { background: var(--orange-dim); color: var(--orange); }
.sb-footer { margin-top: auto; padding-top: var(--sp-4); border-top: 1px solid var(--border); }

/* ── MAIN ─────────────────────────────────────────────────────── */
.main {
  grid-area: main;
  padding: var(--sp-6) var(--sp-6);
  overflow-y: auto;
  animation: fadeInUp .25s ease both;
}
@media (max-width: 900px) {
  .main { padding: var(--sp-5) var(--sp-4); }
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--sp-4);
  margin-bottom: var(--sp-5);
  flex-wrap: wrap;
}
.page-title {
  font-family: var(--font-brand);
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: 1.5px;
  color: var(--text);
  margin: 0 0 4px;
}
.page-sub {
  font-size: .85rem;
  color: var(--muted);
  margin: 0;
}
.page-actions { display: flex; gap: var(--sp-2); align-items: center; flex-wrap: wrap; }

.crumb {
  font-family: var(--font-mono);
  font-weight: var(--fw-mono-small);
  font-size: .64rem;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--dim);
  margin-bottom: 6px;
}
.crumb.sa { color: var(--rose); }

/* ── CARDS ────────────────────────────────────────────────────── */
.card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  border-radius: var(--r-lg);
  /* Was `overflow: hidden` — caused cards inside non-stretch grids to
     clip their internal content (labels cut off, inner boxes cropped).
     Use `clip` only on visual chrome via .card-head / .card-body if
     rounded-corner clipping is needed. */
  overflow: visible;
}
.card + .card { margin-top: var(--sp-4); }
/* But NOT inside a grid/flex parent — those handle spacing via `gap`.
   Covers: .grid / .kanban / .kpi-strip class parents plus inline
   display:grid|flex parents. Add class names here as new layouts emerge. */
.grid > .card + .card,
.kanban > .card + .card,
.kpi-strip > .card + .card,
[style*="display:grid"] > .card + .card,
[style*="display: grid"] > .card + .card,
[style*="display:flex"] > .card + .card,
[style*="display: flex"] > .card + .card { margin-top: 0; }
.card-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  flex-wrap: wrap;
  min-height: 52px;
  box-sizing: border-box;
}
.card-title { font-size: .85rem; font-weight: 700; color: var(--text); margin: 0; white-space: nowrap; }
.card-body { padding: 18px; }
.card-action {
  font-family: var(--font-mono);
  font-weight: var(--fw-mono-small);
  font-size: .65rem;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--orange);
  background: none;
  border: none;
}
.card-action:hover { text-decoration: underline; }

/* ── GRIDS ────────────────────────────────────────────────────── */
/* Grids default to top-aligned so each card sizes to its own content;
   row gap via gap: preserves consistent margins between items.
   If you need equal-height rows (e.g. dashboard KPI strips where every
   card must line up top AND bottom), add class .grid-stretch OR inline
   alignItems:'stretch' + gridAutoRows:'1fr'. */
.grid { display: grid; gap: var(--sp-3); align-items: start; }
.grid > * { min-width: 0; }
.card { display: flex; flex-direction: column; }
.card-body { flex: 1 1 auto; display: flex; flex-direction: column; }

/* OPT-IN — equal-height rows (previous default, kept for KPI strips
   and widget grids where the row should lock to the tallest cell). */
.grid.grid-stretch,
.grid[style*="alignItems: stretch"],
.grid[style*="alignItems:stretch"],
.grid[style*="align-items: stretch"],
.grid[style*="align-items:stretch"],
.grid[style*="gridAutoRows: 1fr"],
.grid[style*="gridAutoRows:1fr"],
.grid[style*="grid-auto-rows: 1fr"],
.grid[style*="grid-auto-rows:1fr"] {
  align-items: stretch;
  grid-auto-rows: 1fr;
}
.grid.grid-stretch > *,
.grid[style*="alignItems: stretch"] > *,
.grid[style*="alignItems:stretch"] > *,
.grid[style*="gridAutoRows: 1fr"] > *,
.grid[style*="gridAutoRows:1fr"] > * {
  display: flex; flex-direction: column; height: 100%;
}
.grid.grid-stretch > .card,
.grid.grid-stretch > .stat,
.grid[style*="alignItems: stretch"] > .card,
.grid[style*="alignItems:stretch"] > .card,
.grid[style*="gridAutoRows: 1fr"] > .card,
.grid[style*="gridAutoRows:1fr"] > .card { height: 100%; }
.card-body > .card-actions:last-child,
.card-body > .row-actions:last-child { margin-top: auto; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 1200px) { .grid-4 { grid-template-columns: repeat(3,1fr); } }
@media (max-width: 980px)  { .grid-4 { grid-template-columns: repeat(2,1fr); } .grid-3 { grid-template-columns: repeat(2,1fr); } }
@media (max-width: 720px)  { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }

/* Kanban / horizontal scroll columns — equal-height columns */
.kanban {
  display: grid; gap: var(--sp-3); align-items: stretch;
  grid-auto-rows: 1fr;
  overflow-x: auto;
}
.kanban > * { display: flex; flex-direction: column; min-width: 0; height: 100%; }

/* ── STAT ─────────────────────────────────────────────────────── */
.stat {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-4);
  display: flex; flex-direction: column; gap: 4px;
  transition: border-color .2s;
}
.stat:hover { border-color: var(--border-2); }
.stat-lbl {
  font-family: var(--font-mono);
  font-weight: var(--fw-mono-small);
  font-size: .62rem;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--muted);
}
.stat-val {
  font-family: var(--font-brand);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
  margin-top: 2px;
}
.stat-val.accent { color: var(--orange); }
.stat-val.beam { color: var(--beam); }
.stat-val.ok   { color: var(--green); }
.stat-val.warn { color: var(--warn); }
.stat-val.bad  { color: var(--red); }
.stat-sub { font-size: .72rem; color: var(--dim); }
.stat-trend {
  font-family: var(--font-mono);
  font-weight: var(--fw-mono-small);
  font-size: .6rem;
  padding: 2px 6px;
  border-radius: 5px;
  align-self: flex-start;
  margin-top: 4px;
}
.stat-trend.up   { background: var(--green-dim); color: var(--green); border:1px solid rgba(0,217,122,.3); }
.stat-trend.down { background: var(--red-dim);   color: var(--red);   border:1px solid rgba(255,112,112,.3); }
.stat-trend.flat { background: var(--surface-3); color: var(--muted); border:1px solid var(--border); }

/* ── BUTTONS ──────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 16px;
  border-radius: 8px;
  font-size: .82rem;
  font-weight: 600;
  border: 1px solid transparent;
  transition: transform .15s, box-shadow .15s, background .15s, border-color .15s, color .15s;
  white-space: nowrap;
}
.btn-primary {
  background: var(--orange);
  color: #0d1623;
  border-color: var(--orange);
  font-weight: 700;
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(240,168,48,.3); }
.btn-ghost {
  background: none;
  color: var(--text-2);
  border-color: var(--border-2);
}
.btn-ghost:hover { border-color: var(--orange); color: var(--orange); }
.btn-danger { background: var(--red); color: #fff; border-color: var(--red); }
.btn-sm { padding: 5px 12px; font-size: .74rem; }

/* ── FORMS ────────────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--sp-3); }
.field label {
  font-size: .78rem;
  font-weight: 600;
  color: var(--text-2);
}
.field input,
.field textarea,
.field select {
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: 10px;
  padding: 10px 14px;
  color: var(--text);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  width: 100%;
}
.field input::placeholder, .field textarea::placeholder { color: var(--dim); }
.field input:focus,
.field textarea:focus,
.field select:focus { border-color: var(--orange); box-shadow: 0 0 0 3px var(--orange-dim); }
.field-hint { font-size: .72rem; color: var(--dim); }

/* ── BOXES (inline notices) ───────────────────────────────────── */
.box {
  border-radius: 10px;
  padding: 12px 14px;
  font-size: .82rem;
  line-height: 1.5;
  border: 1px solid;
  display: flex; gap: 10px; align-items: flex-start;
}
.box svg { flex-shrink: 0; margin-top: 2px; }
.box.info  { background: var(--beam-dim);  border-color: rgba(0,207,239,.25); color: var(--text-2); }
.box.warn  { background: var(--warn-dim);  border-color: rgba(245,184,0,.3);  color: var(--text-2); }
.box.ok    { background: var(--green-dim); border-color: rgba(0,217,122,.3);  color: var(--text-2); }
.box.bad   { background: var(--red-dim);   border-color: rgba(255,112,112,.3);color: var(--text-2); }
.box.sa    { background: var(--rose-dim);  border-color: rgba(255,107,157,.3);color: var(--text-2); }
.box strong { color: var(--text); }
.box.info strong { color: var(--beam); }
.box.warn strong { color: var(--warn); }
.box.ok   strong { color: var(--green); }
.box.bad  strong { color: var(--red); }
.box.sa   strong { color: var(--rose); }

/* ── TAG / PILL ───────────────────────────────────────────────── */
.tag {
  display: inline-flex; align-items: center; gap: 4px;
  font-family: var(--font-mono);
  font-weight: var(--fw-mono-small);
  font-size: .62rem;
  letter-spacing: .5px;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  color: var(--muted);
}
.tag.ok   { background: var(--green-dim); border-color: rgba(0,217,122,.3); color: var(--green); }
.tag.warn { background: var(--warn-dim);  border-color: rgba(245,184,0,.3);  color: var(--warn); }
.tag.bad  { background: var(--red-dim);   border-color: rgba(255,112,112,.3);color: var(--red); }
.tag.beam { background: var(--beam-dim);  border-color: rgba(0,207,239,.3); color: var(--beam); }
.tag.sa   { background: var(--rose-dim);  border-color: rgba(255,107,157,.3);color: var(--rose); }

/* ── TABLE ────────────────────────────────────────────────────── */
.table-wrap { border: 1px solid var(--border); border-radius: var(--r-lg); overflow: hidden; background: var(--surface-2); }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 11px 14px; text-align: left; font-size: .82rem; }
.table th {
  font-family: var(--font-mono);
  font-weight: var(--fw-mono-small);
  font-size: .62rem;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--surface-3);
  border-bottom: 1px solid var(--border);
}
.table td { border-bottom: 1px solid var(--border); color: var(--text-2); }
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: var(--surface-3); }

/* ── TOGGLE ───────────────────────────────────────────────────── */
.switch {
  position: relative;
  width: 34px; height: 20px;
  background: var(--border-2);
  border-radius: 11px;
  transition: background .2s;
  display: inline-block;
  flex-shrink: 0;
}
.switch::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #fff;
  transition: left .2s;
}
.switch.on { background: var(--green); }
.switch.on::after { left: 16px; }
.switch.sa.on { background: var(--rose); }

/* ── TWEAKS PANEL ─────────────────────────────────────────────── */
.tweaks {
  position: fixed;
  bottom: 20px; right: 20px;
  width: 280px;
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--r-lg);
  box-shadow: 0 20px 48px rgba(0,0,0,.5), 0 0 0 1px rgba(255,255,255,.03);
  z-index: 400;
  animation: fadeInUp .2s ease both;
  overflow: hidden;
}
.tweaks-head {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  background: var(--surface-2);
}
.tweaks-title {
  font-family: var(--font-brand);
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--orange);
  text-transform: uppercase;
}
.tweaks-body { padding: 14px; display: flex; flex-direction: column; gap: 14px; max-height: 70vh; overflow-y: auto; }
.tw-label {
  font-family: var(--font-mono);
  font-weight: var(--fw-mono-small);
  font-size: .6rem;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 5px;
}
.tw-seg {
  display: flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px;
  gap: 2px;
}
.tw-seg button {
  flex: 1;
  padding: 5px 8px;
  border: none;
  background: none;
  border-radius: 6px;
  color: var(--muted);
  font-size: .72rem;
  transition: background .15s, color .15s;
}
.tw-seg button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.tw-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }

/* Swatch row for accent picker */
.tw-swatches { display: flex; gap: 6px; }
.tw-swatch {
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform .15s;
}
.tw-swatch:hover { transform: scale(1.08); }
.tw-swatch.active { border-color: var(--text); }

/* ── COMMAND PALETTE HINT ─────────────────────────────────────── */
.kbd {
  font-family: var(--font-mono);
  font-weight: var(--fw-mono-small);
  font-size: .62rem;
  padding: 1px 5px;
  border: 1px solid var(--border-2);
  border-radius: 4px;
  color: var(--muted);
  background: var(--surface-2);
}

/* ── RESPONSIVE ──────────────────────────────────────────────── */
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; grid-template-areas: "topbar" "main"; }
  /* Sidebar drawer (see § SIDEBAR DRAWER below) handles nav on mobile.
     Only hide the sidebar for legacy topbar-nav roles (none currently). */
  .app[data-nav="topbar"] .sidebar { display: none; }
  .tweaks { width: calc(100% - 32px); right: 16px; bottom: 16px; }
}


/* ── SUB-TABS (Scanner, Estimator) ───────────────────────────── */
.sub-tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: thin;
}
.sub-tab {
  padding: 10px 16px;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: .82rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: color .15s, border-color .15s;
}
.sub-tab:hover { color: var(--text-2); }
.sub-tab.active { color: var(--orange); border-bottom-color: var(--orange); }

/* ── CHECKBOX-STYLE OPTIONS ──────────────────────────────────── */
.opt-check {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: .78rem; color: var(--text-2);
  cursor: pointer;
}
.opt-check input {
  accent-color: var(--orange);
  width: 14px; height: 14px;
}

/* ── SPINNER ─────────────────────────────────────────────────── */
.spinner {
  width: 14px; height: 14px;
  border: 2px solid var(--orange-dim);
  border-top-color: var(--orange);
  border-radius: 50%;
  animation: wpsbdspin .7s linear infinite;
  flex-shrink: 0;
}
@keyframes wpsbdspin { to { transform: rotate(360deg); } }
@keyframes wpsbdpulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.4); opacity: .5; }
}

/* ── DOWNLOAD / STATUS BAR ───────────────────────────────────── */
.dl-bar {
  margin-top: 14px;
  background: var(--beam-dim);
  border: 1px solid rgba(6,182,212,.25);
  border-radius: 10px;
  padding: 14px 18px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  flex-wrap: wrap;
}
.dl-bar strong { color: var(--beam); font-size: .9rem; display: block; margin-bottom: 2px; }
.dl-bar span { color: var(--muted); font-size: .76rem; }

/* ── OPTION GRID (site type / tier selector) ─────────────────── */
.opt-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 8px;
}
.opt-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  text-align: left;
  cursor: pointer;
  color: var(--text-2);
  font-family: inherit;
  transition: border-color .15s, background .15s;
}
.opt-btn:hover { border-color: var(--border-2); }
.opt-btn.selected {
  background: var(--orange-dim);
  border-color: var(--orange);
  color: var(--text);
}
.opt-btn.tier.selected { background: var(--beam-dim); border-color: var(--beam); }

/* ── TOGGLE ROWS (add-ons) ───────────────────────────────────── */
.toggle-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  min-width: 0;
}
/* First column holds label + price — must be allowed to shrink so later columns
   (toggles, numeric inputs) don't get clipped off the edge. */
.toggle-row > div:first-child { min-width: 0; }
.toggle-row > div:first-child > div { min-width: 0; word-wrap: break-word; overflow-wrap: break-word; }

/* ── TOGGLE SWITCH ───────────────────────────────────────────── */
.tg {
  position: relative;
  width: 38px; height: 22px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  transition: background .15s, border-color .15s;
  flex-shrink: 0;
  padding: 0;
}
.tg .tg-dot {
  position: absolute;
  top: 2px; left: 2px;
  width: 16px; height: 16px;
  background: var(--text-2);
  border-radius: 50%;
  transition: transform .18s ease;
}
.tg.on { background: var(--orange); border-color: var(--orange); }
.tg.on .tg-dot { transform: translateX(16px); background: #fff; }

/* ── SUMMARY CARD (Estimator) ──────────────────────────────────
   The summary card sits inside a sticky wrapper (top:16) in a grid
   that forces equal-height rows. On short viewports or long content
   the wrapper was clipping the bottom CTAs. Let the sticky wrapper
   scroll internally so every row — including "Push to GHL / CRM" —
   stays reachable. */
.summary-card .card-body { padding: 18px; min-width: 0; overflow: visible; }
.summary-card,
.summary-card + .card { overflow: visible; }

/* Sticky side column in Estimator — stick to top on scroll but let
   content below the fold remain reachable via internal scroll.
   When content is tall, this creates a thin scrollbar on the column. */
.grid > div > div[style*="position:sticky"],
.grid > div > div[style*="position: sticky"] {
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border2) transparent;
  /* Pad bottom so last card's buttons aren't flush with the scrollbar end */
  padding-bottom: 4px;
}
.grid > div > div[style*="position:sticky"]::-webkit-scrollbar,
.grid > div > div[style*="position: sticky"]::-webkit-scrollbar { width: 6px; }
.grid > div > div[style*="position:sticky"]::-webkit-scrollbar-thumb,
.grid > div > div[style*="position: sticky"]::-webkit-scrollbar-thumb {
  background: var(--border2); border-radius: 3px;
}
/* Shorter viewports — drop sticky entirely and let the column flow
   with the page so every card is reachable by scrolling the page.
   Only tall desktop monitors (>= 1000px) keep sticky behavior. */
@media (max-height: 999px) {
  .grid > div > div[style*="position:sticky"],
  .grid > div > div[style*="position: sticky"] {
    position: static !important;
    max-height: none;
    overflow: visible;
  }
}
.summary-card .btn {
  /* Narrow sticky sidebar — allow button label to wrap instead of clipping */
  white-space: normal;
  text-align: center;
  line-height: 1.3;
  overflow-wrap: break-word;
  word-break: break-word;
  min-height: 34px;
  height: auto;
  padding: 8px 12px;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  display: inline-flex;
  justify-content: center;
}
.summary-card .btn > * { min-width: 0; }

/* ── COMPACT FIELD (Gallery layouts) ─────────────────────────── */
.compact-field-body input,
.compact-field-body select,
.compact-field-body textarea {
  padding: 6px 8px;
  font-size: .78rem;
  min-width: 0;
  width: 100%;
  box-sizing: border-box;
}

/* Brand gallery — stack on narrow widths */
@media (max-width: 900px) {
  .brand-gallery { grid-template-columns: 1fr !important; }
}

/* Multiplier pills — single-row compact variant for Project Multipliers */
.mult-pill {
  display: flex !important;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 8px 10px !important;
}

/* ── TOOLTIP ─────────────────────────────────────────────────── */
.wpsbd-tooltip {
  position: fixed;
  z-index: 10000;
  transform: translate(-50%, -100%);
  background: var(--surface-4, #1a2230);
  color: var(--text);
  border: 1px solid var(--border-2);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: .74rem;
  font-weight: 500;
  max-width: 240px;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
  pointer-events: none;
  animation: tt-in .14s ease-out;
  line-height: 1.35;
}
.wpsbd-tooltip-bottom { transform: translate(-50%, 0); }
.wpsbd-tooltip::after {
  content:'';
  position: absolute;
  left: 50%; transform: translateX(-50%);
  bottom: -5px;
  border: 5px solid transparent;
  border-top-color: var(--border-2);
  border-bottom: 0;
}
.wpsbd-tooltip-bottom::after {
  top: -5px; bottom: auto;
  border-top: 0;
  border-bottom: 5px solid var(--border-2);
}
@keyframes tt-in {
  from { opacity: 0; transform: translate(-50%, -90%); }
  to   { opacity: 1; transform: translate(-50%, -100%); }
}
.wpsbd-tooltip-bottom { animation: tt-in-b .14s ease-out; }
@keyframes tt-in-b {
  from { opacity: 0; transform: translate(-50%, 10%); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}
.sum-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px;
  padding: 5px 0;
  font-size: .86rem;
  color: var(--text-2);
  min-width: 0;
}
.sum-row > span:first-child { min-width: 0; flex: 1 1 auto; }
.sum-row > span:last-child  { flex: 0 0 auto; }
.sum-row.big {
  font-size: .95rem;
  font-weight: 700;
  color: var(--text);
  padding: 6px 0;
}
.sum-row .mono { font-family: var(--font-mono); font-weight: 600; }
font-weight: var(--fw-mono-small);

/* ── PROPOSAL PAPER ──────────────────────────────────────────── */
.proposal-paper {
  background: #fff;
  color: #0F172A;
  border-radius: 10px;
  padding: 48px 56px;
  max-width: 820px;
  margin: 0 auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
  font-size: .92rem;
  line-height: 1.65;
}
.proposal-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  padding-bottom: 20px;
  border-bottom: 2px solid var(--orange);
  margin-bottom: 24px;
}
.proposal-paper h2 {
  font-size: 1.05rem;
  font-weight: 800;
  color: #0F172A;
  margin: 28px 0 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid #E2E8F0;
}
.proposal-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .9rem;
}
.proposal-table td {
  padding: 10px 0;
  border-bottom: 1px solid #E2E8F0;
  color: #334155;
}
.proposal-table td:last-child { text-align: right; font-family: var(--font-mono); font-weight: 600; color: #0F172A; }
font-weight: var(--fw-mono-small);
.proposal-table tr.sub td { background: #F8FAFC; padding: 14px 12px; font-size: .98rem; }

/* Pages sitemap node */
.sm-line { color: var(--border-2); }

/* ── AUTO-SAVE INDICATOR ─────────────────────────────────────── */
.autosave-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  font-size: .72rem;
  font-weight: 600;
  color: var(--text-2);
  white-space: nowrap;
  cursor: default;
  transition: background .2s, border-color .2s, color .2s;
}
.autosave-chip .autosave-dot { display: inline-flex; align-items: center; justify-content: center; width: 14px; height: 14px; }
.autosave-chip .autosave-dot.spin svg { animation: as-spin 1s linear infinite; }
@keyframes as-spin { to { transform: rotate(360deg); } }
.autosave-chip .autosave-sub { color: var(--dim); font-weight: 500; font-family: var(--font-mono); font-size: .66rem; }
font-weight: var(--fw-mono-small);
.autosave-chip.autosave-ok    { background: rgba(34,197,94,.08); border-color: rgba(34,197,94,.3); color: var(--green); }
.autosave-chip.autosave-beam  { background: var(--beam-dim); border-color: rgba(6,182,212,.4); color: var(--beam); }
.autosave-chip.autosave-warn  { background: rgba(250,204,21,.08); border-color: rgba(250,204,21,.3); color: var(--warn); }
.autosave-chip.autosave-bad   { background: rgba(244,63,94,.08); border-color: rgba(244,63,94,.3); color: var(--rose); }

/* Hide the sub text on narrow topbars to keep chip compact */
@media (max-width: 1100px) {
  .autosave-chip .autosave-sub { display: none; }
}
@media (max-width: 780px) {
  .autosave-chip .autosave-label { display: none; }
}

/* ══════════════════════════════════════════════════════════════════
   RESPONSIVE POLISH — tables, cards, sticky sidebars, action rows
   ══════════════════════════════════════════════════════════════════
   Goals:
   - Tables never clip their rightmost columns; horizontal scroll kicks in
     with a subtle fade hint on the right edge when content overflows.
   - Cards below 900px don't trap wide content (overflow becomes visible
     only on axes that matter so sticky positioning still works).
   - Estimator / summary sticky sidebars drop their `position: sticky`
     and stack below the main column on tablet-and-down.
   - Row-actions, card-actions, and topbar clusters wrap gracefully
     instead of overflowing their container.
   ══════════════════════════════════════════════════════════════════ */

/* Any .card-body that holds a .table becomes a horizontal scroll area.
   Use the :has() selector where supported; fall back to explicit class. */
.card-body.table-scroll,
.card-body:has(> .table:only-child) {
  padding: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}
.card-body.table-scroll .table,
.card-body:has(> .table:only-child) .table {
  min-width: 640px;  /* keep columns readable; scroll kicks in below this */
}
/* When other content sits alongside a table inside card-body, keep the
   padding intact for the siblings and scroll just the table itself. */
.card-body:has(> .table):not(:has(> .table:only-child)) > .table {
  display: block;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Never let a .table row-actions cluster wrap to two lines — keep the
   icons on one row so the column width is predictable. */
.table td .row-actions,
.table td [style*="inline-flex"] {
  white-space: nowrap;
}

/* ── Row-actions / card-actions wrap gracefully ──────────────────── */
.row-actions, .card-actions {
  flex-wrap: wrap;
}

/* ── Tablet breakpoint (≤ 1024px) ────────────────────────────────── */
@media (max-width: 1024px) {
  /* Summary sticky column (Estimator) — unstick and stack */
  .summary-card ~ *,
  .card.summary-card { position: static !important; }
  [style*="position:sticky"][style*="top:16px"],
  [style*="position: sticky"][style*="top: 16px"] {
    position: static !important;
  }

  /* Two-column grids that live inside Estimator → one column */
  .main .grid[style*="grid-template-columns"]:not(.kanban) {
    grid-template-columns: 1fr !important;
  }

  /* Card heads that mix title + long action rows → wrap */
  .card-head {
    flex-wrap: wrap;
    gap: 8px;
    row-gap: 10px;
  }

  /* Table font tighter so more fits */
  .table th, .table td { padding: 10px 12px; font-size: .78rem; }
}

/* ── Small tablet / large phone (≤ 820px) ────────────────────────── */
@media (max-width: 820px) {
  .page-head, .page-header {
    flex-wrap: wrap;
    gap: 10px;
  }
  .page-head .page-actions,
  .page-header .page-actions { width: 100%; }

  /* Topbar clusters wrap */
  .topbar, .topbar-inner {
    flex-wrap: wrap;
    gap: 8px;
    row-gap: 6px;
  }

  /* Hide the decorative "plan pill" text when space is tight */
  .plan-pill, .topbar .plan-pill { font-size: .62rem; }

  /* Stat tiles stack into 2-up */
  .stat { min-width: 0; }

  /* Kanban becomes horizontal scroll with fixed column widths */
  .kanban { grid-auto-flow: column; grid-auto-columns: 78vw; overflow-x: auto; }
}

/* ── Phone (≤ 600px) ─────────────────────────────────────────────── */
@media (max-width: 600px) {
  .main { padding: 14px 12px; }
  .card-head { padding: 12px 14px; }
  .card-body { padding: 14px; }
  .summary-card .card-body { padding: 14px; }

  /* Buttons in row-actions take full width on phone */
  .row-actions .btn { flex: 1 1 auto; }

  /* Page titles compact */
  .page-title { font-size: 1.2rem; }
  .page-sub { font-size: .78rem; }

  /* Sub-tabs become scrollable so all tabs are reachable */
  .sub-tabs { overflow-x: auto; scrollbar-width: none; }
  .sub-tabs::-webkit-scrollbar { display: none; }
  .sub-tab { flex-shrink: 0; }
}


/* ── BUILD ESTIMATE summary (Estimator sidebar) ───────────────────── */
.be-amount {
  font-family: var(--font-mono);
  font-size: 1.9rem;
  font-weight: 700;
  color: var(--orange);
  letter-spacing: .5px;
  line-height: 1.1;
  margin-top: 2px;
}
.be-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  font-size: .78rem;
  color: var(--muted);
  margin-top: 6px;
}
.be-meta-dot { color: var(--dim); }

/* ── RECOMMENDED HOSTING / CARE cards ─────────────────────────────── */
.rec-sub {
  font-size: .62rem;
  letter-spacing: 1px;
  color: var(--dim);
  text-transform: uppercase;
  margin-bottom: 4px;
}
.rec-range {
  font-family: var(--font-mono);
  font-size: 1.1rem;
  color: var(--green);
  font-weight: 600;
  margin-bottom: 12px;
}
.rec-list { display: flex; flex-direction: column; gap: 8px; }
.rec-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.rec-row:first-child { border-color: color-mix(in oklab, var(--green) 45%, var(--border)); }
.rec-row-name { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: .88rem; }
.rec-row-inc { font-size: .72rem; color: var(--dim); margin-top: 2px; }
.rec-row-support { font-size: .66rem; color: var(--muted); font-family: var(--font-mono); }
.rec-badge {
  font-size: .56rem; font-weight: 700; letter-spacing: 1px;
  padding: 2px 6px; border-radius: 4px;
  background: color-mix(in oklab, var(--green) 22%, transparent);
  color: var(--green);
}
.rec-row-price { text-align: right; white-space: nowrap; }
.rec-price { color: var(--beam); font-weight: 700; font-size: .92rem; }
.rec-margin { font-size: .66rem; color: var(--green); font-family: var(--font-mono); margin-top: 2px; }
font-weight: var(--fw-mono-small);

/* ── PLAN COMPARISON table ────────────────────────────────────────── */
.plan-compare-scroll { overflow-x: auto; }
.plan-compare-tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: .82rem;
}
.plan-compare-tbl thead th {
  text-align: left;
  padding: 10px 14px;
  font-size: .68rem;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--dim);
  font-weight: 600;
  background: var(--surface-3);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.plan-compare-tbl th.num, .plan-compare-tbl td.num { text-align: right; }
.plan-compare-tbl tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.plan-compare-tbl tbody tr:hover { background: var(--surface-3); }
.plan-compare-tbl tbody tr.dim td { opacity: .55; }
.plan-compare-tbl tbody tr:last-child td { border-bottom: none; }


/* ══════════════════════════════════════════════════════════════════
   SIDEBAR DRAWER (tablet + mobile)
   ══════════════════════════════════════════════════════════════════
   Sidebar stays left-side on desktop. Below 980px, it collapses into
   a slide-in drawer (35% of viewport width, capped at 320px) triggered
   by the hamburger in the topbar. Main content keeps its full width.
   ══════════════════════════════════════════════════════════════════ */
@media (max-width: 980px) {
  /* Grid collapses so main is the only column. */
  .app[data-nav="sidebar"] {
    grid-template-columns: 1fr;
    grid-template-areas:
      "topbar"
      "main";
  }
  /* Hamburger becomes visible in the topbar. */
  .sidebar-toggle { display: inline-flex; }

  /* Sidebar leaves grid flow and becomes a fixed-position drawer. */
  .app[data-nav="sidebar"] .sidebar {
    position: fixed;
    top: 72px;
    bottom: 0;
    left: 0;
    width: 35vw;
    max-width: 320px;
    min-width: 220px;
    transform: translateX(-100%);
    transition: transform .22s ease;
    box-shadow: 6px 0 28px rgba(0,0,0,.35);
    z-index: 40;
  }

  /* When open, slide in. */
  .app.sb-open[data-nav="sidebar"] .sidebar {
    transform: translateX(0);
  }

  /* Scrim fades over the main content when drawer is open. */
  .app.sb-open .sidebar-scrim {
    display: block;
    opacity: 1;
    pointer-events: auto;
  }
}

/* Desktop: make absolutely sure the drawer state doesn't leak. */
@media (min-width: 981px) {
  .sidebar-scrim { display: none !important; }
}


/* ══════════════════════════════════════════════════════════════════
   SIDEBAR COLLAPSE (desktop ≥ 981px)
   ══════════════════════════════════════════════════════════════════
   Toggle button at the top of the sidebar reduces the column to an
   icon-only rail. State is persisted in localStorage. Active state
   bar, badges, and section headers are hidden; tooltips on hover
   surface the label.

   The mobile drawer (< 981px) ignores this modifier and always shows
   full-width labels — the hamburger toggles show/hide, not collapse.
   ══════════════════════════════════════════════════════════════════ */

/* Default collapsed width — narrow rail wide enough for icon + padding. */
.app.sb-collapsed { --sidebar-w: 64px; }

/* The collapse-toggle button styling (also works expanded: shows
   chevron + 'Collapse' label). */
.sb-collapse-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  margin: 0 0 4px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  border-radius: 8px;
  font-size: .7rem;
  font-family: var(--font-mono);
  font-weight: var(--fw-mono-small);
  letter-spacing: 1px;
  text-transform: uppercase;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
  justify-content: flex-start;
}
.sb-collapse-btn:hover {
  background: var(--surface-3);
  color: var(--text);
  border-color: var(--border-strong);
}
.sb-collapse-btn svg { flex-shrink: 0; }

/* Hide the toggle on tablet/mobile — the topbar hamburger owns
   show/hide there, not collapse. */
@media (max-width: 980px) {
  .sb-collapse-btn { display: none; }
}

/* ── Collapsed state (desktop only) ──────────────────────────── */
@media (min-width: 981px) {
  .app.sb-collapsed .sidebar {
    padding: var(--sp-4) 8px;
    align-items: stretch;
  }

  /* Icon-only rail: hide labels, section headers, badges. */
  .app.sb-collapsed .sb-label { display: none; }
  .app.sb-collapsed .sb-sect  { display: none; }
  .app.sb-collapsed .sb-badge { display: none; }

  /* Center icons in the narrowed item. */
  .app.sb-collapsed .sb-item {
    justify-content: center;
    padding: 10px 0;
    gap: 0;
  }

  /* Active indicator becomes a left bar still, but the background
     is square so it reads as a solid tile. */
  .app.sb-collapsed .sb-item.active {
    box-shadow: inset 2px 0 0 var(--orange);
  }

  /* Collapse-button: icon only, centered. */
  .app.sb-collapsed .sb-collapse-btn {
    padding: 10px 0;
    justify-content: center;
  }
  .app.sb-collapsed .sb-collapse-btn .sb-label { display: none; }

  /* Footer row also compacts. */
  .app.sb-collapsed .sb-footer .sb-item { justify-content: center; }
}


/* ── Light mode overrides — nav + badge contrast ─────────────────
   Use beam (--beam / #0079a3 = 4.93:1 on white, AA) instead of
   orange for all active/selected states. Orange stays in dark mode.
   ────────────────────────────────────────────────────────────── */

/* Active nav item */
html[data-theme="light"] .sb-item.active {
  background: var(--beam-dim);
  border: 1px solid rgba(0,121,163,.20);
  color: var(--beam);
  font-weight: 700;
  box-shadow: inset 3px 0 0 var(--beam);
}
html[data-theme="light"] .sb-item.active:hover {
  background: rgba(0,121,163,.14);
  color: var(--beam);
}

/* Count badges */
html[data-theme="light"] .sb-badge.count {
  background: var(--beam-dim);
  border: 1px solid rgba(0,121,163,.28);
  color: var(--beam);
  font-weight: 700;
}

/* SA-role items stay rose/pink but same boost in light */
html[data-theme="light"] .sb-item.sa.active {
  background: rgba(192,53,123,.10);
  border: 1px solid rgba(192,53,123,.22);
  color: #8b1a5a;
  font-weight: 700;
  box-shadow: inset 3px 0 0 var(--rose);
}
html[data-theme="light"] .sb-badge.sa {
  background: rgba(192,53,123,.10);
  border: 1px solid rgba(192,53,123,.25);
  color: #8b1a5a;
  font-weight: 700;
}

/* Top-bar nav-btn active */
html[data-theme="light"] .nav-btn.active {
  background: var(--beam-dim);
  border: 1px solid rgba(0,121,163,.22);
  color: var(--beam);
  font-weight: 700;
}

/* Sub-tabs (Scanner, Estimator tabs) — was missing, now added */
html[data-theme="light"] .sub-tab.active {
  color: var(--beam);
  border-bottom-color: var(--beam);
}

/* Role switch menu active item */
html[data-theme="light"] .role-switch-menu-item.active {
  background: var(--beam-dim);
  color: var(--beam);
}

/* Hover state */
html[data-theme="light"] .sb-item:hover {
  background: var(--surface-3);
  color: var(--text);
}

/* Section headers */
html[data-theme="light"] .sb-sect {
  color: var(--muted);
  font-weight: 600;
}
