:root {
  --tinta: #0d0d0e;
  --hueso: #eee9e1;
  --fondo: #f6f3ee;
  --papel: #ffffff;
  --oro: #c9a86a;
  --oro-oscuro: #7c6231;
  --texto: #1c1b19;
  --suave: #6a655c;
  --linea: #e3ddd2;
  --rojo: #b3261e;
  --rojo-fondo: #fbe9e7;
  --ambar: #8a5a00;
  --ambar-fondo: #fdf1d8;
  --verde: #1f6b45;
  --verde-fondo: #e3f2ea;
  --azul: #2b5a9b;
  --azul-fondo: #e6eef9;
  --radio: 10px;
  --sombra: 0 1px 2px rgba(0,0,0,.05);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  font-size: 15px; line-height: 1.45; color: var(--texto); background: var(--fondo);
  display: grid; grid-template-columns: 216px 1fr;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--oro-oscuro); outline-offset: 2px; }

/* ---------- navegacion ---------- */
.lateral {
  background: var(--tinta); color: var(--hueso); padding: 22px 14px 16px;
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 22px;
}
.marca { padding: 0 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.marca b { font-weight: 800; letter-spacing: .2em; font-size: 15px; }
.marca i { font-family: Georgia, 'Times New Roman', serif; color: var(--oro); font-size: 19px; }
.lateral nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.lateral nav a {
  padding: 10px 12px; border-radius: 8px; text-decoration: none; color: rgba(238,233,225,.76); font-weight: 600;
}
.lateral nav a:hover { color: #fff; background: rgba(255,255,255,.07); }
.lateral nav a.activo { background: var(--oro); color: var(--tinta); }
.guardado { font-size: 12.5px; color: rgba(238,233,225,.6); padding: 0 12px; min-height: 18px; }
.guardado.error { color: #ffb4ab; font-weight: 600; }

/* ---------- estructura ---------- */
.vista { padding: 26px 30px 60px; min-width: 0; max-width: 1240px; width: 100%; }
.cargando { color: var(--suave); }
.cabecera { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.cabecera h1 { font-size: 25px; font-weight: 700; letter-spacing: -.01em; }
.cabecera p { color: var(--suave); font-size: 14px; }
.acciones { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.tarjeta { background: var(--papel); border: 1px solid var(--linea); border-radius: var(--radio); box-shadow: var(--sombra); }
.relleno { padding: 16px 18px; }
.seccion { margin-bottom: 18px; }
.tarjeta h2 { font-size: 15.5px; font-weight: 700; }
.tit { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 10px; }
.tit a { font-size: 13px; color: var(--oro-oscuro); font-weight: 600; }
.dos { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.suave { color: var(--suave); }
.chico-txt { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }
.der { text-align: right; }
.vacio { text-align: center; padding: 34px 20px; color: var(--suave); }
.vacio b { display: block; color: var(--texto); font-size: 16px; margin-bottom: 4px; }
.vacio .btn { margin-top: 12px; }

/* ---------- botones y campos ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--linea); background: var(--papel);
  font-weight: 600; font-size: 14px; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: #bdb5a6; }
.btn.prim { background: var(--tinta); border-color: var(--tinta); color: #fff; }
.btn.prim:hover { background: #2b2a28; }
.btn.peligro { color: var(--rojo); border-color: #eec7c3; }
.btn.peligro:hover { background: var(--rojo-fondo); }
.btn.chico { padding: 4px 10px; font-size: 13px; }
.btn.fantasma { border-color: transparent; background: transparent; }
.btn.fantasma:hover { background: rgba(0,0,0,.05); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.x { border: 0; background: none; cursor: pointer; font-size: 20px; line-height: 1; color: var(--suave); padding: 2px 8px; border-radius: 6px; }
.x:hover { background: rgba(0,0,0,.06); color: var(--texto); }

.campo { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.campo > span { font-size: 13px; font-weight: 600; color: var(--suave); }
input[type=text], input[type=tel], input[type=email], input[type=password], input[type=search], input[type=number], input[type=date], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid #d6cfc2; border-radius: 8px; background: #fff;
}
textarea { resize: vertical; min-height: 64px; }
input[type=number] { font-variant-numeric: tabular-nums; }
input.chico { padding: 5px 6px; }
.fila { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.filtros { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.filtros input[type=search] { max-width: 280px; }
.filtros select { width: auto; }
.pildoras { display: flex; flex-wrap: wrap; gap: 6px; }
.pildora {
  border: 1px solid var(--linea); background: var(--papel); padding: 5px 12px; border-radius: 99px;
  font-size: 13.5px; font-weight: 600; cursor: pointer;
}
.pildora.activa { background: var(--tinta); color: #fff; border-color: var(--tinta); }
.pildora small { opacity: .7; font-weight: 500; margin-left: 3px; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; cursor: pointer; }

/* ---------- indicadores ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi { padding: 14px 18px; }
.kpi .val { font-size: 27px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; }
.kpi .lab { font-size: 13.5px; color: var(--suave); font-weight: 600; }
.kpi .sub { font-size: 12.5px; color: var(--suave); }
.lista { list-style: none; }
.lista li { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-top: 1px solid var(--linea); align-items: center; }
.lista li:first-child { border-top: 0; }
.lista a { text-decoration: none; font-weight: 600; }
.lista a:hover { text-decoration: underline; }
.barra-fila { display: grid; grid-template-columns: minmax(0, 1fr) 90px 34px; gap: 10px; align-items: center; padding: 6px 0; }
.barra { height: 10px; background: var(--hueso); border-radius: 4px; overflow: hidden; }
.barra i { display: block; height: 100%; background: var(--oro); border-radius: 0 4px 4px 0; }
.trunca { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }

.etq { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12.5px; font-weight: 700; white-space: nowrap; }
.e-pendiente { background: var(--ambar-fondo); color: var(--ambar); }
.e-preparando { background: var(--azul-fondo); color: var(--azul); }
.e-enviado { background: #ece6f7; color: #5a3f96; }
.e-entregado, .e-pagado { background: var(--verde-fondo); color: var(--verde); }
.e-cancelado { background: #ececea; color: #5f5d58; }
.e-debe { background: var(--rojo-fondo); color: var(--rojo); }
.e-parcial { background: var(--ambar-fondo); color: var(--ambar); }

/* ---------- tablas ---------- */
.tabla-caja { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th { text-align: left; font-size: 12.5px; color: var(--suave); font-weight: 700; padding: 9px 12px; white-space: nowrap; border-bottom: 1px solid var(--linea); }
td { padding: 9px 12px; border-top: 1px solid var(--linea); vertical-align: middle; }
tbody tr:first-child td { border-top: 0; }
tr.clic { cursor: pointer; }
tr.clic:hover td { background: #fbf9f5; }
td.der, th.der { text-align: right; }
.muestra { display: inline-block; width: 15px; height: 15px; border-radius: 50%; border: 1px solid rgba(0,0,0,.2); vertical-align: -2px; margin-right: 7px; flex: none; }

/* ---------- stock ---------- */
.modelo-cab { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--linea); flex-wrap: wrap; }
.modelo-cab img { width: 44px; height: 54px; object-fit: contain; background: var(--hueso); border-radius: 6px; }
.modelo-cab h2 { font-size: 16px; }
.modelo-cab .der-auto { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.matriz th.centro, .matriz td.centro { text-align: center; }
.matriz td { padding: 5px 8px; }
.matriz td:first-child { padding-left: 16px; white-space: nowrap; font-weight: 600; font-size: 14px; }
.matriz th:first-child { padding-left: 16px; }
.celda {
  min-width: 54px; width: 100%; padding: 5px 6px; border-radius: 6px; border: 1px solid transparent; background: #f7f4ee;
  font-weight: 700; font-variant-numeric: tabular-nums; cursor: pointer;
}
.celda:hover { border-color: var(--oro-oscuro); }
.celda.bajo { background: var(--ambar-fondo); color: var(--ambar); }
.celda.agotado { background: var(--rojo-fondo); color: var(--rojo); }
.leyenda { display: flex; gap: 14px; font-size: 13px; color: var(--suave); flex-wrap: wrap; }
.leyenda span::before { content: ''; display: inline-block; width: 11px; height: 11px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; background: var(--bg); }
.mat-input { width: 68px; text-align: center; margin: 0 auto; display: block; }
.disp { display: block; font-size: 11.5px; color: var(--suave); text-align: center; }
.disp.cero { color: var(--rojo); font-weight: 600; }

/* ---------- modelos ---------- */
.rejilla { display: grid; grid-template-columns: repeat(auto-fill, minmax(236px, 1fr)); gap: 16px; }
.mod { overflow: hidden; display: flex; flex-direction: column; }
.mod.arch { opacity: .65; }
.mod-foto { height: 210px; background: var(--hueso); display: flex; align-items: center; justify-content: center; color: var(--suave); font-size: 13px; }
.mod-foto img { max-width: 100%; max-height: 100%; object-fit: contain; }
.mod-cuerpo { padding: 12px 14px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.mod-cuerpo h3 { font-size: 16px; }
.muestras { display: flex; flex-wrap: wrap; gap: 4px; }
.muestras .muestra { margin: 0; }
.mod-pie { display: flex; gap: 6px; margin-top: auto; padding-top: 8px; flex-wrap: wrap; }

/* ---------- pedidos ---------- */
.pedido-grid { display: grid; grid-template-columns: minmax(0, 1fr) 390px; gap: 16px; align-items: start; }
.pegajoso { position: sticky; top: 16px; }
.grupo { padding: 10px 0; border-top: 1px solid var(--linea); }
.grupo:first-child { border-top: 0; padding-top: 0; }
.grupo-cab { display: flex; justify-content: space-between; gap: 8px; font-weight: 700; font-size: 14.5px; }
.grupo-nota { font-size: 12.5px; color: var(--suave); margin-bottom: 6px; }
.grupo-nota b { color: var(--verde); font-weight: 600; }
.it { display: grid; grid-template-columns: minmax(0, 1fr) 54px 68px 26px; gap: 6px; align-items: center; padding: 3px 0; font-size: 14px; }
.it .manual { border-color: var(--oro-oscuro); background: #fbf6ea; }
.totales { display: grid; gap: 6px; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--linea); }
.totales > div { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.totales input { width: 96px; text-align: right; }
.total { font-size: 21px; font-weight: 700; font-variant-numeric: tabular-nums; }
.ficha dt { font-size: 12.5px; color: var(--suave); font-weight: 600; margin-top: 8px; }
.ficha dd { font-size: 15px; }
.pago { display: flex; justify-content: space-between; gap: 10px; padding: 6px 0; border-top: 1px solid var(--linea); font-size: 14px; align-items: center; }
.pago:first-child { border-top: 0; }

/* ---------- modales ---------- */
dialog { border: 0; border-radius: 14px; padding: 0; margin: auto; width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 32px); box-shadow: 0 16px 50px rgba(0,0,0,.28); color: var(--texto); }
dialog.ancho { width: min(860px, calc(100vw - 24px)); }
dialog.chico { width: min(420px, calc(100vw - 24px)); }
dialog::backdrop { background: rgba(13,13,14,.5); }
dialog[open] { display: flex; }
.modal-forma { display: flex; flex-direction: column; width: 100%; max-height: calc(100vh - 32px); min-height: 0; }
.modal-cab { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--linea); }
.modal-cab h2 { font-size: 18px; }
.modal-cuerpo { padding: 16px 18px; overflow: auto; display: flex; flex-direction: column; gap: 14px; min-height: 0; }
.modal-pie { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--linea); }
.sub-tit { font-size: 14px; font-weight: 700; margin-bottom: 6px; display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.ayuda { font-size: 13px; color: var(--suave); }
.color-fila { display: grid; grid-template-columns: 46px 42px minmax(0, 1fr) 30px; gap: 8px; align-items: center; padding: 4px 0; }
.color-foto { width: 46px; height: 46px; border-radius: 8px; background: var(--hueso); display: flex; align-items: center; justify-content: center; overflow: hidden; cursor: pointer; font-size: 11px; color: var(--suave); text-align: center; line-height: 1.1; }
.color-foto img { width: 100%; height: 100%; object-fit: contain; }
input[type=color] { width: 42px; height: 38px; padding: 2px; border: 1px solid #d6cfc2; border-radius: 8px; background: #fff; cursor: pointer; }
.precios input { width: 76px; text-align: right; }
.precios .esc input { width: 62px; }
.precios th, .precios td { padding: 4px 6px; border: 0; }
.precios .esc { display: flex; align-items: center; gap: 2px; font-weight: 600; color: var(--suave); font-size: 13px; }

.toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast { background: var(--tinta); color: #fff; padding: 10px 14px; border-radius: 8px; font-size: 14px; font-weight: 600; max-width: 340px; box-shadow: 0 6px 20px rgba(0,0,0,.25); }
.toast.mal { background: var(--rojo); }

/* ---------- inicio de sesion ---------- */
body.sin-sesion { display: block; background: var(--tinta); }
body.sin-sesion .lateral { display: none; }
body.sin-sesion .vista { max-width: none; min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.entrar { width: min(380px, 100%); padding: 26px 24px; display: flex; flex-direction: column; gap: 14px; }
.entrar .marca { padding: 0; color: var(--texto); }
.entrar .marca i { color: var(--oro-oscuro); }
.entrar h1 { font-size: 22px; }

@media (max-width: 1040px) { .pedido-grid { grid-template-columns: 1fr; } .pegajoso { position: static; } }
@media (max-width: 760px) {
  body { display: block; padding-bottom: calc(60px + env(safe-area-inset-bottom)); }
  .lateral { position: fixed; top: auto; bottom: 0; left: 0; right: 0; height: auto; padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); gap: 0; z-index: 20; }
  .marca, .guardado:not(.error) { display: none; }
  .lateral nav { flex-direction: row; justify-content: space-between; overflow-x: auto; }
  .lateral nav a { padding: 9px 8px; font-size: 13px; }
  .guardado.error { padding: 4px 8px; }
  .vista { padding: calc(16px + env(safe-area-inset-top)) 12px 40px; }
  /* iPhone acerca la pantalla si un campo tiene letra menor a 16px */
  input, select, textarea { font-size: 16px; }
  .cabecera h1 { font-size: 22px; }
  .matriz td:first-child, .matriz th:first-child { position: sticky; left: 0; background: var(--papel); z-index: 1; padding-left: 10px; max-width: 128px; white-space: normal; }
  .matriz td { padding: 5px 4px; }
  .mat-input { width: 56px; }
  .celda { min-width: 44px; }
  .color-fila { grid-template-columns: 46px 42px minmax(0, 1fr) 30px; }
}
@media print {
  body { display: block; background: #fff; }
  .lateral, .acciones, .no-imprimir, .toasts { display: none !important; }
  .vista { padding: 0; }
  .tarjeta { border: 0; box-shadow: none; }
  .pedido-grid { grid-template-columns: 1fr; }
}
