/* Central dark palette. Screen-only: printed documents keep their paper styles. */
@media screen {
  html[data-theme="dark"] {
    --night-canvas: #111518;
    --night-panel: #1a2024;
    --night-raised: #222a2f;
    --night-edge: #343e44;
    --night-text: #edf1f3;
    --night-muted: #a5b1ba;
    --night-accent: #ace6cd;
    --night-accent-bg: #263b34;
    --brand: #a0dfc4;
    --brand-dark: #c0edda;
    --brand-soft: #263b34;
    --ink: #edf1f3;
    --muted: #a5b1ba;
    --line: #343e44;
    --paper: #1a2024;
    --canvas: #111518;
    --glass-border: #343e44;
  }
  html[data-theme="dark"] body,
  html[data-theme="dark"] body:is(.dashboard-page, .app-page, .portal-page, .control-page) {
    color: var(--night-text);
    background: var(--night-canvas);
  }
  html[data-theme="dark"] body .app-shell::before,
  html[data-theme="dark"] body .app-shell::after,
  html[data-theme="dark"] body .dashboard-workspace::before,
  html[data-theme="dark"] body .dashboard-workspace::after { opacity: 0; }
  html[data-theme="dark"] body .dashboard-workspace { background: radial-gradient(ellipse at 75% 0, rgba(113,149,192,.045), transparent 45rem), var(--night-canvas); }

  /* Navigation stays visually separate from the working canvas. */
  html[data-theme="dark"] body .dashboard-sidebar { color: var(--night-text); background: #151b1f; border-color: var(--night-edge); box-shadow: none; }
  html[data-theme="dark"] body :is(.topbar, .dashboard-topbar, .portal-topbar) { color: var(--night-text); background: rgba(21,27,31,.94); border-color: var(--night-edge); box-shadow: 0 1px 0 rgba(255,255,255,.02); -webkit-backdrop-filter: blur(18px); backdrop-filter: blur(18px); }
  html[data-theme="dark"] body :is(.dashboard-club-card, .dashboard-search) { color: var(--night-text); border-color: var(--night-edge); background: var(--night-panel); box-shadow: none; }
  html[data-theme="dark"] body .dashboard-brandmark { background: linear-gradient(145deg, #31896d, #22644f); box-shadow: inset 0 1px rgba(255,255,255,.15); animation: none; }
  html[data-theme="dark"] body .dashboard-brandmark::after { opacity: .12; animation: none; }
  html[data-theme="dark"] body .dashboard-nav section { border-color: #2d363c; }
  html[data-theme="dark"] body .dashboard-nav section > strong { color: #d0d8de; }
  html[data-theme="dark"] body .dashboard-nav-overline { color: #a0adb7; }
  html[data-theme="dark"] body .dashboard-nav a { color: #aab7c0; }
  html[data-theme="dark"] body .dashboard-nav a:hover { color: var(--night-text); background: var(--night-raised); }
  html[data-theme="dark"] body .dashboard-nav a.is-active { color: #d3f3e5; border-color: #426658; background: #243b32; box-shadow: none; }
  html[data-theme="dark"] body .dashboard-nav a.is-active::after { background: #a0dfc4; box-shadow: none; }
  html[data-theme="dark"] body .dashboard-nav a > span:first-child { color: #a2b6bd; }
  html[data-theme="dark"] body .dashboard-nav a.is-active > span:first-child { color: #bbebd5; background: rgba(172,230,205,.07); border-color: rgba(172,230,205,.12); }
  html[data-theme="dark"] body :is(.dashboard-user, .platform-status-head, .operation-identity) { border-color: var(--night-edge); }
  html[data-theme="dark"] body :is(.dashboard-theme-toggle, .dashboard-notification, .dashboard-cora summary, .global-theme-toggle) { border-color: var(--night-edge); color: var(--night-text); background: var(--night-raised); box-shadow: none; }
  html[data-theme="dark"] body :is(.app-nav, .portal-nav) a[aria-current="page"] { background: var(--night-raised); color: var(--night-text); border-color: var(--night-edge); box-shadow: none; }

  /* Neutral, gently layered surfaces replace tinted glass. */
  html[data-theme="dark"] body :is(
    .dashboard-panel, .dashboard-rolebar, .dashboard-metrics article,
    .data-panel, .member-hero, .cora-card, .form-section,
    .foundation-grid article, .feature-entry, .colony-card,
    .facility-metrics article, .finance-metrics article, .account-card,
    .finding-card, .billing-preview-card, .portal-metrics article,
    .communication-metrics article, .inspection-metrics article,
    .assets-metrics article, .rental-metrics article, .asset-card,
    .template-card, .policy-card, .resolution-card, .venue-grid article,
    .rental-balance-grid article, .platform-status-card, .operation-metric,
    .operation-row, .tenant-row, .transfer-step, .scan-group-card,
    .scan-upload-card, .scan-safety-card, .cora-center-metrics a,
    .cora-rule-grid article, .receipt-download-card, .receipt-entry-panel,
    .receipt-preview-panel, .receipt-original-panel, .receipt-suggestion-summary,
    .receipt-verification-card, .cora-alert-strip, .cora-alert-card
  ) {
    color: var(--night-text);
    border-color: var(--night-edge);
    background: var(--night-panel);
    box-shadow: 0 8px 24px rgba(0,0,0,.1), inset 0 1px rgba(255,255,255,.025);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
  html[data-theme="dark"] body :is(.cora-center-hero, .cora-rules-hero, .facility-page-hero, .template-library-hero, .serial-letter-hero, .control-customer-hero, .transfer-hero) {
    border-color: var(--night-edge); color: var(--night-text);
    background: linear-gradient(125deg, #232e35, #1a2227);
    box-shadow: 0 12px 30px rgba(0,0,0,.1);
  }
  html[data-theme="dark"] body :is(.dashboard-panel, .dashboard-metrics article, .cora-alert-strip)::after { opacity: 0; }
  html[data-theme="dark"] body :is(.dashboard-metrics article, .dashboard-panel) { border-radius: 20px; }
  html[data-theme="dark"] body.dashboard-page .dashboard-metrics article[class] { background: var(--night-panel); border-color: var(--night-edge); }
  html[data-theme="dark"] body.dashboard-page .dashboard-metrics article.has-warning { background: #292820; border-color: #79633e; }
  html[data-theme="dark"] body .dashboard-metrics article::before { height: 2px; opacity: .55; }
  html[data-theme="dark"] body :is(.dashboard-metrics article > strong, .dashboard-panel h2, .section-heading h2, .operation-facts strong) { color: var(--night-text); }
  html[data-theme="dark"] body :is(.dashboard-metrics small, .dashboard-metrics p, .eyebrow, .dashboard-eyebrow, .dashboard-panel .eyebrow, .data-panel .eyebrow, .cora-card .eyebrow, .cora-alert-card small, .cora-alert-strip header small) { color: var(--night-muted); }
  html[data-theme="dark"] body :is(.metric-icon, .record-avatar, .dashboard-role-symbol, .dashboard-club-card > span, .dashboard-task-list > a > span) { color: #c1dcce; background: #2a3a33; box-shadow: none; }
  html[data-theme="dark"] body .metric-icon.is-blue { color: #bad8f0; background: #293b4a; }
  html[data-theme="dark"] body .metric-icon.is-warn { color: #f0d49e; background: #433827; }

  /* The dashboard hero gets a soft cool highlight, not a wall of green. */
  html[data-theme="dark"] body.dashboard-page .dashboard-hero.dashboard-hero--command {
    min-height: 280px;
    padding: clamp(28px, 4vw, 48px);
    border-color: #3b4851;
    border-radius: 26px;
    background: radial-gradient(ellipse at 94% 10%, rgba(136,167,202,.14), transparent 52%), linear-gradient(125deg, #25323c, #1c252b 70%);
    box-shadow: 0 18px 46px rgba(0,0,0,.16), inset 0 1px rgba(255,255,255,.04);
  }
  html[data-theme="dark"] body.dashboard-page .dashboard-hero--command::before { opacity: .08; animation: none; }
  html[data-theme="dark"] body.dashboard-page .dashboard-hero--command::after { opacity: .15; box-shadow: none; border-color: #8293a0; animation: none; }
  html[data-theme="dark"] body .dashboard-ambient { opacity: .1; }
  html[data-theme="dark"] body .dashboard-hero--command h1 { color: #f0f3f5; font-size: clamp(2.25rem, 4.2vw, 4rem); font-weight: 650; text-shadow: none; letter-spacing: -.045em; line-height: 1.08; }
  html[data-theme="dark"] body .dashboard-hero--command p { color: #b8c6d0; }
  html[data-theme="dark"] body .dashboard-live-grid { background: rgba(12,20,26,.36); border-color: #40505c; border-radius: 13px; box-shadow: none; }
  html[data-theme="dark"] body .dashboard-live-grid > span { border-color: #3a4a55; }
  html[data-theme="dark"] body .dashboard-live-grid small { color: #b2c1cc; }
  html[data-theme="dark"] body .dashboard-live-grid strong { color: #f0f3f5; }
  html[data-theme="dark"] body .dashboard-hero-cora {
    border-color: #485b68; background: linear-gradient(145deg, rgba(89,117,137,.22), rgba(21,33,42,.68));
    box-shadow: 0 16px 34px rgba(0,0,0,.16), inset 0 1px rgba(255,255,255,.06);
    transform: none; animation: none;
  }
  html[data-theme="dark"] body .dashboard-hero-cora::before,
  html[data-theme="dark"] body .dashboard-hero-cora::after { opacity: .08; animation: none; }
  html[data-theme="dark"] body .dashboard-hero-cora small { color: #bdcdd7; }
  html[data-theme="dark"] body .dashboard-hero-cora strong { color: #f0f3f5; }
  html[data-theme="dark"] body .dashboard-hero-cora > div > span { color: #bbcad3; }
  html[data-theme="dark"] body .dashboard-hero-cora > div > .dashboard-cora-signal { color: #b4e5cf; }
  html[data-theme="dark"] body .dashboard-cora-orbit { border-color: rgba(172,230,205,.13); box-shadow: none; }

  /* Controls remain dark while retaining explicit focus and disabled states. */
  html[data-theme="dark"] body :is(.primary-link, .primary-button) { color: #132f24; border-color: #acd9c4; background: linear-gradient(135deg, #b4e7d0, #9ad5b8); box-shadow: 0 5px 15px rgba(0,0,0,.12); }
  html[data-theme="dark"] body :is(.secondary-button, .secondary-link, .quiet-button, .dashboard-cora > div, .dashboard-role-pill) { color: #dce5e9; border-color: #43515a; background: var(--night-raised); box-shadow: none; }
  html[data-theme="dark"] body :is(.secondary-button, .secondary-link, .quiet-button):hover { color: #f4f7f8; border-color: #778e9c; background: #2c373e; }
  html[data-theme="dark"] body .member-form :is(input:not([type="checkbox"]):not([type="radio"]):not([type="file"]), select, textarea),
  html[data-theme="dark"] body :is(.filter-bar, .operations-filters, .communication-filter, .assets-filter, .cora-form) :is(input, select, textarea),
  html[data-theme="dark"] body .dashboard-search input {
    color-scheme: dark; color: #edf1f3; border-color: #485760; background: #171e23; box-shadow: inset 0 1px 2px rgba(0,0,0,.12);
  }
  html[data-theme="dark"] body .member-form :is(input, select, textarea):focus,
  html[data-theme="dark"] body :is(.filter-bar, .operations-filters) :is(input, select):focus { border-color: #a0dfc4; outline: 2px solid rgba(160,223,196,.25); outline-offset: 2px; background: #1c272d; box-shadow: none; }
  html[data-theme="dark"] body .member-form :is(input, textarea)::placeholder,
  html[data-theme="dark"] body .filter-bar input::placeholder { color: #9aa9b4; opacity: 1; }
  html[data-theme="dark"] body .member-form :is(input, select, textarea):disabled,
  html[data-theme="dark"] body .member-form input[readonly] { color: #a4afb8; background: #2a3238; border-color: #404b53; }
  html[data-theme="dark"] body .member-form input[type="file"] { color: var(--night-text); background: #222c32; border-color: #485760; }
  html[data-theme="dark"] body input[type="search"] { -webkit-appearance: none; appearance: none; color-scheme: dark; color: #edf1f3; background: #171e23; border-color: #485760; }
  html[data-theme="dark"] body .dashboard-search input[type="search"]:not([type="checkbox"]):not([type="radio"]) { background: transparent; color: #edf1f3; border: 0; box-shadow: none; }
  html[data-theme="dark"] body .dashboard-search input::placeholder { color: #a5b1ba; opacity: 1; }
  html[data-theme="dark"] body .member-form input:-webkit-autofill { -webkit-text-fill-color: #edf1f3; caret-color: #edf1f3; -webkit-box-shadow: inset 0 0 0 1000px #171e23; }
  html[data-theme="dark"] body :is(.form-field label, .tenant-identity a, .operation-identity a) { color: #dce5e9; }
  html[data-theme="dark"] body :is(.filter-bar, .cora-center-filters, .cora-alert-filters, .info-grid, .operation-facts > div, .subscription-operation) { color: var(--night-text); background: var(--night-raised); border-color: var(--night-edge); box-shadow: none; }
  html[data-theme="dark"] body .info-grid > div { background: var(--night-panel); }
  html[data-theme="dark"] body .info-grid dt { color: var(--night-muted); }
  html[data-theme="dark"] body .info-grid dd { color: var(--night-text); }
  html[data-theme="dark"] body :is(.member-table thead th, .dashboard-table thead th) { background: #222b31; color: #b5c1ca; border-color: var(--night-edge); }
  html[data-theme="dark"] body :is(.member-table td, .dashboard-table td, .dashboard-task-list > a, .finance-row, .document-row, .history-row, .bank-transaction) { border-color: var(--night-edge); }
  html[data-theme="dark"] body :is(.member-table tbody tr, .dashboard-table tbody tr, .dashboard-task-list > a, .finance-row, .document-row, .communication-row, .rental-row, .inspection-row, .bank-transaction):hover { color: var(--night-text); background: #263239; }
  html[data-theme="dark"] body :is(.tenant-facts span, .receipt-recognized span, .facility-result-count) { color: #bedace; background: #293b33; border-color: #435d50; }

  /* Shared form controls also cover search and filter forms outside member-form. */
  html[data-theme="dark"] body:is(.app-page, .control-page, .portal-page, .dashboard-page) input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
  html[data-theme="dark"] body:is(.app-page, .control-page, .portal-page, .dashboard-page) :is(select, textarea) {
    color-scheme: dark; color: var(--night-text); background-color: #171e23; border-color: #485760;
  }
  html[data-theme="dark"] body:is(.app-page, .control-page, .portal-page, .dashboard-page) :is(input, select, textarea):focus-visible {
    outline: 2px solid #a0dfc4; outline-offset: 3px;
  }
  html[data-theme="dark"] body:is(.app-page, .control-page, .portal-page, .dashboard-page) :is(input, textarea)::placeholder { color: #9aa9b4; opacity: 1; }
  html[data-theme="dark"] body:is(.app-page, .control-page, .portal-page, .dashboard-page) :is(input, select, textarea):disabled { color: #a4afb8; background-color: #2a3238; border-color: #404b53; }
  html[data-theme="dark"] body input:is([type="checkbox"], [type="radio"]) { accent-color: #a0dfc4; color-scheme: dark; }
  html[data-theme="dark"] body .member-form ul { background: var(--night-raised); border-color: var(--night-edge); }

  /* Calendar and task lists share the graphite canvas, with semantic event colours. */
  html[data-theme="dark"] body .calendar-grid { background: var(--night-edge); border-color: var(--night-edge); }
  html[data-theme="dark"] body .calendar-day { color: var(--night-text); background: var(--night-panel); }
  html[data-theme="dark"] body .calendar-day:hover { background: #263239; }
  html[data-theme="dark"] body .calendar-day.is-today { background: #293b33; box-shadow: inset 0 3px #a0dfc4; }
  html[data-theme="dark"] body .calendar-event { color: #d9eee4; background: #2a4036; border-color: #84c6a7; }
  html[data-theme="dark"] body .calendar-event small { color: #b7c9bf; }
  html[data-theme="dark"] body .calendar-event.event-kind-deadline { color: #f0d49e; background: #433827; border-color: #d4ac63; }
  html[data-theme="dark"] body .calendar-event:is(.event-kind-meeting, .event-kind-assembly) { color: #c8dff0; background: #293b4a; border-color: #8ab4d5; }
  html[data-theme="dark"] body :is(.work-task-row, .community-event, .meeting-row, .agenda-list > li) { border-color: var(--night-edge); }
  html[data-theme="dark"] body :is(.work-task-row, .community-event, .meeting-row):hover { background: #263239; color: var(--night-text); }
  html[data-theme="dark"] body .work-task-row.is-overdue { background: #342e24; border-color: #79633e; }

  /* Semantic feedback keeps its meaning, independent of decorative accents. */
  html[data-theme="dark"] body :is(.metric-warning, .finance-metrics .metric-warning, .form-guidance, .receipt-analysis-state.is-warning) { border-color: #79633e; color: #f0d49e; background: #342e24; }
  html[data-theme="dark"] body :is(.metric-warning strong, .dashboard-count, .mini-alert) { color: #f0d49e; background: #433827; }
  html[data-theme="dark"] body :is(.success-banner, .receipt-analysis-state.is-ready, .cora-alert-clear) { color: #c0ebd5; background: #243a30; border-color: #486d59; box-shadow: none; }
  html[data-theme="dark"] body :is(.form-alert, .operation-error) { color: #ffd4cf; background: #442c2d; border-color: #90605d; }
  html[data-theme="dark"] body .cora-alert-card.severity-urgent { border-color: #90605d; }
  html[data-theme="dark"] body .cora-alert-card.severity-warning { border-color: #79633e; }
  html[data-theme="dark"] body .cora-alert-card.severity-warning > span { color: #f0d49e; background: #433827; border-color: #79633e; }
  html[data-theme="dark"] body .cora-alert-card p { color: var(--night-muted); }
  html[data-theme="dark"] body .receipt-preview-stage,
  html[data-theme="dark"] body .receipt-original-viewer { background: #10171c; border-color: #43515a; }

  /* Cora retains her living orb; its surrounding panels use the same palette. */
  html[data-theme="dark"] body :is(.cora-assistant, .cora-assistant-context, .cora-message.is-user > div, .cora-composer, .cora-results > a, .cora-quick-actions, .cora-proposal, .cora-sound-settings) { background: var(--night-panel); color: var(--night-text); border-color: var(--night-edge); box-shadow: none; }
  html[data-theme="dark"] body :is(.cora-message p, .cora-proposal dd) { color: #dce5e9; }
  html[data-theme="dark"] body .cora-message.is-user > div { background: #2c473b; }
  html[data-theme="dark"] body :is(.cora-quick-actions > button, .cora-suggestions button, .cora-actions a, .cora-sound-settings select, .cora-facts > span) { background: var(--night-raised); border-color: #43515a; color: #d5e2dc; }
  html[data-theme="dark"] body .cora-launcher { background: linear-gradient(125deg, #2e5243, #233a31); color: #edf7f2; border-color: #5e8973; box-shadow: 0 8px 26px rgba(0,0,0,.23); }
  html[data-theme="dark"] body .cora-launcher small { color: #bedbcd; }
  html[data-theme="dark"] body .cora-facts .is-warning { color: #f0d49e; background: #433827; border-color: #79633e; }
  html[data-theme="dark"] body .cora-facts .is-danger { color: #ffd4cf; background: #442c2d; border-color: #90605d; }

  @media (max-width: 760px) {
    html[data-theme="dark"] body .dashboard-sidebar .dashboard-nav a:not(.is-active) { background: #20292f; border-color: #3b4851; }
  }
}
