:root {
  --primary: #2563EB;
  --primary-hover: #1D4ED8;
  --on-primary: #FFFFFF;
  --accent: #059669;
  --danger: #DC2626;
  --warning: #B45309;
  --bg: #F1F5F9;
  --surface: #FFFFFF;
  --surface-2: #F8FAFC;
  --text: #0F172A;
  --muted: #475569;
  --border: #E2E8F0;
  --ring: #2563EB;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .08);
  --shadow-lg: 0 10px 30px rgba(15, 23, 42, .18);
  --radius: 12px;
  --font-head: "Poppins", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-body: "Open Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --primary: #3B82F6; --primary-hover: #60A5FA; --on-primary: #0B1120;
    --accent: #34D399; --danger: #F87171; --warning: #FBBF24;
    --bg: #0B1120; --surface: #111827; --surface-2: #1F2937;
    --text: #F1F5F9; --muted: #94A3B8; --border: #334155; --ring: #60A5FA;
    --shadow: 0 1px 2px rgba(0,0,0,.4); --shadow-lg: 0 10px 30px rgba(0,0,0,.6);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.5 var(--font-body);
  min-height: 100vh;
}
h1, h2, h3 { font-family: var(--font-head); margin: 0; line-height: 1.25; }
h2 { font-size: 16px; font-weight: 600; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }
/* ── pantalla de entrada (PIN) ── */
.entrada { position: fixed; inset: 0; z-index: 200; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(circle at 50% 0%, color-mix(in srgb, var(--primary) 18%, var(--bg)), var(--bg) 60%); overflow-y: auto; }
body.sin-sesion > :not(.entrada):not(.toasts) { visibility: hidden; }
.entrada-caja { width: min(360px, 100%); text-align: center; display: grid; gap: 10px; justify-items: center; }
.entrada-caja h1 { font: 700 22px var(--font-head); margin: 4px 0 6px; }
.entrada-caja form { width: 100%; text-align: left; display: grid; gap: 4px; }
.entrada-caja form h2 { font: 600 18px var(--font-head); margin: 0; text-align: center; }
.entrada-caja form .btn { margin-top: 6px; }
.ent-lista { display: grid; gap: 10px; width: 100%; }
.ent-persona { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 60px; padding: 10px 16px; border-radius: 14px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font: 600 17px var(--font-head); cursor: pointer; text-align: left; }
.ent-persona:hover { border-color: var(--primary); }
.ent-ini { display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; flex: none;
  background: color-mix(in srgb, var(--primary) 22%, var(--surface)); color: var(--primary); font: 700 16px var(--font-head); }
.ent-hola { display: flex; align-items: center; gap: 6px; font-size: 17px; margin: 0; }
.pin-puntos { display: flex; gap: 14px; justify-content: center; margin: 6px 0 10px; }
.pin-puntos i { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--muted); transition: background .12s, border-color .12s; }
.pin-puntos i.lleno { background: var(--primary); border-color: var(--primary); }
.pin-puntos.error { animation: temblar .35s; }
@keyframes temblar { 25% { transform: translateX(-8px); } 50% { transform: translateX(8px); } 75% { transform: translateX(-4px); } }
.pin-teclado { display: grid; grid-template-columns: repeat(3, 72px); gap: 12px; justify-content: center; }
.pin-teclado button { width: 72px; height: 72px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font: 600 26px var(--font-head); cursor: pointer; display: grid; place-items: center; }
.pin-teclado button:active { background: color-mix(in srgb, var(--primary) 25%, var(--surface)); }
.pin-teclado button svg.ic { width: 24px; height: 24px; }
/* sesión y usuarios */
.sb-sesion { margin-top: auto; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 4px 0;
  border-top: 1px solid var(--border); flex-wrap: wrap; }
.usuarios { display: grid; gap: 8px; margin: 10px 0; }
.usuario-fila { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 8px 10px; border: 1px solid var(--border); border-radius: 12px; }
.usuario-fila .spacer { flex: 1; }
.usuario-nombre { font: 600 15px var(--font-body); border: 1px solid transparent; background: transparent; color: var(--text);
  padding: 6px 8px; border-radius: 8px; min-width: 0; width: 160px; }
.usuario-nombre:not(:disabled):hover, .usuario-nombre:focus { border-color: var(--border); background: var(--surface-2); }

/* recuperar desde el Maestro */
.m-resumen { margin-top: 12px; display: grid; gap: 8px; }
.m-resumen p { margin: 0; }
.m-lista { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; max-height: 260px; overflow-y: auto; }
.m-lista li { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 8px; }
#panel-maestro .ok { color: var(--accent); font-weight: 600; }

/* casillas de números sin flechitas: se escribe el número directo */
input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
input[type="number"]::-webkit-inner-spin-button, input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
svg.ic { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }

/* ── Topbar ── */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center;
  background: var(--primary); color: var(--on-primary); font: 700 14px var(--font-head);
}
.brand h1 { font-size: 17px; }
.live { margin: 0; font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.live .dot { width: 8px; height: 8px; border-radius: 50%; background: #94A3B8; }
.live.on .dot { background: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
.live.off .dot { background: var(--danger); }

/* ── Tabs ── */
.tabs {
  display: flex; gap: 4px; padding: 8px 16px 0; background: var(--surface);
  border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none;
}
.tabs button {
  border: 0; background: none; color: var(--muted); font: 600 14px var(--font-body);
  padding: 10px 14px; min-height: 44px; border-bottom: 2px solid transparent; cursor: pointer; white-space: nowrap;
  transition: color .2s, border-color .2s;
}
.tabs button:hover { color: var(--text); }
.tabs button[aria-selected="true"] { color: var(--primary); border-bottom-color: var(--primary); }

main { padding: 16px; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 8px 14px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: 600 14px var(--font-body); cursor: pointer; text-decoration: none;
  transition: background .2s, border-color .2s, transform .1s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-ghost { border-style: dashed; background: transparent; width: 100%; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger-ghost { color: var(--danger); border-color: transparent; background: transparent; }
.btn-sm { min-height: 34px; padding: 4px 10px; font-size: 13px; }
.icon-btn {
  width: 40px; height: 40px; display: grid; place-items: center; border-radius: 10px;
  border: 0; background: transparent; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* ── Toolbar ── */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.search { position: relative; flex: 1 1 260px; }
.search-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); display: flex; }
.search input { padding-left: 38px; }
.segmented {
  display: inline-flex; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 3px;
}
.segmented button {
  border: 0; background: transparent; color: var(--muted); font: 600 13px var(--font-body);
  padding: 6px 14px; min-height: 36px; border-radius: 8px; cursor: pointer;
}
.segmented button[aria-pressed="true"] { background: var(--primary); color: var(--on-primary); }
.segmented.big { display: flex; margin-bottom: 14px; }
.segmented.big button { flex: 1; min-height: 42px; font-size: 14px; }

/* ── Inputs ── */
input, select, textarea {
  width: 100%; min-height: 42px; padding: 9px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: 15px var(--font-body);
}
textarea { resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--ring); outline-offset: 0; border-color: transparent; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; min-width: 0; }
.field label { font-size: 13px; font-weight: 600; color: var(--muted); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px 4px; margin: 0 0 14px; }
legend { font: 600 13px var(--font-head); padding: 0 6px; color: var(--text); }

/* ── Kanban ── */
.board {
  display: flex; gap: 12px; align-items: flex-start;
  overflow-x: auto; padding-bottom: 12px; min-height: calc(100vh - 230px);
  scroll-snap-type: x proximity; position: relative;
}
.col {
  flex: 0 0 300px; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius); display: flex; flex-direction: column; max-height: calc(100vh - 230px);
  scroll-snap-align: start; transition: flex-basis .2s ease;
}
.col-head {
  display: flex; align-items: center; gap: 8px; padding: 10px 8px 10px 12px;
  border-bottom: 1px solid var(--border); background: var(--surface); border-radius: var(--radius) var(--radius) 0 0;
  border-top: 4px solid var(--col);
}
.col-title { flex: 1; min-width: 0; }
.col-title h3 { font-size: 13.5px; font-weight: 600; }
.col-title p { margin: 0; font-size: 12px; color: var(--muted); }
.count {
  min-width: 26px; height: 24px; padding: 0 8px; border-radius: 12px; display: grid; place-items: center;
  font: 700 12px var(--font-body); background: color-mix(in srgb, var(--col) 15%, transparent); color: var(--col);
}
.col-body { padding: 10px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; flex: 1; min-height: 80px; }
.col.drop-over { outline: 2px dashed var(--col); outline-offset: -2px; background: color-mix(in srgb, var(--col) 8%, var(--surface-2)); }
.empty { color: var(--muted); font-size: 13px; text-align: center; padding: 18px 8px; border: 1px dashed var(--border); border-radius: 10px; }

/* columna plegada */
.col.collapsed { flex: 0 0 52px; cursor: pointer; }
.col.collapsed .col-body, .col.collapsed .col-title p { display: none; }
.col.collapsed .col-head { flex-direction: column; border-radius: var(--radius); border-bottom: 0; padding: 10px 4px; height: 100%; min-height: 260px; }
.col.collapsed .col-title { writing-mode: vertical-rl; transform: rotate(180deg); flex: 0; }
.col.collapsed .col-title h3 { white-space: nowrap; }

/* tarjeta */
.card {
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--col);
  border-radius: 10px; padding: 10px 12px; box-shadow: var(--shadow); cursor: grab;
  transition: box-shadow .2s, transform .15s;
}
.card:hover { box-shadow: var(--shadow-lg); }
.card.dragging { opacity: .5; transform: rotate(1.5deg); }
.card-top { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; flex-wrap: wrap; }
.tag {
  display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 700;
  padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border);
}
.tag.shopify { background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent); border-color: transparent; }
.tag.lima { background: color-mix(in srgb, var(--primary) 12%, transparent); color: var(--primary); border-color: transparent; }
.tag.provincia { background: color-mix(in srgb, #7C3AED 14%, transparent); color: #7C3AED; border-color: transparent; }
.tag.hoy { background: var(--accent); color: #fff; border-color: transparent; }
.tag.manana { background: color-mix(in srgb, var(--accent) 15%, transparent); color: var(--accent); border-color: transparent; }
.tag.atrasado { background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); border-color: transparent; }
@media (prefers-color-scheme: dark) { .tag.provincia { color: #A78BFA; } }
.card h4 { margin: 2px 0; font: 600 14.5px var(--font-head); }
.card .where { font-size: 12.5px; color: var(--muted); display: flex; gap: 4px; align-items: flex-start; }
.card .where svg { width: 14px; height: 14px; margin-top: 2px; }
.card .prods { font-size: 12.5px; margin: 4px 0; color: var(--text); }
.money { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border); }
.money div { display: flex; flex-direction: column; }
.money span { font-size: 11px; color: var(--muted); }
.money strong { font-size: 13.5px; font-variant-numeric: tabular-nums; }
.money .debe { color: var(--danger); }
.money .ok { color: var(--accent); }
.motivo { font-size: 12.5px; color: var(--danger); margin-top: 6px; }
.card-actions { display: flex; gap: 6px; margin-top: 8px; }
.card-actions select { min-height: 34px; padding: 4px 8px; font-size: 13px; flex: 1; }

/* ── KPIs ── */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; margin-bottom: 14px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.kpi span { font-size: 13px; color: var(--muted); font-weight: 600; }
.kpi strong { display: block; font: 700 24px var(--font-head); margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi small { color: var(--muted); font-size: 12px; }
.kpi.green strong { color: var(--accent); }
.kpi.red strong { color: var(--danger); }
.kpi.blue strong { color: var(--primary); }
.kpi.purple strong { color: #8B5CF6; }
.kpi.gris strong { color: var(--muted); }
/* gráfico de anillo: resultados de los pedidos */
.anillo-wrap { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.anillo { width: 150px; height: 150px; flex: none; }
.anillo-n { font: 700 24px var(--font-head); fill: var(--text); }
.anillo-t { font: 500 11px var(--font-body); fill: var(--muted); }
.anillo-ley { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; flex: 1; min-width: 170px; }
.anillo-ley li { display: grid; grid-template-columns: 12px 1fr auto 40px; align-items: center; gap: 8px; font-size: 14px; }
.anillo-ley i { width: 12px; height: 12px; border-radius: 50%; }
.anillo-ley b { font-variant-numeric: tabular-nums; }
.anillo-ley small { color: var(--muted); text-align: right; }
.pct-mini { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.pct-mini div { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; }
.pct-mini b { display: block; font: 700 22px var(--font-head); color: var(--accent); }
.pct-mini span { font-size: 12.5px; color: var(--muted); }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 14px; }
.panel h2 { margin-bottom: 12px; }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 8px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 14px; }
.grid-2 .panel { margin-bottom: 0; }
.grid-gastos { display: grid; grid-template-columns: minmax(280px, 360px) 1fr; gap: 14px; align-items: start; }

/* barras */
.bars { display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 130px 1fr 90px; gap: 10px; align-items: center; font-size: 13px; }
.bar-row .lbl { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .val { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.bar-track { height: 12px; background: var(--surface-2); border-radius: 6px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 6px; transition: width .4s ease; }
.months { display: flex; align-items: flex-end; gap: 14px; height: 200px; padding-top: 10px; overflow-x: auto; }
.month { display: flex; flex-direction: column; align-items: center; gap: 6px; flex: 1; min-width: 60px; height: 100%; }
.month .pair { flex: 1; display: flex; align-items: flex-end; gap: 4px; width: 100%; justify-content: center; }
.month .b { width: 22px; border-radius: 5px 5px 0 0; min-height: 2px; transition: height .4s ease; }
.month small { font-size: 12px; color: var(--muted); }
.legend { display: flex; gap: 14px; font-size: 12.5px; color: var(--muted); margin-top: 10px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

/* tabla */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table td.num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.table th.num { text-align: right; }

/* ── Vista tabla por etapa ── */
.tabla-etapas { display: flex; flex-direction: column; gap: 12px; }
.t-etapa { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--col); border-radius: var(--radius); overflow: hidden; position: relative; }
.t-etapa .table-wrap { position: relative; }
.t-head {
  width: 100%; display: flex; align-items: center; gap: 10px; padding: 12px 14px; min-height: 48px;
  background: transparent; border: 0; color: var(--text); cursor: pointer; text-align: left; font: inherit;
}
.t-head:hover { background: var(--surface-2); }
.t-head h3 { margin: 0; font: 600 15px var(--font-head); }
.t-head .t-sub { margin-left: auto; font-size: 13px; color: var(--muted); font-weight: 600; white-space: nowrap; }
.t-etapa:not(.plegada) .t-head { border-bottom: 1px solid var(--border); }
.t-empty { margin: 12px 14px; }
.t-pedidos { font-size: 13.5px; }
.t-pedidos th { background: var(--surface-2); }
.t-pedidos td { white-space: nowrap; }
.t-pedidos td.c-wrap { white-space: normal; min-width: 160px; max-width: 280px; }
.t-pedidos tbody tr:hover { background: color-mix(in srgb, var(--col) 5%, transparent); }
.t-pedidos .c-cliente { position: sticky; left: 0; background: var(--surface); z-index: 1; min-width: 150px; }
.t-pedidos th.c-cliente { background: var(--surface-2); }
.t-pedidos tbody tr:hover .c-cliente { background: color-mix(in srgb, var(--col) 5%, var(--surface)); }
.t-pedidos .sub { display: block; font-size: 12px; color: var(--muted); }
.t-pedidos .sub svg.ic { width: 13px; height: 13px; vertical-align: -2px; }
.t-pedidos .debe { color: var(--danger); }
.t-pedidos .ok { color: var(--accent); }
.t-pedidos a { color: var(--primary); text-decoration: none; }
.link-cliente { background: none; border: 0; padding: 0; font: 600 14px var(--font-body); color: var(--text); cursor: pointer; text-align: left; }
.link-cliente:hover { color: var(--primary); text-decoration: underline; }
.cell-input {
  width: 120px; min-height: 36px; padding: 6px 8px; border-radius: 8px; border: 1px solid transparent;
  background: var(--surface-2); color: var(--text); font: 500 13.5px var(--font-body);
}
.cell-input.mono { font: 600 13.5px ui-monospace, Consolas, monospace; }
.cell-input.w-sm { width: 96px; }
.cell-input.w-cel { width: 112px; }
.cell-input.w-md { width: 150px; }
.cell-input.w-lg { width: 170px; }
.cell-input.w-xl { width: 230px; }
.cell-input.w-fecha { width: 150px; }
.cell-input.w-plata { width: 90px; text-align: right; }
.cell-select { width: auto; min-width: 110px; padding-right: 4px; cursor: pointer; }
.cell-input:hover { border-color: var(--border); }
.cell-input:focus { border: 1px solid var(--primary); background: var(--surface); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 20%, transparent); }
.cell-input.req:placeholder-shown { border: 1px dashed color-mix(in srgb, var(--danger) 55%, var(--border)); }
.cel-cell { display: flex; align-items: center; gap: 6px; }
/* arrastrar la tabla con la manito; el nombre del cliente queda fijo */
@media (pointer: fine) {
  .t-etapa .table-wrap { cursor: grab; user-select: none; }
  .t-etapa .table-wrap .cell-input { cursor: text; user-select: text; }
  .t-etapa .table-wrap select.cell-input { cursor: pointer; }
  .t-etapa .table-wrap .c-cliente, .t-etapa .table-wrap .link-cliente { cursor: grab; }
  .e-chips, .sub-tabs { cursor: grab; user-select: none; }
  .e-chips.arrastrando, .sub-tabs.arrastrando, .e-chips.arrastrando *, .sub-tabs.arrastrando * { cursor: grabbing !important; }
  .t-etapa .table-wrap.arrastrando, .t-etapa .table-wrap.arrastrando * { cursor: grabbing !important; user-select: none; }
}
.btn.rastrear { white-space: nowrap; }
/* ficha del cliente por partes */
/* arriba de la ficha: primero Lima/Provincia y debajo el estado, los dos a todo lo ancho */
.ficha-top { display: grid; gap: 12px; margin-bottom: 4px; }
.ficha-top .field { margin: 0; }
.ficha-estado select { min-height: 46px; font-weight: 600; }
.ficha-parte { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; margin: 12px 0; background: var(--surface); }
.ficha-parte h3 { display: flex; align-items: center; gap: 8px; font: 600 15px var(--font-head); margin: 0 0 10px; }
.ficha-parte h3 small { font: 500 12px var(--font-body); }
.ficha-parte h3 .n { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%;
  background: var(--primary); color: var(--on-primary); font-size: 12px; flex: none; }
.ficha-parte textarea#p-mensaje { width: 100%; font: 14px/1.5 var(--font-body); margin-bottom: 8px; }
.btn-copiar { white-space: nowrap; }
/* editor de estados */
/* ═════ menú de costado principal ═════ */
.sidebar { position: fixed; z-index: 55; top: 0; left: 0; bottom: 0; width: 260px; display: flex; flex-direction: column; gap: 10px;
  background: var(--surface); border-right: 1px solid var(--border); padding: 14px 12px calc(14px + env(safe-area-inset-bottom)); overflow-y: auto;
  transform: translateX(-105%); transition: transform .22s ease; }
body.sb-abierto .sidebar { transform: none; box-shadow: var(--shadow-lg); }
.sb-fondo { position: fixed; inset: 0; z-index: 54; background: rgba(0,0,0,.4); }
.sb-fondo[hidden] { display: none; }
.sb-brand { display: flex; align-items: center; gap: 10px; padding: 2px 4px 8px; border-bottom: 1px solid var(--border); }
.sb-brand-txt { flex: 1; min-width: 0; }
.sb-brand-txt strong { display: block; font: 700 16px var(--font-head); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-brand .live { margin: 0; }
.sb-hablale { justify-content: center; width: 100%; }
.sb-hablale svg.ic { width: 18px; height: 18px; }
.sb-nav { display: flex; flex-direction: column; gap: 2px; }
.sb-item-wrap { display: flex; align-items: center; }
.sb-item { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 44px; padding: 8px 10px; border: 0; border-radius: 10px;
  background: transparent; color: var(--text); font: 600 15px var(--font-body); cursor: pointer; text-align: left; }
.sb-item svg.ic { width: 20px; height: 20px; color: var(--muted); flex: none; }
.sb-item:hover { background: var(--surface-2); }
.sb-item[aria-current="true"] { background: color-mix(in srgb, var(--primary) 14%, transparent); color: var(--primary); }
.sb-item[aria-current="true"] svg.ic { color: var(--primary); }
.sb-item .beta { font-style: normal; font-size: 10.5px; font-weight: 700; text-transform: uppercase; padding: 1px 6px; border-radius: 999px;
  background: color-mix(in srgb, var(--warning) 22%, transparent); color: var(--warning); margin-left: 4px; }
.sb-toggle { flex: none; width: 36px; height: 36px; display: grid; place-items: center; border: 0; border-radius: 8px; background: transparent;
  color: var(--muted); cursor: pointer; }
.sb-toggle svg.ic { width: 18px; height: 18px; transition: transform .15s; }
.sb-toggle[aria-expanded="false"] svg.ic { transform: rotate(-90deg); }
.sb-toggle:hover { background: var(--surface-2); color: var(--text); }
.sb-toggle.chico { width: 30px; height: 30px; }
.sb-arbol { padding-left: 12px; margin: 0 0 4px 18px; border-left: 2px solid var(--border); }
.sb-arbol[hidden] { display: none; }
.sb-g-fila { display: flex; align-items: center; }
.sb-g, .sb-s { display: flex; align-items: center; gap: 8px; width: 100%; min-height: 38px; padding: 6px 8px; border: 0; border-radius: 8px;
  background: transparent; color: var(--text); cursor: pointer; text-align: left; font: 600 14px var(--font-body); }
.sb-g i { width: 9px; height: 9px; border-radius: 50%; background: var(--col); flex: none; }
.sb-s { font-weight: 500; color: var(--muted); padding-left: 25px; }
.sb-g b, .sb-s b { margin-left: auto; font-size: 11.5px; padding: 0 7px; border-radius: 999px; background: var(--surface-2); color: var(--text); }
.sb-g:hover, .sb-s:hover { background: var(--surface-2); }
.sb-s[aria-current="true"], .sb-g[aria-current="true"] { background: color-mix(in srgb, var(--col) 18%, transparent); color: var(--text); box-shadow: inset 3px 0 0 var(--col); }
.sb-sep { height: 1px; background: var(--border); margin: 8px 4px; }
.topbar-titulo { display: none; margin: 0; font: 600 18px var(--font-head); flex: 1; }
.brand-mark { position: relative; overflow: hidden; }
.brand-mark .logo-img { width: 100%; height: 100%; object-fit: cover; display: block; }
.brand-mark .logo-img[hidden], .brand-ini[hidden] { display: none; }
.brand-mark.grande { width: 72px; height: 72px; font-size: 24px; border-radius: 16px; }
.config-logo { display: flex; align-items: center; gap: 14px; margin: 10px 0 14px; }
.config { max-width: 560px; }
.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.pill.verde { background: color-mix(in srgb, var(--accent) 20%, transparent); color: var(--accent); }
.pill.ambar { background: color-mix(in srgb, var(--warning) 20%, transparent); color: var(--warning); }
.pill.gris { background: var(--surface-2); color: var(--muted); }
.pill.rojo { background: color-mix(in srgb, var(--danger) 18%, transparent); color: var(--danger); }
td.verde, span.verde { color: var(--accent); font-weight: 700; }
td.rojo, span.rojo { color: var(--danger); font-weight: 700; }

/* finanzas: comparativa y porcentajes */
.comp-fila { display: grid; grid-template-columns: 82px 1fr auto; gap: 10px; align-items: center; margin: 10px 0; }
.comp-fila .bar-track { height: 18px; border-radius: 9px; }
.comp-fila .bar-fill { height: 100%; border-radius: 9px; }
.comp-fila strong { font-variant-numeric: tabular-nums; }
.comp-nota { margin: 12px 0 0; font-size: 14px; }
.pct-lista { display: grid; gap: 16px; }
.pct-cab { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 6px; }
.pct-cab b { font-size: 22px; font-family: Poppins, sans-serif; }
.pct-barra { display: flex; height: 14px; border-radius: 7px; overflow: hidden; background: var(--surface-2); }
.pct-barra i { display: block; height: 100%; }
.pct-ley { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 6px; font-size: 13px; color: var(--muted); }
.pct-ley span::before { content: ""; display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--c); margin-right: 5px; }
.integ h2 { margin-bottom: 6px; }
/* en la PC el menú queda fijo al costado, junto al nombre de la tienda */
.btn-hamburguesa { flex: none; }
.btn-hamburguesa svg.ic { width: 22px; height: 22px; }
@media (min-width: 900px) {
  body { padding-left: 260px; transition: padding-left .22s ease; }
  .sidebar { transform: none; }
  .topbar .brand { display: none; }
  .topbar-titulo { display: block; }
  .tabs { display: none !important; }
  /* las pestañas de etapas (Nuevos, Lima, Provincia…) se ven SIEMPRE en la pantalla, también con el menú abierto */
  /* menú escondido con la hamburguesa: la tabla usa todo el ancho */
  body.sb-oculto { padding-left: 0; }
  body.sb-oculto .sidebar { transform: translateX(-105%); }
  body.sb-oculto .topbar .brand { display: flex; }
}

/* menú lateral (hamburguesa) */
.btn-menu { display: inline-flex; align-items: center; gap: 6px; }
.btn-menu svg.ic { width: 18px; height: 18px; }
.menu-lateral { position: fixed; z-index: 50; top: 0; left: 0; bottom: 0; width: min(300px, 86vw); overflow-y: auto;
  background: var(--surface); border-right: 1px solid var(--border); box-shadow: var(--shadow-lg); padding: 12px; }
.menu-lateral[hidden] { display: none; }
.menu-fondo { position: fixed; inset: 0; z-index: 49; background: rgba(0,0,0,.35); }
.menu-fondo[hidden] { display: none; }
.ml-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.ml-head strong { font: 600 16px var(--font-head); flex: 1; }
.ml-fijar { font-size: 12.5px; color: var(--muted); display: flex; gap: 6px; align-items: center; order: 3; flex-basis: 100%; cursor: pointer; }
.ml-fijar input { width: 18px; height: 18px; min-height: 0; padding: 0; margin: 0; flex: none; accent-color: var(--primary); }
@media (max-width: 899px) { .ml-fijar { display: none; } }
.ml-grupo { margin-bottom: 6px; }
.ml-g, .ml-s { display: flex; align-items: center; gap: 8px; width: 100%; min-height: 42px; padding: 8px 10px; border: 0;
  background: transparent; color: var(--text); border-radius: 10px; cursor: pointer; text-align: left; }
.ml-g { font: 600 15px var(--font-head); }
.ml-g i { width: 10px; height: 10px; border-radius: 50%; background: var(--col); flex: none; }
.ml-s { font: 500 14px var(--font-body); padding-left: 30px; color: var(--muted); }
.ml-g b, .ml-s b { margin-left: auto; font-size: 12px; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--text); }
.ml-g:hover, .ml-s:hover { background: var(--surface-2); }
.ml-s[aria-current="true"] { background: color-mix(in srgb, var(--col) 18%, transparent); color: var(--text); box-shadow: inset 3px 0 0 var(--col); }
.ml-g[aria-current="true"] { color: var(--col); }
/* menú fijo al costado (en pantallas anchas): reemplaza las pestañas */
@media (min-width: 900px) {
  body.menu-fijo .pedidos-layout { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 14px; align-items: start; }
  body.menu-fijo .menu-lateral { position: sticky; top: calc(var(--alto-topbar, 64px) + 8px); bottom: auto; width: auto;
    max-height: calc(100vh - var(--alto-topbar, 64px) - 24px); box-shadow: none; border: 1px solid var(--border); border-radius: var(--radius); z-index: 1; }
  body.menu-fijo [data-ml-cerrar] { display: none; }
}

/* burbujita de vista previa del mensaje */
.burbuja-msg { position: fixed; z-index: 60; background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: var(--shadow-lg); padding: 10px; }
.burbuja-msg[hidden] { display: none; }
.bm-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.bm-head strong { font: 600 14px var(--font-head); }
.bm-head small { color: var(--muted); font-size: 12px; flex: 1; }
.burbuja-msg textarea { width: 100%; min-height: 170px; max-height: 45vh; resize: vertical; border-radius: 10px; border: 1px solid var(--border);
  background: color-mix(in srgb, #25D366 8%, var(--surface-2)); color: var(--text); font: 14px/1.45 var(--font-body); padding: 10px; }
.bm-acciones { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.sel-estado { min-width: 150px; font-weight: 600; border-left: 4px solid var(--col) !important; }
.estados { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; margin-top: 10px; }
.estado-grupo { border: 1px solid var(--border); border-radius: 12px; padding: 10px; background: var(--surface-2); }
.estado-grupo h3 { font: 600 14px var(--font-head); margin: 0 0 8px; }
.estado-fila { display: flex; gap: 6px; align-items: center; margin-bottom: 6px; }
.estado-fila input[type=color] { width: 34px; height: 34px; padding: 0; border: 0; background: none; cursor: pointer; flex: none; }
.estado-nombre { flex: 1; min-width: 0; min-height: 36px; padding: 6px 8px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: 14px var(--font-body); }
.estado-fila.nuevo .estado-nombre { border-style: dashed; }
.t-sub b { font-weight: 700; }
.t-sub .debe { color: var(--danger); }
.t-sub .pagar { color: var(--warning); }
.cell-select.sel-pend { color: var(--warning); font-weight: 600; }
.cell-select.sel-ok { color: var(--accent); font-weight: 600; }
/* pestañas de etapas fijas arriba en la vista de pedidos */
#tabla-pedidos .e-chips { margin: 0 0 10px; padding: 8px 0; align-items: center; }
.e-grupo { flex: none; font: 700 11px var(--font-head); text-transform: uppercase; letter-spacing: .06em; color: var(--muted);
  padding-left: 10px; margin-left: 4px; border-left: 2px solid var(--border); align-self: stretch; display: flex; align-items: center; }
.e-grupo-fin { padding-left: 0; }
#tabla-pedidos .t-head { cursor: default; }
#tabla-pedidos .t-head:hover { background: transparent; }
.cell-input.w-prod { width: 260px; }
.x-precio { font-size: 12px; color: var(--muted); white-space: nowrap; }
.cell-input.w-cant { width: 58px; text-align: center; }
.multi-prod { max-width: 220px; white-space: normal; font-size: 13px; }
.wa-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; flex: none;
  background: #128C7E; color: #fff !important;
}
.wa-btn:hover { filter: brightness(.92); }
.wa-btn svg.ic { width: 18px; height: 18px; }
.foto-cell { display: flex; align-items: center; gap: 8px; }
.foto-cell .lect { font-size: 12px; color: var(--muted); }
.mini-thumb { width: 40px; height: 40px; padding: 0; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; cursor: pointer; background: var(--surface-2); flex: none; }
.mini-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.t-actions { display: flex; align-items: center; gap: 6px; }
.t-actions select { min-height: 34px; padding: 4px 8px; font-size: 13px; max-width: 170px; }
.t-pedidos .c-acciones { text-align: right; }

/* ── Vista lista (pensada para celular) ── */
.solo-movil { display: none; }
/* los filtros quedan plegados detrás del botón "Filtros" (PC y celular) */
.filtros-extra { display: none; flex-basis: 100%; flex-wrap: wrap; gap: 8px; }
.filtros-extra.abierto { display: flex; }
/* navegación de pedidos: pestañas principales y sub-pestañas, fijas arriba */
.nav-pedidos { position: sticky; top: var(--alto-topbar, 64px); z-index: 5; background: var(--bg); padding: 6px 0 8px; margin-bottom: 10px; }
#tabla-pedidos .nav-pedidos .e-chips { position: static; margin: 0; padding: 2px 0; }
.e-chip svg.ic { width: 16px; height: 16px; margin-left: -2px; }
.e-chip[aria-selected="true"] svg.ic { transform: rotate(180deg); }
.sub-tabs { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; margin-top: 8px; padding: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; }
.sub-tabs::-webkit-scrollbar { display: none; }
.sub-tab { flex: none; display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 6px 12px; border-radius: 9px;
  border: 0; background: transparent; color: var(--muted); font: 600 14px var(--font-body); cursor: pointer; }
.sub-tab b { min-width: 22px; padding: 1px 7px; border-radius: 999px; font-size: 12px; background: var(--surface-2); color: var(--text); text-align: center; }
.sub-tab:hover { color: var(--text); }
.sub-tab[aria-selected="true"] { background: color-mix(in srgb, var(--col) 18%, transparent); color: var(--text);
  box-shadow: inset 0 -3px 0 var(--col); }
.lista { max-width: 760px; }
.e-chips {
  display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 2px 2px 10px;
  position: sticky; top: var(--alto-topbar, 64px); z-index: 5; background: var(--bg);
}
.e-chips::-webkit-scrollbar { display: none; }
.e-chip {
  flex: none; display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 6px 14px;
  border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: 600 14px var(--font-body); cursor: pointer; white-space: nowrap;
}
.e-chip i { width: 10px; height: 10px; border-radius: 50%; background: var(--col); }
.e-chip b { min-width: 24px; padding: 1px 7px; border-radius: 999px; font-size: 12px; text-align: center;
  background: color-mix(in srgb, var(--col) 15%, transparent); color: var(--col); }
.e-chip[aria-selected="true"] { background: var(--col); border-color: var(--col); color: #fff; }
.e-chip[aria-selected="true"] i { background: #fff; }
.e-chip[aria-selected="true"] b { background: rgba(255,255,255,.25); color: #fff; }
.l-cab { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; padding: 4px 4px 10px; border-bottom: 3px solid var(--col); margin-bottom: 8px; }
.l-cab h3 { margin: 0; font: 600 17px var(--font-head); }
.l-cab span { font-size: 13px; color: var(--muted); font-weight: 600; text-align: right; }
.l-items { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.l-item { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--col); border-radius: var(--radius); overflow: hidden; }
.l-row {
  width: 100%; display: flex; align-items: center; gap: 10px; padding: 12px; min-height: 64px;
  background: transparent; border: 0; color: var(--text); font: inherit; text-align: left; cursor: pointer;
}
.l-row:hover { background: var(--surface-2); }
.l-row > svg.ic { color: var(--muted); transition: transform .2s; }
.l-item.abierto .l-row > svg.ic { transform: rotate(180deg); }
.l-num { flex: none; font: 700 12.5px var(--font-body); color: var(--muted); min-width: 46px; }
.l-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.l-nombre { font: 600 15px var(--font-head); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.l-pista { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.l-pista .tag { font-size: 11px; padding: 0 6px; }
.mono { font-family: ui-monospace, Consolas, monospace; font-weight: 600; color: var(--text); }
.falta { color: var(--danger); font-weight: 600; }
.l-monto { flex: none; display: flex; flex-direction: column; align-items: flex-end; font: 700 14px var(--font-body); font-variant-numeric: tabular-nums; }
.l-monto small { font-size: 11px; font-weight: 600; opacity: .8; }
.l-monto.debe { color: var(--danger); }
.l-monto.ok { color: var(--accent); }
.l-det { padding: 4px 12px 12px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 12px; }
.l-contacto { display: flex; gap: 8px; flex-wrap: wrap; padding-top: 10px; }
.l-contacto .btn { min-height: 40px; }
.l-datos { margin: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 14px; }
.l-item, .l-det, .lista { min-width: 0; }
.l-dato .btn { max-width: 100%; }
.l-dato { min-width: 0; }
.l-dato dt { font-size: 12px; color: var(--muted); font-weight: 600; }
.l-dato dd { margin: 2px 0 0; font-size: 14px; overflow-wrap: anywhere; }
.l-dato dd .sub { display: block; font-size: 12px; color: var(--muted); }
.l-dato .cell-input, .l-dato .cell-input.w-lg { width: 100%; min-height: 42px; font-size: 15px; }
.l-dato .foto-cell { flex-wrap: wrap; }
.l-plata { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; background: var(--surface-2); border-radius: 10px; padding: 10px; }
.l-plata div { display: flex; flex-direction: column; }
.l-plata span { font-size: 11.5px; color: var(--muted); font-weight: 600; }
.l-plata strong { font-size: 14px; font-variant-numeric: tabular-nums; }
.l-plata .debe { color: var(--danger); } .l-plata .ok { color: var(--accent); }
.l-acciones { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.l-acciones select { flex: 1 1 160px; min-height: 40px; font-size: 14px; }
.seccion-titulo { font: 600 18px var(--font-head); margin: 22px 0 12px; }
.tabs button svg.ic { display: none; }
/* botón del medio en la PC: resaltado */
.tabs button.tab-centro { display: inline-flex; align-items: center; gap: 6px; color: var(--on-primary); background: var(--primary);
  border-radius: 999px; padding: 6px 14px; margin: 6px 4px; border-bottom: 0; }
.tabs button.tab-centro svg.ic { display: block; width: 16px; height: 16px; }
.tabs button.tab-centro[aria-selected="true"] { box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 35%, transparent); color: var(--on-primary); }
/* chat de la bandeja */
.chat { max-width: 760px; margin: 0 auto; display: flex; flex-direction: column; gap: 10px; }
.chat-intro { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.chat-intro h2 { font: 600 17px var(--font-head); margin: 0 0 4px; }
.chat-intro p { margin: 4px 0; }
.chat-intro .ok { color: var(--accent); font-weight: 600; }
.chat-intro .warn { color: var(--warning); font-weight: 600; }
.chat-log { list-style: none; margin: 0; padding: 4px 0; display: flex; flex-direction: column; gap: 8px; max-height: 60vh; overflow-y: auto; }
.chat-log li { display: flex; }
.chat-log .msg-yo { justify-content: flex-end; }
.burbuja { max-width: 82%; padding: 9px 12px; border-radius: 14px; background: var(--surface); border: 1px solid var(--border); font-size: 14.5px; }
.burbuja p { margin: 2px 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-yo .burbuja { background: color-mix(in srgb, var(--primary) 16%, var(--surface)); border-color: transparent; border-bottom-right-radius: 4px; }
.msg-app .burbuja { border-bottom-left-radius: 4px; }
.msg-app.error .burbuja, .msg-app.sin_pedido .burbuja { border-color: color-mix(in srgb, var(--warning) 60%, var(--border)); }
.burbuja img { display: block; max-width: 240px; max-height: 240px; border-radius: 10px; margin: 4px 0; }
.burbuja audio { max-width: 240px; margin: 4px 0; }
.burbuja time { display: block; text-align: right; font-size: 11px; color: var(--muted); }
.burbuja .cambios { margin: 6px 0; padding-left: 18px; font-size: 13.5px; }
.chat-form { display: flex; gap: 6px; align-items: flex-end; background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 6px; }
.chat-form textarea { flex: 1; resize: none; border: 0; background: transparent; color: var(--text); font: 15px/1.4 var(--font-body);
  padding: 9px 6px; min-height: 40px; outline: none; }
.chat-form .icon-btn { width: 42px; height: 42px; flex: none; }
#chat-btn-audio.grabando { background: var(--danger); color: #fff; border-radius: 50%; }
.chat-vacio { justify-content: center; padding: 16px; }

/* sección comprobante en la ficha */
.comprobante .codigos { display: grid; grid-template-columns: 1.4fr 1fr 1fr; gap: 12px; }
.comprobante .codigos input { font-family: ui-monospace, Consolas, monospace; font-weight: 600; }

/* plantillas */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips code { background: var(--surface-2); border: 1px solid var(--border); padding: 2px 8px; border-radius: 6px; font-size: 12.5px; }
.plantillas { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 14px; }
.plantilla { border-top: 4px solid var(--col); margin-bottom: 0; }
.plantilla textarea { min-height: 180px; font-size: 14px; }
.plantilla .row-gap { margin-top: 8px; }

.row-gap { display: flex; gap: 8px; flex-wrap: wrap; }
.log { list-style: none; margin: 0; padding: 0; max-height: 60vh; overflow-y: auto; }
.log li { display: grid; grid-template-columns: 120px 1fr; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.log time { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }

/* ── Modal ── */
.modal {
  border: 0; padding: 0; border-radius: 16px; width: min(640px, calc(100vw - 24px));
  max-height: calc(100vh - 24px); background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg);
}
.modal-sm { width: min(480px, calc(100vw - 24px)); }
.modal::backdrop { background: rgba(15, 23, 42, .55); }
.modal > form { display: flex; flex-direction: column; max-height: calc(100vh - 24px); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.modal-body { padding: 16px; overflow-y: auto; }
.modal-foot { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.spacer { flex: 1; }
.form-error { color: var(--danger); font-size: 13.5px; margin: 0; min-height: 1em; }

.item-row { display: grid; grid-template-columns: 1fr 70px 100px 40px; gap: 8px; align-items: end; margin-bottom: 8px; }
.item-row .field { margin-bottom: 0; }
.item-row .icon-btn { height: 42px; }
.money-row { margin-top: 12px; }
.totales {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; background: var(--surface-2);
  border-radius: 10px; padding: 10px 12px; margin-bottom: 12px;
}
.totales div { display: flex; flex-direction: column; }
.totales span { font-size: 12px; color: var(--muted); }
.totales strong { font: 700 17px var(--font-head); font-variant-numeric: tabular-nums; }

form.tipo-lima .solo-provincia, form.tipo-provincia .solo-lima { display: none; }
form:not(.es-cancelado) .solo-cancelado { display: none; }

/* ── Filtros ── */
.filter-select { width: auto; min-width: 170px; min-height: 42px; }
.chip-toggle {
  border: 1px solid var(--border); background: var(--surface); color: var(--muted); border-radius: 999px;
  padding: 6px 14px; min-height: 42px; font: 600 13px var(--font-body); cursor: pointer; transition: background .2s, color .2s;
}
.chip-toggle[aria-pressed="true"] { background: color-mix(in srgb, var(--primary) 12%, var(--surface)); color: var(--primary); border-color: var(--primary); }
.toolbar > .small { align-self: center; }
.small { font-size: 12.5px; }
.tag.code { font-family: ui-monospace, Consolas, monospace; font-weight: 600; }

/* ── Archivos ── */
.files { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin-bottom: 10px; }
.file {
  border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--surface-2);
  display: flex; flex-direction: column; font-size: 12px;
}
.file .thumb { all: unset; cursor: pointer; display: block; aspect-ratio: 4 / 3; background: var(--border); position: relative; }
.file .thumb img, .file .thumb video { width: 100%; height: 100%; object-fit: cover; display: block; }
.file .thumb .ph { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-weight: 700; }
.file .thumb:focus-visible { outline: 2px solid var(--ring); outline-offset: -2px; }
.file .meta { padding: 6px 8px; display: flex; flex-direction: column; gap: 2px; }
.file .meta .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.file .lect { color: var(--muted); }
.file .lect.ok { color: var(--accent); }
.file .lect.error { color: var(--danger); }
.file .file-actions { display: flex; border-top: 1px solid var(--border); }
.file .file-actions button { flex: 1; border: 0; background: none; color: var(--muted); min-height: 34px; cursor: pointer; font: 600 12px var(--font-body); }
.file .file-actions button:hover { background: var(--surface); color: var(--text); }
.file .file-actions button + button { border-left: 1px solid var(--border); }
.upload {
  display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; cursor: pointer;
  border: 1.5px dashed var(--border); border-radius: 10px; color: var(--primary); font-weight: 600; margin-bottom: 8px;
}
.upload:hover, .upload.over { background: color-mix(in srgb, var(--primary) 6%, transparent); border-color: var(--primary); }
.upload input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.upload:focus-within { outline: 2px solid var(--ring); outline-offset: 2px; }
.modal-visor { width: min(960px, calc(100vw - 24px)); }
.visor { display: grid; place-items: center; gap: 12px; }
.visor img, .visor video { max-width: 100%; max-height: 70vh; border-radius: 8px; }
.visor iframe { width: 100%; height: 70vh; border: 0; }
.visor dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0; font-size: 14px; width: 100%; }
.visor dt { color: var(--muted); }
.visor dd { margin: 0; font-weight: 600; word-break: break-all; }

/* ── Toasts ── */
/* avisos: uno solo a la vez, arriba (debajo de la barra) para no tapar la tabla; el nuevo reemplaza al anterior */
.toasts { position: fixed; top: calc(var(--alto-topbar, 60px) + 8px); left: 50%; transform: translateX(-50%); display: flex;
  flex-direction: column; align-items: center; z-index: 100; width: max-content; max-width: min(560px, calc(100vw - 24px)); pointer-events: none; }
.toast { flex-wrap: wrap; }
.toast .btn.btn-wa { background: #1DA851; color: #fff; }
.toast-x { width: 30px; height: 30px; min-height: 30px; color: inherit; opacity: .7; }
.toast-x svg.ic { width: 16px; height: 16px; }
/* filas: Lima azul suave, provincia morado suave */
.t-pedidos tr.f-lima td { background: color-mix(in srgb, #2563EB 7%, var(--surface)); }
.t-pedidos tr.f-provincia td { background: color-mix(in srgb, #7C3AED 7%, var(--surface)); }
.t-pedidos tr.f-lima td.c-cliente { box-shadow: inset 3px 0 0 color-mix(in srgb, #2563EB 55%, transparent); }
.t-pedidos tr.f-provincia td.c-cliente { box-shadow: inset 3px 0 0 color-mix(in srgb, #7C3AED 55%, transparent); }
.toast {
  background: var(--text); color: var(--bg); border-radius: 12px; padding: 10px 12px 10px 14px; pointer-events: auto;
  display: flex; align-items: center; gap: 10px; box-shadow: var(--shadow-lg); font-size: 14px;
  animation: pop .22s cubic-bezier(.2, .9, .3, 1.3);
}
.toast.chico { padding: 7px 12px 7px 8px; border-radius: 999px; font-size: 13px; font-weight: 600; }
.toast-ok { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--accent); color: #fff; flex: none; }
.toast-ok svg.ic { width: 14px; height: 14px; stroke-width: 3; }
.toast .btn { min-height: 34px; padding: 4px 12px; background: var(--bg); color: var(--text); border: 0; font-weight: 700; }
.toast p { margin: 0; flex: 1; }
@keyframes in { from { opacity: 0; transform: translateY(8px); } }
@keyframes pop { from { opacity: 0; transform: translateX(10px) scale(.92); } }

/* seleccionar pedidos */
.sel-ped, .sel-todos input { width: 18px; height: 18px; accent-color: var(--primary); cursor: pointer; vertical-align: middle; margin: 0 8px 0 0; }
.t-pedidos td.c-cliente { white-space: nowrap; }
.t-pedidos td.c-cliente .sel-ped { float: left; margin-top: 2px; }
.t-pedidos td.c-cliente .sub { display: block; padding-left: 26px; }
.t-pedidos td.c-cliente .link-cliente { white-space: normal; }
.t-pedidos tr.sel td { background: color-mix(in srgb, var(--primary) 9%, var(--surface)); }
.sel-todos { display: inline-flex; vertical-align: middle; }
.sel-barra { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 8px 12px; margin: 0 0 8px;
  border: 1px solid color-mix(in srgb, var(--primary) 45%, var(--border)); border-radius: var(--radius);
  background: color-mix(in srgb, var(--primary) 10%, var(--surface)); animation: in .15s ease-out; }
.sel-barra .spacer { flex: 1; }
.btn-danger { background: var(--danger); color: #fff; border-color: transparent; }
.btn-cols { margin-left: auto; }
.t-head { flex-wrap: wrap; }

/* ventana de columnas */
.cols-lista { list-style: none; margin: 8px 0 12px; padding: 0; display: grid; gap: 4px; max-height: 50vh; overflow-y: auto; }
.cols-fila { display: flex; align-items: center; gap: 2px; padding: 4px 6px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
.cols-fila.oculta { opacity: .55; }
.cols-check { flex: 1; display: flex; align-items: center; gap: 10px; min-height: 40px; cursor: pointer; font-weight: 600; font-size: 14px; }
.cols-check input { width: 18px; height: 18px; accent-color: var(--primary); }
.cols-fila .icon-btn:disabled { opacity: .3; cursor: default; }
.icon-btn-hueco { display: inline-block; width: 40px; }
.cols-nueva { display: flex; gap: 8px; }
.cols-nueva input { flex: 1; min-width: 0; }

/* barra fija abajo para mover la tabla */
.t-etapa .table-wrap { scrollbar-width: none; }
.t-etapa .table-wrap::-webkit-scrollbar { display: none; }
.barra-h { position: fixed; bottom: 6px; z-index: 30; height: 18px; border-radius: 9px; cursor: pointer; touch-action: none;
  background: color-mix(in srgb, var(--surface-2) 85%, transparent); border: 1px solid var(--border);
  box-shadow: var(--shadow-lg); backdrop-filter: blur(6px); }
.barra-h-thumb { position: absolute; top: 2px; bottom: 2px; left: 0; border-radius: 7px; background: var(--muted); opacity: .75; cursor: grab; }
.barra-h:hover .barra-h-thumb, .barra-h.activa .barra-h-thumb { background: var(--primary); opacity: 1; }
.barra-h.activa .barra-h-thumb { cursor: grabbing; }
main { padding-bottom: 40px; }

.solo-movil-i { display: none; }
@media (max-width: 760px) {
  .t-pedidos .c-pedido { display: none; }
  .solo-movil-i { display: inline; }
  .t-pedidos .c-cliente { min-width: 0; width: 118px; max-width: 118px; white-space: normal; box-shadow: 1px 0 0 var(--border); }
  .t-pedidos .link-cliente { font-size: 13.5px; }
  main { padding: 12px; }
  .grid-gastos, .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .grid-gastos input, .grid-gastos select { min-width: 0; max-width: 100%; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .kpi { padding: 12px; }
  .kpi strong { font-size: 20px; }
  .kpi small { font-size: 11.5px; }
  .field-row { grid-template-columns: 1fr; gap: 0; }
  .comprobante .codigos { grid-template-columns: 1fr 1fr; gap: 0 12px; }
  .comprobante .codigos .field:first-child { grid-column: 1 / -1; }
  .t-head .t-sub { font-size: 12px; }
  .col { flex-basis: 85vw; max-height: none; }
  .board { min-height: 0; }
  .bar-row { grid-template-columns: 100px 1fr 80px; }
  .item-row { grid-template-columns: 1fr 70px 96px 40px; }
  .item-row .field:first-child { grid-column: 1 / -1; }
  /* las 5 pestañas principales más compactas para que entren en el celular */
  #tabla-pedidos .e-chips { gap: 5px; }
  #tabla-pedidos .e-chip { padding: 6px 9px; font-size: 13px; gap: 4px; min-height: 40px; }
  #tabla-pedidos .e-chip b { min-width: 0; padding: 0 5px; font-size: 11px; }
  #tabla-pedidos .e-chip svg.ic { display: none; }
  .sub-tab { font-size: 13px; padding: 6px 10px; } /* en el celular el nombre del producto ocupa toda la fila */
  .log li { grid-template-columns: 1fr; gap: 2px; }
  .modal { width: 100vw; max-width: 100vw; max-height: 100vh; height: 100vh; border-radius: 0; }
  .modal > form { max-height: 100vh; height: 100%; }
  .modal-body { flex: 1; }
  #btn-nuevo .txt { display: none; }

  /* barra de secciones abajo, como app */
  body { padding-bottom: calc(68px + env(safe-area-inset-bottom)); }
  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--border); border-bottom: 0; justify-content: space-around; gap: 0;
  }
  .tabs button {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 2px;
    min-height: 56px; font-size: 11.5px; border-bottom: 0; border-top: 2px solid transparent;
  }
  .tabs button svg.ic { display: block; width: 22px; height: 22px; }
  .tabs button[aria-selected="true"] { border-top-color: var(--primary); }
  /* botón del medio: grande y redondo */
  /* el círculo queda centrado y un poco levantado; el texto alineado con los demás */
  .tabs button.tab-centro { position: relative; justify-content: flex-end; border-top-color: transparent; color: var(--primary);
    font-weight: 700; background: none; border-radius: 0; padding: 6px 2px; margin: 0; box-shadow: none !important; }
  .tabs button.tab-centro[aria-selected="true"] { color: var(--primary); }
  .tabs button.tab-centro svg.ic {
    position: absolute; left: 50%; top: -22px; transform: translateX(-50%);
    width: 56px; height: 56px; padding: 15px; border-radius: 50%;
    background: var(--primary); color: var(--on-primary); box-shadow: 0 6px 16px color-mix(in srgb, var(--primary) 45%, transparent);
    border: 4px solid var(--surface); transition: transform .15s ease;
  }
  .tabs button.tab-centro:active svg.ic { transform: translateX(-50%) scale(.94); }
  .chat-log { max-height: none; }
  .chat-form { position: sticky; bottom: calc(68px + env(safe-area-inset-bottom)); }

  /* filtros plegables */
  .solo-movil { display: inline-flex; align-items: center; }
  .toolbar { gap: 8px; }
  .toolbar .modos { flex: 1; }
  .toolbar .modos button { flex: 1; }
  .search { flex-basis: 100%; order: 3; }
  .filtros-extra { display: none; order: 4; flex-basis: 100%; flex-wrap: wrap; gap: 8px; }
  .filtros-extra.abierto { display: flex; }
  .filtros-extra .filter-select { flex: 1; }
  .toolbar > #f-resultado { order: 5; }
  .l-num { min-width: 40px; font-size: 12px; }
  .barra-h { bottom: calc(72px + env(safe-area-inset-bottom)); height: 20px; }
  .btn-cols { padding: 4px 8px; }
  main { padding-bottom: 36px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
