/**
 * Fixxr Design System
 * Central theme tokens and shared foundations for the portal app.
 * Load before app.css; tenant overrides via render_brand_styles() come last.
 */

/* ---------- Typography (self-hosted for CSP) ---------- */
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("../fonts/inter/inter-latin-400-normal.woff2") format("woff2");
}

@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("../fonts/inter/inter-latin-500-normal.woff2") format("woff2");
}

@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("../fonts/inter/inter-latin-600-normal.woff2") format("woff2");
}

@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("../fonts/inter/inter-latin-700-normal.woff2") format("woff2");
}

@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 800;
  font-display: swap;
  src: url("../fonts/inter/inter-latin-800-normal.woff2") format("woff2");
}

/* ---------- Design tokens ---------- */
:root {
  /* Brand palette */
  --navy: #0a1528;
  --navy-700: #0f1e36;
  --navy-600: #16294a;

  /* Sidebar */
  --sidebar-bg: #152238;
  --sidebar-accent: #5b9fd4;
  --sidebar-accent-muted: #4a8bc4;
  --sidebar-text: #e8f0f8;
  --sidebar-text-muted: #8fa8c4;
  --sidebar-text-sub: #b8c9db;
  --sidebar-border: rgba(255, 255, 255, .14);
  --sidebar-hover-bg: rgba(255, 255, 255, .1);
  --sidebar-active-bg: rgba(91, 159, 212, .28);

  /* Primary */
  --primary: #3d74a5;
  --primary-600: #2f6290;

  /* Accent */
  --accent: #0a8578;
  --accent-dark: #066b60;
  --accent-600: #0f766e;
  --accent-soft: rgba(10, 133, 120, .12);
  --accent-focus-ring: rgba(10, 133, 120, .28);

  /* Semantic */
  --warning: #c2410c;
  --danger: #b91c1c;
  --success: #047857;

  /* Surfaces */
  --bg: #e8ecf1;
  --bg-subtle: #dfe6ed;
  --card: #ffffff;
  --topbar-bg: #ffffff;
  --surface-hover: #e3e9f0;
  --surface-muted: #eef1f6;
  --input-bg: #f0f4f8;
  --input-bg-readonly: #e4eaf1;
  --input-bg-focus: #ffffff;
  --modal-header-bg: #eef1f6;
  --pill-bg: #eef4fb;
  --pill-border: #c8d9ec;
  --success-soft: rgba(4, 120, 87, .12);
  --success-soft-border: rgba(4, 120, 87, .22);
  --success-on-soft: #065f46;
  --info-soft: rgba(61, 116, 165, .12);
  --danger-soft: rgba(185, 28, 28, .12);
  --warning-soft: rgba(194, 65, 12, .12);
  --purple-soft: rgba(91, 33, 182, .12);
  --neutral-soft: rgba(71, 85, 105, .1);
  --modal-backdrop: rgba(10, 18, 32, .45);
  --purple: #5b21b6;

  /* Dashboard cards */
  --dashboard-card-min: 403px;
  --dashboard-card-radius: 8px;
  --card-footer-bg: #f0f4f8;
  --card-hover-bg: #fafbfd;
  --dashboard-panel-bg: #ffffff;

  /* Text */
  --text: #0b1220;
  --text-secondary: #1e293b;
  --muted: #475569;

  /* Borders */
  --line: #b8c4d0;
  --border: var(--line);
  --border-strong: #94a3b8;

  /* Tables */
  --table-header-bg: #eef1f6;
  --table-header-text: #334155;
  --table-row-hover: #e9edf2;

  /* Calendar */
  --calendar-header-bg: #f8fafc;
  --calendar-today-bg: #eff6ff;
  --calendar-today-col-bg: rgba(239, 246, 255, .35);
  --calendar-grid-line: rgba(184, 196, 208, .8);

  /* Layout */
  --sidebar-w: 256px;
  --topbar-h: 56px;

  /* Radius — sharper for desktop utility feel */
  --radius: 6px;
  --radius-sm: 4px;

  /* Shadows — crisper, more defined elevation */
  --shadow-sm: 0 1px 2px rgba(10, 18, 32, .1), 0 0 0 1px rgba(10, 18, 32, .06);
  --shadow: 0 2px 6px rgba(10, 18, 32, .14), 0 0 0 1px rgba(10, 18, 32, .08);
  --shadow-lg: 0 6px 20px rgba(10, 18, 32, .18), 0 0 0 1px rgba(10, 18, 32, .1);

  /* Typography */
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  /* Auth */
  --auth-space-xs: .75rem;
  --auth-space-sm: 1.25rem;
  --auth-space-md: 2rem;
  --auth-space-lg: 2.75rem;
  --auth-space-xl: 3.5rem;
  --auth-radius: 12px;
  --auth-input-h: 3rem;
  --auth-splash-bg: url('../images/bg_splash.jpg');
  --auth-splash-bg-shaded: linear-gradient(
    rgba(10, 21, 40, 0.62),
    rgba(10, 21, 40, 0.78)
  ), var(--auth-splash-bg);

  color-scheme: light;
}

@media (min-width: 1024px) {
  :root {
    --radius: 4px;
    --radius-sm: 3px;
    --topbar-h: 52px;
  }
}

/* ---------- Shared reset ---------- */
*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
}

/* ---------- Dark theme (Windows 11–inspired) ---------- */
[data-theme="dark"] {
  --navy: #f0f0f0;
  --navy-700: #e0e0e0;
  --navy-600: #d0d0d0;

  --sidebar-bg: #1a1a1a;
  --sidebar-accent: #60cdff;
  --sidebar-accent-muted: #4eb8e8;
  --sidebar-text: #f3f3f3;
  --sidebar-text-muted: #9a9a9a;
  --sidebar-text-sub: #b0b0b0;
  --sidebar-border: rgba(255, 255, 255, .08);
  --sidebar-hover-bg: rgba(255, 255, 255, .06);
  --sidebar-active-bg: rgba(96, 205, 255, .16);

  --primary: #60cdff;
  --primary-600: #4ab8e8;

  --accent: #4dd4c4;
  --accent-dark: #3bc4b4;
  --accent-600: #2eb8a8;
  --accent-soft: rgba(77, 212, 196, .14);
  --accent-focus-ring: rgba(77, 212, 196, .28);

  --warning: #f59e0b;
  --danger: #f87171;
  --success: #34d399;

  --bg: #1c1c1c;
  --bg-subtle: #242424;
  --card: #2c2c2c;
  --topbar-bg: #2c2c2c;
  --surface-hover: #383838;
  --surface-muted: #323232;
  --input-bg: #2a2a2a;
  --input-bg-readonly: #242424;
  --input-bg-focus: #323232;
  --modal-header-bg: #242424;
  --pill-bg: #353535;
  --pill-border: #505050;
  --success-soft: rgba(52, 211, 153, .18);
  --success-soft-border: rgba(52, 211, 153, .28);
  --success-on-soft: #86efac;
  --info-soft: rgba(96, 205, 255, .18);
  --danger-soft: rgba(248, 113, 113, .18);
  --warning-soft: rgba(245, 158, 11, .18);
  --purple-soft: rgba(167, 139, 250, .18);
  --neutral-soft: rgba(166, 166, 166, .14);
  --modal-backdrop: rgba(0, 0, 0, .55);
  --purple: #c4b5fd;

  --dashboard-card-min: 403px;
  --dashboard-card-radius: 8px;
  --card-footer-bg: #242424;
  --card-hover-bg: #323232;
  --dashboard-panel-bg: #2c2c2c;

  --text: #ffffff;
  --text-secondary: #e0e0e0;
  --muted: #a6a6a6;

  --line: #3d3d3d;
  --border-strong: #505050;

  --table-header-bg: #323232;
  --table-header-text: #d4d4d4;
  --table-row-hover: #353535;

  --calendar-header-bg: #2f2f2f;
  --calendar-today-bg: #343b42;
  --calendar-today-col-bg: rgba(96, 205, 255, .06);
  --calendar-grid-line: rgba(255, 255, 255, .12);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .35), 0 0 0 1px rgba(255, 255, 255, .04);
  --shadow: 0 2px 8px rgba(0, 0, 0, .4), 0 0 0 1px rgba(255, 255, 255, .06);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, .5), 0 0 0 1px rgba(255, 255, 255, .08);

  color-scheme: dark;
}

[data-theme="dark"] .sidebar {
  border-right-color: rgba(0, 0, 0, .35);
  box-shadow: 2px 0 8px rgba(0, 0, 0, .35);
}

[data-theme="dark"] .topbar {
  box-shadow: 0 1px 0 rgba(0, 0, 0, .35);
}

[data-theme="dark"] .tenant-picker-card,
[data-theme="dark"] .join-tenant-card,
[data-theme="dark"] .app-modal-panel,
[data-theme="dark"] .confirm-modal-panel,
[data-theme="dark"] .profile-dropdown,
[data-theme="dark"] .data-table tbody tr {
  background: var(--card);
}

[data-theme="dark"] .tenant-picker-card-avatar {
  background: var(--surface-muted);
  border-color: var(--line);
  color: var(--text);
}

[data-theme="dark"] .alert-info,
[data-theme="dark"] .xero-banner,
[data-theme="dark"] .info-banner {
  background: rgba(96, 205, 255, .12);
  border-color: rgba(96, 205, 255, .28);
  color: #b8e6ff;
}

[data-theme="dark"] .alert-warning,
[data-theme="dark"] .warning-banner {
  background: rgba(245, 158, 11, .12);
  border-color: rgba(245, 158, 11, .28);
  color: #fcd34d;
}

[data-theme="dark"] .alert-success,
[data-theme="dark"] .success-banner {
  background: rgba(52, 211, 153, .12);
  border-color: rgba(52, 211, 153, .28);
  color: #86efac;
}

[data-theme="dark"] .notifications .notification {
  background: var(--card);
  border-color: var(--border-strong);
}

[data-theme="dark"] .app-loading-overlay {
  background: rgba(0, 0, 0, .55);
}

[data-theme="dark"] .notification-success {
  background: rgba(52, 211, 153, .14);
  color: #86efac;
  border-color: rgba(52, 211, 153, .28);
}

[data-theme="dark"] .notification-error {
  background: rgba(248, 113, 113, .14);
  color: #fca5a5;
  border-color: rgba(248, 113, 113, .28);
}

[data-theme="dark"] .notification-warning {
  background: rgba(245, 158, 11, .14);
  color: #fcd34d;
  border-color: rgba(245, 158, 11, .28);
}

[data-theme="dark"] .tenant-license-group,
[data-theme="dark"] .tenant-module-card,
[data-theme="dark"] .notification-settings-card {
  background: var(--card);
}

[data-theme="dark"] .sidebar-backdrop {
  background: rgba(0, 0, 0, .55);
}

/* Form controls — override hardcoded light field styles */
[data-theme="dark"] input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="file"]):not([type="hidden"]):not([type="submit"]):not([type="button"]):not([type="reset"]):not([type="image"]),
[data-theme="dark"] select,
[data-theme="dark"] textarea {
  background-color: var(--input-bg) !important;
  color: var(--text) !important;
  border-color: var(--border-strong);
  color-scheme: dark;
}

[data-theme="dark"] input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="file"]):not([type="hidden"]):not([type="submit"]):not([type="button"]):not([type="reset"]):not([type="image"]):hover,
[data-theme="dark"] select:hover,
[data-theme="dark"] textarea:hover {
  background-color: var(--surface-muted) !important;
}

[data-theme="dark"] input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="file"]):not([type="hidden"]):not([type="submit"]):not([type="button"]):not([type="reset"]):not([type="image"]):focus,
[data-theme="dark"] select:focus,
[data-theme="dark"] textarea:focus {
  background-color: var(--input-bg-focus) !important;
  color: var(--text) !important;
}

[data-theme="dark"] input[readonly],
[data-theme="dark"] input:read-only,
[data-theme="dark"] textarea[readonly],
[data-theme="dark"] textarea:read-only {
  background-color: var(--input-bg-readonly) !important;
  color: var(--muted) !important;
}

[data-theme="dark"] select option,
[data-theme="dark"] select optgroup {
  background-color: var(--card);
  color: var(--text);
}

[data-theme="dark"] input::placeholder,
[data-theme="dark"] textarea::placeholder {
  color: var(--muted);
  opacity: .85;
}

[data-theme="dark"] input:-webkit-autofill,
[data-theme="dark"] input:-webkit-autofill:hover,
[data-theme="dark"] input:-webkit-autofill:focus,
[data-theme="dark"] textarea:-webkit-autofill {
  -webkit-box-shadow: 0 0 0 1000px var(--input-bg) inset !important;
  box-shadow: 0 0 0 1000px var(--input-bg) inset !important;
  -webkit-text-fill-color: var(--text) !important;
  caret-color: var(--text);
}

[data-theme="dark"] .form label:has(> select)::after {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23a6a6a6' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
}

[data-theme="dark"] .form label:has(> select:focus)::after {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2360cdff' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
}

[data-theme="dark"] .customer-picker-option:hover,
[data-theme="dark"] .customer-picker-option.is-active,
[data-theme="dark"] .site-combobox-option:hover,
[data-theme="dark"] .site-combobox-option.is-active,
[data-theme="dark"] .filter-style-multiselect-option:hover {
  background: var(--surface-hover);
}

[data-theme="dark"] .app-modal-header {
  background: var(--modal-header-bg) !important;
  border-bottom-color: var(--border-strong);
}

[data-theme="dark"] .app-modal-close-btn:hover {
  background: var(--surface-hover);
}

[data-theme="dark"] .invoice-lines-group-label,
[data-theme="dark"] .invoice-lines-card--readonly,
[data-theme="dark"] .invoice-lines-totals,
[data-theme="dark"] .invoice-manual-details {
  background: var(--surface-muted);
}

[data-theme="dark"] .xero-invoice-preview-wrap .xero-invoice-mock,
[data-theme="dark"] .accounts-invoice-doc {
  background: var(--card);
  color: var(--text);
}

[data-theme="dark"] .accounts-invoice-doc-parties,
[data-theme="dark"] .accounts-invoice-doc-table thead th {
  background: var(--surface-muted);
}

[data-theme="dark"] .accounts-invoice-doc-header {
  background: rgba(96, 205, 255, .1);
  border-bottom-color: rgba(96, 205, 255, .18);
}

[data-theme="dark"] .accounts-invoice-doc-header .accounts-invoice-doc-type {
  color: var(--primary);
}

[data-theme="dark"] .xero-invoice-mock .panel-note,
[data-theme="dark"] .accounts-invoice-doc-empty {
  color: var(--muted);
}

[data-theme="dark"] .invoice-lines-card {
  background: var(--card);
}

[data-theme="dark"] .invoice-lines-table td {
  border-bottom-color: var(--line);
}

[data-theme="dark"] .proposal-labour-calc {
  background: var(--surface-muted);
}

[data-theme="dark"] .input-prefix-wrap {
  background: var(--input-bg) !important;
  border-color: var(--border-strong);
}

[data-theme="dark"] .input-prefix-wrap:focus-within {
  background: var(--input-bg-focus) !important;
}

[data-theme="dark"] .proposal-builder .input-suffix {
  background: var(--surface-muted);
  border-color: var(--border-strong);
}

[data-theme="dark"] .proposal-labour-tech-hours select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23a6a6a6' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
}

[data-theme="dark"] .proposal-labour-tech-hours select:focus {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2360cdff' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
}

[data-theme="dark"] .proposal-add-customer-box:hover {
  background: var(--accent-soft);
  color: var(--primary);
}

/* Calendar — soften dark grid chrome */
[data-theme="dark"] .schedule-week {
  border-color: var(--border-strong);
  background: var(--card);
}

[data-theme="dark"] .schedule-week-corner,
[data-theme="dark"] .schedule-week-dayhead,
[data-theme="dark"] .schedule-week-times,
[data-theme="dark"] .schedule-week-time,
[data-theme="dark"] .schedule-week-daycol {
  border-color: var(--calendar-grid-line);
}

[data-theme="dark"] .schedule-week-grid--header .schedule-week-corner {
  background: linear-gradient(
    180deg,
    var(--calendar-header-bg) 0%,
    var(--calendar-header-bg) 70%,
    color-mix(in srgb, var(--calendar-header-bg) 88%, transparent) 100%
  );
}

[data-theme="dark"] .calendar-picker-label {
  background: var(--card);
  border-color: var(--border-strong);
  color: var(--muted);
}

[data-theme="dark"] .calendar-picker-label:hover {
  background: var(--surface-hover);
  border-color: var(--primary);
  color: var(--text);
}

[data-theme="dark"] .calendar-view-btn.is-active {
  color: var(--primary);
  background: var(--info-soft);
}

[data-theme="dark"] .schedule-week-dayhead.is-today .schedule-week-date {
  color: var(--primary);
}

/* Dashboard cards — dark theme polish */
[data-theme="dark"] .stat-card--highlight,
[data-theme="dark"] .stat-card.highlight {
  background: var(--warning-soft);
  border-color: color-mix(in srgb, var(--warning) 32%, var(--border-strong));
}

[data-theme="dark"] .dashboard-status-section {
  background: var(--dashboard-panel-bg);
  box-shadow: var(--shadow-sm);
}

[data-theme="dark"] .job-card-footer {
  background: var(--card-footer-bg);
}

[data-theme="dark"] .job-number {
  background: var(--surface-muted);
  border-color: var(--line);
  color: var(--text-secondary);
}

[data-theme="dark"] .dashboard-panel--alert {
  border-color: color-mix(in srgb, var(--warning) 28%, var(--border-strong));
  background: color-mix(in srgb, var(--warning-soft) 55%, var(--dashboard-panel-bg));
}

[data-theme="dark"] .proposal-number {
  background: var(--surface-muted);
  border-color: var(--line);
  color: var(--text-secondary);
}

[data-theme="dark"] .license-issues-table .row-highlight {
  background: var(--danger-soft);
}

@media (max-width: 899px) {
  [data-theme="dark"] .customer-list-table tbody tr.customer-row {
    background: var(--card);
  }

  [data-theme="dark"] .customer-list-table td.cell-primary {
    background: var(--surface-muted);
  }

  [data-theme="dark"] .customer-list-table td[data-label="Status"],
  [data-theme="dark"] .customer-list-table td.table-actions {
    background: var(--card-footer-bg);
  }

  [data-theme="dark"] .customer-list-table td.table-actions .icon-btn.table-action-btn {
    background: var(--card);
    border-color: var(--border-strong);
  }
}

/* ---------- System theme (follows OS via prefers-color-scheme) ---------- */
html[data-theme-pref="system"] {
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  html[data-theme-pref="system"] {
  --navy: #f0f0f0;
  --navy-700: #e0e0e0;
  --navy-600: #d0d0d0;

  --sidebar-bg: #1a1a1a;
  --sidebar-accent: #60cdff;
  --sidebar-accent-muted: #4eb8e8;
  --sidebar-text: #f3f3f3;
  --sidebar-text-muted: #9a9a9a;
  --sidebar-text-sub: #b0b0b0;
  --sidebar-border: rgba(255, 255, 255, .08);
  --sidebar-hover-bg: rgba(255, 255, 255, .06);
  --sidebar-active-bg: rgba(96, 205, 255, .16);

  --primary: #60cdff;
  --primary-600: #4ab8e8;

  --accent: #4dd4c4;
  --accent-dark: #3bc4b4;
  --accent-600: #2eb8a8;
  --accent-soft: rgba(77, 212, 196, .14);
  --accent-focus-ring: rgba(77, 212, 196, .28);

  --warning: #f59e0b;
  --danger: #f87171;
  --success: #34d399;

  --bg: #1c1c1c;
  --bg-subtle: #242424;
  --card: #2c2c2c;
  --topbar-bg: #2c2c2c;
  --surface-hover: #383838;
  --surface-muted: #323232;
  --input-bg: #2a2a2a;
  --input-bg-readonly: #242424;
  --input-bg-focus: #323232;
  --modal-header-bg: #242424;
  --pill-bg: #353535;
  --pill-border: #505050;
  --success-soft: rgba(52, 211, 153, .18);
  --success-soft-border: rgba(52, 211, 153, .28);
  --success-on-soft: #86efac;
  --info-soft: rgba(96, 205, 255, .18);
  --danger-soft: rgba(248, 113, 113, .18);
  --warning-soft: rgba(245, 158, 11, .18);
  --purple-soft: rgba(167, 139, 250, .18);
  --neutral-soft: rgba(166, 166, 166, .14);
  --modal-backdrop: rgba(0, 0, 0, .55);
  --purple: #c4b5fd;

  --dashboard-card-min: 403px;
  --dashboard-card-radius: 8px;
  --card-footer-bg: #242424;
  --card-hover-bg: #323232;
  --dashboard-panel-bg: #2c2c2c;

  --text: #ffffff;
  --text-secondary: #e0e0e0;
  --muted: #a6a6a6;

  --line: #3d3d3d;
  --border-strong: #505050;

  --table-header-bg: #323232;
  --table-header-text: #d4d4d4;
  --table-row-hover: #353535;

  --calendar-header-bg: #2f2f2f;
  --calendar-today-bg: #343b42;
  --calendar-today-col-bg: rgba(96, 205, 255, .06);
  --calendar-grid-line: rgba(255, 255, 255, .12);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .35), 0 0 0 1px rgba(255, 255, 255, .04);
  --shadow: 0 2px 8px rgba(0, 0, 0, .4), 0 0 0 1px rgba(255, 255, 255, .06);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, .5), 0 0 0 1px rgba(255, 255, 255, .08);

  color-scheme: dark;
}

  html[data-theme-pref="system"] .accounts-invoice-doc-header {
    background: rgba(96, 205, 255, .1);
    border-bottom-color: rgba(96, 205, 255, .18);
  }

  html[data-theme-pref="system"] .accounts-invoice-doc-header .accounts-invoice-doc-type {
    color: var(--primary);
  }

html[data-theme-pref="system"] .sidebar {
  border-right-color: rgba(0, 0, 0, .35);
  box-shadow: 2px 0 8px rgba(0, 0, 0, .35);
}

html[data-theme-pref="system"] .topbar {
  box-shadow: 0 1px 0 rgba(0, 0, 0, .35);
}

html[data-theme-pref="system"] .tenant-picker-card,
html[data-theme-pref="system"] .join-tenant-card,
html[data-theme-pref="system"] .app-modal-panel,
html[data-theme-pref="system"] .confirm-modal-panel,
html[data-theme-pref="system"] .profile-dropdown,
html[data-theme-pref="system"] .data-table tbody tr {
  background: var(--card);
}

html[data-theme-pref="system"] .tenant-picker-card-avatar {
  background: var(--surface-muted);
  border-color: var(--line);
  color: var(--text);
}

html[data-theme-pref="system"] .alert-info,
html[data-theme-pref="system"] .xero-banner,
html[data-theme-pref="system"] .info-banner {
  background: rgba(96, 205, 255, .12);
  border-color: rgba(96, 205, 255, .28);
  color: #b8e6ff;
}

html[data-theme-pref="system"] .alert-warning,
html[data-theme-pref="system"] .warning-banner {
  background: rgba(245, 158, 11, .12);
  border-color: rgba(245, 158, 11, .28);
  color: #fcd34d;
}

html[data-theme-pref="system"] .alert-success,
html[data-theme-pref="system"] .success-banner {
  background: rgba(52, 211, 153, .12);
  border-color: rgba(52, 211, 153, .28);
  color: #86efac;
}

html[data-theme-pref="system"] .notifications .notification {
  background: var(--card);
  border-color: var(--border-strong);
}

html[data-theme-pref="system"] .app-loading-overlay {
  background: rgba(0, 0, 0, .55);
}

html[data-theme-pref="system"] .notification-success {
  background: rgba(52, 211, 153, .14);
  color: #86efac;
  border-color: rgba(52, 211, 153, .28);
}

html[data-theme-pref="system"] .notification-error {
  background: rgba(248, 113, 113, .14);
  color: #fca5a5;
  border-color: rgba(248, 113, 113, .28);
}

html[data-theme-pref="system"] .notification-warning {
  background: rgba(245, 158, 11, .14);
  color: #fcd34d;
  border-color: rgba(245, 158, 11, .28);
}

html[data-theme-pref="system"] .tenant-license-group,
html[data-theme-pref="system"] .tenant-module-card,
html[data-theme-pref="system"] .notification-settings-card {
  background: var(--card);
}

html[data-theme-pref="system"] .sidebar-backdrop {
  background: rgba(0, 0, 0, .55);
}

/* Form controls — override hardcoded light field styles */
html[data-theme-pref="system"] input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="file"]):not([type="hidden"]):not([type="submit"]):not([type="button"]):not([type="reset"]):not([type="image"]),
html[data-theme-pref="system"] select,
html[data-theme-pref="system"] textarea {
  background-color: var(--input-bg) !important;
  color: var(--text) !important;
  border-color: var(--border-strong);
  color-scheme: dark;
}

html[data-theme-pref="system"] input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="file"]):not([type="hidden"]):not([type="submit"]):not([type="button"]):not([type="reset"]):not([type="image"]):hover,
html[data-theme-pref="system"] select:hover,
html[data-theme-pref="system"] textarea:hover {
  background-color: var(--surface-muted) !important;
}

html[data-theme-pref="system"] input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="file"]):not([type="hidden"]):not([type="submit"]):not([type="button"]):not([type="reset"]):not([type="image"]):focus,
html[data-theme-pref="system"] select:focus,
html[data-theme-pref="system"] textarea:focus {
  background-color: var(--input-bg-focus) !important;
  color: var(--text) !important;
}

html[data-theme-pref="system"] input[readonly],
html[data-theme-pref="system"] input:read-only,
html[data-theme-pref="system"] textarea[readonly],
html[data-theme-pref="system"] textarea:read-only {
  background-color: var(--input-bg-readonly) !important;
  color: var(--muted) !important;
}

html[data-theme-pref="system"] select option,
html[data-theme-pref="system"] select optgroup {
  background-color: var(--card);
  color: var(--text);
}

html[data-theme-pref="system"] input::placeholder,
html[data-theme-pref="system"] textarea::placeholder {
  color: var(--muted);
  opacity: .85;
}

html[data-theme-pref="system"] input:-webkit-autofill,
html[data-theme-pref="system"] input:-webkit-autofill:hover,
html[data-theme-pref="system"] input:-webkit-autofill:focus,
html[data-theme-pref="system"] textarea:-webkit-autofill {
  -webkit-box-shadow: 0 0 0 1000px var(--input-bg) inset !important;
  box-shadow: 0 0 0 1000px var(--input-bg) inset !important;
  -webkit-text-fill-color: var(--text) !important;
  caret-color: var(--text);
}

html[data-theme-pref="system"] .form label:has(> select)::after {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23a6a6a6' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
}

html[data-theme-pref="system"] .form label:has(> select:focus)::after {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2360cdff' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
}

html[data-theme-pref="system"] .customer-picker-option:hover,
html[data-theme-pref="system"] .customer-picker-option.is-active,
html[data-theme-pref="system"] .site-combobox-option:hover,
html[data-theme-pref="system"] .site-combobox-option.is-active,
html[data-theme-pref="system"] .filter-style-multiselect-option:hover {
  background: var(--surface-hover);
}

html[data-theme-pref="system"] .app-modal-header {
  background: var(--modal-header-bg) !important;
  border-bottom-color: var(--border-strong);
}

html[data-theme-pref="system"] .app-modal-close-btn:hover {
  background: var(--surface-hover);
}

html[data-theme-pref="system"] .invoice-lines-group-label,
html[data-theme-pref="system"] .invoice-lines-card--readonly,
html[data-theme-pref="system"] .invoice-lines-totals,
html[data-theme-pref="system"] .invoice-manual-details {
  background: var(--surface-muted);
}

html[data-theme-pref="system"] .xero-invoice-preview-wrap .xero-invoice-mock,
html[data-theme-pref="system"] .accounts-invoice-doc {
  background: var(--card);
  color: var(--text);
}

html[data-theme-pref="system"] .accounts-invoice-doc-parties,
html[data-theme-pref="system"] .accounts-invoice-doc-table thead th {
  background: var(--surface-muted);
}

html[data-theme-pref="system"] .xero-invoice-mock .panel-note,
html[data-theme-pref="system"] .accounts-invoice-doc-empty {
  color: var(--muted);
}

html[data-theme-pref="system"] .invoice-lines-card {
  background: var(--card);
}

html[data-theme-pref="system"] .invoice-lines-table td {
  border-bottom-color: var(--line);
}

html[data-theme-pref="system"] .proposal-labour-calc {
  background: var(--surface-muted);
}

html[data-theme-pref="system"] .input-prefix-wrap {
  background: var(--input-bg) !important;
  border-color: var(--border-strong);
}

html[data-theme-pref="system"] .input-prefix-wrap:focus-within {
  background: var(--input-bg-focus) !important;
}

html[data-theme-pref="system"] .proposal-builder .input-suffix {
  background: var(--surface-muted);
  border-color: var(--border-strong);
}

html[data-theme-pref="system"] .proposal-labour-tech-hours select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23a6a6a6' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
}

html[data-theme-pref="system"] .proposal-labour-tech-hours select:focus {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2360cdff' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
}

html[data-theme-pref="system"] .proposal-add-customer-box:hover {
  background: var(--accent-soft);
  color: var(--primary);
}

/* Calendar — soften dark grid chrome */
html[data-theme-pref="system"] .schedule-week {
  border-color: var(--border-strong);
  background: var(--card);
}

html[data-theme-pref="system"] .schedule-week-corner,
html[data-theme-pref="system"] .schedule-week-dayhead,
html[data-theme-pref="system"] .schedule-week-times,
html[data-theme-pref="system"] .schedule-week-time,
html[data-theme-pref="system"] .schedule-week-daycol {
  border-color: var(--calendar-grid-line);
}

html[data-theme-pref="system"] .schedule-week-grid--header .schedule-week-corner {
  background: linear-gradient(
    180deg,
    var(--calendar-header-bg) 0%,
    var(--calendar-header-bg) 70%,
    color-mix(in srgb, var(--calendar-header-bg) 88%, transparent) 100%
  );
}

html[data-theme-pref="system"] .calendar-picker-label {
  background: var(--card);
  border-color: var(--border-strong);
  color: var(--muted);
}

html[data-theme-pref="system"] .calendar-picker-label:hover {
  background: var(--surface-hover);
  border-color: var(--primary);
  color: var(--text);
}

html[data-theme-pref="system"] .calendar-view-btn.is-active {
  color: var(--primary);
  background: var(--info-soft);
}

html[data-theme-pref="system"] .schedule-week-dayhead.is-today .schedule-week-date {
  color: var(--primary);
}

/* Dashboard cards — dark theme polish */
html[data-theme-pref="system"] .stat-card--highlight,
html[data-theme-pref="system"] .stat-card.highlight {
  background: var(--warning-soft);
  border-color: color-mix(in srgb, var(--warning) 32%, var(--border-strong));
}

html[data-theme-pref="system"] .dashboard-status-section {
  background: var(--dashboard-panel-bg);
  box-shadow: var(--shadow-sm);
}

html[data-theme-pref="system"] .job-card-footer {
  background: var(--card-footer-bg);
}

html[data-theme-pref="system"] .job-number {
  background: var(--surface-muted);
  border-color: var(--line);
  color: var(--text-secondary);
}

html[data-theme-pref="system"] .dashboard-panel--alert {
  border-color: color-mix(in srgb, var(--warning) 28%, var(--border-strong));
  background: color-mix(in srgb, var(--warning-soft) 55%, var(--dashboard-panel-bg));
}

html[data-theme-pref="system"] .proposal-number {
  background: var(--surface-muted);
  border-color: var(--line);
  color: var(--text-secondary);
}

html[data-theme-pref="system"] .license-issues-table .row-highlight {
  background: var(--danger-soft);
}

@media (max-width: 899px) {
  html[data-theme-pref="system"] .customer-list-table tbody tr.customer-row {
    background: var(--card);
  }

  html[data-theme-pref="system"] .customer-list-table td.cell-primary {
    background: var(--surface-muted);
  }

  html[data-theme-pref="system"] .customer-list-table td[data-label="Status"],
  html[data-theme-pref="system"] .customer-list-table td.table-actions {
    background: var(--card-footer-bg);
  }

  html[data-theme-pref="system"] .customer-list-table td.table-actions .icon-btn.table-action-btn {
    background: var(--card);
    border-color: var(--border-strong);
  }
}

}
