/* Presupuestos Exquisito — mobile first */
:root {
  --marron: #4a1a0b;
  --marron-2: #6b2c17;
  --rojo: #b3261e;
  --rojo-osc: #8f1d17;
  --naranja: #e8730c;
  --verde-wa: #1f9d55;
  --crema: #fbf6f0;
  --crema-2: #f3e9de;
  --borde: #e6d9cb;
  --texto: #2b1a14;
  --gris: #7a6a62;
  --blanco: #fff;
  --radio: 14px;
  --sombra: 0 1px 2px rgba(74, 26, 11, .06), 0 4px 16px rgba(74, 26, 11, .06);
  --nav-h: 64px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--texto);
  -webkit-text-size-adjust: 100%;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--crema); }
body { min-height: 100dvh; -webkit-tap-highlight-color: transparent; }
body.con-nav { padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); }
[hidden] { display: none !important; }
img { max-width: 100%; display: block; }
h1 { font-size: 1.35rem; margin: 0; color: var(--marron); letter-spacing: -.01em; }
h2 { font-size: .8rem; margin: 0 0 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--rojo); }

/* ---------- Barra superior ---------- */
.barra {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(8px + env(safe-area-inset-top)) 14px 8px;
  background: var(--blanco); border-bottom: 1px solid var(--borde);
}
.barra-marcas { display: flex; align-items: center; gap: 10px; }
.barra-logo { height: 30px; width: auto; }
.barra-logo-pg { height: 25px; }
.barra-sep { width: 1px; height: 24px; background: var(--borde); }
.barra-usuario {
  display: flex; align-items: center; gap: 6px; border: 0; background: var(--crema);
  color: var(--marron); font: inherit; font-size: .85rem; font-weight: 600;
  padding: 8px 10px; border-radius: 999px; cursor: pointer;
}

/* ---------- Navegación inferior ---------- */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(3, 1fr);
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--blanco); border-top: 1px solid var(--borde);
}
.nav a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--gris); text-decoration: none; font-size: .75rem; font-weight: 600;
}
.nav svg { width: 26px; height: 26px; }
.nav a.activo { color: var(--rojo); }

/* ---------- Layout ---------- */
.vista { max-width: 640px; margin: 0 auto; padding: 16px 14px 24px; }
.titulo-vista { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 4px 2px 14px; }
.tarjeta {
  background: var(--blanco); border: 1px solid var(--borde); border-radius: var(--radio);
  padding: 16px; margin-bottom: 14px; box-shadow: var(--sombra);
}
.fila-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.aviso { background: #fff4e6; border: 1px solid #f6d3a8; color: #7a4a10; border-radius: 10px; padding: 10px 12px; font-size: .9rem; margin: 0 0 14px; }
.estado-carga, .estado-error { text-align: center; padding: 40px 12px; color: var(--gris); }
.estado-error { color: var(--rojo); }
.vacio { text-align: center; padding: 30px 12px; color: var(--gris); list-style: none; }

/* ---------- Campos ---------- */
.campo { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.campo > span { font-size: .82rem; font-weight: 600; color: var(--marron-2); }
input, select, textarea {
  width: 100%; font: inherit; font-size: 16px; /* evita zoom en iOS */
  color: var(--texto); background: var(--blanco);
  border: 1.5px solid var(--borde); border-radius: 10px; padding: 12px;
  min-height: 48px; outline: none; transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; min-height: 84px; }
input:focus, select:focus, textarea:focus { border-color: var(--rojo); box-shadow: 0 0 0 3px rgba(179, 38, 30, .12); }
.campo.invalido input { border-color: var(--rojo); background: #fff6f5; }
.campo.invalido > span::after { content: " — obligatorio"; color: var(--rojo); font-weight: 500; }
.check { display: flex; align-items: center; gap: 10px; font-weight: 600; color: var(--marron); min-height: 44px; cursor: pointer; }
.check input { width: 22px; height: 22px; min-height: 0; accent-color: var(--rojo); }
.error-form { color: var(--rojo); font-size: .88rem; margin: 4px 0 10px; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 50px; padding: 0 18px; border-radius: 12px; border: 0;
  font: inherit; font-weight: 700; font-size: 1rem; cursor: pointer; text-decoration: none;
  transition: transform .08s, background .15s, opacity .15s;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .55; cursor: default; }
.btn-bloque { width: 100%; }
.btn-chico { min-height: 40px; font-size: .9rem; padding: 0 14px; }
.btn-prim { background: var(--rojo); color: var(--blanco); }
.btn-prim:hover { background: var(--rojo-osc); }
.btn-wa { background: var(--verde-wa); color: var(--blanco); }
.btn-sec { background: var(--blanco); color: var(--marron); border: 1.5px solid var(--borde); }
.btn-peligro { background: var(--rojo); color: var(--blanco); }
.btn-texto-peligro { color: var(--rojo); }
.btn-link { background: none; border: 0; color: var(--rojo); font: inherit; font-weight: 600; font-size: .9rem; padding: 8px 4px; cursor: pointer; }
.btn-icono { background: none; border: 0; color: var(--gris); padding: 8px; margin: -8px -8px -8px 0; border-radius: 8px; cursor: pointer; }

.segmentado { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--crema-2); border-radius: 12px; padding: 4px; gap: 4px; }
.segmentado button {
  min-height: 42px; border: 0; border-radius: 9px; background: transparent;
  font: inherit; font-weight: 600; color: var(--gris); cursor: pointer;
}
.segmentado button.activo { background: var(--blanco); color: var(--marron); box-shadow: 0 1px 3px rgba(0,0,0,.08); }

/* ---------- Login ---------- */
.login { max-width: 400px; margin: 0 auto; padding: 8vh 4px 20px; }
.login-marcas { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: center; padding: 0 10px; }
.login-alianza { text-align: center; color: var(--gris); font-style: italic; margin: 12px 0 26px; }
.login h1 { text-align: center; margin-bottom: 18px; }

/* ---------- Productos en el presupuesto ---------- */
.buscador { position: relative; margin-bottom: 12px; }
.sugerencias {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 10;
  list-style: none; margin: 0; padding: 6px; background: var(--blanco);
  border: 1px solid var(--borde); border-radius: 12px; box-shadow: 0 10px 30px rgba(74, 26, 11, .15);
  max-height: 320px; overflow-y: auto;
}
.sugerencias button {
  width: 100%; display: flex; justify-content: space-between; gap: 10px; text-align: left;
  min-height: 46px; padding: 10px; border: 0; background: none; border-radius: 8px;
  font: inherit; color: var(--texto); cursor: pointer;
}
.sugerencias button:hover, .sugerencias button:focus { background: var(--crema); }
.sugerencias strong { color: var(--marron); white-space: nowrap; }
.sugerencias .sug-manual { color: var(--rojo); font-weight: 600; }

.items { list-style: none; margin: 0; padding: 0; }
.items-vacio { color: var(--gris); text-align: center; padding: 14px; font-size: .92rem; background: var(--crema); border-radius: 10px; }
.item { border: 1px solid var(--borde); border-radius: 12px; padding: 12px; margin-bottom: 10px; background: var(--crema); }
.item-cab { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.item-cab .item-nombre { font-weight: 700; color: var(--marron); }
input.item-nombre { min-height: 42px; padding: 8px 10px; }
.item-datos { display: grid; grid-template-columns: auto auto 1fr; align-items: center; gap: 8px; }
.item-sub { grid-column: 1 / -1; text-align: right; color: var(--marron); font-size: 1.02rem; }
.stepper { display: flex; align-items: center; border: 1.5px solid var(--borde); border-radius: 10px; background: var(--blanco); overflow: hidden; }
.stepper button { width: 40px; min-height: 44px; border: 0; background: none; font-size: 1.3rem; color: var(--rojo); cursor: pointer; }
.stepper input { width: 52px; min-height: 44px; border: 0; border-radius: 0; text-align: center; padding: 0; box-shadow: none !important; }
.por { color: var(--gris); }
.precio { display: flex; align-items: center; border: 1.5px solid var(--borde); border-radius: 10px; background: var(--blanco); padding-left: 10px; }
.precio span { color: var(--gris); }
.precio input { border: 0; min-height: 44px; padding: 0 10px 0 6px; box-shadow: none !important; }
.item-guardar { margin-top: 4px; padding-left: 0; }

.total-linea { display: flex; justify-content: space-between; align-items: baseline; padding: 12px 2px 4px; border-top: 2px dashed var(--borde); margin-top: 6px; color: var(--marron); }
.total-linea strong { font-size: 1.35rem; }

.bloque-senia { background: var(--crema); border-radius: 12px; padding: 12px; margin-top: 6px; }
.saldo { margin: 0; color: var(--marron); }

.barra-guardar {
  position: sticky; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 8px); z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--marron); color: var(--blanco); border-radius: 16px; padding: 10px 10px 10px 16px;
  box-shadow: 0 8px 24px rgba(74, 26, 11, .3);
}
.barra-guardar small { display: block; opacity: .75; font-size: .75rem; }
.barra-guardar strong { font-size: 1.2rem; }
.barra-guardar .btn { flex-shrink: 0; }

/* ---------- Detalle ---------- */
.acciones-principales { display: grid; gap: 10px; margin-bottom: 14px; }
.acciones-secundarias { display: grid; grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); gap: 10px; }
.resumen-fila { display: flex; justify-content: space-between; gap: 14px; padding: 7px 0; border-bottom: 1px solid var(--crema-2); font-size: .95rem; }
.resumen-fila:last-child { border-bottom: 0; }
.resumen-fila > span:first-child { color: var(--gris); flex-shrink: 0; }
.resumen-fila > :last-child { text-align: right; }
.lista-items { list-style: none; margin: 0 0 4px; padding: 0; }
.lista-items li { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--crema-2); }
.notas { background: var(--crema); border-radius: 10px; padding: 10px 12px; margin: 10px 0 0; white-space: pre-wrap; }
.estados { display: flex; flex-wrap: wrap; gap: 8px; }
.chip-btn { min-height: 40px; padding: 0 14px; border-radius: 999px; border: 1.5px solid var(--borde); background: var(--blanco); font: inherit; font-weight: 600; color: var(--gris); cursor: pointer; }
.chip-btn.activo { background: var(--marron); border-color: var(--marron); color: var(--blanco); }

.chip { display: inline-block; padding: 4px 10px; border-radius: 999px; font-size: .75rem; font-weight: 700; white-space: nowrap; }
.chip-borrador { background: #eee7e1; color: #6b5d55; }
.chip-enviado { background: #e3edfb; color: #1f4f96; }
.chip-aceptado { background: #dff3e6; color: #17703d; }
.chip-rechazado { background: #fbe4e2; color: var(--rojo-osc); }
.chip-vencido { background: #fdf0dc; color: #8a5208; }

/* ---------- Historial / catálogo ---------- */
.filtros { display: grid; gap: 10px; margin-bottom: 14px; }
.historial, .catalogo { list-style: none; margin: 0; padding: 0; }
.historial li a {
  display: block; text-decoration: none; color: inherit; background: var(--blanco);
  border: 1px solid var(--borde); border-radius: 12px; padding: 12px 14px; margin-bottom: 8px;
}
.h-fila1, .h-fila2 { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.h-fila1 strong:first-child { color: var(--marron); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.h-fila2 { margin-top: 6px; color: var(--gris); font-size: .85rem; }
.paginado { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 12px; color: var(--gris); }

.catalogo li:not(.vacio) {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  background: var(--blanco); border: 1px solid var(--borde); border-radius: 12px; padding: 10px 12px; margin-bottom: 8px;
}
.catalogo li.inactivo { opacity: .55; }
.cat-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.cat-info strong { color: var(--marron); }
.cat-info span { color: var(--gris); font-size: .85rem; }
.cat-acc { display: flex; flex-shrink: 0; }

/* ---------- Modal y toast ---------- */
.modal-fondo { position: fixed; inset: 0; z-index: 50; background: rgba(43, 26, 20, .45); display: grid; place-items: center; padding: 20px; }
.modal { background: var(--blanco); border-radius: 16px; padding: 20px; width: 100%; max-width: 380px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal p { margin: 0 0 18px; font-size: 1.02rem; color: var(--marron); }
.modal-acciones { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 84px); z-index: 60;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  max-width: calc(100% - 32px); width: max-content;
  background: var(--marron); color: var(--blanco); padding: 12px 18px; border-radius: 12px;
  font-weight: 600; font-size: .95rem; box-shadow: 0 10px 30px rgba(0,0,0,.25); transition: all .2s;
}
.toast.visible { opacity: 1; transform: translate(-50%, 0); }
.toast-error { background: var(--rojo); }

@media (min-width: 700px) {
  .vista { padding-top: 24px; }
  .barra-logo { height: 36px; }
  .barra-logo-pg { height: 30px; }
}
