/* ==========================================================================
   RORO UI — design system layer
   Loaded after style.css. Redefines the design tokens that the rest of the
   app already consumes (430+ var() references, 138 tokenised rgba channels),
   then modernises the shared components on top.

   Direction: functional logistics UI — light neutral surfaces, one restrained
   accent, no metallic gradients, no uppercase button shouting.
   Mobile-first; breakpoints layer upward.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. TOKENS
   -------------------------------------------------------------------------- */

:root {
    /* Brand — warm logistics orange. Restrained: actions + active states only. */
    --brand-50: #FFF4ED;
    --brand-100: #FFE7D6;
    --brand-200: #FFCDAC;
    --brand-300: #FFAB78;
    --brand-400: #FB8140;
    --brand-500: #F26A1B;
    --brand-600: #DC5510;
    --brand-700: #B8420C;
    --brand-800: #93370F;
    --brand-900: #762F10;
    --brand-rgb: 242, 106, 27;

    /* Neutrals — slightly warm slate */
    --n-0: #FFFFFF;
    --n-25: #FCFCFD;
    --n-50: #F7F8FA;
    --n-100: #F1F2F5;
    --n-200: #E4E6EB;
    --n-300: #CDD1D9;
    --n-400: #9BA1AE;
    --n-500: #6B7280;
    --n-600: #4B5563;
    --n-700: #343A45;
    --n-800: #1F242D;
    --n-900: #12161C;
    --n-950: #0B0E13;

    /* Semantic */
    --success: #15803D;
    --success-bg: #ECFDF3;
    --warning: #B45309;
    --warning-bg: #FFFAEB;
    --danger: #DC2626;
    --danger-bg: #FEF3F2;
    --info: #2563EB;
    --info-bg: #EFF6FF;

    /* Typography */
    --font-heading: 'Plus Jakarta Sans', 'Inter', system-ui, -apple-system, sans-serif;
    --font-body: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;

    /* Fluid type scale — clamps between mobile and desktop */
    --text-2xs: 0.6875rem;
    --text-xs: 0.75rem;
    --text-sm: 0.8125rem;
    --text-base: 0.9375rem;
    --text-md: 1rem;
    --text-lg: clamp(1.0625rem, 0.98rem + 0.4vw, 1.1875rem);
    --text-xl: clamp(1.1875rem, 1.06rem + 0.6vw, 1.4375rem);
    --text-2xl: clamp(1.375rem, 1.16rem + 1vw, 1.875rem);
    --text-3xl: clamp(1.625rem, 1.25rem + 1.8vw, 2.5rem);

    /* Spacing — 4pt grid */
    --sp-1: 4px;
    --sp-2: 8px;
    --sp-3: 12px;
    --sp-4: 16px;
    --sp-5: 20px;
    --sp-6: 24px;
    --sp-8: 32px;
    --sp-10: 40px;
    --sp-12: 48px;

    /* Radii — moderate, not pill */
    --radius-xs: 6px;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius-full: 999px;

    /* Elevation — soft and low, never the old 30px/0.5 black slab */
    --shadow-xs: 0 1px 2px rgba(16, 24, 40, 0.05);
    --shadow-sm: 0 1px 3px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.04);
    --shadow-md: 0 4px 8px -2px rgba(16, 24, 40, 0.08), 0 2px 4px -2px rgba(16, 24, 40, 0.04);
    --shadow-lg: 0 12px 16px -4px rgba(16, 24, 40, 0.08), 0 4px 6px -2px rgba(16, 24, 40, 0.03);
    --shadow-xl: 0 20px 24px -4px rgba(16, 24, 40, 0.10), 0 8px 8px -4px rgba(16, 24, 40, 0.04);

    /* Motion */
    --ease: cubic-bezier(0.2, 0, 0.2, 1);
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
    --dur-fast: 120ms;
    --dur: 200ms;
    --dur-slow: 320ms;

    /* Layout */
    --header-height: 60px;
    --nav-height: 60px;
    --sidebar-w: 248px;
    --content-max: 1200px;
    --reading-max: 760px;
    --tap-min: 44px;
    --safe-b: env(safe-area-inset-bottom, 0px);
    --safe-t: env(safe-area-inset-top, 0px);
    --safe-l: env(safe-area-inset-left, 0px);
    --safe-r: env(safe-area-inset-right, 0px);

    /* Theme ramp — the only values that differ between themes. Everything
       below derives from these, so dark mode is one block, not a second
       stylesheet. */
    --page: var(--n-50);
    --glass-rgb: 255, 255, 255;
    --accent-text: var(--brand-700);
    --accent-fill: var(--brand-700);
    --accent-soft: var(--brand-50);
    --on-accent: #FFFFFF;

    color-scheme: light;
}

/* Dark theme. Keyed on the <html> marker that the inline bootstrap sets before
   first paint — keying on `body.light-mode` would render one dark frame on
   every load, because that class is only added at DOMContentLoaded.
   A page with neither marker falls through to the light tokens above. */
html.dark-mode-active {
    --n-0: #171B22;
    --n-25: #151920;
    --n-50: #12161C;
    --n-100: #1B2029;
    --n-200: #262C37;
    --n-300: #343B48;
    --n-400: #5A6474;
    --n-500: #8A93A3;
    --n-600: #A8B0BE;
    --n-700: #C7CDD7;
    --n-800: #E2E6EC;
    --n-900: #F4F6F8;
    --n-950: #FFFFFF;

    --success: #34D399;
    --success-bg: rgba(52, 211, 153, 0.14);
    --warning: #FBBF24;
    --warning-bg: rgba(251, 191, 36, 0.14);
    --danger: #F87171;
    --danger-bg: rgba(248, 113, 113, 0.14);
    --info: #60A5FA;
    --info-bg: rgba(96, 165, 250, 0.14);

    --danger-rgb: 248, 113, 113;
    --success-rgb: 52, 211, 153;
    --warning-rgb: 251, 191, 36;
    --info-rgb: 96, 165, 250;

    /* On dark surfaces the accent has to lighten, not darken, to hold contrast.
       The ramp shades used directly for text are flipped here too, so every
       `var(--brand-700)` reference resolves correctly without a per-component
       dark override. */
    --brand-rgb: 249, 115, 22;
    --brand-700: #FF9052;
    --brand-600: #F97316;
    --brand-50: rgba(249, 115, 22, 0.14);
    --page: #0B0E13;
    --glass-rgb: 23, 27, 34;
    --accent-text: #FF9052;
    /* Vivid orange with near-black text reaches 7:1; white on it only 2.5. */
    --accent-fill: #F97316;
    --accent-soft: rgba(var(--brand-rgb), 0.14);
    --on-accent: #0B0E13;

    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 8px -2px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 12px 16px -4px rgba(0, 0, 0, 0.5);
    --shadow-xl: 0 20px 24px -4px rgba(0, 0, 0, 0.55);

    color-scheme: dark;
}

/* Semantic mappings. Theme-agnostic — every value reads from the ramp above.
   Declared at body level (and on `body.light-mode`) so they out-rank the
   legacy `body.light-mode` palette that style.css still declares. */
:root,
body,
body.light-mode {
    /* --- Compatibility: legacy names the rest of the app still consumes ---
       `--gold-base` backs 160+ inline `color:` declarations, so it must be the
       text-safe shade: brand-700 clears 4.5:1 on white and on brand-50, where
       brand-600 only reached 3.9:1. */
    --gold-base: var(--accent-text);
    /* Also a text colour in practice (25 call sites), so it gets the
       contrast-safe shade rather than the decorative brand-500. */
    --gold-highlight: var(--accent-text);
    --gold-shadow: var(--brand-800);
    --gold-gradient: linear-gradient(135deg, var(--brand-500) 0%, var(--brand-600) 100%);
    --gold-text-shine: linear-gradient(90deg, var(--brand-600), var(--brand-500));
    --gold-glow: 0 0 0 4px rgba(var(--brand-rgb), 0.12);
    --shadow-glow: var(--gold-glow);

    --primary: var(--accent-fill);
    --primary-gradient: var(--gold-gradient);
    --primary-light: var(--brand-400);

    --black-bg: var(--page);
    --black-surface: var(--n-0);
    --black-lighter: var(--n-100);

    --bg-body: var(--page);
    --bg-surface: var(--n-0);
    --bg-surface-2: var(--n-100);
    --bg-input: var(--n-0);

    --text-primary: var(--n-900);
    --text-secondary: var(--n-600);
    --text-muted: var(--n-500);
    --text-on-primary: var(--on-accent);

    --border: var(--n-200);
    --glass-bg: rgba(var(--glass-rgb), 0.86);
    --glass-border: var(--n-200);

    --select2-opt-muted: var(--n-500);
    --select2-opt-light: var(--n-700);
    --select2-opt-italic: var(--n-400);
    --select2-opt-img-bg: var(--n-100);
    --select2-opt-img-border: var(--n-200);

    /* Subtle fills — replace the old translucent-white washes that vanish on
       a light surface. */
    --surface-subtle: var(--n-50);
    --surface-muted: var(--n-100);

    /* Alpha channels for semantic tints used in inline styles */
    --danger-rgb: 220, 38, 38;
    --success-rgb: 21, 128, 61;
    --warning-rgb: 180, 83, 9;
    --info-rgb: 37, 99, 235;
}

/* --------------------------------------------------------------------------
   2. BASE
   -------------------------------------------------------------------------- */

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

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    /* Page colour is painted here rather than on body. A body background
       propagates to the canvas, which makes it awkward to reason about during
       theme swaps; <html> is the element the theme class lands on, so the
       colour and the class that selects it stay together. */
    background-color: var(--page);
}

body {
    font-family: var(--font-body);
    font-size: var(--text-base);
    line-height: 1.55;
    letter-spacing: -0.006em;
    color: var(--text-primary);
    background: transparent;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior-y: none;
    text-rendering: optimizeLegibility;
}

h1,
h2,
h3,
h4,
h5,
.greeting-title,
.section-title,
.step-title,
.hero-title,
.stat-value,
.balance-amount,
.custom-modal-title,
.modal-header-fixed h3 {
    font-family: var(--font-heading);
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.2;
    color: var(--text-primary);
}

h1,
.hero-title {
    font-size: var(--text-3xl);
    font-weight: 800;
}

h2 {
    font-size: var(--text-2xl);
}

h3 {
    font-size: var(--text-xl);
}

h4 {
    font-size: var(--text-lg);
}

/* Nothing in a functional UI should be smaller than this. */
small,
.small-text,
.text-muted,
.txn-date,
.upload-subtitle,
.step-indicator {
    font-size: var(--text-xs);
    line-height: 1.5;
}

.text-gold,
.text-primary-accent {
    color: var(--brand-700);
    background: none !important;
    -webkit-text-fill-color: currentColor !important;
}

html.dark-mode-active .text-gold {
    color: var(--brand-500);
}

/* Kill the metallic text-clip treatment app-wide — it fails contrast and
   reads as decorative rather than informational. */
.greeting-title span,
.hero-title,
.stat-value,
h1,
h2,
h3 {
    -webkit-text-fill-color: currentColor;
}

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

a:hover {
    text-decoration: underline;
}

/* --------------------------------------------------------------------------
   3. ACCESSIBILITY & MOTION
   -------------------------------------------------------------------------- */

:where(a, button, input, select, textarea, [tabindex], .nav-item, .tab-btn, .truck-card, .file-upload-zone):focus-visible {
    outline: 2px solid var(--brand-600);
    outline-offset: 2px;
    border-radius: var(--radius-xs);
}

:focus:not(:focus-visible) {
    outline: none;
}

@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* --------------------------------------------------------------------------
   4. APP SHELL — header, nav, main
   -------------------------------------------------------------------------- */

.app-header {
    height: calc(var(--header-height) + var(--safe-t));
    padding: var(--safe-t) max(var(--sp-4), var(--safe-l)) 0 max(var(--sp-4), var(--safe-r));
    background: var(--glass-bg);
    backdrop-filter: saturate(180%) blur(16px);
    -webkit-backdrop-filter: saturate(180%) blur(16px);
    border-bottom: 1px solid var(--border);
    box-shadow: none;
    gap: var(--sp-3);
}

.header-badge {
    background: var(--n-100);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    padding: 3px 10px;
    font-size: var(--text-2xs);
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: none;
}

/* --- Bottom nav (mobile) --- */
.bottom-nav {
    height: calc(var(--nav-height) + var(--safe-b));
    padding-bottom: var(--safe-b);
    background: var(--glass-bg);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border-top: 1px solid var(--border);
    box-shadow: 0 -1px 0 rgba(16, 24, 40, 0.02);
    display: flex;
    justify-content: space-around;
    align-items: stretch;
}

.nav-item {
    flex: 1 1 0;
    min-width: 0;
    min-height: var(--tap-min);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 6px 4px;
    font-family: var(--font-body);
    font-size: var(--text-2xs);
    font-weight: 600;
    letter-spacing: 0;
    text-transform: none;
    color: var(--text-muted);
    background: none;
    -webkit-text-fill-color: currentColor;
    transition: color var(--dur-fast) var(--ease);
    position: relative;
}

.nav-item i {
    font-size: 1.15rem;
    margin: 0;
    transition: transform var(--dur) var(--ease-out);
}

.nav-item span {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.nav-item.active,
.nav-item.active i,
.nav-item.active span {
    color: var(--brand-700);
    background: none;
    -webkit-text-fill-color: currentColor;
    filter: none;
    transform: none;
}

.nav-item.active i {
    transform: translateY(-1px);
}

/* Active indicator pill instead of the old lift-and-glow */
.nav-item.active::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 28px;
    height: 3px;
    border-radius: 0 0 3px 3px;
    background: var(--brand-700);
}

.nav-item:active i {
    transform: scale(0.9);
}

/* --- Main content --- */
main {
    padding: var(--sp-4) max(var(--sp-4), var(--safe-l)) calc(var(--nav-height) + var(--safe-b) + var(--sp-6)) max(var(--sp-4), var(--safe-r));
}

section,
section#section-help {
    padding: 0;
}

/* --------------------------------------------------------------------------
   5. SURFACES
   -------------------------------------------------------------------------- */

.card,
.premium-card,
.section-card,
.transaction-card,
.info-box-premium,
.user-card-premium,
.stat-card-premium,
.profile-header-card,
.wallet-balance-card,
.booking-item-card,
.setting-card,
.review-card,
.help-grid .card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: var(--sp-5);
    margin-bottom: var(--sp-4);
}

.card:hover,
.premium-card:hover {
    box-shadow: var(--shadow-md);
}

/* Cards that carry an interaction get a clearer affordance. */
.booking-item-card,
.transaction-card,
.truck-card,
.payment-method-card,
.conversation-item {
    transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease), transform var(--dur) var(--ease);
}

.booking-item-card:hover,
.transaction-card:hover,
.payment-method-card:hover {
    border-color: var(--n-300);
    box-shadow: var(--shadow-md);
    transform: none;
}

/* --------------------------------------------------------------------------
   6. BUTTONS
   Sentence case, weight 600, moderate radius. No uppercase, no letter-spacing,
   no metallic gradient, no shimmer sweep.
   -------------------------------------------------------------------------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--sp-2);
    min-height: var(--tap-min);
    padding: 11px var(--sp-5);
    /* Explicit, or variants with no background of their own fall through to the
       UA button face — which `color-scheme: dark` renders as mid grey. */
    background: transparent;
    color: inherit;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    font-family: var(--font-body);
    font-size: var(--text-base);
    font-weight: 600;
    line-height: 1.2;
    letter-spacing: 0;
    text-transform: none;
    cursor: pointer;
    transition: background-color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
    overflow: hidden;
    text-align: center;
}

.btn:active {
    transform: scale(0.985);
}

.btn:disabled,
.btn[disabled] {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.btn-primary {
    background: var(--accent-fill);
    color: var(--on-accent);
    border-color: var(--accent-fill);
    box-shadow: var(--shadow-xs);
}

.btn-primary:hover {
    background: var(--accent-fill);
    border-color: var(--accent-fill);
    filter: brightness(0.92);
    box-shadow: var(--shadow-sm);
    transform: none;
    filter: none;
}

/* Retire the shimmer sweep */
.btn-primary::after {
    display: none !important;
}

.btn-secondary {
    background: var(--bg-surface);
    color: var(--text-primary);
    border-color: var(--border);
    backdrop-filter: none;
}

.btn-secondary:hover {
    background: var(--n-50);
    border-color: var(--n-300);
    transform: none;
}

.btn-outline,
.btn-outline-gold {
    background: transparent;
    color: var(--brand-700);
    border-color: var(--brand-300);
    margin-top: 0;
}

.btn-outline-gold:hover {
    background: var(--brand-50);
    border-color: var(--brand-500);
    box-shadow: none;
    transform: none;
}

html.dark-mode-active .btn-outline-gold {
    color: var(--brand-500);
    border-color: var(--n-300);
}

html.dark-mode-active .btn-outline-gold:hover {
    background: rgba(var(--brand-rgb), 0.12);
}

.btn-success {
    background: var(--success);
    color: #fff;
    border-color: var(--success);
    box-shadow: var(--shadow-xs);
}

.btn-success:hover {
    filter: brightness(0.94);
    transform: none;
    box-shadow: var(--shadow-sm);
}

.btn-danger,
.btn-outline-danger {
    background: transparent;
    color: var(--danger);
    border-color: var(--danger);
}

.btn-danger:hover,
.btn-outline-danger:hover {
    background: var(--danger-bg);
}

.btn-white {
    background: var(--n-0);
    color: var(--n-900);
    border-color: var(--border);
    border-radius: var(--radius-md);
    font-weight: 600;
    box-shadow: var(--shadow-sm);
}

.btn-white:hover {
    background: var(--n-50);
    transform: none;
    box-shadow: var(--shadow-md);
}

.btn-block {
    width: 100%;
    margin-bottom: 0;
}

.btn-sm {
    min-height: 36px;
    padding: 7px var(--sp-3);
    font-size: var(--text-sm);
    border-radius: var(--radius-sm);
}

.btn-xs {
    min-height: 30px;
    padding: 5px 10px;
    font-size: var(--text-xs);
    border-radius: var(--radius-xs);
}

.btn-lg {
    min-height: 52px;
    padding: 14px var(--sp-6);
    font-size: var(--text-md);
}

/* Icon-only round actions keep a real tap target */
.btn-action-round,
.action-btn,
.close-modal-btn,
.map-back-btn,
.map-gps-btn-extended,
.theme-toggle {
    min-width: var(--tap-min);
    min-height: var(--tap-min);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* --------------------------------------------------------------------------
   7. FORMS
   -------------------------------------------------------------------------- */

.input-group {
    margin-bottom: var(--sp-4);
}

.input-group label,
.form-label,
.input-label,
.item-row-label {
    display: block;
    margin-bottom: 6px;
    font-family: var(--font-body);
    font-size: var(--text-sm);
    font-weight: 600;
    letter-spacing: 0;
    text-transform: none;
    color: var(--text-secondary);
}

input[type="text"],
input[type="number"],
input[type="email"],
input[type="password"],
input[type="tel"],
input[type="date"],
input[type="datetime-local"],
input[type="search"],
select,
textarea,
.form-input,
.input-field {
    width: 100%;
    min-height: var(--tap-min);
    padding: 11px var(--sp-3);
    font-family: var(--font-body);
    /* 16px stops iOS Safari zooming the viewport on focus */
    font-size: 16px;
    color: var(--text-primary);
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-xs);
    transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
    appearance: none;
    -webkit-appearance: none;
}

textarea {
    min-height: 88px;
    line-height: 1.55;
    resize: vertical;
}

input::placeholder,
textarea::placeholder {
    color: var(--n-400);
}

input:focus,
select:focus,
textarea:focus,
.form-input:focus {
    border-color: var(--brand-500);
    box-shadow: 0 0 0 3px rgba(var(--brand-rgb), 0.14);
    outline: none;
}

input[aria-invalid="true"],
.is-invalid {
    border-color: var(--danger);
    box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.12);
}

.premium-input-field {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    min-height: var(--tap-min);
    padding: 0 var(--sp-3);
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-xs);
    transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}

.premium-input-field:focus-within {
    border-color: var(--brand-500);
    box-shadow: 0 0 0 3px rgba(var(--brand-rgb), 0.14);
}

.premium-input-field input,
.premium-input-field select {
    border: none;
    box-shadow: none;
    background: transparent;
    padding-left: 0;
    padding-right: 0;
}

.premium-input-field input:focus,
.premium-input-field select:focus {
    box-shadow: none;
}

.premium-input-field>i {
    color: var(--n-400);
    font-size: 0.95rem;
    flex-shrink: 0;
}

.premium-input-field:focus-within>i {
    color: var(--brand-600);
}

/* Checkbox / radio get a real hit area */
input[type="checkbox"],
input[type="radio"] {
    min-height: 0;
    width: 20px;
    height: 20px;
    accent-color: var(--brand-600);
    box-shadow: none;
    flex-shrink: 0;
}

/* Upload zones */
.file-upload-zone {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    min-height: 64px;
    padding: var(--sp-3) var(--sp-4);
    background: var(--bg-surface);
    border: 1.5px dashed var(--n-300);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: border-color var(--dur) var(--ease), background-color var(--dur) var(--ease);
}

.file-upload-zone:hover {
    border-color: var(--brand-400);
    background: var(--brand-50);
}

.file-upload-zone.has-file,
.custom-file-upload .has-file {
    border-style: solid;
    border-color: var(--success);
    background: var(--success-bg);
}

.upload-title {
    font-weight: 600;
    font-size: var(--text-base);
}

/* --------------------------------------------------------------------------
   8. TABS, BADGES, CHIPS
   -------------------------------------------------------------------------- */

.tab-btn,
.driver-tab-btn,
.umodal-tab {
    min-height: 40px;
    padding: 8px var(--sp-4);
    border-radius: var(--radius-sm);
    font-family: var(--font-body);
    font-size: var(--text-sm);
    font-weight: 600;
    letter-spacing: 0;
    text-transform: none;
    color: var(--text-secondary);
    background: transparent;
    border: none;
    cursor: pointer;
    transition: color var(--dur-fast) var(--ease), background-color var(--dur-fast) var(--ease);
}

.tab-btn.active,
.driver-tab-btn.active,
.umodal-tab.active {
    color: var(--brand-700);
    background: var(--brand-50);
}

html.dark-mode-active .tab-btn.active,
html.dark-mode-active .driver-tab-btn.active,
html.dark-mode-active .umodal-tab.active {
    color: var(--brand-500);
    background: rgba(var(--brand-rgb), 0.14);
}

.role-badge,
.status-badge,
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 9px;
    border-radius: var(--radius-full);
    font-size: var(--text-2xs);
    font-weight: 600;
    letter-spacing: 0.01em;
    line-height: 1.4;
    white-space: nowrap;
}

.badge-success,
.status-verified {
    background: var(--success-bg);
    color: var(--success);
}

.badge-warning,
.status-pending {
    background: var(--warning-bg);
    color: var(--warning);
}

.badge-danger,
.status-declined {
    background: var(--danger-bg);
    color: var(--danger);
}

/* --------------------------------------------------------------------------
   9. MODALS — centred dialog on desktop, bottom sheet on mobile
   -------------------------------------------------------------------------- */

.modal {
    padding: 0;
    background: rgba(16, 24, 40, 0.45);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.modal-content,
.custom-modal-box,
.notification-modal-content,
.camera-modal-content {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    max-height: min(88vh, 900px);
}

.modal-header-fixed {
    padding: var(--sp-5) var(--sp-5) var(--sp-3);
    border-bottom: 1px solid var(--border);
    background: var(--bg-surface);
}

.modal-header-fixed h3 {
    font-size: var(--text-lg);
}

.modal-scrollable-body,
.modal-body-fixed {
    padding: var(--sp-5);
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

.modal-footer-fixed {
    padding: var(--sp-4) var(--sp-5) calc(var(--sp-4) + var(--safe-b));
    border-top: 1px solid var(--border);
    background: var(--bg-surface);
    gap: var(--sp-3);
}

.close-modal-btn {
    border-radius: var(--radius-full);
    background: var(--n-100);
    border: none;
    color: var(--text-secondary);
}

.close-modal-btn:hover {
    background: var(--n-200);
    color: var(--text-primary);
}

@media (max-width: 639px) {

    /* Bottom sheet: reachable with a thumb, dismissible downward */
    .modal {
        align-items: flex-end;
    }

    .modal-content,
    .custom-modal-box,
    .notification-modal-content {
        width: 100%;
        max-width: 100%;
        max-height: 92vh;
        margin: 0;
        border-radius: var(--radius-xl) var(--radius-xl) 0 0;
        border-bottom: none;
    }

    /* Grab handle */
    .modal-content::before {
        content: '';
        position: absolute;
        top: 8px;
        left: 50%;
        transform: translateX(-50%);
        width: 36px;
        height: 4px;
        border-radius: var(--radius-full);
        background: var(--n-300);
        z-index: 10;
    }

    .modal-header-fixed {
        padding-top: var(--sp-6);
    }
}

/* --------------------------------------------------------------------------
   10. TABLES — real table on desktop, stacked cards on mobile
   -------------------------------------------------------------------------- */

.premium-table-container {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.premium-table {
    width: 100%;
    border-collapse: collapse;
}

.premium-table thead tr {
    background: var(--n-50);
}

.premium-table th {
    padding: var(--sp-3) var(--sp-4);
    font-size: var(--text-xs);
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    color: var(--text-muted);
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.premium-table td {
    padding: var(--sp-4);
    font-size: var(--text-sm);
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

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

.premium-table tbody tr:hover {
    background: var(--n-50);
}

@media (max-width: 767px) {

    .premium-table,
    .premium-table thead,
    .premium-table tbody,
    .premium-table tr,
    .premium-table td {
        display: block;
        width: 100%;
    }

    .premium-table thead {
        display: none;
    }

    .premium-table tr {
        margin-bottom: var(--sp-3);
        padding: var(--sp-2) 0;
        border: 1px solid var(--border);
        border-radius: var(--radius-md);
        background: var(--bg-surface);
    }

    .premium-table td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: var(--sp-4);
        padding: 10px var(--sp-4);
        border-bottom: none;
        text-align: right;
    }

    .premium-table td::before {
        content: attr(data-label);
        flex-shrink: 0;
        font-size: var(--text-xs);
        font-weight: 600;
        color: var(--text-muted);
        text-align: left;
    }

    .premium-table td:empty {
        display: none;
    }
}

/* Anything genuinely wide scrolls inside itself rather than the page. */
.table-scroll,
.premium-table-container {
    max-width: 100%;
}

@media (min-width: 768px) {
    .premium-table-container {
        overflow-x: auto;
    }
}

/* --------------------------------------------------------------------------
   11. RESPONSIVE LAYOUT
   -------------------------------------------------------------------------- */

/* --- Tablet: 640px+ --- */
@media (min-width: 640px) {
    main {
        padding: var(--sp-5) var(--sp-6) calc(var(--nav-height) + var(--safe-b) + var(--sp-8));
    }

    .card,
    .premium-card {
        padding: var(--sp-6);
    }

    /* Two-up stat and card grids once there is room */
    .stats-grid,
    .stat-grid,
    .help-grid,
    .user-grid,
    .payment-methods-grid {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: var(--sp-4);
    }

    .stats-grid>*,
    .help-grid>*,
    .user-grid>*,
    .payment-methods-grid>* {
        margin-bottom: 0;
    }
}

/* --- Tablet portrait and up: nav stays bottom but roomier --- */
@media (min-width: 768px) and (max-width: 1023px) {
    .bottom-nav {
        justify-content: center;
        gap: var(--sp-6);
    }

    .nav-item {
        flex: 0 1 120px;
        flex-direction: row;
        gap: var(--sp-2);
        font-size: var(--text-sm);
    }

    .nav-item.active::before {
        display: none;
    }

    .nav-item.active {
        background: var(--brand-50);
        border-radius: var(--radius-md);
    }

    html.dark-mode-active .nav-item.active {
        background: rgba(var(--brand-rgb), 0.14);
    }
}

/* --- Laptop / desktop: 1024px+ — sidebar shell --- */
@media (min-width: 1024px) {
    .bottom-nav {
        top: 0;
        bottom: 0;
        left: 0;
        right: auto;
        width: var(--sidebar-w);
        height: 100vh;
        padding: calc(var(--header-height) + var(--sp-4)) var(--sp-3) var(--sp-4);
        display: flex;
        flex-direction: column;
        justify-content: flex-start;
        gap: var(--sp-1);
        background: var(--bg-surface);
        border-top: none;
        border-right: 1px solid var(--border);
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
        overflow-y: auto;
    }

    .nav-item {
        flex: 0 0 auto;
        flex-direction: row;
        justify-content: flex-start;
        gap: var(--sp-3);
        width: 100%;
        min-height: 44px;
        padding: 10px var(--sp-3);
        border-radius: var(--radius-md);
        font-size: var(--text-base);
        font-weight: 500;
        text-align: left;
    }

    .nav-item i {
        width: 22px;
        font-size: 1.05rem;
        text-align: center;
    }

    .nav-item span {
        text-overflow: ellipsis;
    }

    .nav-item:hover {
        background: var(--n-100);
        color: var(--text-primary);
    }

    .nav-item.active {
        background: var(--brand-50);
        color: var(--brand-700);
        font-weight: 600;
        border: none;
    }

    html.dark-mode-active .nav-item.active {
        background: rgba(var(--brand-rgb), 0.14);
        color: var(--brand-500);
    }

    .nav-item.active::before {
        top: 50%;
        left: 0;
        transform: translateY(-50%);
        width: 3px;
        height: 20px;
        border-radius: 0 3px 3px 0;
    }

    .app-header {
        /* `right` is required: admin.php pins the header with position:fixed,
           where width:auto would otherwise shrink-to-fit its content. */
        left: var(--sidebar-w);
        right: 0;
        width: auto;
        padding-left: var(--sp-6);
        padding-right: var(--sp-6);
    }

    main {
        margin-left: var(--sidebar-w);
        padding: calc(var(--header-height) + var(--sp-6)) var(--sp-8) var(--sp-10);
    }

    /* The single most impactful desktop fix: stop stretching mobile layout
       across 1400px. Content gets a measured column. */
    main>section,
    main>.section {
        max-width: var(--content-max);
        margin-inline: auto;
    }

    /* Reading/forms stay narrow even inside the wide column */
    .auth-form,
    .reg-step,
    .verification-box {
        max-width: var(--reading-max);
        margin-inline: auto;
    }

    .stats-grid,
    .stat-grid,
    .help-grid,
    .payment-methods-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

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

    /* Modals become proper centred dialogs */
    .modal-content {
        max-width: 640px;
    }

    .modal-content-lg {
        max-width: 900px;
    }
}

/* --- Wide desktop --- */
@media (min-width: 1440px) {
    main {
        padding-left: var(--sp-10);
        padding-right: var(--sp-10);
    }

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

/* --------------------------------------------------------------------------
   12. MOBILE ERGONOMICS
   -------------------------------------------------------------------------- */

@media (max-width: 1023px) {

    /* Scroll containers get momentum and stop chaining to the page */
    .modal-scrollable-body,
    .modal-body-scroll,
    .chat-sidebar,
    .conversation-list,
    .truck-options {
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }

    /* Horizontal rails snap instead of drifting */
    .truck-options:not(.owl-carousel) {
        display: flex;
        gap: var(--sp-3);
        overflow-x: auto;
        scroll-snap-type: x mandatory;
        scrollbar-width: none;
        padding-bottom: var(--sp-2);
    }

    .truck-options:not(.owl-carousel)::-webkit-scrollbar {
        display: none;
    }

    .truck-options:not(.owl-carousel)>* {
        scroll-snap-align: center;
        flex: 0 0 78%;
    }

    /* Sticky primary action inside multi-step flows */
    .form-actions.is-sticky,
    .step-actions.is-sticky {
        position: sticky;
        bottom: calc(var(--nav-height) + var(--safe-b));
        z-index: 20;
        margin-inline: calc(var(--sp-4) * -1);
        padding: var(--sp-3) var(--sp-4) calc(var(--sp-3) + var(--safe-b));
        background: var(--glass-bg);
        backdrop-filter: blur(12px);
        -webkit-backdrop-filter: blur(12px);
        border-top: 1px solid var(--border);
    }

    /* Stacked button rows read better than cramped side-by-side on narrow screens */
    .step-actions.d-flex .btn,
    .form-actions .btn {
        flex: 1 1 auto;
    }
}

/* --------------------------------------------------------------------------
   12b. INTENTIONALLY DARK SURFACES
   The location picker and camera overlays sit on top of a map/video feed and
   stay dark in both themes. Accent and text inside them need the on-dark
   values, or the light-mode accent drops to 3.6:1 against near-black.
   -------------------------------------------------------------------------- */

/* These panels float over map tiles / a camera feed, so they stay dark in both
   themes — the surrounding imagery, not the theme, sets the contrast context.
   The background is pinned explicitly because the tokenisation pass would
   otherwise have followed --bg-body straight to light. */
.map-top-section,
.map-bottom-section {
    background: rgba(11, 14, 19, 0.94);
    backdrop-filter: saturate(160%) blur(12px);
    -webkit-backdrop-filter: saturate(160%) blur(12px);
}

.crosshair-label {
    background: rgba(11, 14, 19, 0.88);
    color: #fff;
    padding: 4px 10px;
    border-radius: var(--radius-full);
    font-size: var(--text-xs);
}

.map-top-section,
.map-bottom-section,
.camera-modal-content .modal-header-fixed,
.selfie-viewport {
    --accent-text: #FF9052;
    --gold-base: #FF9052;
    --gold-highlight: #FF9052;
    --text-primary: #F4F6F8;
    --text-secondary: #C7CDD7;
    --text-muted: #A8B0BE;
    --border: rgba(255, 255, 255, 0.14);
    color: var(--text-primary);
}

.map-top-section .map-title,
.map-bottom-section .map-title {
    color: #fff;
    font-size: var(--text-lg);
}

.map-back-btn,
.map-gps-btn-extended {
    width: var(--tap-min);
    height: var(--tap-min);
    min-width: var(--tap-min);
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    border-radius: var(--radius-full);
}

.map-back-btn:hover,
.map-gps-btn-extended:hover {
    background: rgba(255, 255, 255, 0.22);
}

/* --------------------------------------------------------------------------
   12c. TOUCH TARGETS & LEGIBILITY FLOOR
   Nothing interactive drops below 40px, nothing readable below 12px.
   -------------------------------------------------------------------------- */

.qty-btn,
.btn-xs,
.slot-remove,
.action-btn {
    min-width: 36px;
    min-height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Standalone action links and icon buttons clear WCAG 2.5.8 (24×24). Prose
   links are left alone — an inline link inside a paragraph is exempt. */
.back-btn,
a[href^="javascript"],
a[onclick],
.btn-link {
    min-height: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--sp-1);
    background: transparent;
    border: none;
    color: var(--accent-text);
    font-weight: 600;
}

/* Not `pointer: coarse` alone — hybrid laptops and many Android browsers report
   a fine pointer while still being touched. Narrow viewport is the safer cue. */
@media (max-width: 767px),
(pointer: coarse) {

    .btn-sm,
    .btn-xs,
    .qty-btn,
    .action-btn,
    .tab-btn,
    .driver-doc-view-btn {
        min-height: 40px;
        min-width: 40px;
    }
}

.stat-label,
.truck-description,
.crosshair-label,
.header-badge,
.txn-date,
.upload-subtitle,
.capacity-info,
.truck-subtitle,
.balance-label,
.item-row-label,
.step-indicator,
.driver-doc-card-status,
.user-email-sm {
    font-size: var(--text-xs);
    letter-spacing: 0;
}

/* --------------------------------------------------------------------------
   13. EMPTY & LOADING STATES
   -------------------------------------------------------------------------- */

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--sp-3);
    padding: var(--sp-10) var(--sp-5);
    text-align: center;
    color: var(--text-muted);
}

.empty-state__icon {
    display: grid;
    place-items: center;
    width: 56px;
    height: 56px;
    border-radius: var(--radius-full);
    background: var(--n-100);
    color: var(--n-400);
    font-size: 1.4rem;
}

.empty-state__title {
    font-family: var(--font-heading);
    font-size: var(--text-lg);
    font-weight: 700;
    color: var(--text-primary);
}

.skeleton {
    position: relative;
    overflow: hidden;
    background: var(--n-100);
    border-radius: var(--radius-sm);
}

.skeleton::after {
    content: '';
    position: absolute;
    inset: 0;
    transform: translateX(-100%);
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.55), transparent);
    animation: roro-shimmer 1.4s infinite;
}

@keyframes roro-shimmer {
    100% {
        transform: translateX(100%);
    }
}

/* --------------------------------------------------------------------------
   14. INLINE-STYLE NEUTRALISERS
   The templates carry ~1,150 inline style attributes, many with colours baked
   for the old dark navy theme. These re-point the common offenders at tokens
   so the refresh is not undone element by element.
   -------------------------------------------------------------------------- */

/* `color:#fff` used to mean "primary text on a dark surface". On light
   surfaces it is invisible. Remap it — but only where the element does not
   paint its own background, and never on buttons or badges. */
[style*="color: #fff"]:not([style*="background"]):not([class*="btn"]):not([class*="badge"]),
[style*="color:#fff"]:not([style*="background"]):not([class*="btn"]):not([class*="badge"]),
[style*="color: #ffffff"]:not([style*="background"]):not([class*="btn"]):not([class*="badge"]),
[style*="color: white"]:not([style*="background"]):not([class*="btn"]):not([class*="badge"]) {
    color: var(--text-primary) !important;
}

/* …except inside something that genuinely is a coloured panel, where white
   text is still correct. */
[style*="var(--gold-gradient)"] [style*="color: #fff"],
[style*="var(--gold-gradient)"] [style*="color:#fff"],
[style*="var(--brand-"] [style*="color: #fff"],
[style*="var(--danger)"] [style*="color: #fff"],
[style*="var(--success)"] [style*="color: #fff"],
.btn [style*="color: #fff"] {
    color: #fff !important;
}

/* Translucent white text -> secondary token */
[style*="color: rgba(255,255,255"],
[style*="color:rgba(255,255,255"],
[style*="color: rgba(255, 255, 255"] {
    color: var(--text-secondary) !important;
}

[style*="var(--gold-gradient)"] [style*="color: rgba(0,0,0"],
[style*="var(--gold-gradient)"] [style*="color: rgba(0, 0, 0"] {
    color: rgba(255, 255, 255, 0.92) !important;
}

/* Inline radii/shadows tuned for the old chunky look */
[style*="box-shadow: 0 10px 20px"],
[style*="box-shadow: 0 10px 30px"],
[style*="box-shadow: 0 25px 50px"],
[style*="box-shadow: 0 20px 40px"] {
    box-shadow: var(--shadow-md) !important;
}

[style*="border-radius: 99px"],
[style*="border-radius:99px"] {
    border-radius: var(--radius-full) !important;
}
