:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #0f766e;
  --primary-dark: #115e59;
  --primary-light: #ccfbf1;
  --danger: #dc2626;
  --warn: #d97706;
  --ok: #16a34a;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 6px 20px rgba(15, 23, 42, .04);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

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

.app { display: flex; flex-direction: column; min-height: 100%; }

/* ---------- splash / spinner ---------- */
.splash { display: grid; place-content: center; gap: 1rem; height: 100vh; color: var(--muted); }
.spinner { width: 38px; height: 38px; border: 3px solid var(--border); border-top-color: var(--primary);
  border-radius: 50%; animation: spin 0.8s linear infinite; margin: 0 auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- top bar ---------- */
.appbar { position: sticky; top: 0; z-index: 20; background: var(--primary); color: #fff;
  padding: calc(var(--safe-top) + .85rem) 1rem .85rem; display: flex; align-items: center;
  gap: .75rem; box-shadow: var(--shadow); }
.appbar h1 { font-size: 1.05rem; margin: 0; font-weight: 650; flex: 1; }
.appbar .who { font-size: .78rem; opacity: .85; }
.appbar button.link { background: rgba(255,255,255,.15); color: #fff; border: 0;
  padding: .4rem .7rem; border-radius: 8px; font-size: .8rem; }

/* ---------- offline / sync banner ---------- */
.banner { font-size: .82rem; padding: .5rem 1rem; text-align: center; font-weight: 600; }
.banner.offline { background: #fef3c7; color: #92400e; }
.banner.pending { background: var(--primary-light); color: var(--primary-dark); }

/* ---------- main content ---------- */
main { flex: 1; padding: 1rem; padding-bottom: 6rem; max-width: 760px; width: 100%; margin: 0 auto; }
h2.section { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted);
  margin: 1.25rem .25rem .5rem; }

/* ---------- cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem; box-shadow: var(--shadow); margin-bottom: .75rem; }
.card .title { font-weight: 650; }
.card .sub { color: var(--muted); font-size: .85rem; margin-top: .15rem; }
.row { display: flex; align-items: center; gap: .75rem; }
.row .grow { flex: 1; min-width: 0; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- stats grid ---------- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: .6rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .8rem; text-align: center; }
.stat .n { font-size: 1.6rem; font-weight: 700; }
.stat .l { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  border: 0; border-radius: 12px; padding: .85rem 1.1rem; font-size: .95rem; font-weight: 600;
  background: var(--primary); color: #fff; cursor: pointer; width: 100%; }
.btn:active { transform: translateY(1px); }
.btn.secondary { background: var(--surface); color: var(--primary); border: 1.5px solid var(--primary); }
.btn.ghost { background: transparent; color: var(--muted); border: 1.5px solid var(--border); }
.btn.danger { background: var(--danger); }
.btn.small { width: auto; padding: .5rem .8rem; font-size: .82rem; border-radius: 10px; }
.btn:disabled { opacity: .5; }
.btn-row { display: flex; gap: .6rem; }

/* ---------- big scan button ---------- */
.scan-hero { display: grid; place-items: center; gap: 1rem; padding: 2rem 1rem; }
.scan-btn { width: 180px; height: 180px; border-radius: 50%; background: var(--primary); color: #fff;
  border: 0; font-size: 1.1rem; font-weight: 700; box-shadow: 0 10px 30px rgba(15,118,110,.35);
  display: grid; place-content: center; gap: .4rem; cursor: pointer; }
.scan-btn .icon { font-size: 2.8rem; }

/* ---------- scan feedback ---------- */
.feedback { border-radius: var(--radius); padding: 1rem; font-weight: 600; text-align: center;
  margin-bottom: 1rem; }
.feedback.matched { background: #dcfce7; color: #166534; }
.feedback.created { background: #dcfce7; color: #166534; }
.feedback.created_new_customer { background: #dcfce7; color: #166534; }
.feedback.already_scanned { background: #e0e7ff; color: #3730a3; }
.feedback.customer_unknown { background: #fef3c7; color: #92400e; }

/* ---------- status chips ---------- */
.chip { display: inline-block; font-size: .7rem; font-weight: 700; padding: .2rem .55rem;
  border-radius: 999px; text-transform: uppercase; letter-spacing: .03em; }
.chip.planned { background: #f1f5f9; color: #475569; }
.chip.ready { background: #dcfce7; color: #166534; }
.chip.routed { background: #e0e7ff; color: #3730a3; }
.chip.en_route { background: #cffafe; color: #155e75; }
.chip.delivered { background: var(--primary); color: #fff; }
.chip.failed { background: #fee2e2; color: #991b1b; }

/* ---------- forms ---------- */
label { display: block; font-size: .82rem; color: var(--muted); margin: .75rem 0 .25rem; }
input, select { width: 100%; padding: .8rem; border: 1.5px solid var(--border); border-radius: 12px;
  font-size: 1rem; background: var(--surface); color: var(--text); }
input:focus, select:focus { outline: 0; border-color: var(--primary); }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-content: center; padding: 1.5rem; gap: .25rem; }
.login .logo { font-size: 2rem; font-weight: 800; color: var(--primary); text-align: center; }
.login .tag { color: var(--muted); text-align: center; margin-bottom: 1.5rem; }
.login .card { width: min(380px, 90vw); }
.hint { font-size: .76rem; color: var(--muted); margin-top: 1rem; line-height: 1.5; }

/* ---------- bottom nav ---------- */
.bottomnav { position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; background: var(--surface);
  border-top: 1px solid var(--border); display: flex; padding-bottom: var(--safe-bottom); }
.bottomnav button { flex: 1; background: none; border: 0; padding: .6rem; color: var(--muted);
  font-size: .7rem; display: grid; gap: .15rem; justify-items: center; cursor: pointer; }
.bottomnav button .icon { font-size: 1.3rem; }
.bottomnav button.active { color: var(--primary); font-weight: 700; }

/* ---------- camera ---------- */
.camera-wrap { position: relative; border-radius: var(--radius); overflow: hidden; background: #000;
  aspect-ratio: 3/4; margin-bottom: 1rem; }
.camera-wrap video { width: 100%; height: 100%; object-fit: cover; }
.camera-wrap .reticle { position: absolute; inset: 22% 12%; border: 3px solid rgba(255,255,255,.85);
  border-radius: 12px; box-shadow: 0 0 0 100vmax rgba(0,0,0,.35); }

/* ---------- signature pad ---------- */
.sigpad { border: 2px dashed var(--border); border-radius: var(--radius); background: #fff;
  touch-action: none; width: 100%; height: 220px; display: block; }

/* ---------- stop list ---------- */
.stop { display: flex; gap: .8rem; align-items: flex-start; }
.stop .seq { width: 30px; height: 30px; border-radius: 50%; background: var(--primary); color: #fff;
  display: grid; place-content: center; font-weight: 700; flex-shrink: 0; font-size: .85rem; }
.stop.done .seq { background: var(--ok); }
.stop.failed .seq { background: var(--danger); }

/* ---------- modal sheet ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(15,23,42,.5); z-index: 40;
  display: flex; align-items: flex-end; }
.sheet { background: var(--surface); border-radius: 20px 20px 0 0; width: 100%; max-height: 92vh;
  overflow: auto; padding: 1.25rem; padding-bottom: calc(1.25rem + var(--safe-bottom)); }
.sheet h3 { margin: 0 0 .25rem; }

/* ---------- toast ---------- */
.toast-host { position: fixed; bottom: 5.5rem; left: 0; right: 0; display: grid; gap: .5rem;
  justify-items: center; z-index: 60; pointer-events: none; padding: 0 1rem; }
.toast { background: var(--text); color: #fff; padding: .7rem 1rem; border-radius: 10px;
  font-size: .88rem; box-shadow: var(--shadow); max-width: 90vw; animation: rise .2s ease; }
.toast.error { background: var(--danger); }
.toast.ok { background: var(--ok); }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

/* ---------- map ---------- */
.map { height: 340px; width: 100%; border-radius: var(--radius); overflow: hidden;
  border: 1px solid var(--border); margin-bottom: .75rem; background: #e2e8f0; }
.map-pin { width: 26px; height: 26px; border-radius: 50%; color: #fff; display: grid;
  place-content: center; font-weight: 700; font-size: .8rem; border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,.4); }

.empty { text-align: center; color: var(--muted); padding: 3rem 1rem; }
.muted { color: var(--muted); }
.spacer { height: .5rem; }
a.maplink { color: var(--primary); font-weight: 600; text-decoration: none; }
