/* ===== CSS Variables — EMS V3 Brand (Deep Navy + Teal) =====
   Palette pulled directly from the brand sheet:
     Deep Navy  #091B2C   primary
     Teal       #0D8395   accent
     Cool Gray  #9DA8AB   text-muted
     Light Gray #D7D7D5   borders
   Typography: Satoshi (Regular 400 / Medium 500 / SemiBold 600 / Bold 700).
   The sage-green palette from V2.5 has been retired. */
:root {
    --primary: #091B2C;          /* Deep Navy — main brand */
    --primary-soft: #e8edf2;     /* Very light navy tint (backgrounds) */
    --primary-dark: #040E1A;     /* Darker navy for hover */
    --accent: #0D8395;           /* Teal — links, focus, secondary CTAs */
    --accent-soft: #e0f2f4;
    --accent-dark: #0a6675;
    --surface: #ffffff;
    --surface-2: #f7f9fb;
    --surface-3: #eef2f6;
    --bg: #f4f6f8;
    --text: #091B2C;             /* Deep navy reads as body text too */
    --text-soft: #5a6b7a;
    --text-muted: #9DA8AB;       /* Brand cool gray */
    --border: #e2e8f0;
    --border-strong: #cbd5e1;
    --success: #15803d;
    --success-soft: #dcfce7;
    --warning: #c49520;
    --warning-soft: #fef8e8;
    --error: #c0392b;
    --error-soft: #fde8e5;
    --info: #0D8395;             /* Teal-aligned info to match brand */
    --info-soft: #e0f2f4;
    --radius: 8px;
    --radius-lg: 14px;
    --shadow: 0 1px 3px rgba(9,27,44,0.06), 0 1px 2px rgba(9,27,44,0.04);
    --shadow-lg: 0 12px 28px rgba(9,27,44,0.10), 0 4px 10px rgba(9,27,44,0.04);
    --transition: 0.2s ease;
    --sidebar-width: 240px;
    --topbar-height: 56px;
    --surface-elevated: #f1f5f9;
    --text-primary: #091B2C;
}

/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; }
body {
    font-family: 'Satoshi', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
    overflow: hidden;
}
input, select, textarea, button { font-family: inherit; font-size: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-dark); }

/* ===== Login Screen — V3 marketable two-pane layout ===== */
.login-screen {
    position: fixed; inset: 0;
    background: linear-gradient(135deg, #091B2C 0%, #0a3a4a 55%, #0D8395 100%);
    display: flex; align-items: stretch; justify-content: stretch;
    z-index: 9999; overflow: auto;
    transition: opacity 0.3s ease;
}
/* When logged in, REMOVE the login overlay from the rendering tree —
   not just opacity:0. A transparent z-index:9999 layer sitting over
   the whole viewport can confuse the browser compositor into briefly
   blanking modals / popups when the user clicks: each click triggers
   a repaint that "rediscovers" the (still-present) overlay and the
   modal content under it flickers as the layers re-stack. display:
   none (matching portal-login.hidden) sidesteps the whole issue. */
.login-screen.hidden { display: none; }
.login-card {
    background: var(--surface);
    border-radius: 16px;
    padding: 40px;
    width: 380px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}
.login-card h1 { font-size: 22px; font-weight: 700; margin-bottom: 4px; color: var(--text); }
.login-card .subtitle { color: var(--text-soft); font-size: 13px; margin-bottom: 28px; }
.login-card .logo { font-size: 28px; color: var(--primary); margin-bottom: 16px; }
.login-field { margin-bottom: 16px; }
.login-field label { display: block; font-size: 12px; font-weight: 600; color: var(--text-soft); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.5px; }
.login-field input {
    width: 100%; padding: 10px 14px;
    border: 1.5px solid var(--border-strong); border-radius: var(--radius);
    font-size: 14px; transition: border-color var(--transition);
}
.login-field input:focus { outline: none; border-color: var(--primary); }
.login-error { color: var(--error); font-size: 12px; margin-bottom: 12px; min-height: 18px; }
.login-btn {
    width: 100%; padding: 12px; background: var(--primary); color: #fff;
    border: none; border-radius: var(--radius); font-weight: 600; font-size: 14px;
    cursor: pointer; transition: background var(--transition);
}
.login-btn:hover { background: var(--primary-dark); }

/* ── V3 marketable login: two-pane layout ───────────────────────────
   Left pane = brand hero (logo, tagline, value props) on a navy/teal
   gradient. Right pane = white sign-in card. Stacks to single-column
   under 960px so phones still get a usable form. */
.login-shell {
    display: grid; grid-template-columns: 1fr 1fr; min-height: 100vh; width: 100%;
}
@media (max-width: 960px) {
    .login-shell { grid-template-columns: 1fr; }
    .login-hero { padding: 40px 28px !important; }
}
.login-hero {
    color: #fff; padding: 56px 64px; display: flex; flex-direction: column;
    justify-content: space-between; gap: 32px;
    background: linear-gradient(135deg, rgba(9,27,44,0.92), rgba(13,131,149,0.08));
}
.login-hero-top { display: flex; align-items: center; gap: 12px; }
.login-hero-logo { height: 34px; width: auto; filter: brightness(0) invert(1); }
.login-hero-brand { display: flex; align-items: center; gap: 14px; padding-right: 16px; border-right: 1px solid rgba(255,255,255,0.18); }
.login-hero-tagline {
    color: rgba(255,255,255,0.82); font-size: 13px; letter-spacing: 0.4px;
    text-transform: uppercase; font-weight: 600;
}
.login-hero-tagline small { display: block; font-size: 11px; color: rgba(255,255,255,0.55); margin-top: 4px; letter-spacing: 1.5px; font-weight: 500; }
.login-hero-headline {
    font-size: 38px; font-weight: 700; line-height: 1.18; letter-spacing: -0.6px;
    margin-bottom: 14px;
}
.login-hero-headline .accent { color: #5cc4d2; }
.login-hero-sub {
    font-size: 15px; color: rgba(255,255,255,0.82); line-height: 1.55;
    max-width: 480px; margin-bottom: 28px;
}
.login-hero-features { display: grid; gap: 12px; }
.login-hero-feature {
    display: flex; align-items: flex-start; gap: 12px;
    color: rgba(255,255,255,0.92); font-size: 13.5px; line-height: 1.5;
}
.login-hero-feature i {
    width: 32px; height: 32px; flex-shrink: 0;
    border-radius: 8px; background: rgba(13,131,149,0.25);
    color: #5cc4d2; display: inline-flex; align-items: center; justify-content: center;
    font-size: 13px;
}
.login-hero-feature strong { display: block; font-weight: 600; color: #fff; margin-bottom: 2px; }
.login-hero-foot {
    font-size: 11px; color: rgba(255,255,255,0.55); letter-spacing: 1px; text-transform: uppercase;
}
.login-pane {
    display: flex; align-items: center; justify-content: center;
    padding: 56px 32px; background: var(--surface);
}
.login-pane .login-card {
    width: 100%; max-width: 420px; padding: 44px 40px;
    box-shadow: none; border-radius: 16px;
}
.login-toggle {
    display: flex; gap: 4px; padding: 4px; margin: 0 0 24px;
    background: var(--surface-3); border-radius: 999px;
}
.login-toggle button {
    flex: 1; padding: 9px 14px; border: none; background: transparent;
    color: var(--text-soft); font-size: 13px; font-weight: 600; cursor: pointer;
    border-radius: 999px; transition: all var(--transition);
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.login-toggle button.active {
    background: var(--surface); color: var(--primary);
    box-shadow: 0 1px 3px rgba(9,27,44,0.08);
}
.login-toggle button i { font-size: 12px; }
.login-meta { margin-top: 22px; font-size: 11.5px; color: var(--text-muted); text-align: center; }
.login-meta a { color: var(--accent); font-weight: 600; }
.login-back {
    display: inline-flex; align-items: center; gap: 6px;
    color: rgba(255,255,255,0.7); font-size: 12px; text-decoration: none;
    padding: 6px 12px; border-radius: 999px;
    background: rgba(255,255,255,0.08); transition: all var(--transition);
}
.login-back:hover { color: #fff; background: rgba(255,255,255,0.16); }

/* ===== Lock Screen ===== */
.lock-screen {
    position: fixed; inset: 0;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(8px);
    display: flex; align-items: center; justify-content: center;
    z-index: 9998;
    transition: opacity 0.3s ease;
}
/* Same compositor-flicker fix as login-screen.hidden — fully drop
   the lock overlay from the rendering tree when unlocked rather than
   leaving an invisible click-through layer at z-index:9998. */
.lock-screen.hidden { display: none; }
.lock-card {
    background: var(--surface); border-radius: 16px; padding: 36px;
    width: 340px; text-align: center; box-shadow: var(--shadow-lg);
}
.lock-avatar { width: 64px; height: 64px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); display: flex; align-items: center; justify-content: center; font-size: 24px; margin: 0 auto 12px; }

/* ===== App Layout ===== */
.app-layout {
    display: flex;
    height: 100vh;
    transition: opacity 0.3s ease;
}
.app-layout.hidden { opacity: 0; pointer-events: none; }

/* ===== Sidebar ===== */
.sidebar {
    width: var(--sidebar-width);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column;
    flex-shrink: 0;
    overflow-y: auto;
}
.sidebar-logo {
    padding: 18px 20px;
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: 10px;
}
.sidebar-logo .logo-icon { width: 32px; height: 32px; background: var(--primary); border-radius: 8px; display: flex; align-items: center; justify-content: center; color: #fff; font-size: 15px; }
.sidebar-logo .logo-text { font-weight: 700; font-size: 14px; line-height: 1.2; }
.sidebar-logo .logo-text small { display: block; font-weight: 400; font-size: 10px; color: var(--text-muted); }
/* V3 brand wordmark — replaces the old text-based "Excise Management
   Solutions" lockup with the official logo image. Sized down 30%
   from the original 30px so it sits proportionally in the sidebar
   header. */
.sidebar-logo-img { height: 21px; width: auto; max-width: 112px; display: block; }
.sidebar-logo--brand { padding: 18px 22px; justify-content: flex-start; }

.sidebar-nav { padding: 12px 8px; flex: 1; }
.sidebar-version {
    padding: 10px 14px 12px;
    border-top: 1px solid var(--border);
    font-size: 11px;
    color: var(--text-muted);
    background: var(--surface-2);
    line-height: 1.4;
}
.sidebar-version-line { font-weight: 600; color: var(--text-soft); display: flex; align-items: center; gap: 5px; }
.sidebar-version-line i { font-size: 10px; opacity: 0.7; }
.sidebar-version-build { font-size: 10px; opacity: 0.75; margin-top: 2px; font-family: 'SF Mono', Monaco, monospace; }
.nav-group-label { padding: 8px 12px 4px; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 1px; color: var(--text-muted); }
.nav-item {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 12px; margin: 1px 0; border-radius: var(--radius);
    cursor: pointer; font-size: 13px; font-weight: 500;
    color: var(--text-soft); transition: all var(--transition);
    position: relative;
}
.nav-item:hover { background: var(--surface-3); color: var(--text); }
.nav-item.active { background: var(--primary-soft); color: var(--primary-dark); font-weight: 600; }
.nav-item i { width: 18px; text-align: center; font-size: 13px; }
.nav-item .nav-badge {
    position: absolute; right: 10px;
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--error); color: #fff;
    font-size: 10px; font-weight: 700;
    min-width: 18px; height: 18px;
    border-radius: 9px; padding: 0 5px;
    /* Body inherits line-height:1.5 which makes the digit float
     * slightly above centre on these small badges. Locking to 1
     * sits the number dead-centre. */
    line-height: 1;
}
.nav-item-sub { padding-left: 40px; font-size: 12px; }

/* ===== Top Bar ===== */
.topbar {
    height: var(--topbar-height);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center;
    padding: 0 24px;
    gap: 16px;
}
.topbar-search {
    flex: 1; max-width: 480px;
    position: relative;
}
.topbar-search input {
    width: 100%; padding: 8px 14px 8px 36px;
    border: 1.5px solid var(--border); border-radius: 20px;
    background: var(--surface-2); font-size: 13px;
    transition: border-color var(--transition);
}
.topbar-search input:focus { outline: none; border-color: var(--primary); background: var(--surface); }
.topbar-search i { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-muted); font-size: 13px; }

.topbar-right { display: flex; align-items: center; gap: 12px; margin-left: auto; }
.topbar-notifications {
    position: relative; width: 36px; height: 36px;
    border-radius: 50%; background: var(--surface-2); border: 1px solid var(--border);
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; font-size: 14px; color: var(--text-soft);
    transition: all var(--transition);
}
.topbar-notifications:hover { background: var(--surface-3); color: var(--text); }
.topbar-notifications .badge {
    position: absolute; top: -2px; right: -2px;
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--error); color: #fff;
    font-size: 9px; font-weight: 700;
    min-width: 16px; height: 16px;
    border-radius: 8px; padding: 0 4px;
    line-height: 1;
}
.topbar-user {
    display: flex; align-items: center; gap: 8px;
    padding: 4px 12px 4px 4px;
    border-radius: 20px; background: var(--surface-2);
    border: 1px solid var(--border); cursor: pointer;
    transition: all var(--transition);
}
.topbar-user:hover { background: var(--surface-3); }
.topbar-user .avatar {
    width: 28px; height: 28px; border-radius: 50%;
    background: var(--primary); color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: 11px; font-weight: 700;
}
.topbar-user .user-info { font-size: 12px; line-height: 1.3; }
.topbar-user .user-name { font-weight: 600; color: var(--text); }
.topbar-user .user-role { color: var(--text-muted); font-size: 10px; }

/* ===== Main Content ===== */
.main-content {
    flex: 1;
    display: flex; flex-direction: column;
    overflow: hidden;
}
.content-area {
    flex: 1; overflow-y: auto;
    padding: 24px;
}

/* ===== Sections ===== */
.section { display: none; }
.section.active { display: block; }
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }
.section-header h2 { font-size: 20px; font-weight: 800; margin: 0; }

/* ===== Cards ===== */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    box-shadow: var(--shadow);
}
.card-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 16px;
}
.card-header h3 { font-size: 15px; font-weight: 700; }

/* ===== Stats Grid ===== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 14px; margin-bottom: 24px;
}
/* Stat card — see EMS Branding Law §5.4. Single canonical rule;
   the second .stat-card definition further down was deleted. */
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px 18px;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.stat-card .stat-label,
.stat-card .stat-card-content h3 { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); margin-bottom: 4px; }
.stat-card .stat-value,
.stat-card .stat-card-content p { font-size: 28px; font-weight: 800; color: var(--text); line-height: 1.1; margin: 0; }
.stat-card .stat-sub { font-size: 11px; color: var(--text-soft); margin-top: 4px; }
.stat-card-icon {
    width: 44px; height: 44px; border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 18px; flex-shrink: 0;
    background: var(--primary-soft); color: var(--primary);
}

/* ===== Role Highlight (dashboard) ===== */
.stat-card.role-highlight {
    border-color: var(--primary);
    border-width: 2px;
    background: linear-gradient(135deg, var(--surface), var(--primary-soft));
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 16px; border-radius: var(--radius);
    font-weight: 600; font-size: 13px;
    cursor: pointer; border: 1px solid transparent;
    transition: all var(--transition);
}
.btn i { font-size: 12px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--surface-3); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #5a8a5a; }
.btn-danger { background: var(--error); color: #fff; }
.btn-danger:hover { background: #a5321f; }
.btn-error { background: var(--error); color: #fff; }
.btn-error:hover { background: #a5321f; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-ghost { background: transparent; color: var(--text-soft); }
.btn-ghost:hover { background: var(--surface-3); color: var(--text); }

/* ===== Progress Bar ===== */
.progress { width: 100%; height: 6px; background: var(--surface-3); border-radius: 3px; overflow: hidden; }
.progress-bar { height: 100%; background: var(--primary); transition: width var(--transition); }

/* ===== Tables ===== */
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table thead th {
    padding: 10px 12px; text-align: left; font-weight: 600; font-size: 11px;
    text-transform: uppercase; letter-spacing: 0.5px;
    color: var(--text-muted); background: var(--surface-2);
    border-bottom: 1px solid var(--border);
}
.data-table tbody td {
    padding: 10px 12px; border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.data-table tbody tr:hover { background: var(--surface-2); }
.data-table tbody tr:last-child td { border-bottom: none; }

/* ===== Modals ===== */
.modal {
    display: none; position: fixed; inset: 0;
    background: rgba(15, 23, 42, 0.45);
    align-items: center; justify-content: center;
    z-index: 5000;
}
.modal.show { display: flex; }
.modal-content {
    background: var(--surface); border-radius: var(--radius-lg);
    width: 90%; max-width: 600px; max-height: 90vh;
    overflow-y: auto; box-shadow: var(--shadow-lg);
}
.modal-header {
    padding: 18px 24px; border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
}
.modal-header h3 { font-size: 16px; font-weight: 700; }
.modal-body { padding: 20px 24px; }
.modal-footer {
    padding: 16px 24px; border-top: 1px solid var(--border);
    display: flex; gap: 10px; justify-content: flex-end;
}
.close-btn, .modal-close {
    width: 32px; height: 32px; border-radius: 8px;
    background: var(--surface-2); border: 1px solid var(--border);
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; color: var(--text-soft); font-size: 16px;
    transition: all var(--transition);
}
.close-btn:hover, .modal-close:hover { background: var(--surface-3); color: var(--text); }

/* ===== Form Elements ===== */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 12px; font-weight: 600; color: var(--text-soft); margin-bottom: 6px; }
.form-group input, .form-group select, .form-group textarea {
    width: 100%; padding: 9px 12px;
    border: 1.5px solid var(--border); border-radius: var(--radius);
    font-size: 13px; transition: border-color var(--transition);
    background: var(--surface);
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
    outline: none; border-color: var(--primary);
}
.form-row { display: flex; gap: 16px; }
.form-row .form-group { flex: 1; }

/* ===== Status Badge ===== */
.status-badge {
    display: inline-block; padding: 3px 10px;
    border-radius: 12px; font-size: 11px;
    font-weight: 600; white-space: nowrap;
}

/* ===== Toast ===== */
.toast-container {
    position: fixed; bottom: 24px; right: 24px;
    display: flex; flex-direction: column; gap: 8px;
    z-index: 10000;
}
.toast {
    padding: 12px 18px; border-radius: var(--radius);
    font-size: 13px; font-weight: 500;
    box-shadow: var(--shadow-lg);
    display: flex; align-items: center; gap: 8px;
    transform: translateX(100%); opacity: 0;
    transition: all 0.3s ease;
}
.toast.show { transform: translateX(0); opacity: 1; }
.toast-success { background: #3d6b3e; color: #fff; }
.toast-error { background: #9b2c2c; color: #fff; }
.toast-info { background: #3b5d8a; color: #fff; }
.toast-warning { background: #8a6420; color: #fff; }

/* ===== Module Toggle ===== */
.module-card {
    border: 1px solid var(--border); border-radius: var(--radius-lg);
    padding: 18px 20px; margin-bottom: 12px;
    display: flex; align-items: center; gap: 16px;
    transition: all var(--transition);
}
.module-card.enabled { border-color: var(--primary); background: var(--primary-soft); }
.module-icon { width: 44px; height: 44px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 18px; }
.module-info { flex: 1; }
.module-info .module-name { font-weight: 700; font-size: 14px; }
.module-info .module-desc { font-size: 12px; color: var(--text-soft); margin-top: 2px; }
.module-toggle {
    position: relative; width: 44px; height: 24px;
    border-radius: 12px; cursor: pointer;
    background: var(--border-strong); transition: background var(--transition);
}
.module-toggle.on { background: var(--primary); }
.module-toggle .toggle-knob {
    position: absolute; top: 2px; left: 2px;
    width: 20px; height: 20px; border-radius: 50%;
    background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,0.2);
    transition: left var(--transition);
}
.module-toggle.on .toggle-knob { left: 22px; }

/* ===== Settings Sidebar ===== */
.settings-layout { display: flex; gap: 0; min-height: 600px; }
.settings-sidebar {
    width: 220px; background: var(--surface-2); border-right: 1px solid var(--border);
    border-radius: var(--radius-lg) 0 0 var(--radius-lg);
    padding: 12px 8px;
}
.settings-nav-item {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px; border-radius: var(--radius);
    cursor: pointer; font-size: 13px; color: var(--text-soft);
    transition: all var(--transition); margin-bottom: 2px;
}
.settings-nav-item:hover { background: var(--surface); color: var(--text); }
.settings-nav-item.active { background: var(--surface); color: var(--primary-dark); font-weight: 600; box-shadow: var(--shadow); }
.settings-nav-item i { width: 18px; text-align: center; }
.settings-content {
    flex: 1; padding: 24px;
    border-radius: 0 var(--radius-lg) var(--radius-lg) 0;
}

/* ===== Wizard Steps ===== */
.wizard-steps {
    display: flex; align-items: center; gap: 0;
    padding: 16px 24px; background: var(--surface-2);
    border-bottom: 1px solid var(--border);
}
.wizard-step {
    display: flex; align-items: center; gap: 8px;
    font-size: 13px; color: var(--text-muted);
}
.wizard-step.active { color: var(--primary); font-weight: 600; }
.wizard-step.done { color: var(--success); }
.wizard-step .step-num {
    width: 24px; height: 24px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 11px; font-weight: 700;
    background: var(--surface-3); color: var(--text-muted);
    border: 2px solid var(--border);
}
.wizard-step.active .step-num { background: var(--primary); color: #fff; border-color: var(--primary); }
.wizard-step.done .step-num { background: var(--success); color: #fff; border-color: var(--success); }
.wizard-connector { width: 32px; height: 2px; background: var(--border); margin: 0 4px; }

/* ===== Reports Module ===== */
.report-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-lg); padding: 20px;
    cursor: pointer; transition: all var(--transition);
}
.report-card:hover {
    border-color: var(--primary); box-shadow: var(--shadow-lg);
    transform: translateY(-2px);
}

.report-table {
    width: 100%; border-collapse: collapse;
    font-size: 13px;
}
.report-table thead {
    background: var(--surface-2); border-bottom: 2px solid var(--border);
}
.report-table th {
    padding: 12px 14px; text-align: left;
    font-weight: 600; color: var(--text);
    white-space: nowrap;
}
.report-table td {
    padding: 11px 14px; border-bottom: 1px solid var(--border);
}
.report-table tbody tr:hover { background: var(--surface-2); }
.report-table tfoot tr { background: var(--surface-2); border-top: 2px solid var(--border); }
.report-table tfoot td { padding: 12px 14px; font-weight: 600; }

/* (Deleted second .stat-card rule — consolidated into the single
   canonical block above. EMS Branding Law §5.4.) */
/* Legacy aliases — keep so any stray markup using .stat-label /
   .stat-value outside a .stat-card still picks up brand styles. */
.stat-label { font-size: 11px; color: var(--text-soft); font-weight: 600; margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.3px; }
.stat-value { font-size: 26px; font-weight: 800; color: var(--text); }

/* ===== Unified Pill Tabs (V2.5 Design) ===== */
.wms-tab-bar {
    display: flex; gap: 4px; background: #f1f5f9; border-radius: 10px;
    padding: 4px; margin-bottom: 20px;
}
.wms-tab-btn {
    flex: 1; display: flex; align-items: center; justify-content: center; gap: 8px;
    padding: 10px 16px; border: none; border-radius: 8px; font-size: 13px;
    font-weight: 500; cursor: pointer; transition: all 0.15s;
    background: transparent; color: #64748b;
    white-space: nowrap;        /* keep labels on one line at all widths */
}
.wms-tab-btn:hover { background: rgba(255,255,255,0.6); color: #374151; }
.wms-tab-btn.active {
    background: #fff; color: #1e293b; font-weight: 700;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.wms-tab-btn .tab-badge {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px;
    background: #dc2626; color: #fff; font-size: 10px; font-weight: 700;
    line-height: 1;
}
.wms-tab-btn:not(.active) .tab-badge { background: #94a3b8; }
.wms-tab-content { padding: 0; min-height: 200px; }

/* ===== Audit Log ===== */
.audit-search-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
}
.audit-search-wrap i {
    position: absolute;
    left: 12px;
    color: var(--text-muted);
    font-size: 13px;
    pointer-events: none;
}
.audit-search-wrap input {
    padding: 8px 14px 8px 34px;
    border: 1.5px solid var(--border);
    border-radius: 20px;
    background: var(--surface-2);
    font-size: 13px;
    width: 260px;
    transition: border-color var(--transition), background var(--transition);
}
.audit-search-wrap input:focus {
    outline: none;
    border-color: var(--primary);
    background: var(--surface);
}
.audit-table-wrap {
    overflow-x: auto;
    max-height: 60vh;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.audit-log-table { margin: 0; font-size: 13px; }
.audit-log-table thead th {
    position: sticky;
    top: 0;
    background: #f9fafb;
    border-bottom: 2px solid #e5e7eb;
    z-index: 1;
}
.audit-log-table tbody tr:hover { background: #f9fafb; }
.audit-action-badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
    text-transform: capitalize;
}
.audit-module-tag {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    background: var(--surface-3);
    color: var(--text-soft);
    text-transform: capitalize;
}
.audit-timestamp {
    white-space: nowrap;
    font-size: 12px;
    color: var(--text-soft);
    font-variant-numeric: tabular-nums;
}
.audit-details-cell {
    font-size: 12px;
    color: var(--text-soft);
    max-width: 260px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.audit-empty-state {
    text-align: center;
    padding: 48px 24px !important;
    color: var(--text-soft);
}
.audit-pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    margin-top: 14px;
    padding: 8px 0;
}
.audit-pagination .btn[disabled] {
    opacity: 0.4;
    pointer-events: none;
}
.audit-pagination-info {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-soft);
}

/* ===== Notification Dropdown ===== */
.notification-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: 360px;
    max-height: 440px;
    overflow-y: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    z-index: 5000;
    display: none;
}
.notification-dropdown.show { display: block; }
.notification-dropdown .dropdown-header {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 700;
    font-size: 14px;
}
.notification-dropdown .dropdown-item {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background var(--transition);
    font-size: 13px;
}
.notification-dropdown .dropdown-item:hover { background: var(--surface-2); }
.notification-dropdown .dropdown-item:last-child { border-bottom: none; }
.notification-dropdown .dropdown-empty {
    padding: 24px 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}

/* ===== Mobile menu trigger (hamburger) =====
 * Hidden on desktop, shown ≤768px. Toggles the sidebar drawer
 * via window.toggleMobileSidebar() (defined in index.html). */
.mobile-menu-trigger {
    display: none;
    /* Fixed-square dimensions so the hamburger and the search trigger
     * are visually identical regardless of glyph width. */
    width: 38px; height: 38px; padding: 0;
    box-sizing: border-box;
    background: none;
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    color: var(--text);
    font-size: 16px;
    line-height: 1;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
}
.mobile-menu-trigger:hover { background: var(--surface-3); }

/* ===== Mobile search trigger + overlay =====
 * On desktop the search bar sits inline in the topbar. On mobile we
 * collapse it: a magnifier-icon button stays visible, and tapping it
 * (toggleMobileSearch in index.html) flips body.mobile-search-open which
 * slides the search field down as a full-width overlay below the topbar.
 * The existing search-results dropdown (#globalSearchDropdown, position:
 * fixed; top:52px) lines up underneath without changes. */
.mobile-search-trigger {
    display: none;
    /* Same fixed-square shape as the hamburger so they line up
     * pixel-perfect on the topbar. */
    width: 38px; height: 38px; padding: 0;
    box-sizing: border-box;
    background: none;
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    color: var(--text);
    font-size: 16px;
    line-height: 1;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
}
.mobile-search-trigger:hover { background: var(--surface-3); }
.mobile-search-close {
    display: none;       /* desktop default — invisible */
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px 8px;
    color: var(--text-soft);
    font-size: 16px;
}
.mobile-search-close:hover { color: var(--text); }
.sidebar-backdrop {
    display: none;
    position: fixed; inset: 0;
    background: rgba(9, 27, 44, 0.5);
    z-index: 999;
    animation: fadeIn 0.18s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ===== Responsive — Tablet (≤960px) ===== */
@media (max-width: 960px) {
    .stats-grid { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; }
    .topbar { padding: 0 16px; }
    .topbar-search { max-width: 320px; }
}

/* ===== Responsive — Mobile (≤768px) =====
 * EMS Branding Law §7 carve-outs allow surface-specific layout on
 * mobile. Same colours / components / typography as desktop — only
 * placement changes. The sidebar becomes an off-canvas drawer
 * triggered by the hamburger button in the topbar. */
@media (max-width: 768px) {
    /* App shell — sidebar slides off-canvas, page scrolls naturally.
     * Desktop locks the viewport (body { overflow: hidden }) and
     * only scrolls the inner .content-area, but on mobile that
     * pattern blocks all scrolling. Explicitly free body's vertical
     * overflow and collapse the nested scroll containers. */
    html { overflow-x: hidden; overflow-y: auto; }
    body { overflow-x: hidden; overflow-y: auto; }
    .app-layout { height: auto; min-height: 100vh; display: block; }
    .main-content { overflow: visible; display: block; }
    .content-area { overflow: visible; padding: 0; }
    .sidebar {
        position: fixed; top: 0; bottom: 0; left: 0;
        width: 280px; z-index: 1000;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        box-shadow: var(--shadow-lg);
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar.open + .sidebar-backdrop,
    .sidebar-backdrop.open { display: block; }

    /* Restore full nav inside the drawer (was icon-only before) */
    .sidebar .nav-item { justify-content: flex-start; padding: 11px 16px; font-size: 14px; }
    .sidebar .nav-item span, .sidebar .nav-group-label, .sidebar .logo-text { display: inline; }
    .sidebar .nav-item i { margin: 0 6px 0 0; width: 18px; }

    .main-content { width: 100%; }

    /* Topbar — show hamburger + search-trigger, hide inline search */
    .topbar { padding: 0 12px; gap: 8px; position: relative; }
    .mobile-menu-trigger { display: inline-flex; }
    .mobile-search-trigger { display: inline-flex; margin-left: auto; }
    /* Inline search bar collapsed by default on mobile; the trigger
     * button gates expansion via body.mobile-search-open. */
    .topbar-search { display: none; }
    body.mobile-search-open .topbar-search {
        display: flex;
        position: absolute;
        left: 0; right: 0; top: 100%;
        /* Override the desktop `max-width: 480px` cap and any flex
         * sizing so the white background fills the whole viewport. */
        max-width: none;
        width: auto;
        margin: 0;
        padding: 10px 12px;
        background: var(--surface);
        border-bottom: 1px solid var(--border);
        box-shadow: var(--shadow-md);
        z-index: 7900;   /* below the search-results dropdown (8000) */
        align-items: center;
        gap: 8px;
        box-sizing: border-box;
    }
    body.mobile-search-open .topbar-search input {
        flex: 1;
        font-size: 15px;
        /* 40px left padding leaves room for the magnifier inside the
         * input, and 40px right for the close button so it doesn't
         * cover typed text (FB-2). */
        padding: 10px 40px 10px 40px;
        appearance: none;
        -webkit-appearance: none;
    }
    /* Native [type="search"] X clear button overlapped the close
     * button on iOS Safari, which read like two close affordances
     * stacked left-of-input. Hide the native clear (FB-2). */
    body.mobile-search-open .topbar-search input::-webkit-search-cancel-button,
    body.mobile-search-open .topbar-search input::-webkit-search-decoration {
        -webkit-appearance: none;
        appearance: none;
        display: none;
    }
    /* Magnifier sits inside the input, anchored left (FB-2 fix —
     * it used to be drifting to left:24px which on narrow phones
     * left it floating above the close button on the left edge). */
    body.mobile-search-open .topbar-search > i {
        left: 26px;
        font-size: 14px;
        z-index: 2;
        pointer-events: none;
    }
    /* Close button moves to the RIGHT side of the search bar, where
     * users expect "dismiss" to live (FB-2 fix). */
    body.mobile-search-open .mobile-search-close {
        display: inline-flex;
        position: absolute;
        right: 16px;
        top: 50%;
        transform: translateY(-50%);
        background: var(--surface-2);
        border: 1px solid var(--border);
        border-radius: 999px;
        width: 28px;
        height: 28px;
        align-items: center;
        justify-content: center;
        color: var(--text-soft);
        cursor: pointer;
        font-size: 12px;
        z-index: 3;
    }
    /* Hide the trigger while the overlay is open (close button replaces it) */
    body.mobile-search-open .mobile-search-trigger { display: none; }

    .topbar-right { gap: 8px; }
    .topbar-right > button:first-child span,
    .topbar-right > button:first-child { padding: 6px 10px !important; }
    .topbar-user .user-name, .topbar-user .user-role { display: none; }

    /* Page sections — single content column, tighter padding */
    .section { padding: 16px !important; }
    .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
    .stat-card { padding: 12px 14px; }
    .stat-card .stat-value, .stat-card .stat-card-content p { font-size: 22px; }
    .stat-card-icon { width: 38px; height: 38px; font-size: 15px; }

    /* Form rows stack to 1 column */
    .form-row { grid-template-columns: 1fr !important; gap: 12px; }

    /* Tables get a horizontal scroll wrapper baked in */
    .tbl, .data-table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; white-space: nowrap; }
    .tbl thead, .data-table thead { white-space: nowrap; }

    /* Cards tighter on mobile */
    .card { border-radius: 10px; }
    .card-header { padding: 10px 14px; }
    .card-body { padding: 12px 14px; }

    /* Modals fill the screen on mobile (better tap targets, no horizontal squish) */
    .modal-content {
        width: 100% !important;
        max-width: 100% !important;
        max-height: 100vh !important;
        border-radius: 0 !important;
        margin: 0 !important;
    }
    .modal { padding: 0 !important; align-items: stretch !important; }

    /* Buttons keep min 44px tap target */
    .btn { min-height: 38px; }
    .btn-sm { min-height: 32px; }

    /* Tab bars (.wms-tab-bar) — on desktop each button has flex:1 so all
     * tabs share width equally. On mobile that squeezes 5-6 tabs into
     * ~360px which wraps text and breaks layout. Switch to horizontal
     * scroll: each button keeps its natural width, the tab row swipes
     * left/right with momentum scrolling. The scrollbar is hidden so it
     * looks like the iOS native pattern.
     *
     * Same treatment for .settings-sidebar-style tab rows + the legacy
     * .tabs / .tab-list containers used in older modules. */
    .wms-tab-bar,
    .settings-tab-bar,
    .tabs,
    .tab-list,
    .tab-row {
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;       /* Firefox */
    }
    .wms-tab-bar::-webkit-scrollbar,
    .settings-tab-bar::-webkit-scrollbar,
    .tabs::-webkit-scrollbar,
    .tab-list::-webkit-scrollbar,
    .tab-row::-webkit-scrollbar {
        display: none;               /* WebKit */
    }
    .wms-tab-btn {
        flex: 0 0 auto;              /* don't squish — natural width */
        padding: 10px 14px;
    }

    /* ===== Module-specific mobile fixes ===== */

    /* Settings page — internal sidebar stacks above content on mobile */
    .settings-layout { flex-direction: column; min-height: 0; }
    .settings-sidebar {
        width: 100%; border-right: none; border-bottom: 1px solid var(--border);
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        padding: 8px;
        display: flex; flex-wrap: wrap; gap: 4px;
        overflow-x: auto; -webkit-overflow-scrolling: touch;
    }
    .settings-nav-item {
        flex: 0 0 auto; padding: 8px 12px; font-size: 12px;
        white-space: nowrap;
    }
    .settings-content { padding: 16px; border-radius: 0 0 var(--radius-lg) var(--radius-lg); }

    /* Wizard (multi-step shipment / inventory create flows) — stack steps */
    .wizard-steps { padding: 10px 12px; flex-wrap: wrap; gap: 6px; }
    .wizard-step { font-size: 11px; }

    /* Any 2-column flex/grid layout in modules — stack to 1 column.
       Catches the production-run scan-vs-allocation layout, the
       inventory category/breakdown split, etc. without needing
       per-module changes. */
    .two-col-layout, .split-pane, [data-mobile-stack="true"] {
        grid-template-columns: 1fr !important;
        flex-direction: column !important;
    }

    /* Inline grids declared with style="grid-template-columns:1fr 1fr"
       need help — broader catch-all for any 2-column grid + the
       receiving + production layouts that use percentage splits
       (e.g. "60% 40%" or "2fr 1fr"). On mobile every multi-column
       grid collapses to a single column so nothing gets crushed. */
    div[style*="grid-template-columns:1fr 1fr"],
    div[style*="grid-template-columns: 1fr 1fr"],
    div[style*="grid-template-columns:repeat(2"],
    div[style*="grid-template-columns: repeat(2"],
    div[style*="grid-template-columns:60%"],
    div[style*="grid-template-columns: 60%"],
    div[style*="grid-template-columns:65%"],
    div[style*="grid-template-columns: 65%"],
    div[style*="grid-template-columns:2fr 1fr"],
    div[style*="grid-template-columns: 2fr 1fr"],
    div[style*="grid-template-columns:1fr 2fr"],
    div[style*="grid-template-columns: 1fr 2fr"],
    div[style*="grid-template-columns:3fr 2fr"],
    div[style*="grid-template-columns: 3fr 2fr"],
    div[style*="grid-template-columns:2fr 3fr"],
    div[style*="grid-template-columns: 2fr 3fr"],
    div[style*="grid-template-columns:minmax(0,1fr) minmax(0,1fr)"],
    div[style*="grid-template-columns: minmax(0,1fr) minmax(0,1fr)"],
    div[style*="grid-template-columns:minmax(0, 1fr) minmax(0, 1fr)"] {
        grid-template-columns: 1fr !important;
    }

    /* Receiving + Production scanner panels: tighten the inner controls
     * so the title row, mode buttons, scan input and lookup button all
     * fit within a phone width without clipping. The headline + Scan/
     * Multi-Select buttons end up on the same row on desktop; on mobile
     * we let them wrap naturally. */
    .section .card,
    .section [class*="receiving"],
    .section [class*="production"] {
        min-width: 0;             /* allow shrinking inside flex/grid parents */
    }
    /* Tighten any header row with a title + button group on mobile so
     * the buttons drop below the title rather than crushing it. */
    div[style*="display: flex"][style*="justify-content: space-between"][style*="align-items: center"] {
        flex-wrap: wrap;
    }
    /* Scan/Lookup row: input + button — make sure the button is fully
     * readable, never clipped. The inline `flex: 1` on the input is
     * fine; the button just needs a min-width so its label survives. */
    button[onclick*="lookupBox"],
    button[onclick*="LookupBox"] {
        min-width: 84px;
        white-space: nowrap;
    }

    /* Calendar widget — scrolls horizontally if too wide */
    .calendar-widget, [class*="calendar"] { overflow-x: auto; -webkit-overflow-scrolling: touch; }

    /* Section headers & H2 — slightly smaller on mobile */
    .section h2, h2 { font-size: 18px !important; }
    .section h3, h3 { font-size: 15px !important; }

    /* Receiving / production scan inputs — full-width on mobile so
       the operator can tap easily. */
    input[type="text"], input[type="number"], input[type="search"],
    input[type="email"], input[type="password"], input[type="date"],
    select, textarea {
        font-size: 16px;   /* prevents iOS auto-zoom on focus */
    }

    /* Single-column for tiny phones */
    @media (max-width: 420px) {
        .stats-grid { grid-template-columns: 1fr; }
        .settings-nav-item { font-size: 11px; padding: 7px 10px; }
        .topbar { gap: 6px; padding: 0 8px; }
    }
}
