:root {
  --primary: #e11d48;
  --primary-dark: #be123c;
  --bg: #0f172a;
  --bg-2: #1e293b;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --text: #0f172a;
  --text-soft: #64748b;
  --on-primary: #ffffff;
  --ok: #16a34a;
  --ok-soft: #dcfce7;
  --warn: #d97706;
  --line: #e2e8f0;
  --radius: 14px;
  --shadow: 0 2px 8px rgba(15, 23, 42, .12);
  --shadow-lg: 0 8px 28px rgba(15, 23, 42, .22);
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--sans);
  background: var(--surface-2);
  color: var(--text);
  overscroll-behavior-y: none;
}
button { font-family: inherit; cursor: pointer; border: none; }

/* ---------- App shell ---------- */
.app { max-width: 720px; margin: 0 auto; min-height: 100vh; background: var(--surface-2); display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--bg); color: #fff;
  padding: 12px 14px; display: flex; align-items: center; gap: 10px;
  box-shadow: var(--shadow);
}
.topbar .mdi { font-size: 24px; line-height: 1; }
.topbar h1 { font-size: 16px; margin: 0; font-weight: 600; flex: 1; }
.topbar .sub { font-size: 12px; opacity: .7; font-weight: 400; display: block; }
.iconbtn {
  background: rgba(255,255,255,.12); color: #fff; width: 40px; height: 40px;
  border-radius: 50%; display: grid; place-items: center; font-size: 22px;
}
.iconbtn:active { background: rgba(255,255,255,.28); }

.net-pill { font-size: 11px; padding: 3px 9px; border-radius: 999px; font-weight: 600; display: inline-flex; align-items: center; gap: 4px; }
.net-on { background: var(--ok-soft); color: var(--ok); }
.net-off { background: #fee2e2; color: #b91c1c; }

.content { flex: 1; padding: 14px; }

/* ---------- Login / IdViaje ---------- */
.gate { min-height: 78vh; display: grid; place-items: center; padding: 24px; }
.gate-card {
  background: var(--surface); border-radius: 20px; box-shadow: var(--shadow-lg);
  padding: 30px 24px; width: 100%; max-width: 380px; text-align: center;
}
.gate-card .logo { width: 68px; height: 68px; margin: 0 auto 8px; display: block; }
.gate-card h2 { margin: 6px 0 2px; font-size: 20px; }
.gate-card p { color: var(--text-soft); font-size: 14px; margin: 0 0 22px; }
.field { text-align: left; margin-bottom: 16px; }
.field label { font-size: 13px; font-weight: 600; color: var(--text-soft); display: block; margin-bottom: 6px; }
.field input {
  width: 100%; padding: 14px 16px; font-size: 18px; border: 2px solid var(--line);
  border-radius: var(--radius); outline: none; transition: border-color .15s;
}
.field input:focus { border-color: var(--primary); }
.btn {
  width: 100%; padding: 15px; font-size: 16px; font-weight: 600; border-radius: var(--radius);
  background: var(--primary); color: var(--on-primary); display: inline-flex;
  align-items: center; justify-content: center; gap: 8px; transition: background .15s, transform .05s;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .55; cursor: default; }
.btn-ghost { background: var(--surface-2); color: var(--text); }
.btn-ok { background: var(--ok); }
.btn-sm { width: auto; padding: 10px 16px; font-size: 14px; }
.err { color: #b91c1c; font-size: 13px; margin-top: 10px; }

/* ---------- Progress bar ---------- */
.progress-wrap { background: var(--surface); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); margin-bottom: 12px; }
.progress-head { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 8px; }
.progress-head b { font-size: 15px; }
.bar { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--ok); border-radius: 999px; transition: width .3s ease; }

/* ---------- Client list ---------- */
.list { display: flex; flex-direction: column; gap: 10px; }
.card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px; display: flex; gap: 12px; align-items: flex-start;
  border-left: 5px solid var(--primary); transition: transform .05s;
}
.card:active { transform: scale(.995); }
.card.done { border-left-color: var(--ok); background: #f6fef9; }
.card .avatar {
  width: 44px; height: 44px; border-radius: 12px; flex: none; display: grid; place-items: center;
  background: rgba(225,29,72,.1); color: var(--primary); font-size: 24px;
}
.card.done .avatar { background: var(--ok-soft); color: var(--ok); }
.card .body { flex: 1; min-width: 0; }
.card .name { font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 6px; }
.card .meta { font-size: 13px; color: var(--text-soft); margin-top: 3px; display: flex; align-items: center; gap: 5px; }
.card .meta .mdi { font-size: 15px; }
.card .chips { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.chip { font-size: 12px; background: var(--surface-2); color: var(--text-soft); padding: 3px 9px; border-radius: 999px; font-weight: 600; display: inline-flex; align-items: center; gap: 4px; }
.chip .mdi { font-size: 14px; }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.badge-done { font-size: 11px; background: var(--ok); color: #fff; padding: 2px 8px; border-radius: 999px; }
.card .go { color: var(--text-soft); font-size: 26px; align-self: center; }

/* ---------- Detail ---------- */
.detail-head { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 12px; }
.detail-head .name { font-size: 20px; font-weight: 700; }
.detail-head .row { display: flex; align-items: center; gap: 7px; color: var(--text-soft); font-size: 14px; margin-top: 6px; }
.detail-head .row .mdi { font-size: 18px; color: var(--primary); }
.detail-head .row a { color: var(--primary); text-decoration: none; font-weight: 600; }

.pedido { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 12px; overflow: hidden; }
.pedido-head { padding: 12px 14px; background: var(--bg-2); color: #fff; display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 14px; }
.pedido-head .folio { font-family: ui-monospace, monospace; letter-spacing: .5px; }
.pedido-head .count { margin-left: auto; font-size: 12px; opacity: .8; }

.etiquetas { padding: 10px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.etq {
  border: 2px solid var(--line); border-radius: 12px; padding: 12px 10px; text-align: center;
  transition: transform .12s, background .2s, border-color .2s;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.etq .mdi { font-size: 26px; color: var(--text-soft); }
.etq .code { font-family: ui-monospace, monospace; font-size: 15px; font-weight: 700; letter-spacing: .5px; }
.etq .st { font-size: 11px; color: var(--text-soft); }
.etq.scanned { border-color: var(--ok); background: var(--ok-soft); }
.etq.scanned .mdi { color: var(--ok); }
.etq.scanned .st { color: var(--ok); font-weight: 700; }
.etq.flash { animation: flash .9s ease; }
@keyframes flash {
  0%   { transform: scale(1); box-shadow: 0 0 0 0 rgba(22,163,74,.6); }
  25%  { transform: scale(1.09); box-shadow: 0 0 0 10px rgba(22,163,74,.25); }
  100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(22,163,74,0); }
}

/* ---------- Scan bar ---------- */
.scanbar {
  position: sticky; bottom: 0; z-index: 15; background: var(--surface);
  border-top: 1px solid var(--line); padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  box-shadow: 0 -4px 16px rgba(15,23,42,.1);
}
.scan-row { display: flex; gap: 8px; align-items: center; }
.scan-input {
  flex: 1; padding: 13px 14px; font-size: 16px; border: 2px solid var(--line);
  border-radius: var(--radius); outline: none; font-family: ui-monospace, monospace;
}
.scan-input:focus { border-color: var(--primary); }
.scan-status { text-align: center; font-size: 13px; font-weight: 600; padding: 6px 0 2px; min-height: 22px; }
.scan-status.ok { color: var(--ok); }
.scan-status.dup { color: var(--warn); }
.scan-status.bad { color: #b91c1c; }
.shake { animation: shake .4s; }
@keyframes shake { 0%,100%{transform:translateX(0)} 20%,60%{transform:translateX(-7px)} 40%,80%{transform:translateX(7px)} }

.deliver-cta { padding: 12px 14px 0; }

/* ---------- Camera scanner ---------- */
.cam-modal { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.9); display: flex; flex-direction: column; }
.cam-modal video { width: 100%; height: 100%; object-fit: cover; position: absolute; inset: 0; }
.cam-frame { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; }
.cam-frame .box { width: 74%; max-width: 340px; aspect-ratio: 5/3; border: 3px solid rgba(255,255,255,.9); border-radius: 16px; box-shadow: 0 0 0 2000px rgba(0,0,0,.35); }
.cam-top { position: relative; z-index: 3; color: #fff; padding: 16px; display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.cam-top > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.cam-hint { position: absolute; top: 30%; left: 0; right: 0; text-align: center; color: #fff; font-size: 13px; z-index: 2; opacity: .85; }

/* Lista de códigos superpuesta sobre la cámara */
.cam-list {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 3;
  max-height: 42vh; display: flex; flex-direction: column;
  background: linear-gradient(to top, rgba(0,0,0,.92) 70%, rgba(0,0,0,0));
  padding: 22px 12px calc(14px + env(safe-area-inset-bottom));
}
.cam-list-head { color: #fff; font-size: 14px; font-weight: 700; display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.cam-list-head .mdi { color: var(--ok); font-size: 18px; }
.cam-chips { display: flex; flex-wrap: wrap; gap: 7px; overflow-y: auto; }
.cam-chip {
  font-family: ui-monospace, monospace; font-size: 14px; font-weight: 700; letter-spacing: .5px;
  padding: 7px 11px; border-radius: 999px; display: inline-flex; align-items: center; gap: 5px;
  color: rgba(255,255,255,.65); background: rgba(255,255,255,.1);
  border: 1.5px solid rgba(255,255,255,.25); transition: all .2s;
}
.cam-chip .mdi { font-size: 15px; }
.cam-chip.found {
  color: #fff; background: var(--ok); border-color: #22c55e;
  box-shadow: 0 0 10px rgba(34,197,94,.55);
}
.cam-chip.hit { animation: chipPop .7s ease; }
@keyframes chipPop {
  0% { transform: scale(1); }
  30% { transform: scale(1.22); box-shadow: 0 0 0 6px rgba(34,197,94,.4); }
  100% { transform: scale(1); }
}

.empty { text-align: center; color: var(--text-soft); padding: 50px 20px; }
.empty .mdi { font-size: 54px; opacity: .4; }

.toast {
  position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%);
  background: var(--bg); color: #fff; padding: 10px 18px; border-radius: 999px;
  font-size: 14px; box-shadow: var(--shadow-lg); z-index: 60; animation: rise .25s;
}
@keyframes rise { from { opacity: 0; transform: translate(-50%, 12px); } to { opacity: 1; transform: translate(-50%, 0); } }

@media (min-width: 520px) { .etiquetas { grid-template-columns: repeat(3, 1fr); } }
