body.portal-centered {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--brand);
  padding: var(--space-8);
}

.card {
  background: var(--card-bone);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-3);
  padding: var(--space-16) var(--space-12);
  max-width: 420px;
  width: 100%;
}

.card h1 { text-align: center; font-size: 1.75rem; margin-bottom: var(--space-8); }
.card h1 em { color: var(--accent); font-style: italic; }

.stack { display: flex; flex-direction: column; gap: var(--space-4); }
.stack[hidden] { display: none; }
.stack label { display: flex; flex-direction: column; gap: var(--space-1); font-size: 0.9rem; color: var(--muted); }
.stack input {
  font: inherit;
  padding: var(--space-3);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--ink);
}
.stack input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.stack button {
  font: inherit;
  font-weight: 600;
  padding: var(--space-3) var(--space-4);
  border: none;
  border-radius: 999px;
  background: var(--accent);
  color: var(--brand-deep);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.stack button:hover { background: var(--accent-hover); }
.stack button:active { transform: scale(0.98); }

.error { color: #b3261e; font-size: 0.9rem; margin: 0; }
.hint { color: var(--muted); font-size: 0.9rem; margin: 0; text-align: center; }

.dashboard-status {
  display: inline-block;
  padding: var(--space-1) var(--space-3);
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
}
.dashboard-status.active { background: #dff0d8; color: #2f6b2f; }
.dashboard-status.past_due { background: #fbe8c8; color: #8a5a12; }
.dashboard-status.suspended { background: #f7d3d3; color: #a12727; }
.dashboard-status.pending_payment { background: #e4e0f5; color: #4b3d8f; }

/* App shell — dashboard, stats, roadmap, reports (wider than the auth pages' centered card) */
body.app-shell { background: var(--bg); min-height: 100vh; }

.app-header {
  background: var(--brand);
  padding: var(--space-4) var(--space-8);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: var(--space-4);
}
.app-header .brand-mark {
  font-family: 'Fraunces', serif;
  color: var(--on-brand);
  font-size: 1.1rem;
  white-space: nowrap;
}
.app-header .brand-mark em { color: var(--accent); font-style: italic; }

.header-actions { display: flex; align-items: center; justify-content: flex-end; gap: var(--space-4); flex-wrap: wrap; }


@media (max-width: 720px) {
  .app-header { grid-template-columns: 1fr; justify-items: center; text-align: center; }
  .header-actions { justify-content: center; }
}

#portal-nav { display: flex; gap: var(--space-2); flex-wrap: wrap; }
#portal-nav a {
  color: var(--on-brand);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 600;
  padding: var(--space-3);
  border-radius: 999px;
  transition: background var(--dur-fast) var(--ease);
  display: inline-flex;
  align-items: center;
}
#portal-nav a:hover { background: var(--highlight-ondark); }
#portal-nav a.active { background: var(--accent); color: var(--brand-deep); }

.app-header form { margin: 0; }
.app-header button {
  font: inherit;
  font-size: 0.85rem;
  padding: var(--space-3);
  border: 1px solid var(--border-ondark);
  border-radius: 999px;
  background: transparent;
  color: var(--on-brand);
  cursor: pointer;
}
.app-header button:hover { background: var(--highlight-ondark); }

.app-content {
  max-width: 960px;
  margin: 0 auto;
  padding: var(--space-8);
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
}
.app-content h1 { font-size: 1.5rem; }
.app-content h1 em { color: var(--accent); font-style: italic; }

.panel {
  background: var(--card-bone);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
  padding: var(--space-6);
}
.panel h2 { font-size: 1.1rem; margin: 0 0 var(--space-4); }

.stat-row { display: flex; gap: var(--space-6); flex-wrap: wrap; }
.stat-tile { min-width: 140px; }
.stat-tile .value { font-family: 'Fraunces', serif; font-size: 2rem; color: var(--ink); line-height: 1; }
.stat-tile .label { color: var(--muted); font-size: 0.85rem; margin-top: var(--space-1); }

.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.data-table th {
  text-align: left;
  color: var(--muted);
  font-weight: 600;
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--line);
}
.data-table td { padding: var(--space-2) var(--space-3); border-bottom: 1px solid var(--line); }
.data-table tr:last-child td { border-bottom: none; }

.status-pill {
  display: inline-block;
  padding: 2px var(--space-2);
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}
.status-pill.live { background: #dff0d8; color: #2f6b2f; }
.status-pill.planned { background: #ece9e0; color: var(--muted); }

.empty-state { color: var(--muted); font-size: 0.95rem; }
.error-state { color: #b3261e; font-size: 0.95rem; }

/* Admin page — tabs, badges, small buttons, inline edit rows */
.actions-cell {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-2);
  min-width: 90px;
}

.role-badge {
  display: inline-block;
  padding: 2px var(--space-2);
  border-radius: var(--radius-sm);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  background: var(--bg-alt);
  color: var(--muted);
}
.role-badge.admin { background: var(--accent); color: var(--brand-deep); }

.btn-sm {
  /* Under the 44px touch-target guideline even at this padding (deliberate
     exception: 3 stacked actions per admin table row — full 44px would
     roughly triple row height in a dense, desktop/mouse-driven internal
     view). Bumped from the original 4px for partial improvement. */
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}
.btn-sm:hover { background: var(--bg-alt); }
.btn-sm.danger { border-color: #e2b3b3; color: #a12727; }
.btn-sm.danger:hover { background: #fbe9e9; }
.btn-sm.primary { background: var(--accent); border-color: var(--accent); color: var(--brand-deep); }
.btn-sm.primary:hover { background: var(--accent-hover); }

.tabs { display: flex; gap: var(--space-2); border-bottom: 1px solid var(--line); margin-bottom: var(--space-4); }
.tabs[hidden] { display: none; }
.tabs button {
  font: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  padding: var(--space-2) var(--space-3);
  border: none;
  background: none;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tabs button.active { color: var(--ink); border-bottom-color: var(--accent); }

.field-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: var(--space-4); }
.field-grid label { display: flex; flex-direction: column; gap: var(--space-1); font-size: 0.85rem; color: var(--muted); }
.field-grid input, .field-grid select {
  font: inherit;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--ink);
}

.feature-toggles { display: flex; flex-wrap: wrap; gap: var(--space-3); }
.feature-toggles label { display: flex; align-items: center; gap: 4px; font-size: 0.85rem; color: var(--body); }

.edit-row { background: var(--bg-alt); }
.edit-row td { padding: var(--space-4) var(--space-3); }

/* Footer — legal links, present on every page */
.portal-footer {
  text-align: center;
  padding: var(--space-6) var(--space-4);
  font-size: 0.8rem;
  color: var(--muted);
}
.portal-footer a { color: var(--muted); text-decoration: underline; }
.portal-footer a:hover { color: var(--brand-soft); }
.portal-footer .sep { margin: 0 var(--space-2); opacity: 0.5; }

/* On the auth pages (login/setup), the card is centered in a flex row —
   pin the footer to the viewport bottom instead of disrupting that layout */
body.portal-centered .portal-footer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  color: var(--on-brand);
  opacity: 0.7;
}
body.portal-centered .portal-footer a { color: var(--on-brand); }

/* Legal pages — simple prose, reusing the .panel card look */
.legal-content { max-width: 720px; margin: 0 auto; }
.legal-content h2 { font-size: 1.15rem; margin-top: var(--space-8); }
.legal-content p, .legal-content li { color: var(--body); line-height: 1.65; }
.legal-content .effective-date { color: var(--muted); font-style: italic; margin-top: calc(-1 * var(--space-2)); }

/* ============================================================
   Quote portal — Present Mode, quote views, work orders
   ============================================================ */

/* Internal mode wears an unmistakable bar. An estimator must never have to
   squint to work out which mode the customer is looking at. */
.mode-bar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-4);
  padding: var(--space-2) var(--space-4);
  font-size: 0.8125rem; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase;
}
.mode-bar.internal { background: var(--brand); color: var(--on-brand); }
.mode-bar.present  { background: var(--leaf); color: #fff; }
.mode-bar button {
  background: rgba(255,255,255,0.14); color: inherit; border: 1px solid rgba(255,255,255,0.3);
  border-radius: var(--radius-sm); padding: var(--space-1) var(--space-3);
  font: inherit; cursor: pointer;
}
.mode-bar button:hover { background: rgba(255,255,255,0.24); }

/* Present mode hides every internal-only element outright. Belt and braces:
   the server has already stripped cost/margin for roles that may not see them,
   and quote rendering re-derives from a projection — this is the visual layer. */
body.present-mode .internal-only { display: none !important; }
body.present-mode .app-header .header-actions nav { display: none; }
body.present-mode .tabs { display: none; }

.cost-cell { background: var(--cost-tint); font-variant-numeric: tabular-nums; }
.data-table td.num, .data-table th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Margin health dot: meaningless to a customer, decisive for the estimator. */
.margin-dot {
  display: inline-block; width: 0.7rem; height: 0.7rem; border-radius: 50%;
  vertical-align: middle; margin-left: var(--space-2);
  border: 1px solid rgba(0,0,0,0.15);
}
.margin-dot.ok { background: var(--ok); }
.margin-dot.warn { background: var(--warn); }
.margin-dot.low { background: var(--danger); }
.margin-dot.unset { background: var(--line); }

.quote-total { font-family: 'Fraunces', Georgia, serif; font-size: 2.25rem; color: var(--ink); margin: 0; }
.quote-total small { display: block; font-family: inherit; font-size: 0.9rem; color: var(--muted); font-weight: 400; text-transform: none; letter-spacing: 0; }

.present-doc { max-width: 760px; margin: 0 auto; }
.present-doc h2 { font-size: 2rem; }
.present-doc .line-row { display: flex; justify-content: space-between; gap: var(--space-4); padding: var(--space-3) 0; border-bottom: 1px solid var(--line); }
.present-doc .line-row .qty { color: var(--muted); font-size: 0.9rem; }

/* Estimator chat */
.chat-log { display: flex; flex-direction: column; gap: var(--space-3); margin-bottom: var(--space-4); }
.chat-msg { padding: var(--space-3) var(--space-4); border-radius: var(--radius); max-width: 46rem; white-space: pre-wrap; }
.chat-msg.user { background: var(--brand); color: var(--on-brand); align-self: flex-end; }
.chat-msg.assistant { background: var(--card-bone); border: 1px solid var(--line); align-self: flex-start; }
.chat-msg.thinking { color: var(--muted); font-style: italic; }
.chat-form { display: flex; gap: var(--space-2); }
.chat-form textarea { flex: 1; min-height: 3.2rem; resize: vertical; }

.pin-backdrop {
  position: fixed; inset: 0; background: rgba(19,32,24,0.72); z-index: 60;
  display: flex; align-items: center; justify-content: center; padding: var(--space-4);
}
.pin-card { background: var(--card-bone); border-radius: var(--radius-lg); padding: var(--space-8); max-width: 22rem; width: 100%; text-align: center; }
.pin-card input { font-size: 2rem; text-align: center; letter-spacing: 0.5em; width: 100%; }

.gap-note { background: #fdf6e3; border-left: 3px solid var(--accent); padding: var(--space-3) var(--space-4); border-radius: var(--radius-sm); margin: var(--space-3) 0; }
[hidden] { display: none !important; }
