/* ====== Base (mobile-first) ====== */
:root {
  --primario: #1d4ed8; --primario-osc: #1e40af; --fondo: #f4f5f7; --tarjeta: #fff; --texto: #1f2937;
  --muted: #6b7280; --borde: #e5e7eb; --peligro: #dc2626; --ok: #16a34a; --radio: 12px;
  --gris: #6b7280; --azul: #2563eb; --ambar: #d97706; --morado: #7c3aed; --verde: #16a34a; --rojo: #dc2626;
  --nav-alto: 64px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; background: var(--fondo); color: var(--texto); font-size: 16px; line-height: 1.45; }
body.con-nav { padding-bottom: calc(var(--nav-alto) + env(safe-area-inset-bottom) + 8px); }
a { color: var(--primario); text-decoration: none; }
h1 { font-size: 1.4rem; margin: 0 0 4px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
h2 { font-size: 1.1rem; margin: 20px 0 10px; }
.tarjeta h2:first-child, .tarjeta .encabezado h2 { margin-top: 0; }
code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .85em; background: #f3f4f6; padding: 1px 5px; border-radius: 4px; }
.muted { color: var(--muted); }
small.muted, .muted small { display: block; }
.centro { text-align: center; }
.pre { white-space: pre-wrap; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; }
.mayus { text-transform: uppercase; }
[hidden] { display: none !important; }

/* ====== Barra superior ====== */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px; padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top)); background: var(--primario); color: #fff; }
.marca { display: flex; align-items: center; gap: 8px; color: #fff; font-weight: 700; flex: 1; min-width: 0; }
.marca span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.marca img { background: #fff; border-radius: 8px; }
.nav-escritorio { display: none; }
.menu-usuario { position: relative; }
.menu-usuario summary { list-style: none; cursor: pointer; }
.menu-usuario summary::-webkit-details-marker { display: none; }
.avatar { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; background: rgba(255,255,255,.2); color: #fff; font-weight: 700; }
.menu-panel { position: absolute; right: 0; top: 46px; width: 250px; background: #fff; color: var(--texto); border-radius: var(--radio); box-shadow: 0 10px 30px rgba(0,0,0,.18); overflow: hidden; }
.menu-panel a, .menu-panel button { display: block; width: 100%; text-align: left; padding: 12px 16px; border: 0; background: none; font: inherit; color: var(--texto); border-top: 1px solid var(--borde); cursor: pointer; }
.menu-panel a:hover, .menu-panel button:hover { background: #f9fafb; }
.menu-info { padding: 12px 16px; }
.menu-info small { display: block; color: var(--muted); word-break: break-all; }

/* ====== Navegación inferior (móvil) ====== */
.nav-movil { position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; height: calc(var(--nav-alto) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); background: #fff; border-top: 1px solid var(--borde); display: grid; grid-template-columns: repeat(5, 1fr); align-items: center; }
.nav-movil a { display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--muted); font-size: 11px; padding: 6px 0; }
.nav-movil a.activo { color: var(--primario); font-weight: 600; }
.nav-movil svg { width: 24px; height: 24px; fill: currentColor; }
.nav-movil .nav-nuevo { justify-self: center; width: 54px; height: 54px; border-radius: 50%; background: var(--primario); color: #fff; justify-content: center; margin-top: -22px; box-shadow: 0 6px 16px rgba(29,78,216,.4); }
.nav-movil .nav-nuevo svg { width: 30px; height: 30px; }

/* ====== Contenido ====== */
.contenido { max-width: 1100px; margin: 0 auto; padding: 16px; }
.encabezado { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.encabezado h2 { margin: 0; }
.encabezado p { margin: 0; }
.volver { display: inline-block; font-size: .9rem; margin-bottom: 4px; }
.botones { display: flex; gap: 8px; flex-wrap: wrap; }
.tarjeta { background: var(--tarjeta); border-radius: var(--radio); padding: 16px; margin-bottom: 14px; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.vacio { text-align: center; padding: 28px 16px; color: var(--muted); }
.solo-escritorio { display: none !important; }

/* ====== Botones ====== */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 10px 18px; border-radius: 10px; border: 1px solid transparent; background: var(--primario); color: #fff; font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; -webkit-tap-highlight-color: transparent; }
.btn:active { transform: translateY(1px); }
.btn:hover { background: var(--primario-osc); }
.btn-sec { background: #fff; color: var(--texto); border-color: var(--borde); }
.btn-sec:hover { background: #f9fafb; }
.btn-peligro { background: #fff; color: var(--peligro); border-color: #fecaca; }
.btn-peligro:hover { background: #fef2f2; }
.btn-peq { min-height: 34px; padding: 6px 12px; font-size: .9rem; }
.btn-bloque { width: 100%; }

/* ====== Formularios ====== */
.form label { display: block; font-weight: 600; font-size: .92rem; margin-bottom: 12px; }
.form label small { font-weight: 400; }
input, select, textarea { width: 100%; font: inherit; font-size: 16px; /* evita zoom en iOS */ padding: 11px 12px; border: 1px solid #d1d5db; border-radius: 10px; background: #fff; color: var(--texto); margin-top: 4px; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(29,78,216,.35); border-color: var(--primario); }
input[type=checkbox], input[type=radio] { width: 20px; height: 20px; margin: 0; accent-color: var(--primario); flex: none; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.grid-2 { display: grid; gap: 0 12px; }
.acciones { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 8px; }
.acciones .btn { flex: 1 1 auto; }

.filtros { display: grid; gap: 8px; margin-bottom: 8px; }
.filtros input, .filtros select { margin-top: 0; }
.filtros label.fecha { display: flex; flex-direction: column; font-size: .8rem; color: var(--muted); }
.filtros label.fecha input { margin-top: 2px; }

/* ====== Alertas y badges ====== */
.alerta { padding: 12px 14px; border-radius: 10px; margin-bottom: 14px; }
.alerta ul { margin: 0; padding-left: 18px; }
.alerta p { margin: 0 0 6px; }
.alerta-ok { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.alerta-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: .78rem; font-weight: 600; white-space: nowrap; vertical-align: middle; }
.badge-gris { background: #f3f4f6; color: #374151; }
.badge-azul { background: #dbeafe; color: #1e40af; }
.badge-ambar { background: #fef3c7; color: #92400e; }
.badge-morado { background: #ede9fe; color: #5b21b6; }
.badge-verde { background: #dcfce7; color: #166534; }
.badge-rojo { background: #fee2e2; color: #991b1b; }
.borde-gris { border-left: 4px solid var(--gris) !important; }
.borde-azul { border-left: 4px solid var(--azul) !important; }
.borde-ambar { border-left: 4px solid var(--ambar) !important; }
.borde-morado { border-left: 4px solid var(--morado) !important; }
.borde-verde { border-left: 4px solid var(--verde) !important; }
.borde-rojo { border-left: 4px solid var(--rojo) !important; }

/* ====== Dashboard ====== */
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 8px; }
.kpi { background: #fff; border-radius: var(--radio); padding: 14px; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.kpi small { color: var(--muted); display: block; }
.kpi strong { font-size: 1.6rem; display: block; }
.kpi span { font-size: .9rem; color: var(--muted); }
.estados-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.estado-caja { background: #fff; border-radius: 10px; padding: 10px 12px; color: var(--texto); box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.estado-caja strong { display: block; font-size: 1.3rem; }
.estado-caja span { font-size: .8rem; color: var(--muted); }

/* ====== Listas tipo tarjeta ====== */
.lista { display: grid; gap: 8px; }
.fila-tarjeta { display: flex; justify-content: space-between; align-items: center; gap: 10px; background: #fff; padding: 12px 14px; border-radius: 10px; color: var(--texto); box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.fila-tarjeta > div { display: flex; flex-direction: column; min-width: 0; }
.fila-tarjeta .der { align-items: flex-end; gap: 4px; flex: none; }

/* ====== Tablas: tarjetas en móvil ====== */
.tabla { width: 100%; border-collapse: collapse; }
.tabla thead { display: none; }
.tabla tr { display: block; background: #fff; border-radius: 10px; padding: 10px 14px; margin-bottom: 8px; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.tabla tr[data-href] { cursor: pointer; }
.tabla td { display: flex; justify-content: space-between; gap: 12px; padding: 4px 0; text-align: right; }
.tabla td::before { content: attr(data-label); color: var(--muted); font-size: .85rem; text-align: left; flex: none; }
.tabla td:first-child { text-align: left; display: block; font-size: 1.02rem; padding-bottom: 6px; }
.tabla td:first-child::before { display: none; }
.tabla td.acciones-fila { justify-content: flex-end; }
.tabla td.acciones-fila::before { display: none; }
.tabla tr.inactivo { opacity: .6; }
.tabla td small.muted { display: inline; }

.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 8px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; padding: 7px 14px; border-radius: 999px; background: #fff; border: 1px solid var(--borde); color: var(--texto); font-size: .9rem; }
.chip.activo { background: var(--primario); color: #fff; border-color: var(--primario); }

.paginacion { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin: 12px 0; }

/* ====== Detalle ====== */
.datos { display: grid; gap: 10px; margin: 0; }
.datos dt { font-size: .8rem; color: var(--muted); }
.datos dd { margin: 0; word-break: break-word; }
.zona-peligro { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; margin-top: 20px; }
.grid-detalle { display: grid; gap: 0 14px; }
.items .item { display: flex; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--borde); }
.items .item > div { min-width: 0; }
.totales-detalle div { display: flex; justify-content: space-between; padding: 4px 0; }
.totales-detalle .total { font-size: 1.15rem; font-weight: 700; border-top: 2px solid var(--texto); margin-top: 6px; padding-top: 8px; }

.progreso { display: flex; justify-content: space-between; margin: 8px 0 16px; position: relative; }
.progreso::before { content: ""; position: absolute; top: 15px; left: 10%; right: 10%; height: 3px; background: var(--borde); }
.progreso .alerta { width: 100%; position: relative; }
.paso { position: relative; display: flex; flex-direction: column; align-items: center; flex: 1; text-align: center; gap: 4px; }
.paso .punto { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: #fff; border: 3px solid var(--borde); font-weight: 700; font-size: .85rem; color: var(--muted); }
.paso small { font-size: .7rem; color: var(--muted); line-height: 1.2; }
.paso.hecho .punto { background: var(--ok); border-color: var(--ok); color: #fff; }
.paso.actual .punto { border-color: var(--primario); color: var(--primario); box-shadow: 0 0 0 4px rgba(29,78,216,.15); }
.paso.actual small { color: var(--texto); font-weight: 600; }

.opciones-estado { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.form label.opcion { display: flex; align-items: center; gap: 8px; padding: 12px; border: 1px solid var(--borde); border-radius: 10px; margin: 0; cursor: pointer; }
.form label.opcion:has(input:checked) { background: #eff6ff; border-color: var(--primario); }

.historial { list-style: none; padding: 0; margin: 0; }
.historial li { padding: 10px 0 10px 18px; border-left: 2px solid var(--borde); position: relative; }
.historial li::before { content: ""; position: absolute; left: -6px; top: 16px; width: 10px; height: 10px; border-radius: 50%; background: var(--primario); }
.historial p { margin: 4px 0 0; }
.correos { list-style: none; padding: 0; margin: 0; }
.correos li { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-bottom: 1px solid var(--borde); font-size: .92rem; }
.correos small { word-break: break-all; }

/* ====== Formulario de pedido ====== */
.buscador { position: relative; }
.buscador input { margin-top: 0; }
.resultados { list-style: none; margin: 4px 0 0; padding: 0; background: #fff; border: 1px solid var(--borde); border-radius: 10px; max-height: 320px; overflow-y: auto; box-shadow: 0 8px 20px rgba(0,0,0,.08); position: relative; z-index: 5; }
.resultados li { padding: 12px 14px; border-bottom: 1px solid var(--borde); cursor: pointer; display: flex; justify-content: space-between; gap: 8px; }
.resultados li:last-child { border-bottom: 0; }
.resultados li:hover, .resultados li.foco { background: #eff6ff; }
.resultados li > div { min-width: 0; }
.resultados li.vacio { cursor: default; color: var(--muted); }
.enlace-peq { display: inline-block; margin-top: 10px; font-size: .92rem; }
.elegido { display: flex; justify-content: space-between; align-items: center; gap: 10px; background: #eff6ff; border: 1px solid #bfdbfe; border-radius: 10px; padding: 12px; }
.elegido > div { min-width: 0; }
.lineas { display: grid; gap: 10px; margin-top: 12px; }
.linea { position: relative; border: 1px solid var(--borde); border-radius: 10px; padding: 12px; }
.linea-info { padding-right: 34px; }
.quitar { position: absolute; top: 6px; right: 6px; width: 34px; height: 34px; border: 0; background: none; font-size: 24px; line-height: 1; color: var(--muted); cursor: pointer; border-radius: 8px; }
.quitar:hover { background: #fef2f2; color: var(--peligro); }
.linea-campos { display: grid; grid-template-columns: 1.4fr 1fr; gap: 8px; margin-top: 8px; align-items: end; }
.form .linea-campos label { margin: 0; font-size: .8rem; color: var(--muted); }
.linea-total { grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: baseline; padding-top: 4px; }
.linea-total small { color: var(--muted); }
.stepper { display: flex; align-items: stretch; margin-top: 4px; }
.stepper button { width: 44px; flex: none; border: 1px solid #d1d5db; background: #f9fafb; font-size: 20px; cursor: pointer; color: var(--texto); }
.stepper button:first-child { border-radius: 10px 0 0 10px; }
.stepper button:last-child { border-radius: 0 10px 10px 0; }
.stepper input { margin: 0; border-radius: 0; text-align: center; border-left: 0; border-right: 0; min-width: 0; -moz-appearance: textfield; }
.stepper input::-webkit-outer-spin-button, .stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.resumen-fijo { position: sticky; bottom: calc(var(--nav-alto) + env(safe-area-inset-bottom) + 6px); background: #fff; border-radius: var(--radio); padding: 12px 14px; box-shadow: 0 -2px 16px rgba(0,0,0,.12); display: flex; align-items: center; justify-content: space-between; gap: 12px; z-index: 10; }
.totales { display: flex; flex-direction: column; font-size: .85rem; color: var(--muted); }
.totales b { color: var(--texto); }
.totales .t-total { font-size: 1.05rem; color: var(--texto); }
.totales .t-total b { font-size: 1.25rem; }

/* ====== Login ====== */
.login { min-height: 90vh; display: grid; place-items: center; }
.login-caja { width: 100%; max-width: 380px; background: #fff; padding: 28px 22px; border-radius: 16px; box-shadow: 0 10px 30px rgba(0,0,0,.08); text-align: center; }
.login-caja .form { text-align: left; margin-top: 16px; }
.login-caja h1 { justify-content: center; }
.codigo { background: #f3f4f6; padding: 10px; border-radius: 8px; overflow-x: auto; font-size: 13px; }

/* ====== Tablet / escritorio ====== */
@media (min-width: 640px) {
  .grid-2 { grid-template-columns: 1fr 1fr; }
  .kpis { grid-template-columns: repeat(4, 1fr); }
  .estados-grid { grid-template-columns: repeat(6, 1fr); }
  .filtros { grid-template-columns: 1fr auto auto auto auto; align-items: end; }
  .datos { grid-template-columns: 1fr 1fr; }
  .datos .ancho { grid-column: 1 / -1; }
  .linea-campos { grid-template-columns: 170px 140px 1fr; }
  .linea-total { grid-column: auto; flex-direction: column; align-items: flex-end; }
  .opciones-estado { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
  .acciones .btn { flex: 0 0 auto; }
  .paso small { font-size: .8rem; }
}
@media (min-width: 900px) {
  body.con-nav { padding-bottom: 24px; }
  .nav-movil { display: none; }
  .solo-escritorio { display: inline-flex !important; }
  .nav-escritorio { display: flex; gap: 4px; }
  .nav-escritorio a { color: rgba(255,255,255,.85); padding: 8px 12px; border-radius: 8px; }
  .nav-escritorio a:hover { background: rgba(255,255,255,.12); color: #fff; }
  .nav-escritorio a.activo { background: rgba(255,255,255,.2); color: #fff; font-weight: 600; }
  .contenido { padding: 24px; }
  h1 { font-size: 1.6rem; }
  .grid-detalle { grid-template-columns: 1fr 1.3fr; }
  .resumen-fijo { bottom: 12px; }
  /* Tablas reales en escritorio */
  .tabla { background: #fff; border-radius: var(--radio); overflow: hidden; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
  .tabla thead { display: table-header-group; }
  .tabla th { text-align: left; font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); padding: 12px 14px; background: #f9fafb; border-bottom: 1px solid var(--borde); }
  .tabla tr { display: table-row; padding: 0; margin: 0; box-shadow: none; border-radius: 0; }
  .tabla tbody tr:hover { background: #f9fafb; }
  .tabla td, .tabla td:first-child { display: table-cell; text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--borde); font-size: 1rem; }
  .tabla td::before { display: none; }
  .tabla .num { text-align: right; }
  .tabla td.acciones-fila { text-align: right; }
}
