/* ============================================================
   CREWLY ASCEND - GLOBAL THEME & BASE STYLES
   Version: 5.0 — Premium refresh + light/dark theming
   ------------------------------------------------------------
   Theming model:
   - :root defines brand constants + LIGHT theme semantic tokens.
   - html[data-theme="dark"] overrides the semantic tokens only.
   - Components must use semantic tokens (--surface-*, --text-*,
     --border-*) — never raw hex/rgba — so both themes work.
   ============================================================ */

/* ============================================================
   CSS CUSTOM PROPERTIES (Theme Variables)
   ============================================================ */
:root {
    /* ---------- Brand constants (identical in both themes) ---------- */
    --color-primary: #23486A;          /* brand navy */
    --color-primary-dark: #16293F;
    --color-primary-light: #2E5A7D;

    --color-accent-orange: #E2AC4B;    /* champagne gold */
    --color-accent-orange-hover: #CE9633;
    --color-accent-green: #3FA96C;     /* deep emerald */
    --color-accent-green-hover: #338B59;
    --color-accent-red: #CC4B4B;       /* muted crimson */
    --color-accent-red-hover: #B03A3A;

    --color-white: #ffffff;

    /* ---------- Typography ---------- */
    --font-body: 'Inter', 'Segoe UI', 'Roboto', 'Helvetica Neue', sans-serif;
    --font-display: 'Fraunces', 'Georgia', 'Times New Roman', serif;

    /* ---------- Light theme: semantic tokens ---------- */
    --surface-page: #F3F4F6;                    /* app background       */
    --surface-content: rgba(255, 255, 255, 0.72);/* main content veil   */
    --surface-card: #FFFFFF;                    /* cards, panels        */
    --surface-card-translucent: rgba(255, 255, 255, 0.92);
    --surface-raised: #FAFAF8;                  /* card footers, wells  */
    --surface-inset: #EEF0F3;                   /* inputs-adjacent fill */
    --surface-hover: #F6F2E7;                   /* gold-tinted hover    */

    --text-strong: #17293C;                     /* headings             */
    --text-body: #2B3F53;                       /* default text         */
    --text-muted: #64748B;                      /* secondary text       */
    --text-faint: #94A3B8;                      /* placeholders, hints  */

    --border-subtle: rgba(23, 41, 60, 0.10);
    --border-strong: rgba(23, 41, 60, 0.22);
    --border-gold: rgba(226, 172, 75, 0.45);

    --dot-grid: rgba(23, 41, 60, 0.06);         /* content dot-grid texture */

    --accent-gold-soft: rgba(226, 172, 75, 0.14);/* tinted fills        */
    --focus-ring: rgba(226, 172, 75, 0.30);
    --link-color: var(--color-accent-orange-hover);
    --link-hover: var(--color-accent-orange);

    /* Status tints (bg + readable text, per theme) */
    --tint-success-bg: rgba(63, 169, 108, 0.12);
    --tint-success-text: #256B46;
    --tint-danger-bg: rgba(204, 75, 75, 0.10);
    --tint-danger-text: #A03232;
    --tint-warning-bg: rgba(226, 172, 75, 0.14);
    --tint-warning-text: #8A6414;
    --tint-info-bg: rgba(35, 72, 106, 0.10);
    --tint-info-text: #23486A;

    /* On-brand = content sitting on navy (sidebar, topbar, table heads) */
    --on-brand: #FFFFFF;
    --on-brand-muted: rgba(255, 255, 255, 0.72);
    --on-brand-faint: rgba(255, 255, 255, 0.45);

    /* ---------- Legacy gray scale (remapped per theme) ---------- */
    --color-gray-50: #F8F9FA;
    --color-gray-100: #E9ECEF;
    --color-gray-200: #DEE2E6;
    --color-gray-300: #D0D0D0;
    --color-gray-400: #999999;
    --color-gray-500: #6C757D;
    --color-gray-600: #555555;
    --color-gray-700: #444444;
    --color-gray-800: #333333;

    /* Legacy background aliases */
    --bg-body: var(--surface-page);
    --bg-content: var(--surface-content);
    --bg-card: var(--surface-card-translucent);
    --bg-card-hover: var(--surface-card);

    /* ---------- Layout dimensions ---------- */
    --sidebar-width: 272px;
    --topbar-height: 56px;
    --accent-strip-width: 3px;

    /* ---------- Spacing ---------- */
    --spacing-xs: 0.5rem;
    --spacing-sm: 1rem;
    --spacing-md: 1.5rem;
    --spacing-lg: 2rem;
    --spacing-xl: 3rem;

    /* ---------- Border radius ---------- */
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --radius-full: 9999px;

    /* ---------- Shadows ---------- */
    --shadow-xs: 0 1px 2px rgba(23, 41, 60, 0.06);
    --shadow-sm: 0 1px 3px rgba(23, 41, 60, 0.07), 0 4px 12px rgba(23, 41, 60, 0.05);
    --shadow-md: 0 2px 6px rgba(23, 41, 60, 0.08), 0 8px 24px rgba(23, 41, 60, 0.08);
    --shadow-lg: 0 4px 12px rgba(23, 41, 60, 0.10), 0 16px 40px rgba(23, 41, 60, 0.12);
    --shadow-xl: 0 8px 24px rgba(23, 41, 60, 0.14), 0 24px 64px rgba(23, 41, 60, 0.18);

    /* ---------- Transitions ---------- */
    --transition-fast: 0.15s ease;
    --transition-base: 0.2s ease;
    --transition-slow: 0.3s ease;

    /* ---------- Z-index ---------- */
    --z-dropdown: 100;
    --z-sticky: 200;
    --z-fixed: 300;
    --z-modal-backdrop: 400;
    --z-modal: 500;
    --z-popover: 600;
    --z-tooltip: 700;

    color-scheme: light;
}

/* ============================================================
   DARK THEME OVERRIDES
   ============================================================ */
html[data-theme="dark"] {
    --surface-page: #0D131C;
    --surface-content: rgba(15, 22, 33, 0.72);
    --surface-card: #151F2C;
    --surface-card-translucent: rgba(21, 31, 44, 0.92);
    --surface-raised: #1A2634;
    --surface-inset: #101823;
    --surface-hover: #1E2A3A;

    --text-strong: #F1F5F9;
    --text-body: #CBD5E1;
    --text-muted: #8FA0B3;
    --text-faint: #64748B;

    --border-subtle: rgba(255, 255, 255, 0.08);
    --border-strong: rgba(255, 255, 255, 0.18);
    --border-gold: rgba(226, 172, 75, 0.40);

    --dot-grid: rgba(255, 255, 255, 0.045);     /* content dot-grid texture */

    --accent-gold-soft: rgba(226, 172, 75, 0.12);
    --focus-ring: rgba(226, 172, 75, 0.35);
    --link-color: var(--color-accent-orange);
    --link-hover: #EFC06E;

    --tint-success-bg: rgba(63, 169, 108, 0.16);
    --tint-success-text: #7BD3A4;
    --tint-danger-bg: rgba(204, 75, 75, 0.16);
    --tint-danger-text: #EE9A9A;
    --tint-warning-bg: rgba(226, 172, 75, 0.14);
    --tint-warning-text: #E8C070;
    --tint-info-bg: rgba(94, 148, 197, 0.14);
    --tint-info-text: #9FC3E3;

    /* Legacy grays inverted: 50–200 are fills, 400–800 are text shades */
    --color-gray-50: #1A2431;
    --color-gray-100: #223042;
    --color-gray-200: #2B3A4E;
    --color-gray-300: #3A4C63;
    --color-gray-400: #7A8CA1;
    --color-gray-500: #93A5BA;
    --color-gray-600: #B4C2D3;
    --color-gray-700: #C9D4E0;
    --color-gray-800: #E2E9F1;

    /* Shadows on dark: deeper, black-based */
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.35);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.35), 0 4px 12px rgba(0, 0, 0, 0.25);
    --shadow-md: 0 2px 6px rgba(0, 0, 0, 0.40), 0 8px 24px rgba(0, 0, 0, 0.30);
    --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.45), 0 16px 40px rgba(0, 0, 0, 0.35);
    --shadow-xl: 0 8px 24px rgba(0, 0, 0, 0.50), 0 24px 64px rgba(0, 0, 0, 0.40);

    color-scheme: dark;
}

/* ============================================================
RESET & BASE STYLES
============================================================ */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

html,
body {
    height: 100%;
    overflow: hidden;
    max-width: 100vw;
    overflow-x: hidden;
}

body {
    font-family: var(--font-body);
    font-size: 1rem;
    line-height: 1.6;
    color: var(--text-body);
    background: var(--surface-page);
    /* Quiet, premium wash instead of the old diagonal stripes */
    background-image:
        radial-gradient(1200px 500px at 85% -10%, var(--accent-gold-soft), transparent 60%),
        radial-gradient(1000px 600px at -10% 110%, rgba(35, 72, 106, 0.06), transparent 55%);
    background-attachment: fixed;
    width: 100%;
    max-width: 100%;
    position: relative;
    transition: background-color var(--transition-slow), color var(--transition-slow);
}

/* ============================================================
TYPOGRAPHY
============================================================ */
h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    line-height: 1.2;
    color: var(--text-strong);
    margin-bottom: var(--spacing-sm);
}

h1, h2, h3 {
    font-family: var(--font-display);
    font-weight: 600;
    letter-spacing: 0.01em;
}

h1 {
    font-size: 1.5rem;
}

h2 {
    font-size: 1.35rem;
}

h3 {
    font-size: 1.15rem;
}

h4 {
    font-size: 1.05rem;
}

h5 {
    font-size: 1rem;
}

h6 {
    font-size: 0.9rem;
}

p {
    margin-bottom: var(--spacing-sm);
}

a {
    color: var(--link-color);
    text-decoration: none;
    transition: color var(--transition-base);
}

a:hover {
    color: var(--link-hover);
    text-decoration: underline;
}

/* Anchors acting as controls (buttons, nav items) keep their own styling —
   the link underline is for inline text links only. */
a.btn:hover,
a.nav-link:hover,
.nav-link:hover {
    text-decoration: none;
}

/* ============================================================
UTILITY CLASSES
============================================================ */

/* Small uppercase section label (FA-style) */
.section-label {
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
}

/* Text Colors */
.text-primary { color: var(--text-strong) !important; }
.text-white { color: var(--color-white) !important; }
.text-muted { color: var(--text-muted) !important; }
.text-success { color: var(--tint-success-text) !important; }
.text-danger { color: var(--tint-danger-text) !important; }
.text-warning { color: var(--tint-warning-text) !important; }

/* Background Colors */
.bg-primary { background-color: var(--color-primary) !important; }
.bg-white { background-color: var(--surface-card) !important; }
.bg-gray-50 { background-color: var(--color-gray-50) !important; }

/* Shadows */
.shadow-xs { box-shadow: var(--shadow-xs) !important; }
.shadow-sm { box-shadow: var(--shadow-sm) !important; }
.shadow-md { box-shadow: var(--shadow-md) !important; }
.shadow-lg { box-shadow: var(--shadow-lg) !important; }
.shadow-xl { box-shadow: var(--shadow-xl) !important; }

/* Border Radius */
.rounded-sm { border-radius: var(--radius-sm) !important; }
.rounded-md { border-radius: var(--radius-md) !important; }
.rounded-lg { border-radius: var(--radius-lg) !important; }
.rounded-xl { border-radius: var(--radius-xl) !important; }
.rounded-full { border-radius: var(--radius-full) !important; }

/* Spacing Utilities */
.m-0 { margin: 0 !important; }
.mt-1 { margin-top: var(--spacing-xs) !important; }
.mt-2 { margin-top: var(--spacing-sm) !important; }
.mt-3 { margin-top: var(--spacing-md) !important; }
.mt-4 { margin-top: var(--spacing-lg) !important; }
.mb-1 { margin-bottom: var(--spacing-xs) !important; }
.mb-2 { margin-bottom: var(--spacing-sm) !important; }
.mb-3 { margin-bottom: var(--spacing-md) !important; }
.mb-4 { margin-bottom: var(--spacing-lg) !important; }

.p-0 { padding: 0 !important; }
.p-1 { padding: var(--spacing-xs) !important; }
.p-2 { padding: var(--spacing-sm) !important; }
.p-3 { padding: var(--spacing-md) !important; }
.p-4 { padding: var(--spacing-lg) !important; }

/* Display */
.d-none { display: none !important; }
.d-block { display: block !important; }
.d-flex { display: flex !important; }
.d-grid { display: grid !important; }

/* Flexbox */
.flex-row { flex-direction: row !important; }
.flex-column { flex-direction: column !important; }
.flex-wrap { flex-wrap: wrap !important; }
.flex-nowrap { flex-wrap: nowrap !important; }
.justify-center { justify-content: center !important; }
.justify-between { justify-content: space-between !important; }
.justify-around { justify-content: space-around !important; }
.align-center { align-items: center !important; }
.align-start { align-items: flex-start !important; }
.align-end { align-items: flex-end !important; }
.gap-1 { gap: var(--spacing-xs) !important; }
.gap-2 { gap: var(--spacing-sm) !important; }
.gap-3 { gap: var(--spacing-md) !important; }
.gap-4 { gap: var(--spacing-lg) !important; }

/* Text Alignment */
.text-left { text-align: left !important; }
.text-center { text-align: center !important; }
.text-right { text-align: right !important; }

/* Font Weight */
.font-normal { font-weight: 400 !important; }
.font-medium { font-weight: 500 !important; }
.font-semibold { font-weight: 600 !important; }
.font-bold { font-weight: 700 !important; }

/* Width */
.w-full { width: 100% !important; }
.w-auto { width: auto !important; }
.w-100 { width: 100% !important; }

/* ============================================================
BOOTSTRAP-CONVENTION UTILITIES
Bootstrap's CSS is not loaded, but many pages use its class
names — these aliases make them work with the theme tokens.
============================================================ */
.justify-content-between { justify-content: space-between !important; }
.justify-content-center { justify-content: center !important; }
.justify-content-end { justify-content: flex-end !important; }
.align-items-center { align-items: center !important; }
.align-items-start { align-items: flex-start !important; }
.align-items-end { align-items: flex-end !important; }
.flex-grow-1 { flex: 1 1 auto !important; min-width: 0; }
.flex-shrink-0 { flex-shrink: 0 !important; }
.ms-auto { margin-left: auto !important; }
.me-auto { margin-right: auto !important; }
.text-nowrap { white-space: nowrap !important; }
.text-end { text-align: right !important; }
.text-start { text-align: left !important; }
.small { font-size: 0.85rem; }

.form-text {
    display: block;
    margin-top: 0.35rem;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.form-control-sm,
.form-select-sm {
    padding: 0.4rem 0.65rem !important;
    font-size: 0.85rem !important;
}

/* List groups (used by checklists, managed lists, detail pages) */
.list-group {
    list-style: none;
    margin: 0;
    padding: 0;
    background: var(--surface-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.list-group-flush {
    background: transparent;
    border: none;
    border-radius: 0;
}

.list-group-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.7rem 1rem;
    color: var(--text-body);
    background: transparent;
    border-bottom: 1px solid var(--border-subtle);
}

.list-group-item:last-child {
    border-bottom: none;
}

/* Soft badge variants (bootstrap-convention names, theme-aware) */
.badge.bg-light {
    background: var(--surface-inset) !important;
    color: var(--text-muted) !important;
    border: 1px solid var(--border-strong) !important;
}

.badge.bg-info-subtle {
    background: var(--tint-info-bg) !important;
    color: var(--tint-info-text) !important;
    border: 1px solid var(--border-strong) !important;
}

.text-dark { color: var(--text-strong) !important; }

/* ============================================================
THEME TOGGLE BUTTON (rendered in the top bar)
============================================================ */
.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.15rem;
    height: 2.15rem;
    padding: 0;
    font-size: 1rem;
    color: var(--on-brand-muted);
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: var(--radius-full);
    cursor: pointer;
    transition: all var(--transition-base);
    flex-shrink: 0;
}

.theme-toggle:hover {
    color: var(--color-accent-orange);
    border-color: var(--border-gold);
    background: rgba(255, 255, 255, 0.12);
    transform: rotate(15deg);
}

.theme-toggle:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--focus-ring);
}

/* Icon swap is CSS-driven so Blazor re-renders can't desync it */
.theme-toggle .icon-dark { display: none; }
.theme-toggle .icon-light { display: block; }
html[data-theme="dark"] .theme-toggle .icon-dark { display: block; }
html[data-theme="dark"] .theme-toggle .icon-light { display: none; }

/* ============================================================
NAV TOGGLE (hamburger — visible only in drawer mode, ≤900px)
============================================================ */
.nav-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 2.4rem;
    height: 2.4rem;
    padding: 0;
    font-size: 1.35rem;
    color: var(--on-brand);
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-base);
    flex-shrink: 0;
}

.nav-toggle:hover {
    color: var(--color-accent-orange);
    border-color: var(--border-gold);
    background: rgba(255, 255, 255, 0.12);
}

.nav-toggle:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--focus-ring);
}

@media (max-width: 900px) {
    .nav-toggle {
        display: inline-flex;
    }
}

/* ============================================================
BLAZOR ERROR UI
============================================================ */
#blazor-error-ui {
    background: linear-gradient(135deg, var(--color-accent-red) 0%, var(--color-accent-red-hover) 100%);
    color: var(--color-white);
    padding: var(--spacing-sm);
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: var(--z-modal);
    display: none;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
    box-shadow: var(--shadow-xl);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

#blazor-error-ui.show {
    display: flex;
}

#blazor-error-ui .reload,
#blazor-error-ui .dismiss {
    color: var(--color-white);
    text-decoration: underline;
    cursor: pointer;
    font-weight: 600;
    padding: var(--spacing-xs) var(--spacing-sm);
    border-radius: var(--radius-sm);
    transition: background var(--transition-base);
}

#blazor-error-ui .reload:hover,
#blazor-error-ui .dismiss:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* ============================================================
RESPONSIVE BREAKPOINTS
============================================================ */

/* Tablet and below */
@media (max-width: 992px) {
    :root {
        --sidebar-width: 272px;
    }

    h1 { font-size: 1.45rem; }
    h2 { font-size: 1.3rem; }
    h3 { font-size: 1.1rem; }
}

/* Drawer mode: the sidebar leaves the layout flow (opened via the hamburger) */
@media (max-width: 900px) {
    :root {
        --sidebar-width: 0;
    }
}

/* Mobile */
@media (max-width: 600px) {
    :root {
        --topbar-height: 65px;
    }

    html {
        font-size: 14px;
    }

    h1 { font-size: 1.35rem; }
    h2 { font-size: 1.2rem; }
    h3 { font-size: 1.05rem; }
}

/* Print styles */
@media print {
    body {
        background: white;
        background-image: none;
    }

    .no-print {
        display: none !important;
    }
}

/* ============================================================
   CONFIRMATION DIALOG (shared delete confirmation modal)
   ============================================================ */
.modal-backdrop-custom {
    position: fixed;
    inset: 0;
    background: rgba(10, 18, 28, 0.60);
    backdrop-filter: blur(3px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1080;
    padding: 1rem;
}

.confirm-dialog {
    background: var(--surface-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    max-width: 460px;
    width: 100%;
    padding: 1.5rem 1.75rem;
    animation: confirm-pop 0.15s ease-out;
}

@keyframes confirm-pop {
    from {
        opacity: 0;
        transform: translateY(8px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.confirm-dialog h3 {
    margin: 0 0 0.75rem;
    font-size: 1.2rem;
    font-family: var(--font-body);
    font-weight: 600;
    color: var(--text-strong);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.confirm-dialog p {
    margin: 0 0 1.25rem;
    color: var(--text-muted);
    line-height: 1.5;
}

.confirm-dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
}

.dept-tree-delete {
    margin-left: auto;
    padding: 0.1rem 0.45rem;
    line-height: 1;
}
