/*
 * Maintain Hub dark theme — neutral charcoal palette
 *
 * This file is intentionally loaded last. Legacy feature styles still contain
 * light-mode literals, so the dark theme owns the final colour decision here.
 * Layout, media rendering and product behaviour remain in their feature files.
 */

html[data-theme="dark"] {
  color-scheme: dark;
  --ui-canvas: #151617;
  --ui-sidebar: #1a1b1d;
  --ui-surface: #202123;
  --ui-surface-subtle: #2b2c2e;
  --ui-surface-muted: #262729;
  --ui-input: #191a1c;
  --ui-text: #f1f1ee;
  --ui-text-muted: #b9bab6;
  --ui-text-tertiary: #a3a4a0;
  --ui-primary: #d7d7d2;
  --ui-primary-strong: #efefeb;
  --ui-primary-soft: #303133;
  --ui-action: #e1e1dc;
  --ui-action-hover: #f1f1ee;
  --ui-on-action: #202123;
  --ui-brand: #d1b27c;
  --ui-success: #89ad96;
  --ui-warning: #c7a363;
  --ui-danger: #bd7770;
  --ui-border: #363739;
  --ui-border-strong: #565759;
  --ui-shadow-focus: 0 0 0 3px rgb(225 225 220 / 24%);
  --blue: #d7d7d2;
  --blue-dark: #efefeb;
  --line: #363739;
  --soft: #2b2c2e;
  --text: #f1f1ee;
  --muted: #b9bab6;
  --primary-50: #262729;
  --primary-100: #303133;
  --primary-200: #3b3c3e;
  --primary-300: #565759;
  --primary-400: #a3a4a0;
  --primary-500: #d7d7d2;
  --primary-600: #d7d7d2;
  --primary-700: #deded9;
  --primary-800: #e7e7e2;
  --primary-900: #f1f1ee;
  --neutral-50: #25272a;
  --neutral-100: #292b2f;
  --neutral-200: #34373b;
  --neutral-300: #50535a;
  --neutral-400: #6f7278;
  --neutral-500: #85827c;
  --neutral-600: #b8b5ae;
  --neutral-700: #cbc8c1;
  --neutral-800: #dfdcd6;
  --neutral-900: #f3f1ed;
  --neutral-950: #faf8f4;
  scrollbar-color: #62646a #191b1e;
}

html[data-theme="dark"],
html[data-theme="dark"] body,
html[data-theme="dark"] .app-shell,
html[data-theme="dark"] .workspace,
html[data-theme="dark"] #main-content {
  color: var(--ui-text);
  background: var(--ui-canvas);
}

html[data-theme="dark"] ::selection {
  color: var(--ui-on-action);
  background: var(--ui-action);
}

html[data-theme="dark"] * {
  scrollbar-color: #62646a #191b1e;
}

html[data-theme="dark"] *::-webkit-scrollbar { width: 11px; height: 11px; }
html[data-theme="dark"] *::-webkit-scrollbar-track { background: #191b1e; }
html[data-theme="dark"] *::-webkit-scrollbar-thumb {
  border: 3px solid #191b1e;
  border-radius: 999px;
  background: #62646a;
}
html[data-theme="dark"] *::-webkit-scrollbar-thumb:hover { background: #7b7d82; }

/* Shell and navigation */
html[data-theme="dark"] :is(.sidebar, .sidebar .brand, .sidebar .secondary-nav, .sidebar .collapse-menu) {
  color: var(--ui-text);
  border-color: var(--ui-border);
  background: var(--ui-sidebar);
}

html[data-theme="dark"] .topbar {
  color: var(--ui-text);
  border-color: var(--ui-border);
  background: rgb(26 34 44 / 97%);
  box-shadow: 0 1px 0 rgb(255 255 255 / 3%);
}

html[data-theme="dark"] .app-footer {
  color: var(--ui-text-tertiary);
  border-color: var(--ui-border);
  background: var(--ui-canvas);
}

html[data-theme="dark"] .brand-logo {
  filter: brightness(0) invert(1);
  opacity: .9;
}

html[data-theme="dark"] .brand-wordmark .brand-orbit { color: var(--ui-brand); }
html[data-theme="dark"] .brand-wordmark .brand-orbit::after { border-top-color: var(--ui-brand); }
html[data-theme="dark"] .brand-wordmark .brand-n { color: var(--ui-brand); }
html[data-theme="dark"] .brand-wordmark .brand-it { color: #f3f1ed; }

html[data-theme="dark"][data-brand-mode="official"] .brand-lockup-official .brand-logo {
  filter: none;
  opacity: 1;
}

html[data-theme="dark"] .brand-logo-badge {
  border-color: #526172;
  box-shadow: 0 1px 0 rgb(255 255 255 / 5%);
}

html[data-theme="dark"] .sidebar .brand strong { color: var(--ui-text); }

html[data-theme="dark"] :is(.primary-nav a, .secondary-nav a, .sidebar-logout, .admin-nav-accordion > summary) {
  color: var(--ui-text-muted);
}

html[data-theme="dark"] :is(.primary-nav a, .secondary-nav a, .sidebar-logout) > span {
  color: var(--ui-text-tertiary);
}

html[data-theme="dark"] :is(.primary-nav a, .secondary-nav a, .sidebar-logout, .admin-nav-accordion > summary):hover {
  color: var(--ui-text);
  background: var(--ui-surface-subtle);
}

html[data-theme="dark"] :is(.primary-nav a[aria-current="page"], .admin-nav-links a[aria-current="page"]) {
  color: #f3f1ed;
  background: var(--ui-surface-subtle);
  box-shadow: inset 3px 0 var(--ui-primary);
}

html[data-theme="dark"] :is(.primary-nav a[aria-current="page"], .admin-nav-links a[aria-current="page"]) > span {
  color: #f3f1ed;
}

html[data-theme="dark"] .skip-link {
  color: var(--ui-text);
  border: 1px solid var(--ui-border-strong);
  background: var(--ui-surface-subtle);
}

html[data-theme="dark"] :where(.dashboard-scope, .dashboard-service-filter) {
  border-color: var(--ui-border);
  background: var(--ui-surface-subtle);
}

html[data-theme="dark"] :where(.dashboard-scope, .dashboard-service-filter) a {
  color: var(--ui-text-muted);
  border-color: var(--ui-border-strong);
  background: var(--ui-surface);
}

html[data-theme="dark"] :where(.dashboard-scope, .dashboard-service-filter) a:hover {
  color: var(--ui-text);
  border-color: var(--ui-border-strong);
  background: #302d29;
}

html[data-theme="dark"] :where(.dashboard-scope, .dashboard-service-filter) a.active,
html[data-theme="dark"] :where(.dashboard-scope, .dashboard-service-filter) a[aria-current="page"] {
  color: #f3f1ed;
  border-color: var(--ui-border-strong);
  background: var(--ui-surface-subtle);
}

html[data-theme="dark"] .site-tabs a {
  color: var(--ui-text-muted);
  background: transparent;
}

html[data-theme="dark"] .site-tabs a:hover {
  color: var(--ui-text);
  background: var(--ui-surface-subtle);
}

html[data-theme="dark"] .site-tabs a.active {
  color: var(--ui-primary-strong);
  background: var(--ui-surface-subtle);
  box-shadow: inset 0 -3px var(--ui-primary);
}

html[data-theme="dark"] .sidebar-user .avatar {
  color: #f3f1ed;
  background: var(--ui-surface-subtle);
}

/* Shared surfaces */
html[data-theme="dark"] :where(
  .ops-section, .ops-panel, .detail-card, .site-panel, .compact-panel,
  .portfolio-section, .global-search-focus, .global-search-results,
  .knowledge-list, .knowledge-summary, .knowledge-outline, .knowledge-document,
  .form-card, .prose-card, .quick-log-card, .admin-invite-card,
  .audit-filter-card, .bug-analysis-card, .bug-report-form,
  .account-metadata-card, .account-metadata-edit-card, .backup-settings,
  .external-backup-settings, .passkey-settings, .account-password-settings,
  .account-recovery-settings, .map-provider-settings, .sensitive-field-settings,
  .dashboard-today, .dashboard-recent-sites, .dashboard-recent-evidence,
  .dashboard-workspace-summary, .site-context-header, .site-tabs,
  .responsive-table, .settings-tabs, .site-directory-card, .ops-site-card,
  .portfolio-site-card, .directory-card, .work-case-card, .artifact-list,
  .search-result-group, .handover-board article, .delivery-card,
  .admin-tag-card, .admin-tag-card-body, .admin-tag-icon-editor,
  .knowledge-slash-menu, .knowledge-block-context, .knowledge-drawer,
  .library-preview-card, .site-library-file-section, .site-library-results,
  .site-contact-row, .site-contact-list, .site-contact-form,
  .secret-reveal-modal, .app-modal, .auth-card, .phone-preview,
  .process-stepper, .detail-facts > div, .artifact-metrics > div
) {
  color: var(--ui-text) !important;
  border-color: var(--ui-border) !important;
  background: var(--ui-surface) !important;
  box-shadow: none;
}

html[data-theme="dark"] :where(
  .ops-section, .ops-panel, .detail-card, .site-panel, .compact-panel,
  .portfolio-section, .form-card, .quick-log-card, .admin-invite-card,
  .bug-analysis-card, .account-metadata-card, .account-metadata-edit-card,
  .backup-settings, .external-backup-settings, .passkey-settings,
  .account-password-settings, .account-recovery-settings,
  .map-provider-settings, .sensitive-field-settings
) > header {
  color: var(--ui-text) !important;
  border-color: var(--ui-border) !important;
  background: var(--ui-surface) !important;
}

html[data-theme="dark"] :where(
  .content-list-toolbar, .dashboard-scope, .operations-command-row,
  .operations-search-row, .operations-account-tools, .site-directory-command,
  .library-command-bar, .knowledge-command-bar, .work-command-bar,
  .site-library-controls, .site-library-toolbar, .audit-filter-card,
  .dashboard-find-site, .field-quick-form > header, .site-side-summary,
  .detail-facts, .account-summary, .identity-account-summary,
  .worklog-filter, .quick-log-actions, .quick-log-attachments
) {
  color: var(--ui-text) !important;
  border-color: var(--ui-border) !important;
  background: var(--ui-surface-subtle) !important;
  box-shadow: none;
}

html[data-theme="dark"] :where(
  .field-quick-form, .field-upload-group, .field-quick-actions,
  .field-recent-records > section, .field-work-summary > section,
  .photo-map-workspace, .photo-map-site-rail, .photo-map-detail-panel,
  .bug-report-metrics > article, .admin-user-metrics > article,
  .portfolio-metrics > article, .ops-metrics > article,
  .artifact-metrics > article
) {
  color: var(--ui-text) !important;
  border-color: var(--ui-border) !important;
  background: var(--ui-surface) !important;
  box-shadow: none;
}

html[data-theme="dark"] :where(.field-upload-group, .field-quick-actions) {
  background: var(--ui-surface-subtle) !important;
}

html[data-theme="dark"] :where(.photo-map-site-rail > header, .photo-map-detail-panel > header, .photo-map-detail-panel > footer) {
  color: var(--ui-text);
  border-color: var(--ui-border);
  background: var(--ui-surface-subtle);
}

html[data-theme="dark"] :where(.photo-map-map-tools, .photo-map-provider-status, .photo-map-navigation > div) {
  color: var(--ui-text-muted) !important;
  border-color: var(--ui-border) !important;
  background: rgb(26 34 44 / 94%) !important;
  box-shadow: 0 8px 22px rgb(0 0 0 / 28%);
}

html[data-theme="dark"] .field-quick-guide > section {
  color: var(--ui-text) !important;
  border-color: var(--ui-border) !important;
  background: var(--ui-surface) !important;
}

html[data-theme="dark"] :where(.site-registration-guide, .passkey-secure-note) {
  color: var(--ui-text-muted) !important;
  border-color: var(--ui-border) !important;
  background: var(--ui-surface-subtle) !important;
}

html[data-theme="dark"] :where(
  .knowledge-filter-row > div, .knowledge-results,
  .knowledge-filter-row a, .knowledge-row-icon,
  .knowledge-row-tags span
) {
  color: var(--ui-text-muted) !important;
  border-color: var(--ui-border) !important;
  background: var(--ui-surface) !important;
}

html[data-theme="dark"] .knowledge-filter-row a:hover,
html[data-theme="dark"] .knowledge-filter-row a.active {
  color: #f3f1ed !important;
  border-color: var(--ui-border-strong) !important;
  background: #332e25 !important;
}

html[data-theme="dark"] .knowledge-row-tags span {
  color: #d8c49e !important;
  background: #332e25 !important;
}

html[data-theme="dark"] :is(.status-pill.info, .mini-status.info) {
  color: #d8c49e !important;
  background: #332e25 !important;
}

html[data-theme="dark"] :where(
  .sensitive-field-option, .sensitive-policy-summary,
  .storage-enable, .storage-policy-status
) {
  color: var(--ui-text) !important;
  border-color: var(--ui-border) !important;
  background: var(--ui-surface-subtle) !important;
}

html[data-theme="dark"] .sensitive-field-option em {
  color: var(--ui-text-muted) !important;
  background: #2b2d30 !important;
}

html[data-theme="dark"] .sensitive-field-option.always-protected em {
  color: #f7d98a !important;
  background: #443717 !important;
}

html[data-theme="dark"] .storage-policy-warning {
  color: #f7d98a !important;
  border-color: #806a31 !important;
  background: #332b1a !important;
}

html[data-theme="dark"] :where(.workspace-summary, .work-source-help > p, .library-storage-help > p) {
  color: var(--ui-text-muted) !important;
  border-color: var(--ui-border) !important;
  background: var(--ui-surface) !important;
}

html[data-theme="dark"] :where(.erp-boundary, .artifact-metrics) {
  color: var(--ui-text-muted) !important;
  border-color: var(--ui-border) !important;
  background: var(--ui-surface-subtle) !important;
}

html[data-theme="dark"] .artifact-list > header {
  color: var(--ui-text-muted) !important;
  border-color: var(--ui-border) !important;
  background: var(--ui-surface-subtle) !important;
}

html[data-theme="dark"] .file-kind {
  color: #d8c49e !important;
  background: #332e25 !important;
}

html[data-theme="dark"] :where(.delivery-gallery-card, .delivery-gallery-tag) {
  color: var(--ui-text) !important;
  border-color: var(--ui-border) !important;
  background-color: var(--ui-surface) !important;
}

html[data-theme="dark"] .delivery-gallery-card.no-photo {
  background: var(--ui-surface-subtle) !important;
}

html[data-theme="dark"] :where(.admin-tag-icon-picker, .admin-tag-advanced) {
  color: var(--ui-text) !important;
  border-color: var(--ui-border) !important;
  background: var(--ui-surface-subtle) !important;
}

html[data-theme="dark"] .admin-knowledge-tabs {
  border-color: var(--ui-border) !important;
  background: var(--ui-surface-subtle) !important;
}

html[data-theme="dark"] .admin-knowledge-tabs a {
  color: var(--ui-text-muted) !important;
  background: transparent !important;
}

html[data-theme="dark"] .admin-knowledge-tabs a.active {
  color: #f3f1ed !important;
  background: #332e25 !important;
  box-shadow: none !important;
}

html[data-theme="dark"] .obsidian-flow span {
  color: var(--ui-text-muted) !important;
  border-color: var(--ui-border) !important;
  background: var(--ui-surface-subtle) !important;
}

html[data-theme="dark"] .knowledge-row-icon {
  color: var(--ui-primary) !important;
  background: var(--ui-surface-subtle) !important;
}

html[data-theme="dark"] .site-overview-signals a {
  color: var(--ui-text) !important;
  border-color: var(--ui-border) !important;
  background: var(--ui-surface) !important;
}

html[data-theme="dark"] .site-overview-signals a:hover {
  background: var(--ui-surface-subtle) !important;
}

html[data-theme="dark"] .operations-export-menu > summary {
  color: var(--ui-text) !important;
  border-color: var(--ui-border-strong) !important;
  background: var(--ui-surface) !important;
}

html[data-theme="dark"] .photo-map-site-item {
  color: var(--ui-text-muted);
  border-color: var(--ui-border);
  background: transparent;
}

html[data-theme="dark"] .photo-map-site-item:hover,
html[data-theme="dark"] .photo-map-site-item.active {
  color: var(--ui-text);
  border-color: #75664e;
  background: #332e25;
}

html[data-theme="dark"] .photo-map-unlocated-link {
  color: #f7d98a;
  border-color: #806a31;
  background: #332b1a;
}

html[data-theme="dark"] :where(
  .dashboard-search-empty, .dashboard-find-site > label,
  .dashboard-find-site .dashboard-site-result, .dashboard-find-site .dashboard-site-results-more,
  .map-provider-option, .site-action-menu > div, .operations-export-menu > div,
  .sensitive-field-list, .knowledge-finder-item, .site-file-row,
  .worklog-record-details, .worklog-history > a, .artifact-version-row,
  .site-folder-group, .library-collection-card, .document-preview-section
) {
  color: var(--ui-text) !important;
  border-color: var(--ui-border) !important;
  background: var(--ui-surface) !important;
}

html[data-theme="dark"] :where(
  .dashboard-find-site .dashboard-site-result, .site-directory-card,
  .ops-site-card, .portfolio-site-card, .directory-card,
  .knowledge-list-row, .global-result-row, .site-file-row,
  .site-contact-row, .artifact-version-row, tbody tr
):hover {
  color: var(--ui-text);
  border-color: #5e6065;
  background: var(--ui-surface-subtle);
}

/* Typography and links */
html[data-theme="dark"] :where(
  h1, h2, h3, h4, legend, label, strong, dt, dd,
  .site-context-title, .site-detail-title, .screen-title,
  .empty-state strong, .detail-card h2, .detail-card h3,
  .site-file-row strong, .worklog-history strong,
  .site-contact-identity strong
) { color: var(--ui-text); }

html[data-theme="dark"] :where(
  p, small, time, figcaption, .form-help, .field-help,
  .empty-state, .muted, .site-contact-note, .site-contact-phone,
  .knowledge-finder-item span, .knowledge-info-section p,
  .topbar-page-identity p, .ops-page-header p, .site-detail-header p,
  .screen-header p, .page-header p
) { color: var(--ui-text-muted); }

html[data-theme="dark"] :where(
  a, .text-action, .site-panel-header a, .toolbar-result-count,
  .knowledge-outline a, .site-contact-phone a, .site-contact-actions a
) { color: var(--ui-primary); }

html[data-theme="dark"] :where(.eyebrow, .ops-page-header > div:first-child > span, .site-detail-header > div > span) {
  color: var(--ui-primary-strong);
}

/* Form controls and buttons */
html[data-theme="dark"] :where(
  input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
  select, textarea, .note-rich-editor
) {
  color: var(--ui-text) !important;
  border-color: var(--ui-border-strong) !important;
  background: var(--ui-input) !important;
  caret-color: var(--ui-primary);
}

html[data-theme="dark"] :where(input, textarea)::placeholder { color: var(--ui-text-tertiary); opacity: 1; }

html[data-theme="dark"] :where(input, select, textarea, .note-rich-editor):hover {
  border-color: #657487;
}

html[data-theme="dark"] :where(input, select, textarea, .note-rich-editor):focus {
  border-color: var(--ui-primary);
  box-shadow: var(--ui-shadow-focus);
}

html[data-theme="dark"] :where(input, select, textarea)[readonly],
html[data-theme="dark"] :where(input, select, textarea):disabled {
  color: var(--ui-text-muted) !important;
  border-color: var(--ui-border) !important;
  background: var(--ui-surface-muted) !important;
  cursor: not-allowed;
}

html[data-theme="dark"] :where(
  .outline-action, .ghost-action, .compact-action, .icon-action,
  .text-action, .site-actions button, .site-action-menu > summary,
  .mobile-menu, .mobile-secondary, .ghost-button, button.secondary,
  .knowledge-block-context button, .knowledge-slash-menu button
) {
  color: var(--ui-text) !important;
  border-color: var(--ui-border-strong) !important;
  background: var(--ui-surface) !important;
}

html[data-theme="dark"] :where(
  .outline-action, .ghost-action, .compact-action, .icon-action,
  .text-action, .site-actions button, .site-action-menu > summary,
  .mobile-secondary, .ghost-button, button.secondary
):hover {
  color: #f3f1ed;
  border-color: var(--ui-border-strong);
  background: #302d29;
}

html[data-theme="dark"] :where(.primary-action, button.primary, .button.primary) {
  color: var(--ui-on-action) !important;
  border-color: var(--ui-action) !important;
  background: var(--ui-action) !important;
  box-shadow: 0 2px 5px rgb(0 0 0 / 22%);
}

html[data-theme="dark"] :where(.primary-action, button.primary, .button.primary):hover {
  color: #fff;
  border-color: var(--ui-action-hover);
  background: var(--ui-action-hover);
}

html[data-theme="dark"] :where(button, .primary-action, .outline-action)[disabled],
html[data-theme="dark"] :where(.primary-action, .outline-action)[aria-disabled="true"] {
  color: var(--ui-text-tertiary) !important;
  border-color: var(--ui-border) !important;
  background: var(--ui-surface-muted) !important;
  box-shadow: none !important;
  cursor: not-allowed;
  opacity: .78;
}

html[data-theme="dark"] :where(button, input, select, textarea, a):focus-visible {
  outline: 0;
  box-shadow: var(--ui-shadow-focus);
}

/* Tables and list rows */
html[data-theme="dark"] table { color: var(--ui-text); background: var(--ui-surface); }
html[data-theme="dark"] th,
html[data-theme="dark"] .site-file-list-head {
  color: var(--ui-text-muted);
  border-color: var(--ui-border);
  background: var(--ui-surface-subtle);
}

html[data-theme="dark"] td,
html[data-theme="dark"] :where(.site-file-row, .site-contact-row, .worklog-record-details, .worklog-history > a) {
  color: var(--ui-text);
  border-color: var(--ui-border);
}

html[data-theme="dark"] .responsive-table {
  background: var(--ui-surface);
}

/* Status colours stay semantic and occupy small, deliberate areas. */
html[data-theme="dark"] :is(.status-pill.success, .mini-status.green, .readiness-score.success, .inventory-status.success) {
  color: #91e8ca !important;
  background: #173a32 !important;
}

html[data-theme="dark"] :is(.work-type.delivery, .work-type.inspection, .work-type.maintenance) {
  color: #91e8ca !important;
  background: #173a32 !important;
}

html[data-theme="dark"] :is(.status-pill.warning, .mini-status.warning, .readiness-score.warning, .inventory-status.warning) {
  color: #f7d98a !important;
  background: #443717 !important;
}

html[data-theme="dark"] :is(.status-pill.danger, .mini-status.red, .readiness-score.danger, .inventory-status.danger) {
  color: #e6a0a5 !important;
  background: #39262a !important;
}

html[data-theme="dark"] .readiness-score.neutral {
  color: #b8c2cd !important;
  background: #292b2f !important;
}

html[data-theme="dark"] :is(.status-pill.neutral, .mini-status.neutral, .inventory-status.neutral) {
  color: #c9c6bf !important;
  background: #2b2d30 !important;
}

html[data-theme="dark"] .service-type-badge.one-off { color: #f7d98a; background: #443717; }
html[data-theme="dark"] .service-type-badge.per-call { color: #d4b7ad; background: #342f2b; }
html[data-theme="dark"] .service-type-badge.maintenance { color: #d8c49e; background: #332e25; }

html[data-theme="dark"] :where(.security-notice, .archive-warning, .bug-analysis-waiting, .overview-incident-pending) {
  color: #f7d98a;
  border-color: #806a31;
  background: #332b1a;
}

html[data-theme="dark"] :where(.security-notice, .archive-warning, .bug-analysis-waiting, .overview-incident-pending) :where(strong, p, small, span) {
  color: inherit;
}

html[data-theme="dark"] :where(.global-message:not(:empty), .invitation-issued.mail-sent, .overview-incident-pending.is-clear) {
  color: #91e8ca;
  border-color: #2f6f5d;
  background: #17332d;
}

html[data-theme="dark"] :where(.global-message[data-state="error"], .signup-invitation-summary.invalid) {
  color: #e2aaae;
  border-color: #84404a;
  background: #3a2026;
}

html[data-theme="dark"] :where(.worklog-delete-action, .worklog-purge-action, .danger-action) {
  color: #e6a0a5;
  border-color: #674148;
  background: #342327;
}

html[data-theme="dark"] :where(.worklog-delete-action, .worklog-purge-action, .danger-action):hover {
  color: #f0bec2;
  border-color: #845159;
  background: #432a2f;
}

html[data-theme="dark"] .worklog-purge-warning {
  color: #f0bec2;
  border-color: #674148;
  background: #2c2024;
}

html[data-theme="dark"] .worklog-purge-warning p { color: #e6a0a5; }

html[data-theme="dark"] .worklog-linked-lock { color: #d6b979; }

html[data-theme="dark"] :where(.worklog-photo-download, .worklog-file-download, .site-favorite-button) {
  color: var(--ui-text-muted);
}

html[data-theme="dark"] .worklog-photo-download {
  border-color: var(--ui-border-strong);
  background: var(--ui-surface-subtle);
}

html[data-theme="dark"] .worklog-photo-download:hover {
  color: var(--ui-text);
  border-color: var(--ui-border-strong);
  background: #292b2f;
}

html[data-theme="dark"] :where(.worklog-more-trigger, .worklog-more-popover) {
  color: var(--ui-text);
  border-color: var(--ui-border-strong);
  background: var(--ui-surface);
}

html[data-theme="dark"] .worklog-more-menu[open] > .worklog-more-trigger {
  color: var(--ui-primary-strong);
  border-color: var(--ui-border-strong);
  background: var(--ui-surface-subtle);
}

html[data-theme="dark"] .site-favorite-button.favorite-active { color: #e7c56f; }

/* Page-specific omissions from legacy light styles */
html[data-theme="dark"] :where(.admin-tag-card-body, .admin-tag-icon-editor, .admin-tag-form, .site-contact-list, .site-contact-form) {
  color: var(--ui-text);
  background: var(--ui-surface);
}

html[data-theme="dark"] :where(.admin-tag-card-header, .site-folder-group > header, .document-preview-section > header, .archive-preview-summary) {
  color: var(--ui-text);
  border-color: var(--ui-border);
  background: var(--ui-surface-subtle);
}

html[data-theme="dark"] :where(.knowledge-callout-block, .library-principle) {
  color: var(--ui-text);
  border-color: #806a31;
  background: #332b1a;
}

html[data-theme="dark"] :where(.upload-dropzone, .field-capture-dropzone, .bug-capture-dropzone, .inventory-import-start) {
  color: var(--ui-text-muted);
  border-color: var(--ui-border-strong);
  background: #211f1c;
}

/* Import-only surfaces previously retained their fixed light backgrounds. */
html[data-theme="dark"] .secure-import-warning {
  color: var(--ui-text-muted);
  border-color: var(--ui-border-strong);
  background: var(--ui-surface-subtle);
}

html[data-theme="dark"] .secure-import-warning strong {
  color: var(--ui-text);
}

html[data-theme="dark"] .secure-import-warning span {
  color: var(--ui-text-muted);
}

html[data-theme="dark"] .inventory-import-guide {
  color: var(--ui-text);
  background: var(--ui-surface-muted);
}

html[data-theme="dark"] .inventory-import-guide :is(li, li span) {
  color: var(--ui-text-muted);
}

html[data-theme="dark"] .inventory-import-guide li b {
  color: var(--ui-text);
  background: var(--ui-border);
}

html[data-theme="dark"] .inventory-upload-form [data-file-dropzone] {
  color: var(--ui-text);
  border-color: var(--ui-border-strong);
  background: var(--ui-surface-subtle);
}

html[data-theme="dark"] .inventory-upload-form [data-file-dropzone] :is(span, small) {
  color: var(--ui-text-muted);
}

html[data-theme="dark"] .inventory-upload-form [data-file-dropzone]:is(.dragging, :focus-within) {
  border-color: var(--ui-primary);
  background: var(--ui-surface-muted);
  box-shadow: var(--ui-shadow-focus);
}

html[data-theme="dark"] .inventory-upload-form input[type="file"]::file-selector-button {
  color: var(--ui-text);
  border-color: var(--ui-border-strong);
  background: var(--ui-surface-muted);
}

/* Shared form rows remain neutral while inputs own the visible control frame. */
html[data-theme="dark"] .secure-operations-form [data-file-dropzone] {
  border: 0;
  background: transparent;
}
html[data-theme="dark"] .site-library-selection-tools .danger-action {
  background: var(--ui-surface);
  color: var(--ui-text) !important;
  border-color: var(--ui-border);
}

html[data-theme="dark"] :where(.photo-map-detail-panel, .photo-map-detail-panel > footer) {
  color: var(--ui-text);
  border-color: var(--ui-border);
  background: var(--ui-surface);
}

html[data-theme="dark"] :where(.app-modal-body, .secret-reveal-modal, .auth-screen) {
  color: var(--ui-text);
  background: var(--ui-surface);
}

html[data-theme="dark"] .app-modal-backdrop,
html[data-theme="dark"] .secret-reveal-modal-backdrop,
html[data-theme="dark"] .knowledge-overlay-backdrop {
  background: rgb(4 8 13 / 72%);
}

/* Keep photographs, maps and document pages visually faithful. */
html[data-theme="dark"] :where(.file-preview iframe, .document-preview-frame, .pdf-preview, .office-preview) {
  border-color: var(--ui-border);
  background: #e9edf2;
}

html[data-theme="dark"] :where(.photo-card img, .delivery-gallery img, .artifact-preview img, .note-editor-inline-image img) {
  color-scheme: light;
}

html[data-theme="dark"] :where(.leaflet-control a, .leaflet-popup-content-wrapper, .leaflet-popup-tip) {
  color: #172033;
  background: #f8fafc;
}

@media (prefers-contrast: more) {
  html[data-theme="dark"] {
    --ui-text-muted: #d0cdc6;
    --ui-text-tertiary: #aaa7a0;
    --ui-border: #55585d;
    --ui-border-strong: #707379;
  }
}

/* 2026-10 neutral UI refinement.  Routes and feature markup stay unchanged;
   this layer only normalizes hierarchy, density and scroll ownership. */
html[data-theme="dark"] body { font-size: 14px; line-height: 1.55; }
html[data-theme="dark"] .topbar { background: rgb(32 34 37 / 97%); }

html[data-theme="dark"] :is(.primary-nav a[aria-current="page"], .admin-nav-links a[aria-current="page"]) {
  color: var(--ui-text);
  background: var(--ui-surface-subtle);
  box-shadow: inset 3px 0 var(--ui-primary);
}
html[data-theme="dark"] :is(.primary-nav a[aria-current="page"], .admin-nav-links a[aria-current="page"]) > span { color: var(--ui-primary); }

html[data-theme="dark"] :where(.primary-action, button.primary-action) {
  color: var(--ui-on-action);
  border-color: var(--ui-action);
  background: var(--ui-primary);
  box-shadow: none;
}
html[data-theme="dark"] :where(.primary-action, button.primary-action):hover {
  color: var(--ui-on-action);
  border-color: var(--ui-primary-strong);
  background: var(--ui-primary-strong);
}
html[data-theme="dark"] :where(.outline-action, .icon-action, .text-action) {
  color: var(--ui-text);
  border-color: var(--ui-border-strong);
  background: var(--ui-surface);
}
html[data-theme="dark"] :where(.outline-action, .icon-action, .text-action):hover {
  color: var(--ui-text);
  border-color: var(--ui-border-strong);
  background: var(--ui-surface-subtle);
}

html[data-theme="dark"] :where(input, select, textarea) {
  min-height: 40px;
  color: var(--ui-text);
  border-color: var(--ui-border-strong);
  background: var(--ui-input);
}
html[data-theme="dark"] :where(input, select, textarea):focus {
  border-color: var(--ui-primary);
  box-shadow: var(--ui-shadow-focus);
  outline: 0;
}
html[data-theme="dark"] :where(input, textarea)::placeholder { color: var(--ui-text-tertiary); opacity: 1; }

html[data-theme="dark"] :where(
  .detail-card, .site-panel, .form-card, .ops-section, .ops-panel,
  .dashboard-find-site, .dashboard-today, .dashboard-recent-sites,
  .dashboard-recent-evidence, .site-directory-card, .quick-log-card,
  .worklog-history-card, .knowledge-list-main, .knowledge-summary,
  .global-search-results, .global-search-summary, .field-quick-form,
  .field-quick-guide > section, .settings-tabs, .site-contact-list,
  .site-contact-form, .site-library-file-section, .site-library-results
) {
  border-color: var(--ui-border) !important;
  border-radius: var(--ui-card-radius);
  background: var(--ui-surface) !important;
  box-shadow: none !important;
}

html[data-theme="dark"] :where(
  .detail-card, .site-panel, .form-card, .ops-section, .ops-panel,
  .dashboard-today, .dashboard-recent-sites, .dashboard-recent-evidence,
  .quick-log-card, .worklog-history-card, .field-quick-form,
  .field-quick-guide > section, .site-library-file-section
) > header {
  min-height: 54px;
  box-sizing: border-box;
  padding: 12px 16px;
  border-color: var(--ui-border) !important;
  background: var(--ui-surface) !important;
}

html[data-theme="dark"] :where(.ops-page-header h1, .site-context-title h1) {
  margin: 0;
  color: var(--ui-text);
  font-size: 24px;
  font-weight: 750;
  line-height: 34px;
  letter-spacing: -.025em;
}
html[data-theme="dark"] :where(.detail-card h2, .site-panel h2, .ops-section h2, .ops-panel h2) {
  color: var(--ui-text);
  font-size: 16px;
  font-weight: 740;
  line-height: 24px;
  letter-spacing: -.015em;
}
html[data-theme="dark"] :where(.detail-card h3, .site-panel h3, .ops-section h3) {
  color: var(--ui-text);
  font-size: 15px;
  line-height: 24px;
}
html[data-theme="dark"] :where(.ops-page-header p, .detail-card header p, .site-panel header p) {
  color: var(--ui-text-muted);
  font-size: 13px;
  line-height: 20px;
}

html[data-theme="dark"] :where(.primary-action, .outline-action) {
  min-height: 40px;
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 20px;
}
html[data-theme="dark"] :where(.icon-action, .site-favorite-button) {
  width: 40px;
  min-width: 40px;
  height: 40px;
  min-height: 40px;
  box-sizing: border-box;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border-radius: 8px;
}
html[data-theme="dark"] .site-favorite-button > span { width: 24px; height: 24px; display: grid; place-items: center; }
html[data-theme="dark"] .site-favorite-button .ui-icon { width: 24px; height: 24px; stroke-width: 1.8; }
html[data-theme="dark"] .site-favorite-button.favorite-active {
  color: var(--ui-primary);
  border-color: var(--ui-border-strong);
  background: var(--ui-surface-subtle);
}

html[data-theme="dark"] :is(.site-tabs, .settings-tabs, .knowledge-category-tabs, .global-search-tabs) a.active {
  color: var(--ui-primary-strong);
  border-color: var(--ui-primary);
  background: var(--ui-surface-subtle);
  box-shadow: inset 0 -2px var(--ui-primary);
}

html[data-theme="dark"] :is(.status-pill.info, .work-type.maintenance_inspection, .work-type.maintenance) {
  color: var(--ui-text-muted);
  border-color: var(--ui-border);
  background: var(--ui-surface-subtle);
}
html[data-theme="dark"] :is(.status-pill.success, .mini-status.green) { color: #b8d0c0; border-color: #466151; background: #26362d; }
html[data-theme="dark"] :is(.status-pill.warning, .mini-status.yellow) { color: #dbc28f; border-color: #665536; background: #392f20; }
html[data-theme="dark"] :is(.status-pill.danger, .mini-status.red) { color: #d9aaa5; border-color: #704641; background: #3c2726; }
html[data-theme="dark"] .overview-briefing-grid > div > strong.needs-attention { color: #d1aa68; }
html[data-theme="dark"] .overview-briefing-grid > div > strong.is-ready { color: #9fc3aa; }

/* Long lists own their scroll.  The page itself remains available on short
   viewports and at browser zoom levels. */
@media (min-width: 1025px) and (min-height: 761px) {
  html[data-theme="dark"] :where(
    .worklog-history-card .worklog-history, .site-library-results,
    .site-library-file-list, .knowledge-results, .operations-account-table,
    .inspection-files-card > :last-child
  ) {
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
  }
  html[data-theme="dark"] :where(.field-quick-layout, .knowledge-list-layout, .global-search-layout, .site-contact-layout) { align-items: stretch; }
  html[data-theme="dark"] :where(.field-quick-layout, .knowledge-list-layout, .global-search-layout, .site-contact-layout) > * { min-height: 0; }
}

@media (max-width: 760px) {
  html[data-theme="dark"] :where(.ops-page-header h1, .site-context-title h1) { font-size: 24px; line-height: 34px; }
  html[data-theme="dark"] :where(.detail-card, .site-panel, .form-card, .ops-section, .ops-panel) > header { min-height: 60px; padding: 14px 16px; }
  html[data-theme="dark"] :where(.primary-action, .outline-action, .icon-action, .site-favorite-button) { min-height: 44px; }
}

/* Operations tools use the same quiet surface as the content they control. */
html[data-theme="dark"] .site-detail-page .operations-command-row,
html[data-theme="dark"] .site-detail-page .operations-search-row { background: transparent !important; }
html[data-theme="dark"] .site-detail-page .operations-account-tools { background: var(--ui-surface) !important; }
html[data-theme="dark"] .site-detail-page .operations-subtabs a.active {
  color: var(--ui-text);
  border-color: var(--ui-primary);
  background: transparent;
  box-shadow: inset 0 -2px var(--ui-primary);
}

/* This custom dashboard link is also a button: don't inherit the link color
   from --primary-600, which was identical to its background in dark mode. */
html[data-theme="dark"] .dashboard-all-work {
  color: var(--ui-text) !important;
  background: var(--ui-surface-subtle);
  border: 1px solid var(--ui-border-strong);
}
html[data-theme="dark"] .dashboard-all-work:hover {
  color: var(--ui-text) !important;
  background: var(--ui-surface-muted);
}
html[data-theme="dark"] .dashboard-all-work:focus-visible {
  box-shadow: var(--ui-shadow-focus);
}

/* Photo folders are UI surfaces; keep the photographs themselves unchanged. */
html[data-theme="dark"] :is(
  .photo-map-albums, .photo-map-date-folder, .photo-map-date-items,
  .photo-map-date-folder-row, .photo-map-album
) {
  color: var(--ui-text) !important;
  background: var(--ui-surface);
  border-color: var(--ui-border);
}
html[data-theme="dark"] :is(
  .photo-map-date-folder-row:hover,
  .photo-map-date-folder.expanded .photo-map-date-folder-row,
  .photo-map-album:hover
) { background: var(--ui-surface-subtle); }
html[data-theme="dark"] :is(
  .photo-map-date-copy strong, .photo-map-album-copy strong,
  .photo-map-date-toggle, .photo-map-albums-title strong
) { color: var(--ui-text) !important; }
html[data-theme="dark"] :is(
  .photo-map-date-copy small, .photo-map-album-copy small,
  .photo-map-albums-title span, .photo-map-contact dt,
  .photo-map-facts dt, .photo-map-detail-panel > header p
) { color: var(--ui-text-muted) !important; }
html[data-theme="dark"] :is(.photo-map-albums-title, .photo-map-contact > div) {
  border-color: var(--ui-border);
}
html[data-theme="dark"] :is(.photo-map-date-previews, .photo-map-album-preview) {
  background: var(--ui-surface-muted);
  border-color: var(--ui-border);
}
html[data-theme="dark"] .photo-map-date-previews img { border-color: var(--ui-border); }
html[data-theme="dark"] .photo-map-album-placeholder { color: var(--ui-text-muted); }
html[data-theme="dark"] .photo-map-album-preview > b {
  color: var(--ui-text);
  background: rgb(25 26 28 / 94%);
}
html[data-theme="dark"] .photo-map-navigation > summary {
  color: var(--ui-text);
  background: var(--ui-surface-subtle);
  border: 1px solid var(--ui-border-strong);
}
html[data-theme="dark"] .photo-map-navigation > summary:hover {
  background: var(--ui-surface-muted);
}
html[data-theme="dark"] .photo-map-detail-actions > a {
  min-width: 0;
  padding: 0 8px;
}
html[data-theme="dark"] .photo-map-navigation > div {
  color: var(--ui-text) !important;
  background: var(--ui-surface) !important;
  border-color: var(--ui-border-strong) !important;
  box-shadow: 0 10px 28px rgb(0 0 0 / 24%);
}
html[data-theme="dark"] .photo-map-navigation > div a {
  color: var(--ui-text) !important;
  border-color: var(--ui-border);
}
html[data-theme="dark"] .photo-map-navigation > div a:hover {
  background: var(--ui-surface-subtle);
}
html[data-theme="dark"] :is(
  .photo-map-date-folder-row, .photo-map-album,
  .photo-map-navigation > summary, .photo-map-navigation > div a
):focus-visible { box-shadow: var(--ui-shadow-focus); }

/* Field capture: inherited primary colours are light in the neutral theme,
   so badges and selected controls need the matching dark foreground. */
html[data-theme="dark"] .field-new-site-fields {
  color: var(--ui-text);
  border-color: var(--ui-border);
  background: var(--ui-surface-muted);
}
html[data-theme="dark"] :is(.field-step-number, .field-capture-dropzone b) {
  color: var(--ui-on-action);
  background: var(--ui-action);
}
html[data-theme="dark"] :is(
  .field-quick-step > div:last-child > p, .field-quick-form .form-help,
  .field-quick-form label small, .field-upload-count,
  .field-gps-status, .field-selected-previews figcaption
) { color: var(--ui-text-muted) !important; }
html[data-theme="dark"] .field-readonly-value {
  color: var(--ui-text-muted);
  border-color: var(--ui-border);
  background: var(--ui-surface-muted);
}
html[data-theme="dark"] .field-capture-dropzone {
  color: var(--ui-text);
  border-color: var(--ui-border-strong);
  background: var(--ui-surface-muted);
}
html[data-theme="dark"] .field-capture-dropzone.dragging {
  border-color: var(--ui-primary);
  background: var(--ui-surface-subtle);
  box-shadow: var(--ui-shadow-focus);
}
html[data-theme="dark"] .field-gps-row button {
  color: var(--ui-text);
  border-color: var(--ui-border-strong);
  background: var(--ui-surface-subtle);
}
html[data-theme="dark"] .field-gps-row button.is-active {
  color: var(--ui-on-action);
  border-color: var(--ui-action);
  background: var(--ui-action);
  box-shadow: none;
}
html[data-theme="dark"] .field-gps-row button span { color: inherit; }
html[data-theme="dark"] .field-gps-row button:focus-visible { box-shadow: var(--ui-shadow-focus); }
html[data-theme="dark"] .field-selected-previews .field-selected-file b {
  color: var(--ui-text);
  border-color: var(--ui-border-strong);
  background: var(--ui-surface-subtle);
}

/* The same light literal was used for authentication-method selection. */
html[data-theme="dark"] .auth-form .auth-choice-card {
  color: var(--ui-text);
  border-color: var(--ui-border);
  background: var(--ui-surface);
}
html[data-theme="dark"] .auth-form .auth-choice-card:has(input:checked) {
  border-color: var(--ui-primary);
  background: var(--ui-surface-subtle);
  box-shadow: inset 3px 0 var(--ui-primary);
}
html[data-theme="dark"] .auth-form .auth-choice-card:focus-within {
  outline: 2px solid var(--ui-primary);
  outline-offset: 2px;
}
html[data-theme="dark"] .auth-note {
  color: var(--ui-text-muted);
  border-color: var(--ui-border);
  background: var(--ui-surface-subtle);
}
html[data-theme="dark"] .auth-result-message {
  color: #b8d0c0 !important;
  border-color: #466151;
  background: #26362d;
}
html[data-theme="dark"] .auth-result-message.auth-result-error {
  color: #d9aaa5 !important;
  border-color: #704641;
  background: #3c2726;
}

html[data-theme="dark"] .artifact-lifecycle-modal [data-artifact-action-error] {
  color: #d9aaa5;
}

html[data-theme="dark"] .worklog-more-popover .worklog-destructive-menu {
  color: #d9aaa5;
}

html[data-theme="dark"] :is(.artifact-lifecycle-modal, .artifact-trash-row) .danger-action {
  /* Legacy requirements-ui.css pins danger text/borders with !important. */
  color: #ead0cd !important;
  background: #342827;
  border-color: #77534f !important;
}

html[data-theme="dark"] :is(.artifact-lifecycle-modal, .artifact-trash-row) .danger-action:hover {
  color: #f4e4e2 !important;
  background: #42302e;
}
[data-theme="dark"] .operations-editor-panel [data-operation-error],
[data-theme="dark"] .operations-editor-panel [data-field-error] { color: #edaba3; }
