/* ============================================================================
   Transport ERP — Enterprise Design System
   Layered on top of Bootstrap 5. No markup/logic changes required.
   ============================================================================ */

/* ---------- Design Tokens ---------- */
:root {
    /* Brand */
    --color-primary-950: #172554;
    --color-primary-900: #1E3A8A;
    --color-primary-800: #1E40AF;
    --color-primary-700: #1D4ED8;
    --color-primary-600: #2563EB;
    --color-primary-500: #3B82F6;
    --color-indigo-600: #4F46E5;
    --color-indigo-500: #6366F1;
    --gradient-brand: radial-gradient(1200px 600px at 20% 10%, #4F46E5 0%, transparent 60%), linear-gradient(135deg, #1E3A8A 0%, #2563EB 55%, #4F46E5 100%);
    --gradient-primary: linear-gradient(135deg, #1E3A8A 0%, #2563EB 55%, #4F46E5 100%);
    --brand-primary: #2563EB;
    --brand-primary-rgb: 37, 99, 235;
    --brand-primary-hover: #1D4ED8;
    --brand-primary-active: #1E40AF;
    --brand-secondary: #4F46E5;
    --brand-success: #16A34A;
    --brand-warning: #D97706;
    --brand-danger: #DC2626;
    --brand-info: #0284C7;

    /* 8-point spacing */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 24px;
    --space-6: 32px;
    --space-7: 48px;
    --space-8: 64px;

    /* Radii */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius-pill: 999px;

    /* Typography */
    --font-sans: 'Inter', 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    --font-display: 'Plus Jakarta Sans', 'Inter', var(--font-sans);
    --fs-xs: 0.75rem;
    --fs-sm: 0.8125rem;
    --fs-base: 0.875rem;
    --fs-md: 0.9375rem;
    --fs-lg: 1.0625rem;
    --fs-xl: 1.25rem;
    --fs-2xl: 1.5rem;
    --fs-3xl: 1.875rem;

    /* Shadows (light) */
    --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08);
    --shadow-lg: 0 12px 28px rgba(15, 23, 42, 0.10);
    --shadow-xl: 0 24px 48px rgba(15, 23, 42, 0.14);

    /* Motion */
    --ease: cubic-bezier(0.4, 0, 0.2, 1);
    --t-fast: 150ms var(--ease);
    --t: 200ms var(--ease);
    --t-slow: 250ms var(--ease);

    /* Z-index scale */
    --z-sidebar: 1030;
    --z-topnav: 1020;
    --z-dropdown: 1040;
    --z-modal: 1055;
    --z-toast: 1090;

    /* Shell metrics */
    --sidebar-w: 264px;
    --sidebar-collapsed-w: 76px;
    --topnav-h: 62px;

    /* Controls */
    --control-height-sm: 34px;
    --control-height: 40px;
    --control-height-lg: 46px;

    /* Semantic — Light theme */
    --bg-app: #F4F7FC;
    --bg-surface: #FFFFFF;
    --bg-surface-2: #F8FAFC;
    --bg-surface-3: #F1F5F9;
    --bg-hover: #EFF6FF;
    --bg-selected: #DBEAFE;
    --text-primary: #0F172A;
    --text-secondary: #334155;
    --text-muted: #64748B;
    --border-color: #DCE3ED;
    --border-subtle: #E8EDF4;
    --border-strong: #CBD5E1;

    /* Readable aliases for page and plugin styles */
    --page-bg: var(--bg-app);
    --surface-1: var(--bg-surface);
    --surface-2: var(--bg-surface-2);
    --surface-3: var(--bg-surface-3);
    --surface-hover: var(--bg-hover);
    --surface-selected: var(--bg-selected);

    --sidebar-bg: #FFFFFF;
    --sidebar-border: #E7ECF3;
    --sidebar-item: #475569;
    --sidebar-item-hover-bg: #F1F5F9;
    --sidebar-item-active-bg: rgba(var(--brand-primary-rgb), 0.10);
    --sidebar-item-active: var(--brand-primary);
    --sidebar-group: #94A3B8;

    --topnav-bg: rgba(255, 255, 255, 0.80);
    --focus-ring: rgba(var(--brand-primary-rgb), 0.35);
}

/* Semantic — Dark theme */
[data-theme="dark"] {
    --bg-app: #07111F;
    --bg-surface: #0F1B2D;
    --bg-surface-2: #142238;
    --bg-surface-3: #1A2A42;
    --bg-hover: #1D3150;
    --bg-selected: rgba(37, 99, 235, 0.22);
    --text-primary: #F1F5F9;
    --text-secondary: #CBD5E1;
    --text-muted: #94A3B8;
    --border-color: #263A55;
    --border-subtle: #1D304A;
    --border-strong: #354B68;

    --sidebar-bg: #0B1728;
    --sidebar-border: #213550;
    --sidebar-item: #B8C5D8;
    --sidebar-item-hover-bg: rgba(255, 255, 255, 0.05);
    --sidebar-item-active-bg: rgba(var(--brand-primary-rgb), 0.20);
    --sidebar-item-active: #93B4FF;
    --sidebar-group: #8292AA;

    --topnav-bg: rgba(7, 17, 31, 0.88);
    --focus-ring: rgba(96, 165, 250, 0.34);

    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.30);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.35);
    --shadow-md: 0 6px 16px rgba(0, 0, 0, 0.40);
    --shadow-lg: 0 14px 32px rgba(0, 0, 0, 0.50);
    --shadow-xl: 0 28px 56px rgba(0, 0, 0, 0.60);
}

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

html {
    font-size: 16px;
    position: relative;
    min-height: 100%;
}

body {
    margin: 0;
    font-family: var(--font-sans);
    font-size: var(--fs-base);
    line-height: 1.55;
    color: var(--text-primary);
    background-color: var(--bg-app);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    transition: background-color var(--t), color var(--t);
}

h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5 {
    font-family: var(--font-display);
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--text-primary);
}

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

hr { border-color: var(--border-color); opacity: 1; }

::selection { background: rgba(var(--brand-primary-rgb), 0.18); }

/* Focus visibility (a11y) */
:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--focus-ring);
    border-radius: var(--radius-sm);
}

/* Scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--border-color) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: var(--radius-pill); border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); background-clip: content-box; }

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

/* Sidebar */
.app-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar-w);
    background: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-border);
    display: flex;
    flex-direction: column;
    z-index: var(--z-sidebar);
    transition: width var(--t), transform var(--t);
}

.sidebar-header {
    height: var(--topnav-h);
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: 0 var(--space-4);
    border-bottom: 1px solid var(--sidebar-border);
    flex-shrink: 0;
}

.brand-logo {
    width: 36px; height: 36px; flex-shrink: 0;
    border-radius: 10px;
    display: grid; place-items: center;
    background: linear-gradient(135deg, var(--brand-primary), var(--brand-secondary));
    color: #fff; font-family: var(--font-display); font-weight: 800; font-size: 1.05rem;
    box-shadow: 0 4px 12px rgba(var(--brand-primary-rgb), 0.35);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; overflow: hidden; }
.brand-text strong { font-family: var(--font-display); font-size: 0.95rem; color: var(--text-primary); white-space: nowrap; }
.brand-text small { font-size: 0.7rem; color: var(--text-muted); white-space: nowrap; }

.sidebar-search { padding: var(--space-3) var(--space-3) var(--space-2); }
.sidebar-search .input-affix { position: relative; }
.sidebar-search .input-affix svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--text-muted); pointer-events: none; }
.sidebar-search input {
    width: 100%; height: 38px; padding: 0 var(--space-3) 0 36px;
    background: var(--bg-surface-2); border: 1px solid transparent; border-radius: var(--radius-sm);
    color: var(--text-primary); font-size: var(--fs-sm); transition: var(--t-fast);
}
.sidebar-search input::placeholder { color: var(--text-muted); }
.sidebar-search input:focus { outline: none; background: var(--bg-surface); border-color: var(--brand-primary); box-shadow: 0 0 0 3px var(--focus-ring); }

.sidebar-nav { flex: 1; overflow-y: auto; padding: var(--space-2) var(--space-3) var(--space-4); }
.nav-group { margin-top: var(--space-4); }
.nav-group:first-child { margin-top: var(--space-1); }
.nav-group-label {
    font-size: 0.68rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
    color: var(--sidebar-group); padding: 0 var(--space-3); margin-bottom: var(--space-2);
    white-space: nowrap; overflow: hidden;
}

.nav-link-item {
    position: relative;
    display: flex; align-items: center; gap: var(--space-3);
    padding: 9px var(--space-3); margin-bottom: 2px;
    border-radius: var(--radius-sm);
    color: var(--sidebar-item); font-size: var(--fs-base); font-weight: 500;
    white-space: nowrap; overflow: hidden;
    transition: background var(--t-fast), color var(--t-fast);
}
.nav-link-item:hover { background: var(--sidebar-item-hover-bg); color: var(--text-primary); }
.nav-link-item svg { width: 19px; height: 19px; flex-shrink: 0; }
.nav-link-item .nav-text { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.nav-link-item.active { background: var(--sidebar-item-active-bg); color: var(--sidebar-item-active); font-weight: 600; }
.nav-link-item.active::before {
    content: ""; position: absolute; left: 0; top: 50%; transform: translateY(-50%);
    width: 3px; height: 20px; border-radius: var(--radius-pill); background: var(--sidebar-item-active);
}

.sidebar-footer { border-top: 1px solid var(--sidebar-border); padding: var(--space-3); flex-shrink: 0; }
.user-chip {
    display: flex; align-items: center; gap: var(--space-3);
    padding: var(--space-2); border-radius: var(--radius-sm); cursor: pointer;
    transition: background var(--t-fast);
}
.user-chip:hover { background: var(--sidebar-item-hover-bg); }
.user-avatar {
    width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0;
    display: grid; place-items: center; font-weight: 700; font-size: 0.85rem; color: #fff;
    background: linear-gradient(135deg, var(--brand-secondary), var(--brand-primary));
}
.user-chip .user-meta { overflow: hidden; line-height: 1.2; }
.user-chip .user-meta strong { display: block; font-size: var(--fs-sm); color: var(--text-primary); white-space: nowrap; text-overflow: ellipsis; overflow: hidden; }
.user-chip .user-meta small { font-size: 0.7rem; color: var(--text-muted); }

/* Collapsed sidebar */
.app-shell.sidebar-collapsed .app-sidebar { width: var(--sidebar-collapsed-w); }
.app-shell.sidebar-collapsed .brand-text,
.app-shell.sidebar-collapsed .sidebar-search,
.app-shell.sidebar-collapsed .nav-group-label,
.app-shell.sidebar-collapsed .nav-text,
.app-shell.sidebar-collapsed .user-meta { display: none; }
.app-shell.sidebar-collapsed .sidebar-header { justify-content: center; padding: 0; }
.app-shell.sidebar-collapsed .nav-link-item { justify-content: center; padding: 10px 0; }
.app-shell.sidebar-collapsed .user-chip { justify-content: center; }
.app-shell.sidebar-collapsed .app-main { margin-left: var(--sidebar-collapsed-w); }
/* Tooltip when collapsed */
.app-shell.sidebar-collapsed .nav-link-item[data-title]:hover::after {
    content: attr(data-title);
    position: absolute; left: calc(100% + 10px); top: 50%; transform: translateY(-50%);
    background: #0F172A; color: #fff; font-size: var(--fs-xs); font-weight: 600;
    padding: 6px 10px; border-radius: var(--radius-sm); white-space: nowrap; z-index: var(--z-dropdown);
    box-shadow: var(--shadow-lg);
}

/* Desktop hover-expand: strictly pointer-driven so a clicked control cannot leave
   the rail latched open. Content fades in just after the width transition starts. */
@media (min-width: 992px) {
    .app-shell.sidebar-collapsed .app-sidebar {
        will-change: width;
        transition: width 180ms cubic-bezier(.2, .8, .2, 1), box-shadow 180ms ease;
    }
    .app-shell.sidebar-collapsed .app-sidebar:hover {
        width: var(--sidebar-w);
        box-shadow: 12px 0 28px rgba(15, 23, 42, .13);
    }
    .app-shell.sidebar-collapsed .app-sidebar:hover .brand-text { display: flex; }
    .app-shell.sidebar-collapsed .app-sidebar:hover .sidebar-search,
    .app-shell.sidebar-collapsed .app-sidebar:hover .nav-group-label,
    .app-shell.sidebar-collapsed .app-sidebar:hover .nav-text,
    .app-shell.sidebar-collapsed .app-sidebar:hover .user-meta { display: block; }
    .app-shell.sidebar-collapsed .app-sidebar:hover :is(.brand-text, .sidebar-search, .nav-group-label, .nav-text, .user-meta) {
        animation: sidebarHoverContentIn 120ms ease 65ms both;
    }
    .app-shell.sidebar-collapsed .app-sidebar:hover .sidebar-header {
        justify-content: flex-start;
        padding: 0 var(--space-4);
    }
    .app-shell.sidebar-collapsed .app-sidebar:hover .nav-link-item {
        justify-content: flex-start;
        padding: 9px var(--space-3);
    }
    .app-shell.sidebar-collapsed .app-sidebar:hover .user-chip { justify-content: flex-start; }
    .app-shell.sidebar-collapsed .app-sidebar:hover .nav-link-item[data-title]::after { display: none; }
    .app-shell.sidebar-collapsed .app-sidebar:hover .nav-group-toggle { display: flex; }
    .app-shell.sidebar-collapsed .app-sidebar:hover .nav-group-items { max-height: 0; }
    .app-shell.sidebar-collapsed .app-sidebar:hover .nav-group.open > .nav-group-items { max-height: 640px; }
}
@keyframes sidebarHoverContentIn {
    from { opacity: 0; transform: translateX(-4px); }
    to { opacity: 1; transform: translateX(0); }
}

/* Main column */
.app-main {
    flex: 1; min-width: 0; margin-left: var(--sidebar-w);
    display: flex; flex-direction: column; transition: margin var(--t);
}

/* Topnav */
.app-topnav {
    position: sticky; top: 0; z-index: var(--z-topnav);
    height: var(--topnav-h);
    display: flex; align-items: center; gap: var(--space-3);
    padding: 0 var(--space-5);
    background: var(--topnav-bg);
    backdrop-filter: saturate(180%) blur(12px);
    -webkit-backdrop-filter: saturate(180%) blur(12px);
    border-bottom: 1px solid var(--border-color);
}

.icon-btn {
    width: 40px; height: 40px; flex-shrink: 0;
    display: grid; place-items: center;
    border: 1px solid transparent; border-radius: var(--radius-sm);
    background: transparent; color: var(--text-secondary); cursor: pointer;
    transition: var(--t-fast); position: relative;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn .dot { position: absolute; top: 8px; right: 9px; width: 8px; height: 8px; border-radius: 50%; background: var(--brand-danger); border: 2px solid var(--topnav-bg); }

.topnav-search { position: relative; flex: 1; max-width: 440px; }
.topnav-search svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); width: 17px; height: 17px; color: var(--text-muted); }
.topnav-search input {
    width: 100%; height: 40px; padding: 0 var(--space-4) 0 40px;
    background: var(--bg-surface-2); border: 1px solid transparent; border-radius: var(--radius-sm);
    color: var(--text-primary); font-size: var(--fs-sm); transition: var(--t-fast);
}
.topnav-search input:focus { outline: none; background: var(--bg-surface); border-color: var(--brand-primary); box-shadow: 0 0 0 3px var(--focus-ring); }
.topnav-search kbd {
    position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
    font-size: 0.68rem; font-family: var(--font-sans); color: var(--text-muted);
    background: var(--bg-surface); border: 1px solid var(--border-color); border-radius: 6px; padding: 2px 6px;
}

.app-content { padding: var(--space-5); flex: 1; }
@media (min-width: 1400px) { .app-content { padding: var(--space-5) var(--space-6); } }

.breadcrumb-bar { display: flex; align-items: center; gap: var(--space-2); font-size: var(--fs-sm); color: var(--text-muted); }
.breadcrumb-bar .sep { opacity: 0.5; }
.breadcrumb-bar .current { color: var(--text-primary); font-weight: 600; }

/* Page header helper */
.page-header { display: flex; flex-wrap: wrap; gap: var(--space-3); justify-content: space-between; align-items: center; margin-bottom: var(--space-5); }
.page-header h3, .page-header h1 { margin: 0; font-size: var(--fs-2xl); }
.page-header .subtitle { color: var(--text-muted); font-size: var(--fs-sm); margin-top: 2px; }

/* ============================================================================
   Components — Bootstrap overrides
   ============================================================================ */

/* Cards */
.card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    color: var(--text-primary);
    transition: box-shadow var(--t), transform var(--t), border-color var(--t);
}
.card:hover { box-shadow: var(--shadow-md); }
.card-header {
    background: transparent; border-bottom: 1px solid var(--border-subtle);
    padding: var(--space-4) var(--space-5); font-weight: 600; font-family: var(--font-display);
}
.card-body { padding: var(--space-5); }
.card-footer { background: transparent; border-top: 1px solid var(--border-subtle); padding: var(--space-4) var(--space-5); }

/* Buttons */
.btn {
    --bs-btn-focus-box-shadow: 0 0 0 3px var(--focus-ring);
    font-family: var(--font-sans); font-weight: 600; font-size: var(--fs-base);
    border-radius: var(--radius-sm); padding: 8px 16px;
    display: inline-flex; align-items: center; gap: var(--space-2); justify-content: center;
    transition: var(--t-fast); border-width: 1px;
}
.btn:active { transform: translateY(0.5px); }
.btn svg { width: 17px; height: 17px; }
.btn-sm { padding: 5px 11px; font-size: var(--fs-sm); border-radius: 7px; }
.btn-lg { padding: 11px 22px; font-size: var(--fs-md); border-radius: var(--radius-md); }

.btn-primary { --bs-btn-bg: var(--brand-primary); --bs-btn-border-color: var(--brand-primary); --bs-btn-hover-bg: var(--brand-primary-hover); --bs-btn-hover-border-color: var(--brand-primary-hover); --bs-btn-active-bg: var(--brand-primary-active); --bs-btn-active-border-color: var(--brand-primary-active); box-shadow: 0 2px 6px rgba(var(--brand-primary-rgb), 0.30); }
.btn-primary:hover { box-shadow: 0 4px 12px rgba(var(--brand-primary-rgb), 0.40); }
.btn-success { --bs-btn-bg: var(--brand-success); --bs-btn-border-color: var(--brand-success); --bs-btn-hover-bg: #059669; --bs-btn-hover-border-color: #059669; }
.btn-danger { --bs-btn-bg: var(--brand-danger); --bs-btn-border-color: var(--brand-danger); --bs-btn-hover-bg: #DC2626; --bs-btn-hover-border-color: #DC2626; }
.btn-warning { --bs-btn-bg: var(--brand-warning); --bs-btn-border-color: var(--brand-warning); --bs-btn-color: #fff; --bs-btn-hover-color: #fff; --bs-btn-hover-bg: #D97706; --bs-btn-hover-border-color: #D97706; }

.btn-secondary {
    --bs-btn-bg: var(--bg-surface); --bs-btn-border-color: var(--border-color); --bs-btn-color: var(--text-secondary);
    --bs-btn-hover-bg: var(--bg-hover); --bs-btn-hover-border-color: var(--border-color); --bs-btn-hover-color: var(--text-primary);
    --bs-btn-active-bg: var(--bg-hover); --bs-btn-active-color: var(--text-primary); --bs-btn-active-border-color: var(--border-color);
}
.btn-outline-primary { --bs-btn-color: var(--brand-primary); --bs-btn-border-color: rgba(var(--brand-primary-rgb),0.5); --bs-btn-hover-bg: var(--brand-primary); --bs-btn-hover-border-color: var(--brand-primary); --bs-btn-active-bg: var(--brand-primary-active); }
.btn-outline-secondary { --bs-btn-color: var(--text-secondary); --bs-btn-border-color: var(--border-color); --bs-btn-hover-bg: var(--bg-hover); --bs-btn-hover-color: var(--text-primary); --bs-btn-hover-border-color: var(--border-color); }
.btn-outline-danger { --bs-btn-color: var(--brand-danger); --bs-btn-border-color: rgba(239,68,68,0.5); --bs-btn-hover-bg: var(--brand-danger); --bs-btn-hover-border-color: var(--brand-danger); }
.btn-light { --bs-btn-bg: var(--bg-surface-2); --bs-btn-border-color: var(--border-color); --bs-btn-color: var(--text-secondary); --bs-btn-hover-bg: var(--bg-hover); --bs-btn-hover-color: var(--text-primary); }

/* Forms */
.form-label { font-size: var(--fs-sm); font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; }
.form-control, .form-select {
    background-color: var(--bg-surface); border: 1px solid var(--border-color);
    color: var(--text-primary); border-radius: var(--radius-sm);
    padding: 9px 12px; font-size: var(--fs-base); min-height: 42px;
    transition: border-color var(--t-fast), box-shadow var(--t-fast), background var(--t-fast);
}
.form-control::placeholder { color: var(--text-muted); }
.form-control:focus, .form-select:focus {
    background-color: var(--bg-surface); border-color: var(--brand-primary);
    box-shadow: 0 0 0 3px var(--focus-ring); color: var(--text-primary);
}
.form-control:disabled, .form-select:disabled { background: var(--bg-surface-2); color: var(--text-muted); }
.form-select { background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2394A3B8' stroke-width='2'%3e%3cpath stroke-linecap='round' stroke-linejoin='round' d='m6 9 6 6 6-6'/%3e%3c/svg%3e"); background-size: 18px; }
.form-text { color: var(--text-muted); font-size: var(--fs-xs); }
.input-group-text { background: var(--bg-surface-2); border-color: var(--border-color); color: var(--text-secondary); border-radius: var(--radius-sm); }

/* Validation */
.text-danger, .field-validation-error, .validation-summary-errors { color: var(--brand-danger) !important; font-size: var(--fs-xs); }
.input-validation-error { border-color: var(--brand-danger) !important; box-shadow: 0 0 0 3px rgba(239,68,68,0.15); }

/* Checks & switches */
.form-check-input { border-color: var(--border-color); background-color: var(--bg-surface); width: 1.05em; height: 1.05em; }
.form-check-input:checked { background-color: var(--brand-primary); border-color: var(--brand-primary); }
.form-check-input:focus { border-color: var(--brand-primary); box-shadow: 0 0 0 3px var(--focus-ring); }
.form-switch .form-check-input { width: 2.2em; height: 1.15em; }

/* Tables */
.table {
    --bs-table-bg: transparent; color: var(--text-primary);
    margin-bottom: 0; vertical-align: middle; font-size: var(--fs-base);
}
.table > :not(caption) > * > * { padding: 12px 16px; border-bottom-color: var(--border-subtle); background: transparent; }
.table thead th, .table > thead > tr > th, .table-light th {
    background: var(--bg-surface-2) !important; color: var(--text-secondary);
    font-size: var(--fs-xs); font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
    border-bottom: 1px solid var(--border-color); white-space: nowrap;
}
.table tbody tr { transition: background var(--t-fast); }
.table-hover > tbody > tr:hover > * { background: var(--bg-hover); }
.table-striped > tbody > tr:nth-of-type(odd) > * { background: rgba(148, 163, 184, 0.05); }
.card > .table-responsive { border-radius: var(--radius-lg); }
.table-responsive { border-radius: var(--radius-md); }
.table-sticky thead th { position: sticky; top: 0; z-index: 2; }

/* Badges */
.badge {
    font-weight: 600; font-size: var(--fs-xs); letter-spacing: 0.01em;
    padding: 5px 10px; border-radius: var(--radius-pill);
    display: inline-flex; align-items: center; gap: 5px;
}
.badge svg { width: 12px; height: 12px; }
.badge.bg-primary { background: rgba(var(--brand-primary-rgb), 0.12) !important; color: var(--brand-primary) !important; }
.badge.bg-success { background: rgba(16, 185, 129, 0.14) !important; color: #059669 !important; }
.badge.bg-warning { background: rgba(245, 158, 11, 0.16) !important; color: #B45309 !important; }
.badge.bg-danger { background: rgba(239, 68, 68, 0.14) !important; color: #DC2626 !important; }
.badge.bg-info { background: rgba(14, 165, 233, 0.14) !important; color: #0284C7 !important; }
.badge.bg-secondary { background: var(--bg-surface-2) !important; color: var(--text-secondary) !important; }
[data-theme="dark"] .badge.bg-success { color: #34D399 !important; }
[data-theme="dark"] .badge.bg-warning { color: #FBBF24 !important; }
[data-theme="dark"] .badge.bg-danger { color: #F87171 !important; }
[data-theme="dark"] .badge.bg-info { color: #38BDF8 !important; }

/* Status pill helper */
.status-pill { display: inline-flex; align-items: center; gap: 6px; padding: 5px 11px; border-radius: var(--radius-pill); font-size: var(--fs-xs); font-weight: 600; }
.status-pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status-pending { background: rgba(245,158,11,0.14); color: #B45309; }
.status-active, .status-processing { background: rgba(37,99,235,0.12); color: var(--brand-primary); }
.status-completed, .status-approved, .status-paid { background: rgba(16,185,129,0.14); color: #059669; }
.status-draft { background: var(--bg-surface-2); color: var(--text-secondary); }
.status-cancelled, .status-rejected, .status-overdue { background: rgba(239,68,68,0.14); color: #DC2626; }

/* Dropdowns */
.dropdown-menu {
    background: var(--bg-surface); border: 1px solid var(--border-color);
    border-radius: var(--radius-md); box-shadow: var(--shadow-lg); padding: 6px;
    font-size: var(--fs-base); color: var(--text-primary);
    animation: dropdownIn var(--t-fast);
}
.dropdown-item { border-radius: var(--radius-sm); padding: 8px 12px; color: var(--text-secondary); font-weight: 500; display: flex; align-items: center; gap: 10px; }
.dropdown-item:hover, .dropdown-item:focus { background: var(--bg-hover); color: var(--text-primary); }
.dropdown-item.active, .dropdown-item:active { background: var(--brand-primary); color: #fff; }
.dropdown-item svg { width: 16px; height: 16px; }
.dropdown-divider { border-color: var(--border-subtle); }
.dropdown-header { color: var(--text-muted); font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 0.05em; font-weight: 700; }
@keyframes dropdownIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: translateY(0); } }

/* Modals */
.modal-content { background: var(--bg-surface); border: 1px solid var(--border-color); border-radius: var(--radius-lg); box-shadow: var(--shadow-xl); color: var(--text-primary); }
.modal-header { border-bottom: 1px solid var(--border-subtle); padding: var(--space-4) var(--space-5); }
.modal-title { font-family: var(--font-display); font-weight: 700; }
.modal-body { padding: var(--space-5); }
.modal-footer { border-top: 1px solid var(--border-subtle); padding: var(--space-4) var(--space-5); position: sticky; bottom: 0; background: var(--bg-surface); }
.modal-backdrop.show { opacity: 0.5; backdrop-filter: blur(2px); }
.btn-close { border-radius: var(--radius-sm); transition: var(--t-fast); }
[data-theme="dark"] .btn-close { filter: invert(1) grayscale(1) brightness(1.6); }

/* Alerts */
.alert { border: 1px solid transparent; border-radius: var(--radius-md); padding: var(--space-4); font-size: var(--fs-base); display: flex; gap: var(--space-3); }
.alert-success { background: rgba(16,185,129,0.10); border-color: rgba(16,185,129,0.25); color: #047857; }
.alert-danger { background: rgba(239,68,68,0.10); border-color: rgba(239,68,68,0.25); color: #B91C1C; }
.alert-warning { background: rgba(245,158,11,0.10); border-color: rgba(245,158,11,0.25); color: #B45309; }
.alert-info { background: rgba(14,165,233,0.10); border-color: rgba(14,165,233,0.25); color: #0369A1; }

/* Pagination */
.pagination { --bs-pagination-color: var(--text-secondary); --bs-pagination-bg: var(--bg-surface); --bs-pagination-border-color: var(--border-color); --bs-pagination-hover-bg: var(--bg-hover); --bs-pagination-hover-color: var(--text-primary); --bs-pagination-hover-border-color: var(--border-color); --bs-pagination-active-bg: var(--brand-primary); --bs-pagination-active-border-color: var(--brand-primary); --bs-pagination-focus-box-shadow: 0 0 0 3px var(--focus-ring); gap: 4px; }
.page-link { border-radius: var(--radius-sm) !important; margin: 0; }

/* Breadcrumb (bootstrap) */
.breadcrumb { font-size: var(--fs-sm); margin: 0; }
.breadcrumb-item, .breadcrumb-item a { color: var(--text-muted); }
.breadcrumb-item.active { color: var(--text-primary); font-weight: 600; }

/* Nav tabs */
.nav-tabs { border-bottom: 1px solid var(--border-color); gap: 2px; }
.nav-tabs .nav-link { border: none; border-bottom: 2px solid transparent; color: var(--text-secondary); font-weight: 600; border-radius: 0; padding: 10px 14px; }
.nav-tabs .nav-link:hover { color: var(--text-primary); border-bottom-color: var(--border-color); }
.nav-tabs .nav-link.active { color: var(--brand-primary); background: transparent; border-bottom-color: var(--brand-primary); }

/* Definition lists (details/delete views) */
dl.row dt { color: var(--text-secondary); font-weight: 600; }
dl.row dd { color: var(--text-primary); }

/* ---------- KPI / dashboard helpers ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: var(--space-4); }
.kpi-card {
    background: var(--bg-surface); border: 1px solid var(--border-color); border-radius: var(--radius-lg);
    padding: var(--space-5); box-shadow: var(--shadow-sm);
    transition: transform var(--t), box-shadow var(--t), border-color var(--t);
    display: block; color: inherit; position: relative; overflow: hidden;
}
.kpi-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); border-color: rgba(var(--brand-primary-rgb),0.4); color: inherit; }
.kpi-icon { width: 44px; height: 44px; border-radius: var(--radius-md); display: grid; place-items: center; margin-bottom: var(--space-4); }
.kpi-icon svg { width: 22px; height: 22px; }
.kpi-value { font-family: var(--font-display); font-size: var(--fs-3xl); font-weight: 800; line-height: 1; color: var(--text-primary); }
.kpi-label { color: var(--text-muted); font-size: var(--fs-sm); font-weight: 500; margin-top: 6px; }
.kpi-trend { font-size: var(--fs-xs); font-weight: 700; display: inline-flex; align-items: center; gap: 3px; margin-top: var(--space-2); }
.kpi-trend.up { color: var(--brand-success); }
.kpi-trend.down { color: var(--brand-danger); }
.tint-primary { background: rgba(var(--brand-primary-rgb),0.12); color: var(--brand-primary); }
.tint-success { background: rgba(16,185,129,0.14); color: var(--brand-success); }
.tint-warning { background: rgba(245,158,11,0.16); color: var(--brand-warning); }
.tint-info { background: rgba(14,165,233,0.14); color: var(--brand-info); }
.tint-secondary { background: rgba(79,70,229,0.14); color: var(--brand-secondary); }
.tint-danger { background: rgba(239,68,68,0.14); color: var(--brand-danger); }

/* Skeleton loader */
.skeleton { background: linear-gradient(90deg, var(--bg-surface-2) 25%, var(--bg-hover) 37%, var(--bg-surface-2) 63%); background-size: 400% 100%; animation: shimmer 1.4s ease infinite; border-radius: var(--radius-sm); }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }

/* Text helpers */
.text-muted { color: var(--text-muted) !important; }
.text-secondary { color: var(--text-secondary) !important; }

/* Content entrance */
.app-content > * { animation: pageIn var(--t-slow); }
@keyframes pageIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

@media (prefers-reduced-motion: reduce) {
    *, ::before, ::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

/* ============================================================================
   Sidebar accordion groups
   Group headers are real <button>s (keyboard + aria). Only one group open at a
   time; the group containing the active page is expanded on load (theme.js).
   ============================================================================ */
.nav-group-toggle {
    display: flex; align-items: center; justify-content: space-between;
    width: 100%; border: 0; background: transparent; cursor: pointer;
    padding: 6px var(--space-3); margin-bottom: 2px; border-radius: var(--radius-sm);
    transition: background var(--t-fast), color var(--t-fast);
}
.nav-group-toggle:hover { background: var(--sidebar-item-hover-bg); }
.nav-group-toggle:hover .nav-group-label { color: var(--text-primary); }
.nav-group-toggle .nav-group-label { padding: 0; margin: 0; }
.nav-group-toggle .chev {
    width: 14px; height: 14px; color: var(--sidebar-group); flex-shrink: 0;
    transition: transform var(--t);
}
.nav-group.open > .nav-group-toggle .chev { transform: rotate(90deg); }
.nav-group-items {
    overflow: hidden; max-height: 0;
    transition: max-height var(--t-slow);
}
.nav-group.open > .nav-group-items { max-height: 640px; }
/* Collapsed desktop sidebar: accordion is bypassed — icons stay visible */
.app-shell.sidebar-collapsed .nav-group-toggle { display: none; }
.app-shell.sidebar-collapsed .nav-group-items { max-height: none; }

/* Drawer scroll lock (mobile) */
body.drawer-open { overflow: hidden; }

/* ============================================================================
   Shared page components (moved out of per-view <style> blocks)
   ============================================================================ */

/* Soft inset panel — replaces the hardcoded #f8fafc read-only cards */
.surface-panel {
    background: var(--bg-surface-2) !important;
    border: 1px solid var(--border-color) !important;
}

/* Document freight tables (Memo / Challan entry + read-only partials).
   One themed component, accent per document type. */
.memo-freight-table, .challan-freight-table {
    --doc-accent: var(--brand-primary);
    width: 100%; border-collapse: collapse;
    border: 2px solid var(--doc-accent);
    background: var(--bg-surface);
    font-family: var(--font-sans);
}
.challan-freight-table { --doc-accent: var(--brand-success); }
.memo-freight-table th.header-title, .challan-freight-table th.header-title {
    background: var(--bg-surface); color: var(--doc-accent);
    text-align: center; font-size: 1.25rem; font-weight: 600;
    border-bottom: 2px solid var(--doc-accent); padding: 4px;
    font-family: var(--font-display);
}
.memo-freight-table td, .challan-freight-table td {
    border: 1px solid var(--border-color); padding: 4px 8px;
    vertical-align: middle; font-size: var(--fs-base); color: var(--text-primary);
}
.memo-freight-table td.label-cell, .challan-freight-table td.label-cell { font-weight: 600; width: 18%; color: var(--text-secondary); }
.memo-freight-table td.input-cell, .challan-freight-table td.input-cell { width: 32%; }
.memo-freight-table tr.row-weight, .challan-freight-table tr.row-weight { background: rgba(16, 185, 129, 0.08); }
.memo-freight-table tr.row-rate, .challan-freight-table tr.row-rate { background: rgba(245, 158, 11, 0.10); }
.memo-freight-table .form-control-sm, .memo-freight-table .form-select-sm,
.challan-freight-table .form-control-sm, .challan-freight-table .form-select-sm {
    border: 1px solid var(--border-color); border-radius: 6px; padding: 2px 6px;
    background: var(--bg-surface); color: var(--text-primary);
}
.memo-freight-table input[readonly], .challan-freight-table input[readonly] {
    background: var(--bg-surface-2) !important; font-weight: 600;
}

/* Freight Template master (tabbed heading tables) */
#reportArea .tab-content { display: block; width: 100%; }
#reportArea table { width: 100%; max-width: 600px; }
.templateCell { cursor: pointer; }
.templateCell:hover { font-weight: 600; background: var(--bg-hover); }
.template-link { display: block; text-decoration: none; color: inherit; }
.tpl-idx { color: var(--brand-primary); font-weight: 700; }
.tpl-pct { color: var(--brand-danger); font-weight: 700; }
#reportArea table tfoot { background: var(--bg-surface-2); }

/* Activity Log — changes JSON cell */
.changes-cell { max-width: 420px; }
.changes-cell pre {
    max-height: 120px; overflow: auto; white-space: pre-wrap; word-break: break-all;
    font-size: var(--fs-xs); margin: 0; padding: 4px 6px;
    background: var(--bg-surface-2); border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm); color: var(--text-secondary);
}

/* Outstanding Report — collapsible party groups */
.group-header { cursor: pointer; }
.group-header .toggle-icon { transition: transform var(--t); }
.group-header:not(.collapsed) .toggle-icon { transform: rotate(90deg); }

/* DataTables (Bootstrap 5 build) — align with the design system */
div.dt-buttons .btn, .dt-buttons .btn { margin-right: 6px; }
.dataTables_wrapper .dataTables_filter input,
.dt-search input { min-height: 36px; }

/* ============================================================================
   Responsive — sidebar becomes an off-canvas drawer under 992px
   ============================================================================ */
.sidebar-backdrop { display: none; }
@media (max-width: 991.98px) {
    .app-sidebar { transform: translateX(-100%); box-shadow: var(--shadow-xl); }
    .app-shell.sidebar-open .app-sidebar { transform: translateX(0); width: var(--sidebar-w); }
    .app-main { margin-left: 0 !important; }
    .app-shell.sidebar-collapsed .app-sidebar .brand-text,
    .app-shell.sidebar-collapsed .app-sidebar .nav-text { display: inline; }
    .app-shell.sidebar-collapsed .nav-link-item { justify-content: flex-start; padding: 9px var(--space-3); }
    /* Accordion works normally inside the mobile drawer even when the desktop
       sidebar was left collapsed */
    .app-shell.sidebar-collapsed .nav-group-toggle { display: flex; }
    .app-shell.sidebar-collapsed .nav-group-items { max-height: 0; }
    .app-shell.sidebar-collapsed .nav-group.open > .nav-group-items { max-height: 640px; }
    .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(15,23,42,0.5); z-index: calc(var(--z-sidebar) - 1); opacity: 0; pointer-events: none; transition: opacity var(--t); }
    .app-shell.sidebar-open .sidebar-backdrop { opacity: 1; pointer-events: auto; }
    .topnav-search { display: none; }
    .app-content { padding: var(--space-4); }
}

/* Final guard: stray wide elements scroll inside their own wrappers, never the page */
.app-content { overflow-x: clip; }

@media (max-width: 575.98px) {
    /* 16px inputs prevent iOS auto-zoom on focus */
    .form-control, .form-select { font-size: 1rem; }
    /* Touch-friendly action buttons */
    .btn-sm { padding: 7px 12px; }
    .app-content { padding: var(--space-3); }
    .modal-dialog { margin: var(--space-2); }
    /* Card headers with badges / actions wrap instead of overflowing */
    .card-header.d-flex, .card-header .d-flex { flex-wrap: wrap; row-gap: var(--space-2); }
    .badge.fs-6 { font-size: var(--fs-xs) !important; }
    .breadcrumb-bar { min-width: 0; }
    .breadcrumb-bar .current { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 45vw; }
}

/* ============================================================================
   Enterprise component completion
   These rules normalize Bootstrap utilities and plugin surfaces used by legacy
   Razor pages without changing their model-binding or JavaScript hooks.
   ============================================================================ */

/* Page structure and branded priority surfaces */
.page-shell, .workflow-theme { width: 100%; max-width: 100%; }
.page-section { margin-bottom: var(--space-5); }
.page-header--brand, .hero-panel, .card-header.bg-dark, .workflow-theme > .card:first-child > .card-header.bg-dark {
    color: #fff;
    background: var(--gradient-brand) !important;
    border-color: transparent !important;
}
.page-header--brand, .hero-panel { padding: clamp(18px, 3vw, 30px); border-radius: var(--radius-lg); box-shadow: var(--shadow-md); }
.page-header--brand :is(h1,h2,h3,h4,h5,h6,p),
.hero-panel :is(h1,h2,h3,h4,h5,h6,p),
.card-header.bg-dark :is(h1,h2,h3,h4,h5,h6) { color: #fff; }
.page-subtitle { color: var(--text-muted); margin: 4px 0 0; }
.section-header { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-3); }
.section-title { margin: 0; font-size: var(--fs-lg); }
.page-actions, .toolbar, .filter-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }

/* Neutral surfaces and Bootstrap utility compatibility */
.bg-white, .bg-light, .table-light, .list-group-item { background-color: var(--bg-surface) !important; color: var(--text-primary) !important; }
.bg-body-tertiary, .bg-light-subtle { background-color: var(--bg-surface-2) !important; }
.text-dark, .text-gray-800 { color: var(--text-primary) !important; }
.border, .border-top, .border-bottom, .border-start, .border-end { border-color: var(--border-color) !important; }
.shadow, .shadow-sm { box-shadow: var(--shadow-sm) !important; }
.rounded { border-radius: var(--radius-md) !important; }
.card {
    --bs-card-bg: var(--bg-surface); --bs-card-color: var(--text-primary);
    --bs-card-border-color: var(--border-color); --bs-card-border-radius: var(--radius-lg);
    background: var(--bg-surface); border: 1px solid var(--border-color);
    border-radius: var(--radius-lg); box-shadow: var(--shadow-xs); color: var(--text-primary);
}
.card-header { background: var(--bg-surface-2); border-bottom-color: var(--border-color); padding: 14px 18px; }
.card-body { padding: clamp(16px, 2vw, 22px); }
.card-footer { background: var(--bg-surface-2); border-top-color: var(--border-color); padding: 12px 18px; }
.list-group { --bs-list-group-bg: var(--bg-surface); --bs-list-group-color: var(--text-primary); --bs-list-group-border-color: var(--border-color); }
.list-group-item-action:hover, .list-group-item-action:focus { background: var(--bg-hover) !important; }

/* Buttons and compact action clusters */
.btn { min-height: var(--control-height); display: inline-flex; align-items: center; justify-content: center; gap: 7px; line-height: 1.15; white-space: normal; }
.btn-primary { background: var(--gradient-primary); border-color: transparent; box-shadow: 0 3px 10px rgba(var(--brand-primary-rgb), .22); }
.btn-primary:hover { border-color: transparent; filter: brightness(1.06); transform: translateY(-1px); }
.btn-primary:active { filter: brightness(.96); transform: translateY(0); }
.btn-sm { min-height: var(--control-height-sm); }
.btn-lg { min-height: var(--control-height-lg); }
.btn-group > .btn { white-space: nowrap; }
.table .btn, .table .btn-sm { min-height: 32px; padding-block: 5px; }
.btn:disabled, .btn.disabled { opacity: .52; box-shadow: none; transform: none; cursor: not-allowed; }

/* Forms, readonly fields, file inputs and browser autofill */
.form-control-sm, .form-select-sm { min-height: var(--control-height-sm); padding-block: 5px; }
.form-control-lg, .form-select-lg { min-height: var(--control-height-lg); }
.form-control[readonly], .form-control:read-only { background-color: var(--bg-surface-2); color: var(--text-secondary); }
textarea.form-control { min-height: 96px; resize: vertical; }
input[type="file"].form-control { padding: 6px 8px; }
.form-control::file-selector-button { background: var(--bg-surface-2); color: var(--text-secondary); border: 0; border-right: 1px solid var(--border-color); margin: -6px 10px -6px -8px; padding: 9px 12px; }
.form-floating > label { color: var(--text-muted); }
.required-indicator, .form-label.required::after { color: var(--brand-danger); }
.form-label.required::after { content: " *"; }
input:-webkit-autofill, input:-webkit-autofill:hover, input:-webkit-autofill:focus {
    -webkit-text-fill-color: var(--text-primary); -webkit-box-shadow: 0 0 0 1000px var(--bg-surface) inset;
    caret-color: var(--text-primary); transition: background-color 9999s ease-out;
}
.input-group > :not(:first-child) { border-left-color: var(--border-strong); }
.compact-form :is(.form-control,.form-select,.btn) { min-height: var(--control-height-sm); padding-block: 5px; }

/* Tables, totals, sticky content and scroll containment */
.table-responsive { max-width: 100%; overflow-x: auto; overflow-y: hidden; border: 1px solid var(--border-color); background: var(--bg-surface); }
.card > .table-responsive { border: 0; }
.table > tbody > tr.table-active > *, .table > tbody > tr.selected > * { background: var(--bg-selected) !important; color: var(--text-primary); }
.table-dark, .table > .table-dark { --bs-table-bg: var(--color-primary-950); --bs-table-color: #F8FAFC; --bs-table-border-color: #334A7D; }
.table tfoot > tr > * { background: var(--bg-surface-2); border-top: 2px solid var(--border-strong); font-weight: 700; color: var(--text-primary); }
.table .amount, .table .number, .tabular-nums { font-variant-numeric: tabular-nums; text-align: right; }
.table .actions, .table-actions { text-align: center; white-space: nowrap; }
.table caption { color: var(--text-muted); padding: 10px 16px; }
.empty-state { padding: clamp(28px, 6vw, 56px) 20px; text-align: center; color: var(--text-muted); }
.empty-state__icon { width: 48px; height: 48px; margin: 0 auto 12px; display: grid; place-items: center; border-radius: var(--radius-md); background: rgba(var(--brand-primary-rgb), .12); color: var(--brand-primary); }

/* Accordions, pills and horizontal tab overflow */
.accordion { --bs-accordion-bg: var(--bg-surface); --bs-accordion-color: var(--text-primary); --bs-accordion-border-color: var(--border-color); --bs-accordion-active-bg: var(--bg-selected); --bs-accordion-active-color: var(--color-primary-700); --bs-accordion-btn-focus-box-shadow: 0 0 0 3px var(--focus-ring); }
.accordion-button { color: var(--text-primary); font-weight: 600; }
.accordion-button:not(.collapsed) { box-shadow: inset 0 -1px 0 var(--border-color); }
.nav-pills .nav-link { color: var(--text-secondary); border-radius: var(--radius-sm); }
.nav-pills .nav-link.active { background: var(--gradient-primary); color: #fff; }
.tabs-scroll { display: flex; flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden; scrollbar-width: thin; }
.tabs-scroll .nav-link { white-space: nowrap; }

/* Modal, popover, tooltip, toast and SweetAlert surfaces */
.modal-dialog-scrollable .modal-content { max-height: calc(100vh - 2rem); }
.modal-dialog-scrollable .modal-body { overflow-x: hidden; }
.modal-header.bg-primary, .modal-header.bg-dark { background: var(--gradient-primary) !important; color: #fff; }
.modal-header.bg-primary .modal-title, .modal-header.bg-dark .modal-title { color: #fff; }
.popover { --bs-popover-bg: var(--bg-surface); --bs-popover-border-color: var(--border-color); --bs-popover-header-bg: var(--bg-surface-2); --bs-popover-header-color: var(--text-primary); --bs-popover-body-color: var(--text-secondary); box-shadow: var(--shadow-lg); }
.tooltip { --bs-tooltip-bg: var(--color-primary-950); --bs-tooltip-color: #F8FAFC; }
.toast { --bs-toast-bg: var(--bg-surface); --bs-toast-color: var(--text-primary); --bs-toast-border-color: var(--border-color); box-shadow: var(--shadow-lg); }
.swal2-popup { background: var(--bg-surface) !important; color: var(--text-primary) !important; border: 1px solid var(--border-color); border-radius: var(--radius-lg) !important; box-shadow: var(--shadow-xl) !important; }
.swal2-title, .swal2-html-container { color: var(--text-primary) !important; }
.swal2-input, .swal2-select, .swal2-textarea { background: var(--bg-surface-2) !important; color: var(--text-primary) !important; border-color: var(--border-color) !important; }
.swal2-confirm { background: var(--gradient-primary) !important; }

/* DataTables 1.x/2.x and export controls */
.dataTables_wrapper, div.dt-container { color: var(--text-secondary); }
.dataTables_wrapper .dataTables_length, .dataTables_wrapper .dataTables_filter,
.dataTables_wrapper .dataTables_info, .dataTables_wrapper .dataTables_paginate,
div.dt-container .dt-length, div.dt-container .dt-search, div.dt-container .dt-info { color: var(--text-secondary) !important; }
.dataTables_wrapper :is(select,input), div.dt-container :is(select,input) {
    background-color: var(--bg-surface); color: var(--text-primary); border: 1px solid var(--border-color); border-radius: var(--radius-sm); min-height: 36px; padding: 6px 10px;
}
.dataTables_wrapper .dataTables_paginate .paginate_button,
div.dt-container .dt-paging .dt-paging-button { color: var(--text-secondary) !important; background: var(--bg-surface) !important; border: 1px solid var(--border-color) !important; border-radius: var(--radius-sm) !important; margin: 2px; }
.dataTables_wrapper .dataTables_paginate .paginate_button:hover,
div.dt-container .dt-paging .dt-paging-button:hover { color: var(--text-primary) !important; background: var(--bg-hover) !important; }
.dataTables_wrapper .dataTables_paginate .paginate_button.current,
div.dt-container .dt-paging .dt-paging-button.current { color: #fff !important; background: var(--gradient-primary) !important; border-color: transparent !important; }
table.dataTable thead > tr > th.sorting::before, table.dataTable thead > tr > th.sorting::after { color: var(--brand-primary); }
.dt-buttons { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.dt-buttons .btn { margin: 0 !important; }

/* ============================================================================
   Application tables — shared visual language for lists, reports and editors
   ============================================================================ */
.app-content .table-responsive:not(.dashboard-table-wrap),
.modal-body .table-responsive {
    position: relative;
    border: 1px solid var(--border-color);
    border-radius: 0;
    background: var(--bg-surface);
    box-shadow: 0 5px 18px rgba(15, 23, 42, .035);
    scrollbar-width: thin;
    scrollbar-color: var(--border-strong) transparent;
}
.app-content .workflow-matrix .table-responsive { border: 0; box-shadow: none; }
.table-responsive::-webkit-scrollbar { height: 8px; }
.table-responsive::-webkit-scrollbar-track { background: transparent; }
.table-responsive::-webkit-scrollbar-thumb { border: 2px solid transparent; border-radius: 20px; background: var(--border-strong); background-clip: padding-box; }

.app-content .table:not(.workflow-table):not(.dashboard-table),
.modal-body .table:not(.workflow-table) {
    --bs-table-striped-bg: rgba(148, 163, 184, .035);
    --bs-table-hover-bg: rgba(var(--brand-primary-rgb), .045);
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    color: var(--text-primary);
    font-size: .77rem;
    line-height: 1.45;
}
.app-content .table:not(.workflow-table):not(.dashboard-table) > thead > tr > th,
.modal-body .table:not(.workflow-table) > thead > tr > th {
    position: relative;
    height: 45px;
    padding: 11px 14px !important;
    border-top: 0;
    border-right: 0;
    border-bottom: 1px solid var(--border-color) !important;
    border-left: 0;
    color: var(--text-secondary) !important;
    background: linear-gradient(180deg, var(--bg-surface-2), color-mix(in srgb, var(--bg-surface-2) 70%, var(--bg-surface))) !important;
    font-size: .64rem;
    font-weight: 800;
    letter-spacing: .065em;
    text-transform: uppercase;
    vertical-align: middle;
    white-space: nowrap;
}
.app-content .table:not(.workflow-table):not(.dashboard-table) > thead > tr > th:first-child,
.modal-body .table:not(.workflow-table) > thead > tr > th:first-child { padding-left: 18px !important; }
.app-content .table:not(.workflow-table):not(.dashboard-table) > thead > tr > th:first-child::before,
.modal-body .table:not(.workflow-table) > thead > tr > th:first-child::before {
    content: "";
    position: absolute;
    left: 0;
    top: 11px;
    bottom: 11px;
    width: 3px;
    border-radius: 0 4px 4px 0;
    background: var(--gradient-primary);
}
.app-content .table:not(.workflow-table):not(.dashboard-table) > tbody > tr > td,
.app-content .table:not(.workflow-table):not(.dashboard-table) > tbody > tr > th,
.modal-body .table:not(.workflow-table) > tbody > tr > td,
.modal-body .table:not(.workflow-table) > tbody > tr > th {
    padding: 12px 14px !important;
    border-top: 0;
    border-right: 0;
    border-bottom: 1px solid var(--border-subtle);
    border-left: 0;
    color: var(--text-primary);
    background-color: transparent;
    vertical-align: middle;
}
.app-content .table:not(.workflow-table):not(.dashboard-table) > tbody > tr:last-child > *,
.modal-body .table:not(.workflow-table) > tbody > tr:last-child > * { border-bottom-color: transparent; }
.app-content .table:not(.workflow-table):not(.dashboard-table) > tbody > tr,
.modal-body .table:not(.workflow-table) > tbody > tr {
    position: relative;
    transition: background-color var(--t-fast), box-shadow var(--t-fast), transform var(--t-fast);
}
.app-content .table-hover:not(.workflow-table) > tbody > tr:hover > *,
.modal-body .table-hover:not(.workflow-table) > tbody > tr:hover > * { background-color: rgba(var(--brand-primary-rgb), .05) !important; }
.app-content .table-hover:not(.workflow-table) > tbody > tr:hover,
.modal-body .table-hover:not(.workflow-table) > tbody > tr:hover { box-shadow: inset 3px 0 0 var(--brand-primary); }
.app-content .table-hover:not(.workflow-table) > tbody > tr:hover td:first-child::before,
.modal-body .table-hover:not(.workflow-table) > tbody > tr:hover td:first-child::before { display: none; }
.app-content .table-striped:not(.workflow-table) > tbody > tr:nth-of-type(odd) > * { --bs-table-accent-bg: rgba(148, 163, 184, .035); }

/* Readable values and restrained action controls inside every data grid. */
.app-content .table:not(.workflow-table) td.text-end,
.app-content .table:not(.workflow-table) th.text-end,
.app-content .table:not(.workflow-table) td[class*="amount"],
.app-content .table:not(.workflow-table) td[class*="balance"] { font-variant-numeric: tabular-nums; }
.app-content .table:not(.workflow-table) td.text-muted { color: var(--text-muted) !important; }
.app-content .table:not(.workflow-table) tbody td > a:not(.btn) { color: var(--brand-primary); font-weight: 650; }
.app-content .table:not(.workflow-table) tbody td > a:not(.btn):hover { text-decoration: underline; text-underline-offset: 3px; }
.app-content .table:not(.workflow-table) td .btn,
.modal-body .table:not(.workflow-table) td .btn {
    min-height: 29px;
    padding: 5px 9px;
    border-radius: 8px !important;
    box-shadow: none;
    font-size: .64rem;
    font-weight: 700;
}
.app-content .table:not(.workflow-table) td .btn + .btn,
.app-content .table:not(.workflow-table) td .btn + form,
.app-content .table:not(.workflow-table) td form + .btn { margin-left: 4px; }
.app-content .table:not(.workflow-table) td .btn-outline-secondary:hover { color: var(--text-primary); border-color: var(--border-strong); background: var(--bg-hover); }
.app-content .table:not(.workflow-table) td .btn-outline-primary:hover { box-shadow: 0 3px 9px rgba(var(--brand-primary-rgb), .14); }
.app-content .table:not(.workflow-table) td .btn-outline-danger:hover { box-shadow: 0 3px 9px rgba(220, 38, 38, .12); }

/* Totals, group headers and nested report details. */
.app-content .table:not(.workflow-table) > tfoot > tr > * {
    padding: 12px 14px !important;
    border-top: 2px solid var(--border-strong);
    border-bottom: 0;
    color: var(--text-primary);
    background: linear-gradient(180deg, var(--bg-surface-2), var(--bg-surface)) !important;
    font-weight: 800;
}
.app-content .table:not(.workflow-table) tr.table-light > *,
.app-content .table:not(.workflow-table) tr.table-active > * { color: var(--text-primary); background: var(--bg-surface-2) !important; }
.app-content .table:not(.workflow-table) .group-header > * {
    padding-block: 13px !important;
    color: var(--text-primary);
    background: color-mix(in srgb, var(--bg-surface-2) 82%, rgba(var(--brand-primary-rgb), .08)) !important;
    font-weight: 700;
}
.app-content .table:not(.workflow-table) td[colspan] > .table,
.app-content .table:not(.workflow-table) td[colspan] .table-responsive {
    margin-block: 2px;
    border: 1px solid var(--border-subtle);
    border-radius: 10px;
    box-shadow: none;
}
.app-content .table:not(.workflow-table) .table {
    font-size: .7rem;
    background: var(--bg-surface-2);
}
.app-content .table:not(.workflow-table) .table > thead > tr > th { height: 38px; padding-block: 8px !important; font-size: .59rem; }
.app-content .table:not(.workflow-table) .table > tbody > tr > td { padding-block: 9px !important; }
.app-content .table:not(.workflow-table) tbody tr > td:only-child.text-muted,
.app-content .table:not(.workflow-table) tbody tr > td[colspan].text-muted {
    padding: 30px 18px !important;
    color: var(--text-muted) !important;
    text-align: center;
    background: radial-gradient(circle at center, rgba(var(--brand-primary-rgb), .05), transparent 60%);
}

/* DataTables toolbar: export, length, search, count and pagination. */
.app-content .dataTables_wrapper,
.app-content div.dt-container { --table-control-h: 38px; }
.app-content .dataTables_wrapper > .row:first-child,
.app-content div.dt-container > .row:first-child {
    align-items: center;
    margin: 0 0 12px;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: var(--bg-surface-2);
}
.app-content .dataTables_wrapper > .row:last-child,
.app-content div.dt-container > .row:last-child { align-items: center; margin-top: 12px; }
.app-content .dataTables_wrapper .dataTables_length label,
.app-content .dataTables_wrapper .dataTables_filter label,
.app-content div.dt-container .dt-length label,
.app-content div.dt-container .dt-search label { color: var(--text-muted); font-size: .67rem; font-weight: 700; }
.app-content .dataTables_wrapper :is(select,input),
.app-content div.dt-container :is(select,input) {
    min-height: var(--table-control-h);
    border-color: var(--border-color);
    border-radius: 9px;
    background-color: var(--bg-surface);
    box-shadow: 0 1px 2px rgba(15,23,42,.03);
    font-size: .72rem;
}
.app-content .dataTables_wrapper .dataTables_filter input,
.app-content div.dt-container .dt-search input { min-width: 210px; margin-left: 8px; padding-left: 12px; }
.app-content .dataTables_wrapper .dataTables_filter input:focus,
.app-content div.dt-container .dt-search input:focus { border-color: var(--brand-primary); box-shadow: 0 0 0 3px var(--focus-ring); outline: 0; }
.app-content .dt-buttons { gap: 5px; margin: 0 0 12px; }
.app-content .dt-buttons .btn {
    min-height: var(--table-control-h);
    padding: 7px 11px;
    border-color: var(--border-color);
    border-radius: 9px !important;
    color: var(--text-secondary);
    background: var(--bg-surface);
    box-shadow: 0 1px 2px rgba(15,23,42,.03);
    font-size: .66rem;
    font-weight: 750;
}
.app-content .dt-buttons .btn:hover { color: var(--brand-primary); border-color: rgba(var(--brand-primary-rgb), .35); background: rgba(var(--brand-primary-rgb), .07); transform: translateY(-1px); }
.app-content .dataTables_wrapper .dataTables_info,
.app-content div.dt-container .dt-info { padding-top: 8px !important; color: var(--text-muted) !important; font-size: .66rem; }
.app-content .dataTables_wrapper .dataTables_paginate .paginate_button,
.app-content div.dt-container .dt-paging .dt-paging-button {
    min-width: 34px;
    min-height: 34px;
    display: inline-grid;
    place-items: center;
    padding: 5px 9px !important;
    border-radius: 9px !important;
    font-size: .68rem;
    font-weight: 700;
}
.app-content .dataTables_wrapper .dataTables_paginate .paginate_button.disabled,
.app-content div.dt-container .dt-paging .dt-paging-button.disabled { opacity: .48; }

@media (max-width: 767.98px) {
    .app-content .table-responsive:not(.dashboard-table-wrap) { border-radius: 0; }
    .app-content .table:not(.workflow-table):not(.dashboard-table) { font-size: .73rem; }
    .app-content .table:not(.workflow-table):not(.dashboard-table) > thead > tr > th { height: 41px; padding: 9px 11px !important; }
    .app-content .table:not(.workflow-table):not(.dashboard-table) > tbody > tr > td { padding: 10px 11px !important; }
    .app-content .dataTables_wrapper > .row:first-child,
    .app-content div.dt-container > .row:first-child { padding: 9px; }
    .app-content .dataTables_wrapper .dataTables_filter,
    .app-content div.dt-container .dt-search { width: 100%; margin-top: 8px; text-align: left !important; }
    .app-content .dataTables_wrapper .dataTables_filter label,
    .app-content div.dt-container .dt-search label { display: flex; align-items: center; width: 100%; }
    .app-content .dataTables_wrapper .dataTables_filter input,
    .app-content div.dt-container .dt-search input { min-width: 0; width: 100%; }
    .app-content .dt-buttons { width: 100%; }
    .app-content .dt-buttons .btn { flex: 1 1 auto; }
}

/* Select2, jQuery UI/date pickers and common autocomplete menus */
.select2-container { max-width: 100%; }
.select2-container .select2-selection--single, .select2-container .select2-selection--multiple {
    min-height: var(--control-height); background: var(--bg-surface); border: 1px solid var(--border-color); border-radius: var(--radius-sm); color: var(--text-primary);
}
.select2-container .select2-selection--single .select2-selection__rendered { color: var(--text-primary); line-height: calc(var(--control-height) - 2px); padding-left: 12px; }
.select2-container .select2-selection--single .select2-selection__arrow { height: var(--control-height); }
.select2-dropdown, .ui-autocomplete, .ui-datepicker { background: var(--bg-surface); color: var(--text-primary); border: 1px solid var(--border-color); border-radius: var(--radius-md); box-shadow: var(--shadow-lg); z-index: calc(var(--z-modal) + 10) !important; }
.select2-results__option, .ui-menu-item-wrapper { color: var(--text-secondary); padding: 8px 12px; }
.select2-results__option--highlighted[aria-selected], .select2-results__option--selected, .ui-state-active { background: var(--bg-selected) !important; color: var(--text-primary) !important; border-color: transparent !important; }
.select2-container--default.select2-container--focus .select2-selection--multiple,
.select2-container--default.select2-container--open .select2-selection--single { border-color: var(--brand-primary); box-shadow: 0 0 0 3px var(--focus-ring); }
.ui-datepicker-header { background: var(--bg-surface-2); color: var(--text-primary); border-color: var(--border-color); }

/* Loading and feedback */
.spinner-border, .spinner-grow { color: var(--brand-primary); }
.progress { background: var(--bg-surface-3); border-radius: var(--radius-pill); }
.progress-bar { background: var(--gradient-primary); }
[aria-busy="true"] { cursor: progress; }

/* Responsive completion */
@media (max-width: 767.98px) {
    .page-header, .section-header { align-items: flex-start; }
    .page-header > .page-actions, .page-header > .btn-group, .page-header > form { width: 100%; }
    .page-actions > .btn { flex: 1 1 auto; }
    .card-body { padding: 16px; }
    .table > :not(caption) > * > * { padding: 10px 12px; }
    .modal-dialog { max-width: none; }
    .modal-header, .modal-body, .modal-footer { padding: 14px 16px; }
    .modal-footer { flex-wrap: wrap; }
    .modal-footer > .btn { flex: 1 1 auto; }
    .dataTables_wrapper .row, div.dt-container .row { row-gap: 10px; }
    .dataTables_wrapper .dataTables_filter, .dataTables_wrapper .dataTables_length { text-align: left !important; }
}
@media (max-width: 575.98px) {
    .app-topnav { padding-inline: 10px; gap: 6px; }
    .breadcrumb-bar a, .breadcrumb-bar .sep { display: none; }
    .page-header--brand, .hero-panel { padding: 18px; }
    .page-actions > .btn, .toolbar > .btn { min-height: 44px; }
    .btn-group.mobile-wrap { display: flex; flex-wrap: wrap; }
    .btn-group.mobile-wrap > .btn { flex: 1 1 auto; border-radius: var(--radius-sm) !important; margin: 2px; }
    .modal-dialog.modal-fullscreen-sm-down { margin: 0; }
    .table-responsive { border-radius: var(--radius-sm); }
}

/* Print: business documents stay neutral and navigation/actions disappear */
@media print {
    :root, [data-theme="dark"] { --bg-app: #fff; --bg-surface: #fff; --bg-surface-2: #fff; --text-primary: #000; --text-secondary: #222; --text-muted: #555; --border-color: #777; --border-subtle: #bbb; }
    @page { margin: 12mm; }
    html, body { background: #fff !important; color: #000 !important; font-size: 10pt; }
    .app-sidebar, .app-topnav, .sidebar-backdrop, .page-actions, .toolbar, .btn, .dataTables_filter, .dataTables_length, .dataTables_paginate, .dt-buttons, .no-print { display: none !important; }
    .app-main { margin: 0 !important; }
    .app-content { padding: 0 !important; overflow: visible !important; }
    .card, .surface-panel, .page-header--brand, .hero-panel { box-shadow: none !important; background: #fff !important; color: #000 !important; border-color: #777 !important; }
    .page-header--brand *, .hero-panel *, .card-header.bg-dark * { color: #000 !important; }
    .card-header.bg-dark, .modal-header.bg-dark, .modal-header.bg-primary { background: #fff !important; color: #000 !important; }
    .table-responsive { overflow: visible !important; border: 0; }
    .table { width: 100% !important; color: #000 !important; }
    .table thead { display: table-header-group; }
    .table tfoot { display: table-footer-group; }
    .table tr, .card, .page-section { break-inside: avoid; }
    .table > :not(caption) > * > * { background: #fff !important; color: #000 !important; border-color: #777 !important; }
    a { color: #000 !important; text-decoration: none !important; }
}
