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

:root {
  --pri: #F59E0B;
  --pri-dark: #D97706;
  --ok: #10B981;
  --err: #EF4444;
  --warn: #F97316;
  --bg: #F3F4F6;
  --card: #FFFFFF;
  --text: #111827;
  --muted: #6B7280;
  --border: #E5E7EB;
  --nav-h: 64px;
  --hdr-h: 68px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  overflow-x: hidden;
}

/* ── HEADER ── */
#header {
  position: fixed;
  top: 0; left: 0; right: 0;
  background: var(--pri);
  z-index: 100;
  padding: 10px 16px 0;
  height: var(--hdr-h);
}

.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 8px;
}

#session-date { font-size: 15px; font-weight: 700; color: #fff; }
#session-stats { font-size: 12px; color: rgba(255,255,255,.8); margin-top: 1px; }

.btn-ghost {
  background: rgba(255,255,255,.25);
  border: 1px solid rgba(255,255,255,.4);
  color: #fff;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

#progress-bar-wrap { height: 4px; background: rgba(255,255,255,.3); border-radius: 2px; }
#progress-bar { height: 100%; background: #fff; border-radius: 2px; width: 0; transition: width .4s; }

/* ── MAIN ── */
#main {
  margin-top: var(--hdr-h);
  margin-bottom: calc(var(--nav-h) + 72px);
  padding: 12px;
}

.tab { display: none; }
.tab.active { display: block; }

/* ── NEXT CARD ── */
#next-card {
  background: linear-gradient(135deg, #1F2937, #374151);
  color: #fff;
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.next-label { font-size: 10px; font-weight: 800; color: var(--pri); letter-spacing: 1.2px; }
#next-address { font-size: 17px; font-weight: 700; line-height: 1.3; }
#next-recipient { font-size: 13px; color: rgba(255,255,255,.65); }

.btn-navigate {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--pri);
  color: #000;
  border: none;
  border-radius: 10px;
  padding: 13px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  margin-top: 10px;
  width: 100%;
}
.btn-navigate svg { width: 18px; height: 18px; fill: #000; }

/* ── ACTION BAR ── */
#action-bar { display: flex; gap: 8px; margin-bottom: 12px; }

.btn-act {
  flex: 1;
  padding: 12px 8px;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.btn-pri { background: var(--pri); color: #000; }
.btn-sec { background: var(--card); color: var(--text); border: 1.5px solid var(--border); }
.btn-danger { background: #FEE2E2; color: #991B1B; border: none; }

/* ── PACKAGE CARD ── */
.pkg-card {
  background: var(--card);
  border-radius: 12px;
  padding: 13px;
  margin-bottom: 8px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color .15s;
  -webkit-tap-highlight-color: transparent;
}
.pkg-card:active { border-color: var(--pri); }

.pkg-num {
  min-width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: var(--muted);
  flex-shrink: 0;
}

.pkg-info { flex: 1; min-width: 0; }
.pkg-addr { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.3; }
.pkg-recip { font-size: 13px; color: var(--muted); margin-top: 2px; }
.pkg-note { font-size: 12px; color: var(--muted); margin-top: 3px; font-style: italic; }
.pkg-nogeo { font-size: 11px; color: var(--warn); margin-top: 3px; }

.badge {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 6px;
  white-space: nowrap;
  flex-shrink: 0;
}
.b-pending  { background: #FEF3C7; color: #92400E; }
.b-delivered{ background: #D1FAE5; color: #065F46; }
.b-failed   { background: #FEE2E2; color: #991B1B; }
.b-absent   { background: #FFEDD5; color: #9A3412; }

/* ── SWIPE ── */
.swipe-wrap {
  position: relative;
  border-radius: 12px;
  margin-bottom: 8px;
  overflow: hidden;
}
.swipe-wrap .pkg-card {
  margin-bottom: 0;
  will-change: transform;
  position: relative;
  z-index: 1;
}
.swipe-hint {
  position: absolute;
  top: 0; bottom: 0;
  display: flex;
  align-items: center;
  padding: 0 18px;
  font-size: 13px;
  font-weight: 700;
  gap: 5px;
  z-index: 0;
}
.swipe-hint-right { left: 0; background: #10B981; color: #fff; }
.swipe-hint-left  { right: 0; background: #F97316; color: #fff; }

/* ── ETA CARD ── */
#eta-card {
  background: linear-gradient(135deg, #1e3a5f, #1a4a6b);
  border-radius: 14px;
  padding: 14px 16px 10px;
  margin-bottom: 12px;
  color: #fff;
}

.eta-cols { display: flex; gap: 0; }

.eta-col {
  flex: 1;
  text-align: center;
  border-right: 1px solid rgba(255,255,255,.15);
  padding: 0 8px;
}
.eta-col:first-child { padding-left: 0; }
.eta-col:last-child  { border-right: none; padding-right: 0; }

.eta-val  { font-size: 22px; font-weight: 800; letter-spacing: -.5px; }
.eta-lbl  { font-size: 10px; color: rgba(255,255,255,.6); margin-top: 2px; text-transform: uppercase; letter-spacing: .5px; }

.eta-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid rgba(255,255,255,.12);
}

#eta-traffic { font-size: 12px; color: rgba(255,255,255,.7); }

#btn-eta-refresh {
  background: rgba(255,255,255,.15);
  border: none;
  border-radius: 6px;
  color: #fff;
  font-size: 14px;
  padding: 4px 8px;
  cursor: pointer;
}

/* ── MAP ── */
#tab-mappa { padding: 0; }
#map { height: calc(100dvh - var(--hdr-h) - var(--nav-h)); width: 100%; }

/* ── FAB ── */
#fab {
  position: fixed;
  right: 16px;
  bottom: calc(var(--nav-h) + 16px);
  width: 58px; height: 58px;
  border-radius: 50%;
  background: var(--pri);
  border: none;
  box-shadow: 0 4px 16px rgba(0,0,0,.25);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
  -webkit-tap-highlight-color: transparent;
}
#fab svg { width: 28px; height: 28px; fill: #000; }

/* ── BOTTOM NAV ── */
#bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--nav-h);
  background: #fff;
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 100;
}

.nav-btn {
  flex: 1; background: none; border: none;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px;
  color: var(--muted);
  font-size: 11px; cursor: pointer;
  padding: 8px;
  -webkit-tap-highlight-color: transparent;
}
.nav-btn svg { width: 22px; height: 22px; fill: var(--muted); }
.nav-btn.active { color: var(--pri-dark); }
.nav-btn.active svg { fill: var(--pri-dark); }

/* ── MODAL ── */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 1000;
  display: flex;
  align-items: flex-end;
}
.modal.hidden { display: none; }

.modal-box {
  background: #fff;
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-height: 92dvh;
  overflow-y: auto;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 20px 12px;
  position: sticky;
  top: 0;
  background: #fff;
  border-bottom: 1px solid var(--border);
}
.modal-head h3 { font-size: 17px; font-weight: 700; }

.btn-close {
  width: 30px; height: 30px;
  background: var(--bg); border: none;
  border-radius: 50%; font-size: 13px; cursor: pointer;
}

.modal-body {
  padding: 16px 20px 40px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ── FORM ── */
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.field input {
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  font-size: 15px;
  background: var(--bg);
  outline: none;
  width: 100%;
}
.field input:focus { border-color: var(--pri); background: #fff; }

.btn-big {
  width: 100%; padding: 16px;
  border-radius: 12px; border: none;
  font-size: 16px; font-weight: 700; cursor: pointer;
}

/* ── TYPE TOGGLE ── */
.type-toggle {
  display: flex; gap: 8px; margin-bottom: 4px;
}
.type-btn {
  flex: 1; padding: 10px 0;
  border-radius: 10px; border: 2px solid var(--border);
  background: var(--card); color: var(--muted);
  font-size: 14px; font-weight: 600; cursor: pointer;
  transition: all .15s;
}
.type-btn.type-active[data-type="delivery"] {
  background: #FEF3C7; color: #92400E; border-color: #F59E0B;
}
.type-btn.type-active[data-type="pickup"] {
  background: #DBEAFE; color: #1E40AF; border-color: #3B82F6;
}
.b-pickup-badge {
  font-size: 10px; font-weight: 700;
  background: #DBEAFE; color: #1E40AF;
  border-radius: 4px; padding: 2px 5px;
  margin-left: 4px; vertical-align: middle;
}
.time-badge {
  display: inline-flex; align-items: center; gap: 3px;
  font-size: 11px; font-weight: 700;
  border-radius: 5px; padding: 2px 6px;
  margin-top: 3px;
}
.time-ok     { background: #D1FAE5; color: #065F46; }
.time-soon   { background: #FEF3C7; color: #92400E; }
.time-urgent { background: #FEE2E2; color: #991B1B; }
.time-late   { background: #1F2937; color: #F87171; }

.divider {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  position: relative;
  padding: 4px 0;
}
.divider::before,.divider::after {
  content: '';
  position: absolute;
  top: 50%; width: 30%; height: 1px;
  background: var(--border);
}
.divider::before { left: 0; }
.divider::after { right: 0; }

/* ── STATUS GRID ── */
.status-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.btn-status {
  padding: 15px 8px;
  border: none; border-radius: 10px;
  font-size: 14px; font-weight: 600; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn-status[data-status="delivered"] { background: #D1FAE5; color: #065F46; }
.btn-status[data-status="absent"]    { background: #FFEDD5; color: #9A3412; }
.btn-status[data-status="failed"]    { background: #FEE2E2; color: #991B1B; }
.btn-status[data-status="pending"]   { background: var(--bg); color: var(--text); }

/* ── SPINNER ── */
.spinner {
  width: 40px; height: 40px;
  border: 4px solid var(--border);
  border-top-color: var(--pri);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  margin: 12px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── BATCH ── */
.batch-progress-wrap {
  height: 12px;
  background: var(--border);
  border-radius: 6px;
  overflow: hidden;
  margin: 8px 0;
}
#batch-bar-fill {
  height: 100%;
  background: var(--pri);
  border-radius: 6px;
  width: 0%;
  transition: width .3s ease;
}
.batch-counter {
  font-size: 28px;
  font-weight: 800;
  margin: 8px 0 4px;
}
.batch-status {
  font-size: 13px;
  color: var(--muted);
  min-height: 20px;
  margin-bottom: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.batch-stats {
  display: flex;
  justify-content: center;
  gap: 40px;
}
.batch-stat { text-align: center; }
.batch-stat-val { font-size: 32px; font-weight: 800; }
.batch-stat-val.ok   { color: var(--ok); }
.batch-stat-val.fail { color: var(--err); }
.batch-stat-lbl { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }

/* ── STATS ── */
.stats-today-card {
  background: linear-gradient(135deg, #1F2937, #374151);
  color: #fff;
  border-radius: 16px;
  padding: 18px;
  margin-bottom: 16px;
}

.stats-today-date {
  font-size: 13px;
  color: rgba(255,255,255,.6);
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: .8px;
}

.stats-big-row {
  display: flex;
  gap: 0;
  margin-bottom: 14px;
}

.stats-big-col {
  flex: 1;
  text-align: center;
  border-right: 1px solid rgba(255,255,255,.15);
  padding: 0 6px;
}
.stats-big-col:last-child { border-right: none; }

.stats-big-val { font-size: 26px; font-weight: 800; }
.stats-big-lbl { font-size: 10px; color: rgba(255,255,255,.55); text-transform: uppercase; letter-spacing: .5px; margin-top: 2px; }

.stats-rate-bar {
  height: 8px;
  background: rgba(255,255,255,.2);
  border-radius: 4px;
  margin-bottom: 10px;
  overflow: hidden;
}
.stats-rate-fill {
  height: 100%;
  background: var(--ok);
  border-radius: 4px;
  transition: width .5s;
}

.stats-bottom-row {
  display: flex;
  gap: 0;
  padding-top: 10px;
  border-top: 1px solid rgba(255,255,255,.12);
}

.stats-bot-col {
  flex: 1;
  text-align: center;
  border-right: 1px solid rgba(255,255,255,.1);
  padding: 0 6px;
}
.stats-bot-col:last-child { border-right: none; }

.stats-bot-val { font-size: 17px; font-weight: 700; }
.stats-bot-lbl { font-size: 10px; color: rgba(255,255,255,.5); text-transform: uppercase; margin-top: 2px; }

.stats-section-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 10px;
}

.history-card {
  background: var(--card);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.history-date {
  min-width: 70px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}

.history-bar-wrap {
  flex: 1;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}

.history-bar-fill {
  height: 100%;
  background: var(--ok);
  border-radius: 3px;
}

.history-meta {
  text-align: right;
  min-width: 80px;
}

.history-rate { font-size: 14px; font-weight: 800; color: var(--text); }
.history-detail { font-size: 11px; color: var(--muted); margin-top: 1px; }

.stats-empty {
  text-align: center;
  color: var(--muted);
  padding: 40px 20px;
  font-size: 14px;
}

/* ── CSV PREVIEW TABLE ── */
#csv-preview table {
  width: 100%; border-collapse: collapse; font-size: 12px;
}
#csv-preview th {
  background: var(--bg); padding: 6px 8px;
  text-align: left; font-size: 11px; color: var(--muted);
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
#csv-preview td {
  padding: 6px 8px; border-bottom: 1px solid var(--border);
  max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.batch-failed-title {
  font-size: 13px; font-weight: 700;
  color: var(--err);
  margin-top: 20px; margin-bottom: 10px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.batch-failed-item {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  background: #FEF2F2;
  border-radius: 10px;
  padding: 10px;
  margin-bottom: 8px;
}

.batch-failed-thumb {
  width: 64px; height: 64px;
  object-fit: cover;
  border-radius: 8px;
  flex-shrink: 0;
  cursor: pointer;
}

.batch-failed-form {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.batch-failed-form input {
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 14px;
  background: #fff;
  outline: none;
  width: 100%;
}
.batch-failed-form input:focus { border-color: var(--pri); }

.btn-failed-add {
  background: var(--pri);
  border: none;
  border-radius: 8px;
  padding: 8px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  width: 100%;
}

/* ── TOAST ── */
#toast {
  position: fixed;
  bottom: calc(var(--nav-h) + 80px);
  left: 50%;
  transform: translateX(-50%);
  background: #1F2937;
  color: #fff;
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 14px;
  z-index: 3000;
  white-space: nowrap;
  animation: toastIn .25s ease;
  pointer-events: none;
}
@keyframes toastIn { from { opacity:0; transform: translateX(-50%) translateY(8px); } }

/* ── EMPTY STATE ── */
#empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
}
.empty-icon { font-size: 56px; margin-bottom: 12px; }
#empty-state h2 { font-size: 20px; font-weight: 700; color: var(--text); margin-bottom: 8px; }
#empty-state p { font-size: 14px; }

/* ── DRAG & DROP ── */
.drag-handle {
  cursor: grab;
  color: var(--muted);
  font-size: 18px;
  padding: 0 6px 0 0;
  user-select: none;
  touch-action: none;
  flex-shrink: 0;
  opacity: 0.5;
  line-height: 1;
  display: flex;
  align-items: center;
}
.drag-handle:active { cursor: grabbing; opacity: 1; }
.sortable-ghost { opacity: 0.3; background: #FEF3C7; border-radius: 12px; }

/* ── URGENT ALERT ── */
.urgent-alert {
  background: linear-gradient(135deg, #78350F, #92400E);
  color: #fff;
  border-radius: 14px;
  padding: 14px 16px;
  margin-bottom: 12px;
  animation: pulseWarn 2.5s ease-in-out infinite;
}
.urgent-alert-row {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.4;
}
@keyframes pulseWarn {
  0%, 100% { box-shadow: 0 0 0 0 rgba(245,158,11,.5); }
  50%       { box-shadow: 0 0 0 10px rgba(245,158,11,0); }
}

/* ── SUMMARY MODAL ── */
.summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}
.summary-stat {
  background: var(--bg);
  border-radius: 12px;
  padding: 14px;
  text-align: center;
}
.summary-stat-val { font-size: 28px; font-weight: 800; }
.summary-stat-lbl { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; margin-top: 2px; }
.summary-retry-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.summary-retry-item:last-child { border-bottom: none; }
.summary-retry-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ── BUSINESS BADGE ── */
.b-business-badge {
  font-size: 10px; font-weight: 700;
  background: #DBEAFE; color: #1E40AF;
  border-radius: 4px; padding: 2px 5px;
  vertical-align: middle;
  margin-right: 3px;
}

.btn-business-toggle {
  padding: 5px 14px;
  border-radius: 20px;
  border: 1.5px solid var(--border);
  background: var(--bg);
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
}
.btn-business-toggle[data-business="true"] {
  background: #DBEAFE;
  color: #1E40AF;
  border-color: #93C5FD;
}

/* ── QUICK DELIVER ── */
.btn-quick-deliver {
  min-width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: #10B981;
  color: #fff;
  font-size: 22px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
  transition: transform .1s, background .1s;
}
.btn-quick-deliver:active { background: #059669; transform: scale(.88); }

/* ── QUICK NOTES ── */
.quick-notes {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 6px;
}
.btn-quick-note {
  padding: 6px 12px;
  border-radius: 20px;
  border: 1.5px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn-quick-note:active { background: #FEF3C7; border-color: var(--pri); }

/* ── ADDRESS HISTORY ── */
.addr-history {
  background: rgba(245,158,11,.07);
  border: 1px solid rgba(245,158,11,.28);
  border-radius: 10px;
  padding: 10px 12px;
}
.addr-history-title {
  font-size: 10px;
  font-weight: 800;
  color: #B45309;
  text-transform: uppercase;
  letter-spacing: .6px;
  margin-bottom: 6px;
}
.addr-history-chip {
  display: inline-block;
  background: #FEF3C7;
  color: #92400E;
  border: 1px solid #FDE68A;
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 12px;
  margin: 2px 4px 2px 0;
  cursor: pointer;
}
.addr-history-chip:active { background: #FDE68A; }

.hidden { display: none !important; }
