/* Default token values — overridden at runtime from GET /api/brand
   (brand/brand-config.json) by app.js, so brand/brand-config.json stays the
   single source of truth even for the portal's own styling. These defaults
   only matter for the instant before that fetch resolves. */
:root {
  --color-primary: #32E7C5;
  --color-ink: #0E0E10;
  --color-surface: #1A1F23;
  --color-surface-elevated: #20262B;
  --color-bg: #14171A;
  --color-text: #F2F4F6;
  --color-muted: #B5BBC6;
  --color-meta: #8B93A1;
  --color-border: #2B3137;
  --font-heading: "Space Grotesk", system-ui, sans-serif;
  --font-body: "Space Grotesk", system-ui, sans-serif;
  --radius: 12px;

  /* Semantic status tokens — every badge/box/border colour in the portal
     traces back to exactly one of these five, so a status never gets a
     one-off shade invented at the point of use. */
  --color-success: #22C55E;
  --color-success-text: #86EFAC;
  --color-warning: #F59E0B;
  --color-warning-text: #FBBF67;
  --color-danger: #EF4444;
  --color-danger-text: #FCA5A5;
  --color-neutral: var(--color-muted);

  /* Type scale — page title / section title / subsection / body / meta /
     label / helper. Body stays the html/body 14px default; everything
     else is named here so a page reaches for a role, not a number. */
  --text-section: 15px;
  --text-subsection: 13px;
  --text-meta: 12px;
  --text-label: 12px;
  --text-helper: 12px;

  /* Spacing scale — new/refined rules reach for these; this pass does not
     rewrite every existing hand-placed value (real drift only, per the
     Phase 16 brief), but it gives every future change one shared ruler. */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--color-bg);
  color: #F2F4F6;
  font-family: var(--font-body);
  font-size: 14px;
}

#app {
  display: flex;
  min-height: 100vh;
}

#sidebar {
  width: 220px;
  flex: 0 0 220px;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  padding: 20px 0;
}

.brand-mark {
  font-family: var(--font-heading);
  font-weight: 600;
  padding: 0 20px 20px;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: 12px;
}
.brand-mark span {
  display: block;
  font-size: 11px;
  font-weight: 400;
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* --- Global search (Phase 12) ----------------------------------------------- */
.global-search { position: relative; padding: 0 20px 14px; }
.global-search input[type="search"] {
  width: 100%;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  color: #F2F4F6;
  padding: 7px 10px;
  font-size: 13px;
  font-family: var(--font-body);
}
.global-search input[type="search"]::-webkit-search-cancel-button { filter: invert(1); opacity: 0.6; }
#global-search-results {
  position: absolute;
  left: 20px;
  right: 20px;
  top: calc(100% - 8px);
  z-index: 50;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 8px 0;
  max-height: 60vh;
  overflow-y: auto;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
}
.search-group-heading { padding: 6px 14px 4px; font-size: 10px; letter-spacing: 0.06em; color: var(--color-muted); font-weight: 600; }
.search-group-list { list-style: none; margin: 0 0 6px; padding: 0; }
.search-group-list a {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 14px;
  color: #F2F4F6;
  text-decoration: none;
  font-size: 13px;
}
.search-group-list a:hover, .search-group-list a:focus-visible { background: rgba(255,255,255,0.06); }
.search-result-status { color: var(--color-muted); font-size: 11px; white-space: nowrap; }
.search-empty { padding: 10px 14px; color: var(--color-muted); font-size: 13px; }

/* Group label — "PRIMARY"/"SYSTEM" style small-caps heading above each nav
   cluster, so Dashboard/Clients/... reads as one deliberate group and
   Settings/System Health reads as a distinct, secondary one, without
   needing a heavier divider than the border-top already provides. */
.nav-section-label {
  padding: 10px 20px 4px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-meta);
}

#nav-list { list-style: none; margin: 0; padding: 0; flex: 1; }
#nav-list li a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 20px;
  color: #D5D9DD;
  text-decoration: none;
  font-size: 13px;
  border-left: 3px solid transparent;
}
#nav-list li a:hover { background: rgba(255,255,255,0.04); }
#nav-list li a.active {
  border-left-color: var(--color-primary);
  color: #fff;
  background: rgba(50,231,197,0.08);
}

/* Secondary nav (Settings / System Health) — deliberately not flex:1 like
   #nav-list, so it sits compactly just above the footer rather than
   spreading through the sidebar's free space. */
#nav-list-secondary {
  list-style: none;
  margin: 0;
  padding: 4px 0 8px;
  border-top: 1px solid var(--color-border);
}
#nav-list-secondary li a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 20px;
  color: var(--color-muted);
  text-decoration: none;
  font-size: 12px;
  border-left: 3px solid transparent;
}
#nav-list-secondary li a:hover { background: rgba(255,255,255,0.04); color: #D5D9DD; }
#nav-list-secondary li a.active {
  border-left-color: var(--color-primary);
  color: #fff;
  background: rgba(50,231,197,0.08);
}

.sidebar-footer {
  padding: 12px 20px 0;
  font-size: 11px;
  color: var(--color-muted);
  border-top: 1px solid var(--color-border);
}
.sidebar-operator-name {
  display: block;
  color: #D5D9DD;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 2px;
}
.logout-btn {
  display: block;
  width: 100%;
  margin-top: 10px;
  padding: 6px 10px;
  font-size: 12px;
}

#content {
  flex: 1;
  padding: 28px 32px;
  overflow-x: auto;
  min-width: 0;
}

h1, h2, h3 { font-family: var(--font-heading); font-weight: 600; margin: 0 0 4px; }
h1 { font-size: 20px; }
h2 { font-size: 15px; margin-top: 28px; }
p { color: var(--color-muted); margin: 0 0 16px; }
.loading-state { color: var(--color-muted); font-size: 13px; }

a { color: var(--color-primary); }

/* Branded focus ring, applied consistently to every interactive element —
   :focus-visible (not plain :focus) so it only shows for keyboard
   navigation, not every mouse click, matching how browsers already treat
   native controls. outline (not box-shadow) so it never gets clipped by a
   parent's overflow:hidden. */
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible,
textarea:focus-visible, summary:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
  border-radius: 4px;
}

.table-scroll {
  overflow-x: auto;
  border-radius: var(--radius);
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}
th, td {
  text-align: left;
  padding: 8px 12px;
  border-bottom: 1px solid var(--color-border);
}
th {
  color: var(--color-muted);
  font-weight: 500;
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.04em;
}
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: rgba(255,255,255,0.02); }
tr.is-linked-row { cursor: pointer; }
/* The first cell's <a> is the real, keyboard-operable link a linked row
   needs — but it should read as an ordinary (if slightly emphasized) table
   cell, not a typical underlined blue hyperlink; the row hover state and
   pointer cursor already communicate that it's clickable. */
tr.is-linked-row td:first-child a { color: inherit; text-decoration: none; font-weight: 600; display: block; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  background: transparent;
  color: #F2F4F6;
  font-size: 13px;
  cursor: pointer;
  font-family: var(--font-body);
}
.btn:hover { border-color: var(--color-primary); }
.btn-primary {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: var(--color-ink);
  font-weight: 600;
}
.btn-primary:hover { filter: brightness(1.05); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
/* Reserved for the two genuinely destructive-ish actions in the whole
   system: Move to Trash and Permanently Purge. Every other lifecycle
   action (Archive, Restore, Restore from Trash) is fully reversible and
   uses the plain .btn style — red is never used for anything else. */
.btn-danger { border-color: var(--color-danger); color: var(--color-danger-text); }
.btn-danger:hover { background: rgba(239, 68, 68, 0.1); border-color: var(--color-danger); }
/* Quiet — a tertiary action that shouldn't compete visually with .btn at
   all (e.g. a secondary link-like action sitting next to a real button
   row). No border, no background, ever. */
.btn-quiet { border-color: transparent; background: transparent; color: var(--color-muted); }
.btn-quiet:hover { border-color: transparent; color: #fff; background: rgba(255,255,255,0.04); }

/* A row of actions that isn't all one undifferentiated cluster — the
   preview/utility controls on the left read as a group, the one real
   workflow action (Send/Resend, Record Payment, etc.) is pushed to the
   right and given room to stand alone, so it's never just "button #5 of
   5" in a flat row. Falls back to a plain wrapping row with normal gap on
   narrow screens (see the max-width:800px block below). */
.action-group { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.action-group-cluster { display: flex; gap: 8px; flex-wrap: wrap; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  border: 1px solid var(--color-border);
  color: var(--color-muted);
}
.badge-attention { border-color: var(--color-warning); color: var(--color-warning-text); }
.badge-ok { border-color: var(--color-success); color: var(--color-success-text); }
.badge-draft { border-color: var(--color-muted); }
.badge-sent { border-color: var(--color-primary); color: var(--color-primary); }
/* Invoice-only tone: a Cancelled Invoice is a dead end, not a draft state —
   distinct from .badge-draft's neutral "not sent yet" meaning. */
.badge-negative { border-color: var(--color-danger); color: var(--color-danger-text); }
/* Archived/superseded records — visually subdued rather than any status
   colour, so "no longer current" never competes for attention with a real
   status. Used for archived clients/workspaces and superseded document
   versions. */
.badge-archived { border-color: var(--color-border); color: var(--color-meta); font-style: italic; }

.attention-panel { margin-bottom: 28px; }
.attention-empty { color: var(--color-muted); }
.attention-list { list-style: none; margin: 0; padding: 0; }
.attention-list li {
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-left: 3px solid #F59E0B;
  border-radius: var(--radius);
  margin-bottom: 6px;
  background: var(--color-surface);
  font-size: 13px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
/* Severity is shown by border colour AND an explicit text label rendered
   next to the record-type pill (see dashboard.js#attentionListItem) —
   never colour alone. Upcoming uses the brand teal (a calm, forward-looking
   tone distinct from the warning/danger vocabulary used for Today's items);
   Informational keeps the original neutral border. */
.attention-list li.severity-critical { border-left-color: var(--color-danger); }
.attention-list li.severity-action-required { border-left-color: var(--color-warning); }
.attention-list li.severity-upcoming { border-left-color: var(--color-primary); }
.attention-list li.severity-informational { border-left-color: var(--color-border); }
.attention-severity-label { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; margin-right: 4px; }
.attention-severity-label.severity-critical { color: var(--color-danger-text); }
.attention-severity-label.severity-action-required { color: var(--color-warning-text); }
.attention-severity-label.severity-upcoming { color: var(--color-primary); }
.attention-severity-label.severity-informational { color: var(--color-muted); }
.attention-filter-row { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.attention-filter-chip {
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 12px;
  cursor: pointer;
}
.attention-filter-chip[aria-pressed="true"] { background: var(--color-primary); color: var(--color-ink); border-color: var(--color-primary); font-weight: 600; }
.attention-snooze-btn { background: none; border: 1px solid var(--color-border); color: var(--color-muted); border-radius: 4px; padding: 2px 8px; font-size: 11px; cursor: pointer; white-space: nowrap; }
.attention-snooze-btn:hover { border-color: var(--color-muted); color: var(--color-text); }
.attention-meta-note { font-size: 11px; color: var(--color-muted); }
.attention-type-pill {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-muted);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  padding: 1px 5px;
  margin-right: 2px;
}
.attention-action { white-space: nowrap; font-weight: 600; }

/* Client Timeline — a plain vertical list with a thin connecting rule and a
   small dot per event, deliberately not a decorated "AI-dashboard" timeline
   widget. Every event comes from a real, already-stored timestamp (brief/
   workspace updatedAt, statusHistory entries, handover/maintenance dates) —
   see buildClientTimeline() in client-detail.js. */
.timeline-list { list-style: none; margin: 0; padding: 0; border-left: 2px solid var(--color-border); }
.timeline-list li { position: relative; padding: 0 0 14px 16px; font-size: 13px; }
.timeline-list li:last-child { padding-bottom: 0; }
.timeline-list li::before {
  content: '';
  position: absolute;
  left: -5px;
  top: 3px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-border);
  border: 2px solid var(--color-surface);
}
.timeline-date { color: var(--color-muted); font-size: 11px; display: block; margin-bottom: 1px; }

.compact-stat-row { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 24px; }
.compact-stat {
  display: flex;
  align-items: baseline;
  gap: 6px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 6px 12px;
  font-size: 13px;
}
.compact-stat-value { font-weight: 600; font-family: var(--font-heading); }
.compact-stat-label { color: var(--color-muted); }

.field-row { display: flex; gap: 8px; margin-bottom: 8px; align-items: center; }
.field-row input, .field-row select, .field-row textarea,
input[type="text"], input[type="number"], input[type="email"], input[type="date"], input[type="password"], input[type="search"], select, textarea {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  color: #F2F4F6;
  padding: 6px 8px;
  font-size: 13px;
  font-family: var(--font-body);
}
input::placeholder, textarea::placeholder { color: var(--color-muted); opacity: 0.7; }

/* Brief highlight for a field jumped to via a "Resolve X" deep link (e.g.
   Proposal Management's Timeline blocker action) — a colour/outline change
   only, never motion that would need a reduced-motion guard. */
.field-focus-highlight {
  outline: 2px solid var(--color-primary) !important;
  outline-offset: 2px;
  transition: outline-color 0.3s ease;
}
/* Chrome's native date-input calendar-picker glyph is always dark-on-transparent
   (no CSS control over its own internal colour), so it's invisible against
   this dark theme's background without inverting it explicitly. */
input[type="date"]::-webkit-calendar-picker-indicator { filter: invert(1); }

.client-list-filters { display: flex; gap: 8px; align-items: center; margin: 12px 0; flex-wrap: wrap; }
.client-list-filters input { width: 280px; max-width: 100%; }

.breadcrumb { font-size: 13px; color: var(--color-muted); margin-bottom: 8px; }
.breadcrumb a { color: var(--color-muted); }
.breadcrumb a:hover { color: var(--color-primary); }
.breadcrumb-sep { margin: 0 6px; }
.breadcrumb [aria-current="page"] { color: #F2F4F6; }

.error-box {
  border: 1px solid var(--color-danger);
  color: var(--color-danger-text);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 16px;
}
.error-box ol { margin: 6px 0 0; padding-left: 18px; }

.warning-box {
  border: 1px solid var(--color-warning);
  color: var(--color-warning-text);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 16px;
}
.warning-box ul { margin: 6px 0 0; padding-left: 18px; }

.success-box {
  border: 1px solid var(--color-success);
  color: var(--color-success-text);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 16px;
}

/* A quiet, single-line variant of the three boxes above — for a status
   that's simply informational (e.g. "no blockers") and shouldn't carry the
   same visual weight as an actual problem. Same colour language, far less
   chrome: no border-box, just a coloured dot + text. */
.status-line { display: flex; align-items: center; gap: 8px; font-size: 13px; margin-bottom: 10px; }
.status-line::before { content: ''; width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; }
.status-line.is-success { color: var(--color-success-text); }
.status-line.is-success::before { background: var(--color-success); }
.status-line.is-danger { color: var(--color-danger-text); }
.status-line.is-danger::before { background: var(--color-danger); }
.status-line.is-warning { color: var(--color-warning-text); }
.status-line.is-warning::before { background: var(--color-warning); }

/* Deliberately quiet — a thin muted border, not a red-tinted background or
   a large warning icon. Restraint here is the point: this section should
   read as "a normal part of the page," not as an alarming callout, right up
   until the operator actually clicks Move to Trash or Permanently Purge. */
.danger-zone {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-top: 32px;
}
.danger-zone h2 { margin-top: 0; }
.danger-zone-result:empty { display: none; }
.danger-zone-result { margin-top: 12px; }

.markdown-view {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 24px 32px;
  max-width: 860px;
}
.markdown-view h1, .markdown-view h2 { color: #fff; }
.markdown-view table { margin: 12px 0; }
.markdown-view blockquote {
  border-left: 3px solid var(--color-primary);
  margin: 12px 0;
  padding: 4px 12px;
  color: var(--color-muted);
}

#toast-root {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
}
.toast {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 10px 16px;
  font-size: 13px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
}
.toast.error { border-color: #EF4444; color: #FCA5A5; }

.kv-row { display: flex; gap: 8px; padding: 3px 0; font-size: 13px; }
.kv-label { min-width: 200px; flex: 0 0 200px; color: var(--color-muted); }
.kv-value { min-width: 0; }

.actions-row { margin-top: 16px; display: flex; gap: 8px; flex-wrap: wrap; }

/* --- Client Detail: header (Phase 16B) -------------------------------------- */
.client-detail-header { margin: 10px 0 16px; }
.client-detail-name-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.client-detail-subline { font-size: var(--text-subsection); color: var(--color-muted); margin-top: 4px; }

/* --- Client Detail: workflow header ----------------------------------------- */
.workflow-header {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin: 0 0 16px;
  display: flex;
  gap: var(--space-6);
  flex-wrap: wrap;
}
.workflow-group { flex: 1 1 260px; min-width: 0; }
.workflow-group-label { font-size: var(--text-label); letter-spacing: 0.06em; text-transform: uppercase; color: var(--color-meta); margin-bottom: 8px; }
.workflow-steps { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; }
.workflow-step {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--color-muted);
  padding: 4px 10px 4px 4px;
  position: relative;
}
.workflow-step:not(:last-child)::after {
  content: "";
  width: 20px;
  height: 1px;
  background: var(--color-border);
  margin-left: 6px;
}
.workflow-dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1px solid var(--color-border);
  font-size: 10px;
  font-weight: 700;
  flex: 0 0 auto;
}
.workflow-step.is-done { color: #F2F4F6; }
.workflow-step.is-done .workflow-dot { background: var(--color-primary); border-color: var(--color-primary); color: var(--color-ink); }
.workflow-step.is-current:not(.is-done) { color: #F2F4F6; font-weight: 600; }
.workflow-step.is-current:not(.is-done) .workflow-dot { border-color: var(--color-primary); color: var(--color-primary); }
.workflow-next-action { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.workflow-next-reason { font-size: 12px; color: var(--color-muted); }

/* --- Client Detail: KPI strip (Phase 16B) ----------------------------------
   Restrained, compact — real derived values only, no giant SaaS metric
   tiles. A left accent stripe (not a background flood) marks tone. */
.kpi-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}
.kpi-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-left: 3px solid var(--color-border);
  border-radius: var(--radius);
  padding: 10px 14px;
}
.kpi-card-attention { border-left-color: var(--color-warning); }
.kpi-card-danger { border-left-color: var(--color-danger); }
.kpi-label { font-size: var(--text-label); text-transform: uppercase; letter-spacing: 0.05em; color: var(--color-meta); margin-bottom: 4px; }
.kpi-value { font-family: var(--font-heading); font-size: 19px; font-weight: 600; color: var(--color-text); }

/* --- Client Detail: Next Action panel — the one dominant element --------- */
.next-action-panel {
  background: var(--color-surface-elevated);
  border: 1px solid var(--color-border);
  border-left: 3px solid var(--color-primary);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: var(--space-5);
}
.next-action-eyebrow { font-size: var(--text-label); text-transform: uppercase; letter-spacing: 0.06em; color: var(--color-primary); margin-bottom: 6px; }
.next-action-headline { font-family: var(--font-heading); font-size: 20px; font-weight: 600; color: var(--color-text); margin-bottom: 4px; }
.next-action-detail { font-size: var(--text-subsection); color: var(--color-muted); margin-bottom: 12px; }
.next-action-buttons { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.next-action-done-note { font-size: var(--text-subsection); color: var(--color-muted); }

/* --- Client Detail: Current Work Summary grid ------------------------------ */
.current-work-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-5);
}
.current-work-grid > div {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 14px 16px;
  min-width: 0;
}
.current-work-grid > div h2 { font-size: var(--text-section); margin: 0 0 10px; }

/* --- Client Detail: compact Client Overview -------------------------------- */
.overview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-5);
}
.overview-col { min-width: 0; }
.overview-col h3 { font-size: var(--text-subsection); text-transform: uppercase; letter-spacing: 0.04em; color: var(--color-meta); margin: 0 0 8px; }
.overview-col .kv-label { min-width: 0; flex: 0 0 auto; max-width: 45%; }

/* --- Client Detail: collapsed-section summary hints ------------------------ */
.collapsible-hint { font-size: var(--text-meta); color: var(--color-meta); font-weight: 400; margin-left: auto; padding-right: 8px; }

/* --- Client Detail: Commercial History / Proposal row emphasis ------------ */
tr.row-emphasis td { font-weight: 600; }
tr.row-emphasis { border-left: 2px solid var(--color-primary); }
tr.row-muted td { color: var(--color-muted); }

/* --- Client Detail: Communications compact summary ------------------------ */
.comm-latest-line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: var(--text-subsection); color: var(--color-muted); margin-bottom: 10px; }

/* --- Collapsible sections (native <details>) -------------------------------- */
.collapsible-section {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 4px 14px;
  margin: 28px 0 16px;
}
.collapsible-section summary {
  cursor: pointer;
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: 15px;
  padding: 10px 0;
  list-style: none;
}
.collapsible-section summary::-webkit-details-marker { display: none; }
/* A CSS-drawn triangle, not a Unicode glyph — ▸/▾ render as a barely-visible
   dot in Space Grotesk at this size, which made every collapsible section
   in the portal look closed-and-uninteractive rather than expandable. A
   solid border-triangle is legible at any size/zoom and rotates smoothly
   for the open state instead of swapping glyphs. */
.collapsible-section summary { display: flex; align-items: center; gap: 8px; }
.collapsible-section summary::before {
  content: '';
  display: inline-block;
  width: 0;
  height: 0;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  border-left: 6px solid var(--color-muted);
  transition: transform 0.15s ease;
  flex: 0 0 auto;
}
.collapsible-section[open] summary::before { transform: rotate(90deg); }
.collapsible-section[open] summary { border-bottom: 1px solid var(--color-border); }
.collapsible-section > div { padding: 12px 0 8px; }

/* --- Settings-style long forms: group related fields into a card, rather
   than one continuous flow of headings (Phase 16) ---------------------- */
.settings-section {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: var(--space-5);
  max-width: 640px;
}
.settings-section h3 { margin-top: 0; font-size: var(--text-section); }

/* --- Readiness summary: replaces N stacked "no blockers" + "warnings"
   boxes (one pair per tier) with one compact line per tier, only
   expanding into the full warning/blocker list on demand — the tiers
   almost always repeat the same 2-3 warnings verbatim, which read as
   noise once tripled. See proposal/agreement/invoice/handover-management.js. */
.readiness-summary { margin-bottom: var(--space-4); }
.readiness-tier { border: 1px solid var(--color-border); border-radius: var(--radius); margin-bottom: 6px; }
.readiness-tier-head { display: flex; align-items: center; gap: 10px; padding: 8px 12px; font-size: 13px; }
.readiness-tier-head .tier-name { font-weight: 600; min-width: 140px; }
.readiness-tier-detail { padding: 0 12px 10px 12px; font-size: 13px; }
.readiness-tier-detail ol, .readiness-tier-detail ul { margin: 4px 0 0; padding-left: 18px; }
.readiness-tier-detail .blockers { color: var(--color-danger-text); }
.readiness-tier-detail .warnings { color: var(--color-warning-text); margin-top: 6px; }

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: transparent;
  border: none;
  color: var(--color-muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 8px;
}
.modal-close:hover { color: #fff; }

/* --- Pricing Editor --------------------------------------------------------- */
.pricing-body { display: flex; gap: 24px; align-items: flex-start; margin-top: 12px; }
.pricing-main { flex: 1; min-width: 0; }
.pricing-summary {
  width: 280px;
  flex: 0 0 280px;
  position: sticky;
  top: 20px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 16px;
  order: 2;
}
.pricing-main { order: 1; }

table.line-items-table th:nth-child(2), table.line-items-table td:nth-child(2) { width: 70px; }
table.line-items-table th:nth-child(3), table.line-items-table td:nth-child(3) { width: 120px; }
table.line-items-table th:nth-child(4), table.line-items-table td:nth-child(4) { width: 110px; }
table.line-items-table th:nth-child(5), table.line-items-table td:nth-child(5) { width: 150px; }
table.line-items-table td input { width: 100%; }
.row-total { font-variant-numeric: tabular-nums; font-weight: 600; }
tr.row-invalid td { background: rgba(239, 68, 68, 0.08); }
tr.row-invalid td:first-child { box-shadow: inset 3px 0 0 #EF4444; }

/* --- Proposal preview -------------------------------------------------------- */
.proposal-preview-frame {
  width: 100%;
  height: 80vh;
  min-height: 500px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: #fff;
}
@media (max-width: 600px) {
  .proposal-preview-frame { height: 70vh; min-height: 400px; }
}

@media (max-width: 800px) {
  #app { flex-direction: column; }
  /* flex-wrap:wrap is the actual fix for the long-standing ~6px mobile
     overflow (Phase 12): brand-mark + nav-list + nav-list-secondary never
     fit in one row at narrow widths, and with no wrap the last group
     (Legal Configuration) was pushed a few px past the viewport edge —
     confirmed via live measurement, not guessed. Wrapping onto a second
     row costs nothing visually (the sidebar was already a loose row of
     independent link groups, not a single rigid bar) and needs no other
     layout change. */
  #sidebar { width: 100%; flex: none; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px 16px; }
  .brand-mark { border: none; padding: 0; margin: 0; }
  .nav-section-label { display: none; }
  /* Logout must stay reachable on mobile — only the descriptive "Staff
     only / local instance" text (and the operator name it wraps, less
     essential at this width) is dropped, kept compact inline with the
     wrapping nav row rather than the old full-width footer block. */
  .sidebar-footer { border-top: none; padding: 0; margin-left: auto; }
  .sidebar-footer-text { display: none; }
  .logout-btn { width: auto; margin-top: 0; }
  /* Full-width on its own row rather than squeezed beside the nav links —
     the dropdown below it also needs the full row's width to stay usable. */
  .global-search { flex: 1 1 100%; order: 3; padding: 8px 0 0; }
  #global-search-results { left: 0; right: 0; }
  /* flex-shrink:0 (the old "flex: none") kept this list at its full
     unwrapped content width no matter how narrow the viewport got, since a
     flex item that refuses to shrink never gets small enough for its own
     internal flex-wrap to actually trigger — the page silently overflowed
     horizontally below ~756px even though every individual link would
     have fit on its own row. flex:1 1 auto + min-width:0 lets the browser
     narrow the list first, which is what makes the wrap happen at all. */
  #nav-list { display: flex; flex: 1 1 auto; min-width: 0; flex-wrap: wrap; }
  #nav-list-secondary { display: flex; flex-wrap: wrap; border-top: none; padding: 0; }
  #content { padding: 16px; }

  /* Sticky side panel -> full-width sticky summary bar. -1 keeps it the
     first thing visible in the stacked column, ahead of the line items,
     without needing scroll-tracking of its own — the same sticky-at-top
     bar pattern this list otherwise uses for the top-of-viewport nav. */
  /* align-items:flex-start (set for desktop row layout, so the sticky
     panel doesn't stretch to the tallest sibling's height) governs the
     CROSS axis — vertical in a row, but horizontal once flex-direction
     flips to column here. Left unset, it stopped children from
     stretching to the full available width, which was quietly widening
     the whole column to fit the line-items table instead of letting
     .table-scroll's own horizontal scroll handle it. */
  .pricing-body { flex-direction: column; align-items: stretch; }
  .pricing-summary { width: 100%; flex: none; position: sticky; top: 0; z-index: 5; order: -1; }
}

@media (max-width: 600px) {
  .field-row { flex-wrap: wrap; }
  .field-row input[type="text"],
  .field-row input[type="number"],
  .field-row select {
    flex: 1 1 120px;
    min-width: 0;
  }
  .kv-row { flex-direction: column; gap: 2px; padding: 6px 0; }
  .kv-label { flex: none; min-width: 0; }
}

/* --- Login (Phase 14) -------------------------------------------------------
   auth-mode hides the operator shell chrome entirely — a signed-out visitor
   sees only the sign-in card, never the sidebar/nav that implies access to
   client data. */
body.auth-mode #sidebar { display: none; }
body.auth-mode #content {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-wrap { width: 100%; max-width: 360px; }
.login-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 32px 28px;
}
.login-brand { text-align: center; margin-bottom: 24px; }
.login-mark { font-family: var(--font-heading); font-weight: 600; font-size: 18px; }
.login-sub {
  font-size: 11px;
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 2px;
}
.login-card h1 { text-align: center; font-size: 16px; margin-bottom: 20px; }
.login-field { margin-bottom: 14px; }
.login-field label { display: block; font-size: 13px; color: var(--color-muted); margin-bottom: 4px; }
.login-field input { width: 100%; padding: 9px 10px; font-size: 14px; }
.login-submit { width: 100%; justify-content: center; margin-top: 6px; padding: 9px 14px; }
.login-card .error-box { margin-bottom: 16px; }
