/* =====================================================
   DeliveryPro - Core Stylesheet
   ===================================================== */

/* Force the HTML hidden attribute to work even when CSS classes set display.
   Without this, .modal-backdrop { display: grid } would make [hidden] useless. */
[hidden] {
    display: none !important;
}

/* Ensure modal-backdrop respects hidden attribute */
.modal-backdrop[hidden] {
    display: none !important;
}

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #dbeafe;
    --success: #16a34a;
    --success-light: #dcfce7;
    --warning: #d97706;
    --warning-light: #fef3c7;
    --danger: #dc2626;
    --danger-light: #fee2e2;
    --info: #0891b2;
    --info-light: #cffafe;

    --bg: #f1f5f9;
    --surface: #ffffff;
    --surface-alt: #f8fafc;
    --border: #e2e8f0;
    --text: #0f172a;
    --text-muted: #64748b;
    --text-faint: #94a3b8;

    --radius: 10px;
    --radius-sm: 6px;
    --radius-lg: 16px;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
    --shadow: 0 4px 12px rgba(15, 23, 42, .08);
    --shadow-lg: 0 12px 32px rgba(15, 23, 42, .14);

    --sidebar-w: 250px;
    --topbar-h: 60px;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
}

[data-theme="dark"] {
    --bg: #0f172a;
    --surface: #1e293b;
    --surface-alt: #172033;
    --border: #334155;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --text-faint: #64748b;
    --primary-light: #1e3a8a;
    --success-light: #14532d;
    --warning-light: #78350f;
    --danger-light: #7f1d1d;
    --info-light: #164e63;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    min-height: 100%;
}

body {
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5 { margin: 0 0 .6rem; font-weight: 650; line-height: 1.25; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.1rem; }
h4 { font-size: 1rem; }
p  { margin: 0 0 .8rem; }

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

/* ============ LAYOUT ============ */

.app-shell { display: flex; min-height: 100vh; }

.app-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    margin-left: var(--sidebar-w);
}

.content {
    flex: 1;
    padding: 20px;
    max-width: 100%;
}

.app-footer {
    display: flex;
    justify-content: space-between;
    padding: 14px 20px;
    color: var(--text-faint);
    font-size: 12px;
    border-top: 1px solid var(--border);
}

/* ============ SIDEBAR ============ */

.sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 200;
    overflow-y: auto;
}

.sidebar__brand {
    padding: 16px;
    border-bottom: 1px solid var(--border);
}

.sidebar__brand a {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text);
    text-decoration: none;
}

.sidebar__logo {
    width: 34px; height: 34px;
    display: grid; place-items: center;
    background: var(--primary);
    color: #fff;
    border-radius: 8px;
    font-weight: 800;
    font-size: 14px;
    flex-shrink: 0;
}

.sidebar__name {
    font-weight: 650;
    font-size: 14px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar__nav { flex: 1; padding: 10px 8px; }

.nav__section {
    padding: 12px 10px 5px;
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: .07em;
    text-transform: uppercase;
    color: var(--text-faint);
}

.nav__link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 13.5px;
    font-weight: 500;
    text-decoration: none;
    transition: background .15s, color .15s;
}

.nav__link:hover { background: var(--surface-alt); color: var(--text); text-decoration: none; }
.nav__link.is-active { background: var(--primary-light); color: var(--primary-dark); font-weight: 600; }
[data-theme="dark"] .nav__link.is-active { color: #fff; }
.nav__link--danger:hover { background: var(--danger-light); color: var(--danger); }

.nav__icon { width: 17px; height: 17px; flex-shrink: 0; }

.sidebar__footer { padding: 10px 8px 16px; border-top: 1px solid var(--border); }
.sidebar__role {
    padding: 6px 10px 10px;
    font-size: 11px;
    color: var(--text-faint);
    text-transform: uppercase;
    letter-spacing: .05em;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .5);
    z-index: 199;
}
.sidebar-overlay.is-visible { display: block; }

/* ============ TOPBAR ============ */

.topbar {
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 0 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.topbar__burger {
    display: none;
    flex-direction: column;
    gap: 4px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
}
.topbar__burger span { width: 20px; height: 2px; background: var(--text); border-radius: 2px; }

.topbar__title {
    margin: 0;
    font-size: 17px;
    font-weight: 650;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.topbar__actions { display: flex; align-items: center; gap: 10px; }

.topbar__clock {
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    color: var(--text-muted);
    font-size: 13px;
}

.icon-btn {
    position: relative;
    width: 36px; height: 36px;
    display: grid; place-items: center;
    background: none;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    cursor: pointer;
}
.icon-btn:hover { background: var(--surface-alt); color: var(--text); }

.icon-btn__badge {
    position: absolute;
    top: 2px; right: 2px;
    min-width: 16px; height: 16px;
    padding: 0 4px;
    background: var(--danger);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    border-radius: 8px;
    display: grid; place-items: center;
}

.topbar__notifications, .topbar__user { position: relative; }

.user-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 10px 5px 5px;
    background: none;
    border: 1px solid var(--border);
    border-radius: 20px;
    cursor: pointer;
    color: var(--text);
    font-family: inherit;
    font-size: 13px;
}
.user-chip:hover { background: var(--surface-alt); }

.user-chip__avatar {
    width: 26px; height: 26px;
    display: grid; place-items: center;
    background: var(--primary);
    color: #fff;
    border-radius: 50%;
    font-weight: 700;
    font-size: 12px;
}
.user-chip__name { max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ============ DROPDOWN ============ */

.dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 260px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    z-index: 300;
    overflow: hidden;
}

.dropdown__header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    font-size: 13px;
}

.dropdown__body { max-height: 340px; overflow-y: auto; }
.dropdown__empty { padding: 20px; text-align: center; color: var(--text-faint); font-size: 13px; }

.dropdown__meta {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}
.dropdown__meta small { color: var(--text-faint); font-size: 12px; }

.dropdown--user a,
.dropdown--user button {
    display: block;
    width: 100%;
    padding: 10px 14px;
    text-align: left;
    background: none;
    border: none;
    font: inherit;
    font-size: 13px;
    color: var(--text);
    cursor: pointer;
    text-decoration: none;
}
.dropdown--user a:hover, .dropdown--user button:hover { background: var(--surface-alt); text-decoration: none; }
.dropdown--user .danger { color: var(--danger); }

.notification-item {
    display: block;
    padding: 11px 14px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    text-decoration: none;
    font-size: 13px;
}
.notification-item:hover { background: var(--surface-alt); text-decoration: none; }
.notification-item.is-unread { background: var(--primary-light); }
[data-theme="dark"] .notification-item.is-unread { background: rgba(37, 99, 235, .16); }
.notification-item__title { font-weight: 600; margin-bottom: 2px; }
.notification-item__time { color: var(--text-faint); font-size: 11.5px; margin-top: 3px; }

.link-btn {
    background: none;
    border: none;
    color: var(--primary);
    font: inherit;
    font-size: 12px;
    cursor: pointer;
    padding: 0;
}

/* ============ CARDS ============ */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    margin-bottom: 18px;
    overflow: hidden;
}

.card__header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
}
.card__title { margin: 0; font-size: 15px; font-weight: 650; }
.card__body { padding: 18px; }
.card__footer { padding: 12px 18px; border-top: 1px solid var(--border); background: var(--surface-alt); }

/* ============ STAT CARDS ============ */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    display: flex;
    align-items: center;
    gap: 14px;
    box-shadow: var(--shadow-sm);
}

.stat-card__icon {
    width: 44px; height: 44px;
    display: grid; place-items: center;
    border-radius: var(--radius-sm);
    background: var(--primary-light);
    color: var(--primary-dark);
    flex-shrink: 0;
}
.stat-card__icon svg { width: 21px; height: 21px; }
.stat-card__icon--success { background: var(--success-light); color: var(--success); }
.stat-card__icon--warning { background: var(--warning-light); color: var(--warning); }
.stat-card__icon--danger  { background: var(--danger-light); color: var(--danger); }
.stat-card__icon--info    { background: var(--info-light); color: var(--info); }

.stat-card__value { font-size: 22px; font-weight: 700; line-height: 1.15; }
.stat-card__label { font-size: 12.5px; color: var(--text-muted); }
.stat-card__delta { font-size: 11.5px; margin-top: 2px; }
.stat-card__delta--up { color: var(--success); }
.stat-card__delta--down { color: var(--danger); }

/* ============ TABLES ============ */

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
}

.table th {
    text-align: left;
    padding: 11px 14px;
    background: var(--surface-alt);
    border-bottom: 1px solid var(--border);
    font-weight: 650;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .03em;
    color: var(--text-muted);
    white-space: nowrap;
}

.table td {
    padding: 11px 14px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.table tbody tr:hover { background: var(--surface-alt); }
.table tbody tr:last-child td { border-bottom: none; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .actions { white-space: nowrap; text-align: right; }

.table-empty {
    padding: 40px 20px;
    text-align: center;
    color: var(--text-faint);
}

/* ============ BADGES ============ */

.badge {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 12px;
    font-size: 11.5px;
    font-weight: 600;
    white-space: nowrap;
    line-height: 1.5;
}

.badge-primary   { background: var(--primary-light); color: var(--primary-dark); }
.badge-success   { background: var(--success-light); color: var(--success); }
.badge-warning   { background: var(--warning-light); color: var(--warning); }
.badge-danger    { background: var(--danger-light); color: var(--danger); }
.badge-info      { background: var(--info-light); color: var(--info); }
.badge-secondary { background: var(--border); color: var(--text-muted); }
.badge-dark      { background: #334155; color: #fff; }

/* ============ BUTTONS ============ */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 9px 16px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 13.5px;
    font-weight: 600;
    line-height: 1.2;
    cursor: pointer;
    text-decoration: none;
    transition: background .15s, opacity .15s;
    white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn:disabled, .btn.is-disabled { opacity: .55; cursor: not-allowed; pointer-events: none; }
.btn svg { width: 16px; height: 16px; }

.btn-primary   { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success   { background: var(--success); color: #fff; }
.btn-success:hover { filter: brightness(.92); }
.btn-warning   { background: var(--warning); color: #fff; }
.btn-warning:hover { filter: brightness(.92); }
.btn-danger    { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(.92); }
.btn-secondary { background: var(--surface-alt); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-outline   { background: transparent; color: var(--primary); border-color: var(--primary); }
.btn-outline:hover { background: var(--primary-light); }
.btn-ghost     { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-alt); color: var(--text); }

.btn-sm { padding: 6px 11px; font-size: 12.5px; }
.btn-lg { padding: 12px 22px; font-size: 15px; }
.btn-block { width: 100%; }
.btn-icon { padding: 7px; width: 32px; height: 32px; }

.btn-group { display: inline-flex; gap: 6px; flex-wrap: wrap; }

/* ============ FORMS ============ */

.form-group { margin-bottom: 15px; }

.form-label {
    display: block;
    margin-bottom: 5px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
}
.form-label .req { color: var(--danger); }

.form-control {
    width: 100%;
    padding: 9px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 14px;
    color: var(--text);
    transition: border-color .15s, box-shadow .15s;
}
.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .13);
}
.form-control:disabled { background: var(--surface-alt); color: var(--text-faint); cursor: not-allowed; }
.form-control.is-invalid { border-color: var(--danger); }

textarea.form-control { min-height: 84px; resize: vertical; }
select.form-control { cursor: pointer; }

.form-hint { margin-top: 4px; font-size: 12px; color: var(--text-faint); }
.form-error { margin-top: 4px; font-size: 12px; color: var(--danger); }

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 14px;
}

.form-check { display: flex; align-items: center; gap: 8px; margin-bottom: 9px; }
.form-check input { width: 16px; height: 16px; cursor: pointer; accent-color: var(--primary); }
.form-check label { cursor: pointer; font-size: 13.5px; }

.form-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    padding-top: 6px;
}

/* ============ FILTERS ============ */

.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: flex-end;
    padding: 14px 18px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 16px;
}
.filters .form-group { margin-bottom: 0; min-width: 150px; flex: 1 1 150px; }

/* ============ ALERTS ============ */

.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    font-size: 13.5px;
    border-left: 3px solid;
}
.alert-success { background: var(--success-light); color: var(--success); border-color: var(--success); }
.alert-danger  { background: var(--danger-light); color: var(--danger); border-color: var(--danger); }
.alert-warning { background: var(--warning-light); color: var(--warning); border-color: var(--warning); }
.alert-info    { background: var(--info-light); color: var(--info); border-color: var(--info); }

/* ============ MODAL ============ */

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .55);
    display: grid;
    place-items: center;
    z-index: 500;
    padding: 20px;
}

.modal {
    width: 100%;
    max-width: 520px;
    max-height: 88vh;
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal__header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}
.modal__header h3 { margin: 0; font-size: 16px; }

.modal__close {
    background: none;
    border: none;
    font-size: 24px;
    line-height: 1;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0 4px;
}
.modal__close:hover { color: var(--text); }

.modal__body { padding: 20px; overflow-y: auto; flex: 1; }
.modal__footer {
    padding: 14px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}
.modal__footer:empty { display: none; }

/* ============ TOASTS ============ */

.toast-stack {
    position: fixed;
    bottom: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 900;
    max-width: 340px;
}

.toast {
    padding: 12px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 3px solid var(--primary);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    font-size: 13.5px;
    animation: toastIn .22s ease;
}
.toast--success { border-left-color: var(--success); }
.toast--error   { border-left-color: var(--danger); }
.toast--warning { border-left-color: var(--warning); }

@keyframes toastIn {
    from { opacity: 0; transform: translateX(24px); }
    to   { opacity: 1; transform: translateX(0); }
}

/* ============ PAGINATION ============ */

.pagination {
    display: flex;
    gap: 5px;
    list-style: none;
    padding: 0;
    margin: 18px 0 0;
    flex-wrap: wrap;
}
.page-link {
    display: block;
    padding: 7px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 13px;
    text-decoration: none;
}
.page-link:hover { background: var(--surface-alt); text-decoration: none; }
.page-item.active .page-link { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ============ BREADCRUMBS ============ */

.breadcrumbs {
    display: flex;
    gap: 7px;
    align-items: center;
    margin-bottom: 14px;
    font-size: 12.5px;
    color: var(--text-muted);
    flex-wrap: wrap;
}
.breadcrumbs__sep { color: var(--text-faint); }
.breadcrumbs__current { color: var(--text); font-weight: 600; }

/* ============ OFFLINE BANNER ============ */

.offline-banner {
    padding: 9px 20px;
    background: var(--warning);
    color: #fff;
    font-size: 13px;
    text-align: center;
    font-weight: 500;
}

/* ============ UTILITIES ============ */

.text-muted { color: var(--text-muted); }
.text-faint { color: var(--text-faint); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-sm { font-size: 12.5px; }
.text-lg { font-size: 16px; }
.fw-600 { font-weight: 600; }
.fw-700 { font-weight: 700; }
.nowrap { white-space: nowrap; }
.mono { font-variant-numeric: tabular-nums; font-family: ui-monospace, monospace; }

.mt-0 { margin-top: 0; } .mt-1 { margin-top: 8px; } .mt-2 { margin-top: 16px; } .mt-3 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; } .mb-1 { margin-bottom: 8px; } .mb-2 { margin-bottom: 16px; } .mb-3 { margin-bottom: 24px; }

.d-flex { display: flex; }
.d-grid { display: grid; }
.d-none { display: none; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-end { justify-content: flex-end; }
.gap-1 { gap: 8px; } .gap-2 { gap: 16px; }
.flex-1 { flex: 1; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }

.spinner {
    width: 18px; height: 18px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin .7s linear infinite;
    display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state {
    padding: 50px 20px;
    text-align: center;
    color: var(--text-faint);
}
.empty-state__icon { width: 44px; height: 44px; margin-bottom: 12px; opacity: .5; }

/* ============ RESPONSIVE ============ */

@media (max-width: 1024px) {
    .sidebar { transform: translateX(-100%); transition: transform .25s ease; }
    .sidebar.is-open { transform: translateX(0); }
    .app-main { margin-left: 0; }
    .topbar__burger { display: flex; }
}

@media (max-width: 640px) {
    .content { padding: 14px; }
    .topbar { padding: 0 14px; gap: 8px; }
    .topbar__title { font-size: 15px; }
    .user-chip__name, .topbar__clock { display: none; }
    .stats-grid { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
    .stat-card { padding: 12px; gap: 10px; }
    .stat-card__value { font-size: 18px; }
    .stat-card__icon { width: 36px; height: 36px; }
    .card__body { padding: 14px; }
    .table th, .table td { padding: 9px 10px; font-size: 12.5px; }
    .filters { padding: 12px; }
    .toast-stack { left: 14px; right: 14px; max-width: none; }
    .modal { max-height: 92vh; }
}
