:root {
  --ink: #16151a;
  --ink-2: #5c5b63;
  --ink-3: #97969e;
  --bg: #ffffff;
  --bg-2: #f7f5f2;
  --line: rgba(20, 18, 28, 0.1);
  --violet: #6d28d9;
  --verde: #16a34a;
  --ambar: #d97706;
  --rojo: #e11d48;
  --muestra: #facc15;
  --muestra-ink: #422006;
  --radio: 14px;
  --barra: 64px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg-2); }
body { min-height: 100dvh; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

/* --- Cabecera y pestañas ------------------------------------------------ */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--ink); color: #fff;
}
.top h1 { font-size: 15px; font-weight: 600; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sync { display: flex; align-items: center; gap: 6px; font-size: 12px; padding: 5px 10px; border-radius: 99px; background: rgba(255,255,255,.12); border: 0; color: #fff; }
.sync i { width: 8px; height: 8px; border-radius: 50%; background: var(--verde); display: inline-block; }
.sync.pend i { background: var(--muestra); }
.sync.off i { background: var(--ink-3); }
.sync.err i { background: var(--rojo); }

.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--bg); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button { height: var(--barra); border: 0; background: none; font-size: 13px; font-weight: 600; color: var(--ink-3); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; }
.tabs button b { font-size: 20px; line-height: 1; }
.tabs button.on { color: var(--ink); }

main { padding: 12px 16px calc(var(--barra) + 24px + env(safe-area-inset-bottom)); max-width: 760px; margin: 0 auto; }

/* --- Búsqueda y listas -------------------------------------------------- */
.buscar { position: sticky; top: calc(52px + env(safe-area-inset-top)); z-index: 4; background: var(--bg-2); padding: 4px 0 10px; }
.buscar input { width: 100%; height: 48px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); padding: 0 14px; font-size: 17px; }
.chips { display: flex; gap: 8px; margin-top: 8px; overflow-x: auto; }
.chip { flex: none; height: 32px; padding: 0 12px; border-radius: 99px; border: 1px solid var(--line); background: var(--bg); font-size: 13px; }
.chip.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.resumen { font-size: 13px; color: var(--ink-2); margin: 2px 2px 10px; }

.lista { display: flex; flex-direction: column; gap: 8px; }
.persona { display: flex; align-items: center; gap: 10px; background: var(--bg); border: 1px solid var(--line); border-radius: var(--radio); padding: 10px 10px 10px 14px; min-height: 64px; }
.persona .quien { flex: 1; min-width: 0; text-align: left; background: none; border: 0; padding: 0; }
.persona .quien strong { display: block; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.persona .quien span { display: block; font-size: 13px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.persona.fuera { opacity: .45; }
.marcas { display: flex; gap: 4px; flex: none; font-size: 12px; }
.marcas em { font-style: normal; padding: 3px 7px; border-radius: 99px; background: var(--bg-2); color: var(--ink-2); }
.marcas em.m { background: var(--muestra); color: var(--muestra-ink); }
.marcas em.r { background: #fde68a; color: var(--muestra-ink); }
.marcas em.ia { background: #ede9fe; color: var(--violet); }
.llego { flex: none; width: 92px; height: 44px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--bg); font-weight: 600; font-size: 14px; }
.llego.si { background: var(--verde); border-color: var(--verde); color: #fff; }
.vacio { text-align: center; color: var(--ink-3); padding: 32px 8px; }

.btn { height: 48px; padding: 0 18px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); font-weight: 600; font-size: 15px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn.prim { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.ancho { width: 100%; }
.btn.peligro { color: var(--rojo); }
.btn:disabled { opacity: .5; }
.fila-btn { display: flex; gap: 8px; margin: 12px 0; }
.fila-btn .btn { flex: 1; }

/* --- Ficha de una persona ----------------------------------------------- */
.ficha { position: fixed; inset: 0; z-index: 10; background: var(--bg-2); overflow-y: auto; -webkit-overflow-scrolling: touch; }
.ficha-top { position: sticky; top: 0; z-index: 2; background: var(--bg); border-bottom: 1px solid var(--line); padding: calc(8px + env(safe-area-inset-top)) 12px 10px; display: flex; align-items: center; gap: 10px; }
.ficha-top .volver { width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); font-size: 20px; flex: none; }
.ficha-top .titulo { flex: 1; min-width: 0; }
.ficha-top .titulo strong { display: block; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ficha-top .titulo span { display: block; font-size: 13px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ficha-cuerpo { padding: 12px 12px calc(32px + env(safe-area-inset-bottom)); max-width: 760px; margin: 0 auto; }
.aviso { background: #fef3c7; color: var(--muestra-ink); border-radius: 12px; padding: 10px 12px; font-size: 14px; display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.aviso.ia { background: #ede9fe; color: #4c1d95; }
.aviso .btn { height: 36px; font-size: 13px; margin-left: auto; }
.leyenda { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; color: var(--ink-2); margin: 4px 2px 10px; }
.leyenda b { display: inline-block; width: 14px; height: 14px; border-radius: 4px; vertical-align: -2px; margin-right: 4px; border: 1.5px solid var(--line); }
.leyenda b.g { background: var(--ink); border-color: var(--ink); }
.leyenda b.m { background: var(--muestra); border-color: #eab308; }

.bodega { background: var(--bg); border: 1px solid var(--line); border-radius: var(--radio); padding: 8px; margin-bottom: 8px; }
.bodega h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-2); margin: 2px 4px 6px; font-weight: 700; }
.vinos { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.vino { min-height: 58px; border-radius: 10px; border: 1.5px solid var(--line); background: var(--bg); font-size: 12.5px; line-height: 1.2; padding: 6px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; text-align: center; }
.vino small { font-size: 10.5px; font-weight: 700; letter-spacing: .03em; opacity: .8; }
.vino.e1 { background: var(--ink); border-color: var(--ink); color: #fff; }
.vino.e2 { background: var(--muestra); border-color: #eab308; color: var(--muestra-ink); }
.vino.duda { outline: 3px dashed var(--ambar); outline-offset: 2px; }

.bloque { background: var(--bg); border: 1px solid var(--line); border-radius: var(--radio); padding: 12px; margin: 10px 0; }
.bloque h2 { font-size: 15px; margin: 0 0 8px; }
.fotos { display: flex; gap: 8px; flex-wrap: wrap; }
.fotos img { width: 96px; height: 128px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); background: var(--bg-2); }
.fotos .sube { width: 96px; height: 128px; border-radius: 10px; border: 1.5px dashed var(--ink-3); display: flex; align-items: center; justify-content: center; text-align: center; font-size: 13px; color: var(--ink-2); padding: 6px; }
.foto-grande { position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,.92); display: flex; align-items: center; justify-content: center; }
.foto-grande img { max-width: 100%; max-height: 100%; touch-action: pinch-zoom; }

.campo { display: block; margin-bottom: 10px; }
.campo span { display: block; font-size: 12px; font-weight: 600; color: var(--ink-2); margin-bottom: 4px; }
.campo input, .campo select, .campo textarea { width: 100%; min-height: 46px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); padding: 10px 12px; font-size: 16px; }
.dos { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.interruptor { display: flex; align-items: center; gap: 10px; min-height: 46px; font-size: 15px; }
.interruptor input { width: 22px; height: 22px; }

/* --- Datos --------------------------------------------------------------- */
.cifras { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 10px; }
.cifra { background: var(--bg); border: 1px solid var(--line); border-radius: var(--radio); padding: 12px; }
.cifra b { display: block; font-size: 24px; }
.cifra span { font-size: 12px; color: var(--ink-2); }
table.tabla { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tabla th, table.tabla td { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--line); }
table.tabla td.n, table.tabla th.n { text-align: right; font-variant-numeric: tabular-nums; width: 64px; }
table.tabla tr.b td { font-weight: 700; padding-top: 12px; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-2); }
.nota { font-size: 13px; color: var(--ink-2); margin: 6px 0; }

/* --- Entrar -------------------------------------------------------------- */
.entrar { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.entrar form { width: 100%; max-width: 360px; background: var(--bg); border: 1px solid var(--line); border-radius: 18px; padding: 24px; text-align: center; }
.entrar img { width: 64px; height: 64px; }
.entrar h1 { font-size: 20px; margin: 10px 0 4px; }
.entrar p { color: var(--ink-2); font-size: 14px; margin: 0 0 16px; }
.entrar input { width: 100%; height: 50px; border-radius: 12px; border: 1px solid var(--line); padding: 0 14px; font-size: 17px; margin-bottom: 10px; }
.error { color: var(--rojo); font-size: 14px; min-height: 20px; }

.toast { position: fixed; left: 50%; bottom: calc(var(--barra) + 16px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 30; background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: calc(100% - 32px); box-shadow: 0 6px 24px rgba(0,0,0,.2); }

@media (min-width: 700px) {
  .vino { min-height: 64px; font-size: 13.5px; }
  .bodegas { display: grid; grid-template-columns: 1fr 1fr; gap: 0 8px; }
}
