:root {
  --verde: #1f5e3b;
  --verde-2: #2c7a4f;
  --verde-claro: #e6f0e9;
  --maiz: #e3a72f;
  --maiz-claro: #fbf1da;
  --rojo: #b3261e;
  --rojo-claro: #fbe9e7;
  --fondo: #f5f3ee;
  --tarjeta: #ffffff;
  --texto: #1d2420;
  --texto-2: #5b645f;
  --borde: #e2e0d8;
  --radio: 14px;
  --sombra: 0 1px 2px rgba(20, 30, 25, .06), 0 2px 8px rgba(20, 30, 25, .05);
  --arriba: env(safe-area-inset-top, 0px);
  --abajo: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--fondo);
  color: var(--texto);
  overscroll-behavior-y: none;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------------------------------------------------------- barra */
.barra {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 6px;
  min-height: calc(var(--arriba) + 62px);
  padding: calc(var(--arriba) + 10px) 14px 10px;
  background: var(--verde); color: #fff;
}
.barra-titulo { flex: 1; min-width: 0; }
.barra h1 { margin: 0; font-size: 18px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.barra-titulo span { display: block; font-size: 12.5px; opacity: .8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.barra-titulo span:empty { display: none; }
.icono-btn { border: 0; background: none; color: inherit; padding: 6px; margin-left: -6px; border-radius: 10px; display: grid; place-items: center; }
.icono-btn:active { background: rgba(255,255,255,.15); }
.estado-red { width: 10px; height: 10px; border-radius: 50%; background: #7ee2a0; box-shadow: 0 0 0 3px rgba(255,255,255,.15); flex: none; }
.estado-red.fuera { background: var(--maiz); }

main { padding: 12px 12px calc(84px + var(--abajo)); max-width: 720px; margin: 0 auto; }

/* ---------------------------------------------------------- navegación */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--tarjeta); border-top: 1px solid var(--borde);
  padding-bottom: var(--abajo);
}
.nav a {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0 7px; font-size: 11.5px; color: var(--texto-2); text-decoration: none;
}
.nav a.activo { color: var(--verde); font-weight: 600; }
.nav a.activo svg { stroke-width: 2.2; }
.nav-badge {
  position: absolute; top: 3px; left: calc(50% + 6px);
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--maiz); color: #3b2a00; font-size: 11px; line-height: 18px; text-align: center;
}

/* ---------------------------------------------------------- componentes */
.buscador { position: sticky; top: calc(var(--arriba) + 62px); z-index: 10; margin: -12px -12px 10px; padding: 10px 12px 8px; background: var(--fondo); }
.campo-busqueda { position: relative; }
.campo-busqueda svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--texto-2); width: 19px; height: 19px; }
.campo-busqueda input { padding-left: 40px; }

input, select, textarea {
  width: 100%; padding: 11px 12px; border: 1px solid var(--borde); border-radius: 12px;
  background: var(--tarjeta); outline: none; font-size: 16px;
}
input:focus, select:focus, textarea:focus { border-color: var(--verde-2); box-shadow: 0 0 0 3px var(--verde-claro); }
textarea { resize: vertical; min-height: 64px; }
label.campo { display: block; margin-bottom: 12px; }
label.campo > span { display: block; font-size: 13px; color: var(--texto-2); margin-bottom: 4px; }

.chips { display: flex; gap: 6px; overflow-x: auto; padding-top: 8px; scrollbar-width: none; }
.chip {
  flex: none; border: 1px solid var(--borde); background: var(--tarjeta); color: var(--texto-2);
  padding: 5px 11px; border-radius: 999px; font-size: 13px;
}
.chip.activo { background: var(--verde); border-color: var(--verde); color: #fff; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 12px; padding: 12px 16px; font-weight: 600;
  background: var(--verde); color: #fff; width: 100%;
}
.btn:active { background: var(--verde-2); }
.btn:disabled { opacity: .5; }
.btn.sec { background: var(--verde-claro); color: var(--verde); }
.btn.peligro { background: var(--rojo-claro); color: var(--rojo); }
.btn.chico { width: auto; padding: 8px 12px; font-size: 14px; }
.fila-btns { display: flex; gap: 8px; }
.fila-btns .btn { flex: 1; }

.tarjeta { background: var(--tarjeta); border-radius: var(--radio); box-shadow: var(--sombra); padding: 14px; margin-bottom: 10px; }
.tarjeta h2 { margin: 0 0 8px; font-size: 16px; }
.tarjeta h3 { margin: 0 0 6px; font-size: 13px; color: var(--texto-2); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }

.lista { background: var(--tarjeta); border-radius: var(--radio); box-shadow: var(--sombra); overflow: hidden; }
.item {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 12px 14px; border: 0; border-bottom: 1px solid var(--borde);
  background: none; text-align: left; text-decoration: none; color: inherit;
}
.item:last-child { border-bottom: 0; }
button.item:active, a.item:active { background: var(--fondo); }
.item-cuerpo { flex: 1; min-width: 0; }
.item-titulo { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-titulo.dos { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; line-height: 1.3; }
.item-sub + .item-sub { margin-top: 3px; }
.item-sub { font-size: 13px; color: var(--texto-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-der { text-align: right; flex: none; font-size: 13px; color: var(--texto-2); }
.item-der strong { display: block; color: var(--texto); font-size: 14.5px; }
.item-der strong.sin { color: var(--texto-2); font-weight: 500; font-size: 13px; }
.avatar {
  width: 40px; height: 40px; border-radius: 12px; flex: none; display: grid; place-items: center;
  background: var(--verde-claro); color: var(--verde); font-weight: 700; font-size: 14px;
}

.etiqueta { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 2px 7px; border-radius: 6px; background: var(--verde-claro); color: var(--verde); margin-right: 4px; vertical-align: 1px; }
.etiqueta.alerta { background: var(--maiz-claro); color: #7a5200; }
.etiqueta.mal { background: var(--rojo-claro); color: var(--rojo); }
.etiqueta.gris { background: #eeede8; color: var(--texto-2); }

.nota { font-size: 13px; color: var(--texto-2); text-align: center; padding: 10px; }
.vacio { text-align: center; color: var(--texto-2); padding: 40px 20px; }
.vacio svg { width: 44px; height: 44px; stroke-width: 1.4; opacity: .5; display: block; margin: 0 auto 8px; }
.mensaje { border-radius: 12px; padding: 10px 12px; font-size: 14px; margin-bottom: 10px; background: var(--maiz-claro); color: #5d3f00; }
.mensaje.mal { background: var(--rojo-claro); color: var(--rojo); }
.mensaje.bien { background: var(--verde-claro); color: var(--verde); }

.datos { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
.datos div span { display: block; font-size: 12px; color: var(--texto-2); }
.datos div b { font-weight: 600; font-size: 14.5px; word-break: break-word; }
.datos .ancho { grid-column: 1 / -1; }
.datos a { color: var(--verde); }

.num { font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------- login */
.login { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; padding: 24px; max-width: 420px; margin: 0 auto; }
.login-logo { width: 84px; height: 84px; border-radius: 22px; margin: 0 auto 14px; display: block; box-shadow: var(--sombra); }
.login h1 { text-align: center; margin: 0; font-size: 24px; color: var(--verde); }
.login p { text-align: center; color: var(--texto-2); margin: 4px 0 28px; }

/* ---------------------------------------------------------- pedido */
.linea { padding: 12px 14px; border-bottom: 1px solid var(--borde); }
.linea:last-child { border-bottom: 0; }
.linea-top { display: flex; gap: 8px; align-items: flex-start; }
.linea-top .item-titulo { white-space: normal; flex: 1; font-size: 14.5px; }
.linea-quitar { border: 0; background: none; color: var(--texto-2); padding: 2px; }
.linea-quitar svg { width: 18px; height: 18px; }
.linea-bajo { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.linea-precio { flex: 1; padding: 6px 2px; text-align: left; font-size: 13px; color: var(--texto-2); }
.linea-precio b { color: var(--texto); font-size: 14px; }
.linea-total { font-weight: 650; min-width: 92px; text-align: right; }

.stepper { display: flex; align-items: center; border: 1px solid var(--borde); border-radius: 10px; overflow: hidden; background: var(--tarjeta); flex: none; }
.stepper button { border: 0; background: none; width: 34px; height: 34px; font-size: 20px; color: var(--verde); line-height: 1; }
.stepper button:active { background: var(--verde-claro); }
.stepper input { width: 58px; border: 0; border-radius: 0; padding: 6px 2px; text-align: center; font-weight: 600; box-shadow: none !important; }

.totales { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; font-size: 14.5px; }
.totales .grande { font-size: 19px; font-weight: 700; color: var(--verde); }

.pie-accion {
  position: fixed; left: 0; right: 0; bottom: calc(58px + var(--abajo)); z-index: 15;
  padding: 10px 12px; background: linear-gradient(transparent, var(--fondo) 30%);
}
.pie-accion > div { max-width: 696px; margin: 0 auto; }
.con-pie { padding-bottom: calc(150px + var(--abajo)); }

/* ---------------------------------------------------------- hoja */
.hoja-fondo { position: fixed; inset: 0; z-index: 40; background: rgba(15, 25, 20, .45); }
.hoja {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41;
  max-height: 92vh; display: flex; flex-direction: column;
  background: var(--fondo); border-radius: 18px 18px 0 0;
  padding-bottom: var(--abajo); max-width: 720px; margin: 0 auto;
  animation: subir .18s ease-out;
}
.hoja.completa { height: 92vh; }
@keyframes subir { from { transform: translateY(24px); opacity: .6; } }
.hoja-cab { display: flex; align-items: center; gap: 8px; padding: 14px 14px 8px; }
.hoja-cab h2 { flex: 1; margin: 0; font-size: 17px; }
.hoja-cab .icono-btn { color: var(--texto-2); margin: 0; }
.hoja-cuerpo { overflow-y: auto; padding: 0 14px 14px; flex: 1; }
.hoja .item-sub { white-space: normal; }
.hoja-pie { padding: 10px 14px 14px; border-top: 1px solid var(--borde); background: var(--tarjeta); }

.aviso {
  position: fixed; left: 50%; bottom: calc(76px + var(--abajo)); transform: translateX(-50%); z-index: 60;
  background: #1d2420; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px;
  max-width: calc(100% - 32px); box-shadow: 0 6px 20px rgba(0,0,0,.2);
}
