/* Envíos — estilo minimalista para iPad */

/* Paletas comprobadas con WCAG: todo texto ≥ 4,5:1 y bordes de controles ≥ 3:1. */
/* Tema oscuro (por defecto) */
:root {
  --radius: 18px;
  --radius-sm: 12px;
  --tap: 50px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --bg: #121417; --surface: #1b1e23; --surface-2: #262a31; --surface-3: #31363e;
  --ink: #f2f3f5; --ink-2: #cdd0d6; --ink-3: #a6aab2; --placeholder: #9a9ea6;
  --line: #2f343b; --field-line: #6b717b;
  --primary: #1d7a62; --primary-ink: #ffffff; --primary-press: #175f4d; --primary-soft: #17362d; --accent: #74d4b0;
  --focus-ring: rgba(116, 212, 176, .25);
  --blue: #93b4ff; --blue-soft: #1d2a45; --green: #86d9a8; --green-soft: #173426;
  --amber: #f2bb63; --amber-soft: #3a2b12; --red: #ff9a8a; --red-soft: #41201b; --gray: #a6aab2;
  --on-color: #121417; --disabled-bg: #2c3037; --disabled-ink: #a0a4ac;
  --ok-bg: #16271f; --issue-bg: #2c2312;
  --topbar-bg: rgba(18, 20, 23, .9); --tabbar-bg: rgba(18, 20, 23, .96); --bg-clear: rgba(18, 20, 23, 0);
  --toast-bg: #e9eaee; --toast-ink: #121417; --toast-ok: #1d6a3f;
  --overlay: rgba(0, 0, 0, .62); --shadow-lg: 0 24px 60px rgba(0, 0, 0, .55), 0 2px 8px rgba(0, 0, 0, .3);
  --av0-bg: #1f3a31; --av0-fg: #8fe0c0; --av1-bg: #22304f; --av1-fg: #a9c1ff; --av2-bg: #3a2742; --av2-fg: #e1b3f0; --av3-bg: #43291b; --av3-fg: #ffbe94;
  --av4-bg: #22371d; --av4-fg: #a9dc94; --av5-bg: #432329; --av5-fg: #ffaab8; --av6-bg: #2a2c4a; --av6-fg: #b8bdfa; --av7-bg: #3a3320; --av7-fg: #e8d28c;
  color-scheme: dark;
  --tabbar-h: 0px;
}
/* Tema claro (Admin → Ajustes → Apariencia) */
:root[data-theme="light"] {
  --bg: #f4f3f0; --surface: #ffffff; --surface-2: #efede8; --surface-3: #e4e1db;
  --ink: #1d1d1f; --ink-2: #45474d; --ink-3: #62646a; --placeholder: #64666c;
  --line: #dcd9d2; --field-line: #86837c;
  --primary: #1c6150; --primary-ink: #ffffff; --primary-press: #154a3d; --primary-soft: #e3efea; --accent: #1c6150;
  --focus-ring: rgba(28, 97, 80, .18);
  --blue: #1d4ca8; --blue-soft: #e8eefb; --green: #1d6a3f; --green-soft: #e4f2e9;
  --amber: #7f4a00; --amber-soft: #fbefd9; --red: #a8321f; --red-soft: #fbe6e2; --gray: #585a60;
  --on-color: #ffffff; --disabled-bg: #e4e1db; --disabled-ink: #55575d;
  --ok-bg: #eef7f1; --issue-bg: #fff6e6;
  --topbar-bg: rgba(244, 243, 240, .92); --tabbar-bg: rgba(244, 243, 240, .97); --bg-clear: rgba(244, 243, 240, 0);
  --toast-bg: rgba(29, 29, 31, .94); --toast-ink: #ffffff; --toast-ok: #7ddc9f;
  --overlay: rgba(20, 20, 25, .45); --shadow-lg: 0 24px 60px rgba(20, 20, 25, .18), 0 2px 8px rgba(20, 20, 25, .06);
  --av0-bg: #dcece4; --av0-fg: #17543f; --av1-bg: #e1e8f8; --av1-fg: #24479a; --av2-bg: #eee1f2; --av2-fg: #6f2c84; --av3-bg: #f8e3d6; --av3-fg: #8a3f10;
  --av4-bg: #e0efdb; --av4-fg: #2c6320; --av5-bg: #f6dfe3; --av5-fg: #8c2a3b; --av6-bg: #e4e4f6; --av6-fg: #3c4594; --av7-bg: #f0e9d2; --av7-fg: #5f4b0e;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
* { scrollbar-color: var(--surface-3) transparent; }
body {
  margin: 0; font-family: var(--font); font-size: 17px; line-height: 1.45; color: var(--ink); background: var(--bg);
  -webkit-tap-highlight-color: transparent; -webkit-font-smoothing: antialiased; overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { touch-action: manipulation; cursor: pointer; }
a { color: var(--accent); text-decoration: none; }
h1, h2, h3 { margin: 0; line-height: 1.2; font-weight: 650; letter-spacing: -.015em; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0; }
code { font-size: .9em; background: var(--surface-2); padding: 1px 6px; border-radius: 6px; }
.muted { color: var(--ink-3); }
.small { font-size: .87rem; }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; gap: 12px; }
.row.wrap { flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack.lg { gap: 24px; }
.center { text-align: center; }
.hidden { display: none !important; }
.show-sm { display: none; }
.lead { flex: none; }
.row-extra { display: contents; }
.head-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.row.wrap > .grow:not(:empty) { flex: 1 1 260px; }
.list-row .time { width: 56px; font-weight: 700; }
.event-id { width: 52px; flex: none; }

/* ---------------- Barra superior ---------------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--topbar-bg); backdrop-filter: saturate(180%) blur(16px); -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-bottom: 1px solid var(--line);
  padding: calc(env(safe-area-inset-top) + 10px) max(20px, env(safe-area-inset-right)) 10px max(20px, env(safe-area-inset-left));
  display: flex; align-items: center; gap: 14px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; min-width: 0; }
.brand .logo { width: 30px; height: 30px; border-radius: 9px; background: var(--primary); color: var(--primary-ink); display: grid; place-items: center; flex: none; }
.brand span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.branch-label { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); font-weight: 600; white-space: nowrap; padding-left: 14px; border-left: 1px solid var(--line); min-width: 0; }
.branch-label svg { flex: none; }
.bl-name { overflow: hidden; text-overflow: ellipsis; }
.nav { margin-left: auto; display: flex; gap: 2px; }
.nav a {
  color: var(--ink-2); display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: 999px;
  min-height: 42px; font-weight: 560; font-size: .95rem;
}
.nav a svg { display: none; }
.nav a.active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.nav a .badge-dot { background: var(--blue); color: var(--on-color); border-radius: 999px; font-size: .72rem; font-weight: 700; padding: 1px 7px; }
.admin-pill {
  display: inline-flex; align-items: center; gap: 6px; background: var(--amber-soft); color: var(--amber);
  border: 0; border-radius: 999px; padding: 6px 12px; font-weight: 650; font-size: .8rem; min-height: 34px; white-space: nowrap; flex: none;
}
@media (max-width: 760px) {
  .brand span, .nav a span.label { display: none; }
  .brand { flex: none; }
  .branch-label { padding-left: 10px; }
  .nav a { padding: 8px 11px; }
  .nav a svg { display: block; }
}

.offline-bar { background: var(--red-soft); color: var(--red); text-align: center; padding: 8px; font-weight: 600; font-size: .9rem; }

main.page {
  max-width: 1180px; margin: 0 auto; overflow-x: clip;
  padding: 28px max(20px, env(safe-area-inset-right)) calc(48px + env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
}
.page-head { display: flex; align-items: center; gap: 14px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head .grow h1 { overflow-wrap: anywhere; }
.back-btn { width: 44px; height: 44px; border-radius: 50%; background: var(--surface); display: grid; place-items: center; flex: none; color: var(--ink); border: 1px solid var(--field-line); }

/* ---------------- Superficies ---------------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.card.pad { padding: 22px; }
.section { margin-top: 28px; }
.section-title { display: flex; align-items: baseline; gap: 8px; margin: 0 2px 12px; color: var(--ink); font-size: 1.05rem; font-weight: 650; letter-spacing: -.01em; }
.section-title .count { color: var(--ink-3); font-weight: 500; }
.section-title a { font-size: .9rem; font-weight: 550; }
.grid > * { min-width: 0; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.grid.fit { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
@media (max-width: 400px) { .grid, .grid.fit { grid-template-columns: 1fr; } }

.ship-card {
  padding: 20px; display: flex; flex-direction: column; gap: 6px; text-align: left; width: 100%; color: inherit;
  border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius); transition: transform .08s ease;
}
.ship-card:active { transform: scale(.99); }
.ship-card .top { display: flex; align-items: center; gap: 10px; }
.ship-card .code { color: var(--ink-3); font-size: .85rem; font-variant-numeric: tabular-nums; }
.ship-card .route { font-size: 1.25rem; font-weight: 650; letter-spacing: -.015em; }
.ship-card .meta { color: var(--ink-2); font-size: .93rem; }
.ship-card .items-preview { color: var(--ink-3); font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ship-card .btn { margin-top: 12px; }

.hero { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.hero > .grow { flex: 1 1 220px; }
.hero .where { font-size: .9rem; color: var(--ink-3); font-weight: 500; }
.hero h1 { font-size: 2.2rem; letter-spacing: -.025em; }

.alert { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-radius: 14px; font-weight: 550; text-align: left; width: 100%; border: 0; color: inherit; }
.alert.amber { background: var(--amber-soft); color: var(--amber); }
.alert.red { background: var(--red-soft); color: var(--red); }
.alert.green { background: var(--green-soft); color: var(--green); }
.alert.blue { background: var(--blue-soft); color: var(--blue); }
.alert .grow { font-weight: 450; }
.alert svg { flex: none; }

/* ---------------- Botones ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 0 22px; border-radius: 14px; border: 0;
  background: var(--surface-2); color: var(--ink); font-weight: 600; font-size: 1rem; user-select: none; -webkit-user-select: none;
  transition: transform .06s ease, background .15s ease, opacity .15s;
}
.btn:active:not(:disabled) { transform: scale(.97); background: var(--surface-3); }

.btn.primary, .btn.blue { background: var(--primary); color: var(--primary-ink); }
.btn.primary:active:not(:disabled), .btn.blue:active:not(:disabled) { background: var(--primary-press); }
.btn:disabled, .btn.primary:disabled, .btn.blue:disabled, .btn.danger:disabled { background: var(--disabled-bg); color: var(--disabled-ink); cursor: not-allowed; }
.btn.danger-ghost:disabled, .btn.ghost:disabled { background: transparent; color: var(--disabled-ink); }
.btn.danger { background: var(--red); color: var(--on-color); }
.btn.danger-ghost { background: transparent; color: var(--red); }
.btn.danger-ghost:active:not(:disabled) { background: var(--red-soft); }
.btn.ghost { background: transparent; }
.btn.big { min-height: 58px; font-size: 1.08rem; padding: 0 28px; border-radius: 16px; }
.btn.block { width: 100%; }
.btn.sm { min-height: 40px; padding: 0 14px; font-size: .92rem; border-radius: 11px; }
.icon-btn { width: 44px; height: 44px; border-radius: 12px; border: 0; background: transparent; display: inline-grid; place-items: center; flex: none; color: var(--ink-2); }
.icon-btn:active { background: var(--surface-2); color: var(--ink); }
.icon-btn.danger { color: var(--ink-2); }
.icon-btn.danger:active { color: var(--red); background: var(--red-soft); }

/* ---------------- Formularios ---------------- */
label.field, div.field { display: flex; flex-direction: column; gap: 7px; font-weight: 560; font-size: .9rem; color: var(--ink-2); }
label.field .hint, div.field .hint { font-weight: 400; color: var(--ink-3); font-size: .84rem; }
.issue-list { margin: 10px 0 0; padding-left: 20px; }
.issue-list li { margin: 4px 0; }
.input, select.input, textarea.input {
  width: 100%; min-height: var(--tap); padding: 12px 14px; border-radius: 12px;
  border: 1px solid var(--field-line); background: var(--surface); font-size: 17px; color: var(--ink);
  -webkit-appearance: none; appearance: none; transition: border-color .15s, box-shadow .15s;
}
select.input { background-image: linear-gradient(45deg, transparent 50%, var(--ink-3) 50%), linear-gradient(135deg, var(--ink-3) 50%, transparent 50%); background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%; background-size: 6px 6px; background-repeat: no-repeat; padding-right: 38px; }
textarea.input { min-height: 84px; resize: vertical; }
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--focus-ring); }
.input::placeholder { color: var(--placeholder); opacity: 1; }
.check { display: flex; align-items: center; gap: 12px; min-height: var(--tap); font-weight: 550; cursor: pointer; }
.check input { width: 24px; height: 24px; accent-color: var(--accent); flex: none; }
.check .sub { display: block; font-weight: 400; font-size: .86rem; color: var(--ink-3); }
.form-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.error-text { color: var(--red); font-weight: 550; font-size: .92rem; }

.search { position: relative; }
.search svg { position: absolute; left: 15px; top: 50%; transform: translateY(-50%); color: var(--ink-2); pointer-events: none; }
.search .input { padding-left: 46px; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 2px; scrollbar-width: none; }
.chips.scroll::-webkit-scrollbar { display: none; }
.chip {
  border: 0; background: var(--surface-2); border-radius: 999px; padding: 0 16px; min-height: 40px;
  font-weight: 560; font-size: .92rem; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2);
}
.chip.on { background: var(--ink); color: var(--bg); }

/* Funciones (checkbox en forma de tarjeta) */
.roles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.role-opt { display: flex; flex-direction: column; gap: 4px; padding: 14px; border-radius: 14px; background: var(--surface-2); border: 2px solid transparent; cursor: pointer; text-align: left; }
.role-opt.on { background: var(--primary-soft); border-color: var(--accent); }
.role-opt b { font-weight: 650; color: var(--ink); display: flex; align-items: center; gap: 8px; }
.role-opt span { font-size: .84rem; color: var(--ink-2); }

/* ---------------- Estados ---------------- */
.badge { display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; padding: 3px 10px; font-size: .8rem; font-weight: 600; white-space: nowrap; background: var(--surface-2); color: var(--ink-2); }
.badge.dot::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.preparando { background: var(--surface-2); color: var(--ink-2); }
.badge.en_camino { background: var(--blue-soft); color: var(--blue); }
.badge.recibido, .badge.resuelta, .badge.ok { background: var(--green-soft); color: var(--green); }
.badge.incidencias, .badge.faltante, .badge.sobrante, .badge.danado { background: var(--amber-soft); color: var(--amber); }
.badge.anulado { background: var(--surface-2); color: var(--gray); }
.badge.role { background: var(--surface-2); color: var(--ink-2); }
.badge.off { background: var(--surface-2); color: var(--gray); }
.badge.lock { background: var(--red-soft); color: var(--red); }

/* ---------------- Editor de envío ---------------- */
.editor { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.editor > * { min-width: 0; }
@media (max-width: 900px) { .editor { grid-template-columns: minmax(0, 1fr); } }
.picker { padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); grid-auto-rows: max-content; align-content: start; gap: 10px; max-height: 58vh; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 9px 9px 9px 2px; margin: -7px -9px 0 0; }
@media (max-width: 900px) { .tiles { max-height: none; } }
.tile { position: relative; text-align: left; min-height: 80px; height: auto; padding: 13px 14px; border-radius: 14px; border: 2px solid transparent; background: var(--surface-2); display: block; overflow: visible; }
.tile:active { transform: scale(.98); }
.tile .name { display: block; font-weight: 600; line-height: 1.25; overflow-wrap: break-word; -webkit-hyphens: auto; hyphens: auto; }
.tile .unit { display: block; margin-top: 5px; color: var(--ink-3); font-size: .82rem; }
.tile.in { background: var(--primary-soft); border-color: var(--accent); }
.tile .qty-badge { position: absolute; top: -8px; right: -8px; background: var(--primary); color: var(--primary-ink); border-radius: 999px; padding: 2px 9px; font-size: .8rem; font-weight: 700; border: 2px solid var(--surface); }
.tile.create { background: var(--surface); border: 2px dashed var(--accent); color: var(--accent); }

.cart { position: sticky; top: 88px; display: flex; flex-direction: column; max-height: calc(100vh - 116px); }
@media (max-width: 900px) { .cart { position: static; max-height: none; } }
.cart-head { padding: 18px 20px 14px; }
.cart-list { overflow-y: auto; -webkit-overflow-scrolling: touch; flex: 1; }
.cart-row { display: flex; align-items: center; gap: 8px; padding: 10px 12px 10px 20px; border-top: 1px solid var(--line); }
.cart-row.flash { animation: flash 1s ease; }
@keyframes flash { from { background: var(--primary-soft); } to { background: transparent; } }
.cart-row .name { font-weight: 600; }
.cart-row .note { color: var(--amber); font-size: .84rem; }
.cart-foot { padding: 16px 20px 20px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 14px; }

.stepper { display: inline-flex; align-items: center; border-radius: 12px; background: var(--surface-2); flex: none; }
.stepper button { width: 44px; height: 46px; border: 0; background: transparent; display: grid; place-items: center; color: var(--ink); border-radius: 12px; }
.stepper button:active { background: var(--surface-3); }
.stepper button:disabled { color: var(--ink-3); cursor: not-allowed; }
.stepper input { width: 56px; height: 46px; border: 0; text-align: center; font-weight: 650; font-size: 1.05rem; font-variant-numeric: tabular-nums; -moz-appearance: textfield; background: transparent; }
.stepper input:focus { outline: none; }
.stepper input::-webkit-outer-spin-button, .stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.stepper .u { padding-right: 6px; color: var(--ink-3); font-size: .85rem; min-width: 26px; }
.stepper.lg { border-radius: 16px; }
.stepper.lg button { width: 64px; height: 64px; border-radius: 16px; }
.stepper.lg input { width: 96px; height: 64px; font-size: 1.6rem; }

/* ---------------- Recepción ---------------- */
.progress { height: 6px; background: var(--surface-3); border-radius: 999px; overflow: hidden; }
.progress > div { height: 100%; background: var(--green); border-radius: 999px; transition: width .25s ease; }
.check-row { display: flex; align-items: center; gap: 14px; padding: 14px 16px 14px 20px; border-top: 1px solid var(--line); transition: background .2s; }
.check-row.ok { background: var(--ok-bg); }
.check-row.issue { background: var(--issue-bg); }
.check-row .name { font-weight: 600; font-size: 1.05rem; }
.check-row .sent { font-variant-numeric: tabular-nums; font-weight: 650; font-size: 1.1rem; white-space: nowrap; }
.check-row .detail { font-size: .88rem; color: var(--amber); font-weight: 550; }
.vbtn { width: 54px; height: 54px; border-radius: 50%; border: 2px solid var(--line); background: var(--surface); display: grid; place-items: center; flex: none; color: var(--ink-3); transition: all .15s; }
.vbtn.okb:not(.on) { color: var(--green); border-color: var(--green); }
.vbtn.issueb:not(.on) { color: var(--amber); border-color: var(--amber); }
.vbtn.okb.on { background: var(--green); border-color: var(--green); color: var(--on-color); }
.vbtn.issueb.on { background: var(--amber); border-color: var(--amber); color: var(--on-color); }

.sticky-foot { position: sticky; bottom: var(--tabbar-h); z-index: 5; background: linear-gradient(180deg, var(--bg-clear), var(--bg) 35%); padding: 20px 0 calc(8px + env(safe-area-inset-bottom)); }

/* ---------------- Tablas y listas ---------------- */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: .8rem; color: var(--ink-3); padding: 10px 20px; font-weight: 550; border-top: 1px solid var(--line); }
.table td { padding: 13px 20px; border-top: 1px solid var(--line); vertical-align: top; }
.table .r { text-align: right; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.list-row { display: flex; align-items: center; gap: 14px; padding: 15px 20px; border: 0; border-top: 1px solid var(--line); width: 100%; text-align: left; background: transparent; color: inherit; }
.card > .list-row:first-child, .card > div:first-child > .list-row:first-child { border-top: 0; }
button.list-row:active, a.list-row:active { background: var(--surface-2); }
.list-row .t { font-weight: 600; }
.list-row > svg:last-child { color: var(--ink-2); }
.day-head { padding: 18px 20px 6px; font-size: .85rem; font-weight: 600; color: var(--ink-3); }
.day-head + .list-row { border-top: 0; }

.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.kv > div { padding: 16px 20px; border-left: 1px solid var(--line); }
.kv > div:first-child { border-left: 0; }
@media (max-width: 640px) { .kv > div { border-left: 0; border-top: 1px solid var(--line); } .kv > div:first-child { border-top: 0; } }
.kv .k { font-size: .82rem; color: var(--ink-3); font-weight: 500; }
.kv .v { font-weight: 650; margin-top: 2px; font-size: 1.05rem; }
.kv .s { color: var(--ink-3); font-size: .86rem; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 16px 18px; }
.stat .n { font-size: 1.8rem; font-weight: 650; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat .l { color: var(--ink-3); font-size: .85rem; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: flex; gap: 14px; padding: 12px 0; }
.timeline li + li { border-top: 1px solid var(--line); }
.timeline .dot { width: 30px; height: 30px; border-radius: 50%; background: var(--surface-2); display: grid; place-items: center; flex: none; color: var(--ink-2); }
.timeline .hash { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .74rem; color: var(--ink-3); }

.tabs { display: flex; gap: 4px; overflow-x: auto; margin-bottom: 20px; padding: 4px; background: var(--surface-2); border-radius: 14px; scrollbar-width: none; width: fit-content; max-width: 100%; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { border: 0; background: transparent; padding: 0 16px; min-height: 40px; border-radius: 10px; font-weight: 560; color: var(--ink-2); white-space: nowrap; display: inline-flex; align-items: center; gap: 8px; }
.tabs button svg { display: none; }
.tabs button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.08); }

.empty { text-align: center; padding: 34px 20px; color: var(--ink-3); }
.empty svg { color: var(--ink-3); margin-bottom: 6px; }
.empty .t { font-weight: 600; color: var(--ink-2); }
.empty p { margin-top: 4px; }

/* ---------------- Diálogos ---------------- */
.overlay { position: fixed; inset: 0; z-index: 100; background: var(--overlay); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); display: flex; align-items: center; justify-content: center; padding: 20px; animation: fade .15s ease; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.dialog { background: var(--surface); border: 1px solid var(--line); border-radius: 24px; box-shadow: var(--shadow-lg); width: 100%; max-width: 540px; max-height: calc(100vh - 40px); max-height: calc(100dvh - 40px); display: flex; flex-direction: column; animation: pop .18s ease; }
.dialog.wide { max-width: 760px; }
@keyframes pop { from { transform: translateY(10px) scale(.985); opacity: 0; } to { transform: none; opacity: 1; } }
.dialog-head { display: flex; align-items: center; gap: 12px; padding: 20px 20px 10px 24px; }
.dialog-head h2 { flex: 1; font-size: 1.2rem; }
.dialog-head .icon-btn { color: var(--ink); background: var(--surface-2); border-radius: 50%; width: 38px; height: 38px; }
.dialog-body { padding: 6px 24px 22px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.dialog-foot { padding: 14px 20px calc(18px + env(safe-area-inset-bottom)); display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.dialog-foot .btn { flex: 1; min-width: 140px; }
.steps { display: flex; gap: 6px; padding: 0 24px 8px; }
.steps span { flex: 1; height: 4px; border-radius: 4px; background: var(--line); }
.steps span.on { background: var(--accent); }

.people-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; }
.person { min-height: 60px; border-radius: 14px; border: 2px solid transparent; background: var(--surface-2); font-weight: 600; display: flex; align-items: center; gap: 10px; padding: 8px 12px; text-align: left; }
.person.on { border-color: var(--accent); background: var(--primary-soft); }
.person .grow { min-width: 0; overflow-wrap: break-word; -webkit-hyphens: auto; hyphens: auto; line-height: 1.25; }
.person:disabled { background: var(--disabled-bg); color: var(--disabled-ink); cursor: not-allowed; }
.person:disabled .av { filter: grayscale(1); }
.av { width: 36px; height: 36px; border-radius: 50%; display: inline-grid; place-items: center; font-size: .85rem; font-weight: 700; flex: none; }
.av-0 { background: var(--av0-bg); color: var(--av0-fg); }
.av-1 { background: var(--av1-bg); color: var(--av1-fg); }
.av-2 { background: var(--av2-bg); color: var(--av2-fg); }
.av-3 { background: var(--av3-bg); color: var(--av3-fg); }
.av-4 { background: var(--av4-bg); color: var(--av4-fg); }
.av-5 { background: var(--av5-bg); color: var(--av5-fg); }
.av-6 { background: var(--av6-bg); color: var(--av6-fg); }
.av-7 { background: var(--av7-bg); color: var(--av7-fg); }

.pin-wrap { display: flex; flex-direction: column; align-items: center; gap: 22px; padding-top: 4px; }
.pin-dots { display: flex; gap: 16px; height: 18px; align-items: center; }
.pin-dots span { width: 13px; height: 13px; border-radius: 50%; border: 1.5px solid var(--ink-3); transition: background .1s; }
.pin-dots span.on { background: var(--ink); border-color: var(--ink); }
.pin-dots.shake { animation: shake .35s ease; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
.keypad { display: grid; grid-template-columns: repeat(3, 76px); gap: 14px 24px; }
.keypad button { width: 76px; height: 76px; border-radius: 50%; border: 0; background: var(--surface-2); color: var(--ink); font-size: 1.75rem; font-weight: 400; display: grid; place-items: center; }
.keypad button:active { background: var(--surface-3); transform: scale(.95); }
.keypad button.fn { background: transparent; font-size: .95rem; font-weight: 550; color: var(--ink-2); }

.activation-code { font-size: 2.6rem; font-weight: 700; letter-spacing: .12em; padding: 14px 18px; border-radius: 16px; background: var(--surface-2); color: var(--ink); align-self: center; }
.signer-card { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 14px; background: var(--surface-2); }

/* ---------------- Avisos ---------------- */
.toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(28px + max(var(--tabbar-h), env(safe-area-inset-bottom))); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; width: min(92vw, 520px); pointer-events: none; }
.toast { background: var(--toast-bg); color: var(--toast-ink); padding: 12px 18px; border-radius: 999px; box-shadow: var(--shadow-lg); font-weight: 550; font-size: .95rem; display: flex; align-items: center; gap: 10px; animation: pop .2s ease; pointer-events: none; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.toast.success svg { color: var(--toast-ok); }
.toast.error { background: var(--red); color: var(--on-color); }

/* ---------------- Acceso ---------------- */
.auth { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.auth .card { width: 100%; max-width: 540px; padding: 32px; }
.auth .logo-lg { width: 56px; height: 56px; border-radius: 16px; background: var(--primary); display: grid; place-items: center; color: var(--primary-ink); margin-bottom: 18px; }
.auth hr { border: 0; border-top: 1px solid var(--line); margin: 0; width: 100%; }
.branch-pick { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.branch-pick button { min-height: 104px; border-radius: 18px; border: 2px solid transparent; background: var(--surface-2); font-size: 1.25rem; font-weight: 650; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; color: var(--ink); }
.branch-pick button svg { color: var(--ink-2); }
.branch-pick button.on { border-color: var(--accent); background: var(--primary-soft); }

.spinner { width: 26px; height: 26px; border: 2.5px solid var(--surface-3); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; margin: 40px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

.integrity { display: inline-flex; align-items: center; gap: 6px; font-size: .86rem; font-weight: 550; }
.integrity.ok { color: var(--green); }
.integrity.bad { color: var(--red); }


/* ---------------- Móvil (≤ 600 px) ----------------
   Navegación en una barra de pestañas abajo, filas que apilan sus etiquetas y botones
   debajo del texto, columnas secundarias ocultas y diálogos como hojas inferiores. */
.tabbar { display: none; }
@media (max-width: 600px) {
  :root { --tabbar-h: calc(58px + env(safe-area-inset-bottom)); }
  .hide-sm { display: none !important; }
  .show-sm { display: block; }
  span.show-sm { display: inline; }
  h1 { font-size: 1.5rem; }

  /* Barra superior: logo, sucursal y modo administrador */
  .topbar { gap: 10px; padding: calc(env(safe-area-inset-top) + 8px) max(16px, env(safe-area-inset-right)) 8px max(16px, env(safe-area-inset-left)); min-height: 52px; }
  .topbar .nav { display: none; }
  .branch-label { padding-left: 10px; flex: 0 1 auto; }
  .admin-pill { margin-left: auto; padding: 6px 11px; }
  .admin-pill .pill-long { display: none; }

  /* Barra de pestañas inferior */
  .tabbar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    background: var(--tabbar-bg); backdrop-filter: saturate(180%) blur(16px); -webkit-backdrop-filter: saturate(180%) blur(16px);
    border-top: 1px solid var(--line);
    padding: 4px max(8px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(8px, env(safe-area-inset-left));
  }
  .tabbar a {
    flex: 1; position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    min-height: 54px; color: var(--ink-3); font-size: .72rem; font-weight: 600; letter-spacing: .01em;
  }
  .tabbar a.active { color: var(--accent); }
  .tabbar a svg { width: 24px; height: 24px; }
  .tabbar .badge-dot {
    position: absolute; top: 3px; left: calc(50% + 7px); min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px;
    display: grid; place-items: center; background: var(--blue); color: var(--on-color); font-size: .72rem; font-weight: 700; border: 2px solid var(--bg);
  }

  main.page { padding: 20px max(16px, env(safe-area-inset-right)) calc(28px + var(--tabbar-h)) max(16px, env(safe-area-inset-left)); }
  .page-head { gap: 10px 12px; margin-bottom: 16px; }
  .head-actions { flex: 1 1 100%; gap: 8px; }
  .head-actions > * { flex: 1 1 auto; }
  .btn { padding: 0 16px; }
  .btn.big { padding: 0 20px; }
  .card.pad { padding: 18px; }
  .section { margin-top: 24px; }
  .hero h1 { font-size: 1.9rem; }
  .hero > .btn { width: 100%; }
  .ship-card { padding: 16px 18px; }
  .ship-card .route { font-size: 1.15rem; }
  .list-row { padding: 14px 16px; gap: 12px; }
  .day-head { padding: 16px 16px 4px; }
  .cart-head { padding: 16px 16px 12px; }
  .table th, .table td { padding: 11px 14px; }
  .event-id { width: 44px; }
  .list-row .time { width: 44px; }

  /* Filas apilables: [inicio] texto / etiquetas o botones debajo / [flecha] */
  .list-row.stack-sm { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 0; align-items: center; }
  .list-row.stack-sm > .lead { grid-column: 1; grid-row: 1 / span 2; align-self: start; margin-right: 12px; }
  .list-row.stack-sm > .grow { grid-column: 2; grid-row: 1; }
  .list-row.stack-sm > .row-extra { grid-column: 2; grid-row: 2; display: flex; flex-wrap: wrap; gap: 6px 8px; margin-top: 8px; justify-self: start; }
  .list-row.stack-sm > .row-extra.actions { grid-column: 1 / -1; justify-self: stretch; margin-top: 12px; }
  .list-row.stack-sm > .row-extra.actions > .btn { flex: 1 1 auto; }
  .list-row.stack-sm:has(> .row-extra.actions) > .lead { grid-row: 1; }
  .list-row.stack-sm > .chev { grid-column: 3; grid-row: 1 / span 2; margin-left: 8px; }
  .list-row.stack-sm > svg.lead { margin-top: 2px; }

  /* Filtros que se desplazan de lado: difuminado a la derecha para indicar que hay más */
  .chips.scroll { -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent); mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent); padding-right: 24px; }

  /* Pestañas de administración: cuadrícula 3 × 2 con icono */
  .tabs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); width: 100%; }
  .tabs button { flex-direction: column; justify-content: center; gap: 3px; min-height: 58px; padding: 6px 4px; font-size: .8rem; }
  .tabs button svg { display: block; }

  /* Editor de envío: 2 columnas de productos, lista con scroll propio y filas del envío en dos líneas */
  .picker { padding: 14px; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); max-height: 52vh; max-height: 52dvh; }
  .tile { min-height: 72px; padding: 11px 12px; }
  .cart-row { flex-wrap: wrap; padding: 12px 12px 12px 16px; row-gap: 6px; }
  .cart-row > .grow { flex: 1 1 100%; }
  .cart-row .stepper { margin-right: auto; }

  /* Recepción: nombre y cantidad a la izquierda, botones a la derecha */
  .check-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; grid-template-areas: "main ok issue" "sent ok issue"; column-gap: 10px; padding: 12px 12px 12px 16px; }
  .check-row > .grow { grid-area: main; }
  .check-row > .sent { grid-area: sent; font-size: 1rem; }
  .check-row > .okb { grid-area: ok; }
  .check-row > .issueb { grid-area: issue; }
  .vbtn { width: 50px; height: 50px; }
  .sticky-foot { padding-bottom: 10px; }

  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat { padding: 14px 16px; }
  .stat .n { font-size: 1.55rem; }
  .people-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .branch-pick { grid-template-columns: 1fr; }
  .branch-pick button { min-height: 76px; flex-direction: row; }
  .auth { padding: 16px; place-items: start center; padding-top: calc(env(safe-area-inset-top) + 24px); }
  .auth .card { padding: 24px 20px; }
  .activation-code { font-size: 2.1rem; }

  /* Diálogos como hoja inferior */
  .overlay { align-items: flex-end; padding: calc(env(safe-area-inset-top) + 12px) 0 0; }
  .dialog { max-width: none; border-radius: 22px 22px 0 0; border-bottom: 0; max-height: 100%; animation: sheet .22s ease; }
  .dialog.wide { max-width: none; }
  .dialog-head { padding: 16px 14px 8px 20px; }
  .dialog-body { padding: 4px 20px 18px; }
  .steps { padding: 0 20px 8px; }
  .dialog-foot { padding: 12px 16px calc(14px + env(safe-area-inset-bottom)); }
  .dialog-foot .btn { min-width: 0; padding: 0 14px; }
  .dialog-foot .btn:first-child:not(:only-child) { flex: 0 1 auto; min-width: 96px; }
  .toast { border-radius: 16px; }
}
@keyframes sheet { from { transform: translateY(48px); opacity: .5; } to { transform: none; opacity: 1; } }
/* Móviles pequeños o con poca altura: teclado del PIN más compacto */
@media (max-width: 360px), (max-height: 720px) and (max-width: 600px) {
  .keypad { grid-template-columns: repeat(3, 66px); gap: 10px 22px; }
  .keypad button { width: 66px; height: 66px; font-size: 1.55rem; }
  .pin-wrap { gap: 16px; }
}

/* ---------------- Impresión (albarán) ---------------- */
.print-only { display: none; }
@media print {
  :root, :root[data-theme] {
  --bg: #f4f3f0; --surface: #ffffff; --surface-2: #efede8; --surface-3: #e4e1db;
  --ink: #1d1d1f; --ink-2: #45474d; --ink-3: #62646a; --placeholder: #64666c;
  --line: #dcd9d2; --field-line: #86837c;
  --primary: #1c6150; --primary-ink: #ffffff; --primary-press: #154a3d; --primary-soft: #e3efea; --accent: #1c6150;
  --focus-ring: rgba(28, 97, 80, .18);
  --blue: #1d4ca8; --blue-soft: #e8eefb; --green: #1d6a3f; --green-soft: #e4f2e9;
  --amber: #7f4a00; --amber-soft: #fbefd9; --red: #a8321f; --red-soft: #fbe6e2; --gray: #585a60;
  --on-color: #ffffff; --disabled-bg: #e4e1db; --disabled-ink: #55575d;
  --ok-bg: #eef7f1; --issue-bg: #fff6e6;
  --topbar-bg: rgba(244, 243, 240, .92); --bg-clear: rgba(244, 243, 240, 0);
  --toast-bg: rgba(29, 29, 31, .94); --toast-ink: #ffffff; --toast-ok: #7ddc9f;
  --overlay: rgba(20, 20, 25, .45); --shadow-lg: 0 24px 60px rgba(20, 20, 25, .18), 0 2px 8px rgba(20, 20, 25, .06);
  --av0-bg: #dcece4; --av0-fg: #17543f; --av1-bg: #e1e8f8; --av1-fg: #24479a; --av2-bg: #eee1f2; --av2-fg: #6f2c84; --av3-bg: #f8e3d6; --av3-fg: #8a3f10;
  --av4-bg: #e0efdb; --av4-fg: #2c6320; --av5-bg: #f6dfe3; --av5-fg: #8c2a3b; --av6-bg: #e4e4f6; --av6-fg: #3c4594; --av7-bg: #f0e9d2; --av7-fg: #5f4b0e;
  color-scheme: light;
  }
  @page { margin: 14mm; }
  body { background: #fff; font-size: 12pt; }
  .topbar, .tabbar, .no-print, .toasts, .offline-bar, .btn, .icon-btn, .back-btn { display: none !important; }
  .print-only { display: block; }
  main.page { padding: 0; max-width: none; }
  .card, .kv { border-color: #999; }
  .badge { border: 1px solid #999; }
  .signatures { display: grid !important; grid-template-columns: 1fr 1fr 1fr; gap: 24px; margin-top: 40px; }
  .signatures div { border-top: 1px solid #000; padding-top: 6px; font-size: 10pt; }
}
