/* ============================================================
   Order CRM — Stylesheet
   Design direction: Red / White / Black / Green — a bold, high
   contrast palette. Green stays the primary brand/action color,
   red is the accent (highlights, active states), on a clean
   white/near-white surface with a black sidebar for contrast.
   Fraunces for display type, Inter for UI/data density.
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,500;9..144,600;9..144,700&family=Inter:wght@400;500;600;700&display=swap');

:root {
    --color-bg: #FAFAFA;
    --color-surface: #FFFFFF;
    --color-border: #E2E2E2;
    --color-text: #181818;
    --color-muted: #666666;

    --color-primary: #146C34;
    --color-primary-dark: #0D4D24;
    --color-primary-tint: #E5F1E9;

    --color-accent: #C41E2A;
    --color-accent-dark: #9E1620;
    --color-accent-tint: #FBE7E8;

    --color-green: #1E7A3E;
    --color-red: #C41E2A;
    --color-orange: #C17E28;
    --color-blue: #386890;
    --color-purple: #675884;
    --color-gray: #666666;

    --font-display: 'Fraunces', Georgia, serif;
    --font-body: 'Inter', 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, sans-serif;

    --radius: 14px;
    --radius-sm: 9px;
    --shadow-sm: 0 1px 2px rgba(23,35,26,0.05);
    --shadow: 0 1px 3px rgba(23,35,26,0.04), 0 6px 18px rgba(23,35,26,0.07);
    --shadow-lg: 0 10px 34px rgba(20,32,24,0.16), 0 2px 8px rgba(20,32,24,0.08);
    --sidebar-width: 248px;
    --topbar-height: 56px;
}

/* -------------------- Dark Mode -------------------- */
[data-theme="dark"] {
    --color-bg: #14171A;
    --color-surface: #1E2226;
    --color-border: #30353B;
    --color-text: #EDEDED;
    --color-muted: #9A9FA6;

    --color-primary: #2E9C5C;
    --color-primary-dark: #22B36B;
    --color-primary-tint: #1B3324;

    --color-accent: #E5535F;
    --color-accent-dark: #F0707B;
    --color-accent-tint: #3A1E21;

    --color-green: #2E9C5C;
    --color-red: #E5535F;
    --color-orange: #D99A45;
    --color-blue: #5C93C4;
    --color-purple: #9285B5;
    --color-gray: #9A9FA6;

    --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
    --shadow: 0 1px 3px rgba(0,0,0,0.35), 0 6px 18px rgba(0,0,0,0.3);
    --shadow-lg: 0 10px 34px rgba(0,0,0,0.5), 0 2px 8px rgba(0,0,0,0.35);
}
[data-theme="dark"] body { background: var(--color-bg); }
[data-theme="dark"] .sidebar { background: linear-gradient(165deg, #101214 0%, #0A0B0C 60%, #000000 100%); }
[data-theme="dark"] .table th { background: #22262B; }
[data-theme="dark"] .table tbody tr:hover { background: #262b30; }
[data-theme="dark"] input[type=text], [data-theme="dark"] input[type=email],
[data-theme="dark"] input[type=password], [data-theme="dark"] input[type=number],
[data-theme="dark"] input[type=date], [data-theme="dark"] select, [data-theme="dark"] textarea {
    background: #22262B;
}
[data-theme="dark"] .auth-card { background: var(--color-surface); }
[data-theme="dark"] .badge { box-shadow: inset 0 0 0 1px rgba(255,255,255,0.06); }

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }
html, body { max-width: 100%; overflow-x: hidden; }

body {
    margin: 0;
    font-family: var(--font-body);
    background: var(--color-bg);
    color: var(--color-text);
    transition: background 0.15s ease, color 0.15s ease;
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

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

h1, h2, h3 { font-family: var(--font-display); font-weight: 600; letter-spacing: -0.01em; }

/* -------------------- App shell -------------------- */
.app-shell { min-height: 100vh; }

/* Mobile hamburger button — completely out of document flow (position:fixed),
   so it can NEVER push or shift the sidebar/content, even if CSS fails to load. */
.hamburger-btn {
    display: none;
    position: fixed; top: 12px; left: 12px; z-index: 90;
    background: var(--color-primary-dark); border: none; color: #fff; font-size: 20px;
    cursor: pointer; padding: 8px 12px; line-height: 1; border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
}
.hamburger-btn:hover { background: var(--color-primary); }

.sidebar-overlay {
    display: none;
    position: fixed; inset: 0; background: rgba(20,28,22,0.5);
    z-index: 70;
}
.sidebar-overlay.show { display: block; }

/* Floating Chat button — bottom-right corner, always accessible, out of
   document flow so it never affects page layout. */
.chat-fab {
    position: fixed;
    bottom: 24px; right: 24px;
    width: 56px; height: 56px;
    border-radius: 50%;
    background: var(--color-primary);
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: 26px;
    box-shadow: var(--shadow-lg);
    z-index: 95;
    text-decoration: none;
    transition: transform 0.15s ease, background 0.15s ease;
}
.chat-fab:hover { background: var(--color-primary-dark); transform: scale(1.06); text-decoration: none; color: #fff; }
.chat-fab-badge {
    position: absolute; top: -4px; right: -4px;
    background: var(--color-red); color: #fff;
    font-size: 11px; font-weight: 700;
    min-width: 20px; height: 20px; padding: 0 5px;
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    border: 2px solid var(--color-bg);
}

/* -------------------- New Message Toast Popup -------------------- */
#new-message-toast-container {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: none;
    align-items: center; justify-content: center;
    background: rgba(0,0,0,0.35);
    padding: 16px;
}
#new-message-toast-container.show { display: flex; }
#new-message-toast-container .msg-toast-stack {
    display: flex; flex-direction: column; gap: 10px;
    max-width: 380px; width: 100%;
}
.msg-toast {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-left: 4px solid var(--color-primary);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 16px 18px;
    cursor: pointer;
    animation: msgToastIn 0.2s ease;
    display: flex; gap: 12px; align-items: flex-start;
}
.msg-toast:hover { background: var(--color-primary-tint); }
.msg-toast-icon { font-size: 22px; flex-shrink: 0; }
.msg-toast-body { flex: 1; min-width: 0; }
.msg-toast-sender { font-weight: 700; font-size: 14px; color: var(--color-text); }
.msg-toast-text { font-size: 13px; color: var(--color-muted); margin-top: 3px; overflow-wrap: break-word; }
.msg-toast-close { background: none; border: none; color: var(--color-muted); cursor: pointer; font-size: 18px; line-height: 1; padding: 2px; flex-shrink: 0; }
@keyframes msgToastIn {
    from { opacity: 0; transform: scale(0.94); }
    to { opacity: 1; transform: scale(1); }
}

.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    background: linear-gradient(165deg, #1A1A1A 0%, #0F0F0F 60%, #000000 100%);
    color: #D9D9D9;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 80;
    transition: width 0.18s ease;
    box-shadow: 3px 0 24px rgba(0,0,0,0.25);
}

.sidebar-brand {
    font-family: var(--font-display);
    font-size: 19px;
    font-weight: 700;
    letter-spacing: -0.01em;
    padding: 24px 22px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    color: #fff;
    display: flex; align-items: center; gap: 10px;
    white-space: nowrap; overflow: hidden;
}

.sidebar-collapse-btn {
    position: absolute;
    top: 22px; left: calc(var(--sidebar-width) - 14px);
    width: 28px; height: 28px;
    border-radius: 50%;
    border: 1px solid rgba(255,255,255,0.2);
    background: #1A1A1A;
    color: #D9D9D9;
    cursor: pointer;
    font-size: 15px;
    display: flex; align-items: center; justify-content: center;
    z-index: 85;
    transition: left 0.18s ease, transform 0.18s ease;
}
.sidebar-collapse-btn:hover { background: var(--color-accent); color: #fff; }

.sidebar-nav { flex: 1; padding: 14px 12px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; overflow-x: hidden; }

.sidebar-nav a {
    color: #BFBFBF;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 13.5px;
    font-weight: 500;
    border-left: 3px solid transparent;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
    display: flex; align-items: center; gap: 10px;
    white-space: nowrap;
}

.sidebar-nav a:hover { background: rgba(255,255,255,0.08); color: #fff; text-decoration: none; }
.sidebar-nav a.active { background: rgba(196,30,42,0.22); color: #fff; border-left-color: var(--color-accent); font-weight: 600; box-shadow: 0 1px 4px rgba(0,0,0,0.15) inset; }

/* -------------------- Collapsed (icon-only) sidebar -------------------- */
.sidebar.collapsed { width: 68px; }
.sidebar.collapsed .sidebar-collapse-btn { left: 54px; transform: rotate(180deg); }
.sidebar.collapsed .nav-text { display: none; }
.sidebar.collapsed .sidebar-nav a { justify-content: center; padding: 12px 0; }
.sidebar.collapsed .sidebar-brand { justify-content: center; padding: 24px 8px; }
.sidebar.collapsed .user-chip { justify-content: center; }
.sidebar.collapsed .sidebar-footer-links a { justify-content: center; }

/* Hovering a collapsed sidebar temporarily widens it back out (showing full
   labels) without pushing the page content — it just overlaps on top while
   the mouse is over it, and shrinks back the moment the mouse leaves. */
.sidebar.collapsed.hover-expanded {
    width: var(--sidebar-width);
    z-index: 95;
    box-shadow: 6px 0 30px rgba(0,0,0,0.35);
}
.sidebar.collapsed.hover-expanded .sidebar-collapse-btn { left: calc(var(--sidebar-width) - 14px); transform: none; }
.sidebar.collapsed.hover-expanded .nav-text { display: inline; }
.sidebar.collapsed.hover-expanded .sidebar-nav a { justify-content: flex-start; padding: 10px 14px; }
.sidebar.collapsed.hover-expanded .sidebar-brand { justify-content: flex-start; padding: 24px 20px; }
.sidebar.collapsed.hover-expanded .user-chip { justify-content: flex-start; }
.sidebar.collapsed.hover-expanded .sidebar-footer-links a { justify-content: flex-start; }
.sidebar.collapsed.hover-expanded .theme-toggle-btn { justify-content: flex-start; }

.sidebar-footer { padding: 16px; border-top: 1px solid rgba(255,255,255,0.08); }

.user-chip { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }

.avatar {
    width: 34px; height: 34px; border-radius: 50%;
    background: var(--color-accent);
    color: #fff; font-family: var(--font-display);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; flex-shrink: 0;
}

.user-name { font-size: 13px; font-weight: 600; color: #fff; }
.user-role { font-size: 11px; color: #8C8C8C; }
.logout-link { font-size: 12px; color: #F08080; }
.sidebar-footer-links { display: flex; flex-direction: column; gap: 8px; }
.sidebar-footer-links a { font-size: 12px; }
.sidebar-footer-links a:not(.logout-link) { color: #BFBFBF; }
.sidebar-footer-links a.active-link { color: var(--color-accent); font-weight: 700; }

.theme-toggle-btn {
    display: flex; align-items: center; gap: 10px;
    background: none; border: none; cursor: pointer;
    font-size: 12px; color: #BFBFBF; font-family: inherit;
    padding: 0; text-align: left; width: 100%;
}
.theme-toggle-btn:hover { color: #fff; }
.sidebar.collapsed .theme-toggle-btn { justify-content: center; }

.main-content { min-width: 0; padding: 30px 36px; margin-left: var(--sidebar-width); transition: margin-left 0.18s ease; }
body.sidebar-collapsed .main-content { margin-left: 68px; }
.content-inner { max-width: 1280px; margin: 0 auto; }

/* -------------------- Page header -------------------- */
.page-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 24px; flex-wrap: wrap; gap: 10px; }
.page-header h1 { margin: 0 0 4px 0; font-size: 24px; color: var(--color-primary-dark); }
.text-muted { color: var(--color-muted); }
.text-red { color: var(--color-red); }
.small { font-size: 12px; }

/* -------------------- Cards -------------------- */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
    margin-bottom: 20px;
    overflow-x: auto;
    transition: box-shadow 0.2s ease;
}

.card-narrow { max-width: 520px; }
.card-form-compact { max-width: 100%; }

/* -------------------- Order Detail: main content + sticky Timeline sidebar -------------------- */
.order-detail-layout {
    display: grid;
    grid-template-columns: 1fr 380px;
    gap: 20px;
    align-items: start;
}
.order-detail-main { min-width: 0; }
.order-detail-timeline { position: sticky; top: 20px; }
.order-detail-timeline .card { max-height: calc(100vh - 40px); overflow-y: auto; }
@media (max-width: 1300px) {
    .order-detail-layout { grid-template-columns: 1fr; }
    .order-detail-timeline { position: static; }
    .order-detail-timeline .card { max-height: none; }
}
.card-form-compact .form-row { gap: 10px 16px; margin-bottom: 4px; }
.card-form-compact input[type=text], .card-form-compact textarea, .card-form-compact select {
    max-width: 100%;
}
.card-form-compact label { font-size: 12.5px; margin-bottom: 3px; display: block; }
/* The Order Items table needs its own natural sizing — don't squeeze its
   product dropdown/qty fields down to the narrow 280px form-field width,
   and don't force the table itself to a min-width that would overflow the
   compact card (causing an unwanted horizontal scrollbar). */
.card-form-compact #edit-items-table { min-width: 0; width: 100%; table-layout: fixed; }
.card-form-compact #edit-items-table select,
.card-form-compact #edit-items-table input {
    max-width: 100%;
    width: 100%;
}
.card-form-compact #edit-items-table td:nth-child(1) { width: 55%; }
.card-form-compact #edit-items-table td:nth-child(2) { width: 15%; }
.card-form-compact #edit-items-table td:nth-child(3) { width: 20%; }
.card-form-compact #edit-items-table td:nth-child(4) { width: 10%; }
.card-form-compact #edit-items-table select { font-size: 12.5px; white-space: normal; }
.card-form-compact .table { min-width: 0; }

.card-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 16px; flex-wrap: wrap; gap: 8px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--color-border);
}

.card-header h3 { margin: 0; font-size: 16px; color: var(--color-primary-dark); letter-spacing: -0.005em; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

/* -------------------- Compact Order Form -------------------- */
.order-form-grid { display: grid; grid-template-columns: 360px 1fr; gap: 18px; align-items: start; }
.order-form-grid .card { margin-bottom: 0; }

.section-title-first { margin-top: 0; }

.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }

.table-compact th, .table-compact td { padding: 7px 8px; font-size: 12.5px; }
.table-compact select, .table-compact input { min-height: 34px; padding: 6px 8px; font-size: 13px; }

/* Orders list — dense, no-scroll layout: merged columns, tighter cells */
.table-compact-orders { min-width: 0; width: 100%; table-layout: auto; }
.table-compact-orders th, .table-compact-orders td { padding: 9px 8px; font-size: 12.5px; line-height: 1.45; }
.table-compact-orders .badge { font-size: 10.5px; padding: 2px 9px; }

.section-title {
    font-family: var(--font-display);
    font-size: 15px; font-weight: 600;
    margin: 20px 0 12px; color: var(--color-primary-dark);
    border-bottom: 1px solid var(--color-border); padding-bottom: 8px;
}

/* -------------------- Stats -------------------- */
.stat-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 16px; margin-bottom: 24px; }

.stat-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 18px 20px;
    box-shadow: var(--shadow);
    border-left: 4px solid var(--color-primary);
    transition: transform 0.18s ease, box-shadow 0.18s ease;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.stat-orange { border-left-color: var(--color-orange); }
.stat-green { border-left-color: var(--color-green); }
.stat-red { border-left-color: var(--color-red); }
.stat-blue { border-left-color: var(--color-blue); }

.stat-value { font-family: var(--font-display); font-size: 25px; font-weight: 700; color: var(--color-text); letter-spacing: -0.01em; }
.stat-label { font-size: 12px; color: var(--color-muted); margin-top: 3px; font-weight: 500; }
.stat-sub { font-size: 12px; color: var(--color-primary-dark); margin-top: 6px; font-weight: 700; }

/* -------------------- Dashboard analytics bars -------------------- */
.analytics-bars { display: flex; flex-direction: column; gap: 14px; }
.analytics-bar-row { display: grid; grid-template-columns: 150px 1fr 110px; align-items: center; gap: 12px; }
.analytics-bar-label { font-size: 13px; font-weight: 600; color: var(--color-text); }
.analytics-bar-track {
    height: 14px; background: var(--color-bg); border-radius: 8px; overflow: hidden;
    border: 1px solid var(--color-border);
}
.analytics-bar-fill {
    height: 100%; border-radius: 8px;
    transition: width 0.5s ease;
}
.fill-orange { background: var(--color-orange); }
.fill-blue { background: var(--color-blue); }
.fill-green { background: var(--color-green); }
.fill-red { background: var(--color-red); }
.analytics-bar-count { font-size: 12.5px; color: var(--color-muted); text-align: right; white-space: nowrap; }

/* -------------------- Forms -------------------- */
form label { display: block; margin: 10px 0 5px; font-size: 12.5px; font-weight: 600; color: #3B4A40; }

.checkbox-label {
    display: flex !important; align-items: center; gap: 8px;
    font-weight: 500 !important; margin: 8px 0 !important;
    cursor: pointer;
}
.checkbox-label input[type=checkbox] { width: auto; accent-color: var(--color-primary); }

input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], select, textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    background: #FEFEFC;
    color: var(--color-text);
    font-family: inherit;
    min-height: 42px;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

textarea { resize: vertical; min-height: unset; }

input:hover, select:hover, textarea:hover { border-color: #CFC9B4; }

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3.5px var(--color-primary-tint);
}

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-actions { margin-top: 18px; display: flex; gap: 10px; flex-wrap: wrap; }

/* -------------------- Buttons -------------------- */
.btn {
    display: inline-block;
    padding: 10px 18px;
    border-radius: var(--radius-sm);
    border: none;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    min-height: 42px;
    line-height: 22px;
    transition: background 0.18s ease, transform 0.12s ease, box-shadow 0.18s ease;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--color-primary); color: #fff; box-shadow: 0 1px 2px rgba(22,48,31,0.15), 0 3px 10px rgba(22,48,31,0.18); }
.btn-primary:hover { background: var(--color-primary-dark); transform: translateY(-1px); box-shadow: 0 2px 4px rgba(22,48,31,0.18), 0 6px 16px rgba(22,48,31,0.22); }
.btn-secondary { background: var(--color-primary-tint); color: var(--color-primary-dark); border: 1px solid rgba(35,75,55,0.12); }
.btn-secondary:hover { background: #DCE7DF; transform: translateY(-1px); }
.btn-block { width: 100%; margin-top: 14px; }
.btn-sm { padding: 8px 14px; font-size: 13px; min-height: 36px; }

/* -------------------- Table -------------------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; margin-top: 8px; min-width: 640px; }
.table th, .table td { padding: 12px; text-align: left; border-bottom: 1px solid var(--color-border); font-size: 13px; }
.table th { color: var(--color-muted); font-weight: 600; text-transform: uppercase; font-size: 10.5px; letter-spacing: 0.05em; white-space: nowrap; background: #FAF9F4; }
.table tbody tr { transition: background 0.12s ease; }
.table tbody tr:hover { background: var(--color-primary-tint); }
.actions a, .actions button { margin-right: 10px; font-size: 13px; }
.link { color: var(--color-primary); background: none; border: none; cursor: pointer; padding: 0; font-size: 13px; font-weight: 600; }
.link-danger { color: var(--color-red); background: none; border: none; cursor: pointer; padding: 0; font-size: 13px; font-weight: 600; }
.text-right { text-align: right; }

/* -------------------- Badges -------------------- */
.badge {
    display: inline-block;
    padding: 3px 11px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 700;
    text-transform: capitalize;
    white-space: nowrap;
    letter-spacing: 0.01em;
    box-shadow: inset 0 0 0 1px rgba(0,0,0,0.04);
}
.badge-lg { padding: 5px 14px; font-size: 12px; margin-left: 6px; }
.badge-gray { background: #EEEDE4; color: #565F52; }
.badge-blue { background: #E1EBF1; color: #2A5876; }
.badge-green { background: #DEEEE1; color: #2A6B45; }
.badge-red { background: #F5E1E1; color: #963030; }
.badge-orange { background: #F6E9D2; color: #A16A1F; }
.badge-purple { background: #E9E4F0; color: #574A78; }

/* -------------------- Alerts -------------------- */
.alert { padding: 13px 16px; border-radius: var(--radius-sm); margin-bottom: 16px; font-size: 13px; border-left: 3px solid transparent; }
.alert-success { background: #DEEEE1; color: #235539; border-left-color: var(--color-green); }
.alert-error { background: #F5E1E1; color: #7A2626; border-left-color: var(--color-red); }

/* -------------------- Auth pages -------------------- */
.auth-body {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh; background: linear-gradient(160deg, #0D0D0D 0%, #123D26 55%, #146C34 100%);
    padding: 20px;
}
.auth-card {
    background: #fff; padding: 42px 36px; border-radius: 18px;
    width: 100%; max-width: 380px; box-shadow: 0 30px 80px rgba(0,0,0,0.45), 0 2px 8px rgba(0,0,0,0.2);
    border: 1px solid rgba(255,255,255,0.06);
    border-top: 3px solid var(--color-accent);
}
.auth-logo-badge {
    width: 60px; height: 60px;
    margin: 0 auto 14px;
    border-radius: 50%;
    background: linear-gradient(145deg, var(--color-primary-tint), #fff);
    border: 2px solid rgba(20,108,52,0.18);
    display: flex; align-items: center; justify-content: center;
    font-size: 28px;
    box-shadow: 0 6px 18px rgba(20,108,52,0.16), inset 0 1px 2px rgba(255,255,255,0.8);
}
.auth-welcome-eyebrow {
    text-align: center;
    font-size: 11.5px;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--color-accent-dark);
    margin: 0 0 2px;
}
.auth-brand { font-family: var(--font-display); font-size: 25px; font-weight: 700; text-align: center; color: var(--color-primary-dark); letter-spacing: -0.01em; line-height: 1.25; }
.auth-divider {
    display: flex; align-items: center; text-align: center;
    color: var(--color-border); margin: 18px 0 16px;
}
.auth-divider::before, .auth-divider::after {
    content: ''; flex: 1; height: 1px; background: var(--color-border);
}
.auth-divider span { padding: 0 10px; font-size: 15px; opacity: 0.7; }
.auth-subtitle { text-align: center; color: var(--color-muted); margin-bottom: 0; font-size: 13px; }
.auth-hint { text-align: center; margin-top: 16px; font-size: 12px; color: var(--color-muted); }

/* -------------------- Search bar -------------------- */
.search-bar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.search-bar input { flex: 1 1 220px; }
.search-bar select { width: 200px; }

/* -------------------- Orders filter grid -------------------- */
.filter-card {
    background: linear-gradient(180deg, #FBFAF5 0%, #FFFFFF 100%);
    border: 1px solid #E6E2D0;
}
[data-theme="dark"] .filter-card {
    background: linear-gradient(180deg, #1E2226 0%, #191C1F 100%);
    border: 1px solid var(--color-border);
}

/* Desktop: everything stays on ONE line. If it doesn't all fit, the row
   scrolls horizontally instead of wrapping to a second line. */
.filter-grid {
    display: flex; flex-wrap: nowrap; gap: 6px; margin-bottom: 14px; align-items: center;
    overflow-x: auto; padding-bottom: 4px;
}
.filter-grid input[type=text] { flex: 1 1 150px; min-width: 130px; }
.filter-grid select { width: auto; min-width: 100px; max-width: 150px; flex: 1 1 100px; font-size: 13px; padding: 9px 8px; }
.filter-grid input[type=date] { width: auto; flex: 0 0 118px; font-size: 13px; padding: 9px 8px; }
.filter-grid .btn { flex: 0 0 auto; white-space: nowrap; padding: 9px 12px; }

/* Labeled filter layout — 4 columns per row on desktop, extra compact. */
.filter-grid-2col {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 2px 10px;
    margin-top: 4px;
}
.filter-grid-2col label {
    margin: 8px 0 3px;
    font-size: 10px;
    color: var(--color-primary-dark);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 700;
}
.filter-grid-2col select,
.filter-grid-2col input[type=date] {
    min-height: 30px;
    padding: 4px 6px;
    font-size: 12px;
    border-color: #DCD8C6;
    background: #FEFEFC;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.filter-grid-2col select:hover,
.filter-grid-2col input[type=date]:hover {
    border-color: var(--color-primary);
    background: #fff;
}

#orders-filter-form { position: relative; }
#orders-filter-form > label { margin: 0 0 4px; font-size: 10px; color: var(--color-primary-dark); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 700; }
#orders-filter-form > input[type=text] {
    min-height: 34px; padding: 6px 12px 6px 34px; font-size: 12.5px;
    background: #FEFEFC url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23234B37' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E") no-repeat 10px center;
    background-size: 14px;
}
#orders-filter-form .form-actions { margin-top: 10px; gap: 8px; padding-top: 2px; }
#orders-filter-form .form-actions .btn { padding: 6px 14px; min-height: 32px; font-size: 12px; font-weight: 700; }
#orders-filter-form .form-actions .btn-primary { box-shadow: 0 2px 8px rgba(20,108,52,0.28); }
[data-theme="dark"] .filter-grid-2col select,
[data-theme="dark"] .filter-grid-2col input[type=date],
[data-theme="dark"] #orders-filter-form > input[type=text] {
    background-color: var(--color-surface);
}
[data-theme="dark"] #orders-filter-form > input[type=text] {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23EDEDED' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E");
}

.filter-status-pill {
    display: inline-flex; align-items: center; gap: 6px;
    background: var(--color-primary-tint);
    color: var(--color-primary-dark);
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 11.5px;
    margin-top: 10px;
    border: 1px solid rgba(20,108,52,0.14);
}

/* -------------------- Assign Order bulk bar -------------------- */
.assign-bar {
    display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
    background: var(--color-primary-tint); border: 1px solid var(--color-border); border-radius: var(--radius-sm);
    padding: 12px 14px; margin-bottom: 14px;
}
.assign-bar select { width: auto; min-width: 180px; flex: 1 1 180px; }
.assign-bar-label { display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; white-space: nowrap; }

/* -------------------- Modal (stock adjust) -------------------- */
.modal {
    display: none;
    position: fixed; inset: 0;
    background: rgba(20,28,22,0.5);
    align-items: center; justify-content: center;
    z-index: 100;
    padding: 16px;
}
.modal.show { display: flex; }
.modal-box {
    background: #fff; padding: 26px; border-radius: var(--radius);
    width: 100%; max-width: 400px;
    max-height: 90vh; overflow-y: auto;
    box-shadow: var(--shadow-lg);
}
.modal-box-lg { max-width: 700px; }

/* -------------------- Timeline -------------------- */
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li {
    padding: 12px 0 12px 18px;
    border-left: 2px solid var(--color-border);
    position: relative;
    margin-left: 6px;
}
.timeline li::before {
    content: '';
    position: absolute; left: -6px; top: 16px;
    width: 10px; height: 10px; border-radius: 50%;
    background: var(--color-accent);
}
.timeline li p { margin: 4px 0 0; color: var(--color-text); }

/* -------------------- AWB Transit History popup -------------------- */
.awb-history-header {
    display: flex; justify-content: space-between; align-items: flex-start;
    margin-bottom: 16px; padding-bottom: 14px;
    border-bottom: 1px solid var(--color-border);
}
.awb-history-header h3 { margin: 0 0 4px; font-size: 20px; }
#awb-history-body { max-height: 60vh; overflow-y: auto; }
.awb-history-timeline { list-style: none; padding: 0; margin: 0; }
.awb-history-timeline li {
    display: flex; gap: 14px;
    padding-bottom: 20px;
    position: relative;
}
.awb-history-timeline li:not(:last-child)::before {
    content: '';
    position: absolute; left: 5px; top: 16px; bottom: 0;
    width: 2px; background: var(--color-border);
}
.awb-history-dot {
    width: 12px; height: 12px; border-radius: 50%;
    border: 2px solid var(--color-primary);
    background: var(--color-surface);
    flex-shrink: 0; margin-top: 3px; z-index: 1;
}
.awb-history-timeline li:first-child .awb-history-dot { background: var(--color-primary); }
.awb-history-content { flex: 1; }
.awb-history-date { font-weight: 700; font-size: 13.5px; }
.awb-history-status { font-size: 13px; color: var(--color-muted); margin-top: 2px; }

.order-total { text-align: right; font-size: 17px; font-weight: 700; margin: 12px 0; font-family: var(--font-display); }

/* -------------------- Leaderboard -------------------- */
/* -------------------- Chat -------------------- */
.chat-layout { display: grid; grid-template-columns: 280px 1fr; gap: 16px; align-items: start; }

.chat-contacts { padding: 16px; max-height: 620px; display: flex; flex-direction: column; }
.chat-contact-list { overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }

.chat-contact {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 10px; border-radius: var(--radius-sm);
    color: var(--color-text);
}
.chat-contact:hover { background: var(--color-primary-tint); text-decoration: none; }
.chat-contact.active { background: var(--color-primary-tint); border-left: 3px solid var(--color-primary); }
.chat-contact-info { flex: 1; min-width: 0; }
.chat-contact-name { font-weight: 600; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-unread-badge { flex-shrink: 0; }

.chat-window { padding: 16px; display: flex; flex-direction: column; height: 620px; }
.chat-messages {
    flex: 1; overflow-y: auto; padding: 10px 6px;
    display: flex; flex-direction: column; gap: 10px;
    background: var(--color-bg); border-radius: var(--radius-sm); margin-bottom: 12px;
}

.chat-bubble {
    max-width: 72%; padding: 9px 13px; border-radius: 14px; font-size: 13.5px;
}
.chat-bubble-mine {
    align-self: flex-end; background: var(--color-primary); color: #fff; border-bottom-right-radius: 4px;
}
.chat-bubble-theirs {
    align-self: flex-start; background: #fff; border: 1px solid var(--color-border); border-bottom-left-radius: 4px;
}
.chat-bubble-time { margin-top: 3px; opacity: 0.75; font-size: 10.5px; }
.chat-bubble-mine .chat-bubble-time { color: #E7EEE8; }

.chat-input-row { display: flex; gap: 8px; }
.chat-input-row input { flex: 1; }

.leaderboard { display: flex; flex-direction: column; gap: 10px; }
.leaderboard-row {
    display: flex; align-items: center; gap: 16px;
    padding: 14px 18px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border);
    background: #FBFAF6;
    flex-wrap: wrap;
}
.rank-gold {
    background: linear-gradient(90deg, #FBF3D9, #FBFAF6);
    border-color: #E3C578;
    animation: rankGoldGlow 2s ease-in-out infinite;
    position: relative;
    overflow: hidden;
}
.rank-silver {
    background: linear-gradient(90deg, #F1F1EC, #FBFAF6);
    border-color: #CDCDC0;
    animation: rankSilverGlow 2.4s ease-in-out infinite;
}
.rank-bronze {
    background: linear-gradient(90deg, #F3E7DA, #FBFAF6);
    border-color: #D9B78F;
    animation: rankBronzeGlow 2.8s ease-in-out infinite;
}

.lb-rank { font-size: 26px; width: 40px; text-align: center; flex-shrink: 0; }
.rank-normal .lb-rank { font-size: 16px; font-weight: 700; color: var(--color-muted); }

/* Medal bounce — top 3 get a gentle up-down bounce on their emoji, gold bounces
   the most enthusiastically to feel extra celebratory. */
.rank-gold .lb-rank { display: inline-block; animation: rankBounceBig 1.4s ease-in-out infinite; }
.rank-silver .lb-rank { display: inline-block; animation: rankBounceSmall 1.8s ease-in-out infinite; }
.rank-bronze .lb-rank { display: inline-block; animation: rankBounceSmall 2.2s ease-in-out infinite; }

.rank-gold .lb-name .crown-emoji { display: inline-block; animation: crownWiggle 1.6s ease-in-out infinite; }

@keyframes rankGoldGlow {
    0%, 100% { box-shadow: 0 0 0 rgba(226,197,65,0.35); }
    50% { box-shadow: 0 0 22px rgba(226,197,65,0.55); }
}
@keyframes rankSilverGlow {
    0%, 100% { box-shadow: 0 0 0 rgba(180,180,175,0.25); }
    50% { box-shadow: 0 0 14px rgba(180,180,175,0.45); }
}
@keyframes rankBronzeGlow {
    0%, 100% { box-shadow: 0 0 0 rgba(200,150,100,0.2); }
    50% { box-shadow: 0 0 12px rgba(200,150,100,0.4); }
}
@keyframes rankBounceBig {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    50% { transform: translateY(-6px) rotate(-4deg); }
}
@keyframes rankBounceSmall {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-3px); }
}
@keyframes crownWiggle {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(-10deg); }
    75% { transform: rotate(10deg); }
}

@media (prefers-reduced-motion: reduce) {
    .rank-gold, .rank-silver, .rank-bronze,
    .rank-gold .lb-rank, .rank-silver .lb-rank, .rank-bronze .lb-rank,
    .rank-gold .lb-name .crown-emoji {
        animation: none;
    }
}

.lb-avatar { width: 42px; height: 42px; font-size: 16px; }
.lb-info { flex: 1; min-width: 140px; }
.lb-name { font-weight: 700; font-size: 15px; font-family: var(--font-display); }
.lb-meta { margin-top: 2px; }

.lb-stats { display: flex; gap: 22px; flex-wrap: wrap; }
.lb-stat { text-align: center; min-width: 70px; }
.lb-stat-value { font-size: 17px; font-weight: 700; font-family: var(--font-display); }
.lb-stat-label { font-size: 11px; color: var(--color-muted); text-transform: uppercase; letter-spacing: 0.02em; }
.lb-stat-sub { font-size: 11px; color: var(--color-primary-dark); font-weight: 700; margin-top: 2px; }

/* -------------------- Code / long text wrapping -------------------- */
code, pre {
    word-break: break-all;
    overflow-wrap: break-word;
    white-space: pre-wrap;
    max-width: 100%;
    display: inline-block;
    background: var(--color-primary-tint);
    color: var(--color-primary-dark);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 12px;
}
pre { display: block; padding: 10px; }

/* ============================================================
   Responsive breakpoints
   ============================================================ */

/* Tablet and below: stack two-column layouts */
@media (max-width: 900px) {
    .grid-2 { grid-template-columns: 1fr; }
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
    .order-form-grid { grid-template-columns: 1fr; }
    .filter-grid-2col { grid-template-columns: 1fr 1fr; }
}

/* Mobile: sidebar becomes a slide-in drawer, floating hamburger button appears */
@media (max-width: 768px) {
    .hamburger-btn { display: block; }
    .sidebar-collapse-btn { display: none; }
    .chat-fab { width: 48px; height: 48px; font-size: 22px; bottom: 16px; right: 16px; }
    .analytics-bar-row { grid-template-columns: 1fr; gap: 4px; }
    .analytics-bar-count { text-align: left; }

    .sidebar, .sidebar.collapsed {
        width: var(--sidebar-width);
        position: fixed;
        top: 0; left: 0; bottom: 0;
        transform: translateX(-100%);
        transition: transform 0.2s ease;
        box-shadow: 2px 0 12px rgba(0,0,0,0.2);
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar.collapsed .nav-text { display: block; }
    .sidebar.collapsed .sidebar-nav a { justify-content: flex-start; padding: 10px 14px; }

    .main-content { padding: 64px 14px 18px; margin-left: 0; }
    body.sidebar-collapsed .main-content { margin-left: 0; }
    .content-inner { max-width: 100%; }

    .page-header { flex-direction: column; align-items: stretch; }
    .page-header .btn { width: 100%; text-align: center; }

    .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .stat-value { font-size: 18px; }

    .form-row { grid-template-columns: 1fr; }
    .form-row-3 { grid-template-columns: 1fr; }

    .card { padding: 16px; }

    .filter-grid, .search-bar, .assign-bar {
        flex-direction: column; align-items: stretch;
    }
    .filter-grid select, .filter-grid input, .search-bar select, .search-bar input,
    .assign-bar select { width: 100%; flex: none; }

    .filter-grid-2col { grid-template-columns: 1fr; }

    .form-actions { flex-direction: column; }
    .form-actions .btn { width: 100%; text-align: center; }

    .modal-box-lg { max-width: 100%; }

    .leaderboard-row { flex-direction: column; align-items: flex-start; text-align: left; }

    .chat-layout { grid-template-columns: 1fr; }
    .chat-contacts { max-height: 200px; }
    .chat-window { height: 480px; }
    .lb-stats { width: 100%; justify-content: space-between; }
}

@media (max-width: 420px) {
    .stat-grid { grid-template-columns: 1fr; }
    .auth-card { padding: 28px 22px; }
}
