/*
 * assets/css/style.css
 * SoukExpress COD Dashboard — Design System
 * Aesthetic: Refined Moroccan-meets-SaaS. Dark sidebar, warm neutrals, amber accent.
 * Fonts: Syne (display/headings) + DM Sans (body)
 * ─────────────────────────────────────────────────────────────────────────── */

/* ── Custom Properties ───────────────────────────────────────────────────── */
:root {
    /* Brand */
    --accent:        #F59E0B;       /* Amber – warm, COD money feel        */
    --accent-dim:    #FEF3C7;
    --accent-dark:   #D97706;

    /* Sidebar */
    --sidebar-bg:    #0F1117;
    --sidebar-w:     240px;

    /* Surface */
    --bg:            #F5F4F1;       /* Warm off-white paper                */
    --surface:       #FFFFFF;
    --surface-2:     #F9F8F6;
    --border:        #E8E6E1;

    /* Text */
    --text-primary:  #1A1917;
    --text-secondary:#6B6660;
    --text-muted:    #A8A49F;

    /* Status palette */
    --green:    #16A34A;  --green-bg:  #DCFCE7;
    --amber:    #D97706;  --amber-bg:  #FEF3C7;
    --blue:     #2563EB;  --blue-bg:   #DBEAFE;
    --red:      #DC2626;  --red-bg:    #FEE2E2;
    --slate:    #64748B;  --slate-bg:  #F1F5F9;

    /* Sizing */
    --radius:   12px;
    --radius-sm:8px;
    --shadow:   0 1px 3px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.04);
    --shadow-md:0 4px 12px rgba(0,0,0,.08), 0 12px 32px rgba(0,0,0,.06);

    /* Topbar */
    --topbar-h: 56px;
}

/* ── Reset & Base ────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

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

body {
    font-family: 'DM Sans', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text-primary);
    line-height: 1.6;
    overflow-x: hidden;
}

h1,h2,h3,h4,h5 {
    font-family: 'Syne', sans-serif;
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: -0.02em;
}

a { text-decoration: none; color: inherit; }
img { display: block; max-width: 100%; }
button { cursor: pointer; font-family: inherit; }
input, select, textarea { font-family: inherit; }

/* ── Layout Shell ────────────────────────────────────────────────────────── */
.layout {
    display: flex;
    min-height: 100vh;
}

/* ── Topbar (mobile) ─────────────────────────────────────────────────────── */
.topbar {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--topbar-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: none;
    align-items: center;
    padding: 0 16px;
    gap: 12px;
    z-index: 200;
}
.topbar-title {
    font-family: 'Syne', sans-serif;
    font-weight: 700;
    font-size: 1rem;
    flex: 1;
}
.topbar-right { display: flex; align-items: center; gap: 12px; margin-left: auto; }
.topbar-date {
    font-size: .75rem;
    color: var(--text-muted);
    white-space: nowrap;
}
.menu-toggle {
    background: none;
    border: none;
    padding: 6px;
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: center;
}
.menu-toggle:hover { background: var(--surface-2); }

.notification-bell {
    position: relative;
    cursor: pointer;
    padding: 4px;
    color: var(--text-secondary);
}
.notif-dot {
    position: absolute;
    top: 2px; right: 2px;
    width: 8px; height: 8px;
    background: var(--red);
    border-radius: 50%;
    border: 2px solid var(--surface);
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 299;
    backdrop-filter: blur(2px);
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-w);
    min-height: 100vh;
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
    flex-shrink: 0;
    z-index: 300;
}

/* Scrollbar */
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: #2a2a35; border-radius: 4px; }

/* Brand */
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 24px 20px 20px;
    border-bottom: 1px solid rgba(255,255,255,.06);
}
.brand-icon {
    font-size: 1.5rem;
    width: 40px; height: 40px;
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dark) 100%);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.brand-text {
    display: flex;
    flex-direction: column;
}
.brand-name {
    font-family: 'Syne', sans-serif;
    font-weight: 800;
    font-size: .95rem;
    color: #fff;
    letter-spacing: -.01em;
}
.brand-tag {
    font-size: .65rem;
    color: rgba(255,255,255,.35);
    text-transform: uppercase;
    letter-spacing: .08em;
}

/* Nav */
.sidebar-nav {
    flex: 1;
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.nav-section-label {
    font-size: .65rem;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: rgba(255,255,255,.25);
    padding: 14px 8px 6px;
    display: block;
}
.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    color: rgba(255,255,255,.5);
    font-size: .875rem;
    font-weight: 500;
    transition: all .15s ease;
    position: relative;
}
.nav-item svg {
    width: 17px; height: 17px;
    flex-shrink: 0;
    stroke: currentColor;
}
.nav-item:hover {
    background: rgba(255,255,255,.07);
    color: rgba(255,255,255,.85);
}
.nav-item.active {
    background: rgba(245,158,11,.12);
    color: var(--accent);
}
.nav-item.active::before {
    content: '';
    position: absolute;
    left: 0; top: 50%;
    transform: translateY(-50%);
    width: 3px; height: 60%;
    background: var(--accent);
    border-radius: 0 3px 3px 0;
}
.nav-badge {
    margin-left: auto;
    background: var(--red);
    color: #fff;
    font-size: .65rem;
    font-weight: 700;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
}

/* Agent card */
.sidebar-footer {
    padding: 12px;
    border-top: 1px solid rgba(255,255,255,.06);
}
.agent-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: rgba(255,255,255,.04);
    border-radius: var(--radius-sm);
}
.agent-avatar {
    width: 34px; height: 34px;
    background: linear-gradient(135deg, #6366F1 0%, #8B5CF6 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Syne', sans-serif;
    font-weight: 700;
    font-size: .85rem;
    color: #fff;
    flex-shrink: 0;
}
.agent-info { flex: 1; min-width: 0; }
.agent-name {
    display: block;
    font-size: .8rem;
    font-weight: 600;
    color: rgba(255,255,255,.8);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.agent-role {
    display: block;
    font-size: .68rem;
    color: rgba(255,255,255,.3);
}
.agent-status-dot {
    width: 8px; height: 8px;
    background: var(--green);
    border-radius: 50%;
    border: 2px solid var(--sidebar-bg);
    flex-shrink: 0;
}

/* ── Main Content ─────────────────────────────────────────────────────────── */
.main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.page-header {
    padding: 32px 32px 0;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}
.page-header-left {}
.page-header h1 {
    font-size: 1.7rem;
    color: var(--text-primary);
}
.page-subtitle {
    color: var(--text-secondary);
    font-size: .875rem;
    margin-top: 4px;
}
.page-body { padding: 24px 32px 40px; }

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    padding: 24px;
}
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}
.card-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
}
.card-subtitle {
    font-size: .8rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* ── Stat Cards ──────────────────────────────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.stat-card {
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    padding: 20px;
    position: relative;
    overflow: hidden;
    transition: transform .15s ease, box-shadow .15s ease;
}
.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}
.stat-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 3px;
}
.stat-card.amber::before { background: var(--accent); }
.stat-card.green::before { background: var(--green); }
.stat-card.blue::before  { background: var(--blue); }
.stat-card.red::before   { background: var(--red); }
.stat-card.purple::before{ background: #8B5CF6; }

.stat-icon {
    font-size: 1.4rem;
    margin-bottom: 12px;
}
.stat-value {
    font-family: 'Syne', sans-serif;
    font-size: 1.9rem;
    font-weight: 800;
    letter-spacing: -.03em;
    color: var(--text-primary);
    line-height: 1;
    margin-bottom: 6px;
}
.stat-label {
    font-size: .78rem;
    color: var(--text-secondary);
    font-weight: 500;
}
.stat-delta {
    font-size: .72rem;
    margin-top: 8px;
    display: flex;
    align-items: center;
    gap: 3px;
    font-weight: 500;
}
.stat-delta.up   { color: var(--green); }
.stat-delta.down { color: var(--red); }

/* ── Status Badges ───────────────────────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: .72rem;
    font-weight: 600;
    white-space: nowrap;
}
.badge::before {
    content: '';
    width: 6px; height: 6px;
    border-radius: 50%;
    background: currentColor;
}
.badge-delivered { background: var(--green-bg);  color: var(--green); }
.badge-pending   { background: var(--amber-bg);  color: var(--amber); }
.badge-confirmed { background: var(--blue-bg);   color: var(--blue); }
.badge-returned  { background: var(--red-bg);    color: var(--red); }
.badge-no_answer { background: var(--slate-bg);  color: var(--slate); }

/* ── Table ───────────────────────────────────────────────────────────────── */
.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
table {
    width: 100%;
    border-collapse: collapse;
    font-size: .85rem;
}
thead {
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
}
th {
    text-align: left;
    padding: 10px 14px;
    font-size: .72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-muted);
    white-space: nowrap;
}
td {
    padding: 13px 14px;
    border-bottom: 1px solid var(--border);
    color: var(--text-primary);
    vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tbody tr {
    transition: background .1s ease;
}
tbody tr:hover { background: var(--surface-2); }

.order-id {
    font-family: 'Syne', sans-serif;
    font-size: .8rem;
    font-weight: 700;
    color: var(--text-secondary);
}
.customer-name { font-weight: 600; }
.phone-link {
    color: var(--blue);
    font-size: .82rem;
}
.price-cell {
    font-family: 'Syne', sans-serif;
    font-weight: 700;
    font-size: .9rem;
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 18px;
    border-radius: var(--radius-sm);
    font-size: .85rem;
    font-weight: 600;
    border: none;
    transition: all .15s ease;
    cursor: pointer;
    white-space: nowrap;
}
.btn-primary {
    background: var(--accent);
    color: #fff;
}
.btn-primary:hover { background: var(--accent-dark); }

.btn-success {
    background: var(--green);
    color: #fff;
}
.btn-success:hover { background: #15803D; }

.btn-danger {
    background: var(--red);
    color: #fff;
}
.btn-danger:hover { background: #B91C1C; }

.btn-ghost {
    background: var(--surface-2);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}
.btn-ghost:hover {
    background: var(--border);
    color: var(--text-primary);
}
.btn-sm { padding: 6px 12px; font-size: .78rem; }

/* ── Form Controls ───────────────────────────────────────────────────────── */
.form-group { margin-bottom: 18px; }
.form-label {
    display: block;
    font-size: .8rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
}
.form-control {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text-primary);
    font-size: .875rem;
    transition: border-color .15s ease, box-shadow .15s ease;
}
.form-control:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(245,158,11,.12);
}
.form-control::placeholder { color: var(--text-muted); }

/* Search + Filter bar */
.toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}
.search-wrap {
    position: relative;
    flex: 1;
    min-width: 200px;
}
.search-wrap svg {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px; height: 16px;
    color: var(--text-muted);
    pointer-events: none;
}
.search-wrap .form-control { padding-left: 34px; }

.filter-select {
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text-primary);
    font-size: .85rem;
    font-family: inherit;
    cursor: pointer;
    min-width: 140px;
}
.filter-select:focus {
    outline: none;
    border-color: var(--accent);
}

/* ── Grid Layouts ────────────────────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; }

/* ── Confirm Page ────────────────────────────────────────────────────────── */
.confirm-grid {
    display: grid;
    grid-template-columns: 1fr 380px;
    gap: 20px;
    align-items: start;
}
.order-queue {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.queue-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface);
    cursor: pointer;
    transition: all .15s ease;
}
.queue-item:hover {
    border-color: var(--accent);
    background: var(--accent-dim);
}
.queue-item.active {
    border-color: var(--accent);
    background: var(--accent-dim);
}
.queue-avatar {
    width: 38px; height: 38px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dark) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Syne', sans-serif;
    font-weight: 700;
    color: #fff;
    font-size: .9rem;
    flex-shrink: 0;
}
.queue-details { flex: 1; min-width: 0; }
.queue-name {
    font-weight: 600;
    font-size: .875rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.queue-meta {
    font-size: .75rem;
    color: var(--text-secondary);
}

/* Customer detail panel */
.detail-panel {}
.detail-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    font-size: .875rem;
}
.detail-row:last-child { border-bottom: none; }
.detail-key {
    color: var(--text-secondary);
    font-size: .8rem;
}
.detail-val {
    font-weight: 600;
    text-align: right;
}
.action-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 10px;
    margin-top: 20px;
}
.status-result {
    display: none;
    margin-top: 16px;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: .875rem;
    font-weight: 600;
    text-align: center;
}
.status-result.show { display: block; }
.status-result.success { background: var(--green-bg); color: var(--green); }
.status-result.danger  { background: var(--red-bg);   color: var(--red); }
.status-result.warning { background: var(--amber-bg); color: var(--amber); }

/* ── Tracking Timeline ───────────────────────────────────────────────────── */
.timeline {
    position: relative;
    padding-left: 32px;
}
.timeline::before {
    content: '';
    position: absolute;
    left: 11px; top: 16px; bottom: 0;
    width: 2px;
    background: var(--border);
}
.timeline-item {
    position: relative;
    margin-bottom: 28px;
}
.timeline-dot {
    position: absolute;
    left: -32px;
    top: 4px;
    width: 22px; height: 22px;
    border-radius: 50%;
    background: var(--surface);
    border: 2px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .65rem;
    z-index: 1;
}
.timeline-item.done .timeline-dot {
    background: var(--green);
    border-color: var(--green);
    color: #fff;
}
.timeline-item.current .timeline-dot {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    box-shadow: 0 0 0 4px rgba(245,158,11,.2);
}
.timeline-time {
    font-size: .72rem;
    color: var(--text-muted);
    margin-bottom: 2px;
}
.timeline-title {
    font-weight: 600;
    font-size: .875rem;
}
.timeline-desc {
    font-size: .8rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* ── Charts ──────────────────────────────────────────────────────────────── */
.chart-container {
    position: relative;
    height: 220px;
}

/* ── Settings ────────────────────────────────────────────────────────────── */
.settings-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}
.zone-table { width: 100%; }
.zone-table td { padding: 8px 0; }
.zone-table td:first-child { color: var(--text-secondary); font-size: .85rem; }
.zone-table td:last-child { text-align: right; }
.fee-input {
    width: 80px;
    padding: 5px 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: .85rem;
    text-align: right;
    font-family: 'Syne', sans-serif;
    font-weight: 600;
}

/* ── Empty State ─────────────────────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 48px 24px;
}
.empty-icon { font-size: 2.5rem; margin-bottom: 12px; }
.empty-title { font-size: 1rem; font-weight: 600; margin-bottom: 6px; }
.empty-desc { font-size: .85rem; color: var(--text-secondary); }

/* ── Toast Notification ──────────────────────────────────────────────────── */
#toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: var(--text-primary);
    color: #fff;
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    font-size: .875rem;
    font-weight: 500;
    z-index: 9999;
    transform: translateY(80px);
    opacity: 0;
    transition: all .3s cubic-bezier(.34,1.56,.64,1);
    pointer-events: none;
    max-width: 320px;
}
#toast.show {
    transform: translateY(0);
    opacity: 1;
}

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
    .topbar { display: flex; }

    .layout { padding-top: var(--topbar-h); }

    .sidebar {
        position: fixed;
        top: 0; left: 0;
        height: 100%;
        transform: translateX(-100%);
        transition: transform .25s cubic-bezier(.4,0,.2,1);
        box-shadow: var(--shadow-md);
        z-index: 300;
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar-overlay.open { display: block; }

    .page-header { padding: 20px 16px 0; }
    .page-body   { padding: 16px 16px 32px; }

    .grid-2, .grid-3 { grid-template-columns: 1fr; }
    .confirm-grid    { grid-template-columns: 1fr; }
    .settings-grid   { grid-template-columns: 1fr; }
    .action-buttons  { grid-template-columns: 1fr 1fr; }

    .stats-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; }
    .page-header h1 { font-size: 1.3rem; }
    .stat-value { font-size: 1.6rem; }
    .toolbar { flex-direction: column; align-items: stretch; }
    .search-wrap { min-width: 0; }
}

/* ── Misc helpers ────────────────────────────────────────────────────────── */
.mt-4  { margin-top: 4px; }
.mt-8  { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-16 { margin-bottom: 16px; }
.text-muted  { color: var(--text-muted); font-size: .82rem; }
.text-right  { text-align: right; }
.flex-center { display: flex; align-items: center; gap: 8px; }
.hidden { display: none !important; }

/* Page fade-in */
.main { animation: fadeIn .25s ease; }
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Progress bar */
.progress-bar {
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
    margin-top: 8px;
}
.progress-fill {
    height: 100%;
    border-radius: 3px;
    transition: width .6s ease;
}

/* Mini sparkline placeholder */
.sparkline-row {
    display: flex;
    align-items: flex-end;
    gap: 3px;
    height: 32px;
    margin-top: 12px;
}
.sparkline-bar {
    flex: 1;
    background: var(--accent);
    border-radius: 2px 2px 0 0;
    opacity: .3;
    min-height: 4px;
    transition: opacity .2s;
}
.sparkline-bar:last-child { opacity: 1; }
