/* Dispatch OS driver PWA — mobile-first. No framework.
 * Stitch design-system aligned 2026-06-04:
 *   primary  green   #22c55e   (delivered / CTA)
 *   warn     amber   #fbbf24   (no-answer / pending COD)
 *   info     blue    #60a5fa   (en-route / location-issue)
 *   danger   red     #ef4444   (failed)
 *   surface  #1c1f24 on bg #0b0d10
 *   font     DM Sans + system fallback
 *   radius   12 px
 */

:root {
  --bg:           #0b0d10;
  --surface:      #1c1f24;
  --surface-2:    #232930;
  --text:         #e6edf3;
  --text-dim:     #9aa4af;
  --primary:      #22c55e;
  --primary-ink:  #052e15;
  --warn:         #fbbf24;
  --warn-ink:     #3b2a05;
  --info:         #60a5fa;
  --info-ink:     #0a1f3d;
  --danger:       #ef4444;
  --danger-ink:   #4c0d0d;
  --radius:       12px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  font-family: "DM Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

body {
  padding-bottom: env(safe-area-inset-bottom);
}

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.75rem 1rem;
  background: #0b1220;
  border-bottom: 1px solid #1f2937;
}
.brand { display: flex; align-items: center; gap: 0.5rem; font-weight: 600; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: #22c55e; }
.title { font-size: 1.05rem; }

main { padding: 1rem; max-width: 720px; margin: 0 auto; }

.state {
  text-align: center;
  padding: 3rem 1rem;
  color: #94a3b8;
}
.state h2 { color: #fca5a5; margin-bottom: 0.25rem; }
.state p { color: #cbd5e1; margin-bottom: 1rem; word-break: break-word; }

.summary {
  background: #1e293b;
  border-radius: 0.75rem;
  padding: 1rem;
  margin-bottom: 1rem;
}
.summary h1 { margin: 0 0 0.25rem 0; font-size: 1.2rem; }
.muted { color: #94a3b8; font-size: 0.85rem; margin: 0 0 0.75rem; }

.progress-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.5rem;
  margin-bottom: 0.75rem;
}
.progress-grid > div {
  background: #0f172a; padding: 0.5rem; border-radius: 0.5rem;
  text-align: center;
}
.progress-grid span {
  display: block; font-size: 1.4rem; font-weight: 700;
}
.progress-grid label {
  display: block; font-size: 0.7rem; color: #94a3b8; margin-top: 0.1rem;
}

.badge {
  display: inline-block; padding: 0.25rem 0.5rem; border-radius: 999px;
  font-size: 0.75rem; font-weight: 600; text-transform: uppercase;
}
.badge.low { background: #064e3b; color: #6ee7b7; }
.badge.medium { background: #422006; color: #fcd34d; }
.badge.high { background: #450a0a; color: #fca5a5; }

.stop-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 0.75rem; }

.stop-card {
  background: #1e293b;
  border-radius: 0.75rem;
  padding: 1rem;
  border: 1px solid #1f2937;
}
.stop-card.is-delivered { opacity: 0.55; }
.stop-card.is-failed { border-color: #7f1d1d; }
.stop-card.is-active { border-color: #2563eb; }
.stop-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}
.stop-head .seq {
  background: #334155; color: #cbd5e1; border-radius: 0.5rem;
  padding: 0.2rem 0.5rem; font-weight: 600; font-size: 0.85rem;
}
.stop-head .eta { color: #94a3b8; font-size: 0.85rem; }
.stop-name { font-weight: 600; font-size: 1.05rem; margin: 0 0 0.25rem; }
.stop-area { color: #94a3b8; font-size: 0.85rem; margin: 0 0 0.25rem; }
.stop-address { color: #e2e8f0; font-size: 0.95rem; margin: 0 0 0.5rem; }
.stop-meta { color: #94a3b8; font-size: 0.8rem; margin: 0 0 0.5rem; }
.strict-warn {
  display: inline-block; padding: 0.15rem 0.4rem; border-radius: 0.4rem;
  background: #422006; color: #fcd34d; font-size: 0.75rem;
  margin-left: 0.4rem;
}

.tap-row {
  display: flex; gap: 0.4rem; flex-wrap: wrap; margin-bottom: 0.5rem;
}
.tap-row a, .tap-row button {
  flex: 1 1 auto; min-width: 30%;
  background: #0f172a; color: #e2e8f0;
  border: 1px solid #334155; border-radius: 0.5rem;
  padding: 0.55rem 0.5rem; font-size: 0.9rem;
  text-align: center; text-decoration: none;
  cursor: pointer;
}

.actions {
  display: flex; gap: 0.4rem; flex-wrap: wrap;
}
.actions button {
  flex: 1 1 calc(50% - 0.4rem);
  border: 1px solid #334155; background: #0f172a; color: #e2e8f0;
  border-radius: 0.5rem; padding: 0.65rem 0.5rem; font-size: 0.9rem;
  cursor: pointer;
}
.actions button.primary-btn { background: #2563eb; border-color: #2563eb; }
.actions button.danger-btn { background: #7f1d1d; border-color: #7f1d1d; }
.actions button.warn-btn { background: #422006; border-color: #422006; }

.status-pill {
  display: inline-block; padding: 0.2rem 0.55rem; border-radius: 999px;
  font-size: 0.75rem; font-weight: 600; text-transform: uppercase;
  background: #334155; color: #e2e8f0;
}
.status-pill.delivered { background: #064e3b; color: #6ee7b7; }
.status-pill.en_route, .status-pill.arrived { background: #1e3a8a; color: #93c5fd; }
.status-pill.failed, .status-pill.skipped { background: #7f1d1d; color: #fecaca; }
.status-pill.customer_not_answering, .status-pill.location_issue {
  background: #422006; color: #fcd34d;
}

.primary-btn, .ghost-btn {
  border-radius: var(--radius); padding: 0.85rem 0.9rem; font-size: 1rem;
  font-weight: 600;
  cursor: pointer; border: 1px solid transparent;
  min-height: 56px;
}
.primary-btn { background: var(--primary); color: var(--primary-ink); }
.ghost-btn { background: transparent; color: var(--text); border-color: #334155; }

/* ============================================================
 * Stitch-aligned polish additions (2026-06-04)
 * Non-destructive: all new classes; existing selectors untouched.
 * ============================================================ */

.cod-badge {
  display: inline-flex; align-items: center; gap: 0.35rem;
  background: var(--warn); color: var(--warn-ink);
  padding: 0.5rem 0.85rem;
  border-radius: var(--radius);
  font-size: 1.05rem; font-weight: 700;
  letter-spacing: 0.02em;
  box-shadow: 0 0 0 1px rgba(251, 191, 36, 0.25);
}
.cod-badge .cod-label {
  font-size: 0.7rem; font-weight: 500; opacity: 0.75; text-transform: uppercase;
}

.actions-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-top: 0.5rem;
}
.actions-grid button {
  min-height: 56px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: 0.95rem; font-weight: 600;
  cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 0.15rem;
}
.actions-grid .btn-delivered { background: var(--primary); color: var(--primary-ink); grid-column: 1 / -1; min-height: 64px; font-size: 1.1rem; }
.actions-grid .btn-no-answer { background: var(--warn);    color: var(--warn-ink); }
.actions-grid .btn-location  { background: var(--info);    color: var(--info-ink); }
.actions-grid .btn-failed    { background: var(--danger);  color: var(--danger-ink); }
.actions-grid .btn-skip      { background: var(--surface-2); color: var(--text-dim); }
.actions-grid button .ar { display: block; font-size: 0.8rem; opacity: 0.85; font-weight: 500; }

.welcome-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.5rem 1.25rem;
  margin: 2rem auto 1rem;
  max-width: 480px;
  text-align: center;
}
.welcome-card h1 {
  margin: 0 0 0.25rem; font-size: 1.6rem; font-weight: 700;
}
.welcome-card .ar { display: block; margin-top: 0.1rem; font-size: 1.05rem; color: var(--text-dim); }
.welcome-card .date-pill {
  display: inline-block; margin: 0.75rem 0 1rem;
  background: var(--surface-2); color: var(--text);
  padding: 0.3rem 0.75rem; border-radius: 999px; font-size: 0.85rem;
}
.welcome-card .route-stats {
  background: var(--surface-2); border-radius: var(--radius);
  padding: 0.75rem; margin: 0.5rem 0 1rem;
  display: flex; justify-content: space-around;
}
.welcome-card .route-stats span { font-weight: 700; font-size: 1.1rem; }
.welcome-card .route-stats label { display: block; font-size: 0.7rem; color: var(--text-dim); margin-top: 0.15rem; }
.welcome-card .flow-steps {
  display: flex; justify-content: space-between; align-items: center;
  margin: 1rem 0; gap: 0.4rem; font-size: 0.75rem;
}
.welcome-card .flow-steps .step {
  flex: 1; padding: 0.5rem 0.4rem; border-radius: 0.4rem;
  background: var(--surface-2); color: var(--text-dim); text-align: center;
}
.welcome-card .flow-steps .step.active { background: var(--primary); color: var(--primary-ink); font-weight: 600; }
.welcome-card .escape {
  display: block; margin-top: 0.5rem; color: var(--text-dim); font-size: 0.8rem;
}

.complete-summary {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.5rem 1.25rem;
  margin: 1rem auto;
  max-width: 480px;
}
.complete-summary .checkmark {
  width: 64px; height: 64px; margin: 0 auto 1rem;
  border-radius: 50%; background: var(--primary); color: var(--primary-ink);
  display: flex; align-items: center; justify-content: center;
  font-size: 2rem; font-weight: 800;
}
.complete-summary h1 { text-align: center; margin: 0 0 0.25rem; font-size: 1.4rem; }
.complete-summary h1 .ar { display: block; font-size: 1.05rem; color: var(--text-dim); font-weight: 500; }
.complete-summary .meta { text-align: center; color: var(--text-dim); font-size: 0.85rem; margin-bottom: 1rem; }

.complete-stats {
  display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; margin: 1rem 0;
}
.complete-stats .stat {
  background: var(--surface-2); border-radius: var(--radius);
  padding: 0.75rem; text-align: center;
}
.complete-stats .stat .num { display: block; font-size: 1.6rem; font-weight: 700; }
.complete-stats .stat.delivered .num { color: var(--primary); }
.complete-stats .stat.no-answer .num { color: var(--warn); }
.complete-stats .stat.failed    .num { color: var(--danger); }
.complete-stats .stat.location  .num { color: var(--info); }
.complete-stats .stat label { display: block; font-size: 0.75rem; color: var(--text-dim); margin-top: 0.15rem; }

.cash-section {
  background: var(--warn); color: var(--warn-ink);
  border-radius: var(--radius);
  padding: 1rem 1.25rem; margin: 1rem 0;
  text-align: center;
}
.cash-section .label { font-size: 0.75rem; opacity: 0.8; text-transform: uppercase; letter-spacing: 0.05em; }
.cash-section .amount { display: block; font-size: 2rem; font-weight: 800; margin-top: 0.25rem; }
.cash-section .sub { display: block; font-size: 0.8rem; opacity: 0.75; margin-top: 0.25rem; }

/* RTL hint — when html[lang=ar] or html[dir=rtl], mirror flex/grid where helpful */
html[dir="rtl"] .stop-head,
html[dir="rtl"] .tap-row,
html[dir="rtl"] .actions,
html[dir="rtl"] .actions-grid { direction: rtl; }

.hidden { display: none !important; }

.sheet {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 20;
}
.sheet-inner {
  width: 100%; max-width: 720px;
  background: #1e293b; padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom));
  border-top-left-radius: 1rem; border-top-right-radius: 1rem;
}
.sheet textarea {
  width: 100%; background: #0f172a; color: #e2e8f0;
  border: 1px solid #334155; border-radius: 0.5rem;
  padding: 0.5rem; font-family: inherit; font-size: 1rem;
}
.sheet-actions {
  display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 0.5rem;
}
