:root {
  --navy: #01054C;
  --navy-2: #1B2070;
  --cyan: #00DBFF;
  --cyan-soft: #E0FAFF;
  --bg: #F4F5FA;
  --card: #FFFFFF;
  --text: #0B0E33;
  --muted: #6B6F8E;
  --line: #E4E6F0;
  --red: #D93D4A;
  --amber: #C98A00;
  --green: #12A36B;
  --radius: 18px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.4 "Nunito", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- Estructura ---------- */
.screen { max-width: 560px; margin: 0 auto; padding: calc(16px + var(--safe-t)) 16px calc(96px + var(--safe-b)); min-height: 100%; }
.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.topbar img { height: 26px; }
.avatar { width: 36px; height: 36px; border-radius: 50%; border: 0; background: var(--navy); color: #fff; font-weight: 800; font-size: 14px; cursor: pointer; }
.demo-banner { background: var(--cyan-soft); color: var(--navy); border-radius: 12px; padding: 8px 12px; font-size: 13px; font-weight: 600; margin-bottom: 16px; }
h1 { font-size: 24px; font-weight: 800; margin: 0 0 14px; color: var(--navy); }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; justify-content: center; gap: 8px;
  padding: 8px 16px calc(8px + var(--safe-b));
  background: rgba(255,255,255,.92); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.tab { flex: 1; max-width: 200px; border: 0; background: none; padding: 6px; border-radius: 12px; color: var(--muted); font-size: 12px; font-weight: 700; display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer; }
.tab svg { width: 24px; height: 24px; }
.tab.on { color: var(--navy); }

/* ---------- Inicio ---------- */
.hero { display: flex; flex-direction: column; align-items: center; padding: 24px 0 28px; }
.scan-btn {
  width: 168px; height: 168px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--navy); color: var(--cyan);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  box-shadow: 0 14px 34px rgba(1,5,76,.28), inset 0 0 0 6px rgba(0,219,255,.12);
  transition: transform .12s;
}
.scan-btn:active { transform: scale(.96); }
.scan-btn svg { width: 54px; height: 54px; }
.scan-btn span { color: #fff; font-weight: 800; font-size: 15px; }

.search { position: relative; }
.search input {
  width: 100%; height: 50px; border-radius: 14px; border: 1px solid var(--line); background: var(--card);
  padding: 0 14px 0 44px; font-size: 16px; outline: none;
}
.search input:focus { border-color: var(--navy); }
.search svg { position: absolute; left: 14px; top: 15px; width: 20px; height: 20px; color: var(--muted); }
.hint { color: var(--muted); font-size: 14px; text-align: center; margin: 14px 0; }

/* ---------- Listas ---------- */
.list { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.row {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px; cursor: pointer;
}
.row:active { background: #F7F8FC; }
.tag { flex: none; min-width: 58px; text-align: center; font-weight: 800; font-size: 14px; color: var(--navy); background: var(--cyan-soft); border-radius: 10px; padding: 6px 8px; font-variant-numeric: tabular-nums; }
.tag.free { background: #EAFBF3; color: var(--green); }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row.muted { opacity: .55; }
.empty { color: var(--muted); text-align: center; padding: 28px 8px; }

.inv-head { display: flex; align-items: center; justify-content: space-between; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 12px 0 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 7px 12px; font-size: 14px; font-weight: 700; color: var(--muted); cursor: pointer; white-space: nowrap; }
.chip.on { background: var(--navy); border-color: var(--navy); color: #fff; }
.count { color: var(--muted); font-size: 13px; margin-top: 8px; }

/* ---------- Botones ---------- */
.btn { border: 0; border-radius: 14px; padding: 14px 18px; font-weight: 800; cursor: pointer; font-size: 16px; }
.btn.primary { background: var(--navy); color: #fff; }
.btn.accent { background: var(--cyan); color: var(--navy); }
.btn.ghost { background: #EEF0F7; color: var(--navy); }
.btn.ghost-light { background: rgba(255,255,255,.16); color: #fff; }
.btn.small { padding: 9px 14px; font-size: 14px; border-radius: 12px; }
.btn:disabled { opacity: .5; }
.btns { display: flex; gap: 10px; margin-top: 18px; }
.btns .btn { flex: 1; }
.link { background: none; border: 0; color: var(--navy); font-weight: 700; text-decoration: underline; cursor: pointer; padding: 6px 0; }

/* ---------- Hojas (fichas y formularios) ---------- */
.layer { position: fixed; inset: 0; z-index: 20; background: rgba(1,5,30,.42); display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
#picker { z-index: 30; }
.panel {
  background: var(--bg); width: 100%; max-width: 560px; max-height: 94vh; overflow-y: auto;
  border-radius: 24px 24px 0 0; padding: 10px 18px calc(22px + var(--safe-b));
  animation: up .2s ease-out;
}
.grab { width: 40px; height: 5px; border-radius: 3px; background: #CDD0DE; margin: 0 auto 12px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.panel-head h2 { margin: 0; font-size: 20px; font-weight: 800; color: var(--navy); }
.x { border: 0; background: #E6E8F2; width: 32px; height: 32px; border-radius: 50%; font-size: 18px; line-height: 1; cursor: pointer; color: var(--navy); flex: none; }
@keyframes up { from { transform: translateY(40px); opacity: .4; } }
@keyframes fade { from { opacity: 0; } }

.big-tag { font-size: 34px; font-weight: 800; color: var(--navy); letter-spacing: .5px; font-variant-numeric: tabular-nums; }
.pill { display: inline-block; border-radius: 999px; padding: 4px 10px; font-size: 13px; font-weight: 800; }
.pill.ok { background: #E3F8EF; color: var(--green); }
.pill.warn { background: #FFF4D6; color: var(--amber); }
.pill.bad { background: #FDE6E8; color: var(--red); }
.pill.off { background: #ECEDF3; color: var(--muted); }
.what { font-size: 19px; font-weight: 800; margin: 2px 0 14px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 4px 14px; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.kv:last-child { border-bottom: 0; }
.kv .k { color: var(--muted); font-size: 14px; flex: none; }
.kv .v { font-weight: 700; text-align: right; overflow-wrap: anywhere; }
.photo { width: 100%; border-radius: var(--radius); margin-bottom: 12px; display: block; max-height: 320px; object-fit: cover; background: #E6E8F2; }

details.hist { margin-top: 16px; }
details.hist summary { cursor: pointer; font-weight: 800; color: var(--navy); padding: 8px 0; list-style: none; }
details.hist summary::-webkit-details-marker { display: none; }
details.hist summary::after { content: " ▾"; color: var(--muted); }
.h-item { border-left: 3px solid var(--cyan); padding: 4px 0 4px 12px; margin: 10px 0; }
.h-item b { display: block; }
.h-item small { color: var(--muted); }
.h-item p { margin: 2px 0; font-size: 14px; white-space: pre-line; }

.free-box { text-align: center; padding: 18px 0 6px; }
.free-box p { color: var(--muted); margin: 6px 0 18px; }

/* ---------- Formularios ---------- */
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; font-weight: 800; color: var(--muted); margin: 0 0 6px 4px; }
.field input, .field textarea, .field select, .pick {
  width: 100%; min-height: 48px; border: 1px solid var(--line); border-radius: 14px; background: var(--card);
  padding: 12px 14px; font-size: 16px; outline: none;
}
.field input:focus, .field textarea:focus { border-color: var(--navy); }
.field textarea { min-height: 80px; resize: vertical; }
.pick { display: flex; align-items: center; justify-content: space-between; text-align: left; cursor: pointer; }
.pick .ph { color: #A0A3BB; }
.pick::after { content: "›"; color: var(--muted); font-size: 22px; line-height: 1; margin-left: 8px; }
.two { display: flex; gap: 10px; }
.with-btn { display: flex; gap: 8px; align-items: stretch; }
.with-btn input { flex: 1; min-width: 0; }
.with-btn .btn { flex: none; }
.two .field { flex: 1; min-width: 0; }
.photo-pick { display: flex; align-items: center; gap: 12px; }
.photo-pick img { width: 64px; height: 64px; border-radius: 12px; object-fit: cover; }
.err { color: var(--red); font-size: 14px; font-weight: 700; margin: 8px 4px 0; }

/* ---------- Selector con búsqueda ---------- */
.pk-list { margin-top: 10px; display: flex; flex-direction: column; background: var(--card); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.pk-item { border: 0; background: none; text-align: left; padding: 13px 14px; border-bottom: 1px solid var(--line); cursor: pointer; display: flex; justify-content: space-between; gap: 8px; }
.pk-item:last-child { border-bottom: 0; }
.pk-item.sel { font-weight: 800; color: var(--navy); }
.pk-item.sel::after { content: "✓"; color: var(--navy); }
.pk-item.add { color: var(--navy); font-weight: 800; }
.pk-item.clear { color: var(--muted); }
.pk-group { font-size: 12px; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; padding: 10px 14px 4px; background: #F8F9FC; }

/* ---------- Escáner ---------- */
#scanner { position: fixed; inset: 0; z-index: 40; background: #000; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; padding: 20px; }
#reader { width: 100%; max-width: 520px; border-radius: 18px; overflow: hidden; }
#reader video { border-radius: 18px; }
.scan-hint { color: #fff; font-weight: 700; margin: 0; text-align: center; }

/* ---------- Login / cargando ---------- */
.center { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; padding: 24px; text-align: center; }
.center img.logo { height: 40px; }
.center p { color: var(--muted); margin: 0; max-width: 320px; }
.setup-field { width: 100%; max-width: 420px; text-align: left; }
.setup-field textarea { min-height: 180px; }
.spinner { width: 34px; height: 34px; border: 4px solid #DDE0EC; border-top-color: var(--navy); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

#toast {
  position: fixed; left: 50%; bottom: calc(92px + var(--safe-b)); transform: translateX(-50%); z-index: 50;
  background: var(--navy); color: #fff; padding: 12px 18px; border-radius: 14px; font-weight: 700; font-size: 15px;
  box-shadow: 0 10px 30px rgba(1,5,76,.3); max-width: calc(100% - 32px); text-align: center;
}
