/* ============================================================
   TransLog - Premium Design System
   Freight Forwarding UI - v2.0
   ============================================================ */

/* === Google Font Import === */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

/* === CSS Variables ===
 * Design tokens snap to an 8-spaced rhythm (4/8/12/16/20/24px) and a 7-step
 * typographic scale (11/12/13/14/16/18/22/28). Anything outside should be a
 * deliberate exception. */
:root {
    /* --- Brand --- */
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-dark: #1d4ed8;
    --primary-light: #dbeafe;
    --primary-50: #eff6ff;
    --primary-gradient: linear-gradient(135deg, #2563eb 0%, #4f46e5 100%);

    /* --- Sidebar (dark) --- */
    --sidebar-bg: #0c1222;
    --sidebar-hover: #1a2744;
    --sidebar-active: rgba(37, 99, 235, 0.15);
    --sidebar-active-border: #2563eb;
    --sidebar-text: #7b8ba5;
    --sidebar-text-active: #ffffff;
    --sidebar-section-bg: rgba(255,255,255,0.02);
    --sidebar-width: 272px;
    --sidebar-rail-width: 64px;
    --topbar-height: 60px;

    /* --- Surface --- */
    --bg: #f5f7fa;          /* page background — neutral cool grey */
    --bg-soft: #f8fafc;     /* table head, footers, sub-bands */
    --card-bg: #ffffff;
    --text: #0f172a;        /* slate 900 */
    --text-secondary: #475569; /* slate 600 */
    --text-muted: #94a3b8;  /* slate 400 */
    --border: #dde3ed;      /* visible separator */
    --border-light: #ebeef3; /* subtler separator (rows, etc.) */
    --surface-2: #f8fafc;   /* alias used by some components */

    /* --- Semantic --- */
    --success: #059669;
    --success-light: #d1fae5;
    --warning: #d97706;
    --warning-light: #fef3c7;
    --danger: #dc2626;
    --danger-light: #fee2e2;
    --info: #0891b2;
    --info-light: #cffafe;

    /* --- Shadows (more restrained, ERP feel) --- */
    --shadow-sm: 0 1px 2px rgba(15,23,42,0.04);
    --shadow: 0 1px 2px rgba(15,23,42,0.05), 0 1px 1px rgba(15,23,42,0.04);
    --shadow-md: 0 4px 8px rgba(15,23,42,0.06), 0 1px 3px rgba(15,23,42,0.04);
    --shadow-lg: 0 10px 20px rgba(15,23,42,0.08), 0 3px 6px rgba(15,23,42,0.04);
    --shadow-xl: 0 18px 36px rgba(15,23,42,0.10), 0 6px 12px rgba(15,23,42,0.05);

    /* --- Radii --- */
    --radius-sm: 4px;
    --radius: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;

    /* --- Motion --- */
    --transition: 160ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 260ms cubic-bezier(0.4, 0, 0.2, 1);

    /* --- Type --- */
    --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --font-mono: 'JetBrains Mono', 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
}

/* === Reset === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; scroll-behavior: smooth; }
body {
    font-family: var(--font);
    color: var(--text);
    background: var(--bg);
    line-height: 1.5;
    overflow-x: hidden;
    /* Inter stylistic alternates: rounder one, simpler four, narrower lL,
     * disambiguated zero. Makes numbers sharper in dense tables. */
    font-feature-settings: 'cv02', 'cv03', 'cv04', 'cv11', 'tnum';
}
a { color: var(--primary); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--primary-dark); }
img { max-width: 100%; }
table { border-collapse: collapse; width: 100%; }
input, select, textarea, button { font-family: inherit; font-size: inherit; }

/* === Page Loader (Truck Animation) === */
.page-loader {
    position: fixed;
    inset: 0;
    background: rgba(240, 244, 248, 0.85);
    backdrop-filter: blur(8px);
    z-index: 10000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    opacity: 1;
    transition: opacity 0.4s ease, visibility 0.4s ease;
}
.page-loader.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}
.truck-loader {
    width: 160px;
    height: 80px;
    position: relative;
}
.truck-loader svg {
    width: 100%;
    height: 100%;
}
.truck-body {
    fill: var(--primary);
    animation: truckBounce 0.8s ease-in-out infinite;
}
.truck-cabin {
    fill: var(--primary-dark);
    animation: truckBounce 0.8s ease-in-out infinite;
    animation-delay: 0.05s;
}
.truck-wheel {
    fill: #334155;
    animation: wheelSpin 0.5s linear infinite;
    transform-origin: center;
}
.truck-wheel-inner {
    fill: #94a3b8;
    animation: wheelSpin 0.5s linear infinite;
    transform-origin: center;
}
@keyframes truckBounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-3px); }
}
@keyframes wheelSpin {
    to { transform: rotate(360deg); }
}

/* Road animation under truck */
.truck-road {
    width: 200px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin-top: 8px;
    position: relative;
    overflow: hidden;
}
.truck-road::after {
    content: '';
    position: absolute;
    top: 0;
    left: -60%;
    width: 40%;
    height: 100%;
    background: linear-gradient(90deg, transparent, var(--primary), transparent);
    animation: roadGlow 1.2s ease-in-out infinite;
}
@keyframes roadGlow {
    0% { left: -40%; }
    100% { left: 100%; }
}

.loader-text {
    margin-top: 16px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    letter-spacing: 0.5px;
}

/* Inline spinner (used in buttons/tables) */
.spinner {
    width: 18px;
    height: 18px;
    border: 2.5px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* === Login Page === */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #0c1222 0%, #162040 30%, #1e3a6e 60%, #2563eb 100%);
    position: relative;
    overflow: hidden;
}
.login-page::before {
    content: '';
    position: absolute;
    top: -50%;
    right: -30%;
    width: 80%;
    height: 200%;
    background: radial-gradient(ellipse, rgba(37,99,235,0.15) 0%, transparent 70%);
    pointer-events: none;
}
.login-page::after {
    content: '';
    position: absolute;
    bottom: -20%;
    left: -20%;
    width: 60%;
    height: 60%;
    background: radial-gradient(ellipse, rgba(79,70,229,0.1) 0%, transparent 70%);
    pointer-events: none;
}
.login-box {
    background: rgba(255,255,255,0.95);
    backdrop-filter: blur(20px);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl), 0 0 0 1px rgba(255,255,255,0.1);
    padding: 48px 44px;
    width: 440px;
    max-width: 95vw;
    position: relative;
    z-index: 1;
    animation: loginAppear 0.5s ease-out;
}
@keyframes loginAppear {
    from { opacity: 0; transform: translateY(20px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}
.login-logo { text-align: center; margin-bottom: 36px; }
.login-logo h1 { font-size: 30px; font-weight: 800; color: var(--text); letter-spacing: -0.5px; }
.login-logo h1 span { background: var(--primary-gradient); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; }
.login-logo p { color: var(--text-secondary); font-size: 13px; margin-top: 6px; font-weight: 500; }
.login-box .form-group { margin-bottom: 20px; }
.login-box .form-group label { display: block; font-weight: 600; margin-bottom: 6px; color: var(--text); font-size: 13px; }
.login-box .form-control { width: 100%; padding: 11px 16px; border: 1.5px solid var(--border); border-radius: var(--radius); font-size: 14px; transition: border-color var(--transition), box-shadow var(--transition); background: #fff; }
.login-box .form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.12); }
.login-box .btn-login { width: 100%; padding: 13px; font-size: 15px; font-weight: 700; border-radius: var(--radius); letter-spacing: 0.3px; }
.login-error { background: var(--danger-light); color: var(--danger); padding: 12px 16px; border-radius: var(--radius); margin-bottom: 20px; font-size: 13px; border-left: 4px solid var(--danger); font-weight: 500; }

/* === Environment banner (rendered only when APP_ENV != production) === */
.env-banner {
    background: var(--danger, #dc2626);
    color: #fff;
    text-align: center;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    padding: 5px 12px;
}

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

/* === Sidebar === */
.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    transition: width var(--transition-slow);
    overflow: hidden;
    border-right: 1px solid rgba(255,255,255,0.04);
}

/* Sidebar header / logo */
.sidebar-header {
    height: var(--topbar-height);
    display: flex;
    align-items: center;
    padding: 0 24px;
    flex-shrink: 0;
    position: relative;
}
.sidebar-header::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 24px;
    right: 24px;
    height: 1px;
    background: linear-gradient(90deg, rgba(255,255,255,0.08), rgba(255,255,255,0.02));
}
.sidebar-header .logo {
    font-size: 22px;
    font-weight: 800;
    color: #fff;
    letter-spacing: -0.5px;
    display: flex;
    align-items: center;
    gap: 3px;
}
.sidebar-header .logo span {
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
.sidebar-header .logo-icon {
    width: 28px;
    height: 28px;
    margin-right: 8px;
    opacity: 0.9;
}

/* Sidebar nav */
.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 16px 0 8px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.08) transparent;
}
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 2px; }

/* Nav section with collapsible support */
.nav-section {
    padding: 0 12px;
    margin-bottom: 2px;
}
.nav-section-title {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    padding: 14px 12px 6px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    user-select: none;
    transition: color var(--transition);
    position: relative;
}
.nav-section-title { gap: 8px; }
.nav-section-title:hover { color: var(--sidebar-text-active); }
.nav-section-title .section-chevron {
    width: 14px;
    height: 14px;
    opacity: 0.4;
    transition: transform var(--transition-slow), opacity var(--transition);
    flex-shrink: 0;
}
.nav-section-title:hover .section-chevron { opacity: 0.7; }
.nav-section.collapsed .section-chevron { transform: rotate(-90deg); }
.nav-section-title .nav-section-icon {
    width: 14px;
    height: 14px;
    opacity: 0.45;
    flex-shrink: 0;
    transition: opacity var(--transition), color var(--transition);
}
.nav-section-title:hover .nav-section-icon { opacity: 0.9; }
/* Tint the icon active-blue only when the section is COLLAPSED with the
 * active page hidden inside — when expanded, the highlighted item itself
 * already signals "you're here", so a second indicator would be noise. */
.nav-section.has-active.collapsed .nav-section-title .nav-section-icon {
    opacity: 1;
    color: var(--sidebar-active-border);
}
/* The label fills the middle so the chevron stays right-anchored. */
.nav-section-title .nav-section-label { flex: 1; min-width: 0; }
.nav-section-items {
    overflow: hidden;
    transition: max-height var(--transition-slow), opacity var(--transition-slow);
    max-height: 500px;
    opacity: 1;
}
.nav-section.collapsed .nav-section-items {
    max-height: 0;
    opacity: 0;
}

/* Nav items */
.nav-item {
    display: flex;
    align-items: center;
    padding: 7px 10px;
    border-radius: var(--radius);
    color: var(--sidebar-text);
    font-size: 13px;
    font-weight: 500;
    transition: background var(--transition), color var(--transition);
    cursor: pointer;
    margin-bottom: 1px;
    gap: 10px;
    position: relative;
    border: 1px solid transparent;
}
.nav-item:hover {
    background: var(--sidebar-hover);
    color: var(--sidebar-text-active);
}
.nav-item.active {
    background: var(--sidebar-active);
    color: #fff;
    font-weight: 600;
}
.nav-item.active::before {
    content: '';
    position: absolute;
    left: -12px;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 18px;
    background: var(--sidebar-active-border);
    border-radius: 0 3px 3px 0;
}
.nav-item .nav-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    opacity: 0.55;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity var(--transition);
}
.nav-item:hover .nav-icon { opacity: 0.85; }
.nav-item.active .nav-icon { opacity: 1; }
.nav-item .nav-label { white-space: nowrap; }
.nav-item .nav-badge {
    margin-left: auto;
    background: rgba(37,99,235,0.25);
    color: #93bbff;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 12px;
    letter-spacing: 0.3px;
}

/* Sidebar Footer */
.sidebar-footer {
    padding: 12px;
    flex-shrink: 0;
    position: relative;
}
.sidebar-footer::before {
    content: '';
    position: absolute;
    top: 0;
    left: 24px;
    right: 24px;
    height: 1px;
    background: linear-gradient(90deg, rgba(255,255,255,0.08), rgba(255,255,255,0.02));
}
.sidebar-user-wrap { position: relative; }
.sidebar-user {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius);
    transition: background var(--transition);
    width: 100%;
    background: transparent;
    border: none;
    cursor: pointer;
    color: inherit;
    text-align: left;
    font: inherit;
}
.sidebar-user:hover { background: var(--sidebar-hover); }
.sidebar-user.open { background: var(--sidebar-hover); }
.sidebar-user .user-avatar {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: var(--primary-gradient);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(37,99,235,0.3);
}
.sidebar-user .user-info { overflow: hidden; flex: 1; min-width: 0; }
.sidebar-user .user-name { color: #fff; font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user .user-role { color: var(--text-muted); font-size: 11px; font-weight: 500; }
.sidebar-user .user-menu-chevron {
    width: 14px;
    height: 14px;
    color: var(--text-muted);
    flex-shrink: 0;
    transition: transform var(--transition);
}
.sidebar-user.open .user-menu-chevron { transform: rotate(180deg); }

/* User menu popover — anchors above the user pill (we're at sidebar bottom). */
.user-menu {
    position: absolute;
    bottom: calc(100% + 6px);
    left: 0;
    right: 0;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-xl);
    z-index: 1100;
    display: none;
    overflow: hidden;
    animation: dropdownIn 0.15s ease-out;
    padding: 6px;
}
.user-menu.show { display: block; }
.user-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    text-decoration: none;
    border-radius: 6px;
    transition: background var(--transition), color var(--transition);
}
.user-menu-item svg { width: 16px; height: 16px; flex-shrink: 0; }
.user-menu-item:hover { background: var(--primary-50); color: var(--primary); }
.user-menu-item-danger { color: var(--danger, #dc2626); }
.user-menu-item-danger:hover { background: rgba(220,38,38,0.08); color: var(--danger, #dc2626); }
.user-menu-sep {
    height: 1px;
    background: var(--border-light);
    margin: 4px 6px;
}

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

/* === Topbar === */
.topbar {
    height: var(--topbar-height);
    background: rgba(255,255,255,0.85);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 100;
    gap: 16px;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-breadcrumb { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-secondary); }
.topbar-breadcrumb a { color: var(--text-secondary); font-weight: 500; }
.topbar-breadcrumb a:hover { color: var(--primary); }
.topbar-breadcrumb .sep { color: var(--text-muted); font-size: 11px; }
.topbar-breadcrumb .current { color: var(--text); font-weight: 600; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.topbar-btn {
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--card-bg);
    color: var(--text-secondary);
    cursor: pointer;
    transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.topbar-btn:hover { background: var(--primary-50); color: var(--primary); border-color: var(--primary-light); }

/* Time display in topbar */
.topbar-time {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    background: var(--bg);
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    font-variant-numeric: tabular-nums;
}

/* === Company Switcher === */
.company-switcher { position: relative; }
.company-switcher-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 14px;
    background: var(--primary-50);
    border: 1px solid var(--primary-light);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    color: var(--primary-dark);
    transition: all var(--transition);
    max-width: 220px;
}
.company-switcher-btn:hover { border-color: var(--primary); background: var(--primary-light); box-shadow: 0 2px 8px rgba(37,99,235,0.12); }
.company-switcher-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.company-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-xl);
    min-width: 260px;
    z-index: 200;
    display: none;
    overflow: hidden;
    animation: dropdownIn 0.15s ease-out;
}
.company-dropdown.show { display: block; }
.company-option {
    display: block;
    padding: 11px 16px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
    border-bottom: 1px solid var(--border-light);
}
.company-option:last-child { border-bottom: none; }
.company-option:hover { background: var(--primary-50); color: var(--primary); }
.company-option.active { background: var(--primary-50); color: var(--primary); font-weight: 700; }

/* === Language Switcher === */
.lang-switcher { position: relative; }
.lang-switcher-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 7px 12px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    color: var(--text);
    transition: all var(--transition);
}
.lang-switcher-btn:hover { border-color: var(--primary); background: var(--primary-50); }
.lang-flag { font-size: 11px; font-weight: 700; color: var(--text-secondary); }
.lang-code { text-transform: uppercase; }
.lang-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-xl);
    min-width: 170px;
    z-index: 200;
    display: none;
    overflow: hidden;
    animation: dropdownIn 0.15s ease-out;
}
.lang-dropdown.show { display: block; }
.lang-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
}
.lang-option:hover { background: var(--primary-50); color: var(--primary); }
.lang-option.active { background: var(--primary-50); color: var(--primary); font-weight: 700; }

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

/* === Content Area === */
.content { flex: 1; padding: 24px; max-width: 1600px; }
.content-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    gap: 16px;
    flex-wrap: wrap;
}
.content-header h1 {
    font-size: 22px;
    font-weight: 700;
    color: var(--text);
    line-height: 1.2;
    letter-spacing: -0.2px;
}
.content-header .actions { display: flex; gap: 8px; align-items: center; }

/* === Cards ===
 * Cards aren't interactive by default → no hover shadow change. Reserve that
 * for `.card.is-interactive` if a feature really needs it. */
.card {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    margin-bottom: 20px;
}
.card.is-interactive { transition: box-shadow var(--transition), border-color var(--transition); cursor: pointer; }
.card.is-interactive:hover { box-shadow: var(--shadow-md); border-color: var(--text-muted); }
.card-header {
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.card-header h2, .card-header h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    letter-spacing: -0.1px;
}
.card-body { padding: 20px; }
.card-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--border);
    background: var(--bg-soft);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    font-size: 12px;
    color: var(--text-secondary);
}

/* === Buttons ===
 * Restrained motion (no bounce), 1px borders, sharp focus ring. Matches
 * the dense ERP feel — animation is communication, not decoration. */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 600;
    border-radius: var(--radius);
    border: 1px solid transparent;
    cursor: pointer;
    transition: background var(--transition), border-color var(--transition), color var(--transition), box-shadow var(--transition);
    white-space: nowrap;
    line-height: 1.3;
    user-select: none;
}
.btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.btn:disabled, .btn[disabled] { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); color: #fff; }
.btn-primary:active { background: var(--primary-dark); }
.btn-secondary { background: var(--card-bg); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--bg-soft); border-color: var(--text-muted); color: var(--text); }
.btn-secondary:active { background: var(--bg); }
.btn-success { background: var(--success); color: #fff; border-color: var(--success); }
.btn-success:hover { background: #047857; border-color: #047857; color: #fff; }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { background: #b91c1c; border-color: #b91c1c; color: #fff; }
.btn-warning { background: var(--warning); color: #fff; border-color: var(--warning); }
.btn-warning:hover { background: #b45309; border-color: #b45309; color: #fff; }
.btn-info { background: var(--info); color: #fff; border-color: var(--info); }
.btn-info:hover { background: #0e7490; border-color: #0e7490; color: #fff; }
.btn-sm { padding: 6px 12px; font-size: 12px; gap: 4px; }
.btn-lg { padding: 11px 22px; font-size: 14px; font-weight: 600; }
.btn-icon { width: 34px; height: 34px; padding: 0; }
.btn-icon.btn-sm { width: 28px; height: 28px; }
.btn-group { display: inline-flex; gap: 0; }
.btn-group .btn { border-radius: 0; margin-left: -1px; }
.btn-group .btn:first-child { border-radius: var(--radius) 0 0 var(--radius); margin-left: 0; }
.btn-group .btn:last-child { border-radius: 0 var(--radius) var(--radius) 0; }
.btn-link { background: transparent; border: none; color: var(--primary); padding: 4px 8px; font-weight: 600; }
.btn-link:hover { background: var(--primary-50); }

/* === Forms ===
 * Single source of truth for control geometry: every interactive field
 * (input, select, textarea, Tom Select) shares the same height (36px),
 * border (1px), radius and focus ring. Mixed weights/heights look like
 * bugs, not design — keep them in lockstep. */
.form-group { margin-bottom: 14px; }
.form-group:last-child { margin-bottom: 0; }
.form-label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 5px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    line-height: 1.3;
}
.form-label .required { color: var(--danger); margin-left: 2px; font-weight: 700; }
.form-control {
    width: 100%;
    min-height: 36px;
    padding: 7px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    font-family: inherit;
    color: var(--text);
    background: #fff;
    transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
    line-height: 1.4;
}
.form-control:hover:not(:focus):not(:disabled):not([readonly]) { border-color: #b6c0d0; }
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.12); }
.form-control::placeholder { color: var(--text-muted); }
.form-control:disabled, .form-control[readonly] { background: var(--bg-soft); color: var(--text-secondary); cursor: not-allowed; }
input[type="number"].form-control { font-variant-numeric: tabular-nums; }
input[type="date"].form-control, input[type="time"].form-control, input[type="datetime-local"].form-control {
    font-variant-numeric: tabular-nums;
    height: 36px;          /* WebKit otherwise renders date inputs ~38px */
    line-height: 1.2;
}
input[type="date"].form-control::-webkit-calendar-picker-indicator { opacity: 0.55; cursor: pointer; }
input[type="date"].form-control:hover::-webkit-calendar-picker-indicator { opacity: 1; }
input[type="date"].form-control::-webkit-datetime-edit { padding: 0; }
select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2 4l4 4 4-4' stroke='%2394a3b8' stroke-width='1.6' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
    cursor: pointer;
}
textarea.form-control { resize: vertical; min-height: 64px; line-height: 1.5; padding: 8px 12px; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; align-items: start; }
.form-row-2 { grid-template-columns: 1fr 1fr; }
.form-row-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-row-4 { grid-template-columns: 1fr 1fr 1fr 1fr; }
.form-hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; line-height: 1.4; }
.form-text { font-size: 11px; color: var(--text-muted); margin-top: 4px; line-height: 1.45; display: block; }
.form-text.text-muted { color: var(--text-muted); }
.form-error { font-size: 12px; color: var(--danger); margin-top: 4px; font-weight: 500; }
.form-control.input-error { border-color: var(--danger) !important; box-shadow: 0 0 0 3px rgba(220,38,38,0.18) !important; }
.form-section { margin-bottom: 22px; }
.form-section:last-child { margin-bottom: 0; }
.form-section-title {
    font-size: 12px;
    font-weight: 700;
    color: var(--text);
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}
.form-section-title svg { color: var(--primary); width: 16px; height: 16px; flex-shrink: 0; }
.form-actions { display: flex; gap: 8px; padding-top: 16px; border-top: 1px solid var(--border); margin-top: 20px; }
.form-toolbar { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; align-items: center; }
.form-check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; user-select: none; line-height: 1.3; }
.form-check input[type="checkbox"], .form-check input[type="radio"] {
    width: 16px; height: 16px; accent-color: var(--primary); cursor: pointer; flex-shrink: 0; margin: 0;
}
/* Inline checkbox + helper text aligned to the bottom of a sibling field */
.form-check-aligned {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    min-height: 36px;
    align-self: end;
}
.form-check-aligned .form-text { margin-top: 0; }

/* === Tables ===
 * Dense, scannable rows with tabular-nums on numeric columns. Hover is a
 * subtle wash, not a colour pop. */
.table-responsive { overflow-x: auto; border-radius: var(--radius); }
.table { width: 100%; font-size: 13px; }
.table th {
    background: var(--bg-soft);
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    font-size: 10.5px;
    letter-spacing: 0.6px;
    padding: 10px 14px;
    text-align: left;
    white-space: nowrap;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
}
.table td {
    padding: 9px 14px;
    border-bottom: 1px solid var(--border-light);
    vertical-align: middle;
    color: var(--text);
    line-height: 1.4;
}
.table tr:hover td { background: var(--bg-soft); }
.table tr:last-child td { border-bottom: none; }
.table .text-right, .table td.text-right { text-align: right; font-variant-numeric: tabular-nums; }
.table .text-center, .table td.text-center { text-align: center; }
.table .text-nowrap { white-space: nowrap; }
.table .col-actions { width: 120px; white-space: nowrap; }
.table .col-id { width: 56px; color: var(--text-muted); }
.table .col-status { width: 110px; }
.table .col-date { width: 100px; }
.table .col-amount { width: 130px; text-align: right; font-variant-numeric: tabular-nums; }
.table .row-link { cursor: pointer; }
.table .row-link:hover td { background: var(--primary-50); }
.table-empty { text-align: center; padding: 40px 20px; color: var(--text-muted); }
.table-empty svg { width: 44px; height: 44px; margin-bottom: 10px; opacity: 0.3; }
.table-summary { background: var(--primary-50); font-weight: 700; }
.table-summary td { border-top: 1px solid var(--primary); }
/* Mono font + tabular figures for any explicit money/code cell. */
.table .font-mono, .font-mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.table .amount, .amount { font-variant-numeric: tabular-nums; font-weight: 600; }

/* === Badges ===
 * Compact pill — ERP uses badges as status, not as decoration. Subtle border
 * keeps the badge legible on coloured rows. */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.2px;
    white-space: nowrap;
    border: 1px solid transparent;
    line-height: 1.5;
}
.badge-primary { background: var(--primary-light); color: var(--primary-dark); border-color: rgba(37,99,235,0.15); }
.badge-success { background: var(--success-light); color: var(--success); border-color: rgba(5,150,105,0.18); }
.badge-warning { background: var(--warning-light); color: var(--warning); border-color: rgba(217,119,6,0.18); }
.badge-danger { background: var(--danger-light); color: var(--danger); border-color: rgba(220,38,38,0.18); }
.badge-info { background: var(--info-light); color: var(--info); border-color: rgba(8,145,178,0.18); }
.badge-secondary { background: var(--bg-soft); color: var(--text-secondary); border-color: var(--border); }

/* === Filter Bar === */
.filter-bar {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 14px 20px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-sm);
}
.filter-row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.filter-group { display: flex; flex-direction: column; gap: 4px; }
.filter-group label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.filter-group .form-control { padding: 7px 12px; font-size: 13px; min-width: 140px; }
.filter-group select.form-control { min-width: 160px; }
.filter-actions { display: flex; gap: 6px; align-items: flex-end; margin-left: auto; }

/* === Pagination === */
.pagination-wrap { display: flex; align-items: center; justify-content: space-between; padding: 12px 0; gap: 16px; flex-wrap: wrap; }
.pagination { display: flex; gap: 2px; list-style: none; }
.pagination li a, .pagination li span {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 32px;
    padding: 0 8px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    border: 1px solid var(--border);
    background: var(--card-bg);
    transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.pagination li a:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-50); }
.pagination li.active span { background: var(--primary); color: #fff; border-color: var(--primary); }
.pagination li.disabled span { color: var(--text-muted); cursor: default; background: var(--bg-soft); }
.pagination-info { font-size: 12px; color: var(--text-muted); font-weight: 500; }

/* === Dashboard Widgets === */
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
.stat-card {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: 18px 20px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 14px;
    position: relative;
    overflow: hidden;
}
.stat-icon {
    width: 42px;
    height: 42px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.stat-icon.blue { background: var(--primary-light); color: var(--primary); }
.stat-icon.green { background: var(--success-light); color: var(--success); }
.stat-icon.orange { background: var(--warning-light); color: var(--warning); }
.stat-icon.red { background: var(--danger-light); color: var(--danger); }
.stat-icon.cyan { background: var(--info-light); color: var(--info); }
.stat-info { min-width: 0; }
.stat-info .stat-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--text);
    line-height: 1.1;
    letter-spacing: -0.4px;
    font-variant-numeric: tabular-nums;
}
.stat-info .stat-label {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
    font-weight: 500;
}
.stat-info .stat-change { font-size: 11px; margin-top: 4px; font-weight: 600; }
.stat-change.up { color: var(--success); }
.stat-change.down { color: var(--danger); }

.dashboard-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.dashboard-grid .full-width { grid-column: 1 / -1; }

/* === Dashboard Tabs === */
.dashboard-tabs {
    display: flex;
    gap: 2px;
    margin-bottom: 16px;
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: 4px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
}
.dash-tab {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    transition: background var(--transition), color var(--transition);
    white-space: nowrap;
}
.dash-tab:hover { background: var(--bg-soft); color: var(--text); }
.dash-tab.active { background: var(--primary); color: #fff; }
.dash-tab .icon-sm { width: 16px; height: 16px; }

/* === Date Range Bar === */
.date-range-bar {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: 14px 20px;
    margin-bottom: 24px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
}
.date-range-form { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.period-presets { display: flex; gap: 4px; flex-wrap: wrap; }
.preset-btn {
    padding: 7px 14px;
    border-radius: var(--radius);
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    background: var(--bg);
    transition: all var(--transition);
}
.preset-btn:hover { background: var(--primary-light); color: var(--primary); }
.preset-btn.active { background: var(--primary-gradient); color: #fff; box-shadow: 0 2px 6px rgba(37,99,235,0.2); }
.date-inputs { display: flex; align-items: center; gap: 8px; }
.date-inputs .form-control-sm { padding: 7px 12px; font-size: 12px; width: 140px; }
.date-sep { color: var(--text-muted); font-size: 12px; }

/* === Aging Bars === */
.aging-cell { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
.aging-bar { height: 6px; border-radius: 3px; min-width: 0; transition: width 0.3s ease; }
.table-footer { background: var(--bg); font-weight: 700; }
.table-footer td { border-top: 2px solid var(--border); }

/* === Alerts / Toast === */
.alert {
    padding: 11px 16px;
    border-radius: var(--radius);
    margin-bottom: 14px;
    font-size: 13px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 10px;
    border: 1px solid;
    border-left-width: 3px;
    animation: alertIn 0.22s ease-out;
}
@keyframes alertIn {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}
.alert-success { background: var(--success-light); border-color: var(--success); color: #065f46; }
.alert-danger {
    background: var(--danger);
    border-color: #991b1b;
    color: #fff;
    font-weight: 600;
    box-shadow: 0 4px 14px rgba(220, 38, 38, 0.35);
}
.alert-danger a { color: #fff; text-decoration: underline; }
.alert-warning { background: var(--warning-light); border-color: var(--warning); color: #92400e; }
.alert-info { background: var(--info-light); border-color: var(--info); color: #155e75; }

.toast-container { position: fixed; top: 16px; right: 16px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; }
.toast {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 12px 16px;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border);
    border-left: 3px solid var(--primary);
    min-width: 300px;
    max-width: 420px;
    animation: toastIn 220ms ease;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    font-weight: 500;
}
.toast.success { border-left-color: var(--success); }
.toast.danger { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }
.toast-close { margin-left: auto; cursor: pointer; color: var(--text-muted); padding: 2px 6px; border: none; background: none; font-size: 16px; line-height: 1; transition: color var(--transition); }
.toast-close:hover { color: var(--text); }
@keyframes toastIn { from { opacity: 0; transform: translateX(30px); } to { opacity: 1; transform: translateX(0); } }

/* === Modal === */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15,23,42,0.5);
    z-index: 2000;
    display: none;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}
.modal-overlay.active { display: flex; }
.modal {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    width: 540px;
    max-width: 95vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    animation: modalIn 200ms ease;
    border: 1px solid var(--border);
}
.modal-lg { width: 760px; }
.modal-xl { width: 1080px; }
.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.modal-header h3 { font-size: 15px; font-weight: 600; letter-spacing: -0.1px; }
/* Icon-only ✕ — ONLY the header close button. Footer cancel buttons also
   carry .modal-close (for the JS close binding) but must stay normal .btn:
   scoping here keeps them from collapsing to a 30px transparent square. */
.modal-header .modal-close {
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius);
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    transition: background var(--transition), color var(--transition);
    padding: 0;
}
.modal-header .modal-close:hover { background: var(--bg-soft); color: var(--text); }
.modal-body { padding: 20px; overflow-y: auto; flex: 1; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; background: var(--bg-soft); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
@keyframes modalIn { from { opacity: 0; transform: scale(0.97) translateY(6px); } to { opacity: 1; transform: scale(1) translateY(0); } }

/* === Tabs === */
.tabs { display: flex; gap: 0; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.tab {
    padding: 10px 18px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    cursor: pointer;
    transition: color var(--transition), border-color var(--transition);
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* === Detail View === */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.detail-section { margin-bottom: 24px; }
.detail-section-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 8px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}
.detail-row { display: flex; padding: 7px 0; font-size: 13px; border-bottom: 1px solid var(--border-light); align-items: baseline; gap: 12px; }
.detail-row:last-child { border-bottom: none; }
.detail-label { width: 160px; color: var(--text-secondary); font-weight: 500; flex-shrink: 0; font-size: 12px; }
.detail-value { color: var(--text); font-weight: 500; }

/* === Stop (Loading/Unloading) Cards === */
.stops-container { display: flex; flex-direction: column; gap: 10px; }
.stop-card {
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 14px 16px;
    position: relative;
    transition: border-color var(--transition), box-shadow var(--transition);
    background: var(--card-bg);
}
.stop-card:hover { border-color: #b6c0d0; box-shadow: var(--shadow-sm); }
.stop-card:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.08); }
.stop-card.loading { border-left: 3px solid var(--success); }
.stop-card.unloading { border-left: 3px solid var(--warning); }
.stop-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; padding-right: 32px; }
.stop-type { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.8px; }
.stop-type.loading { color: var(--success); }
.stop-type.unloading { color: var(--warning); }
.stop-number { font-size: 11px; color: var(--text-muted); background: var(--bg); padding: 3px 10px; border-radius: 12px; font-weight: 600; }
.stop-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px 14px; }
.stop-grid .form-group { margin-bottom: 0; }
.stop-remove { position: absolute; top: 8px; right: 8px; }

/* Cargo lines nested inside a loading stop. Compact (12px font / 30px tall)
 * so a row of 6 fields + delete button fits without horizontal scroll. */
.cargo-lines-section {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px dashed var(--border);
}
.cargo-lines-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    gap: 8px;
}
.cargo-lines-header-label {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.cargo-lines-container { display: flex; flex-direction: column; gap: 6px; }
.cargo-line-row {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr 1fr 1fr 1.2fr auto;
    gap: 6px;
    align-items: end;
    padding: 8px;
    background: var(--bg-soft);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-light);
}
.cargo-line-row .form-group { margin: 0; }
.cargo-line-row .form-label { font-size: 10px; margin-bottom: 3px; }
.cargo-line-row .form-control { font-size: 12px; min-height: 30px; padding: 4px 8px; }
.cargo-line-row select.form-control { padding-right: 26px; background-position: right 8px center; }
.cargo-line-remove { display: flex; align-items: end; padding-bottom: 1px; }
.cargo-line-remove .btn { padding: 4px 8px; font-size: 11px; min-height: 30px; }

/* === Sortable table headers (all list pages) === */
.table thead .sort-link { color: inherit; text-decoration: none; cursor: pointer; white-space: nowrap; }
.table thead .sort-link:hover { text-decoration: underline; }
.table thead .sort-link.active { color: var(--primary); }

/* === Utility Classes === */
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-left { text-align: left; }
.text-primary { color: var(--primary); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.font-mono { font-family: var(--font-mono); }
.font-bold { font-weight: 700; }
.font-semibold { font-weight: 600; }
.mt-0 { margin-top: 0; } .mt-8 { margin-top: 8px; } .mt-16 { margin-top: 16px; } .mt-24 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; } .mb-8 { margin-bottom: 8px; } .mb-16 { margin-bottom: 16px; } .mb-24 { margin-bottom: 24px; }
.mr-8 { margin-right: 8px; }
.ml-auto { margin-left: auto; }
.p-0 { padding: 0; }
.gap-8 { gap: 8px; }
.gap-16 { gap: 16px; }
.d-flex { display: flex; }
.d-grid { display: grid; }
.flex-1 { flex: 1; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.w-100 { width: 100%; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hidden { display: none !important; }
.clickable { cursor: pointer; }

/* === SVG Icons (inline) === */
.icon { width: 18px; height: 18px; display: inline-block; vertical-align: middle; }
.icon-sm { width: 14px; height: 14px; }
.icon-lg { width: 24px; height: 24px; }

/* === Amount highlighting === */
.amount { font-family: var(--font-mono); font-weight: 700; font-size: 13px; letter-spacing: -0.3px; }
.amount-positive { color: var(--success); }
.amount-negative { color: var(--danger); }

/* === Print Styles === */
@media print {
    .sidebar, .topbar, .filter-bar, .content-header .actions, .pagination-wrap, .btn, .no-print, .page-loader { display: none !important; }
    .main-content { margin-left: 0 !important; }
    .content { padding: 0 !important; }
    .card { box-shadow: none !important; border: 1px solid #ddd !important; }
    body { background: #fff !important; }
}

/* === Responsive ===
 * Primary target is 1920x1080 / 1440p — keep dense 4-col stat grid up to
 * ~1280px viewport width. Below that, collapse progressively. */
@media (max-width: 1280px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .dashboard-grid { grid-template-columns: 1fr; }
    .form-row-4 { grid-template-columns: 1fr 1fr; }
    .detail-grid { grid-template-columns: 1fr; }
    .dashboard-tabs { flex-wrap: wrap; }
    .date-range-form { flex-direction: column; align-items: stretch; }
    .date-inputs { justify-content: flex-start; }
}
@media (max-width: 1024px) {
    :root { --sidebar-width: 220px; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .dash-tab { padding: 8px 14px; font-size: 12px; }
    .content { padding: 18px; }
}

/* === Scrollbar === */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* === Quick search === */
.quick-search { position: relative; }
.quick-search input {
    padding: 8px 14px 8px 36px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    width: 280px;
    background: var(--bg);
    transition: all var(--transition);
}
.quick-search input:focus { background: #fff; border-color: var(--primary); box-shadow: 0 0 0 4px rgba(37,99,235,0.1); width: 340px; outline: none; }
.quick-search .search-icon { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--text-muted); }

/* === Tooltip === */
[data-tooltip] { position: relative; }
[data-tooltip]:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--sidebar-bg);
    color: #fff;
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
    z-index: 100;
    margin-bottom: 6px;
    box-shadow: var(--shadow-md);
}

/* === Progress bar === */
.progress-bar { height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; }
.progress-bar .fill { height: 100%; border-radius: 3px; transition: width 300ms ease; }
.progress-bar .fill.green { background: var(--success); }
.progress-bar .fill.orange { background: var(--warning); }
.progress-bar .fill.red { background: var(--danger); }
.progress-bar .fill.blue { background: var(--primary); }

/* === KPI mini chart === */
.mini-chart { height: 60px; display: flex; align-items: flex-end; gap: 3px; padding: 4px 0; }
.mini-chart .bar { flex: 1; background: var(--primary-light); border-radius: 3px 3px 0 0; transition: height 300ms ease; }
.mini-chart .bar:hover { background: var(--primary); }

/* === Tom Select Overrides ===
 * Locked to .form-control geometry (36px tall, 1px border, 3px focus ring)
 * so a Tom Select sits flush in a .form-row next to a native input/select.
 *
 * Tom Select's vendor CSS is aggressive: it ships `padding: 8px`,
 * `line-height: 18px`, a `padding-right: !important` rule built from CSS
 * variables, and an `.input-active` state that paints an extra background
 * ring around the inner item div — which is what reads as a "double border".
 * We use `!important` on the geometry rules so vendor `!important` ones can
 * never push the wrapper past 36px or re-introduce inner chrome. */
.ts-wrapper {
    font-size: 13px;
    background: transparent !important;
    border: 0 !important;
    box-shadow: none !important;
    padding: 0 !important;
}
.ts-wrapper .ts-control {
    box-sizing: border-box !important;
    border: 1px solid var(--border) !important;
    border-radius: var(--radius) !important;
    padding: 0 12px !important;
    min-height: 36px !important;
    background: #fff !important;
    box-shadow: none !important;
    align-items: center !important;
    line-height: 1.4 !important;
    overflow: hidden;
    transition: border-color var(--transition), box-shadow var(--transition);
}
.ts-wrapper.single .ts-control { height: 36px !important; }
.ts-wrapper.multi .ts-control { padding: 3px 12px !important; min-height: 36px !important; height: auto !important; }
.ts-wrapper.multi.has-items .ts-control { padding: 4px 8px 0 8px !important; }

/* Inner input/items: strip every visual chrome so only the wrapper border
 * is ever visible. This kills the "double border" artifact. */
.ts-wrapper .ts-control > input,
.ts-wrapper .ts-control > input:focus {
    border: 0 !important;
    box-shadow: none !important;
    outline: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    background: transparent !important;
    font-size: 13px !important;
    line-height: 1.4 !important;
    height: auto !important;
    min-height: 0 !important;
    color: var(--text);
}
.ts-wrapper.single .ts-control > .item,
.ts-wrapper.single .ts-control > div:not(.ts-dropdown) {
    background: transparent !important;
    border: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    line-height: 1.4 !important;
}
.ts-wrapper .ts-control .item { color: var(--text); }
.ts-wrapper .ts-control > .item.placeholder,
.ts-wrapper .ts-control > input::placeholder { color: var(--text-muted) !important; }

.ts-wrapper:not(.focus):not(.disabled) .ts-control:hover { border-color: #b6c0d0 !important; }
.ts-wrapper.focus .ts-control { border-color: var(--primary) !important; box-shadow: 0 0 0 3px rgba(37,99,235,0.12) !important; }
.ts-wrapper.disabled .ts-control { background: var(--bg-soft) !important; color: var(--text-secondary); cursor: not-allowed; }

/* The hidden underlying <select> keeps `.form-control` from the markup;
 * make doubly sure its border can never show through. */
.ts-wrapper .ts-hidden-accessible {
    border: 0 !important;
    padding: 0 !important;
    height: 1px !important;
    width: 1px !important;
}
.ts-wrapper .ts-dropdown { border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-xl); margin-top: 4px; }
.ts-wrapper .ts-dropdown .ts-option-item { padding: 10px 14px; }
.ts-wrapper .ts-dropdown .ts-option-item .ts-option-text { font-weight: 600; }
.ts-wrapper .ts-dropdown .ts-option-item .ts-option-subtitle { display: block; font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.ts-wrapper .ts-dropdown .active { background: var(--primary-50); color: var(--primary); }
.ts-wrapper .ts-dropdown .no-results { padding: 12px; text-align: center; color: var(--text-muted); font-size: 13px; }

/* Search count summary (top of dropdown) + add-new footer.
 * Inserted by App.renderSearchExtras() once results arrive. */
.ts-wrapper .ts-dropdown .ts-search-summary {
    padding: 8px 14px;
    font-size: 11px;
    color: var(--text-muted);
    background: var(--surface-2, #f8fafc);
    border-bottom: 1px solid var(--border-light);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    font-weight: 600;
}
.ts-wrapper .ts-dropdown .ts-search-footer {
    padding: 8px;
    background: var(--surface-2, #f8fafc);
    border-top: 1px solid var(--border-light);
    position: sticky;
    bottom: 0;
}
.ts-wrapper .ts-dropdown .ts-search-footer .ts-add-btn {
    width: 100%;
    padding: 8px 12px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: background var(--transition);
}
.ts-wrapper .ts-dropdown .ts-search-footer .ts-add-btn:hover {
    background: var(--primary-hover, #1d4ed8);
}
.ts-wrapper .ts-dropdown .ts-search-footer .ts-add-icon {
    font-size: 16px;
    line-height: 1;
    font-weight: 700;
}

/* Quick-add button next to select */
.select-with-add { display: flex; gap: 6px; align-items: flex-start; }
.select-with-add .ts-wrapper, .select-with-add select { flex: 1; }
.btn-quick-add { width: 40px; height: 40px; padding: 0; display: flex; align-items: center; justify-content: center; flex-shrink: 0; font-size: 18px; font-weight: 700; }

/* === Smooth page transitions === */
.content {
    animation: contentFadeIn 0.3s ease-out;
}
@keyframes contentFadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ============================================================
 * Sidebar UX additions: header controls, rail mode, active dot
 * ============================================================ */

:root {
    --sidebar-rail-width: 64px;
}

/* Logo + control buttons sit on the same row in the header. */
.sidebar-header { gap: 6px; }
.sidebar-header .logo { flex: 1; min-width: 0; }
.sidebar-controls { display: flex; gap: 4px; flex-shrink: 0; }
.sidebar-control-btn {
    width: 30px;
    height: 30px;
    background: transparent;
    border: none;
    color: var(--sidebar-text);
    cursor: pointer;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition), color var(--transition);
    padding: 0;
}
.sidebar-control-btn:hover {
    background: var(--sidebar-hover);
    color: var(--sidebar-text-active);
}
.sidebar-control-btn svg { width: 16px; height: 16px; }

/* Active-section dot indicator: shows on the section title when the section
 * is collapsed AND it owns the currently active page. JS sets `.has-active`. */
.nav-section.has-active.collapsed .nav-section-title {
    color: var(--sidebar-text-active);
    padding-left: 18px;
}
.nav-section.has-active.collapsed .nav-section-title::before {
    content: '';
    position: absolute;
    left: 6px;
    top: 50%;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--sidebar-active-border);
    transform: translateY(-50%);
    box-shadow: 0 0 6px rgba(37, 99, 235, 0.6);
}

/* ----- Rail mode -----
 * Triggered by `.rail-mode` on <html> (set by inline script in head to avoid
 * FOUC). Sidebar shrinks to 64px showing only icons; hover expands as overlay
 * without pushing main-content. */
html.rail-mode .sidebar { width: var(--sidebar-rail-width); }
html.rail-mode .main-content { margin-left: var(--sidebar-rail-width); }
html.rail-mode .sidebar:hover {
    width: var(--sidebar-width);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.35);
}

/* In rail mode (not hovered), keep only the essentials:
 *   - logo icon (text hidden)
 *   - rail toggle button (collapse-all is hidden — irrelevant in rail)
 *   - icons of every nav-item (labels hidden)
 *   - section structure flattened (titles hidden, items always shown) */
html.rail-mode .sidebar:not(:hover) .logo,
html.rail-mode .sidebar:not(:hover) .nav-label,
html.rail-mode .sidebar:not(:hover) .nav-section-title,
html.rail-mode .sidebar:not(:hover) .control-collapse-all,
html.rail-mode .sidebar:not(:hover) .user-info {
    display: none;
}

/* Collapse animation must not hide items in rail mode — sections are always
 * "open" when rail mode is on (not hovered). On hover, normal collapse rules
 * apply again. */
html.rail-mode .sidebar:not(:hover) .nav-section.collapsed .nav-section-items {
    max-height: none;
    opacity: 1;
}

/* Tighten paddings and center icons in rail mode. */
html.rail-mode .sidebar:not(:hover) .nav-section { padding: 0 8px; }
html.rail-mode .sidebar:not(:hover) .nav-item {
    justify-content: center;
    padding: 9px 8px;
    gap: 0;
}
html.rail-mode .sidebar:not(:hover) .sidebar-footer .sidebar-user { justify-content: center; padding: 12px; }
html.rail-mode .sidebar:not(:hover) .sidebar-user .user-menu-chevron { display: none; }
/* In rail mode the menu is too narrow to anchor inside — pop it out to the right. */
html.rail-mode .sidebar:not(:hover) .user-menu {
    bottom: 0;
    left: calc(100% + 8px);
    right: auto;
    width: 220px;
}

/* In rail mode the header collapses to host only the rail-toggle, centered.
 * The whole .sidebar-controls cluster stays in normal flow (NOT display:none —
 * that would prevent any descendant from rendering and lock the user out of
 * rail mode). */
html.rail-mode .sidebar:not(:hover) .sidebar-header {
    padding: 0;
    justify-content: center;
}
html.rail-mode .sidebar:not(:hover) .sidebar-controls {
    width: 100%;
    justify-content: center;
}

/* Chevron direction: points left when expanded (clicking collapses to rail),
 * flips to point right when in rail (clicking expands back). */
html.rail-mode .sidebar:not(:hover) .control-rail-toggle svg { transform: rotate(180deg); }

/* Active item left bar already exists at left:-12px relative to nav-item;
 * in rail mode it'd clip — pull it inside. */
html.rail-mode .sidebar:not(:hover) .nav-item.active::before { left: -8px; }
