:root {
  --brand-primary: #6d28d9;
  --brand-primary-dark: #5b21b6;
  --brand-bg: #f4f5fb;
  --status-new: #16a34a;
  --status-processing: #d97706;
  --status-out: #2563eb;
  --status-delivered: #0d9488;
  --status-failed: #dc2626;
  --status-cancelled: #6b7280;
  --sidebar-w: 250px;
}

body {
  background: var(--brand-bg);
  font-family: "Segoe UI", Roboto, -apple-system, BlinkMacSystemFont, sans-serif;
  color: #1f2430;
}

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

.sidebar {
  width: var(--sidebar-w);
  background: #171327;
  color: #d9d5e8;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  transition: transform .2s ease;
}
.sidebar .brand { padding: 1.25rem 1.25rem 1rem; display: flex; align-items: center; gap: .6rem; }
.sidebar .brand-name { font-weight: 700; color: #fff; font-size: 1.05rem; line-height: 1.1; }
.sidebar .brand-sub { font-size: .7rem; color: #a89fcf; }
.sidebar nav { padding: .5rem .75rem 2rem; }
.sidebar .nav-section { font-size: .68rem; text-transform: uppercase; letter-spacing: .06em; color: #6f6790; margin: 1rem .5rem .35rem; }
.sidebar a.nav-link { color: #cbc4e6; border-radius: .5rem; padding: .5rem .75rem; display: flex; align-items: center; gap: .6rem; font-size: .9rem; }
.sidebar a.nav-link:hover { background: #241d3c; color: #fff; }
.sidebar a.nav-link.active { background: var(--brand-primary); color: #fff; }
.sidebar a.nav-link .badge { margin-left: auto; }

.main-content { flex: 1; min-width: 0; }
.topbar {
  background: #fff;
  border-bottom: 1px solid #e7e5f0;
  padding: .75rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 20;
}
.page-body { padding: 1.5rem; }

/* ---------- Cards ---------- */
.stat-card {
  border-radius: 1rem;
  padding: 1.1rem 1.25rem;
  color: #fff;
  min-height: 96px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-decoration: none;
  transition: transform .15s ease, box-shadow .15s ease;
  box-shadow: 0 6px 16px rgba(20, 15, 50, .07);
}
.stat-card:hover { transform: translateY(-2px); box-shadow: 0 10px 22px rgba(20,15,50,.14); color: #fff; }
.stat-card .stat-value { font-size: 1.9rem; font-weight: 700; line-height: 1; }
.stat-card .stat-label { font-size: .82rem; opacity: .92; margin-top: .35rem; }
.stat-card.bg-new { background: linear-gradient(135deg,#16a34a,#15803d); }
.stat-card.bg-processing { background: linear-gradient(135deg,#f59e0b,#d97706); }
.stat-card.bg-out { background: linear-gradient(135deg,#3b82f6,#2563eb); }
.stat-card.bg-delivered { background: linear-gradient(135deg,#14b8a6,#0d9488); }
.stat-card.bg-failed { background: linear-gradient(135deg,#ef4444,#dc2626); }
.stat-card.bg-cancelled { background: linear-gradient(135deg,#9ca3af,#6b7280); }
.stat-card.bg-muted { background: #ffffff; color:#1f2430; border:1px solid #eceaf5; box-shadow:none; }
.stat-card.bg-muted .stat-label{color:#8a84a3;}

.card { border: 1px solid #edebf6; border-radius: .9rem; box-shadow: 0 2px 10px rgba(20,15,50,.03); }
.card-header { background: #fff; border-bottom: 1px solid #f0eef8; font-weight: 600; }

/* ---------- Status badges ---------- */
.badge-status { font-weight: 600; font-size: .74rem; padding: .38em .7em; border-radius: 999px; }
.badge-status-new_order { background:#dcfce7; color:#15803d; }
.badge-status-accepted { background:#dbeafe; color:#1d4ed8; }
.badge-status-processing { background:#fef3c7; color:#b45309; }
.badge-status-ready_for_delivery { background:#fef3c7; color:#b45309; }
.badge-status-assigned { background:#e0e7ff; color:#4338ca; }
.badge-status-out_for_delivery { background:#dbeafe; color:#1d4ed8; }
.badge-status-delivered { background:#ccfbf1; color:#0f766e; }
.badge-status-failed_delivery { background:#fee2e2; color:#b91c1c; }
.badge-status-cancelled { background:#e5e7eb; color:#4b5563; }
.badge-status-returned { background:#e5e7eb; color:#4b5563; }

.badge-status.payment-pending { background:#fef3c7; color:#b45309; }
.badge-status.payment-paid { background:#dcfce7; color:#15803d; }
.badge-status.payment-failed { background:#fee2e2; color:#b91c1c; }
.badge-status.payment-refunded { background:#e5e7eb; color:#4b5563; }

/* ---------- Tables ---------- */
.table-orders thead th { font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; color: #7c7796; border-bottom-width: 1px; white-space: nowrap; }
.table-orders td { vertical-align: middle; font-size: .89rem; }
.table-orders tbody tr:hover { background: #faf9ff; }

.quick-filters .btn { border-radius: 999px; font-size: .82rem; }
.quick-filters .btn.active { background: var(--brand-primary); border-color: var(--brand-primary); color: #fff; }

/* ---------- Timeline ---------- */
.timeline { position: relative; padding-left: 1.75rem; }
.timeline::before { content: ""; position: absolute; left: .4rem; top: .2rem; bottom: .2rem; width: 2px; background: #e6e3f4; }
.timeline-item { position: relative; padding-bottom: 1.25rem; }
.timeline-item::before { content: ""; position: absolute; left: -1.75rem; top: .15rem; width: .7rem; height: .7rem; border-radius: 50%; background: var(--brand-primary); box-shadow: 0 0 0 3px #ece7fb; }
.timeline-item .t-time { font-size: .74rem; color: #8a84a3; }
.timeline-item .t-title { font-weight: 600; font-size: .9rem; }
.timeline-item .t-remark { font-size: .82rem; color: #6b6684; }

/* ---------- Login ---------- */
.auth-wrap { min-height: 100vh; display:flex; align-items:center; justify-content:center; background: radial-gradient(circle at top left, #7c3aed, #2a1a5e 60%); padding: 1.5rem; }
.auth-card { max-width: 400px; width:100%; background:#fff; border-radius:1.2rem; padding: 2.25rem 2rem; box-shadow: 0 24px 60px rgba(0,0,0,.35); }
.auth-logo { width:54px; height:54px; border-radius:14px; background:var(--brand-primary); color:#fff; display:flex; align-items:center; justify-content:center; font-size:1.5rem; margin-bottom:1rem; }

/* ---------- Driver portal (mobile-first) ---------- */
.driver-shell { max-width: 480px; margin: 0 auto; min-height: 100vh; background:#f4f5fb; padding-bottom: 5.5rem; }
.driver-topbar { background: var(--brand-primary); color:#fff; padding: 1rem 1.1rem 1.4rem; border-radius: 0 0 1.4rem 1.4rem; }
.driver-order-card { border-radius: 1rem; border:1px solid #edebf6; background:#fff; padding:1rem; margin-bottom: .9rem; box-shadow: 0 3px 10px rgba(20,15,50,.05); }
.driver-btn { border-radius: .8rem; font-weight:600; padding: .7rem; font-size: .95rem; }
.driver-sticky-actions { position: sticky; bottom: 0; background: #fff; border-top: 1px solid #eee; padding: .75rem 1rem calc(.75rem + env(safe-area-inset-bottom)); display:flex; gap:.6rem; z-index: 30; }
.bottom-nav { position: fixed; bottom:0; left:0; right:0; max-width:480px; margin:0 auto; background:#fff; border-top:1px solid #eee; display:flex; z-index: 40; }
.bottom-nav a { flex:1; text-align:center; padding:.6rem 0; color:#8a84a3; font-size:.72rem; text-decoration:none; }
.bottom-nav a.active { color: var(--brand-primary); font-weight:600; }
.bottom-nav a i { display:block; font-size:1.2rem; margin-bottom: .1rem; }

@media (max-width: 991px) {
  .sidebar { position: fixed; z-index: 50; transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
}

/* =====================================================================
   Modernization layer — refined SaaS-admin polish on top of the design
   system above. Additive only: nothing above this line was removed, so
   existing markup keeps working even where it hasn't picked up the new
   classes yet.
   ===================================================================== */

:root {
  --ink-900: #14101f;
  --ink-700: #3f3a52;
  --ink-500: #6b6684;
  --ink-300: #a29cbd;
  --border-soft: #ece9f6;
  --shadow-sm: 0 1px 2px rgba(20, 15, 50, .04);
  --shadow-md: 0 4px 14px rgba(20, 15, 50, .06);
  --shadow-lg: 0 12px 32px rgba(20, 15, 50, .12);
  --radius-sm: .55rem;
  --radius-md: .85rem;
  --sidebar-w-collapsed: 76px;
}

* { scrollbar-width: thin; }

body { font-size: .925rem; -webkit-font-smoothing: antialiased; }

a { text-decoration: none; }

.card { box-shadow: var(--shadow-sm); }
.card-header { font-size: .88rem; letter-spacing: .01em; }

.btn { font-weight: 500; border-radius: var(--radius-sm); }
.btn:focus-visible, .form-control:focus, .form-select:focus, a:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(109, 40, 217, .18);
}
.btn-primary { background: var(--brand-primary); border-color: var(--brand-primary); }
.btn-primary:hover { background: var(--brand-primary-dark); border-color: var(--brand-primary-dark); }
.btn-outline-primary { color: var(--brand-primary); border-color: #d9cff5; }
.btn-outline-primary:hover { background: var(--brand-primary); border-color: var(--brand-primary); }

/* ---------- Sidebar: collapsible desktop mode ---------- */
.sidebar { transition: width .18s ease, transform .2s ease; }
.sidebar .brand { position: relative; }
.sidebar-collapse-btn {
  border: none; background: transparent; color: #a89fcf; padding: .3rem .5rem;
  border-radius: .4rem; margin-left: auto; display: none;
}
.sidebar-collapse-btn:hover { background: #241d3c; color: #fff; }
@media (min-width: 992px) { .sidebar-collapse-btn { display: inline-flex; } }

html.sb-collapsed .sidebar { width: var(--sidebar-w-collapsed); }
html.sb-collapsed .sidebar .brand-name,
html.sb-collapsed .sidebar .brand-sub,
html.sb-collapsed .sidebar .nav-section,
html.sb-collapsed .sidebar .nav-link span.nav-label,
html.sb-collapsed .sidebar .nav-link .badge { display: none; }
html.sb-collapsed .sidebar .brand { justify-content: center; padding: 1.1rem .5rem; }
html.sb-collapsed .sidebar .sidebar-collapse-btn { transform: rotate(180deg); margin: 0 auto; }
html.sb-collapsed .sidebar nav { padding-left: .5rem; padding-right: .5rem; }
html.sb-collapsed .sidebar a.nav-link { justify-content: center; padding: .6rem; }

.sidebar a.nav-link { transition: background .12s ease, color .12s ease; }

/* ---------- Topbar / breadcrumb ---------- */
.topbar-heading { line-height: 1.15; }
.breadcrumb-trail { font-size: .74rem; color: var(--ink-500); margin-bottom: .1rem; display: flex; align-items: center; gap: .35rem; }
.breadcrumb-trail .sep { opacity: .5; }

/* ---------- Dropdown polish ---------- */
.dropdown-menu { border: 1px solid var(--border-soft); box-shadow: var(--shadow-lg); border-radius: var(--radius-md); padding: .4rem; }
.dropdown-item { border-radius: .5rem; font-size: .86rem; padding: .45rem .65rem; }
.dropdown-item:hover, .dropdown-item:focus { background: #f4f1fc; }
.dropdown-item.text-danger:hover { background: #fef2f2; }
.dropdown-item form { margin: 0; }

/* ---------- Table polish ---------- */
.table-orders tbody tr { transition: background .1s ease; }
.table-orders thead th { padding-top: .8rem; padding-bottom: .8rem; }

/* ---------- Empty states ---------- */
.empty-state { text-align: center; padding: 3rem 1.5rem; color: var(--ink-500); }
.empty-state i { font-size: 2.1rem; color: var(--ink-300); display: block; margin-bottom: .6rem; }
.empty-state .empty-title { font-weight: 600; color: var(--ink-700); margin-bottom: .25rem; }
.empty-state .empty-desc { font-size: .85rem; }

/* ---------- Form sections ---------- */
.form-section { border: 1px solid var(--border-soft); border-radius: var(--radius-md); padding: 1.25rem; margin-bottom: 1.1rem; background: #fff; }
.form-section-title { font-weight: 600; font-size: .88rem; color: var(--ink-700); margin-bottom: .9rem; display: flex; align-items: center; gap: .5rem; }
.form-section-title i { color: var(--brand-primary); }

/* ---------- Toasts ---------- */
.toast { border-radius: var(--radius-md); box-shadow: var(--shadow-lg); }

@media (max-width: 991px) {
  html.sb-collapsed .sidebar { width: var(--sidebar-w); }
  html.sb-collapsed .sidebar .brand-name, html.sb-collapsed .sidebar .brand-sub,
  html.sb-collapsed .sidebar .nav-section, html.sb-collapsed .sidebar .nav-link span.nav-label,
  html.sb-collapsed .sidebar .nav-link .badge { display: initial; }
  html.sb-collapsed .sidebar .brand { justify-content: flex-start; padding: 1.25rem 1.25rem 1rem; }
  html.sb-collapsed .sidebar a.nav-link { justify-content: flex-start; padding: .5rem .75rem; }
}
