/* =============================================================================
   NEXSOFTGEN AILIMS — ENTERPRISE DESIGN SYSTEM
   Version: 2.0.0 | LIMS Premium UI/UX
   Industry: Laboratory Information Management (ISO/IEC 17025 / ISO 15189)
   Design: Clean enterprise SaaS — Healthcare / Scientific Instrumentation tier
   ============================================================================= */

/* ---------------------------------------------------------------------------
   PHASE 2: DESIGN TOKENS (CSS Custom Properties)
   All colors, dimensions, spacing defined once — used everywhere.
   --------------------------------------------------------------------------- */
:root {
    /* --- Brand Palette (ISO Enterprise Sapphire Theme) --- */
    --brand-primary:        #1b65af;   /* Clinical enterprise sapphire */
    --brand-primary-dark:   #12487f;
    --brand-primary-light:  #eaf2fa;
    --brand-primary-hover:  #155392;
    --brand-secondary:      #0e7490;   /* Deep teal accent */
    --brand-secondary-light:#ecfeff;
    --brand-accent:         #6366f1;   /* Violet / indigo for AI/Vision */

    /* --- Semantic Status --- */
    --color-success:        #0d9488;
    --color-success-bg:     #f0fdf9;
    --color-success-border: #ccfbf1;
    --color-warning:        #d97706;
    --color-warning-bg:     #fffbeb;
    --color-warning-border: #fde68a;
    --color-danger:         #dc2626;
    --color-danger-bg:      #fef2f2;
    --color-danger-border:  #fecaca;
    --color-info:           #0284c7;
    --color-info-bg:        #f0f9ff;
    --color-info-border:    #bae6fd;

    /* --- Neutral Palette --- */
    --color-page-bg:        #eef2f6;   /* Enterprise slate tint - creates clean contrast against white cards */
    --color-surface:        #ffffff;
    --color-surface-alt:    #f8fafc;   /* Slate-50 */
    --color-border:         #cbd5e1;   /* Slate-300 - crisp, visible borders */
    --color-border-strong:  #94a3b8;   /* Slate-400 */

    /* --- Typography --- */
    --color-text-primary:   #0f172a;   /* Slate-900 */
    --color-text-secondary: #334155;   /* Slate-700 */
    --color-text-muted:     #475569;   /* Slate-600 — high contrast, accessible */
    --color-text-inverse:   #ffffff;

    /* --- Font System --- */
    --font-sans:    "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono:    "JetBrains Mono", "Cascadia Code", "Fira Code", "Consolas", monospace;

    --font-size-xs:   0.75rem;    /* 12px */
    --font-size-sm:   0.8125rem;  /* 13px */
    --font-size-base: 0.875rem;   /* 14px */
    --font-size-md:   0.9375rem;  /* 15px */
    --font-size-lg:   1rem;       /* 16px */
    --font-size-xl:   1.125rem;   /* 18px */
    --font-size-2xl:  1.25rem;    /* 20px */
    --font-size-3xl:  1.5rem;     /* 24px */

    /* --- Layout Dimensions --- */
    --sidebar-width:          260px;
    --sidebar-collapsed-width: 68px;
    --topbar-height:           60px;
    --footer-height:           48px;
    --content-padding:         1.25rem;
    --content-padding-sm:      0.85rem;

    /* --- Sidebar Colors --- */
    --sidebar-bg:             #0f172a;  /* Slate-900 — premium dark nav */
    --sidebar-bg-hover:       #1e293b;
    --sidebar-bg-active:      #1b65af;
    --sidebar-text:           #94a3b8;
    --sidebar-text-active:    #ffffff;
    --sidebar-text-hover:     #e2e8f0;
    --sidebar-header-text:    #475569;
    --sidebar-brand-bg:       #0a0f1e;

    /* --- Control Dimensions (Strict Enterprise Grid) --- */
    --control-height:         38px;
    --control-height-sm:      34px;
    --control-height-xs:      28px;
    --control-height-lg:      44px;
    --border-radius-sm:       4px;
    --border-radius:          6px;
    --border-radius-md:       8px;
    --border-radius-lg:       12px;
    --border-radius-xl:       16px;

    /* --- Shadows --- */
    --shadow-xs:  0 1px 2px rgba(0,0,0,0.05);
    --shadow-sm:  0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md:  0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.04);
    --shadow-lg:  0 10px 15px rgba(0,0,0,0.08), 0 4px 6px rgba(0,0,0,0.04);
    --shadow-xl:  0 20px 25px rgba(0,0,0,0.1), 0 10px 10px rgba(0,0,0,0.04);

    /* --- Spacing Scale --- */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.25rem;
    --space-6: 1.5rem;
    --space-8: 2rem;

    /* --- Table --- */
    --table-row-height: 48px;
    --table-header-bg:  #f8fafc;

    /* --- Modal --- */
    --modal-sm-width:   480px;
    --modal-md-width:   600px;
    --modal-lg-width:   800px;
    --modal-xl-width:   1000px;
}

/* ---------------------------------------------------------------------------
   PHASE 2: BASE & RESET
   --------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

html {
    font-size: 16px;
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font-sans);
    font-size: var(--font-size-base);
    color: var(--color-text-primary);
    background-color: var(--color-page-bg);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ---------------------------------------------------------------------------
   PHASE 3: APPLICATION SHELL LAYOUT
   --------------------------------------------------------------------------- */
.app-wrapper {
    display: flex;
    min-height: 100vh;
    width: 100%;
}

/* ---------------------------------------------------------------------------
   SIDEBAR NAVIGATION
   --------------------------------------------------------------------------- */
.app-sidebar {
    width: var(--sidebar-width);
    background-color: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 1050;
    overflow: hidden;
    transition: width 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 2px 0 8px rgba(0,0,0,0.25);
}

.app-sidebar.collapsed {
    width: var(--sidebar-collapsed-width);
}

/* Brand Logo */
.sidebar-brand {
    height: var(--topbar-height);
    background-color: var(--sidebar-brand-bg);
    display: flex;
    align-items: center;
    padding: 0 1rem;
    text-decoration: none;
    flex-shrink: 0;
    overflow: hidden;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    gap: 0.75rem;
    white-space: nowrap;
}

.sidebar-brand-icon {
    width: 36px;
    height: 36px;
    border-radius: var(--border-radius-md);
    background: linear-gradient(135deg, var(--brand-primary), var(--brand-secondary));
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 1.1rem;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(26,86,219,0.4);
}

.sidebar-brand-text {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-brand-name {
    font-size: 0.9375rem;
    font-weight: 700;
    color: #fff;
    letter-spacing: -0.3px;
    line-height: 1.2;
}

.sidebar-brand-tagline {
    font-size: 0.65rem;
    color: var(--sidebar-text);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 500;
}

.app-sidebar.collapsed .sidebar-brand-text,
.app-sidebar.collapsed .nav-item-text,
.app-sidebar.collapsed .nav-header,
.app-sidebar.collapsed .nav-link-badge {
    display: none !important;
}

/* Sidebar Scroll Container */
.sidebar-scroll {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0.75rem 0;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.1) transparent;
}

.sidebar-scroll::-webkit-scrollbar { width: 4px; }
.sidebar-scroll::-webkit-scrollbar-track { background: transparent; }
.sidebar-scroll::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 4px; }

/* Navigation Section Headers */
.sidebar-menu { list-style: none; margin: 0; padding: 0 0.625rem; }

.nav-header {
    font-size: 0.6rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--sidebar-header-text);
    padding: 1rem 0.75rem 0.4rem;
    white-space: nowrap;
    user-select: none;
}

/* Nav Items */
.sidebar-menu .nav-item {
    margin-bottom: 1px;
}

.sidebar-menu .nav-link {
    display: flex;
    align-items: center;
    padding: 0.5rem 0.75rem;
    color: var(--sidebar-text);
    text-decoration: none;
    border-radius: var(--border-radius);
    transition: all 0.15s ease;
    white-space: nowrap;
    overflow: hidden;
    gap: 0.75rem;
    min-height: 40px;
    position: relative;
}

.sidebar-menu .nav-link:hover {
    background-color: var(--sidebar-bg-hover);
    color: var(--sidebar-text-hover);
}

.sidebar-menu .nav-link.active {
    background-color: var(--sidebar-bg-active);
    color: var(--sidebar-text-active);
    font-weight: 600;
    box-shadow: 0 2px 6px rgba(26,86,219,0.35);
}

.sidebar-menu .nav-link.active::before {
    content: '';
    position: absolute;
    left: -0.625rem;
    top: 0; bottom: 0;
    width: 3px;
    background: #60a5fa;
    border-radius: 0 3px 3px 0;
}

.nav-link-icon {
    font-size: 1rem;
    width: 20px;
    text-align: center;
    flex-shrink: 0;
    line-height: 1;
}

.nav-item-text {
    font-size: var(--font-size-base);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
}

.nav-link-badge {
    margin-left: auto;
    font-size: 0.6rem;
    padding: 0.2em 0.45em;
    flex-shrink: 0;
}

/* Sidebar footer area */
.sidebar-footer {
    border-top: 1px solid rgba(255,255,255,0.08);
    padding: 0.75rem 0.85rem;
    flex-shrink: 0;
}

.sidebar-system-badge {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.45rem 0.65rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--border-radius);
    color: #cbd5e1;
}

.sidebar-system-badge i {
    font-size: 1.15rem;
    flex-shrink: 0;
}

.system-badge-text {
    display: flex;
    flex-direction: column;
    line-height: 1.25;
}

.system-badge-title {
    font-size: 0.75rem;
    font-weight: 700;
    color: #ffffff;
    letter-spacing: 0.02em;
}

.system-badge-sub {
    font-size: 0.65rem;
    color: #94a3b8;
    font-weight: 500;
}

.sidebar-footer .nav-link {
    font-size: var(--font-size-sm);
    color: var(--sidebar-text);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.4rem 0.75rem;
    border-radius: var(--border-radius);
    text-decoration: none;
}

.sidebar-footer .nav-link:hover {
    background-color: var(--sidebar-bg-hover);
    color: var(--sidebar-text-hover);
}

/* Sidebar toggle button on sidebar */
.sidebar-toggle-btn {
    position: absolute;
    bottom: 1rem;
    right: -12px;
    width: 24px;
    height: 24px;
    background: var(--brand-primary);
    border: 2px solid var(--sidebar-bg);
    border-radius: 50%;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 0.65rem;
    z-index: 10;
    transition: background 0.2s;
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}

.sidebar-toggle-btn:hover { background: var(--brand-primary-dark); }

/* ---------------------------------------------------------------------------
   MAIN APPLICATION AREA
   --------------------------------------------------------------------------- */
.app-main {
    margin-left: var(--sidebar-width);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 100vh;
    transition: margin-left 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.app-main.sidebar-collapsed-main {
    margin-left: var(--sidebar-collapsed-width);
}

/* ---------------------------------------------------------------------------
   TOP NAVIGATION BAR
   --------------------------------------------------------------------------- */
.app-topbar {
    height: var(--topbar-height);
    background: linear-gradient(135deg, #155291 0%, #1b65af 55%, #2073c4 100%);
    border-bottom: 2px solid #124982;
    color: #ffffff;
    display: flex;
    align-items: center;
    padding: 0 var(--content-padding);
    justify-content: space-between;
    gap: 1rem;
    position: sticky;
    top: 0;
    z-index: 1040;
    box-shadow: 0 2px 8px rgba(27, 101, 175, 0.22);
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 1rem;
    min-width: 0;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 0;
}

/* Mobile sidebar toggle button */
.topbar-menu-btn {
    display: none;
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.28);
    border-radius: var(--border-radius);
    color: #ffffff;
    padding: 0.4rem 0.55rem;
    cursor: pointer;
    line-height: 1;
    font-size: 1.15rem;
    transition: all 0.15s ease;
}

.topbar-menu-btn:hover {
    background: rgba(255, 255, 255, 0.25);
    color: #ffffff;
}

/* Breadcrumb */
.topbar-breadcrumb {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: var(--font-size-sm);
    color: rgba(255, 255, 255, 0.75);
    flex-wrap: nowrap;
    overflow: hidden;
}

.topbar-breadcrumb a {
    color: rgba(255, 255, 255, 0.85);
    text-decoration: none;
    white-space: nowrap;
}

.topbar-breadcrumb a:hover { color: #ffffff; text-decoration: underline; }

.topbar-breadcrumb .breadcrumb-sep {
    color: rgba(255, 255, 255, 0.5);
    font-size: 0.65rem;
}

.topbar-breadcrumb .breadcrumb-current {
    color: #ffffff;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Tenant Badge on Topbar */
.tenant-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    background: rgba(255, 255, 255, 0.14);
    border: 1px solid rgba(255, 255, 255, 0.28);
    border-radius: var(--border-radius);
    padding: 0.35rem 0.75rem;
    font-size: var(--font-size-sm);
    color: #ffffff;
    white-space: nowrap;
    backdrop-filter: blur(4px);
}

.tenant-badge .tenant-dot {
    width: 8px;
    height: 8px;
    background: #34d399; /* Bright emerald */
    border-radius: 50%;
    flex-shrink: 0;
    box-shadow: 0 0 6px rgba(52, 211, 153, 0.8);
    animation: pulse-dot 2s infinite;
}

.tenant-badge .tenant-label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: rgba(255, 255, 255, 0.82) !important;
}

.tenant-badge strong {
    font-size: 0.8125rem;
    color: #ffffff !important;
    font-weight: 700;
}

.tenant-badge .tenant-sub {
    font-size: 0.7rem;
    color: rgba(255, 255, 255, 0.75) !important;
}

/* System health indicator (Legacy fallback) */
.db-status-badge {
    display: none !important;
}

/* Clock on Topbar */
.topbar-clock {
    font-size: 0.8rem;
    font-weight: 500;
    color: #ffffff;
    background: rgba(0, 0, 0, 0.16);
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: var(--border-radius);
    padding: 0.32rem 0.7rem;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
}

/* User Avatar & Dropdown on Topbar */
.user-menu-toggle {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    text-decoration: none;
    color: #ffffff !important;
    padding: 0.25rem 0.6rem;
    border-radius: var(--border-radius);
    transition: background 0.15s ease;
}

.user-menu-toggle:hover {
    background: rgba(255, 255, 255, 0.15);
    color: #ffffff !important;
}

.user-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: #ffffff;
    color: #1b65af;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.875rem;
    font-weight: 700;
    flex-shrink: 0;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.95);
}

.user-name {
    font-size: var(--font-size-base);
    font-weight: 600;
    color: #ffffff !important;
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-menu-toggle i.bi-chevron-down {
    color: rgba(255, 255, 255, 0.75) !important;
}

/* ---------------------------------------------------------------------------
   PAGE CONTENT AREA
   --------------------------------------------------------------------------- */
.page-content {
    flex: 1;
    padding: var(--content-padding);
    max-width: 100%;
}

/* ---------------------------------------------------------------------------
   PAGE HEADER — Standardized across all pages
   --------------------------------------------------------------------------- */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.page-header-left { flex: 1; min-width: 0; }

.page-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--color-text-primary);
    letter-spacing: -0.02em;
    margin: 0 0 0.35rem 0;
    line-height: 1.3;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.page-title-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--border-radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
    box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}

.page-subtitle {
    font-size: 0.875rem;
    color: #475569;
    margin: 0;
    line-height: 1.5;
}

.page-header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    flex-shrink: 0;
}

/* ---------------------------------------------------------------------------
   FOOTER
   --------------------------------------------------------------------------- */
.app-footer {
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
    padding: 0 var(--content-padding);
    height: var(--footer-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    gap: 1rem;
}

.footer-brand {
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--color-text-primary);
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.footer-meta {
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: nowrap;
}

.footer-sep { color: var(--color-border-strong); }

/* ---------------------------------------------------------------------------
   PHASE 2: TYPOGRAPHY SYSTEM
   --------------------------------------------------------------------------- */
h1, .h1 { font-size: var(--font-size-3xl); font-weight: 700; letter-spacing: -0.5px; }
h2, .h2 { font-size: var(--font-size-2xl); font-weight: 700; letter-spacing: -0.3px; }
h3, .h3 { font-size: var(--font-size-xl); font-weight: 600; }
h4, .h4 { font-size: var(--font-size-lg); font-weight: 600; }
h5, .h5 { font-size: var(--font-size-md); font-weight: 600; }
h6, .h6 { font-size: var(--font-size-base); font-weight: 600; }

code, .font-mono {
    font-family: var(--font-mono);
    font-size: 0.85em;
    background: var(--color-surface-alt);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-sm);
    padding: 0.1em 0.4em;
    color: var(--brand-secondary);
}

/* ---------------------------------------------------------------------------
   PHASE 2: CARD SYSTEM
   --------------------------------------------------------------------------- */
.card {
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-md);
    background: var(--color-surface);
    box-shadow: 0 1px 3px 0 rgba(15, 23, 42, 0.08), 0 1px 2px -1px rgba(15, 23, 42, 0.04);
    display: flex;
    flex-direction: column;
}

.card > .card-body {
    flex: 1 1 auto;
}

/* Card row height and alignment harmonization across all grid columns */
.row:not(.align-items-start) > [class*="col"]:has(> .kpi-card),
.row:not(.align-items-start) > [class*="col"]:has(> .card),
.row:not(.align-items-start) > [class*="col"]:has(> .table-card) {
    display: flex;
    flex-direction: column;
}

.row:not(.align-items-start) > [class*="col"] > .kpi-card,
.row:not(.align-items-start) > [class*="col"] > .card,
.row:not(.align-items-start) > [class*="col"] > .table-card {
    flex: 1 1 auto;
    width: 100%;
}

.card-header {
    padding: 0.875rem 1.25rem;
    background: #f8fafc;
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.card-header-title {
    font-size: var(--font-size-base);
    font-weight: 600;
    color: var(--color-text-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0;
}

.card-header-title i {
    color: var(--brand-primary);
}

.card-body {
    padding: 1.25rem;
}

.card-footer {
    padding: 0.75rem 1.25rem;
    background: var(--color-surface-alt);
    border-top: 1px solid var(--color-border);
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
}

/* KPI / Stat Cards */
.kpi-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-md);
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    gap: 0.35rem;
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.2s, transform 0.2s;
    position: relative;
    overflow: hidden;
    height: 100%; /* Guarantees identical card length / height across the entire row */
    min-height: 146px;
}

.kpi-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 4px;
    border-radius: var(--border-radius-md) var(--border-radius-md) 0 0;
}

.kpi-card.kpi-primary::before,   .kpi-card.primary::before   { background: var(--brand-primary); }
.kpi-card.kpi-success::before,   .kpi-card.success::before   { background: var(--color-success); }
.kpi-card.kpi-warning::before,   .kpi-card.warning::before   { background: var(--color-warning); }
.kpi-card.kpi-danger::before,    .kpi-card.danger::before    { background: var(--color-danger); }
.kpi-card.kpi-info::before,      .kpi-card.info::before      { background: var(--color-info); }
.kpi-card.kpi-secondary::before, .kpi-card.secondary::before { background: var(--color-text-muted); }
.kpi-card.kpi-accent::before,    .kpi-card.accent::before    { background: var(--brand-accent); }

.kpi-card:hover {
    box-shadow: 0 6px 16px rgba(15, 23, 42, 0.1);
    transform: translateY(-2px);
}

.kpi-label {
    font-size: 0.8125rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #334155;
    padding-right: 48px;
    line-height: 1.35;
    min-height: 2.7rem; /* Standardizes label height so numbers align horizontally */
    display: flex;
    align-items: flex-start;
}

.kpi-value {
    font-size: 2rem;
    font-weight: 800;
    color: #0f172a;
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
    margin: 0.25rem 0 0.5rem 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.kpi-icon {
    position: absolute;
    top: 1.15rem;
    right: 1.15rem;
    width: 44px;
    height: 44px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.kpi-footer,
.kpi-desc {
    font-size: 0.8125rem;
    color: #475569;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.35rem;
    margin-top: auto; /* Pins footers to exact same bottom baseline */
    padding-top: 0.5rem;
    border-top: 1px dashed #f1f5f9;
}

/* Color variants for KPI icons & badges */
.bg-primary-soft   { background: #eff6ff !important; color: #1d4ed8 !important; border: 1px solid #bfdbfe; }
.bg-success-soft   { background: #ecfdf5 !important; color: #047857 !important; border: 1px solid #a7f3d0; }
.bg-warning-soft   { background: #fffbeb !important; color: #b45309 !important; border: 1px solid #fde68a; }
.bg-danger-soft    { background: #fef2f2 !important; color: #b91c1c !important; border: 1px solid #fecaca; }
.bg-info-soft      { background: #f0f9ff !important; color: #0284c7 !important; border: 1px solid #bae6fd; }
.bg-accent-soft    { background: #f5f3ff !important; color: #7c3aed !important; border: 1px solid #ddd6fe; }
.bg-secondary-soft { background: #f1f5f9 !important; color: #334155 !important; border: 1px solid #cbd5e1; }

/* ---------------------------------------------------------------------------
   PHASE 2: BUTTON SYSTEM
   Strict Enterprise Grid: 38px standard, 34px small, 28px action buttons
   --------------------------------------------------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    height: 38px;
    padding: 0 1rem;
    font-size: var(--font-size-base);
    font-weight: 500;
    border-radius: var(--border-radius);
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
    text-decoration: none;
    line-height: 36px;
    box-sizing: border-box;
    vertical-align: middle;
    font-family: var(--font-sans);
}

.btn i, .btn .bi { font-size: 0.9375rem; line-height: 1; display: inline-block; }

.btn-sm {
    height: 34px !important;
    min-height: 34px !important;
    max-height: 34px !important;
    padding: 0 0.75rem !important;
    font-size: var(--font-size-sm) !important;
    line-height: 32px !important;
    border-radius: var(--border-radius-sm);
    gap: 0.35rem;
}

.btn-sm i, .btn-sm .bi { font-size: 0.8125rem; }

.btn-lg {
    height: var(--control-height-lg);
    padding: 0 1.5rem;
    font-size: var(--font-size-md);
    border-radius: var(--border-radius-md);
}

/* Primary */
.btn-primary {
    background: var(--brand-primary);
    border-color: var(--brand-primary);
    color: #fff;
    box-shadow: 0 1px 3px rgba(27,101,175,0.3);
}
.btn-primary:hover {
    background: var(--brand-primary-hover);
    border-color: var(--brand-primary-hover);
    color: #fff;
    box-shadow: 0 2px 6px rgba(27,101,175,0.4);
}
.btn-primary:focus-visible {
    outline: 3px solid rgba(27,101,175,0.4);
    outline-offset: 2px;
}

/* Secondary */
.btn-secondary {
    background: var(--color-surface-alt);
    border-color: var(--color-border-strong);
    color: var(--color-text-secondary);
}
.btn-secondary:hover {
    background: var(--color-border);
    border-color: var(--color-border-strong);
    color: var(--color-text-primary);
}

/* Outline Primary */
.btn-outline-primary {
    background: transparent;
    border-color: var(--brand-primary);
    color: var(--brand-primary);
}
.btn-outline-primary:hover {
    background: var(--brand-primary);
    color: #fff;
}

/* Danger */
.btn-danger {
    background: var(--color-danger);
    border-color: var(--color-danger);
    color: #fff;
}
.btn-danger:hover {
    background: #b91c1c;
    border-color: #b91c1c;
    color: #fff;
}

/* Outline Danger */
.btn-outline-danger {
    background: transparent;
    border-color: var(--color-danger);
    color: var(--color-danger);
}
.btn-outline-danger:hover {
    background: var(--color-danger);
    color: #fff;
}

/* Success */
.btn-success {
    background: var(--color-success);
    border-color: var(--color-success);
    color: #fff;
}

/* Outline Secondary */
.btn-outline-secondary {
    background: transparent;
    border-color: var(--color-border-strong);
    color: var(--color-text-secondary);
}
.btn-outline-secondary:hover {
    background: var(--color-surface-alt);
    color: var(--color-text-primary);
    border-color: var(--color-border-strong);
}

/* Ghost */
.btn-ghost {
    background: transparent;
    border-color: transparent;
    color: var(--color-text-secondary);
}
.btn-ghost:hover {
    background: var(--color-surface-alt);
    color: var(--color-text-primary);
}

/* Loading state */
.btn.loading { pointer-events: none; opacity: 0.75; }
.btn.loading::after {
    content: '';
    width: 14px; height: 14px;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    animation: btn-spin 0.6s linear infinite;
    display: inline-block;
    margin-left: 0.4rem;
}
@keyframes btn-spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------------------
   PHASE 2: FORM CONTROLS — Consistent heights & vertical alignment
   --------------------------------------------------------------------------- */
.form-control:not(.form-control-sm):not(.form-control-lg):not(textarea),
.form-select:not(.form-select-sm):not(.form-select-lg),
.form-control[type="date"]:not(.form-control-sm),
.form-control[type="time"]:not(.form-control-sm),
.form-control[type="datetime-local"]:not(.form-control-sm),
.form-control[type="number"]:not(.form-control-sm) {
    height: 38px !important;
    min-height: 38px !important;
    max-height: 38px !important;
    padding: 0 0.75rem !important;
    line-height: 36px !important;
    font-size: var(--font-size-base) !important;
    border: 1px solid var(--color-border-strong);
    border-radius: var(--border-radius);
    background-color: var(--color-surface);
    color: var(--color-text-primary);
    transition: border-color 0.15s, box-shadow 0.15s;
    font-family: var(--font-sans);
    box-sizing: border-box !important;
    vertical-align: middle;
}

textarea.form-control {
    height: auto !important;
    min-height: 80px !important;
    max-height: none !important;
    padding: 0.5rem 0.75rem !important;
    line-height: 1.5 !important;
    resize: vertical;
}

.form-control:focus,
.form-select:focus {
    border-color: var(--brand-primary);
    box-shadow: 0 0 0 3px rgba(27,101,175,0.15);
    outline: none;
}

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

.form-control:disabled,
.form-control[readonly],
.form-select:disabled {
    background-color: var(--color-surface-alt);
    color: var(--color-text-muted);
    cursor: not-allowed;
}

.form-control.form-control-sm,
.form-select.form-select-sm,
input[type="date"].form-control-sm,
input[type="time"].form-control-sm {
    height: 34px !important;
    min-height: 34px !important;
    max-height: 34px !important;
    font-size: var(--font-size-sm) !important;
    line-height: 32px !important;
    padding: 0 0.65rem !important;
    box-sizing: border-box !important;
    vertical-align: middle;
}

.form-control.form-control-lg,
.form-select.form-select-lg {
    height: var(--control-height-lg);
    font-size: var(--font-size-md);
}

/* Input Groups */
.input-group {
    align-items: stretch;
}

.input-group:not(.input-group-sm):not(.input-group-lg) > .form-control,
.input-group:not(.input-group-sm):not(.input-group-lg) > .form-select,
.input-group:not(.input-group-sm):not(.input-group-lg) > .input-group-text,
.input-group:not(.input-group-sm):not(.input-group-lg) > .btn {
    height: 38px !important;
    min-height: 38px !important;
    max-height: 38px !important;
    line-height: 36px !important;
    box-sizing: border-box !important;
}

.input-group-sm > .form-control,
.input-group-sm > .form-select,
.input-group-sm > .input-group-text,
.input-group-sm > .btn {
    height: 34px !important;
    min-height: 34px !important;
    max-height: 34px !important;
    line-height: 32px !important;
    box-sizing: border-box !important;
    font-size: var(--font-size-sm) !important;
}

.input-group-text {
    display: flex;
    align-items: center;
    padding: 0 0.75rem;
    font-size: var(--font-size-base);
    color: var(--color-text-secondary);
    background-color: var(--color-surface-alt);
    border: 1px solid var(--color-border-strong);
    border-radius: var(--border-radius);
}

.input-group > .form-control,
.input-group > .form-select { flex: 1; }

.input-group > *:not(:last-child) { border-right: 0; border-radius: var(--border-radius) 0 0 var(--border-radius); }
.input-group > *:not(:first-child) { border-left: 0; border-radius: 0 var(--border-radius) var(--border-radius) 0; }

/* Form Labels */
.form-label {
    display: block;
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--color-text-secondary);
    margin-bottom: 0.375rem;
}

.form-label .required-mark {
    color: var(--color-danger);
    margin-left: 2px;
}

/* Validation */
.form-control.is-invalid,
.form-select.is-invalid {
    border-color: var(--color-danger);
    padding-right: 2.5rem;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' width='12' height='12' fill='none' stroke='%23dc2626'%3e%3ccircle cx='6' cy='6' r='4.5'/%3e%3cpath stroke-linejoin='round' d='M5.8 3.6h.4L6 6.5z'/%3e%3ccircle cx='6' cy='8.2' r='.6' fill='%23dc2626' stroke='none'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 16px 16px;
}

.invalid-feedback {
    display: block;
    font-size: var(--font-size-xs);
    color: var(--color-danger);
    margin-top: 0.25rem;
}

.valid-feedback {
    display: block;
    font-size: var(--font-size-xs);
    color: var(--color-success);
    margin-top: 0.25rem;
}

/* Form sections */
.form-section {
    margin-bottom: 1.5rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--color-border);
}

.form-section:last-child {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

.form-section-title {
    font-size: var(--font-size-sm);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-text-muted);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Switch */
.form-check-input[type="checkbox"].form-check-input,
.form-check-input[type="radio"] {
    width: 1rem;
    height: 1rem;
    margin-top: 0.1rem;
    cursor: pointer;
    accent-color: var(--brand-primary);
}

.form-switch .form-check-input {
    width: 2em;
    height: 1.1em;
}

.form-check-label {
    font-size: var(--font-size-base);
    color: var(--color-text-secondary);
    cursor: pointer;
    padding-left: 0.25rem;
}

/* ---------------------------------------------------------------------------
   PHASE 2: TABLE SYSTEM (Enterprise DataTables)
   --------------------------------------------------------------------------- */
.table-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-md);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.table-card-header {
    padding: 0.75rem 1.25rem;
    background: #f8fafc;
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    flex-wrap: wrap;
    min-height: 52px;
}

.table-card-title {
    font-size: var(--font-size-base);
    font-weight: 600;
    color: var(--color-text-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0;
}

.table-card-title i { color: var(--brand-primary); }

.table-card-actions {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* Table itself */
.table {
    width: 100%;
    border-collapse: collapse;
    margin: 0;
    font-size: var(--font-size-base);
}

/* Primary Data Grid & DataTables Headers — Sapphire Theme (#1b65af) */
.table-card > .table-responsive > table:not(.table-nested):not(.table-sm) > thead > tr > th,
.table-card > .table-responsive > table:not(.table-nested):not(.table-sm) > thead > tr > td,
table.dataTable:not(.table-nested):not(.table-sm) > thead > tr > th,
table.dataTable:not(.table-nested):not(.table-sm) > thead > tr > td,
table.table-sapphire > thead > tr > th {
    padding: 0.7rem 0.85rem !important;
    background-color: #1b65af !important;
    font-size: 0.75rem !important;
    font-weight: 700 !important;
    text-transform: uppercase !important;
    letter-spacing: 0.05em !important;
    color: #ffffff !important;
    border-bottom: 2px solid #124982 !important;
    border-top: none !important;
    border-right: 1px solid rgba(255, 255, 255, 0.14) !important;
    white-space: nowrap !important;
    user-select: none;
    vertical-align: middle !important;
}

.table-card > .table-responsive > table:not(.table-nested):not(.table-sm) > thead > tr > th:last-child,
table.dataTable:not(.table-nested):not(.table-sm) > thead > tr > th:last-child,
table.table-sapphire > thead > tr > th:last-child {
    border-right: none !important;
}

/* DataTables scroll collapse suppression - ensures no duplicate/extra cloned header ever displays */
div.dataTables_scrollBody thead,
div.dataTables_scrollBody thead tr,
div.dataTables_scrollBody thead th,
div.dataTables_scrollBody thead td,
.dataTables_scrollBody table > thead {
    height: 0px !important;
    min-height: 0px !important;
    max-height: 0px !important;
    padding-top: 0px !important;
    padding-bottom: 0px !important;
    border-top: none !important;
    border-bottom: none !important;
    border-left: none !important;
    border-right: none !important;
    margin: 0px !important;
    background: transparent !important;
    color: transparent !important;
    line-height: 0 !important;
    font-size: 0px !important;
    overflow: hidden !important;
    visibility: hidden !important;
    opacity: 0 !important;
}

/* Default / Nested / Card Sub-Table Headers — Clean Subtle Light Slate */
.table th,
.table thead th {
    padding: 0.55rem 0.75rem;
    background-color: #f8fafc;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: #475569;
    border-bottom: 1px solid #e2e8f0;
    border-top: none;
    vertical-align: middle;
}

/* DataTables Sorting Arrow Contrast on Sapphire Header */
table.dataTable:not(.table-nested):not(.table-sm) thead > tr > th.dt-orderable-asc span.dt-column-order:before,
table.dataTable:not(.table-nested):not(.table-sm) thead > tr > th.dt-orderable-desc span.dt-column-order:after,
table.dataTable:not(.table-nested):not(.table-sm) thead .sorting:before,
table.dataTable:not(.table-nested):not(.table-sm) thead .sorting:after,
table.dataTable:not(.table-nested):not(.table-sm) thead .sorting_asc:before,
table.dataTable:not(.table-nested):not(.table-sm) thead .sorting_asc:after,
table.dataTable:not(.table-nested):not(.table-sm) thead .sorting_desc:before,
table.dataTable:not(.table-nested):not(.table-sm) thead .sorting_desc:after,
table.dataTable:not(.table-nested):not(.table-sm) thead th.sorting::after,
table.dataTable:not(.table-nested):not(.table-sm) thead th.sorting::before,
table.dataTable:not(.table-nested):not(.table-sm) thead th.sorting_asc::after,
table.dataTable:not(.table-nested):not(.table-sm) thead th.sorting_desc::after {
    color: #ffffff !important;
    opacity: 0.85 !important;
}

table.dataTable:not(.table-nested):not(.table-sm) thead th:hover:not(.no-sort) {
    background-color: #165696 !important;
    color: #ffffff !important;
}

table.dataTable:not(.table-nested):not(.table-sm) thead th.sorting_asc,
table.dataTable:not(.table-nested):not(.table-sm) thead th.sorting_desc {
    background-color: #14508c !important;
    color: #ffffff !important;
}

.table td {
    padding: 0.55rem 0.75rem;
    border-bottom: 1px solid #e2e8f0;
    color: #0f172a;
    font-size: 0.8125rem;
    vertical-align: middle;
    min-height: var(--table-row-height);
}

.table th.col-actions,
.table td.col-actions {
    width: 78px !important;
    min-width: 78px !important;
    max-width: 88px !important;
    white-space: nowrap !important;
    text-align: center !important;
    padding-left: 0.4rem !important;
    padding-right: 0.4rem !important;
}

.action-dropdown-btn {
    height: 28px !important;
    min-height: 28px !important;
    max-height: 28px !important;
    line-height: 26px !important;
    padding: 0 0.55rem !important;
    font-size: 0.75rem !important;
    font-weight: 600 !important;
    border-radius: var(--border-radius-sm);
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 0.25rem !important;
    box-sizing: border-box !important;
    vertical-align: middle;
}

.col-actions .btn,
.table td.col-actions .btn,
.action-btn-group .btn {
    height: 28px !important;
    min-height: 28px !important;
    max-height: 28px !important;
    line-height: 26px !important;
    padding: 0 0.55rem !important;
    font-size: 0.75rem !important;
    font-weight: 500;
    border-radius: var(--border-radius-sm);
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 0.25rem;
    box-sizing: border-box !important;
    vertical-align: middle;
}

.col-actions .dropdown-menu {
    min-width: 175px !important;
    font-size: 0.8125rem !important;
    padding: 0.35rem !important;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15) !important;
    border: 1px solid var(--color-border) !important;
    border-radius: var(--border-radius) !important;
    z-index: 1060 !important;
}

.col-actions .dropdown-item {
    padding: 0.4rem 0.65rem !important;
    display: flex !important;
    align-items: center !important;
    gap: 0.5rem !important;
    font-size: 0.8125rem !important;
    border-radius: var(--border-radius-sm) !important;
    color: var(--color-text-secondary);
    text-decoration: none;
    cursor: pointer;
}

.col-actions .dropdown-item:hover {
    background-color: var(--color-surface-alt);
    color: var(--color-text-primary);
}

.col-actions .dropdown-item.text-danger:hover {
    background-color: var(--color-danger-bg);
    color: var(--color-danger);
}

.col-actions .dropdown-item i {
    font-size: 0.875rem !important;
    width: 16px !important;
    text-align: center !important;
}

/* Standardized Filter Bar */
.table-filter-bar {
    background: #ffffff;
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-md);
    padding: 0.85rem 1.15rem;
    margin-bottom: 1.25rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.table-filter-bar form.row,
.table-filter-bar .row {
    align-items: flex-end !important;
}

.table-filter-bar .form-label {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #475569;
    margin-bottom: 0.35rem;
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

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

.table tbody tr:hover td { background: rgba(26,86,219,0.02); }

.table-empty-state {
    padding: 3rem 2rem;
    text-align: center;
    color: var(--color-text-muted);
}

.table-empty-state i {
    font-size: 2.5rem;
    display: block;
    margin-bottom: 0.75rem;
    opacity: 0.4;
}

.table-empty-state p {
    font-size: var(--font-size-base);
    margin: 0;
}

/* Cell helpers */
.cell-mono {
    font-family: var(--font-mono);
    font-size: 0.8125rem;
}

.cell-primary { font-weight: 600; color: var(--brand-primary); }
.cell-muted { color: var(--color-text-muted); font-size: var(--font-size-sm); }

/* Action buttons inside table */
.action-btn-group {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

/* ---------------------------------------------------------------------------
   PHASE 2: BADGE SYSTEM
   --------------------------------------------------------------------------- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25em 0.6em;
    font-size: var(--font-size-xs);
    font-weight: 600;
    border-radius: var(--border-radius-sm);
    white-space: nowrap;
    line-height: 1.4;
}

/* Status badges — semantic & high contrast */
.badge-success     { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.badge-warning     { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }
.badge-danger      { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.badge-info        { background: #f0f9ff; color: #075985; border: 1px solid #bae6fd; }
.badge-primary     { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }
.badge-neutral     { background: #f1f5f9; color: #334155; border: 1px solid #cbd5e1; }
.badge-dark        { background: #1e293b; color: #ffffff; border: 1px solid #0f172a; }

/* ---------------------------------------------------------------------------
   PHASE 2: MODAL SYSTEM — Standardized
   --------------------------------------------------------------------------- */
.modal-content {
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-xl);
}

.modal-header {
    padding: 1.125rem 1.5rem;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-surface);
    border-radius: var(--border-radius-lg) var(--border-radius-lg) 0 0;
}

.modal-title {
    font-size: var(--font-size-lg);
    font-weight: 700;
    color: var(--color-text-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0;
}

.modal-title i { color: var(--brand-primary); }

.btn-close {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--color-text-muted);
    font-size: 1rem;
    padding: 0.25rem;
    border-radius: var(--border-radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.7;
    transition: opacity 0.15s;
}

.btn-close:hover { opacity: 1; color: var(--color-text-primary); }

.modal-body {
    padding: 1.5rem;
    color: var(--color-text-primary);
}

.modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--color-border);
    background: var(--color-surface-alt);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.5rem;
    border-radius: 0 0 var(--border-radius-lg) var(--border-radius-lg);
}

/* Modal sizes */
.modal-sm .modal-dialog { max-width: var(--modal-sm-width); }
.modal-md .modal-dialog { max-width: var(--modal-md-width); }
.modal-lg .modal-dialog { max-width: var(--modal-lg-width); }
.modal-xl .modal-dialog { max-width: var(--modal-xl-width); }

/* ---------------------------------------------------------------------------
   PHASE 2: ALERT SYSTEM
   --------------------------------------------------------------------------- */
.alert {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    border-radius: var(--border-radius-md);
    font-size: var(--font-size-base);
    border: 1px solid transparent;
}

.alert i { font-size: 1.1rem; flex-shrink: 0; margin-top: 0.1rem; }

.alert-success {
    background: var(--color-success-bg);
    border-color: var(--color-success-border);
    color: #065f46;
}

.alert-warning {
    background: var(--color-warning-bg);
    border-color: var(--color-warning-border);
    color: #92400e;
}

.alert-danger {
    background: var(--color-danger-bg);
    border-color: var(--color-danger-border);
    color: #991b1b;
}

.alert-info {
    background: var(--color-info-bg);
    border-color: var(--color-info-border);
    color: #0c4a6e;
}

/* ---------------------------------------------------------------------------
   TOAST NOTIFICATIONS
   --------------------------------------------------------------------------- */
.toast-container {
    position: fixed;
    top: calc(var(--topbar-height) + 1rem);
    right: 1.5rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    pointer-events: none;
}

.toast {
    min-width: 300px;
    max-width: 400px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-md);
    padding: 0.875rem 1rem;
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    box-shadow: var(--shadow-lg);
    pointer-events: all;
    animation: toast-in 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    font-size: var(--font-size-base);
}

.toast.hiding { animation: toast-out 0.2s cubic-bezier(0.4, 0, 0.2, 1) forwards; }

@keyframes toast-in {
    from { transform: translateX(100%); opacity: 0; }
    to   { transform: translateX(0); opacity: 1; }
}

@keyframes toast-out {
    to { transform: translateX(100%); opacity: 0; }
}

.toast-icon { font-size: 1.1rem; flex-shrink: 0; margin-top: 0.1rem; }
.toast-body { flex: 1; }
.toast-title { font-weight: 600; margin-bottom: 0.1rem; color: var(--color-text-primary); font-size: var(--font-size-sm); }
.toast-message { color: var(--color-text-secondary); font-size: var(--font-size-sm); }

.toast.toast-success { border-left: 3px solid var(--color-success); }
.toast.toast-success .toast-icon { color: var(--color-success); }
.toast.toast-warning { border-left: 3px solid var(--color-warning); }
.toast.toast-warning .toast-icon { color: var(--color-warning); }
.toast.toast-danger  { border-left: 3px solid var(--color-danger); }
.toast.toast-danger  .toast-icon { color: var(--color-danger); }
.toast.toast-info    { border-left: 3px solid var(--color-info); }
.toast.toast-info    .toast-icon { color: var(--color-info); }

/* ---------------------------------------------------------------------------
   DATATABLE OVERRIDES — jQuery DataTables integration
   --------------------------------------------------------------------------- */
.dataTables_wrapper {
    padding: 0;
    width: 100%;
}

.dt-toolbar-top {
    background: #f8fafc;
    border-bottom: 1px solid var(--color-border);
    padding: 0.75rem 1rem;
}

.dt-toolbar-bottom {
    background: #f8fafc;
    border-top: 1px solid var(--color-border);
    padding: 0.75rem 1rem;
}

.dataTables_wrapper .dataTables_filter,
.dataTables_wrapper .dataTables_length {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.dataTables_wrapper .dataTables_filter label,
.dataTables_wrapper .dataTables_length label {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
    font-weight: 500;
    margin-bottom: 0;
}

.dataTables_wrapper .dataTables_filter input {
    height: 34px !important;
    min-height: 34px !important;
    max-height: 34px !important;
    line-height: 32px !important;
    padding: 0 0.65rem !important;
    font-size: var(--font-size-sm) !important;
    border: 1px solid var(--color-border-strong);
    border-radius: var(--border-radius-sm);
    background: #ffffff;
    color: var(--color-text-primary);
    min-width: 220px;
    box-sizing: border-box !important;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.dataTables_wrapper .dataTables_filter input:focus {
    border-color: var(--brand-primary);
    outline: none;
    box-shadow: 0 0 0 2px rgba(27, 101, 175, 0.2);
}

.dataTables_wrapper .dataTables_length select {
    height: 34px !important;
    min-height: 34px !important;
    max-height: 34px !important;
    line-height: 32px !important;
    padding: 0 0.6rem !important;
    font-size: var(--font-size-sm) !important;
    border: 1px solid var(--color-border-strong);
    border-radius: var(--border-radius-sm);
    background: #ffffff;
    color: var(--color-text-primary);
    cursor: pointer;
    box-sizing: border-box !important;
}

.dt-buttons {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.dt-buttons .btn {
    height: 34px !important;
    min-height: 34px !important;
    max-height: 34px !important;
    line-height: 32px !important;
    font-size: var(--font-size-xs) !important;
    font-weight: 600;
    padding: 0 0.75rem !important;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    border-radius: var(--border-radius-sm);
    box-sizing: border-box !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    box-shadow: none;
}

.dataTables_wrapper .dataTables_info {
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
    padding: 0;
    font-weight: 500;
}

.dataTables_wrapper .dataTables_paginate {
    padding: 0;
    display: flex;
    justify-content: flex-end;
}

.dataTables_paginate .paginate_button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 32px;
    padding: 0 0.5rem;
    margin: 0 1px;
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary) !important;
    border: 1px solid var(--color-border) !important;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    background: var(--color-surface) !important;
    transition: all 0.15s;
    text-decoration: none;
}

.dataTables_paginate .paginate_button:hover:not(.disabled) {
    background: var(--brand-primary-light) !important;
    color: var(--brand-primary) !important;
    border-color: var(--brand-primary) !important;
}

.dataTables_paginate .paginate_button.current {
    background: var(--brand-primary) !important;
    color: #fff !important;
    border-color: var(--brand-primary) !important;
    font-weight: 600;
}

.dataTables_paginate .paginate_button.disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* DataTable toolbar */
.dt-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.25rem;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-surface-alt);
    gap: 0.75rem;
    flex-wrap: wrap;
    min-height: 52px;
}

.dt-toolbar-left,
.dt-toolbar-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.dt-search-box {
    position: relative;
    display: inline-flex;
    align-items: center;
}

.dt-search-box i {
    position: absolute;
    left: 0.7rem;
    color: var(--color-text-muted);
    font-size: 0.85rem;
    pointer-events: none;
    z-index: 2;
}

.dt-search-box input {
    height: 34px !important;
    min-height: 34px !important;
    max-height: 34px !important;
    line-height: 32px !important;
    padding: 0 0.65rem 0 2rem !important;
    width: 240px;
    font-size: var(--font-size-sm) !important;
    border: 1px solid var(--color-border-strong) !important;
    border-radius: var(--border-radius-sm) !important;
    background: #ffffff !important;
    color: var(--color-text-primary) !important;
    box-sizing: border-box !important;
}

.dt-page-size {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
}

.dt-page-size select {
    height: 34px !important;
    min-height: 34px !important;
    max-height: 34px !important;
    line-height: 32px !important;
    padding: 0 0.5rem;
    font-size: var(--font-size-sm);
    min-width: 70px;
    box-sizing: border-box !important;
}

/* DataTable export buttons */
.dt-export-btn {
    height: 34px !important;
    min-height: 34px !important;
    max-height: 34px !important;
    line-height: 32px !important;
    padding: 0 0.75rem !important;
    font-size: var(--font-size-xs) !important;
    font-weight: 600;
    border-radius: var(--border-radius-sm);
    border: 1px solid var(--color-border-strong);
    background: var(--color-surface);
    color: var(--color-text-secondary);
    cursor: pointer;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 0.35rem;
    transition: all 0.15s;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    box-sizing: border-box !important;
    vertical-align: middle;
}

.dt-export-btn:hover {
    background: var(--color-surface-alt);
    color: var(--color-text-primary);
    border-color: var(--color-border-strong);
}

.dt-export-btn.btn-excel  { color: #16a34a; }
.dt-export-btn.btn-csv    { color: var(--color-info); }
.dt-export-btn.btn-pdf    { color: var(--color-danger); }
.dt-export-btn.btn-copy   { color: var(--color-text-secondary); }
.dt-export-btn.btn-print  { color: var(--color-text-primary); }

/* Table footer */
.dt-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 1.25rem;
    border-top: 1px solid var(--color-border);
    background: var(--color-surface-alt);
    flex-wrap: wrap;
    gap: 0.5rem;
}

/* ---------------------------------------------------------------------------
   UTILITY CLASSES
   --------------------------------------------------------------------------- */
.text-primary     { color: var(--brand-primary) !important; }
.text-secondary   { color: var(--color-text-secondary) !important; }
.text-muted       { color: var(--color-text-muted) !important; }
.text-success     { color: var(--color-success) !important; }
.text-warning     { color: var(--color-warning) !important; }
.text-danger      { color: var(--color-danger) !important; }
.text-info        { color: var(--color-info) !important; }

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

.font-mono { font-family: var(--font-mono); }

.fs-xs { font-size: var(--font-size-xs); }
.fs-sm { font-size: var(--font-size-sm); }
.fs-base { font-size: var(--font-size-base); }
.fs-md { font-size: var(--font-size-md); }

/* Loading overlay */
.loading-overlay {
    position: absolute;
    inset: 0;
    background: rgba(255,255,255,0.75);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    border-radius: inherit;
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--color-border);
    border-top-color: var(--brand-primary);
    border-radius: 50%;
    animation: spinner-rotate 0.7s linear infinite;
}

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

/* ISO clause tag */
.iso-tag {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    font-size: var(--font-size-xs);
    font-weight: 700;
    color: var(--color-text-muted);
    background: var(--color-surface-alt);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-sm);
    padding: 0.15em 0.5em;
    letter-spacing: 0.03em;
    text-transform: uppercase;
}

/* Divider line with label */
.section-divider {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin: 1.5rem 0;
    color: var(--color-text-muted);
    font-size: var(--font-size-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.section-divider::before,
.section-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--color-border);
}

/* QMS border-start variants */
.border-start.border-primary { border-left-color: var(--brand-primary) !important; }
.border-start.border-success { border-left-color: var(--color-success) !important; }
.border-start.border-danger  { border-left-color: var(--color-danger) !important; }
.border-start.border-warning { border-left-color: var(--color-warning) !important; }
.border-start.border-info    { border-left-color: var(--color-info) !important; }

/* ---------------------------------------------------------------------------
   CONFIRMATION MODAL
   --------------------------------------------------------------------------- */
.confirm-modal-icon {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.75rem;
    margin: 0 auto 1rem;
}

.confirm-modal-icon.danger { background: var(--color-danger-bg); color: var(--color-danger); }
.confirm-modal-icon.warning { background: var(--color-warning-bg); color: var(--color-warning); }

/* ---------------------------------------------------------------------------
   PHASE 6: RESPONSIVE
   --------------------------------------------------------------------------- */
@media (max-width: 1024px) {
    :root {
        --content-padding: 1.25rem;
    }
}

@media (max-width: 768px) {
    :root {
        --content-padding: var(--content-padding-sm);
    }

    .app-sidebar {
        transform: translateX(-100%);
        transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1), width 0.25s;
        width: var(--sidebar-width) !important;
    }

    .app-sidebar.mobile-open {
        transform: translateX(0);
    }

    .app-main {
        margin-left: 0 !important;
    }

    .topbar-menu-btn {
        display: flex;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .page-header-actions {
        width: 100%;
    }

    .topbar-clock,
    .db-status-badge,
    .tenant-badge .tenant-label { display: none; }

    .user-name { display: none; }

    .footer-meta { display: none; }

    .table-card-header { flex-direction: column; align-items: flex-start; }
    .table-card-actions { width: 100%; }

    .dt-toolbar { flex-direction: column; align-items: flex-start; }
    .dt-search-box input { width: 100%; }

    .modal-dialog { margin: 0.75rem; }
    .modal-sm .modal-dialog,
    .modal-md .modal-dialog,
    .modal-lg .modal-dialog { max-width: calc(100vw - 1.5rem); }

    .kpi-value { font-size: 1.5rem; }
}

@media (max-width: 576px) {
    .btn { font-size: var(--font-size-sm); }
    .btn-sm { height: 28px; font-size: var(--font-size-xs); }
    .table th, .table td { padding: 0.5rem 0.75rem; }
    .page-title { font-size: var(--font-size-xl); }
}

/* Mobile sidebar overlay */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1049;
    backdrop-filter: blur(2px);
}

@media (max-width: 768px) {
    .sidebar-overlay.active { display: block; }
}

/* ---------------------------------------------------------------------------
   DROPDOWN OVERRIDES
   --------------------------------------------------------------------------- */
.dropdown-menu {
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-md);
    box-shadow: var(--shadow-lg);
    padding: 0.375rem;
    min-width: 180px;
    background: var(--color-surface);
    font-size: var(--font-size-base);
}

.dropdown-item {
    padding: 0.5rem 0.75rem;
    border-radius: var(--border-radius-sm);
    color: var(--color-text-secondary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
    transition: background 0.1s;
}

.dropdown-item i { width: 1rem; text-align: center; }

.dropdown-item:hover {
    background: var(--color-surface-alt);
    color: var(--color-text-primary);
}

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

.dropdown-header {
    font-size: var(--font-size-xs);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-text-muted);
    padding: 0.5rem 0.75rem 0.25rem;
}

.dropdown-divider {
    border-top: 1px solid var(--color-border);
    margin: 0.375rem 0;
}

/* ---------------------------------------------------------------------------
   LIST GROUP OVERRIDES
   --------------------------------------------------------------------------- */
.list-group-item {
    border-color: var(--color-border);
    color: var(--color-text-primary);
    padding: 0.75rem 1rem;
    font-size: var(--font-size-base);
}

.list-group-item:first-child { border-radius: var(--border-radius) var(--border-radius) 0 0; }
.list-group-item:last-child  { border-radius: 0 0 var(--border-radius) var(--border-radius); }

/* ---------------------------------------------------------------------------
   MISCELLANEOUS
   --------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------
   ADVANCED SCROLLABLE TABLE & COLUMN RETENTION SYSTEM
   Guarantees no columns are hidden. Uses hscroll / vscroll if length exceeds.
   --------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------
   RESPONSIVE DATA TABLE SYSTEM
   - Horizontal scroll (hscroll) activates smoothly ONLY when columns exceed width.
   - Vertical scroll (vscroll) is NOT forced on every grid; tables expand naturally with
     pagination, letting the whole page scroll smoothly.
   - Vertical scroll (vscroll) applies ONLY when explicitly opted in via .table-vscroll
     or .has-vscroll.
   --------------------------------------------------------------------------- */
.table-card > .table-responsive,
.table-responsive {
    width: 100%;
    overflow-x: auto;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
    border-radius: 0 0 var(--border-radius-md) var(--border-radius-md);
    position: relative;
}

/* Opt-in vertical scroll (ONLY when explicitly required) */
.table-responsive.table-vscroll,
.table-card.has-vscroll > .table-responsive {
    overflow-y: auto !important;
    max-height: calc(100vh - 270px);
}

.table-card > .table-responsive > table:not(.no-datatable):not(.table-nested):not(.table-sm) {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

/* Sticky Header on vertical scroll only when vscroll is explicitly enabled */
.table-responsive.table-vscroll thead th,
.table-card.has-vscroll > .table-responsive thead th {
    position: sticky;
    top: 0;
    z-index: 5;
    background-color: #1b65af !important;
    color: #ffffff !important;
    box-shadow: 0 2px 5px rgba(27, 101, 175, 0.28);
}

/* Retain full cell contents without awkward text compression on data grids */
.table-card > .table-responsive > table:not(.table-nested):not(.table-sm) th,
.table-card > .table-responsive > table:not(.table-nested):not(.table-sm) td {
    white-space: nowrap;
}

/* Small, card, and nested tables - fluid and scoped */
.card-body .table,
table.table-sm,
table.table-nested {
    min-width: 0 !important;
    width: 100% !important;
    white-space: normal;
}

/* Scoped Role Permissions Inner Scroll Container */
.role-permissions-list {
    max-height: 240px;
    overflow-y: auto;
    overflow-x: hidden;
    border: 1px solid #e2e8f0;
    border-radius: var(--border-radius-sm);
    overscroll-behavior: contain;
    background-color: #ffffff;
}

.role-permissions-list table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background-color: #f8fafc !important;
    color: #475569 !important;
    border-bottom: 1px solid #e2e8f0 !important;
    font-size: 0.7rem !important;
    padding: 0.45rem 0.75rem !important;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.role-permissions-list table td {
    padding: 0.45rem 0.75rem !important;
    font-size: 0.75rem !important;
    border-bottom: 1px solid #f1f5f9;
}

/* Modern smooth scrollbars for horizontal and vertical scrolling */
.table-responsive::-webkit-scrollbar,
.dataTables_scrollBody::-webkit-scrollbar {
    width: 7px;
    height: 7px;
}

.table-responsive::-webkit-scrollbar-track,
.dataTables_scrollBody::-webkit-scrollbar-track {
    background: #f8fafc;
    border-radius: 4px;
}

.table-responsive::-webkit-scrollbar-thumb,
.dataTables_scrollBody::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

.table-responsive::-webkit-scrollbar-thumb:hover,
.dataTables_scrollBody::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

::selection {
    background: rgba(26,86,219,0.2);
    color: var(--color-text-primary);
}

a { color: var(--brand-primary); text-decoration: none; }
a:hover { color: var(--brand-primary-dark); text-decoration: underline; }

.text-decoration-none { text-decoration: none; }
.text-decoration-none:hover { text-decoration: none; }

/* Print styles */
@media print {
    .app-sidebar, .app-topbar, .app-footer,
    .page-header-actions, .action-btn-group,
    .dt-toolbar, .dataTables_paginate { display: none !important; }
    .app-main { margin-left: 0 !important; }
    .page-content { padding: 0 !important; }
    .table-card { box-shadow: none; border: 1px solid #ccc; }
}
