/* ===== PostCI Tracking v3 — Design System ===== */
@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@400;500;600;700;800&family=DM+Sans:ital,wght@0,400;0,500;0,600;1,400&display=swap');

:root {
  --orange: #E85D04;
  --orange-light: #F48C06;
  --orange-glow: rgba(232,93,4,.12);
  --dark: #1A1410;
  --dark-2: #2D2620;
  --text: #3D3530;
  --text-2: #7A7068;
  --text-3: #A89E96;
  --bg: #FDFBF7;
  --bg-2: #F5F0EA;
  --bg-3: #EDE6DD;
  --card: #FFFFFF;
  --line: #E8E0D8;
  --green: #2D6A4F;
  --green-bg: #D8F3DC;
  --red: #D62828;
  --red-bg: #FFE0E0;
  --yellow: #E9C46A;
  --yellow-bg: #FFF8E1;
  --blue: #0077B6;
  --blue-bg: #D4EEFF;
  --shadow-sm: 0 1px 3px rgba(26,20,16,.06);
  --shadow: 0 4px 16px rgba(26,20,16,.08);
  --shadow-lg: 0 12px 40px rgba(26,20,16,.12);
  --radius: 12px;
  --radius-lg: 20px;
  --font: 'DM Sans', system-ui, sans-serif;
  --font-display: 'Outfit', system-ui, sans-serif;
  --transition: .2s cubic-bezier(.4,0,.2,1);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}

h1, h2, h3, h4, h5 { font-family: var(--font-display); font-weight: 700; line-height: 1.2; color: var(--dark); }

a { color: var(--orange); text-decoration: none; }
a:hover { color: var(--orange-light); }

.hidden { display: none !important; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 22px; border-radius: 999px; font-family: var(--font-display);
  font-weight: 600; font-size: 14px; cursor: pointer; border: none;
  transition: var(--transition); white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--orange); color: #fff; }
.btn-primary:hover { background: var(--orange-light); box-shadow: 0 4px 20px rgba(232,93,4,.3); }
.btn-secondary { background: var(--dark); color: #fff; }
.btn-secondary:hover { background: var(--dark-2); }
.btn-ghost { background: transparent; color: var(--text); border: 1.5px solid var(--line); }
.btn-ghost:hover { border-color: var(--orange); color: var(--orange); }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { opacity: .9; }
.btn-sm { padding: 6px 14px; font-size: 13px; }
.btn-lg { padding: 14px 32px; font-size: 16px; }
.btn-icon { width: 40px; height: 40px; padding: 0; border-radius: 50%; }

/* ===== Inputs ===== */
input, select, textarea {
  font-family: var(--font); font-size: 14px;
  padding: 10px 14px; border: 1.5px solid var(--line);
  border-radius: var(--radius); background: var(--card);
  color: var(--text); transition: var(--transition);
  width: 100%; outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--orange); box-shadow: 0 0 0 3px var(--orange-glow);
}
select { cursor: pointer; appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='7'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%237A7068' stroke-width='1.5' fill='none'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px; }
label { font-size: 13px; font-weight: 600; color: var(--text-2); display: block; margin-bottom: 4px; }

/* ===== Cards ===== */
.card {
  background: var(--card); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm); border: 1px solid var(--line);
  padding: 24px; transition: var(--transition);
}
.card:hover { box-shadow: var(--shadow); }

/* ===== Status badges ===== */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 12px; border-radius: 999px; font-size: 12px;
  font-weight: 600; letter-spacing: .02em; white-space: nowrap;
}
.badge-active { background: var(--blue-bg); color: var(--blue); }
.badge-live   { background: var(--orange-glow); color: var(--orange); animation: pulse-badge 2s infinite; }
.badge-done   { background: var(--green-bg); color: var(--green); }
.badge-error  { background: var(--red-bg); color: var(--red); }
.badge-warn   { background: var(--yellow-bg); color: #B8860B; }

@keyframes pulse-badge { 0%,100% { opacity: 1; } 50% { opacity: .7; } }

/* ===== Toast ===== */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--dark); color: #fff; padding: 12px 24px; border-radius: 999px;
  font-size: 14px; font-weight: 500; z-index: 999; opacity: 0;
  transition: opacity .3s, transform .3s; pointer-events: none;
  box-shadow: var(--shadow-lg);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-8px); }

/* ===== Tables ===== */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
thead th {
  text-align: left; padding: 10px 14px; font-size: 12px; font-weight: 600;
  color: var(--text-3); text-transform: uppercase; letter-spacing: .06em;
  border-bottom: 1px solid var(--line); white-space: nowrap;
}
tbody td { padding: 12px 14px; border-bottom: 1px solid var(--bg-2); vertical-align: middle; }
tbody tr:hover { background: var(--bg-2); }
tbody tr { cursor: pointer; transition: background .1s; }

/* ===== Modal ===== */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100; background: rgba(26,20,16,.5);
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(4px); padding: 16px;
}
.modal {
  background: var(--card); border-radius: var(--radius-lg); padding: 28px;
  max-width: 500px; width: 100%; box-shadow: var(--shadow-lg);
  max-height: 90vh; overflow-y: auto;
}
.modal h3 { margin-bottom: 20px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }

/* ===== Grid helpers ===== */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-sm { gap: 8px; }
.gap-md { gap: 16px; }
.gap-lg { gap: 24px; }

/* ===== Scanner overlay ===== */
.scan-overlay {
  position: fixed; inset: 0; z-index: 200; background: rgba(0,0,0,.95);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.scan-overlay .scan-close {
  position: absolute; top: 18px; right: 18px; background: none; border: none;
  color: #fff; font-size: 32px; cursor: pointer; z-index: 201;
}
.scan-overlay .scan-title { color: #fff; font-family: var(--font-display); font-size: 20px; margin-bottom: 16px; }
.scan-overlay .scan-hint { color: rgba(255,255,255,.5); font-size: 13px; margin-top: 16px; max-width: 300px; text-align: center; }
#scan-reader { width: 320px; max-width: 90vw; }

.btn-scan {
  background: none; border: 2px solid var(--line); border-radius: 50%;
  width: 44px; height: 44px; display: grid; place-items: center;
  cursor: pointer; flex-shrink: 0; transition: var(--transition);
}
.btn-scan:hover { border-color: var(--orange); color: var(--orange); }
.btn-scan svg { width: 20px; height: 20px; }

/* ===== QR display ===== */
.qr-result { text-align: center; margin-top: 14px; }
.qr-result img { max-width: 180px; margin: 8px auto; display: block; border-radius: 8px; }
.qr-actions { display: flex; gap: 10px; justify-content: center; margin-top: 10px; flex-wrap: wrap; }

/* ===== Stat cards ===== */
.stat-card {
  background: var(--card); border-radius: var(--radius-lg); padding: 20px;
  border: 1px solid var(--line); text-align: center;
}
.stat-card .stat-value { font-family: var(--font-display); font-size: 32px; font-weight: 800; color: var(--dark); }
.stat-card .stat-label { font-size: 13px; color: var(--text-2); margin-top: 4px; }

/* ===== Sidebar layout (admin/agent) ===== */
.app-layout { display: flex; min-height: 100dvh; }
.sidebar {
  width: 260px; background: var(--dark); color: #fff; padding: 24px 16px;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100dvh;
  overflow-y: auto; flex-shrink: 0;
}
.sidebar .brand { display: flex; align-items: center; gap: 12px; margin-bottom: 32px; padding: 0 8px; }
.sidebar .brand-icon { width: 40px; height: 40px; background: var(--orange); border-radius: 12px; display: grid; place-items: center; font-family: var(--font-display); font-weight: 800; font-size: 18px; }
.sidebar .brand-text { font-family: var(--font-display); font-weight: 700; font-size: 16px; }
.sidebar .brand-sub { font-size: 12px; color: rgba(255,255,255,.5); }
.sidebar nav { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.sidebar .nav-item {
  display: flex; align-items: center; gap: 12px; padding: 10px 14px;
  border-radius: var(--radius); color: rgba(255,255,255,.6);
  font-size: 14px; font-weight: 500; cursor: pointer; transition: var(--transition);
}
.sidebar .nav-item:hover { background: rgba(255,255,255,.08); color: #fff; }
.sidebar .nav-item.active { background: var(--orange); color: #fff; }
.sidebar .nav-item svg { width: 20px; height: 20px; flex-shrink: 0; }
.sidebar .sidebar-footer { margin-top: auto; padding-top: 16px; border-top: 1px solid rgba(255,255,255,.1); }
.sidebar .user-info { display: flex; align-items: center; gap: 10px; padding: 8px; }
.sidebar .user-avatar { width: 36px; height: 36px; background: var(--orange-light); border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 14px; }
.sidebar .user-name { font-size: 14px; font-weight: 600; }
.sidebar .user-role { font-size: 12px; color: rgba(255,255,255,.5); }

.main-content { flex: 1; padding: 28px 36px; max-width: 100%; overflow-x: hidden; }
.main-content h1 { margin-bottom: 24px; font-size: 28px; }

/* ===== Login page ===== */
.login-page {
  display: flex; align-items: center; justify-content: center;
  min-height: 100dvh; padding: 24px;
  background: linear-gradient(135deg, var(--bg) 0%, var(--bg-3) 100%);
}
.login-box {
  background: var(--card); border-radius: var(--radius-lg); padding: 40px;
  max-width: 400px; width: 100%; box-shadow: var(--shadow-lg);
  text-align: center;
}
.login-box .brand-icon { width: 56px; height: 56px; background: var(--orange); border-radius: 16px; display: grid; place-items: center; font-family: var(--font-display); font-weight: 800; font-size: 24px; color: #fff; margin: 0 auto 16px; }
.login-box h2 { margin-bottom: 8px; }
.login-box .subtitle { color: var(--text-2); margin-bottom: 28px; font-size: 14px; }
.login-box .field { margin-bottom: 16px; text-align: left; }
.login-box .btn { width: 100%; margin-top: 8px; }
.login-error { color: var(--red); font-size: 13px; margin-top: 8px; }

/* ===== Responsive ===== */
@media (max-width: 900px) {
  .grid-4 { grid-template-columns: 1fr 1fr; }
  .grid-3 { grid-template-columns: 1fr 1fr; }
  .sidebar { display: none; }
  .mobile-header { display: flex !important; }
  .main-content { padding: 16px; }
  .main-content h1 { font-size: 22px; }
}
@media (max-width: 600px) {
  .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
  .stat-card .stat-value { font-size: 24px; }
}

/* ===== Mobile header (hidden on desktop) ===== */
.mobile-header {
  display: none; background: var(--dark); color: #fff; padding: 12px 16px;
  align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 50;
}
.mobile-header .brand { display: flex; align-items: center; gap: 10px; }
.mobile-header .brand-icon { width: 32px; height: 32px; background: var(--orange); border-radius: 8px; display: grid; place-items: center; font-family: var(--font-display); font-weight: 800; font-size: 14px; }
.mobile-header .brand-text { font-family: var(--font-display); font-weight: 700; font-size: 15px; }

/* ===== Livreur mobile bottom nav ===== */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; background: var(--card);
  border-top: 1px solid var(--line); display: flex; padding: 8px 0;
  padding-bottom: max(8px, env(safe-area-inset-bottom)); z-index: 50;
}
.bottom-nav .nav-tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 6px; cursor: pointer; color: var(--text-3); font-size: 11px;
  font-weight: 600; transition: var(--transition); background: none; border: none;
  font-family: var(--font);
}
.bottom-nav .nav-tab.active { color: var(--orange); }
.bottom-nav .nav-tab svg { width: 22px; height: 22px; }
.livreur-content { padding-bottom: 80px; }

/* ===== Delivery card (livreur) ===== */
.delivery-card {
  background: var(--card); border-radius: var(--radius); padding: 16px;
  border: 1px solid var(--line); margin-bottom: 12px; transition: var(--transition);
}
.delivery-card:active { transform: scale(.98); }
.delivery-card .dc-code { font-family: var(--font-display); font-weight: 700; font-size: 15px; }
.delivery-card .dc-dest { font-size: 13px; color: var(--text-2); margin-top: 2px; }
.delivery-card .dc-bottom { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; }

/* ===== Map ===== */
.map-container { height: 280px; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); }

/* ===== Public page hero ===== */
.hero {
  min-height: 60dvh; display: flex; flex-direction: column; align-items: center;
  justify-content: center; text-align: center; padding: 40px 20px;
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%);
  position: relative; overflow: hidden;
}
.hero::before {
  content: ''; position: absolute; width: 600px; height: 600px;
  background: radial-gradient(circle, rgba(232,93,4,.08) 0%, transparent 70%);
  top: -200px; right: -200px; pointer-events: none;
}
.hero::after {
  content: ''; position: absolute; width: 400px; height: 400px;
  background: radial-gradient(circle, rgba(232,93,4,.06) 0%, transparent 70%);
  bottom: -150px; left: -100px; pointer-events: none;
}
.hero-brand { margin-bottom: 32px; }
.hero-brand .brand-icon { width: 64px; height: 64px; background: var(--orange); border-radius: 18px; display: grid; place-items: center; font-family: var(--font-display); font-weight: 800; font-size: 28px; color: #fff; margin: 0 auto 12px; box-shadow: 0 8px 32px rgba(232,93,4,.3); }
.hero-brand .brand-name { font-family: var(--font-display); font-size: 22px; font-weight: 700; color: var(--dark); }
.hero-brand .brand-sub { font-size: 14px; color: var(--text-2); }
.hero h1 { font-size: clamp(28px, 5vw, 48px); margin-bottom: 12px; position: relative; z-index: 1; }
.hero h1 span { color: var(--orange); }
.hero p { color: var(--text-2); font-size: 16px; max-width: 440px; margin-bottom: 28px; position: relative; z-index: 1; }

.search-box {
  display: flex; gap: 10px; max-width: 520px; width: 100%;
  background: var(--card); padding: 8px; border-radius: 999px;
  box-shadow: var(--shadow-lg); border: 1.5px solid var(--line);
  position: relative; z-index: 1;
}
.search-box input {
  border: none; padding: 12px 18px; font-size: 16px; flex: 1;
  border-radius: 999px; background: transparent; min-width: 0;
}
.search-box input:focus { box-shadow: none; }
.search-box .btn { padding: 12px 28px; font-size: 15px; }

/* ===== Tracking result (public) ===== */
.result-section { max-width: 700px; margin: 0 auto; padding: 20px; }
.result-header {
  background: var(--dark); color: #fff; border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 24px; display: flex; justify-content: space-between; align-items: center;
}
.result-header .rh-code { font-family: var(--font-display); font-weight: 800; font-size: 20px; }
.result-header .rh-route { color: rgba(255,255,255,.6); font-size: 14px; margin-top: 4px; }
.result-body { background: var(--card); border-radius: 0 0 var(--radius-lg) var(--radius-lg); padding: 24px; border: 1px solid var(--line); border-top: none; }

.timeline { position: relative; padding-left: 28px; }
.timeline::before { content: ''; position: absolute; left: 8px; top: 8px; bottom: 8px; width: 2px; background: var(--line); }
.timeline-item { position: relative; padding-bottom: 20px; }
.timeline-item:last-child { padding-bottom: 0; }
.timeline-dot {
  position: absolute; left: -24px; top: 4px; width: 14px; height: 14px;
  border-radius: 50%; background: var(--line); border: 2px solid var(--bg);
}
.timeline-item.active .timeline-dot { background: var(--orange); box-shadow: 0 0 0 4px var(--orange-glow); }
.timeline-item.done .timeline-dot { background: var(--green); }
.timeline-status { font-weight: 600; font-size: 14px; }
.timeline-date { font-size: 12px; color: var(--text-3); }
.timeline-comment { font-size: 13px; color: var(--text-2); margin-top: 2px; }
