:root {
    --cmms-primary: #3d6b7f;
    --cmms-primary-dark: #2c5364;
    --cmms-primary-light: #4a90a4;
    --cmms-primary-tint: #eaf2f5;
    --cmms-gradient-chrome: linear-gradient(135deg, var(--cmms-primary) 0%, var(--cmms-primary-dark) 100%);
    --cmms-gradient-drawer: linear-gradient(180deg, #17333f 0%, #0f2027 100%);

    --cmms-ink: #1b2430;
    --cmms-body: #2e3a47;
    --cmms-muted: #5d6b7a;
    --cmms-faint: #9aa7b4;
    --cmms-line: #dee4eb;
    --cmms-line-soft: #e9eef3;
    --cmms-line-input: #b9c6d4;
    --cmms-canvas: #f4f6f9;
    --cmms-surface: #ffffff;

    --cmms-success: #2e7d32;
    --cmms-success-soft: #e7f2e8;
    --cmms-success-deep: #1d5a22;
    --cmms-warning: #ed6c02;
    --cmms-warning-soft: #fdf0e1;
    --cmms-warning-deep: #9a4a00;
    --cmms-error: #c62828;
    --cmms-error-soft: #fbeaea;
    --cmms-error-deep: #9e1f1f;
    --cmms-info: #0277bd;
    --cmms-info-soft: #e5f1f9;
    --cmms-info-deep: #01579b;

    --cmms-radius-control: 4px;
    --cmms-radius-card: 8px;
    --cmms-radius-hero: 12px;
    --cmms-shadow-card: 0 2px 8px rgba(15, 32, 39, 0.08);
    --cmms-shadow-raised: 0 8px 24px rgba(15, 32, 39, 0.12);
    --cmms-shadow-overlay: 0 18px 48px rgba(15, 32, 39, 0.28);

    --cmms-space-1: 4px;
    --cmms-space-2: 8px;
    --cmms-space-3: 12px;
    --cmms-space-4: 16px;
    --cmms-space-5: 20px;
    --cmms-space-6: 24px;
    --cmms-space-8: 32px;
    --cmms-control-height: 36px;
    --cmms-action-height: 40px;
    --cmms-appbar-height: 56px;
    --cmms-drawer-width: 272px;
    --cmms-content-max: 1680px;
    --cmms-transition-fast: 140ms ease;
    --cmms-z-sticky: 20;
    --cmms-z-actionbar: 30;
    --cmms-z-overlay: 1300;

    --cmms-font: "Roboto", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
    --cmms-font-mono: "Roboto Mono", Consolas, "Cascadia Code", Menlo, monospace;
}

/* Dark mode (Account Settings ▸ Appearance). theme.js sets html[data-theme] from the account's saved choice;
   MudBlazor switches its own palette through IsDarkMode, these tokens recolour the CMMS chrome. */
html[data-theme="dark"] {
    color-scheme: dark;
    --cmms-primary-tint: rgba(74, 144, 164, 0.18);
    --cmms-gradient-drawer: linear-gradient(180deg, #0f1a21 0%, #0a1216 100%);

    --cmms-ink: #e8eef4;
    --cmms-body: #d5dde5;
    --cmms-muted: #9fb0c0;
    --cmms-faint: #6f8090;
    --cmms-line: #2f3c4a;
    --cmms-line-soft: #27323e;
    --cmms-line-input: #3a4857;
    --cmms-canvas: #0f161c;
    --cmms-surface: #1c2630;

    --cmms-success-soft: #173322;
    --cmms-success-deep: #8fd19a;
    --cmms-warning-soft: #3a2a12;
    --cmms-warning-deep: #f0b06a;
    --cmms-error-soft: #3a1d1d;
    --cmms-error-deep: #f09a9a;
    --cmms-info-soft: #14283a;
    --cmms-info-deep: #8ec7ee;

    --cmms-shadow-card: 0 2px 8px rgba(0, 0, 0, 0.45);
    --cmms-shadow-raised: 0 8px 24px rgba(0, 0, 0, 0.5);
    --cmms-shadow-overlay: 0 18px 48px rgba(0, 0, 0, 0.6);
}

html[data-theme="dark"] body {
    background: var(--cmms-canvas);
    color: var(--cmms-body);
}

html[data-theme="dark"] .main-content {
    background: var(--cmms-canvas) !important;
}

html[data-theme="dark"] .content-wrapper .mud-paper,
html[data-theme="dark"] .content-wrapper .mud-card,
html[data-theme="dark"] .content-wrapper .rpt-card {
    background: var(--cmms-surface);
    color: var(--cmms-body);
    border-color: var(--cmms-line);
}

html[data-theme="dark"] .content-wrapper .mud-table,
html[data-theme="dark"] .content-wrapper .mud-table-cell,
html[data-theme="dark"] .content-wrapper .mud-input,
html[data-theme="dark"] .content-wrapper .mud-input-label,
html[data-theme="dark"] .content-wrapper .mud-typography {
    color: var(--cmms-body);
}

html[data-theme="dark"] .content-wrapper .mud-table-row:hover {
    background: rgba(255, 255, 255, 0.04);
}

html[data-theme="dark"] .content-wrapper .mud-input-outlined-border {
    border-color: var(--cmms-line-input);
}


/* Inline styles the pages carry (report headers, chips, icon boxes) cannot be recoloured by class, so the

   colours they actually use are matched by attribute. Both `prop:value` and `prop: value` spellings occur. */

html[data-theme="dark"] [style*="color:#333"]:not([style*="background"]),
html[data-theme="dark"] [style*="color: #333"]:not([style*="background"]),
html[data-theme="dark"] [style*="color:#222"]:not([style*="background"]),
html[data-theme="dark"] [style*="color: #222"]:not([style*="background"]),
html[data-theme="dark"] [style*="color:#000"]:not([style*="background"]),
html[data-theme="dark"] [style*="color: #000"]:not([style*="background"]),
html[data-theme="dark"] [style*="color:#263238"]:not([style*="background"]),
html[data-theme="dark"] [style*="color: #263238"]:not([style*="background"]),
html[data-theme="dark"] [style*="color:#37474f"]:not([style*="background"]),
html[data-theme="dark"] [style*="color: #37474f"]:not([style*="background"]),
html[data-theme="dark"] [style*="color:#444"]:not([style*="background"]),
html[data-theme="dark"] [style*="color: #444"]:not([style*="background"]),
html[data-theme="dark"] [style*="color:#555"]:not([style*="background"]),
html[data-theme="dark"] [style*="color: #555"]:not([style*="background"]),
html[data-theme="dark"] [style*="color:#1b2430"]:not([style*="background"]),
html[data-theme="dark"] [style*="color: #1b2430"]:not([style*="background"]),
html[data-theme="dark"] [style*="color:#2e3a47"]:not([style*="background"]),
html[data-theme="dark"] [style*="color: #2e3a47"]:not([style*="background"]),
html[data-theme="dark"] [style*="color:#1a4548"]:not([style*="background"]),
html[data-theme="dark"] [style*="color: #1a4548"]:not([style*="background"]),
html[data-theme="dark"] [style*="color:#1e4548"]:not([style*="background"]),
html[data-theme="dark"] [style*="color: #1e4548"] {
    color: var(--cmms-body) !important;
}

html[data-theme="dark"] [style*="color:#888"]:not([style*="background"]),
html[data-theme="dark"] [style*="color: #888"]:not([style*="background"]),
html[data-theme="dark"] [style*="color:#999"]:not([style*="background"]),
html[data-theme="dark"] [style*="color: #999"]:not([style*="background"]),
html[data-theme="dark"] [style*="color:#777"]:not([style*="background"]),
html[data-theme="dark"] [style*="color: #777"]:not([style*="background"]),
html[data-theme="dark"] [style*="color:#666"]:not([style*="background"]),
html[data-theme="dark"] [style*="color: #666"]:not([style*="background"]),
html[data-theme="dark"] [style*="color:#78909e"]:not([style*="background"]),
html[data-theme="dark"] [style*="color: #78909e"]:not([style*="background"]),
html[data-theme="dark"] [style*="color:#78909c"]:not([style*="background"]),
html[data-theme="dark"] [style*="color: #78909c"]:not([style*="background"]),
html[data-theme="dark"] [style*="color:#546e7a"]:not([style*="background"]),
html[data-theme="dark"] [style*="color: #546e7a"]:not([style*="background"]),
html[data-theme="dark"] [style*="color:#607d8b"]:not([style*="background"]),
html[data-theme="dark"] [style*="color: #607d8b"]:not([style*="background"]),
html[data-theme="dark"] [style*="color:#757575"]:not([style*="background"]),
html[data-theme="dark"] [style*="color: #757575"]:not([style*="background"]),
html[data-theme="dark"] [style*="color:#90a4ae"]:not([style*="background"]),
html[data-theme="dark"] [style*="color: #90a4ae"]:not([style*="background"]),
html[data-theme="dark"] [style*="color:#bbb"]:not([style*="background"]),
html[data-theme="dark"] [style*="color: #bbb"]:not([style*="background"]),
html[data-theme="dark"] [style*="color:#5d6b7a"]:not([style*="background"]),
html[data-theme="dark"] [style*="color: #5d6b7a"] {
    color: var(--cmms-muted) !important;
}

html[data-theme="dark"] [style*="color:#1565c0"]:not([style*="background"]),
html[data-theme="dark"] [style*="color: #1565c0"]:not([style*="background"]),
html[data-theme="dark"] [style*="color:#0d47a1"]:not([style*="background"]),
html[data-theme="dark"] [style*="color: #0d47a1"] {
    color: #8ec7ee !important;
}

html[data-theme="dark"] [style*="background:#fff"],
html[data-theme="dark"] [style*="background: #fff"],
html[data-theme="dark"] [style*="background:#ffffff"],
html[data-theme="dark"] [style*="background: #ffffff"],
html[data-theme="dark"] [style*="background:white"],
html[data-theme="dark"] [style*="background: white"],
html[data-theme="dark"] [style*="background:#f8fafc"],
html[data-theme="dark"] [style*="background: #f8fafc"],
html[data-theme="dark"] [style*="background:#fafbfc"],
html[data-theme="dark"] [style*="background: #fafbfc"],
html[data-theme="dark"] [style*="background:#fafafa"],
html[data-theme="dark"] [style*="background: #fafafa"],
html[data-theme="dark"] [style*="background:#f5f5f5"],
html[data-theme="dark"] [style*="background: #f5f5f5"],
html[data-theme="dark"] [style*="background:#f4f6f9"],
html[data-theme="dark"] [style*="background: #f4f6f9"],
html[data-theme="dark"] [style*="background:#f7fbff"],
html[data-theme="dark"] [style*="background: #f7fbff"],
html[data-theme="dark"] [style*="background-color:#fff"],
html[data-theme="dark"] [style*="background-color: #fff"],
html[data-theme="dark"] [style*="background-color:#ffffff"],
html[data-theme="dark"] [style*="background-color: #ffffff"],
html[data-theme="dark"] [style*="background-color:white"],
html[data-theme="dark"] [style*="background-color: white"],
html[data-theme="dark"] [style*="background-color:#f8fafc"],
html[data-theme="dark"] [style*="background-color: #f8fafc"],
html[data-theme="dark"] [style*="background-color:#fafbfc"],
html[data-theme="dark"] [style*="background-color: #fafbfc"],
html[data-theme="dark"] [style*="background-color:#fafafa"],
html[data-theme="dark"] [style*="background-color: #fafafa"],
html[data-theme="dark"] [style*="background-color:#f5f5f5"],
html[data-theme="dark"] [style*="background-color: #f5f5f5"],
html[data-theme="dark"] [style*="background-color:#f4f6f9"],
html[data-theme="dark"] [style*="background-color: #f4f6f9"],
html[data-theme="dark"] [style*="background-color:#f7fbff"],
html[data-theme="dark"] [style*="background-color: #f7fbff"] {
    background: var(--cmms-surface) !important;
}

html[data-theme="dark"] [style*="background:#e8f5e9"],
html[data-theme="dark"] [style*="background: #e8f5e9"] {
    background: rgba(46, 125, 50, 0.28) !important;
}

html[data-theme="dark"] [style*="background:#e3f2fd"],
html[data-theme="dark"] [style*="background: #e3f2fd"] {
    background: rgba(2, 119, 189, 0.28) !important;
}

html[data-theme="dark"] [style*="background:#fff3e0"],
html[data-theme="dark"] [style*="background: #fff3e0"] {
    background: rgba(237, 108, 2, 0.26) !important;
}

html[data-theme="dark"] [style*="background:#e8f4fd"],
html[data-theme="dark"] [style*="background: #e8f4fd"] {
    background: rgba(21, 101, 192, 0.26) !important;
}

html[data-theme="dark"] [style*="background:#fff8e1"],
html[data-theme="dark"] [style*="background: #fff8e1"] {
    background: rgba(245, 127, 23, 0.26) !important;
}

html[data-theme="dark"] [style*="background:#fce4ec"],
html[data-theme="dark"] [style*="background: #fce4ec"] {
    background: rgba(173, 20, 87, 0.26) !important;
}

html[data-theme="dark"] [style*="background:#eef5ff"],
html[data-theme="dark"] [style*="background: #eef5ff"] {
    background: rgba(21, 101, 192, 0.22) !important;
}

html[data-theme="dark"] [style*="background:#eaf4fc"],
html[data-theme="dark"] [style*="background: #eaf4fc"] {
    background: rgba(2, 119, 189, 0.22) !important;
}

html[data-theme="dark"] [style*="background:#ffffcc"],
html[data-theme="dark"] [style*="background: #ffffcc"] {
    background: rgba(255, 235, 59, 0.25) !important;
}

html[data-theme="dark"] [style*="background:#ccffcc"],
html[data-theme="dark"] [style*="background: #ccffcc"] {
    background: rgba(76, 175, 80, 0.25) !important;
}

html[data-theme="dark"] [style*="background:#e8eaf6"],
html[data-theme="dark"] [style*="background: #e8eaf6"] {
    background: rgba(57, 73, 171, 0.28) !important;
}

html[data-theme="dark"] [style*="background:#e0f2f1"],
html[data-theme="dark"] [style*="background: #e0f2f1"] {
    background: rgba(0, 121, 107, 0.28) !important;
}

html[data-theme="dark"] [style*="background:#f3e5f5"],
html[data-theme="dark"] [style*="background: #f3e5f5"] {
    background: rgba(123, 31, 162, 0.28) !important;
}

html[data-theme="dark"] [style*="background:#fbe9e7"],
html[data-theme="dark"] [style*="background: #fbe9e7"] {
    background: rgba(216, 67, 21, 0.26) !important;
}

html[data-theme="dark"] [style*="background:#ede7f6"],
html[data-theme="dark"] [style*="background: #ede7f6"] {
    background: rgba(69, 39, 160, 0.28) !important;
}

html[data-theme="dark"] [style*="background:rgba(44,95,98,.06)"],
html[data-theme="dark"] [style*="background: rgba(44,95,98,.06)"] {
    background: rgba(74, 144, 164, 0.14) !important;
}

html[data-theme="dark"] [style*="background:rgba(44,95,98,.12)"],
html[data-theme="dark"] [style*="background: rgba(44,95,98,.12)"] {
    background: rgba(74, 144, 164, 0.18) !important;
}

html[data-theme="dark"] [style*="border:1px solid #e0e0e0"],
html[data-theme="dark"] [style*="border: 1px solid #e0e0e0"],
html[data-theme="dark"] [style*="border:1px solid #ccc"],
html[data-theme="dark"] [style*="border: 1px solid #ccc"],
html[data-theme="dark"] [style*="border:1px solid #ddd"],
html[data-theme="dark"] [style*="border: 1px solid #ddd"],
html[data-theme="dark"] [style*="border:1px solid #eee"],
html[data-theme="dark"] [style*="border: 1px solid #eee"],
html[data-theme="dark"] [style*="border:1px solid #e9eef3"],
html[data-theme="dark"] [style*="border: 1px solid #e9eef3"],
html[data-theme="dark"] [style*="border:1px solid #dee4eb"],
html[data-theme="dark"] [style*="border: 1px solid #dee4eb"] {
    border-color: var(--cmms-line) !important;
}


/* MudBlazor pieces the palette does not reach. */
html[data-theme="dark"] .mud-input.mud-input-outlined .mud-input-outlined-border,
html[data-theme="dark"] .mud-select .mud-input-outlined-border {
    border-color: var(--cmms-line-input);
}

html[data-theme="dark"] .mud-input-slot,
html[data-theme="dark"] .mud-input > input,
html[data-theme="dark"] .mud-input > textarea,
html[data-theme="dark"] .mud-select-input,
html[data-theme="dark"] .mud-input-label,
html[data-theme="dark"] .mud-checkbox .mud-typography,
html[data-theme="dark"] .mud-radio .mud-typography {
    color: var(--cmms-body);
}

html[data-theme="dark"] .mud-input-helper-text,
html[data-theme="dark"] .mud-typography.mud-text-secondary,
html[data-theme="dark"] .mud-text-secondary {
    color: var(--cmms-muted) !important;
}

html[data-theme="dark"] .mud-table-head .mud-table-cell,
html[data-theme="dark"] .mud-table-cell,
html[data-theme="dark"] .mud-simple-table td,
html[data-theme="dark"] .mud-simple-table th {
    color: var(--cmms-body);
    border-color: var(--cmms-line-soft);
}

html[data-theme="dark"] .mud-chip.mud-chip-filled.mud-chip-color-default {
    background: #2a3541;
    color: var(--cmms-body);
}

html[data-theme="dark"] .mud-dialog,
html[data-theme="dark"] .mud-popover,
html[data-theme="dark"] .mud-list,
html[data-theme="dark"] .mud-picker-container {
    background: var(--cmms-surface);
    color: var(--cmms-body);
}

html[data-theme="dark"] .mud-skeleton {
    background: rgba(255, 255, 255, 0.08);
}

html[data-theme="dark"] input,
html[data-theme="dark"] select,
html[data-theme="dark"] textarea {
    color: var(--cmms-body);
    background-color: transparent;
}

/* A native <select> (Audit Trail page size, a few form fields) opens a browser-drawn list that
   takes the select's own colours: transparent became white with light text, so the options were
   invisible. The list needs an explicit dark background and a dark colour scheme. */
html[data-theme="dark"] select {
    background-color: var(--cmms-surface);
    color-scheme: dark;
}

html[data-theme="dark"] select option {
    background-color: var(--cmms-surface);
    color: var(--cmms-body);
}

html[data-theme="dark"] ::placeholder {
    color: var(--cmms-faint);
}

html[data-theme="dark"] a:not(.mud-button):not(.nav-link):not(.mud-nav-link) {
    color: #8ec7ee;
}

/* Work request / work order summary tiles: pin the text and panel colours so nothing inherited can dim them. */
html[data-theme="dark"] .work-summary-group {
    background: rgba(255, 255, 255, 0.035);
    border-color: var(--cmms-line);
}

html[data-theme="dark"] .work-summary-card {
    color: var(--cmms-body);
    background: var(--cmms-surface);
    border-color: var(--cmms-line);
}

html[data-theme="dark"] .work-summary-card__count {
    color: var(--cmms-ink) !important;
}

html[data-theme="dark"] .work-summary-card__label,
html[data-theme="dark"] .work-summary-group__heading {
    color: var(--cmms-muted) !important;
}

html[data-theme="dark"] .work-summary-card--team,
html[data-theme="dark"] .work-summary-card--cancelled {
    --summary-soft: rgba(100, 116, 139, 0.28);
    --summary-deep: #b6c2d1;
}

html[data-theme="dark"] .work-summary-card--mine {
    --summary-soft: rgba(74, 144, 164, 0.28);
    --summary-deep: #9fd0e0;
}

html[data-theme="dark"] .work-summary-card--new { --summary-soft: rgba(2, 132, 199, 0.26); --summary-deep: #7cc4ef; }
html[data-theme="dark"] .work-summary-card--todo { --summary-soft: rgba(147, 51, 234, 0.26); --summary-deep: #c9a3f5; }
html[data-theme="dark"] .work-summary-card--progress { --summary-soft: rgba(202, 138, 4, 0.26); --summary-deep: #f0c94f; }
html[data-theme="dark"] .work-summary-card--hold { --summary-soft: rgba(234, 88, 12, 0.26); --summary-deep: #f6a56d; }
html[data-theme="dark"] .work-summary-card--completed { --summary-soft: rgba(21, 128, 61, 0.26); --summary-deep: #7fd39a; }
html[data-theme="dark"] .work-summary-card--closed { --summary-soft: rgba(180, 35, 42, 0.26); --summary-deep: #f29aa0; }

html[data-theme="dark"] [style*="background:#f1f8e9"],
html[data-theme="dark"] [style*="background: #f1f8e9"] {
    background: rgba(76, 175, 80, 0.26) !important;
}
