/* ============================================================================
   CaterManage — Design System
   ----------------------------------------------------------------------------
   One stylesheet for the whole app. Every class here is a CONTRACT: the 89
   module pages under modules/ already use these names, so names must not be
   renamed or removed — only restyled.

   Theming: light only. Every colour decision goes through the tokens below, so
   the palette can be retuned in one place.
   ========================================================================== */

/* ── DESIGN TOKENS ──────────────────────────────────────────── */
:root {
    /* Brand — a single coral accent, used sparingly */
    --primary:            #F15A29;
    --primary-hover:      #DC4A1B;
    --primary-active:     #C13F16;
    --primary-light:      #FFF1EB;
    --primary-border:     #F9D2C1;
    --primary-shadow:     rgba(241, 90, 41, 0.24);
    --primary-on:         #FFFFFF;

    --secondary:          #F15A29;
    --secondary-light:    #FFF1EB;

    /* Surfaces — warm off-whites rather than cool slate */
    --bg:                 #FDFBFA;
    --surface:            #FFFFFF;
    --surface-variant:    #FBF9F8;
    --surface-hover:      #F6F3F1;
    --surface-sunken:     #F6F3F1;

    /* Text */
    --on-surface:         #24242E;
    --on-surface-muted:   #7A7A8C;
    --on-surface-subtle:  #A8A8B8;

    /* Border */
    --border:             #EFEDEB;
    --border-strong:      #DEDAD7;
    --border-focus:       #F15A29;

    /* Status */
    --success:            #2FB344;
    --success-light:      #F1FBF3;
    --success-border:     #C4EACC;
    --warning:            #F5A524;
    --warning-light:      #FFF8EC;
    --warning-border:     #FBE2B4;
    --danger:             #EF4444;
    --danger-light:       #FEF2F2;
    --danger-border:      #FBD0D0;
    --info:               #3B82F6;
    --info-light:         #F0F5FF;
    --info-border:        #C7DBFD;
    --purple:             #8B5CF6;
    --purple-light:       #F5F3FF;

    /* Sidebar */
    --sidebar-bg:         #FFFFFF;
    --sidebar-surface:    #FBF9F8;
    --sidebar-hover:      #F6F3F1;
    --sidebar-active-bg:  #FFF1EB;
    --sidebar-text:       #6B6B7B;
    --sidebar-text-dim:   #A8A8B8;
    --sidebar-active:     #F15A29;
    --sidebar-border:     #EFEDEB;
    --sidebar-width:      252px;
    --sidebar-collapsed:  76px;

    /* Layout */
    --header-height:      68px;
    --radius-sm:          8px;
    --radius:             10px;
    --radius-lg:          14px;
    --radius-xl:          18px;
    --radius-pill:        999px;

    /* Elevation — soft and layered, never heavy */
    --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.06), 0 2px 4px rgba(15, 23, 42, 0.04);
    --shadow-lg: 0 12px 28px rgba(15, 23, 42, 0.08), 0 4px 8px rgba(15, 23, 42, 0.04);
    --shadow-xl: 0 24px 48px rgba(15, 23, 42, 0.12), 0 8px 16px rgba(15, 23, 42, 0.06);

    /* Spacing scale — use these, not ad-hoc values */
    --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;

    /* Motion */
    --ease:      cubic-bezier(0.4, 0, 0.2, 1);
    --ease-out:  cubic-bezier(0.16, 1, 0.3, 1);
    --dur-fast:  120ms;
    --dur:       180ms;
    --dur-slow:  280ms;
}


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

* { margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 14px;
    line-height: 1.55;
    color: var(--on-surface);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a { color: var(--primary); text-decoration: none; transition: color var(--dur-fast) var(--ease); }
a:hover { color: var(--primary-hover); }

img, svg { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: none; cursor: pointer; }

h1, h2, h3, h4 { line-height: 1.25; letter-spacing: -0.018em; font-weight: 650; }
/* clamp(min, preferred, max) — readable at 320px, generous on desktop, no
   breakpoints needed and it survives a 200% browser zoom. */
h1 { font-size: clamp(21px, 1.15rem + 1.1vw, 30px); }
h2 { font-size: clamp(17px, 1rem + 0.55vw, 22px); line-height: 1.3; }
h3 { font-size: clamp(15px, 0.92rem + 0.3vw, 18px); line-height: 1.35; }
h4 { font-size: clamp(14px, 0.88rem + 0.2vw, 16px); line-height: 1.4; }

/* Focus — visible for keyboard users, quiet for mouse users */
:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
    border-radius: 4px;
}

::selection { background: var(--primary); color: var(--primary-on); }

/* Skip link — keyboard users reach content without tabbing the whole sidebar */
.skip-link {
    position: absolute; left: 50%; top: -60px;
    transform: translateX(-50%);
    z-index: 999;
    padding: 10px 18px;
    background: var(--primary);
    color: var(--primary-on);
    font-size: 13px; font-weight: 600;
    border-radius: 0 0 var(--radius) var(--radius);
    transition: top var(--dur) var(--ease);
}
.skip-link:focus { top: 0; color: var(--primary-on); }

/* Scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
*::-webkit-scrollbar { width: 9px; height: 9px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 999px; border: 2px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background: var(--on-surface-subtle); background-clip: content-box; }

@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;
    }
}

/* ── APP LAYOUT ─────────────────────────────────────────────── */
.app-wrapper { display: flex; min-height: 100vh; }

.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-width: 0;
    display: flex;
    flex-direction: column;
    transition: margin-left var(--dur-slow) var(--ease-out);
}
.main-content.collapsed { margin-left: var(--sidebar-collapsed); }

.page-content {
    padding: 26px 30px 48px;
    flex: 1;
    max-width: 1600px;
    width: 100%;
    animation: page-in var(--dur-slow) var(--ease-out);
}

@keyframes page-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: none; }
}

/* ── SIDEBAR ────────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    position: fixed;
    inset: 0 auto 0 0;
    display: flex;
    flex-direction: column;
    z-index: 100;
    overflow-y: auto;
    overflow-x: hidden;
    padding-bottom: 12px;
    border-right: 1px solid var(--sidebar-border);
    transition: width var(--dur-slow) var(--ease-out), transform var(--dur-slow) var(--ease-out);
}
.sidebar.collapsed { width: var(--sidebar-collapsed); }

.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border-strong); }

/* Brand */
.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px 20px 18px;
    margin-bottom: 6px;
    border-bottom: 1px solid var(--sidebar-border);
    min-height: var(--header-height);
}

/* The one place the brand colour appears in the chrome. */
.logo-icon {
    width: 36px; height: 36px;
    flex-shrink: 0;
    border-radius: 10px;
    background: var(--primary);
    display: flex; align-items: center; justify-content: center;
    font-size: 13px; font-weight: 700; letter-spacing: -0.4px;
    color: var(--primary-on);
}

.sidebar-logo-text { min-width: 0; transition: opacity var(--dur) var(--ease); }
.sidebar-logo-text h2 {
    font-size: 15px; font-weight: 700; color: var(--on-surface);
    letter-spacing: -0.02em; white-space: nowrap;
}
.sidebar-logo-text span {
    font-size: 11px; color: var(--sidebar-text-dim);
    display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.sidebar-collapse-btn {
    position: absolute; right: 14px; top: 24px;
    width: 24px; height: 24px; border-radius: 7px;
    background: var(--sidebar-surface);
    border: 1px solid var(--sidebar-border);
    color: var(--sidebar-text);
    display: flex; align-items: center; justify-content: center;
    font-size: 9px;
    transition: all var(--dur) var(--ease);
}
.sidebar-collapse-btn:hover { background: var(--surface-hover); color: var(--on-surface); border-color: var(--border-strong); }

/* Nav */
.sidebar-nav { display: block; }

.nav-section {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.09em;
    text-transform: uppercase;
    color: var(--sidebar-text-dim);
    padding: 16px 22px 7px;
    white-space: nowrap;
}

/* Each destination is its own outlined chip, as in the reference. */
.nav-item {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 10px 14px;
    margin: 5px 14px;
    border-radius: var(--radius);
    border: 1px solid var(--sidebar-border);
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    font-size: 13.5px;
    font-weight: 500;
    white-space: nowrap;
    position: relative;
    transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease),
                border-color var(--dur-fast) var(--ease), box-shadow var(--dur) var(--ease);
}
.nav-item i {
    width: 17px; flex-shrink: 0;
    font-size: 14px; text-align: center;
    color: var(--sidebar-text-dim);
    transition: color var(--dur-fast) var(--ease);
}
.nav-item:hover {
    background: var(--sidebar-surface);
    border-color: var(--border-strong);
    color: var(--on-surface);
}
.nav-item:hover i { color: var(--on-surface-muted); }

.nav-item.active {
    background: var(--sidebar-active-bg);
    border-color: var(--primary-border);
    color: var(--sidebar-active);
    font-weight: 600;
}
.nav-item.active i { color: var(--primary); }
/* Active rail, tucked inside the chip */
.nav-item.active::before {
    content: '';
    position: absolute; left: 0; top: 50%;
    transform: translateY(-50%);
    width: 3px; height: 60%;
    border-radius: 0 3px 3px 0;
    background: var(--primary);
}

.nav-label { transition: opacity var(--dur) var(--ease); }

.nav-badge {
    margin-left: auto;
    background: var(--primary-light);
    border: 1px solid var(--primary-border);
    color: var(--primary);
    font-size: 10px; font-weight: 650;
    min-width: 19px; height: 19px;
    padding: 0 6px;
    border-radius: var(--radius-pill);
    display: flex; align-items: center; justify-content: center;
}

/* Sidebar footer / user */
.sidebar-user {
    margin: auto 12px 0;
    padding: 11px 12px;
    display: flex; align-items: center; gap: 11px;
    background: var(--sidebar-surface);
    border: 1px solid var(--sidebar-border);
    border-radius: var(--radius-lg);
}
.sidebar-user .avatar {
    width: 32px; height: 32px; flex-shrink: 0;
    border-radius: 9px;
    background: var(--primary-light);
    border: 1px solid var(--primary-border);
    display: flex; align-items: center; justify-content: center;
    font-size: 12px; font-weight: 700; color: var(--primary);
}
.user-info { min-width: 0; flex: 1; }
.user-name {
    font-size: 12.5px; font-weight: 600; color: var(--on-surface);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.user-role { font-size: 11px; color: var(--sidebar-text-dim); }
.logout-link {
    color: var(--sidebar-text-dim); font-size: 13px;
    width: 28px; height: 28px; flex-shrink: 0;
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    transition: all var(--dur-fast) var(--ease);
}
.logout-link:hover { background: var(--danger); color: #fff; }

/* Collapsed state */
.sidebar.collapsed .sidebar-logo-text,
.sidebar.collapsed .nav-label,
.sidebar.collapsed .nav-section,
.sidebar.collapsed .nav-badge,
.sidebar.collapsed .user-info,
.sidebar.collapsed .logout-link { opacity: 0; width: 0; overflow: hidden; pointer-events: none; }

.sidebar.collapsed .sidebar-logo { justify-content: center; padding-left: 0; padding-right: 0; }
.sidebar.collapsed .sidebar-collapse-btn { right: 50%; transform: translateX(50%); top: 62px; }
.sidebar.collapsed .nav-item { justify-content: center; padding-left: 0; padding-right: 0; margin-inline: 10px; }
.sidebar.collapsed .nav-section { padding-block: 8px; height: 1px; margin: 8px 18px; background: var(--sidebar-border); }
.sidebar.collapsed .sidebar-user { justify-content: center; padding-inline: 0; }

/* Collapsed tooltips */
.sidebar.collapsed .nav-item::after {
    content: attr(data-tooltip);
    position: absolute; left: calc(100% + 12px); top: 50%;
    transform: translateY(-50%) scale(0.94);
    background: var(--on-surface);
    color: var(--surface);
    border: 1px solid var(--on-surface);
    padding: 6px 11px;
    border-radius: 8px;
    font-size: 12px; font-weight: 500;
    white-space: nowrap;
    opacity: 0; pointer-events: none;
    box-shadow: var(--shadow-lg);
    transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease-out);
    z-index: 200;
}
.sidebar.collapsed .nav-item:hover::after { opacity: 1; transform: translateY(-50%) scale(1); }

/* Mobile drawer scrim */
.sidebar-overlay {
    position: fixed; inset: 0;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(2px);
    z-index: 99;
    opacity: 0; pointer-events: none;
    transition: opacity var(--dur) var(--ease);
}
.sidebar-overlay.active { opacity: 1; pointer-events: auto; }

/* ── TOP HEADER ─────────────────────────────────────────────── */
.top-header {
    height: var(--header-height);
    background: var(--surface);                                    /* fallback */
    background: color-mix(in srgb, var(--surface) 82%, transparent);
    backdrop-filter: saturate(180%) blur(14px);
    -webkit-backdrop-filter: saturate(180%) blur(14px);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 0 30px;
    position: sticky; top: 0;
    z-index: 60;
}

.page-title {
    font-size: clamp(14px, 0.85rem + 0.35vw, 18px);
    font-weight: 650;
    letter-spacing: -0.02em;
    color: var(--on-surface);
    line-height: 1.2;
}

.breadcrumb {
    display: flex; align-items: center; gap: 7px;
    font-size: 12px; color: var(--on-surface-muted);
    margin-top: 2px;
}
.breadcrumb a { color: var(--on-surface-muted); font-weight: 500; }
.breadcrumb a:hover { color: var(--primary); }
.breadcrumb .sep { color: var(--on-surface-subtle); font-size: 8px; display: inline-flex; }
.breadcrumb .current { color: var(--on-surface); font-weight: 600; }

.header-titles { min-width: 0; }
.header-actions { margin-left: auto; display: flex; align-items: center; gap: 9px; }

#mobile-toggle { border: none; background: transparent; }

.toast-close {
    background: none; border: none; cursor: pointer;
    color: var(--on-surface-subtle);
    font-size: 13px; margin-left: 6px; padding: 2px;
    border-radius: 5px; line-height: 1;
    transition: color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.toast-close:hover { color: var(--on-surface); background: var(--surface-hover); }

.icon-btn {
    width: 37px; height: 37px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--on-surface-muted);
    display: flex; align-items: center; justify-content: center;
    font-size: 14px;
    position: relative;
    text-decoration: none;
    transition: all var(--dur) var(--ease);
}
.icon-btn:hover {
    border-color: var(--border-strong);
    color: var(--on-surface);
    background: var(--surface-hover);
}
.icon-btn:active { transform: translateY(1px); }

.notif-badge {
    position: absolute; top: -5px; right: -5px;
    background: var(--danger);
    color: #fff;
    font-size: 9px; font-weight: 700;
    min-width: 17px; height: 17px;
    padding: 0 4px;
    border-radius: var(--radius-pill);
    display: flex; align-items: center; justify-content: center;
    border: 2px solid var(--surface);
}

/* ── DROPDOWNS (notifications + user menu) ──────────────────── */
.dropdown-wrapper { position: relative; }

.notif-dropdown-content,
.user-dropdown-content {
    position: absolute; right: 0; top: calc(100% + 10px);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    z-index: 200;
    display: none;
    overflow: hidden;
    transform-origin: top right;
}
.notif-dropdown-content { width: 356px; }
.user-dropdown-content { width: 232px; }

.notif-dropdown-content.show,
.user-dropdown-content.show {
    display: block;
    animation: dropdown-in var(--dur) var(--ease-out);
}

@keyframes dropdown-in {
    from { opacity: 0; transform: translateY(-6px) scale(0.97); }
    to   { opacity: 1; transform: none; }
}

.notif-dropdown-header {
    padding: 13px 16px;
    border-bottom: 1px solid var(--border);
    display: flex; justify-content: space-between; align-items: center;
    font-weight: 650; font-size: 13px;
    color: var(--on-surface);
}
.notif-dropdown-header a { font-size: 12px; color: var(--primary); font-weight: 600; }

.notif-dropdown-body { max-height: 396px; overflow-y: auto; }

.notif-drop-item {
    display: flex; gap: 12px;
    padding: 13px 16px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background var(--dur-fast) var(--ease);
}
.notif-drop-item:hover { background: var(--surface-hover); }
.notif-drop-item:last-child { border-bottom: none; }

.notif-drop-icon {
    width: 34px; height: 34px; flex-shrink: 0;
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 13px;
}
.notif-drop-icon {
    background: var(--surface-hover);
    border: 1px solid var(--border);
    color: var(--on-surface-muted);
}
.notif-drop-icon.primary { color: var(--success); }
.notif-drop-icon.warning { color: var(--warning); }
.notif-drop-icon.danger  { color: var(--danger); }
.notif-drop-icon.info    { color: var(--info); }
.notif-drop-icon.muted   { color: var(--on-surface-subtle); }

.notif-drop-content { flex: 1; min-width: 0; }
.notif-drop-title { font-size: 13px; font-weight: 600; color: var(--on-surface); margin-bottom: 2px; }
.notif-drop-msg {
    font-size: 12px; color: var(--on-surface-muted); line-height: 1.45;
    display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2;
    -webkit-box-orient: vertical; overflow: hidden;
}
.notif-drop-time { font-size: 11px; color: var(--on-surface-subtle); margin-top: 4px; }

/* User chip */
.user-chip {
    display: flex; align-items: center; gap: 9px;
    padding: 4px 12px 4px 4px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    cursor: pointer;
    font-family: inherit;
    transition: all var(--dur) var(--ease);
}
.user-chip:hover { border-color: var(--border-strong); background: var(--surface-hover); }
.user-chip .chip-avatar {
    width: 27px; height: 27px; flex-shrink: 0;
    border-radius: 50%;
    background: var(--surface-hover);
    border: 1px solid var(--border);
    display: flex; align-items: center; justify-content: center;
    font-size: 11px; font-weight: 650; color: var(--on-surface-muted);
}
.user-chip span { font-size: 12.5px; font-weight: 550; color: var(--on-surface); }
.user-chip i { font-size: 9px; color: var(--on-surface-subtle); transition: transform var(--dur) var(--ease); }
.user-chip[aria-expanded="true"] i { transform: rotate(180deg); }

.user-dropdown-header { padding: 13px 15px; border-bottom: 1px solid var(--border); }
.user-dropdown-name { font-size: 13px; font-weight: 650; color: var(--on-surface); }
.user-dropdown-meta { font-size: 11px; color: var(--on-surface-subtle); margin-top: 2px; }

.user-dropdown-item {
    display: flex; align-items: center; gap: 11px;
    padding: 10px 15px;
    font-size: 13px; font-weight: 500;
    color: var(--on-surface);
    transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.user-dropdown-item:hover { background: var(--surface-hover); color: var(--on-surface); }
.user-dropdown-item i { width: 15px; font-size: 12px; color: var(--on-surface-subtle); }
.user-dropdown-item.danger { color: var(--danger); border-top: 1px solid var(--border); }
.user-dropdown-item.danger i { color: var(--danger); }
.user-dropdown-item.danger:hover { background: var(--danger-light); color: var(--danger); }

/* ── TOAST / FLASH ──────────────────────────────────────────── */
.toast-container {
    position: fixed; top: 82px; right: 26px;
    z-index: 400;
    display: flex; flex-direction: column; gap: 10px;
}

.toast {
    display: flex; align-items: flex-start; gap: 11px;
    min-width: 306px; max-width: 430px;
    padding: 13px 15px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 3px solid var(--on-surface-subtle);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    animation: toast-in var(--dur-slow) var(--ease-out);
}
@keyframes toast-in {
    from { opacity: 0; transform: translateX(28px) scale(0.97); }
    to   { opacity: 1; transform: none; }
}

.toast-icon { font-size: 15px; margin-top: 1px; flex-shrink: 0; }
.toast-body { flex: 1; font-size: 13px; line-height: 1.5; color: var(--on-surface); }

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

/* ── PAGE HEADER ────────────────────────────────────────────── */
.page-header {
    display: flex; align-items: flex-start; justify-content: space-between;
    gap: 16px; flex-wrap: wrap;
    margin-bottom: 22px;
}
/* Direct h1 too — a few older pages (users/) don't wrap it in .page-header-left */
.page-header-left h1,
.page-header > h1 {
    font-size: clamp(19px, 1.05rem + 0.85vw, 26px); font-weight: 680;
    letter-spacing: -0.028em;
    color: var(--on-surface);
}
.page-header-left .sub {
    font-size: 13px; color: var(--on-surface-muted); margin-top: 3px;
}
.page-header-actions { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }

/* ── CARDS ──────────────────────────────────────────────────── */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xs);
    overflow: hidden;
    transition: box-shadow var(--dur) var(--ease), border-color var(--dur) var(--ease), transform var(--dur) var(--ease);
}

.card-header {
    padding: 15px 18px;
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.card-title {
    font-size: 14px; font-weight: 650;
    color: var(--on-surface);
    display: flex; align-items: center; gap: 9px;
    letter-spacing: -0.01em;
}
.card-title i { color: var(--on-surface-subtle); font-size: 13px; }
.card-subtitle { font-size: 12px; color: var(--on-surface-muted); margin-top: 2px; }
.card-body { padding: 18px; }

/* Clickable card (reports hub) */
.card-link {
    display: block;
    position: relative;
    color: var(--on-surface);
}
.card-link:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--border-strong);
    color: var(--on-surface);
}
.card-link:hover h3 { color: var(--primary); }
.card-link h3 { transition: color var(--dur) var(--ease); }
.card-link i { color: var(--on-surface-muted) !important; transition: color var(--dur) var(--ease); }
.card-link:hover i { color: var(--primary) !important; }

/* Form card — the surface every add/edit page sits on */
.form-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xs);
    padding: 24px;
}

/* ── STAT CARDS ─────────────────────────────────────────────── */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(212px, 1fr));
    gap: 15px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 18px;
    box-shadow: var(--shadow-xs);
    position: relative;
    overflow: hidden;
    transition: transform var(--dur) var(--ease-out), box-shadow var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--border-strong);
}

.stat-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }

.stat-value {
    font-size: clamp(20px, 1.1rem + 0.9vw, 27px); font-weight: 700;
    letter-spacing: -0.035em;
    color: var(--on-surface);
    line-height: 1.15;
}
.stat-label {
    font-size: 12px; font-weight: 500;
    color: var(--on-surface-muted);
    margin-top: 4px;
}

.stat-icon {
    width: 38px; height: 38px; flex-shrink: 0;
    border-radius: 10px;
    background: var(--surface-hover);
    border: 1px solid var(--border);
    color: var(--on-surface-muted);
    display: flex; align-items: center; justify-content: center;
    font-size: 14px;
    transition: color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.stat-card:hover .stat-icon { color: var(--on-surface); border-color: var(--border-strong); }

/* Semantic variants. The dashboard passes colour words via $k['cls']
   (green/orange/blue/red); other pages use the semantic names. Both are mapped.
   Kept neutral: meaning lives in the label, so only the glyph takes a tint. */
.stat-card.green  .stat-icon,
.stat-card.success .stat-icon { color: var(--success); }
.stat-card.orange .stat-icon,
.stat-card.warning .stat-icon { color: var(--primary); }
.stat-card.red    .stat-icon,
.stat-card.danger .stat-icon  { color: var(--danger); }
.stat-card.blue   .stat-icon,
.stat-card.info   .stat-icon  { color: var(--info); }
.stat-card.purple .stat-icon  { color: var(--on-surface-muted); }

/* ── TABLES ─────────────────────────────────────────────────── */
.table-wrapper {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xs);
    overflow: hidden;
}

.table-toolbar {
    padding: 13px 16px;
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: 9px; flex-wrap: wrap;
    background: var(--surface-variant);
}

.data-table, table.table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 13px;
}

.data-table thead th, table.table thead th {
    position: sticky; top: 0; z-index: 2;
    background: var(--surface-variant);
    text-align: left;
    padding: 11px 16px;
    font-size: 11px;
    font-weight: 650;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--on-surface-muted);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.data-table tbody td, table.table tbody td {
    padding: 13px 16px;
    border-bottom: 1px solid var(--border);
    color: var(--on-surface);
    vertical-align: middle;
}
.data-table tbody tr:last-child td, table.table tbody tr:last-child td { border-bottom: none; }

.data-table tbody tr, table.table tbody tr { transition: background var(--dur-fast) var(--ease); }
.data-table tbody tr:hover, table.table tbody tr:hover { background: var(--surface-hover); }

/* Detail tables (view.php pages) use .data-table without a thead */
.card > .data-table tbody tr:hover { background: transparent; }

.table-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px; flex-wrap: wrap;
    font-size: 12px;
    color: var(--on-surface-muted);
    background: var(--surface-variant);
}

/* Pagination */
.pagination { display: flex; align-items: center; gap: 5px; }
.page-btn {
    min-width: 32px; height: 32px;
    padding: 0 9px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--on-surface-muted);
    font-size: 12.5px; font-weight: 550;
    display: inline-flex; align-items: center; justify-content: center;
    transition: all var(--dur-fast) var(--ease);
}
.page-btn:hover { border-color: var(--border-strong); color: var(--on-surface); background: var(--surface-hover); }
.page-btn.active {
    background: var(--on-surface); border-color: var(--on-surface);
    color: var(--surface); font-weight: 650;
}
.page-btn.disabled { opacity: 0.4; pointer-events: none; }

/* ── FORMS ──────────────────────────────────────────────────── */
.form-group { margin-bottom: 17px; flex: 1; min-width: 0; }

.form-label {
    display: block;
    font-size: 12.5px; font-weight: 600;
    color: var(--on-surface);
    margin-bottom: 6px;
    letter-spacing: -0.005em;
}
.form-label .req { color: var(--danger); margin-left: 2px; }

.form-control {
    width: 100%;
    padding: 9px 12px;
    font-size: 13.5px;
    color: var(--on-surface);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
    appearance: none;
}
.form-control::placeholder { color: var(--on-surface-subtle); }
.form-control:hover:not(:focus):not(:disabled) { border-color: var(--border-strong); }
.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}
.form-control:disabled, .form-control[readonly] {
    background: var(--surface-sunken);
    color: var(--on-surface-muted);
    cursor: not-allowed;
}
.form-control:user-invalid { border-color: var(--danger); }
.form-control:user-invalid:focus { box-shadow: 0 0 0 3px var(--danger-light); }

textarea.form-control { resize: vertical; min-height: 72px; line-height: 1.55; }

/* Native select + date affordances */
select.form-control {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748B' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 11px center;
    padding-right: 32px;
    cursor: pointer;
}
input[type="date"], input[type="time"] { cursor: pointer; }

.form-row { display: flex; gap: 15px; flex-wrap: wrap; }
.form-row > .form-group { flex: 1 1 220px; }
.form-row-3 { display: flex; gap: 15px; flex-wrap: wrap; }
.form-row-3 > .form-group { flex: 1 1 180px; }

.form-hint { font-size: 11.5px; color: var(--on-surface-subtle); margin-top: 5px; }

.form-actions {
    display: flex; align-items: center; justify-content: flex-end;
    gap: 10px;
    margin-top: 24px;
    padding-top: 19px;
    border-top: 1px solid var(--border);
}

.input-prefix {
    position: absolute; left: 13px; top: 50%;
    transform: translateY(-50%);
    color: var(--on-surface-subtle);
    font-size: 13px;
    pointer-events: none;
}

input[type="checkbox"], input[type="radio"] { accent-color: var(--primary); cursor: pointer; }

/* Bare search form (users/) — inputs there carry no .form-control class */
.search-form { display: flex; gap: 9px; flex-wrap: wrap; margin-bottom: 17px; }
.search-form input[type="text"] {
    flex: 1 1 240px; max-width: 340px;
    padding: 9px 12px;
    font-size: 13.5px;
    color: var(--on-surface);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.search-form input[type="text"]::placeholder { color: var(--on-surface-subtle); }
.search-form input[type="text"]:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

/* ── BUTTONS ────────────────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    gap: 7px;
    padding: 9px 15px;
    font-size: 13px; font-weight: 600;
    font-family: inherit;
    line-height: 1.2;
    border-radius: var(--radius);
    border: 1px solid transparent;
    cursor: pointer;
    white-space: nowrap;
    text-decoration: none;
    position: relative;
    overflow: hidden;
    transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease),
                color var(--dur-fast) var(--ease), box-shadow var(--dur) var(--ease), transform var(--dur-fast) var(--ease);
}
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn.disabled { opacity: 0.55; pointer-events: none; }
.btn i { font-size: 12px; }

/* Ripple */
.btn::after {
    content: '';
    position: absolute; left: 50%; top: 50%;
    width: 0; height: 0;
    border-radius: 50%;
    background: currentColor;
    opacity: 0.22;
    transform: translate(-50%, -50%);
    pointer-events: none;
}
.btn.is-rippling::after { animation: ripple 480ms var(--ease-out); }
@keyframes ripple {
    from { width: 0; height: 0; opacity: 0.24; }
    to   { width: 240px; height: 240px; opacity: 0; }
}

.btn-primary {
    background: var(--primary);
    color: var(--primary-on);
    box-shadow: 0 1px 2px rgba(15,23,42,0.08);
}
.btn-primary:hover { background: var(--primary-hover); box-shadow: var(--shadow-md); transform: translateY(-1px); color: var(--primary-on); }
.btn-primary:active { background: var(--primary-active); transform: translateY(0); }

/* Secondary is a neutral solid, not a second brand colour. */
.btn-secondary { background: var(--on-surface); color: var(--surface); }
.btn-secondary:hover { background: var(--on-surface-muted); color: var(--surface); }

.btn-outline {
    background: var(--surface);
    border-color: var(--border);
    color: var(--on-surface);
}
.btn-outline:hover {
    border-color: var(--border-strong);
    color: var(--on-surface);
    background: var(--surface-hover);
}

.btn-ghost { background: transparent; color: var(--on-surface-muted); }
.btn-ghost:hover { background: var(--surface-hover); color: var(--on-surface); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #DC2626; box-shadow: 0 4px 14px rgba(239,68,68,0.3); transform: translateY(-1px); color: #fff; }

.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #16A34A; box-shadow: 0 4px 14px rgba(34,197,94,0.3); transform: translateY(-1px); color: #fff; }

.btn-info { background: var(--info); color: #fff; }
.btn-info:hover { background: #0284C7; transform: translateY(-1px); color: #fff; }

.btn-sm { padding: 6px 11px; font-size: 12px; border-radius: var(--radius-sm); }
.btn-sm i { font-size: 11px; }

.btn-icon { padding: 0; width: 31px; height: 31px; flex-shrink: 0; }
.btn-icon.btn-sm { width: 28px; height: 28px; }

.btn-ghost.text-danger:hover { background: var(--danger-light); color: var(--danger); }

/* Loading state — add class="is-loading" */
.btn.is-loading { color: transparent !important; pointer-events: none; }
.btn.is-loading::before {
    content: '';
    position: absolute; left: 50%; top: 50%;
    width: 14px; height: 14px;
    margin: -7px 0 0 -7px;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    color: var(--primary-on);
    animation: spin 620ms linear infinite;
}
.btn-outline.is-loading::before, .btn-ghost.is-loading::before { color: var(--primary); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── BADGES ─────────────────────────────────────────────────── */
/* Quiet outline + a small status dot. The dot carries the meaning, so the badge
   itself stays neutral and a table full of them doesn't turn into confetti. */
.badge-pill, .badge {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 3px 10px 3px 8px;
    font-size: 11px; font-weight: 600;
    line-height: 1.5;
    border-radius: var(--radius-pill);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--on-surface-muted);
    white-space: nowrap;
}
.badge-pill::before, .badge::before {
    content: '';
    width: 6px; height: 6px;
    border-radius: 50%;
    flex-shrink: 0;
    background: var(--on-surface-subtle);
}
.badge-success::before { background: var(--success); }
.badge-danger::before  { background: var(--danger); }
.badge-warning::before { background: var(--warning); }
.badge-info::before    { background: var(--info); }
.badge-primary::before { background: var(--primary); }
.badge-muted::before   { background: var(--on-surface-subtle); }

/* Slightly darker text on the states that matter most to read quickly. */
.badge-danger, .badge-warning { color: var(--on-surface); }

/* ── ALERTS ─────────────────────────────────────────────────── */
.alert {
    display: flex; align-items: flex-start; gap: 11px;
    padding: 13px 15px;
    border-radius: var(--radius-lg);
    border: 1px solid transparent;
    font-size: 13px;
    line-height: 1.55;
    margin-bottom: 17px;
}
/* Neutral surface; only the icon and the left rule carry the state colour. */
.alert {
    background: var(--surface);
    border-color: var(--border);
    border-left: 3px solid var(--on-surface-subtle);
    color: var(--on-surface);
}
.alert i { font-size: 15px; margin-top: 1px; flex-shrink: 0; color: var(--on-surface-subtle); }
.alert-success { border-left-color: var(--success); }
.alert-success i { color: var(--success); }
.alert-danger  { border-left-color: var(--danger); }
.alert-danger i { color: var(--danger); }
.alert-warning { border-left-color: var(--warning); }
.alert-warning i { color: var(--warning); }
.alert-info    { border-left-color: var(--info); }
.alert-info i { color: var(--info); }

/* ── MODALS ─────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(3px);
    z-index: 500;
    display: none;
    align-items: center; justify-content: center;
    padding: 20px;
}
.modal-overlay.active { display: flex; animation: fade-in var(--dur) var(--ease); }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    width: 100%; max-width: 520px;
    max-height: 90vh;
    overflow-y: auto;
    animation: modal-in var(--dur-slow) var(--ease-out);
}
@keyframes modal-in {
    from { opacity: 0; transform: translateY(16px) scale(0.97); }
    to   { opacity: 1; transform: none; }
}
.modal-header {
    padding: 17px 20px;
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    font-weight: 650;
}
.modal-body { padding: 20px; }
.modal-footer {
    padding: 15px 20px;
    border-top: 1px solid var(--border);
    display: flex; justify-content: flex-end; gap: 10px;
}

/* ── TABS ───────────────────────────────────────────────────── */
.tabs {
    display: flex; gap: 3px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 20px;
}
[data-tab-target] {
    padding: 9px 15px;
    font-size: 13px; font-weight: 600;
    color: var(--on-surface-muted);
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    cursor: pointer;
    transition: color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
[data-tab-target]:hover { color: var(--on-surface); }
[data-tab-target].active { color: var(--primary); border-bottom-color: var(--primary); }

/* ── EMPTY STATE ────────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 52px 22px;
}
.empty-icon {
    font-size: 34px;
    color: var(--on-surface-subtle);
    opacity: 0.55;
    margin-bottom: 14px;
    display: block;
}
.empty-state h3 {
    font-size: 15px; font-weight: 650;
    color: var(--on-surface);
    margin-bottom: 5px;
}
.empty-state p { font-size: 13px; color: var(--on-surface-muted); max-width: 380px; margin: 0 auto; }

/* ── LOADING SKELETON ───────────────────────────────────────── */
.skeleton {
    background: linear-gradient(90deg, var(--surface-hover) 25%, var(--surface-variant) 37%, var(--surface-hover) 63%);
    background-size: 400% 100%;
    animation: shimmer 1.3s ease-in-out infinite;
    border-radius: var(--radius-sm);
    color: transparent !important;
    user-select: none;
}
@keyframes shimmer { from { background-position: 100% 50%; } to { background-position: 0 50%; } }

/* ── GRIDS & UTILITIES ──────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 17px; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 17px; }
.grid-4 { display: grid; grid-template-columns: repeat(auto-fit, minmax(205px, 1fr)); gap: 15px; }
.row    { display: flex; flex-wrap: wrap; gap: 15px; }
.col-md-6 { flex: 1 1 300px; min-width: 0; }

.d-flex   { display: flex; }
.d-inline { display: inline-block; }
.justify-end { justify-content: flex-end; }
.align-center { align-items: center; }

.gap-1 { gap: 5px; }
.gap-2 { gap: 9px; }
.gap-3 { gap: 13px; }
.gap-4 { gap: 17px; }

.mb-2 { margin-bottom: 9px; }
.mb-3 { margin-bottom: 15px; }
.mb-4 { margin-bottom: 22px; }
.mt-3 { margin-top: 15px; }
.mt-4 { margin-top: 22px; }

.text-right  { text-align: right; }
.text-center { text-align: center; }
.text-nowrap { white-space: nowrap; }

.text-primary { color: var(--primary); }
.text-accent  { color: var(--primary); }
.text-success { color: var(--success); }
.text-danger  { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-muted   { color: var(--on-surface-muted); }

.fw-600 { font-weight: 650; }


/* ── CHARTS: fluid height, never overflowing their card ─────── */
.chart-box { position: relative; width: 100%; height: clamp(200px, 26vw, 260px); }
.chart-box > canvas { position: absolute; inset: 0; width: 100% !important; height: 100% !important; }
@media (max-width: 768px) { .chart-box { height: 220px; } }
@media (max-width: 375px) { .chart-box { height: 190px; } }

/* ── RESPONSIVE ──────────────────────────────────────────────
   Breakpoints
     ≤375   mobile small      ≤480   mobile large
     ≤768   tablet portrait   ≤1024  tablet landscape
     ≤1440  laptop            ≥1441  desktop

   Sidebar behaviour by size:
     ≥1025  permanent, expanded (user may collapse)
     769–1024  permanent but collapsed to an icon rail
     ≤768   off-canvas drawer behind the hamburger
   ────────────────────────────────────────────────────────── */

/* Nothing may push the page sideways. */
html, body { max-width: 100%; overflow-x: hidden; }
.page-content, .main-content, .app-wrapper { min-width: 0; }
img, video, canvas, svg, table { max-width: 100%; }

/* Long unbroken strings (emails, URLs, notes) wrap instead of overflowing. */
.data-table td, table.table td, .card-body, .empty-state p,
.notif-drop-msg, .user-dropdown-name, .toast-body { overflow-wrap: anywhere; }

/* ── Desktop ≥1441 ─────────────────────────────────────────── */
@media (min-width: 1441px) {
    .stat-grid { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
    .grid-4    { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
}

/* ── Laptop ≤1440: four stat cards ─────────────────────────── */
@media (max-width: 1440px) {
    .stat-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .grid-4    { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (max-width: 1200px) {
    .page-content { padding: 22px 22px 40px; }
    .top-header   { padding: 0 22px; }
}

/* ── Tablet landscape ≤1024: sidebar collapses to an icon rail ─ */
@media (max-width: 1024px) {
    .sidebar     { width: var(--sidebar-collapsed); }
    .main-content { margin-left: var(--sidebar-collapsed); }

    /* Mirror the .collapsed presentation without needing the class. */
    .sidebar .sidebar-logo-text,
    .sidebar .nav-label,
    .sidebar .nav-badge,
    .sidebar .user-info,
    .sidebar .logout-link { opacity: 0; width: 0; overflow: hidden; pointer-events: none; }
    .sidebar .sidebar-logo  { justify-content: center; padding-inline: 0; }
    .sidebar .nav-item      { justify-content: center; padding-inline: 0; margin-inline: 10px; }
    .sidebar .sidebar-user  { justify-content: center; padding-inline: 0; }
    .sidebar .nav-section   { padding-block: 8px; height: 1px; margin: 8px 18px; background: var(--sidebar-border); overflow: hidden; }
    .sidebar-collapse-btn   { display: none; }
    .sidebar .nav-item::after {
        content: attr(data-tooltip);
        position: absolute; left: calc(100% + 12px); top: 50%;
        transform: translateY(-50%) scale(0.94);
        background: var(--on-surface); color: var(--surface);
        padding: 6px 11px; border-radius: 8px;
        font-size: 12px; font-weight: 500; white-space: nowrap;
        opacity: 0; pointer-events: none; box-shadow: var(--shadow-lg);
        transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease-out);
        z-index: 200;
    }
    .sidebar .nav-item:hover::after { opacity: 1; transform: translateY(-50%) scale(1); }

    .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid-2, .grid-3, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .order-grid { grid-template-columns: 1fr; }
    .order-aside { position: static; max-height: none; overflow: visible; }
}

@media (min-width: 769px) {
    #mobile-toggle { display: none !important; }
}

/* ── Tablet portrait ≤768: drawer, single column, stacked tables ─ */
@media (max-width: 768px) {
    .sidebar {
        width: var(--sidebar-width);
        transform: translateX(-100%);
        box-shadow: var(--shadow-xl);
    }
    .sidebar.open { transform: translateX(0); }
    .main-content, .main-content.collapsed { margin-left: 0; }
    #mobile-toggle { display: flex !important; }

    /* The drawer is always fully expanded — undo every collapsed/rail rule. */
    .sidebar .sidebar-logo-text,
    .sidebar .nav-label,
    .sidebar .nav-badge,
    .sidebar .user-info,
    .sidebar .logout-link { opacity: 1; width: auto; overflow: visible; pointer-events: auto; }
    .sidebar .sidebar-logo { justify-content: flex-start; padding: 20px; }
    .sidebar .nav-item     { justify-content: flex-start; padding: 10px 14px; margin-inline: 14px; }
    .sidebar .sidebar-user { justify-content: flex-start; padding-inline: 12px; }
    .sidebar .nav-section  {
        height: auto; background: none; margin: 0; overflow: visible;
        padding: 16px 22px 7px; opacity: 1; width: auto;
    }
    .sidebar .nav-item::after { display: none; }

    .page-content { padding: 18px 16px 36px; }
    .top-header   { padding: 0 16px; gap: 10px; }
    .page-header  { flex-direction: column; align-items: stretch; }
    .page-header-actions { width: 100%; }
    .page-header-actions .btn { flex: 1 1 auto; }
    .stat-grid, .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
    .row > .col-md-6 { flex: 1 1 100%; }
    .form-row, .form-row-3 { flex-direction: column; gap: 0; }
    .user-chip span { display: none; }
    .notif-dropdown-content, .user-dropdown-content { width: calc(100vw - 32px); }
    .menu-toolbar .btn { flex: 1 1 auto; }
    .mcat.open .mcat-body { grid-template-columns: 1fr; }

    /* Anything the module pages sized inline must still fit the viewport. */
    [style*="max-width"] { max-width: 100% !important; }
    .form-row > *, .form-row-3 > *, .table-toolbar > *, .page-header-actions > *,
    .menu-toolbar > *, .row > * { min-width: 0 !important; }

    /* ── Tables become stacked cards ────────────────────────────
       app.js copies each column heading onto its cells as data-label,
       so a row reads as a labelled card with no per-page markup. */
    .table-wrapper { overflow-x: visible; }
    .data-table, table.table { min-width: 0; }
    .data-table thead, table.table thead { display: none; }
    .data-table tbody, table.table tbody { display: block; }

    .data-table tbody tr, table.table tbody tr {
        display: block;
        margin: 10px;
        padding: 4px 0;
        border: 1px solid var(--border);
        border-radius: var(--radius-lg);
        background: var(--surface);
        box-shadow: var(--shadow-xs);
    }
    .data-table tbody tr:hover, table.table tbody tr:hover { background: var(--surface); }

    .data-table tbody td, table.table tbody td {
        display: flex;
        align-items: flex-start;
        justify-content: space-between;
        gap: 14px;
        padding: 8px 14px;
        border-bottom: 1px dashed var(--border);
        text-align: right;
    }
    .data-table tbody td:last-child, table.table tbody td:last-child { border-bottom: none; }

    .data-table tbody td::before, table.table tbody td::before {
        content: attr(data-label);
        flex: 0 0 40%;
        text-align: left;
        font-size: 11px; font-weight: 650;
        letter-spacing: 0.04em; text-transform: uppercase;
        color: var(--on-surface-muted);
    }
    /* Cells with no heading (action columns) span the full width. */
    .data-table tbody td[data-label=""]::before,
    table.table tbody td[data-label=""]::before { display: none; }
    .data-table tbody td[data-label=""], table.table tbody td[data-label=""] { justify-content: flex-end; }
    .data-table tbody td .d-flex { justify-content: flex-end; }

    /* An empty-state cell must not be dressed as a data row. */
    .data-table tbody tr:has(.empty-state) { border: none; box-shadow: none; margin: 0; background: none; }
    .data-table tbody tr:has(.empty-state) td { display: block; text-align: center; border: none; padding: 0; }
    .data-table tbody tr:has(.empty-state) td::before { display: none; }

    .table-toolbar { flex-direction: column; align-items: stretch; }
    .table-toolbar form { width: 100%; flex-direction: column; }
    .table-toolbar .form-control, .table-toolbar .btn { width: 100%; max-width: none; }
    .table-footer { flex-direction: column; align-items: center; gap: 10px; }

    /* Modals go near-full-screen. */
    .modal-overlay { padding: 0; align-items: flex-end; }
    .modal {
        max-width: none; width: 100%;
        max-height: 92vh;
        border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    }

    .form-actions { flex-direction: column-reverse; align-items: stretch; }
    .form-actions .btn { width: 100%; }
    .aside-actions { grid-template-columns: 1fr; }
}

/* ── Mobile large ≤480 ─────────────────────────────────────── */
@media (max-width: 480px) {
    .page-content { padding: 16px 12px 32px; }
    .top-header   { padding: 0 12px; }
    .toast-container { top: 76px; right: 12px; left: 12px; }
    .toast { min-width: 0; max-width: none; }
    .form-card { padding: 16px; }
    .breadcrumb { display: none; }
    .data-table tbody td::before, table.table tbody td::before { flex-basis: 45%; }
}

/* ── Mobile small ≤375 ─────────────────────────────────────── */
@media (max-width: 375px) {
    .page-content { padding: 14px 10px 28px; }
    .header-actions { gap: 6px; }
    .icon-btn { width: 34px; height: 34px; }
    .data-table tbody td, table.table tbody td { padding: 7px 11px; gap: 10px; }
    .data-table tbody td::before, table.table tbody td::before { font-size: 10px; flex-basis: 42%; }
}

/* ── Touch devices: every target reaches 44px ──────────────── */
@media (pointer: coarse) {
    .btn { min-height: 44px; }
    .btn-sm { min-height: 38px; }
    .btn-icon, .btn-icon.btn-sm, .icon-btn { min-width: 44px; min-height: 44px; }
    .page-btn { min-width: 44px; height: 44px; }
    .nav-item { padding-block: 12px; }
    .user-dropdown-item, .notif-drop-item { padding-block: 13px; }
    .dish { padding-block: 12px; }
    .mcat-head { padding-block: 15px; }
    .form-control { min-height: 44px; }
    .logout-link, .toast-close { min-width: 44px; min-height: 44px; }
    input[type="checkbox"], input[type="radio"] { width: 18px; height: 18px; }
}

/* ── PRINT ──────────────────────────────────────────────────── */
@media print {
    .sidebar, .top-header, .sidebar-overlay, .toast-container,
    .no-print, .page-header-actions, .pagination, .table-toolbar { display: none !important; }
    .main-content, .main-content.collapsed { margin-left: 0 !important; }
    .page-content { padding: 0 !important; animation: none !important; }
    body { background: #fff; color: #000; font-size: 12px; }
    .card, .table-wrapper, .stat-card, .form-card {
        box-shadow: none !important;
        border: 1px solid #ddd !important;
        break-inside: avoid;
    }
    .badge-pill::before, .badge::before { display: none !important; }
    a { color: #000 !important; text-decoration: none !important; }
}

/* ── ORDER: MENU SELECTION (category accordion) ─────────────── */
.menu-toolbar {
    display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
    margin-bottom: 12px;
}
.menu-search { position: relative; flex: 1; min-width: 220px; }
.menu-search i {
    position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
    color: var(--on-surface-subtle); font-size: 12px; pointer-events: none;
}
.menu-search .form-control { padding-left: 32px; }

.menu-accordion {
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.mcat + .mcat { border-top: 1px solid var(--border); }

.mcat-head {
    width: 100%;
    display: flex; align-items: center; gap: 10px;
    padding: 12px 15px;
    background: var(--surface-variant);
    font-family: inherit; font-size: 13.5px; font-weight: 650;
    color: var(--on-surface);
    text-align: left;
    transition: background var(--dur-fast) var(--ease);
}
.mcat-head:hover { background: var(--surface-hover); }
.mcat-caret { font-size: 10px; color: var(--on-surface-subtle); transition: transform var(--dur) var(--ease); }
.mcat.open .mcat-caret { transform: rotate(90deg); }
.mcat.has-sel .mcat-name { color: var(--primary); }

.mcat-name { flex: 1; }
.mcat-meta { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.mcat-count { font-size: 11.5px; color: var(--on-surface-subtle); }
.mcat-sel {
    font-size: 11px; font-weight: 650;
    padding: 2px 8px; border-radius: var(--radius-pill);
    background: var(--primary-light); color: var(--primary);
    border: 1px solid var(--primary-border);
}

.mcat-body { display: none; padding: 6px; background: var(--surface); }
.mcat.open .mcat-body { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 2px; }

.dish {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 11px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 13.5px;
    transition: background var(--dur-fast) var(--ease);
}
.dish:hover { background: var(--surface-hover); }
.dish.on { background: var(--primary-light); }
.dish input[type="checkbox"] { width: 15px; height: 15px; flex-shrink: 0; }
.dish-name { flex: 1; min-width: 0; }
.dish.on .dish-name { font-weight: 600; }
.dish-flag { flex-shrink: 0; }
.dish-cost {
    font-variant-numeric: tabular-nums;
    font-size: 12.5px; font-weight: 600;
    color: var(--on-surface-muted);
    flex-shrink: 0;
}
/* Manual pricing: dish costs are reference-only, so they recede. */
.dish-cost.muted { color: var(--on-surface-subtle); font-weight: 400; opacity: 0.6; }

/* ── ORDER FORM: numbered step badges ───────────────────────── */
.step-n {
    width: 22px; height: 22px; flex-shrink: 0;
    border-radius: 50%;
    background: var(--primary-light);
    border: 1px solid var(--primary-border);
    color: var(--primary);
    font-size: 11px; font-weight: 700;
    font-variant-numeric: tabular-nums;
    display: inline-flex; align-items: center; justify-content: center;
    margin-right: 2px;
}

/* ── ORDER FORM: two-column working area with a pinned bill ──── */
.order-form { max-width: 1320px; }

.order-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 336px;
    gap: 20px;
    align-items: start;
}
.order-main { min-width: 0; }

/* The bill follows you from Menu Selection through Additional Charges. */
.order-aside {
    position: sticky;
    top: calc(var(--header-height) + 18px);
    max-height: calc(100vh - var(--header-height) - 36px);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.order-aside .form-card { padding: 18px; }
.order-aside .aside-actions {
    margin-top: 0;
    padding-top: 0;
    border-top: none;
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 9px;
}

/* The number the owner actually reads */
#total_lbl { font-size: 17px !important; }
.order-aside .card-title { padding-bottom: 2px; }

/* Value changed → brief flash so live updates are noticeable */
@keyframes bill-flash {
    from { background: var(--primary-light); }
    to   { background: transparent; }
}
.bill-bump { animation: bill-flash 600ms var(--ease); border-radius: 4px; }


/* ── ORDER FORM: live payment position ──────────────────────── */
.pay-live { width: 100%; font-size: 13px; margin-top: 14px; }
.pay-live td { padding: 4px 0; color: var(--on-surface-muted); }
.pay-live td.text-right { color: var(--on-surface); font-variant-numeric: tabular-nums; }
.pay-live .pay-due td {
    border-top: 1px solid var(--border);
    padding-top: 7px;
    font-weight: 700;
    color: var(--on-surface);
}
.pay-live .pay-due td.text-right { font-size: 15px; }
