/* Appearance only. Shared surfaces and semantic states keep every workspace in sync. */
.header-controls, .policy-tools { display: flex; align-items: center; gap: 16px; }
.policy-tools { justify-content: space-between; margin-bottom: 20px; }
.theme-toggle {
  display: inline-flex; align-items: center; justify-content: center; flex: 0 0 44px;
  width: 44px; height: 44px; padding: 10px; border: 1px solid var(--line);
  border-radius: 50%; background: transparent; color: var(--ink); cursor: pointer;
}
.theme-toggle:hover { background: var(--mint); border-color: var(--control-border); }
.theme-toggle svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.theme-sun { display: none; }
.demo-banner { padding: 16px; background: #fff3cd; color: #302500; text-align: center; }

:root[data-theme="dark"] {
  color-scheme: dark;
  --canvas: #141918;
  --paper: #202725;
  --surface-soft: #28312e;
  --surface-raised: #303b36;
  --field: #171e1b;
  --ink: #f0f3ee;
  --muted: #b6c1ba;
  --quiet: #9eada4;
  --brand: #87d5bf;
  --brand-dark: #b0ead8;
  --mint: #304239;
  --line: #3c4942;
  --control-border: #6f8175;
  --accent-ink: #142d24;
  --accent-fill: #94d8c2;
  --success-surface: #244035;
  --success-text: #b4e6cd;
  --warning-surface: #3b3324;
  --warning-text: #f0d69f;
  --error-surface: #3d2928;
  --error: #ffb8ad;
  --error-border: #bc7167;
  --shadow-soft: 0 2px 6px #00000014, 0 12px 28px #00000024;
}
[data-theme="dark"] .theme-moon { display: none; }
[data-theme="dark"] .theme-sun { display: block; }
[data-theme="dark"] ::selection { background: #436858; color: #fff; }

/* Charcoal surfaces; teal is reserved for actions and selection. */
:root[data-theme="dark"] :is(.button.secondary, .skip-link, .service-panel, .panel-header, .panel-footer,
  .metrics, .dashboard-toolbar, .lead, .empty-state, .settings-card, .policy, .demo-calendar,
  .followup-attention, .settings-group, .settings-group-body, .map-card, .coverage-screening,
  .preview-card, .preview-source, .preview-results, .invite-create-panel, .invite-share-panel,
  .request-sheet, .demo-calendar-day) {
  background: var(--paper); color: var(--ink); border-color: var(--line);
}
:root[data-theme="dark"] :is(#invite-text, #demo-list > section) { background: var(--paper); color: var(--ink); border-color: var(--line); }
:root[data-theme="dark"] :is(.service-panel, .metrics, .request-sheet, .settings-fields, .policy) { border-top-color: #6d9884; }
:root[data-theme="dark"] .metric { background: transparent; border-color: var(--line); }
:root[data-theme="dark"] :is(.request-summary, .confirmation-time, .avatar, .today-section,
  .settings-preview, .lead-photo, .demo-calendar-agenda, .preview-empty, .preview-metrics > div,
  .request-group, .preview-source-label, .request-group > summary) {
  background: var(--surface-soft); border-color: var(--line); color: var(--ink);
}
:root[data-theme="dark"] :is(.snapshot-status, .preview-limits, .results-interpretation, .run-inputs) { background: transparent; color: var(--muted); }
:root[data-theme="dark"] :is(.settings-savebar, .save-bar) {
  background: var(--surface-raised); color: var(--ink); border-color: #60766a;
  box-shadow: 0 4px 20px #0004;
}
:root[data-theme="dark"] .panel-footer { box-shadow: 0 -6px 18px #00000018; }
:root[data-theme="dark"] .lead.lead-urgent { background: var(--paper); color: var(--ink); border-color: var(--error-border); }
:root[data-theme="dark"] .lead.lead-urgent:hover { border-color: var(--error); }

/* Text that was hand-colored for the light palette must stay readable here. */
:root[data-theme="dark"] :is(.service-tags span, .header-note, .intro .eyebrow, .intro-copy,
  .demo-information, .journey-number, .step-count, .panel-title-row .eyebrow, .form-guidance,
  .lead-description, .demo-calendar-weekdays, .demo-calendar-count, .demo-calendar-label,
  .settings-preview p, .preview-detail span, .hero-note, .specimen-caption, .sheet-label,
  .sheet-id, .sheet-facts dt, .sheet-facts dd span, .specimen-footnote, .scope-strip p,
  .scope-strip > span, .workflow-intro, .workflow-list p, .step-tag, .rollout-copy > p,
  .faq-list details p, .marketing-footer > span, .marketing-footer nav a, .group-summary,
  .preview-rule, .request-row .request-transition) { color: var(--muted); }
:root[data-theme="dark"] .marketing-page .eyebrow { color: var(--muted); }
:root[data-theme="dark"] .marketing-page h1 > span { color: #a5c7b6; }
:root[data-theme="dark"] :is(.intake-group legend, .request-sheet blockquote, .request-state,
  .demo-calendar-upcoming-link, .demo-calendar-time, .settings-tools > summary, .preview-limits strong) { color: var(--ink); }
:root[data-theme="dark"] :is(.site-header, .intake-group, .photo-attachment, .sheet-header,
  .sheet-facts > div, .scope-strip, .scope-strip > span, .workflow-list li, .rollout-section,
  .faq-list details, .marketing-footer, .preview-detail, .demo-calendar-entry,
  .demo-calendar-upcoming-link, .followup-timeline > li, .eligibility-table th,
  .eligibility-table td, .baseline-list) { border-color: var(--line); }
:root[data-theme="dark"] .settings-group > summary::before { color: var(--quiet); }
:root[data-theme="dark"] .group-chevron { border-color: var(--muted); }
:root[data-theme="dark"] .request-state::before { background: var(--brand); }

/* Comfortable inputs, distinct button levels, visible keyboard focus. */
:root[data-theme="dark"] :is(input, select, textarea) {
  background: var(--field); color: var(--ink); border-color: var(--control-border);
}
:root[data-theme="dark"] :is(input, textarea)::placeholder { color: var(--quiet); opacity: 1; }
:root[data-theme="dark"] :is(input, select, textarea):hover:not(:disabled) { border-color: #8eaa99; }
:root[data-theme="dark"] :is(input, select, textarea):focus-visible {
  border-color: var(--brand); box-shadow: 0 0 0 3px #87d5bf24; outline: none;
}
:root[data-theme="dark"] :focus-visible { outline: 2px solid var(--brand); outline-offset: 3px; }
:root[data-theme="dark"] input[type="checkbox"]:focus-visible { outline: 2px solid var(--brand); outline-offset: 3px; }
:root[data-theme="dark"] :is(input[type="file"], input[type="range"]) { background: transparent; }
:root[data-theme="dark"] input::file-selector-button { background: var(--surface-soft); color: var(--ink); border-color: var(--control-border); }
:root[data-theme="dark"] [aria-invalid="true"] { border-color: var(--error); }
:root[data-theme="dark"] .brand-mark { background: #08776a; color: white; }
:root[data-theme="dark"] .brand:hover { color: var(--ink); }
:root[data-theme="dark"] .button.primary { background: var(--accent-fill); border-color: var(--accent-fill); color: var(--accent-ink); }
:root[data-theme="dark"] .button.primary:hover:not(:disabled) { background: #b0ead8; border-color: #b0ead8; color: var(--accent-ink); }
:root[data-theme="dark"] .button.secondary { border-color: #617569; }
:root[data-theme="dark"] .button.secondary:hover:not(:disabled) { background: var(--surface-raised); border-color: #8eaa99; }
:root[data-theme="dark"] :is(.top-nav a:hover, .settings-group > summary:hover) { background: var(--surface-soft); }
:root[data-theme="dark"] :is(.settings-group > summary, .demo-calendar-day, .demo-calendar button):focus-visible { outline-offset: -4px; }
:root[data-theme="dark"] :is(.example-selector, .mode-switch, .source-switch, .demo-calendar-views) {
  background: var(--field); border: 1px solid var(--line);
}
:root[data-theme="dark"] :is(.example-selector button, .mode-switch button, .source-switch button,
  .demo-calendar-views .button, .tool-button) { color: var(--muted); background: transparent; border-color: transparent; }
:root[data-theme="dark"] :is(.example-selector button[aria-pressed="true"], .mode-switch [aria-pressed="true"],
  .demo-calendar-views [aria-pressed="true"], .source-switch [aria-pressed="true"], .tool-button[aria-pressed="true"]) {
  background: #354b40; color: #d8f3e6; border-color: #6b9b80; box-shadow: 0 1px 3px #0002;
}
:root[data-theme="dark"] :is(.example-selector button:hover:not([aria-pressed="true"]), .mode-switch button:hover:not([aria-pressed="true"]),
  .source-switch button:hover:not([aria-pressed="true"]), .tool-button:hover:not(:disabled), .demo-calendar-views .button:hover:not([aria-pressed="true"])) {
  background: var(--surface-soft); color: var(--ink);
}
:root[data-theme="dark"] :is(.button, .tool-button, .mode-switch button, .source-switch button):disabled {
  opacity: 1; background: var(--surface-soft); color: var(--quiet); border-color: var(--line); box-shadow: none;
}

/* Intake and scheduling: keep the active step and selected day unmistakable. */
:root[data-theme="dark"] .chat-bubble { background: #2b4036; color: var(--ink); }
:root[data-theme="dark"] .chat-bubble.customer { background: var(--surface-soft); color: var(--ink); }
:root[data-theme="dark"] .slot-button { background: var(--paper); border-color: var(--control-border); }
:root[data-theme="dark"] .slot-button:hover:not(:disabled) { background: var(--mint); border-color: var(--brand); }
:root[data-theme="dark"] .journey [aria-current] .journey-number { background: var(--accent-fill); color: var(--accent-ink); border-color: var(--accent-fill); }
:root[data-theme="dark"] .demo-calendar-day:hover { background: var(--surface-raised); }
:root[data-theme="dark"] .demo-calendar-day.outside-month { background: #191f1c; color: var(--quiet); }
:root[data-theme="dark"] .demo-calendar-day.selected { background: #2d463b; box-shadow: inset 0 0 0 2px var(--brand); color: var(--ink); }
:root[data-theme="dark"] .demo-calendar-day[aria-current="date"] .demo-calendar-number { background: var(--accent-fill); color: var(--accent-ink); }
:root[data-theme="dark"] .demo-calendar-number { min-width: 26px; text-align: center; font-size: .875rem; }
:root[data-theme="dark"] .demo-calendar-count { font-size: .75rem; }
:root[data-theme="dark"] .demo-calendar-legend .confirmed::before { background: var(--brand); }
:root[data-theme="dark"] .demo-calendar-legend .requested::before { background: #e3bc6c; }
:root[data-theme="dark"] :is(.panel-scroll, .conversation, .followup-timeline) { scrollbar-color: #6b8074 transparent; }
:root[data-theme="dark"] .panel-scroll::-webkit-scrollbar-thumb { background: #6b8074; }

/* Status colors mean the same thing in cards, calendars, and previews. */
:root[data-theme="dark"] :is(.summary-check, .confirmation-icon, .journey .is-complete .journey-number,
  .appointment-label, .pill, .demo-calendar-event.confirmed, .demo-calendar-status.confirmed,
  .followup-count, .pin-result) { background: var(--success-surface); color: var(--success-text); border-color: #598e72; }
:root[data-theme="dark"] :is(.sheet-next, .followup-tag) { background: var(--surface-soft); color: #d5e2d8; border-color: var(--line); }
:root[data-theme="dark"] .sheet-next p { color: var(--muted); }
:root[data-theme="dark"] :is(.message.error, .urgent-summary, .urgent-badge, .followup-tag.urgent,
  .followup-tag.overdue, .pin-result[data-result="outside"], .urgent-example .sheet-next) {
  background: var(--error-surface); color: var(--error); border-color: var(--error-border);
}
:root[data-theme="dark"] :is(.urgent-example .request-state, .urgent-example .sheet-next > strong,
  .urgent-example .sheet-next .sheet-label, .urgent-example .sheet-next p, .request-row .request-urgent) { color: var(--error); }
:root[data-theme="dark"] .urgent-example .request-state::before { background: var(--error); }
:root[data-theme="dark"] .settings-savebar .message.error { background: transparent; }
:root[data-theme="dark"] :is(.handoff, .demo-booking-option, .demo-calendar-event.requested,
  .demo-calendar-status.requested, .followup-tag.today, .followup-closed, .lab-label,
  .pin-result[data-result="review"], .pill.contacted, .demo-banner,
  .preview-source-label[data-source="example"]) { background: var(--warning-surface); color: var(--warning-text); border-color: #8c7645; }
:root[data-theme="dark"] .preview-results[data-stale="true"] #result-status { background: var(--warning-surface); color: var(--warning-text); }
:root[data-theme="dark"] .preview-results[data-stale="true"] .preview-metrics { opacity: 1; }
:root[data-theme="dark"] .pill.booked { color: #b7d3f4; background: #24364b; }
:root[data-theme="dark"] .pill.closed { color: var(--muted); background: var(--surface-soft); }
:root[data-theme="dark"] .preview-readonly { background: var(--surface-soft); color: var(--muted); }

/* Marketing keeps the same understated hierarchy as the product. */
:root[data-theme="dark"] .workspace-section { background: #1d2a24; color: var(--ink); border-block: 1px solid var(--line); }
:root[data-theme="dark"] :is(.workspace-heading, .honesty-note) { border-color: #475d4f; }
:root[data-theme="dark"] :is(.workspace-section .eyebrow, .workspace-heading > p, .workspace-notes p, .calendar-shot figcaption) { color: #c0cfc4; }
:root[data-theme="dark"] :is(.workspace-index, .honesty-note strong) { color: #cbe2d2; }
:root[data-theme="dark"] .calendar-shot > a { background: var(--paper); border: 1px solid var(--line); box-shadow: var(--shadow-soft); }

/* Only the basemap is filtered. Photos and overlay geometry retain their colors. */
:root[data-theme="dark"] #coverage-map { background: var(--canvas); border-color: var(--control-border); }
:root[data-theme="dark"] .leaflet-tile-pane { filter: brightness(.88) invert(1) contrast(.8) hue-rotate(180deg) saturate(.4); }
:root[data-theme="dark"] :is(.leaflet-control-zoom a, .leaflet-control-attribution, .leaflet-tooltip) { background: var(--paper); color: var(--ink); border-color: var(--line); }
:root[data-theme="dark"] .leaflet-control-zoom a:hover { background: var(--surface-raised); }
:root[data-theme="dark"] .leaflet-control-attribution a { color: var(--brand); }
:root[data-theme="dark"] .leaflet-tooltip-top::before { border-top-color: var(--paper); }
:root[data-theme="dark"] .leaflet-tooltip-bottom::before { border-bottom-color: var(--paper); }
:root[data-theme="dark"] .leaflet-tooltip-left::before { border-left-color: var(--paper); }
:root[data-theme="dark"] .leaflet-tooltip-right::before { border-right-color: var(--paper); }
:root[data-theme="dark"] .coverage-boundary { stroke: var(--brand); fill: var(--brand); }
:root[data-theme="dark"] .coverage-guide { stroke: var(--brand); }
:root[data-theme="dark"] .coverage-pin { stroke: #d7e9ff; fill: #8cbbef; }
:root[data-theme="dark"] .coverage-pin-inside { stroke: #d2f4e3; fill: var(--brand); }
:root[data-theme="dark"] .coverage-pin-outside { stroke: #ffd8d0; fill: var(--error); }
:root[data-theme="dark"] .coverage-pin-review { stroke: #fff0cf; fill: var(--warning-text); }
:root[data-theme="dark"] .coverage-handle::after { background: var(--field); border-color: var(--brand); }
:root[data-theme="dark"] .key-area { background: #87d5bf33; border-color: var(--brand); }
:root[data-theme="dark"] #coverage-map[data-crosshair="true"]::after { color: var(--ink); text-shadow: 0 1px 4px #000; }
:root[data-theme="dark"] .save-info > span[data-state="saved"] { background: var(--brand); }

@media (prefers-reduced-motion: no-preference) {
  body, .theme-toggle, .button, .service-panel, .panel-header, .panel-footer,
  .request-sheet, .sheet-next, .settings-group, .settings-group > summary,
  .settings-group-body, .settings-savebar, .demo-calendar, .demo-calendar-agenda,
  .lead, .followup-attention, .dashboard-toolbar, .policy, .workspace-section {
    transition: background-color .18s ease, border-color .18s ease, color .18s ease, box-shadow .18s ease;
  }
  .theme-toggle svg { transition: transform .18s ease; }
  .theme-toggle:hover svg { transform: rotate(12deg); }
  .group-chevron { transition: transform .18s ease; }
}
@media (max-width: 760px) {
  .header-controls { gap: 8px; }
  .header-controls .header-note { display: none; }
  .marketing-header nav { gap: 12px; }
  .theme-toggle { flex-basis: 44px; }
}
@media (max-width: 420px) {
  .marketing-header .brand { font-size: 1.3rem; }
  .marketing-header .button { padding-inline: 12px; }
  .marketing-header nav { gap: 8px; }
}
