﻿/**
 * Shift Scheduler - Professional Design System
 * Based on ShiftManager/ShiftMaster UI patterns
 */

/* ============================================================================
   PALETTE LAYER — raw named colors.
   Swap the active block via <html data-theme="earthy">.
   Add new themes by adding another [data-theme] block with the same variable
   names; the semantic layer below will repaint automatically.
   ============================================================================ */

:root,
[data-theme="default"] {
    /* Brand — Emerald (single accent per ui.md) */
    --c-brand:        #10b981;
    --c-brand-strong: #059669;
    --c-brand-soft:   #d1fae5;
    --c-brand-alpha:  rgba(16, 185, 129, 0.1);
    --c-brand-rgb:    16, 185, 129;
    --c-brand-accent: #34d399;          /* lighter emerald — paired stop for gradients */

    /* Status — Emerald success (shares the brand hue), amber warning, red danger */
    --c-success:        #10b981;
    --c-success-strong: #059669;
    --c-success-soft:   #d1fae5;
    --c-success-rgb:    16, 185, 129;

    --c-warning:        #f59e0b;
    --c-warning-strong: #d97706;
    --c-warning-soft:   #fef3c7;
    --c-warning-rgb:    245, 158, 11;

    --c-danger:         #ef4444;
    --c-danger-strong:  #dc2626;
    --c-danger-soft:    #fee2e2;
    --c-danger-rgb:     239, 68, 68;

    /* Info — de-emphasized (blue "almost never appears" per ui.md); kept as a
       neutral slate so any legacy .info usage stays legible without shouting. */
    --c-info:           #64748b;
    --c-info-strong:    #475569;
    --c-info-soft:      #e2e8f0;
    --c-info-rgb:       100, 116, 139;

    /* Purple — categorical accent (workflow "control" step, tags), not tied
       to a semantic status like success/warning/danger. */
    --c-purple:         #7c3aed;
    --c-purple-strong:  #6d28d9;
    --c-purple-soft:    #ede9fe;
    --c-purple-rgb:     124, 58, 237;

    /* Surfaces / ink (ui.md neutrals) */
    --c-paper:        #ffffff;
    --c-paper-alt:    #f9fafb;
    --c-bg:           #f6f7f9;           /* very slightly gray, never pure white */
    --c-bg-alt:       #eef0f3;

    --c-ink:          #1f2937;           /* body text primary */
    --c-ink-heading:  #111827;           /* dark slate — headings/icons/important text */
    --c-ink-secondary:#6b7280;
    --c-ink-muted:    #9ca3af;
    --c-ink-inverse:  #ffffff;

    --c-line:         #ececec;           /* very subtle borders */
    --c-line-light:   #f3f4f6;
    --c-line-dark:    #e0e0e0;

    --c-shell:        #ffffff;           /* sidebar bg — white per ui.md */
    --c-shell-strong: #f9fafb;           /* paired subtle tone */
    --c-shell-border: #ececec;
}

/* ============================================================================
   SEMANTIC LAYER — purpose-based tokens that the rest of the app references.
   Every value here resolves through the palette layer above, so a [data-theme]
   change repaints everything automatically.
   ============================================================================ */
:root {
    /* Brand */
    --primary:       var(--c-brand);
    --primary-hover: var(--c-brand-strong);
    --primary-light: var(--c-brand-soft);
    --primary-soft:  var(--c-brand-alpha);

    /* Status */
    --success:       var(--c-success);
    --success-light: var(--c-success-soft);
    --success-dark:  var(--c-success-strong);

    --warning:       var(--c-warning);
    --warning-light: var(--c-warning-soft);
    --warning-dark:  var(--c-warning-strong);

    --danger:        var(--c-danger);
    --danger-light:  var(--c-danger-soft);
    --danger-dark:   var(--c-danger-strong);

    --info:          var(--c-info);
    --info-light:    var(--c-info-soft);
    --info-dark:     var(--c-info-strong);

    /* Purple — categorical accent (not a semantic status). */
    --purple:        var(--c-purple);
    --purple-light:  var(--c-purple-soft);
    --purple-dark:   var(--c-purple-strong);

    /* RGB triplets — pair with rgba(var(--xxx-rgb), alpha) for theme-aware
       translucent fills (focus rings, soft hovers, alert borders, etc.). */
    --primary-rgb: var(--c-brand-rgb);
    --success-rgb: var(--c-success-rgb);
    --warning-rgb: var(--c-warning-rgb);
    --danger-rgb:  var(--c-danger-rgb);
    --info-rgb:    var(--c-info-rgb);
    --purple-rgb:  var(--c-purple-rgb);

    /* Backgrounds & surfaces */
    --bg:               var(--c-bg);
    --bg-alt:           var(--c-bg-alt);
    --surface:          var(--c-paper);
    --surface-alt:      var(--c-paper-alt);
    --surface-elevated: var(--c-paper);

    /* Borders */
    --border:       var(--c-line);
    --border-light: var(--c-line-light);
    --border-dark:  var(--c-line-dark);
    --border-color: var(--c-line);   /* dedupe alias for legacy --border-color usage */

    /* Text */
    --text:           var(--c-ink);
    --text-heading:   var(--c-ink-heading);
    --text-secondary: var(--c-ink-secondary);
    --text-muted:     var(--c-ink-muted);
    --text-inverse:   var(--c-ink-inverse);

    /* Sidebar — white shell per ui.md; solid-Emerald active item */
    --sidebar-bg:             var(--c-shell);
    --sidebar-width:          260px;
    --sidebar-collapsed-width: 64px;
    --sidebar-text:           var(--c-ink-secondary);
    --sidebar-text-active:    #ffffff;
    --sidebar-hover:          var(--c-bg-alt);
    --sidebar-active-bg:      var(--primary);
    --sidebar-border:         var(--c-shell-border);

    /* Header */
    --header-height: 72px;

    /* Typography */
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;

    --text-xs:   0.75rem;     /* 12px — small labels */
    --text-sm:   0.875rem;    /* 14px */
    --text-base: 0.9375rem;   /* 15px — body */
    --text-lg:   1.125rem;    /* 18px */
    --text-xl:   1.25rem;     /* 20px — card title */
    --text-2xl:  1.5rem;      /* 24px — section */
    --text-3xl:  2.25rem;     /* 36px — dashboard/page title */
    --text-4xl:  2.75rem;     /* 44px */

    /* Spacing */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.25rem;
    --space-6: 1.5rem;       /* 24px — card interior / around components */
    --space-7: 1.75rem;      /* 28px — roomier card interior */
    --space-8: 2rem;         /* 32px — between sections */
    --space-10: 2.5rem;      /* 40px — between groups */
    --space-12: 3rem;

    /* Border Radius (ui.md: cards 20px, buttons/inputs 12px, search 14px) */
    --radius-sm:   0.375rem;  /* 6px */
    --radius:      0.75rem;   /* 12px — buttons, inputs */
    --radius-md:   0.875rem;  /* 14px — search, dashboard tiles */
    --radius-lg:   1.25rem;   /* 20px — cards, charts */
    --radius-xl:   1.5rem;    /* 24px */
    --radius-full: 9999px;

    /* Shadows — very soft / almost invisible per ui.md */
    --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.03);
    --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.04);
    --shadow:    0 8px 30px rgba(15, 23, 42, 0.06);
    --shadow-md: 0 8px 30px rgba(15, 23, 42, 0.06);
    --shadow-lg: 0 20px 45px rgba(15, 23, 42, 0.08);

    /* Transitions (ui.md: 180ms ease-out on hover interactions) */
    --transition-fast: 150ms ease;
    --transition:      180ms ease-out;
    --transition-slow: 300ms ease;

    /* ------------------------------------------------------------------------
       Bootstrap variable bridge — Bootstrap components inherit the active theme.
       ------------------------------------------------------------------------ */
    --bs-primary:          var(--primary);
    --bs-primary-rgb:      var(--primary-rgb); /* themed via the palette layer */
    --bs-success:          var(--success);
    --bs-success-rgb:      var(--success-rgb);
    --bs-warning:          var(--warning);
    --bs-warning-rgb:      var(--warning-rgb);
    --bs-danger:           var(--danger);
    --bs-danger-rgb:       var(--danger-rgb);
    --bs-info:             var(--info);
    --bs-info-rgb:         var(--info-rgb);

    --bs-body-bg:          var(--bg);
    --bs-body-color:       var(--text);
    --bs-secondary-color:  var(--text-secondary);
    --bs-tertiary-bg:      var(--surface-alt);
    --bs-emphasis-color:   var(--text);

    --bs-border-color:     var(--border);
    --bs-border-radius:    var(--radius);
    --bs-border-radius-sm: var(--radius-sm);
    --bs-border-radius-lg: var(--radius-lg);

    --bs-link-color:       var(--primary);
    --bs-link-hover-color: var(--primary-hover);

    --bs-font-sans-serif:  var(--font-family);
    --bs-box-shadow-sm:    var(--shadow-sm);
    --bs-box-shadow:       var(--shadow-md);
}

/* Bootstrap rgb helpers (--bs-*-rgb) are wired to the active theme through the
   palette layer above (--c-*-rgb), so no per-theme override block is needed. */

/* ============================================
   Reset & Base
   ============================================ */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

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

body {
    font-family: var(--font-family);
    font-size: var(--text-sm);
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    min-height: 100vh;
    overflow-x: hidden;
}

h1, h2, h3, h4, h5, h6 {
    color: var(--text-heading);
    font-weight: 700;
    line-height: 1.25;
    letter-spacing: -0.01em;
}

a {
    color: var(--primary);
    text-decoration: none;
    transition: color var(--transition-fast);
}

a:hover {
    color: var(--primary-hover);
}

img, svg {
    display: block;
    max-width: 100%;
}

button {
    font-family: inherit;
    cursor: pointer;
}

input, select, textarea {
    font-family: inherit;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* Material Symbols */
.material-symbols-outlined {
    font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
    font-size: 20px;
    line-height: 1;
    vertical-align: middle;
}

/* ============================================
   App Layout
   ============================================ */
.app-layout {
    display: flex;
    min-height: 100vh;
}

.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: margin-left var(--transition);
}

.content-wrapper {
    flex: 1;
    width: 100%;
    padding: var(--space-6) var(--space-8);
}

/* ============================================
   Sidebar - White Shell (ui.md)
   ============================================ */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-border);
    display: flex;
    flex-direction: column;
    z-index: 1000;
    transition: width var(--transition), transform var(--transition);
    overflow: hidden;
}

/* Logo Section */
.sidebar-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 var(--space-5);
    border-bottom: 1px solid var(--sidebar-border);
}

.logo {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    text-decoration: none;
}

.logo-icon {
    width: 32px;
    height: 32px;
    background: var(--primary);
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    color: white;
    flex-shrink: 0;
    overflow: hidden;
}

.logo-icon .sidebar-logo-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: transparent;
}

.logo-text {
    font-size: var(--text-lg);
    font-weight: 700;
    color: var(--text-heading);
    letter-spacing: -0.02em;
}

/* Navigation */
.sidebar-nav {
    flex: 1;
    padding: var(--space-4) var(--space-3);
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar-nav::-webkit-scrollbar {
    width: 4px;
}

.sidebar-nav::-webkit-scrollbar-thumb {
    background: var(--sidebar-border);
    border-radius: var(--radius-full);
}

.nav-section {
    margin-bottom: var(--space-5);
}

.nav-section-title {
    display: block;
    padding: var(--space-2) var(--space-3);
    font-size: var(--text-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--sidebar-text);
    opacity: 0.6;
}

.sidebar-nav ul {
    list-style: none;
}

.sidebar-nav li a {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3);
    margin-bottom: var(--space-3);
    color: var(--sidebar-text);
    font-size: var(--text-sm);
    font-weight: 500;
    border-radius: var(--radius);
    transition: all var(--transition-fast);
}

.sidebar-nav li a:hover {
    background: var(--sidebar-hover);
    color: var(--text-heading);
}

.sidebar-nav li a.active {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-text-active);
}

.sidebar-nav li a.active .nav-icon,
.sidebar-nav li a.active .material-symbols-outlined {
    color: var(--sidebar-text-active);
}

.nav-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    font-size: 22px;
    flex-shrink: 0;
}

.nav-icon .material-symbols-outlined {
    font-size: 22px;
}

.nav-label {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex: 1;
}

.nav-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 6px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    background: linear-gradient(135deg, var(--success) 0%, var(--success-dark) 100%);
    color: white;
    border-radius: var(--radius-sm);
    line-height: 1;
    box-shadow: 0 2px 4px rgba(var(--success-rgb), 0.2);
}

.sidebar-nav li a.active .nav-badge {
    background: rgba(255, 255, 255, 0.25);
    color: #ffffff;
    box-shadow: none;
}

/* Submenu */
.submenu-toggle {
    position: relative;
}

.submenu-arrow {
    margin-left: auto;
    display: flex;
    align-items: center;
    transition: transform var(--transition-fast);
}

.submenu-toggle.active .submenu-arrow,
.submenu-toggle[aria-expanded="true"] .submenu-arrow {
    transform: rotate(180deg);
}

.submenu {
    max-height: 0;
    overflow: hidden;
    transition: max-height var(--transition-fast) ease-out;
    margin: 0;
    padding: 0;
    list-style: none;
}

.submenu.show {
    max-height: 500px;
    transition: max-height var(--transition-fast) ease-in;
}

.submenu li {
    margin: 0;
}

.submenu li a {
    padding: var(--space-2) var(--space-3) var(--space-2) var(--space-12);
    font-size: var(--text-sm);
}

.submenu li a:hover {
    background: var(--sidebar-hover);
}

.submenu li a.active {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-text-active);
}

/* Sidebar Footer */
.sidebar-footer {
    padding: var(--space-4);
    border-top: 1px solid var(--sidebar-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.user-info {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    flex: 1;
    min-width: 0;
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    background: linear-gradient(135deg, var(--primary) 0%, var(--c-brand-accent) 100%);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: var(--text-sm);
    flex-shrink: 0;
}

.user-details {
    flex: 1;
    min-width: 0;
}

.user-name {
    display: block;
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--text-heading);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-role {
    display: block;
    font-size: var(--text-xs);
    color: var(--sidebar-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.logout-form {
    margin: 0;
    padding: 0;
    line-height: 0;
}

.logout-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: var(--radius);
    color: var(--sidebar-text);
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    transition: all var(--transition-fast);
}

.logout-btn:hover {
    background: rgba(var(--danger-rgb), 0.15);
    color: var(--danger);
}

/* ============================================
   Header - Clean Top Bar
   ============================================ */
.header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 var(--space-6);
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    box-shadow: var(--shadow-xs);
}

.header-left {
    display: flex;
    align-items: center;
    gap: var(--space-4);
}

.header-right {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.sidebar-toggle {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    width: 32px;
    height: 32px;
    padding: 6px;
    background: none;
    border: none;
    cursor: pointer;
    border-radius: var(--radius);
}

.sidebar-toggle span {
    display: block;
    width: 100%;
    height: 2px;
    background: var(--text-secondary);
    border-radius: var(--radius-full);
    transition: var(--transition-fast);
}

.sidebar-toggle:hover {
    background: var(--bg);
}

.sidebar-toggle:hover span {
    background: var(--text);
}

.page-title {
    font-size: var(--text-lg);
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.02em;
}

/* Search */
.header-search {
    display: flex;
    align-items: center;
    height: 46px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
    transition: all var(--transition-fast);
}

.header-search:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}

.header-search .search-input {
    width: 220px;
    padding: var(--space-2) var(--space-3);
    border: none;
    background: transparent;
    font-size: var(--text-sm);
    color: var(--text);
    outline: none;
    transition: width var(--transition);
}

.header-search .search-input::placeholder {
    color: var(--text-muted);
}

.header-search:focus-within .search-input {
    width: 280px;
}

.header-search .search-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--text-muted);
    padding: var(--space-2);
    cursor: pointer;
    transition: color var(--transition-fast);
}

.header-search .search-btn:hover {
    color: var(--primary);
}

/* Header Date */
.header-date {
    font-size: var(--text-sm);
    color: var(--text-secondary);
    font-weight: 500;
    display: none;
}

/* Theme switcher (in header) */
@media (min-width: 1024px) {
    .header-date {
        display: block;
    }
}

/* Icon Buttons */
.icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-secondary);
    transition: all var(--transition-fast);
}

.icon-btn:hover {
    background: var(--surface);
    border-color: var(--border-dark);
    color: var(--text);
}

/* Notification Bell */
.notification-bell {
    position: relative;
}

.notification-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: var(--bg);
    border: none;
    border-radius: var(--radius);
    font-size: 1rem;
    color: var(--text-secondary);
    transition: all var(--transition-fast);
}

.notification-btn:hover {
    background: var(--border);
    color: var(--text);
}

.notification-badge {
    position: absolute;
    top: 2px;
    right: 2px;
    min-width: 8px;
    height: 8px;
    background: var(--danger);
    border-radius: var(--radius-full);
    border: 2px solid var(--surface);
}

.notification-dropdown {
    display: none;
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    width: 340px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

.notification-bell.active .notification-dropdown {
    display: block;
    animation: dropdownSlide 0.15s ease;
}

@keyframes dropdownSlide {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.dropdown-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-4);
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    font-size: var(--text-sm);
}

.dropdown-header a {
    font-size: var(--text-xs);
    font-weight: 500;
}

.dropdown-body {
    max-height: 300px;
    overflow-y: auto;
    padding: var(--space-2);
}

.dropdown-item {
    display: flex;
    gap: var(--space-3);
    padding: var(--space-3);
    text-decoration: none;
    color: inherit;
    border-radius: var(--radius);
    transition: background var(--transition-fast);
}

.dropdown-item:hover {
    background: var(--bg);
}

.dropdown-item-icon {
    width: 32px;
    height: 32px;
    background: var(--primary-light);
    color: var(--primary);
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.875rem;
    flex-shrink: 0;
}

.dropdown-item-content {
    flex: 1;
    min-width: 0;
}

.dropdown-item-title {
    font-weight: 500;
    font-size: var(--text-sm);
    color: var(--text);
    margin-bottom: 2px;
}

.dropdown-item-text {
    font-size: var(--text-xs);
    color: var(--text-muted);
}

/* Header Profile */
.header-profile {
    position: relative;
}

.profile-link {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: 2px;
    border-radius: var(--radius-full);
    transition: background var(--transition-fast);
}

.profile-link:hover {
    background: var(--bg);
}

.profile-avatar {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    background: linear-gradient(135deg, var(--primary) 0%, var(--c-brand-accent) 100%);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: var(--text-sm);
    border: 2px solid var(--surface);
    box-shadow: var(--shadow-sm);
}

/* ============================================================================
   Card system — one shell + composable modifiers.

   Base shell is the same surface/border/radius/shadow we used to ship as
   `.card` and `.stat-card`. Modifiers follow the `is-*` / `accent-*` /
   `tone-*` convention from `.form-page-icon` so anyone can build a new
   variant by combining classes instead of re-inventing CSS.

   Usage cheat-sheet
   -----------------
     <div class="card">                                   plain panel
     <div class="card card-body">                         padded one-shot card
     <div class="card is-stat accent-primary">            KPI / stat tile
     <div class="card is-compact is-interactive">         small clickable tile
     <div class="card tone-warning">                      tinted alert-style card
     <div class="card-grid">...stat cards...</div>        responsive 4-up grid

   `.card-icon`  — the rounded-square Material/icon badge inside cards.
                   `.is-soft` is the muted variant; `accent-*` recolours.
   ============================================================================ */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    transition: box-shadow var(--transition), transform var(--transition);
}

/* Generic cards get a soft shadow bump on hover; small tiles / clickable cards
   (.is-stat, .is-hoverable, or an <a> wrapped as a card) also lift -2px per
   ui.md ("cards lift slightly", 180ms ease-out). Full-width content/form
   panels intentionally don't jump. */
.card:hover {
    box-shadow: var(--shadow);
}
.card.is-stat:hover,
.card.is-hoverable:hover,
a.card:hover {
    transform: translateY(-2px);
}

@media (prefers-reduced-motion: reduce) {
    .card,
    .card:hover,
    .card.is-stat,
    .card.is-stat:hover,
    .card.is-hoverable:hover,
    a.card:hover {
        transform: none;
        transition: none;
    }
}

.card-header {
    padding: var(--space-5) var(--space-6);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
}

.card-title {
    font-size: var(--text-xl);
    font-weight: 700;
    color: var(--text-heading);
    letter-spacing: -0.02em;
}

.card-subtitle {
    font-size: var(--text-sm);
    color: var(--text-secondary);
    margin-top: 2px;
}

.card-body {
    padding: var(--space-6);
}

.card-footer {
    padding: var(--space-4) var(--space-6);
    border-top: 1px solid var(--border);
    background: var(--bg);
}

/* --- Modifiers ---------------------------------------------------------- */

/* Stat / KPI tile (replaces the old `.stat-card`). Compact, uniform, and flat
   — no coloured stripe. The `accent-*` modifiers are kept as no-ops for
   backward compatibility (they used to paint a top stripe); the accent now
   only shows through the soft icon tile colour. */
.card.is-stat {
    padding: var(--space-3);
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: var(--space-2);
    transition: box-shadow var(--transition-fast);
}
.card.is-stat:hover {
    box-shadow: var(--shadow);
}

/* Hoverable / clickable card. */
.card.is-interactive {
    transition: transform var(--transition-fast), box-shadow var(--transition-fast), border-color var(--transition-fast);
    cursor: pointer;
}
.card.is-interactive:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--primary);
}

/* Compact: tighter paddings on header / body — used for detail / step / type
   cards that need to fit inside a narrower layout. */
.card.is-compact { padding: var(--space-4); }
.card.is-compact .card-header,
.card.is-compact .card-body  { padding: var(--space-4); }
.card.is-compact .card-footer { padding: var(--space-3) var(--space-4); }

/* Bare: no border / shadow / surface — useful when the card sits inside a
   parent that already provides those (e.g. inside another card). */
.card.is-bare {
    border: 0;
    box-shadow: none;
    background: transparent;
}

.card.is-elevated { box-shadow: var(--shadow-md); }

/* Flush body: drop the card-body padding — used when the card wraps a
   full-bleed element (a table, for example) that provides its own padding. */
.card-body.is-flush { padding: 0; }

/* Positions the card as an anchor for an absolutely-positioned overlay
   (e.g. .loading-overlay) without reaching for an inline style. */
.card.has-overlay { position: relative; }

/* Tinted variants for "callout" cards (warnings, info notes, success
   confirmations). Uses the soft palette tokens so the contrast stays right
   when the theme switches. */
.card.tone-primary { background: var(--primary-light); border-color: var(--primary-light); }
.card.tone-success { background: var(--success-light); border-color: var(--success-light); }
.card.tone-warning { background: var(--warning-light); border-color: var(--warning-light); }
.card.tone-danger  { background: var(--danger-light);  border-color: var(--danger-light); }
.card.tone-info    { background: var(--info-light);    border-color: var(--info-light); }

/* Rounded-square icon badge for card headers / stat tiles. */
.card-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--radius);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    flex-shrink: 0;
    color: var(--text-inverse);
    background: var(--primary);
}
.card-icon .material-symbols-outlined { font-size: 22px; }

/* Soft variant — light tinted background, coloured glyph. */
.card-icon.is-soft { background: var(--primary-light); color: var(--primary); }

.card-icon.accent-primary { background: var(--primary); color: var(--text-inverse); }
.card-icon.accent-success { background: var(--success); color: var(--text-inverse); }
.card-icon.accent-warning { background: var(--warning); color: var(--text-inverse); }
.card-icon.accent-danger  { background: var(--danger);  color: var(--text-inverse); }
.card-icon.accent-info    { background: var(--info);    color: var(--text-inverse); }

.card-icon.accent-primary.is-soft { background: var(--primary-light); color: var(--primary); }
.card-icon.accent-success.is-soft { background: var(--success-light); color: var(--success-dark); }
.card-icon.accent-warning.is-soft { background: var(--warning-light); color: var(--warning-dark); }
.card-icon.accent-danger.is-soft  { background: var(--danger-light);  color: var(--danger-dark); }
.card-icon.accent-info.is-soft    { background: var(--info-light);    color: var(--info-dark); }

/* Responsive grid for stat tiles (replaces page-local `.stats-row` redos).
   The 220px floor + explicit breakpoints keep 5–6 tile pages on one row at
   desktop and collapse cleanly (4→3→2→1) as the viewport shrinks. */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: var(--space-3);
    margin-bottom: var(--space-5);
}

/* Opt-in 6-up variant for pages that ship exactly 6 stat tiles
   (e.g. payroll/periods/index) so they sit on one row at desktop. */
.card-grid.is-6up {
    grid-template-columns: repeat(6, 1fr);
}

@media (max-width: 1280px) {
    .card-grid { grid-template-columns: repeat(4, 1fr); }
    .card-grid.is-6up { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 1024px) {
    .card-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 768px) {
    .card-grid { grid-template-columns: repeat(2, 1fr); }
    .card-grid.is-6up { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 480px) {
    .card-grid { grid-template-columns: 1fr; }
}

/* Legacy `.stats-row` kept as an alias for views that still reference it. */
.stats-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-4);
    margin-bottom: var(--space-6);
}

@media (max-width: 1280px) {
    .stats-row {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 640px) {
    .stats-row {
        grid-template-columns: 1fr;
    }
}

/* ----------------------------------------------------------------------------
   Backward-compat: a number of pages (dashboard, departments/index,
   positions/index, employers/index, contracts/index) still use the older
   `.stat-card` markup directly. We alias them onto `.card.is-stat` +
   `.accent-*` so they pick up the unified chrome without view changes.
   New code should use `.card.is-stat.accent-*` directly.
   ---------------------------------------------------------------------------- */
/* `.stat-card` is a deprecated alias for `.card.is-stat` — kept only so any
   view that hasn't been migrated yet doesn't render unstyled. Do not use it
   for new markup; use `.card.is-stat` (or the `components.stat-card`
   partial) so every KPI tile in the app shares one definition. */
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: var(--space-3);
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: var(--space-2);
    transition: box-shadow var(--transition-fast);
}
.stat-card:hover { box-shadow: var(--shadow); }

.stat-icon {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    flex-shrink: 0;
}

.stat-icon.primary { background: var(--primary-light); color: var(--primary); }
.stat-icon.success { background: var(--success-light); color: var(--success); }
.stat-icon.warning { background: var(--warning-light); color: var(--warning); }
.stat-icon.danger  { background: var(--danger-light);  color: var(--danger); }
.stat-icon.info    { background: var(--info-light);    color: var(--info); }
.stat-icon.purple  { background: var(--purple-light); color: var(--purple-dark); }
/* Bare .stat-icon (no variant) falls back to a soft primary tile. */
.stat-icon:not(.primary):not(.success):not(.warning):not(.danger):not(.info):not(.purple) {
    background: var(--primary-light);
    color: var(--primary);
}

.stat-content {
    flex: 1;
    min-width: 0;
}

.stat-label {
    font-size: 0.6875rem;
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 2px;
}

.stat-value {
    font-size: var(--text-lg);
    font-weight: 700;
    color: var(--text-heading);
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.stat-change {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    font-size: 0.6875rem;
    font-weight: 600;
    margin-top: 2px;
}

.stat-change .material-symbols-outlined {
    font-size: 14px;
}

.stat-change.positive { color: var(--success); }
.stat-change.negative { color: var(--danger); }

/* Plain muted caption under a stat value (e.g. "available to take") — use
   this instead of `.stat-change` when there's no positive/negative delta. */
.stat-hint {
    display: block;
    font-size: 0.6875rem;
    color: var(--text-muted);
    margin-top: 2px;
}

/* Lets a whole `.card.is-stat` act as a plain link (e.g. a KPI tile that
   navigates somewhere) without the anchor's default blue/underline. */
a.card.is-stat {
    color: inherit;
    text-decoration: none;
}

/* ============================================
   Welcome Banner
   ============================================ */
.welcome-banner {
    background: linear-gradient(135deg, var(--primary) 0%, var(--c-brand-accent) 100%);
    border-radius: var(--radius-lg);
    padding: var(--space-6) var(--space-8);
    margin-bottom: var(--space-6);
    position: relative;
    overflow: hidden;
    color: white;
}

.welcome-banner::before {
    content: '';
    position: absolute;
    top: -50%;
    right: -10%;
    width: 300px;
    height: 300px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-full);
}

.welcome-banner::after {
    content: '';
    position: absolute;
    bottom: -30%;
    right: 10%;
    width: 150px;
    height: 150px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: var(--radius-full);
}

.welcome-content {
    position: relative;
    z-index: 1;
    max-width: 600px;
}

.welcome-title {
    font-size: var(--text-2xl);
    font-weight: 700;
    margin-bottom: var(--space-2);
    letter-spacing: -0.02em;
}

.welcome-text {
    font-size: var(--text-base);
    opacity: 0.9;
    margin-bottom: var(--space-5);
    line-height: 1.6;
}

.welcome-btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    background: white;
    color: var(--primary);
    font-weight: 600;
    font-size: var(--text-sm);
    border-radius: var(--radius);
    transition: all var(--transition-fast);
    box-shadow: var(--shadow-sm);
}

.welcome-btn:hover {
    background: var(--surface-alt);
    transform: translateY(-1px);
    box-shadow: var(--shadow);
    color: var(--primary);
}

/* ============================================================================
   Buttons — Bootstrap is canonical.

   The Bootstrap `.btn` / `.btn-primary` / `.btn-secondary` / `.btn-outline-*`
   stack is already loaded in `[layouts/main.php]` and picks up the active
   theme through the `--bs-*` bridge defined at the top of this file. The
   custom `.btn-*` rules that used to live here have been retired.

   We only ship the things Bootstrap can't express cleanly:
     • `.btn-icon` — square icon-only button. Compose with a Bootstrap
       colour, e.g. `class="btn btn-light btn-icon"` or
       `class="btn btn-outline-secondary btn-icon"`.
     • `.btn-ghost` — kept as a thin shim that aliases
       `class="btn btn-link text-secondary"`. Existing markup keeps working.
   ============================================================================ */

/* Oversized, touch-friendly controls per ui.md (~44px). Dense contexts opt out
   via .btn-sm / .btn-icon. Buttons darken on hover (Bootstrap handles the tint);
   only cards lift. */
.btn:not(.btn-sm):not(.btn-icon):not(.btn-link) {
    padding: 0.75rem 1.375rem;
    font-weight: 600;
}
.btn { transition: color var(--transition-fast), background-color var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast); }

/* Bootstrap 5.3 button *variants* bake their colour into per-variant
   `--bs-btn-*` custom props at compile time, so overriding `--bs-primary`
   alone does NOT recolour `.btn-primary`. Bridge each themed variant to the
   design-system tokens here so buttons follow the Emerald theme app-wide. */
.btn-primary {
    --bs-btn-bg: var(--primary);
    --bs-btn-border-color: var(--primary);
    --bs-btn-hover-bg: var(--primary-hover);
    --bs-btn-hover-border-color: var(--primary-hover);
    --bs-btn-active-bg: var(--primary-hover);
    --bs-btn-active-border-color: var(--primary-hover);
    --bs-btn-disabled-bg: var(--primary);
    --bs-btn-disabled-border-color: var(--primary);
}
.btn-success {
    --bs-btn-bg: var(--success);
    --bs-btn-border-color: var(--success);
    --bs-btn-hover-bg: var(--success-dark);
    --bs-btn-hover-border-color: var(--success-dark);
    --bs-btn-active-bg: var(--success-dark);
    --bs-btn-active-border-color: var(--success-dark);
    --bs-btn-disabled-bg: var(--success);
    --bs-btn-disabled-border-color: var(--success);
}
.btn-danger {
    --bs-btn-bg: var(--danger);
    --bs-btn-border-color: var(--danger);
    --bs-btn-hover-bg: var(--danger-dark);
    --bs-btn-hover-border-color: var(--danger-dark);
    --bs-btn-active-bg: var(--danger-dark);
    --bs-btn-active-border-color: var(--danger-dark);
    --bs-btn-disabled-bg: var(--danger);
    --bs-btn-disabled-border-color: var(--danger);
}
.btn-warning {
    --bs-btn-bg: var(--warning);
    --bs-btn-border-color: var(--warning);
    --bs-btn-hover-bg: var(--warning-dark);
    --bs-btn-hover-border-color: var(--warning-dark);
    --bs-btn-active-bg: var(--warning-dark);
    --bs-btn-active-border-color: var(--warning-dark);
    --bs-btn-disabled-bg: var(--warning);
    --bs-btn-disabled-border-color: var(--warning);
}
.btn-info {
    --bs-btn-bg: var(--info);
    --bs-btn-border-color: var(--info);
    --bs-btn-hover-bg: var(--info-dark);
    --bs-btn-hover-border-color: var(--info-dark);
    --bs-btn-active-bg: var(--info-dark);
    --bs-btn-active-border-color: var(--info-dark);
    --bs-btn-disabled-bg: var(--info);
    --bs-btn-disabled-border-color: var(--info);
}
.btn-outline-primary {
    --bs-btn-color: var(--primary);
    --bs-btn-border-color: var(--primary);
    --bs-btn-hover-bg: var(--primary);
    --bs-btn-hover-border-color: var(--primary);
    --bs-btn-active-bg: var(--primary);
    --bs-btn-active-border-color: var(--primary);
    --bs-btn-disabled-color: var(--primary);
    --bs-btn-disabled-border-color: var(--primary);
}
.btn-link {
    --bs-btn-color: var(--primary);
    --bs-btn-hover-color: var(--primary-hover);
}

/* Square icon-only button — composes with any Bootstrap colour variant. */
.btn-icon {
    width: 38px;
    height: 38px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.btn-icon.btn-sm { width: 32px; height: 32px; }
.btn-icon.btn-lg { width: 44px; height: 44px; }
.btn-icon .material-symbols-outlined { font-size: 20px; }

/* `.btn-ghost` shim — preserve legacy markup. New code should use
   `class="btn btn-link text-secondary"` instead. */
.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid transparent;
}
.btn-ghost:hover:not(:disabled) {
    background: var(--bg);
    color: var(--text);
}

/* Bootstrap dropped `.btn-block` in 5.x; thin shim for legacy markup.
   Prefer `class="btn ... w-100"` going forward. */
.btn-block {
    display: flex;
    width: 100%;
}

/* Same Bootstrap-5.3-bakes-colour-at-compile-time issue as `.btn-primary`
   above, but for `.nav-pills` — `--bs-nav-pills-link-active-bg` compiles to
   Bootstrap's own blue, not our `--bs-primary`. Used by the settings tab
   nav (app/Views/settings/_tabs.php); bridge it to Emerald explicitly. */
.nav-pills {
    --bs-nav-pills-link-active-bg: var(--primary);
}
.nav-pills .nav-link.active,
.nav-pills .show > .nav-link {
    background-color: var(--primary);
    color: var(--text-inverse);
}
.nav-pills .nav-link:not(.active) {
    color: var(--text-secondary);
}
.nav-pills .nav-link:not(.active):hover {
    background-color: var(--bg);
    color: var(--text);
}

/* ============================================================================
   Forms

   Bootstrap form classes (`.form-label`, `.form-control`, `.form-select`,
   `.input-group`, `.form-check`, `.is-invalid` + `.invalid-feedback`) are
   canonical — they pick up the active theme through the `--bs-*` bridge at
   the top of this file. New code should use those classes directly.

   The `.form-group`, `.form-control`, etc. rules below are kept as a thin
   compatibility layer for the existing custom-form pages (employees/users
   create+edit, contracts wizard). Their tokens match Bootstrap's, so the
   visual is identical.
   ============================================================================ */
.form-group {
    margin-bottom: var(--space-4);
}

.form-group label {
    display: block;
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: var(--space-2);
}

.form-control {
    width: 100%;
    padding: 0.6875rem var(--space-4);
    font-size: var(--text-base);
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border-dark);
    border-radius: var(--radius);
    transition: all var(--transition-fast);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}

.form-control.error {
    border-color: var(--danger);
}

.form-control.error:focus {
    box-shadow: 0 0 0 3px rgba(var(--danger-rgb), 0.1);
}

.form-control::placeholder {
    color: var(--text-muted);
}

textarea.form-control {
    min-height: 100px;
    resize: vertical;
}

select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7280' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right var(--space-3) center;
    padding-right: var(--space-8);
}

/* Match Bootstrap selects to the roomier input height (skip .*-sm dense variants). */
.form-select:not(.form-select-sm) {
    padding-top: 0.6875rem;
    padding-bottom: 0.6875rem;
    font-size: var(--text-base);
}

.form-row {
    display: flex;
    gap: var(--space-4);
}

.form-row .form-group {
    flex: 1;
}

.form-hint {
    font-size: var(--text-xs);
    color: var(--text-muted);
    margin-top: var(--space-1);
}

.form-error {
    font-size: var(--text-xs);
    color: var(--danger);
    margin-top: var(--space-1);
}

/* ============================================
   Tables
   ============================================ */
.table-wrapper {
    overflow-x: auto;
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--text-base);
}

.table th,
.table td {
    padding: 1.0625rem var(--space-5);
    text-align: left;
    border-bottom: 1px solid var(--border-light);
}

.table th {
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: var(--surface);
    white-space: nowrap;
}

.table tbody tr {
    transition: background var(--transition-fast);
}

.table tbody tr:hover {
    background: var(--bg);
}

.table tbody tr:last-child td {
    border-bottom: none;
}

/* ============================================
   Badges
   ============================================ */
.badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: 3px var(--space-2);
    font-size: var(--text-xs);
    font-weight: 500;
    border-radius: var(--radius-full);
    white-space: nowrap;
}

/* Icon-bearing badges (status pills that pair an icon with text) — sized to
   sit inline with the badge's text without per-usage inline styles. */
.badge .material-symbols-outlined {
    font-size: 14px;
}

.badge-primary {
    background: var(--primary-light);
    color: var(--primary);
}

.badge-success {
    background: var(--success-light);
    color: var(--success-dark);
}

.badge-warning {
    background: var(--warning-light);
    color: var(--warning-dark);
}

.badge-danger {
    background: var(--danger-light);
    color: var(--danger-dark);
}

.badge-info {
    background: var(--info-light);
    color: var(--info-dark);
}

.badge-neutral {
    background: var(--bg-alt);
    color: var(--text-secondary);
}

.badge-purple {
    background: var(--purple-light);
    color: var(--purple-dark);
}

/* ============================================================================
   Lists & toolbars — one search/filter bar + server pager for every list page.
   Rendered by components/list-toolbar.php and components/pagination.php.
   Replaces the ~8 per-module filter bars and the copy-pasted Bootstrap pager.
   ============================================================================ */
.list-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--border);
}

.list-toolbar-search {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0 var(--space-3);
    flex: 1 1 220px;
    max-width: 360px;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.list-toolbar-search:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.12);
}
.list-toolbar-search .material-symbols-outlined {
    font-size: 20px;
    color: var(--text-muted);
}
.list-toolbar-input {
    flex: 1;
    border: 0;
    background: transparent;
    padding: var(--space-2) 0;
    font-size: var(--text-sm);
    color: var(--text);
    outline: none;
}
.list-toolbar-input::placeholder { color: var(--text-muted); }

.list-toolbar-filters {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--space-2);
}

@media (max-width: 1024px) {
    .list-toolbar { padding: var(--space-3) var(--space-4); gap: var(--space-2); }
}

@media (max-width: 640px) {
    .list-toolbar-search { max-width: none; }
    .list-toolbar-filters { width: 100%; }
}

/* Server-side pager (components/pagination.php) — sits in a .card-footer. */
.list-pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: var(--space-3);
}
.list-pagination-info {
    font-size: var(--text-sm);
    color: var(--text-muted);
}

/* ============================================
   Alerts
   ============================================ */
.alert {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    padding: var(--space-4);
    border-radius: var(--radius);
    margin-bottom: var(--space-4);
    font-size: var(--text-sm);
    border: 1px solid;
}

.alert-icon {
    flex-shrink: 0;
    font-size: 1.125rem;
}

.alert-content {
    flex: 1;
}

.alert-success {
    background: var(--success-light);
    color: var(--success-dark);
    border-color: rgba(var(--success-rgb), 0.2);
}

.alert-error {
    background: var(--danger-light);
    color: var(--danger-dark);
    border-color: rgba(var(--danger-rgb), 0.2);
}

.alert-warning {
    background: var(--warning-light);
    color: var(--warning-dark);
    border-color: rgba(var(--warning-rgb), 0.2);
}

.alert-info {
    background: var(--primary-light);
    color: var(--primary);
    border-color: rgba(var(--primary-rgb), 0.2);
}

.alert-close {
    margin-left: auto;
    background: none;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    opacity: 0.6;
    transition: opacity var(--transition-fast);
}

.alert-close:hover {
    opacity: 1;
}

/* ============================================
   Auth Pages
   ============================================ */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--c-shell) 0%, var(--c-shell-strong) 100%);
    padding: var(--space-6);
    position: relative;
}

.auth-page::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background:
        radial-gradient(circle at 20% 30%, rgba(var(--primary-rgb), 0.18) 0%, transparent 40%),
        radial-gradient(circle at 80% 70%, rgba(var(--info-rgb), 0.12) 0%, transparent 40%);
}

.auth-container {
    width: 100%;
    max-width: 400px;
    position: relative;
    z-index: 1;
}

.auth-card {
    background: var(--surface);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    padding: var(--space-8);
}

.auth-logo {
    text-align: center;
    margin-bottom: var(--space-8);
}

.auth-logo .logo-icon {
    width: 48px;
    height: 48px;
    margin: 0 auto var(--space-4);
    background: var(--primary);
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: white;
}

.auth-logo h1 {
    font-size: var(--text-xl);
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.02em;
}

.auth-logo p {
    font-size: var(--text-sm);
    color: var(--text-secondary);
    margin-top: var(--space-1);
}

.auth-form .form-group {
    margin-bottom: var(--space-5);
}

.auth-footer {
    text-align: center;
    margin-top: var(--space-6);
    padding-top: var(--space-5);
    border-top: 1px solid var(--border);
}

.auth-footer p {
    font-size: var(--text-sm);
    color: var(--text-muted);
}

/* ============================================
   Form Pages (shared layout — used by employees/users create+edit)
   ============================================ */
/* ============================================================================
   Page header — canonical in-page header for list / detail pages.
   Title (+ optional icon) and subtitle on the left, primary actions top-right.
   Rendered by app/Views/components/page-header.php. Replaces the per-module
   headers (.emp-list-header, .user-list-header, .abs-header, .contracts-header,
   payroll button group, and inline-flex headers).
   ============================================================================ */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-4);
    flex-wrap: wrap;
    margin-bottom: var(--space-5);
}

.page-header-titles {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-width: 0;
}

.page-header-icon {
    width: 44px;
    height: 44px;
    flex-shrink: 0;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary);
    color: var(--text-inverse);
}
.page-header-icon.is-soft {
    background: var(--primary-light);
    color: var(--primary);
}
.page-header-icon .material-symbols-outlined { font-size: 24px; }

.page-header-title {
    font-size: var(--text-3xl);
    font-weight: 700;
    color: var(--text-heading);
    letter-spacing: -0.02em;
    margin: 0;
    line-height: 1.2;
}

.page-header-subtitle {
    font-size: var(--text-sm);
    color: var(--text-muted);
    margin: 4px 0 0;
}

.page-header-actions {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex-wrap: wrap;
}

@media (max-width: 1024px) {
    .page-header { gap: var(--space-3); margin-bottom: var(--space-4); }
    .page-header-title { font-size: var(--text-2xl); }
}

@media (max-width: 640px) {
    .page-header-actions { width: 100%; }
}

.form-page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-4);
    margin-bottom: var(--space-5);
}

.form-page-title {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

/* Default icon block: solid brand colour, used by Edit pages with initials. */
.form-page-icon {
    width: 48px;
    height: 48px;
    background: var(--primary);
    color: var(--text-inverse);
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: var(--text-lg);
}

/* Soft variant: tinted primary background + primary text, used by Create
   pages with a Material icon inside. Add as second class on the icon div. */
.form-page-icon.is-soft {
    background: var(--primary-light);
    color: var(--primary);
    font-weight: 400;
}
.form-page-icon.is-soft .material-symbols-outlined {
    font-size: 24px;
}

.form-page-info h1 {
    font-size: var(--text-xl);
    font-weight: 700;
    color: var(--text);
    margin: 0 0 4px;
}

.form-page-info p {
    font-size: var(--text-sm);
    color: var(--text-muted);
    margin: 0;
}

.form-breadcrumb {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-bottom: var(--space-4);
    font-size: var(--text-sm);
}

.form-breadcrumb a {
    color: var(--text-muted);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 4px;
}

.form-breadcrumb a:hover {
    color: var(--primary);
}

.form-breadcrumb .material-symbols-outlined {
    font-size: 16px;
}

.breadcrumb-sep {
    color: var(--text-muted);
}

.breadcrumb-current {
    color: var(--text);
    font-weight: 500;
}

/* Two-column form layout (used by users/{edit,create}). On <=1024px collapses
   to a single column. */
.form-layout {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: var(--space-5);
    align-items: start;
}

@media (max-width: 1024px) {
    .form-layout {
        grid-template-columns: 1fr;
    }
}

.form-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

/* Capped-width form card used on single-column form pages (employees/*). */
.form-card.is-capped {
    max-width: 800px;
}

.form-section {
    padding: var(--space-5);
    border-bottom: 1px solid var(--border);
}

.form-section:last-of-type {
    border-bottom: none;
}

.form-section-title {
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--text);
    margin: 0 0 var(--space-4);
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.form-section-title .material-symbols-outlined {
    font-size: 18px;
    color: var(--text-muted);
}

/* Default footer: space-between alignment (Edit pages, status toggle on the
   left, action buttons on the right). */
.form-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-4) var(--space-5);
    background: var(--bg);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* Right-aligned variant: just buttons (Create pages). */
.form-footer.is-end {
    justify-content: flex-end;
    gap: var(--space-3);
}

/* Footer slots (used by components/form-footer.php). `.form-footer` already
   provides the flex/padding/background; the slots just group the left/right
   action clusters so they wrap neatly on narrow viewports. */
.form-footer-left,
.form-footer-right {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    flex-wrap: wrap;
}

/* ----------------------------------------------------------------------------
   Form-page shared helpers — promoted here from the inline <style> blocks of
   users/create.php, users/edit.php, roles/{create,edit}.php and
   employees/edit.php so each view stops redeclaring them. Class names are
   unchanged; only the declaration site moved.
   ---------------------------------------------------------------------------- */

/* Password field with an inline show/hide toggle button. */
.password-input {
    position: relative;
}
.password-input input {
    padding-right: 40px;
}
.password-toggle {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    padding: 4px;
}
.password-toggle:hover {
    color: var(--text);
}

/* "Change password" sub-panel (users/edit). */
.password-section {
    background: var(--bg);
    border-radius: var(--radius);
    padding: var(--space-4);
}
.password-section-header {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-bottom: var(--space-3);
}
.password-section-header span:first-child {
    font-weight: 600;
    color: var(--text);
}

/* Compact sidebar callouts that reuse the shared .card. */
.sidebar-card-header {
    padding: var(--space-4);
    border-bottom: 1px solid var(--border);
}
.sidebar-card-title {
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--text);
    margin: 0;
    display: flex;
    align-items: center;
    gap: var(--space-2);
}
.sidebar-card-title .material-symbols-outlined {
    font-size: 16px;
    color: var(--text-muted);
}
.sidebar-card-body {
    padding: var(--space-4);
}

/* "About roles" list (users/create sidebar). */
.role-info-item {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    padding: var(--space-2) 0;
}
.role-info-item:first-child {
    padding-top: 0;
}
.role-info-item:last-child {
    padding-bottom: 0;
}
.role-info-text {
    font-size: var(--text-xs);
    color: var(--text-muted);
    line-height: 1.4;
}

/* Password-tip checklist (users/create sidebar). */
.password-tips {
    margin: 0;
    padding-left: var(--space-4);
    font-size: var(--text-xs);
    color: var(--text-muted);
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

/* Key/value rows (users/edit sidebar). */
.info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-2) 0;
    border-bottom: 1px solid var(--border-light);
    font-size: var(--text-sm);
}
.info-row:last-child {
    border-bottom: none;
    padding-bottom: 0;
}
.info-row:first-child {
    padding-top: 0;
}
.info-label {
    color: var(--text-muted);
}
.info-value {
    color: var(--text);
    font-weight: 500;
}

/* Active/inactive toggle (employees/edit). */
.status-toggle {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    background: var(--bg);
    border-radius: var(--radius);
    border: 1px solid var(--border);
}
.status-toggle input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}
.status-toggle label {
    margin: 0;
    cursor: pointer;
    font-weight: 500;
}

/* Action slot for the form-page-header (components/form-page-header.php).
   Mirrors .page-header-actions so create/edit pages match list pages. */
.form-page-actions {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex-wrap: wrap;
}
@media (max-width: 640px) {
    .form-page-actions { width: 100%; }
}

/* ----------------------------------------------------------------------------
   Detail (show) pages — canonical header + section + label/value grid.
   Rendered by components/detail-header.php, detail-section.php, detail-grid.php.
   Replaces the bespoke .user-detail-* / .emp-detail-* / .detail-card
   vocabularies that were duplicated per module.
   ---------------------------------------------------------------------------- */
.detail-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-4);
    flex-wrap: wrap;
    margin-bottom: var(--space-5);
}

.detail-header-title {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    min-width: 0;
}

.detail-header-icon {
    width: 56px;
    height: 56px;
    flex-shrink: 0;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary);
    color: var(--text-inverse);
    font-weight: 700;
    font-size: var(--text-xl);
}
.detail-header-icon.is-soft {
    background: var(--primary-light);
    color: var(--primary);
    font-weight: 400;
}
.detail-header-icon .material-symbols-outlined { font-size: 28px; }

.detail-header-info h1 {
    font-size: var(--text-2xl);
    font-weight: 800;
    color: var(--text);
    letter-spacing: -0.02em;
    margin: 0 0 4px;
    display: flex;
    align-items: center;
    gap: var(--space-2);
    line-height: 1.2;
}

.detail-header-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-3);
    font-size: var(--text-sm);
    color: var(--text-muted);
}
.detail-header-meta span {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.detail-header-meta .material-symbols-outlined { font-size: 16px; }

.detail-header-actions {
    display: flex;
    gap: var(--space-2);
    flex-wrap: wrap;
}

@media (max-width: 1024px) {
    .detail-header { gap: var(--space-3); margin-bottom: var(--space-4); }
    .detail-header-info h1 { font-size: var(--text-xl); }
}
@media (max-width: 640px) {
    .detail-header-actions { width: 100%; }
}

/* Multi-column show-page layout. Default is a 2fr/1fr split (main + aside);
   `.is-3up` is three equal columns (employees/show). Both collapse to a single
   stacked column on narrow viewports. */
.detail-layout {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: var(--space-5);
}
.detail-layout.is-3up {
    grid-template-columns: 1fr 1fr 1fr;
}
.detail-layout > * {
    display: flex;
    flex-direction: column;
    gap: var(--space-5);
    min-width: 0;
}
@media (max-width: 1200px) {
    .detail-layout.is-3up { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 1024px) {
    .detail-layout,
    .detail-layout.is-3up { grid-template-columns: 1fr; }
}

/* Titled card holding a block of detail rows. `.card` supplies the surface;
   these rules add the header/body chrome. Specificity is kept at 0 via
   :where() so per-module tweaks (e.g. a stripe modifier) still win. */
:where(.detail-section) {
    margin-bottom: var(--space-5);
}
:where(.detail-section:last-child) {
    margin-bottom: 0;
}
.detail-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--border);
}
.detail-section-title {
    font-size: var(--text-base);
    font-weight: 700;
    color: var(--text);
    margin: 0;
    display: flex;
    align-items: center;
    gap: var(--space-2);
}
.detail-section-title .material-symbols-outlined {
    font-size: 20px;
    color: var(--text-muted);
}
.detail-section-body {
    padding: var(--space-5);
}

/* 2-column label/value list (components/detail-grid.php). */
.detail-grid-list {
    display: grid;
    grid-template-columns: 140px 1fr;
    gap: var(--space-2) var(--space-3);
    margin: 0;
    font-size: var(--text-sm);
}
.detail-grid-list dt {
    color: var(--text-muted);
    font-weight: 500;
}
.detail-grid-list dd {
    color: var(--text);
    margin: 0;
}
@media (max-width: 640px) {
    .detail-grid-list {
        grid-template-columns: 1fr;
        gap: var(--space-1);
    }
    .detail-grid-list dt {
        font-size: var(--text-xs);
        text-transform: uppercase;
        letter-spacing: 0.05em;
    }
}

/* ----------------------------------------------------------------------------
   Detail-page helper widgets — promoted here from the inline <style> blocks of
   users/show.php (and reused by employees/show.php / roles/permissions.php) so
   the show pages stop redeclaring them. Class names unchanged.
   ---------------------------------------------------------------------------- */

/* Permission tag chips (users/show, roles/permissions). */
.permissions-grid {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
}
.permission-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: var(--text-xs);
    color: var(--text);
}
.permission-tag .material-symbols-outlined {
    font-size: 12px;
    color: var(--success);
}

/* Activity timeline (users/show). */
.activity-item {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    padding: var(--space-3) 0;
    border-bottom: 1px solid var(--border-light);
}
.activity-item:last-child {
    border-bottom: none;
}
.activity-icon {
    width: 32px;
    height: 32px;
    border-radius: var(--radius);
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.activity-icon .material-symbols-outlined {
    font-size: 16px;
    color: var(--text-muted);
}
.activity-content {
    flex: 1;
    min-width: 0;
}
.activity-title {
    font-size: var(--text-sm);
    color: var(--text);
    margin-bottom: 2px;
}
.activity-time {
    font-size: var(--text-xs);
    color: var(--text-muted);
}

/* Quick-action tile grid (users/show). */
.quick-actions-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: var(--space-3);
}
.quick-action-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-4);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    text-decoration: none;
    color: var(--text);
    transition: all 0.15s;
    cursor: pointer;
}
.quick-action-btn:hover {
    border-color: var(--primary);
    background: var(--primary-light);
}
.quick-action-btn .material-symbols-outlined {
    font-size: 24px;
    color: var(--text-muted);
}
.quick-action-btn:hover .material-symbols-outlined {
    color: var(--primary);
}
.quick-action-btn span:last-child {
    font-size: var(--text-xs);
    font-weight: 500;
}

/* Group tag chips (employees/show). */
.group-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: var(--text-xs);
    color: var(--text);
    text-decoration: none;
    transition: all 0.15s;
}
.group-tag:hover {
    border-color: var(--primary);
    background: var(--primary-light);
}

/* Linked-user card (employees/show). */
.linked-user-card {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    padding: var(--space-4);
    background: var(--bg);
    border-radius: var(--radius);
}
.linked-user-avatar {
    width: 44px;
    height: 44px;
    background: var(--primary);
    color: var(--text-inverse);
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: var(--text-sm);
    flex-shrink: 0;
}
.linked-user-info {
    flex: 1;
    min-width: 0;
}
.linked-user-name {
    font-weight: 600;
    color: var(--text);
    margin-bottom: 2px;
}
.linked-user-email {
    font-size: var(--text-xs);
    color: var(--text-muted);
}

/* Profile sub-tabs (employees/show). */
.show-tabs {
    display: flex;
    gap: 2px;
    padding: 4px;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    margin-bottom: var(--space-4);
    overflow-x: auto;
}
.show-tabs a {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    font-size: var(--text-sm);
    color: var(--text-muted);
    text-decoration: none;
    white-space: nowrap;
    transition: all .15s;
}
.show-tabs a:hover {
    background: var(--bg);
    color: var(--text);
}
.show-tabs a.is-active {
    background: var(--primary);
    color: var(--text-inverse);
}
.show-tabs a .material-symbols-outlined {
    font-size: 18px;
}

/* ============================================
   DataTable (vanilla JS — see public/assets/js/datatable.js)

   Drop `data-datatable` on a <table class="table"> and the JS auto-wraps it
   in .dt-wrap and renders a footer toolbar. Every value below resolves
   through the active palette/semantic tokens, so theme swaps repaint the
   table for free.
   ============================================ */

/* Pagination hiding. !important so a page's own filter that sets
   row.style.display = '' to "show" can never accidentally override the
   datatable's pagination — pages instead call __dataTable.setFilter(...)
   to integrate with pagination. */
tr.dt-hidden { display: none !important; }

.dt-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-xs);
    overflow: hidden;
    margin-bottom: var(--space-6);
}

.dt-scroll {
    overflow: auto;
    max-height: 70vh;
}

/* Strip the inner table's own border/shadow because .dt-wrap owns them now. */
.dt-wrap > .dt-scroll > table.table {
    margin: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

.dt-wrap thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--surface-alt);
    color: var(--text);
    border-bottom: 1px solid var(--border);
    user-select: none;
    white-space: nowrap;
}

/* Sortable headers get a chevron and become clickable. */
.dt-wrap thead th[data-sortable] {
    cursor: pointer;
    padding-right: 1.75rem;
    position: sticky;
    transition: background-color var(--transition-fast);
}

.dt-wrap thead th[data-sortable]:hover {
    background: var(--bg-alt);
}

.dt-wrap thead th[data-sortable]:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: -2px;
}

.dt-wrap thead th[data-sortable]::after {
    content: "↕";
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.75rem;
    opacity: 0.35;
    color: var(--text-secondary);
    transition: opacity var(--transition-fast), color var(--transition-fast);
}

.dt-wrap thead th[aria-sort="ascending"]::after {
    content: "▲";
    opacity: 1;
    color: var(--primary);
}

.dt-wrap thead th[aria-sort="descending"]::after {
    content: "▼";
    opacity: 1;
    color: var(--primary);
}

/* Footer toolbar (info + page-size + pager). */
.dt-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-3);
    border-top: 1px solid var(--border);
    background: var(--surface-alt);
    font-size: var(--text-sm);
    color: var(--text-secondary);
}

.dt-info {
    flex: 1 1 auto;
    min-width: 0;
}

.dt-page-size-wrap {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
}

.dt-page-size {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 2px var(--space-2);
    font-size: var(--text-sm);
    cursor: pointer;
}

.dt-page-size:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 1px;
}

.dt-pager {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 2px;
}

.dt-pager button {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: var(--radius-sm);
    padding: 2px var(--space-2);
    min-width: 32px;
    font-size: var(--text-sm);
    cursor: pointer;
    transition: background-color var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast);
}

.dt-pager button:hover:not(:disabled):not([aria-current="page"]) {
    background: var(--bg-alt);
    border-color: var(--border-dark);
}

.dt-pager button:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 1px;
}

.dt-pager button[aria-current="page"] {
    background: var(--primary);
    color: var(--text-inverse);
    border-color: var(--primary);
    cursor: default;
}

.dt-pager button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.dt-ellipsis {
    display: inline-flex;
    align-items: center;
    padding: 2px 4px;
    color: var(--text-muted);
}

@media (max-width: 640px) {
    .dt-toolbar {
        flex-direction: column;
        align-items: stretch;
    }
    .dt-info { text-align: center; }
    .dt-pager { justify-content: center; }
    .dt-page-size-wrap { justify-content: center; }
}

/* ============================================
   Empty State
   ============================================ */
.empty-state {
    text-align: center;
    padding: var(--space-12);
    color: var(--text-muted);
}

.empty-state-icon {
    font-size: 3rem;
    margin-bottom: var(--space-4);
    opacity: 0.5;
}

.empty-state-title {
    font-size: var(--text-lg);
    font-weight: 600;
    color: var(--text);
    margin-bottom: var(--space-2);
}

.empty-state-description {
    font-size: var(--text-sm);
    max-width: 320px;
    margin: 0 auto var(--space-6);
}

/* ============================================
   Pagination
   ============================================ */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-1);
    margin-top: var(--space-6);
}

.pagination a,
.pagination span {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 32px;
    padding: 0 var(--space-2);
    font-size: var(--text-sm);
    font-weight: 500;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    transition: all var(--transition-fast);
}

.pagination a:hover {
    background: var(--bg);
    border-color: var(--border-dark);
    color: var(--text);
}

.pagination .active {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

/* ============================================
   Utilities
   ============================================ */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-left { text-align: left; }

.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-danger { color: var(--danger); }

.font-bold { font-weight: 700; }
.font-semibold { font-weight: 600; }
.font-medium { font-weight: 500; }

.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: var(--space-2); }
.mb-2 { margin-bottom: var(--space-4); }
.mb-3 { margin-bottom: var(--space-6); }
.mb-4 { margin-bottom: var(--space-8); }

.mt-0 { margin-top: 0; }
.mt-1 { margin-top: var(--space-2); }
.mt-2 { margin-top: var(--space-4); }
.mt-3 { margin-top: var(--space-6); }
.mt-4 { margin-top: var(--space-8); }

.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-end { justify-content: flex-end; }
.gap-1 { gap: var(--space-2); }
.gap-2 { gap: var(--space-4); }
.gap-3 { gap: var(--space-6); }

.hidden { display: none; }

/* Grid */
.grid {
    display: grid;
    gap: var(--space-6);
}

.grid-cols-2 {
    grid-template-columns: repeat(2, 1fr);
}

.grid-cols-3 {
    grid-template-columns: repeat(3, 1fr);
}

.grid-cols-4 {
    grid-template-columns: repeat(4, 1fr);
}

@media (max-width: 1024px) {
    .grid-cols-3, .grid-cols-4 {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 640px) {
    .grid-cols-2, .grid-cols-3, .grid-cols-4 {
        grid-template-columns: 1fr;
    }
}

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 1024px) {
    .sidebar {
        transform: translateX(-100%);
    }
    
    .sidebar.open {
        transform: translateX(0);
    }
    
    .main-content {
        margin-left: 0;
    }
    
    .sidebar-toggle {
        display: flex;
    }
    
    .content-wrapper {
        padding: var(--space-4);
    }
}

@media (max-width: 768px) {
    .form-row {
        flex-direction: column;
    }
    
    .card-header {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .welcome-banner {
        padding: var(--space-5);
    }
    
    .welcome-title {
        font-size: var(--text-xl);
    }
    
    .auth-card {
        padding: var(--space-6);
    }
}

@media (max-width: 480px) {
    .header {
        padding: 0 var(--space-4);
    }
    
    .page-title {
        font-size: var(--text-base);
    }
    
    .header-search {
        display: none;
    }
}

/* ============================================
   Sidebar Overlay (Mobile)
   ============================================ */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    opacity: 0;
    transition: opacity var(--transition);
}

.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

/* ============================================
   Dynamic Tab System
   ============================================ */
.tab-bar {
    display: none; /* Hidden by default, shown when tabs > 1 */
    align-items: center;
    gap: var(--space-2);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 var(--space-4);
    height: 44px;
    overflow-x: auto;
    overflow-y: hidden;
}

.tab-list {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    flex: 1;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: thin;
}

.tab-list::-webkit-scrollbar {
    height: 4px;
}

.tab-list::-webkit-scrollbar-thumb {
    background: var(--border-dark);
    border-radius: var(--radius-full);
}

.tab {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    background: transparent;
    border: none;
    border-radius: var(--radius) var(--radius) 0 0;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
    color: var(--text-secondary);
    font-size: var(--text-sm);
    position: relative;
    min-width: 120px;
    max-width: 200px;
}

.tab:hover {
    background: var(--surface-alt);
    color: var(--text);
}

.tab.active {
    background: var(--primary-light);
    color: var(--primary);
    font-weight: 600;
}

.tab.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--primary);
}

.tab.loading {
    opacity: 0.6;
    pointer-events: none;
}

.tab-icon {
    font-size: 18px;
    flex-shrink: 0;
}

.tab-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tab-spinner {
    width: 14px;
    height: 14px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    flex-shrink: 0;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.tab-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    opacity: 0.5;
    transition: all var(--transition);
    flex-shrink: 0;
}

.tab-close:hover {
    opacity: 1;
    background: rgba(0, 0, 0, 0.1);
}

.tab-close .material-symbols-outlined {
    font-size: 16px;
}

.tab-actions {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding-left: var(--space-2);
    border-left: 1px solid var(--border);
}

.tab-action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    color: var(--text-secondary);
    transition: all var(--transition);
}

.tab-action-btn:hover {
    background: var(--surface-alt);
    color: var(--text);
}

.tab-action-btn .material-symbols-outlined {
    font-size: 18px;
}

/* Tab Contents */
.tab-contents {
    position: relative;
    min-height: 400px;
}

.tab-pane {
    display: none;
}

.tab-pane.active {
    display: block;
}

/* Tab Loading State */
.tab-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-12);
    color: var(--text-secondary);
}

.tab-loading .spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: var(--space-4);
}

.tab-loading p {
    margin: 0;
    font-size: var(--text-sm);
}

/* Tab Error State */
.tab-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-12);
    text-align: center;
    color: var(--text-secondary);
}

.tab-error .material-symbols-outlined {
    font-size: 48px;
    color: var(--danger);
    margin-bottom: var(--space-4);
}

.tab-error h3 {
    margin: 0 0 var(--space-2);
    color: var(--text);
    font-size: var(--text-lg);
}

.tab-error p {
    margin: 0 0 var(--space-4);
    color: var(--text-secondary);
    font-size: var(--text-sm);
}

/* Form Loading Overlay (for tab form submissions) */
.form-loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    border-radius: var(--radius);
}

.form-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-3);
    color: var(--text-secondary);
}

.form-loading .spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.form-loading p {
    margin: 0;
    font-size: var(--text-sm);
    font-weight: 500;
}

/* Responsive */
@media (max-width: 768px) {
    .tab-bar {
        padding: 0 var(--space-2);
    }
    
    .tab {
        min-width: 100px;
        max-width: 150px;
        padding: var(--space-2) var(--space-3);
    }
    
    .tab-title {
        font-size: var(--text-xs);
    }
}

/* ============================================
   Confirm / delete modal (Bootstrap modal + design tokens)
   ============================================ */
@keyframes spin { to { transform: rotate(360deg); } }

.confirm-modal-icon {
    font-size: 48px;
    color: var(--danger);
}

.confirm-modal-title {
    font-size: var(--text-lg);
    font-weight: 700;
    margin: var(--space-2) 0 var(--space-1);
}

.confirm-modal-subtitle {
    color: var(--text-muted);
    font-size: var(--text-sm);
}

.delete-info-panel {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: var(--space-3) var(--space-4);
    margin-bottom: var(--space-4);
    min-height: 52px;
}

.delete-info-loading {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    color: var(--text-muted);
    font-size: var(--text-sm);
}

.delete-info-loading .material-symbols-outlined {
    font-size: 16px;
    animation: spin 1s linear infinite;
}

.delete-info-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: var(--text-xs);
    color: var(--text-muted);
    padding: 2px 0;
}
.delete-info-item .material-symbols-outlined { font-size: 14px; }
.delete-info-item.has-data { color: var(--text); font-weight: 500; }
.delete-info-item.has-data .material-symbols-outlined { color: var(--warning); }

.delete-scope-options {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    margin-bottom: var(--space-4);
}

.delete-scope-option {
    display: flex;
    gap: var(--space-3);
    align-items: flex-start;
    padding: var(--space-3) var(--space-4);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: border-color .15s;
}

.delete-scope-option input[type="radio"] {
    margin-top: 3px;
    flex-shrink: 0;
}

.delete-scope-option.is-selected {
    border-color: var(--primary);
}

.delete-scope-option.is-selected.is-danger {
    border-color: var(--danger);
}

.delete-scope-option-title {
    font-weight: 600;
    font-size: var(--text-sm);
    color: var(--text);
}

.delete-scope-option-title.is-danger {
    color: var(--danger);
}

.delete-scope-option-desc {
    font-size: var(--text-xs);
    color: var(--text-muted);
    margin-top: 2px;
}

.delete-warning-banner {
    display: none;
    align-items: flex-start;
    gap: var(--space-2);
    background: rgba(239, 68, 68, .1);
    border: 1px solid rgba(239, 68, 68, .3);
    border-radius: var(--radius);
    padding: var(--space-3) var(--space-4);
    margin-bottom: var(--space-4);
}

.delete-warning-banner.is-visible {
    display: flex;
}

.delete-warning-banner .material-symbols-outlined {
    color: var(--danger);
    font-size: 18px;
    flex-shrink: 0;
    margin-top: 1px;
}

.delete-warning-banner span:last-child {
    font-size: var(--text-sm);
    color: var(--danger);
    font-weight: 500;
}

/* ============================================
   Quick-add modals (Bootstrap modal + design tokens)
   ============================================ */
.qa-modal-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: var(--text-base);
    font-weight: 700;
}

.qa-modal-title .material-symbols-outlined {
    font-size: 20px;
    color: var(--primary);
}

.qa-error {
    background: rgba(239, 68, 68, .08);
    border: 1px solid rgba(239, 68, 68, .3);
    border-radius: var(--radius);
    color: var(--danger);
    font-size: var(--text-sm);
    padding: 10px 14px;
}

.qa-trigger-btn {
    flex-shrink: 0;
    height: 38px;
    width: 38px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    align-self: flex-end;
    margin-bottom: 0;
}

/* ============================================
   Print Styles
   ============================================ */
@media print {
    .sidebar,
    .header,
    .sidebar-overlay,
    .tab-bar {
        display: none !important;
    }
    
    .main-content {
        margin-left: 0 !important;
    }
    
    .card {
        box-shadow: none !important;
        border: 1px solid #ddd !important;
    }
}
