/* ============================================
   ParcelFlow Pro — Professional Design System
   ============================================ */

:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-raised: #ffffff;
  --surface-muted: #f1f5f9;
  --text: #0f172a;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-tertiary: #94a3b8;
  --text-quaternary: #cbd5e1;
  --border: #e2e8f0;
  --border-light: #f1f5f9;
  --accent: #3b82f6;
  --accent-light: #eff6ff;
  --accent-dark: #1d4ed8;
  --positive: #10b981;
  --positive-light: #ecfdf5;
  --warning: #f59e0b;
  --warning-light: #fffbeb;
  --danger: #ef4444;
  --danger-light: #fef2f2;
  --info: #06b6d4;
  --info-light: #ecfeff;
  --purple: #8b5cf6;
  --purple-light: #f5f3ff;
  --radius: 16px;
  --radius-lg: 20px;
  --radius-sm: 12px;
  --radius-xs: 8px;
  --shadow-sm: 0 1px 2px rgba(15,23,42,0.04);
  --shadow: 0 1px 3px rgba(15,23,42,0.06), 0 4px 12px rgba(15,23,42,0.04);
  --shadow-md: 0 4px 16px rgba(15,23,42,0.08);
  --shadow-lg: 0 8px 32px rgba(15,23,42,0.12);
  --font-sans: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a;
    --surface: #1e293b;
    --surface-raised: #334155;
    --surface-muted: #1e293b;
    --text: #f8fafc;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-tertiary: #64748b;
    --text-quaternary: #475569;
    --border: #334155;
    --border-light: #1e293b;
    --accent: #60a5fa;
    --accent-light: rgba(59,130,246,0.15);
    --accent-dark: #3b82f6;
    --positive-light: rgba(16,185,129,0.15);
    --warning-light: rgba(245,158,11,0.15);
    --danger-light: rgba(239,68,68,0.15);
    --info-light: rgba(6,182,212,0.15);
    --purple-light: rgba(139,92,246,0.15);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; margin:0; padding:0; }
html, body { height: 100%; font-family: var(--font-sans); background: var(--bg); color: var(--text); overscroll-behavior-y: none; }

#app { max-width: 520px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; position: relative; }

/* Utilities */
.hidden { display: none !important; }
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.gap-4 { gap: 4px; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.flex-1 { flex: 1; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-sm { font-size: 13px; }
.text-xs { font-size: 12px; }
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.font-bold { font-weight: 700; }
.mb-0 { margin-bottom: 0 !important; }
.mb-8 { margin-bottom: 8px; }
.mb-12 { margin-bottom: 12px; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mt-20 { margin-top: 20px; }
.p-16 { padding: 16px; }
.p-20 { padding: 20px; }
.p-24 { padding: 24px; }
.w-full { width: 100%; }
.row { display: flex; }
.row.gap-12 { gap: 12px; }

/* Screens */
.screen { display: none; flex: 1; overflow-y: auto; padding: 16px; padding-bottom: 100px; animation: fadeIn 0.3s var(--ease-out); }
.screen.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* Header */
header {
  position: sticky; top: 0; z-index: 10;
  background: rgba(248,250,252,0.92); backdrop-filter: blur(16px) saturate(1.4); -webkit-backdrop-filter: blur(16px) saturate(1.4);
  border-bottom: 1px solid var(--border);
  padding: 14px 20px;
  display: flex; align-items: center; justify-content: space-between;
}
@media (prefers-color-scheme: dark) {
  header { background: rgba(15,23,42,0.92); }
}
header h1 { font-size: 18px; font-weight: 700; margin: 0; letter-spacing: -0.3px; }

.role-badge {
  font-size: 10px; font-weight: 700; padding: 4px 10px; border-radius: 999px;
  text-transform: uppercase; letter-spacing: 0.8px;
}
.role-badge.user { background: var(--accent-light); color: var(--accent); }
.role-badge.driver { background: var(--positive-light); color: var(--positive); }
.role-badge.admin { background: var(--purple-light); color: var(--purple); }

/* Badges */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 10px; border-radius: 999px;
  font-size: 11px; font-weight: 700; letter-spacing: 0.3px;
}
.badge-new { background: var(--accent-light); color: var(--accent); }
.badge-assigned { background: var(--warning-light); color: #b45309; }
.badge-pickup { background: var(--positive-light); color: #047857; }
.badge-transit { background: var(--info-light); color: #0e7490; }
.badge-out { background: var(--warning-light); color: #b45309; }
.badge-delivered { background: var(--positive-light); color: #047857; }
.badge-confirmed { background: var(--positive-light); color: #047857; }
.badge-cancelled { background: var(--danger-light); color: #b91c1c; }

/* Cards */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px; margin-bottom: 14px;
  box-shadow: var(--shadow-sm); transition: box-shadow 0.2s, transform 0.15s;
}
.card:hover { box-shadow: var(--shadow-md); }
.card-flat { background: var(--surface-muted); border: 1px solid var(--border-light); border-radius: var(--radius-sm); padding: 16px; }
.card-title {
  font-size: 11px; font-weight: 700; color: var(--text-tertiary);
  margin-bottom: 12px; text-transform: uppercase; letter-spacing: 0.6px;
}

/* Stat cards */
.stat-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 16px; }
.stat-row-4 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 16px; }
@media (min-width: 400px) { .stat-row-4 { grid-template-columns: repeat(4, 1fr); } }

.stat-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 14px;
  box-shadow: var(--shadow-sm); position: relative; overflow: hidden;
}
.stat-card::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: var(--accent); border-radius: var(--radius) var(--radius) 0 0;
}
.stat-card.green::before { background: var(--positive); }
.stat-card.amber::before { background: var(--warning); }
.stat-card.red::before { background: var(--danger); }
.stat-card.purple::before { background: var(--purple); }
.stat-card .icon-wrap {
  width: 40px; height: 40px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center; margin-bottom: 10px;
  background: var(--accent-light); color: var(--accent);
}
.stat-card.green .icon-wrap { background: var(--positive-light); color: var(--positive); }
.stat-card.amber .icon-wrap { background: var(--warning-light); color: var(--warning); }
.stat-card.red .icon-wrap { background: var(--danger-light); color: var(--danger); }
.stat-card.purple .icon-wrap { background: var(--purple-light); color: var(--purple); }
.stat-card .num {
  font-size: 28px; font-weight: 700; color: var(--text-primary);
  font-variant-numeric: tabular-nums; letter-spacing: -0.8px; line-height: 1.1;
}
.stat-card .label { font-size: 12px; color: var(--text-tertiary); margin-top: 4px; font-weight: 500; }
.stat-card .trend {
  font-size: 11px; font-weight: 600; margin-top: 6px; display: inline-flex; align-items: center; gap: 3px;
}
.stat-card .trend.up { color: var(--positive); }
.stat-card .trend.down { color: var(--danger); }

/* Inputs */
.input, .select {
  width: 100%; padding: 12px 14px; border: 1.5px solid var(--border);
  border-radius: var(--radius-xs); font-size: 15px; font-family: inherit;
  background: var(--surface); color: var(--text); margin-bottom: 12px;
  outline: none; transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus, .select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 12%, transparent);
}
.input::placeholder { color: var(--text-quaternary); }
.select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 14px center; padding-right: 40px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 18px; border-radius: var(--radius-xs); border: none;
  font-size: 15px; font-weight: 600; font-family: inherit;
  cursor: pointer; transition: transform 0.08s, opacity 0.15s, box-shadow 0.15s;
  touch-action: manipulation;
}
.btn:active { transform: scale(0.98); }
.btn-block { width: 100%; }
.btn-primary { background: var(--accent); color: #fff; box-shadow: 0 1px 3px rgba(59,130,246,0.3); }
.btn-primary:hover { background: var(--accent-dark); }
.btn-secondary { background: var(--surface-muted); color: var(--text-secondary); border: 1.5px solid var(--border); }
.btn-secondary:hover { background: var(--border-light); }
.btn-positive { background: var(--positive); color: #fff; }
.btn-positive:hover { opacity: 0.92; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--surface-muted); }
.btn-sm { padding: 8px 14px; font-size: 13px; }

/* Avatar */
.avatar {
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--border); display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; overflow: hidden; font-size: 15px; font-weight: 700; color: var(--text-secondary);
}
.avatar svg { width: 22px; height: 22px; color: var(--text-secondary); }
.avatar-lg { width: 68px; height: 68px; font-size: 24px; }
.avatar-lg svg { width: 30px; height: 30px; }
.avatar-sm { width: 34px; height: 34px; font-size: 13px; }

/* Lists */
.list-item {
  display: flex; align-items: center; gap: 14px;
  padding: 14px; border-radius: var(--radius-sm);
  background: var(--surface); border: 1px solid var(--border);
  margin-bottom: 10px; cursor: pointer; transition: all 0.15s;
  box-shadow: var(--shadow-sm);
}
.list-item:hover { box-shadow: var(--shadow-md); border-color: var(--accent); transform: translateY(-1px); }
.list-item .content { flex: 1; min-width: 0; }
.list-item .title { font-size: 15px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item .meta { font-size: 12px; color: var(--text-tertiary); margin-top: 3px; font-weight: 500; }

/* Tables */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); box-shadow: var(--shadow-sm); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-size: 11px; font-weight: 700; color: var(--text-tertiary); text-transform: uppercase; letter-spacing: 0.5px; background: var(--surface-muted); }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface-muted); }

/* Map */
.map {
  height: 220px; border-radius: var(--radius); border: 1px solid var(--border);
  position: relative; overflow: hidden; background: var(--surface-muted);
}
.map-grid { position: absolute; inset: 0; opacity: 0.4; background-image: linear-gradient(var(--border) 1px, transparent 1px), linear-gradient(90deg, var(--border) 1px, transparent 1px); background-size: 40px 40px; }
.map-route { position: absolute; top: 50%; left: 10%; right: 10%; height: 4px; background: var(--border); border-radius: 2px; transform: translateY(-50%); }
.map-route .progress { height: 100%; background: var(--positive); border-radius: 2px; transition: width 0.8s var(--ease-out); }
.map-pin { position: absolute; width: 34px; height: 34px; border-radius: 50%; background: var(--text); color: var(--bg); display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 800; transform: translate(-50%, -50%); box-shadow: var(--shadow-md); }
.map-pin.start { left: 10%; top: 50%; }
.map-pin.end { left: 90%; top: 50%; }
.map-pin.driver { left: 55%; top: 50%; background: var(--accent); transition: left 0.8s var(--ease-out); z-index: 2; }

/* Timeline */
.timeline { position: relative; padding-left: 28px; }
.timeline::before { content: ''; position: absolute; left: 8px; top: 6px; bottom: 6px; width: 2px; background: var(--border); border-radius: 1px; }
.t-item { position: relative; margin-bottom: 18px; }
.t-item:last-child { margin-bottom: 0; }
.t-item::before { content: ''; position: absolute; left: -24px; top: 4px; width: 12px; height: 12px; border-radius: 50%; background: var(--border); border: 3px solid var(--surface); transition: background 0.3s; }
.t-item.done::before { background: var(--positive); }
.t-item.active::before { background: var(--accent); border-color: color-mix(in srgb, var(--accent) 25%, transparent); }
.t-time { font-size: 12px; color: var(--text-tertiary); margin-bottom: 2px; font-weight: 500; }
.t-text { font-size: 14px; color: var(--text); font-weight: 500; }

/* Stars */
.stars { display: flex; gap: 8px; justify-content: center; margin: 12px 0; }
.star { width: 40px; height: 40px; cursor: pointer; color: var(--border); transition: color 0.15s, transform 0.1s; }
.star:active { transform: scale(0.88); }
.star.filled { color: var(--warning); }

/* Bottom Nav */
.bottom-nav {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 520px;
  background: rgba(248,250,252,0.95); backdrop-filter: blur(16px) saturate(1.4); -webkit-backdrop-filter: blur(16px) saturate(1.4);
  border-top: 1px solid var(--border);
  display: flex; justify-content: space-around;
  padding: 8px 0 calc(10px + env(safe-area-inset-bottom));
  z-index: 20; box-shadow: 0 -4px 20px rgba(15,23,42,0.04);
}
@media (prefers-color-scheme: dark) {
  .bottom-nav { background: rgba(15,23,42,0.95); }
}
.nav-item {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: 11px; color: var(--text-tertiary); cursor: pointer;
  padding: 5px 16px; border-radius: 12px;
  transition: all 0.15s; background: none; border: none;
  font-family: inherit; font-weight: 600; touch-action: manipulation;
}
.nav-item.active { color: var(--accent); background: var(--accent-light); }
.nav-item svg { width: 22px; height: 22px; }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,0.5);
  z-index: 100; display: none; align-items: flex-end; justify-content: center;
  animation: fadeIn 0.2s;
}
.modal-overlay.active { display: flex; }
.modal-sheet {
  background: var(--surface); border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto;
  padding: 24px; animation: slideUp 0.35s var(--ease-out);
  box-shadow: var(--shadow-lg);
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.modal-header h3 { margin: 0; font-size: 18px; font-weight: 700; }
.modal-close { background: var(--surface-muted); border: none; color: var(--text-tertiary); cursor: pointer; padding: 8px; border-radius: 10px; width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; }
.modal-close:hover { background: var(--border); }

/* Toast */
.toast {
  position: fixed; top: 20px; left: 50%;
  transform: translateX(-50%) translateY(-30px);
  background: var(--text); color: var(--bg);
  padding: 12px 24px; border-radius: 999px;
  font-size: 14px; font-weight: 600;
  opacity: 0; pointer-events: none;
  transition: all 0.35s var(--ease-out);
  z-index: 50; box-shadow: var(--shadow-lg);
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Search */
.search-bar {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); padding: 11px 14px;
  margin-bottom: 14px; box-shadow: var(--shadow-sm);
}
.search-bar svg { width: 18px; height: 18px; color: var(--text-tertiary); flex-shrink: 0; }
.search-bar input { flex: 1; border: none; background: transparent; font-size: 15px; font-family: inherit; color: var(--text); outline: none; }
.search-bar input::placeholder { color: var(--text-quaternary); }

/* Charts */
.chart-bar { display: flex; align-items: flex-end; gap: 10px; height: 140px; padding: 10px 0; }
.chart-bar-item { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.chart-bar-item .bar { width: 100%; background: var(--accent); border-radius: 6px 6px 0 0; min-height: 4px; transition: height 0.6s var(--ease-out); opacity: 0.85; }
.chart-bar-item .bar:hover { opacity: 1; }
.chart-bar-item .label { font-size: 11px; color: var(--text-tertiary); font-weight: 600; }

/* Empty */
.empty { text-align: center; padding: 60px 20px; color: var(--text-tertiary); }
.empty svg { width: 52px; height: 52px; margin-bottom: 14px; color: var(--border); }

/* Auth */
.auth-screen {
  display: none; flex: 1; flex-direction: column; justify-content: center;
  padding: 28px; animation: fadeIn 0.4s var(--ease-out); min-height: 100dvh;
}
.auth-screen.active { display: flex; }
.auth-logo {
  width: 72px; height: 72px; margin: 0 auto 24px;
  border-radius: 20px; background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 24px rgba(59,130,246,0.3);
}
.auth-logo svg { width: 36px; height: 36px; color: #fff; }
.auth-title { font-size: 26px; font-weight: 800; text-align: center; margin-bottom: 6px; letter-spacing: -0.5px; }
.auth-subtitle { font-size: 15px; color: var(--text-tertiary); text-align: center; margin-bottom: 32px; font-weight: 500; }
.auth-toggle { text-align: center; margin-top: 20px; font-size: 14px; color: var(--text-secondary); font-weight: 500; }
.auth-toggle button { background: none; border: none; color: var(--accent); font-weight: 700; cursor: pointer; font-size: inherit; }

/* Parcel ID */
.parcel-id { font-family: var(--font-mono); font-size: 16px; letter-spacing: 1.5px; color: var(--text); user-select: all; font-weight: 600; }

/* Report cards */
.report-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
}
.report-card h4 { font-size: 15px; font-weight: 700; margin-bottom: 14px; color: var(--text); }
.report-row { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border-light); }
.report-row:last-child { border-bottom: none; }
.report-row .label { font-size: 13px; color: var(--text-secondary); font-weight: 500; }
.report-row .value { font-size: 14px; font-weight: 700; color: var(--text); }

/* Scrollbar */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* Section header */
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.section-header h3 { font-size: 16px; font-weight: 700; color: var(--text); }
.section-header .link { font-size: 13px; color: var(--accent); font-weight: 600; cursor: pointer; background: none; border: none; }

/* Extra */
.mt-10 { margin-top: 10px; }
.p-24 { padding: 24px; }
.avatar-lg { width: 68px; height: 68px; font-size: 24px; }
.text-tertiary { color: var(--text-tertiary); }
.text-secondary { color: var(--text-secondary); }