/* =====================================================================
   WEST EAGLE CONTROL - Hoja de estilos
   Identidad: #3E4192 (azul institucional) y blanco.
   Tipografias: Inter (interfaz) y Roboto Mono (DNI, patentes, codigos).
   Mobile first. Probado en telefono, tablet y escritorio.
   ===================================================================== */

:root {
  /* --- Marca */
  --brand:      #3E4192;
  --brand-dk:   #313467;
  --brand-dker: #23254a;
  --brand-lt:   #5c60b8;
  --brand-100:  #e2e3f2;
  --brand-50:   #f0f1f9;

  /* --- Neutros */
  --line:       #e3e5ef;
  --line-2:     #c9ccdf;
  --bg:         #f3f4f9;
  --surface:    #ffffff;
  --surface-2:  #f8f9fc;
  --text:       #191b33;
  --text-2:     #565b7a;
  --text-3:     #9195b0;

  /* --- Estados (semanticos, no de marca) */
  --ok:       #0f9d58;
  --ok-bg:    #e6f6ee;
  --warn:     #d97706;
  --warn-bg:  #fef3c7;
  --err:      #dc2626;
  --err-bg:   #fee2e2;

  --radius:    12px;
  --radius-sm: 8px;
  --shadow:    0 1px 2px rgba(25,27,51,.06), 0 8px 24px rgba(25,27,51,.06);
  --shadow-lg: 0 12px 40px rgba(25,27,51,.20);

  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
  --font-mono: 'Roboto Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { margin: 0 0 .5rem; line-height: 1.25; font-weight: 700; letter-spacing: -.015em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p  { margin: 0 0 .75rem; }

.mono { font-family: var(--font-mono); font-size: .95em; }

/* ------------------------------------------------------------ Topbar */
.topbar {
  position: sticky; top: 0; z-index: 60;
  background: var(--brand);
  color: #fff;
  box-shadow: 0 2px 14px rgba(35,37,74,.28);
}
.topbar-inner {
  display: flex; align-items: center; gap: .75rem;
  max-width: 1280px; margin: 0 auto;
  padding: .5rem .9rem;
}

.topbar .brand { display: flex; align-items: center; gap: .6rem; color: #fff; text-decoration: none; flex: 0 0 auto; }
.topbar .brand:hover { text-decoration: none; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 10px;
  background: #fff; padding: 3px;
  display: grid; place-items: center;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
  flex: 0 0 auto;
}
.brand-mark picture, .brand-mark img { width: 100%; height: 100%; object-fit: contain; display: block; }
.brand-text { display: flex; flex-direction: column; font-weight: 800; font-size: .84rem; letter-spacing: .09em; line-height: 1.05; }
.brand-text small { font-weight: 500; font-size: .62rem; letter-spacing: .24em; color: rgba(255,255,255,.72); }

.nav { display: none; }
.nav a, .nav .nav-link {
  color: rgba(255,255,255,.78); padding: .45rem .6rem; border-radius: var(--radius-sm);
  font-size: .86rem; font-weight: 500; text-decoration: none; white-space: nowrap;
  display: inline-flex; align-items: center; gap: .35rem;
}
.nav a:hover { background: rgba(255,255,255,.14); color: #fff; text-decoration: none; }
.nav a.is-active { background: #fff; color: var(--brand); font-weight: 600; }
.nav-sep { display: inline-block; width: 1px; height: 20px; background: rgba(255,255,255,.25); margin: 0 .3rem; }

.pill {
  background: #fff; color: var(--brand); border-radius: 999px;
  font-size: .68rem; font-weight: 800; padding: 0 .38rem; min-width: 18px; text-align: center;
}
.nav a.is-active .pill { background: var(--brand); color: #fff; }

.topbar-right { margin-left: auto; display: flex; align-items: center; gap: .6rem; }

.ctx-chip {
  display: none; flex-direction: column; align-items: flex-end;
  background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.22);
  padding: .25rem .6rem; border-radius: var(--radius-sm); line-height: 1.2;
}
.ctx-chip strong { font-size: .78rem; color: #fff; }
.ctx-chip span { font-size: .68rem; color: rgba(255,255,255,.8); }

.burger { display: inline-flex; flex-direction: column; justify-content: center; gap: 4px; width: 38px; height: 38px; border: 0; background: transparent; cursor: pointer; padding: 0 8px; }
.burger span { display: block; height: 2px; background: rgba(255,255,255,.9); border-radius: 2px; }

/* Menu de usuario */
.usermenu { position: relative; }
.usermenu summary { list-style: none; cursor: pointer; }
.usermenu summary::-webkit-details-marker { display: none; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%;
  display: grid; place-items: center;
  background: rgba(255,255,255,.16); color: #fff; font-weight: 700; font-size: .76rem;
  border: 1px solid rgba(255,255,255,.35);
}
.usermenu-panel {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 80;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); min-width: 220px; overflow: hidden;
  display: flex; flex-direction: column;
}
.usermenu-head { padding: .7rem .85rem; background: var(--brand-50); border-bottom: 1px solid var(--line); display: flex; flex-direction: column; }
.usermenu-head small { color: var(--text-2); font-size: .75rem; }
.usermenu-panel a, .usermenu-panel .linkbtn {
  padding: .6rem .85rem; color: var(--text); font-size: .88rem; text-decoration: none;
  border: 0; background: none; text-align: left; cursor: pointer; font-family: inherit; width: 100%;
}
.usermenu-panel a:hover, .usermenu-panel .linkbtn:hover { background: var(--surface-2); text-decoration: none; }
.usermenu-panel .danger { color: var(--err); border-top: 1px solid var(--line); }

.nav-backdrop { display: none; }

/* ------------------------------------------------------------ Main */
.app-main {
  max-width: 1280px; margin: 0 auto;
  padding: 1rem .9rem calc(5.5rem + env(safe-area-inset-bottom));
}
.guest-main {
  min-height: 100%; display: grid; place-items: center; padding: 1.5rem 1rem;
  background: linear-gradient(155deg, var(--brand) 0%, var(--brand-dk) 55%, var(--brand-dker) 100%);
}

/* ------------------------------------------------------------ Page head */
.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: .75rem; margin-bottom: 1rem; flex-wrap: wrap;
}
.page-head h1 { margin: 0; }
.page-head .sub { color: var(--text-2); font-size: .88rem; margin: .15rem 0 0; }
.page-actions { display: flex; gap: .5rem; flex-wrap: wrap; }

/* ------------------------------------------------------------ Cards */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  margin-bottom: 1rem; overflow: hidden;
}
/* Tarjetas con desplegables que no deben recortarse */
.card.no-clip { overflow: visible; }
.card-head {
  padding: .8rem 1rem; border-bottom: 1px solid var(--line); background: var(--surface-2);
  display: flex; align-items: center; justify-content: space-between; gap: .6rem; flex-wrap: wrap;
}
.card-head h2, .card-head h3 { margin: 0; font-size: .95rem; }
.card-head .hint { color: var(--text-2); font-size: .8rem; font-weight: 400; }
.card-body { padding: 1rem; }
.card-body.tight { padding: .6rem; }
.card-foot { padding: .75rem 1rem; border-top: 1px solid var(--line); background: var(--surface-2); display: flex; gap: .5rem; justify-content: flex-end; flex-wrap: wrap; }

/* ------------------------------------------------------------ Grid */
.grid { display: grid; gap: 1rem; }
.grid > * { min-width: 0; }
.grid-2 { grid-template-columns: 1fr; }
.grid-3 { grid-template-columns: 1fr; }
.grid-4 { grid-template-columns: repeat(2, 1fr); }

/* ------------------------------------------------------------ Stats */
/* Se acomoda sola a la cantidad de tarjetas, sin dejar huecos */
.stats-grid {
  display: grid; gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: .6rem; }
}

.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: .85rem .9rem; box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.stat::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--line-2); }
.stat.ok::before    { background: var(--ok); }
.stat.primary::before { background: var(--brand); }
.stat.info::before  { background: var(--brand-lt); }
.stat.warn::before  { background: var(--warn); }
.stat .label { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-2); font-weight: 600; }
.stat .value { font-size: 1.7rem; font-weight: 800; line-height: 1.1; margin-top: .15rem; letter-spacing: -.03em; color: var(--brand-dker); }
.stat .foot  { font-size: .74rem; color: var(--text-3); margin-top: .2rem; }

/* ------------------------------------------------------------ Formularios */
.field { margin-bottom: .85rem; }
.field > label, .label {
  display: block; font-size: .76rem; font-weight: 600; color: var(--text-2);
  text-transform: uppercase; letter-spacing: .05em; margin-bottom: .3rem;
}
.field .help { font-size: .78rem; color: var(--text-3); margin-top: .25rem; }

input[type=text], input[type=password], input[type=number], input[type=email],
input[type=tel], input[type=date], input[type=search], input[type=datetime-local],
select, textarea {
  width: 100%; font-family: inherit; font-size: 16px; /* 16px evita el zoom en iOS */
  color: var(--text); background: var(--surface);
  border: 1px solid var(--line-2); border-radius: var(--radius-sm);
  padding: .6rem .7rem; outline: none; transition: border-color .12s, box-shadow .12s;
  -webkit-appearance: none; appearance: none;
}
select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%23565b7a' d='M1 1l5 5 5-5'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right .7rem center; padding-right: 2rem; }
textarea { min-height: 84px; resize: vertical; }

input:focus, select:focus, textarea:focus {
  border-color: var(--brand); box-shadow: 0 0 0 3px rgba(62,65,146,.16);
}
input[readonly], input:disabled, select:disabled, textarea:disabled { background: var(--surface-2); color: var(--text-2); }

.input-lg { font-size: 20px !important; padding: .75rem .8rem !important; font-weight: 600; letter-spacing: .04em; }

.row { display: grid; gap: .75rem; grid-template-columns: 1fr; }
.row > * { min-width: 0; }
.row-2 { grid-template-columns: 1fr 1fr; }
.row-3 { grid-template-columns: 1fr; }

/* Checkbox */
.check { display: flex; align-items: center; gap: .6rem; cursor: pointer; user-select: none; padding: .55rem .7rem; border: 1px solid var(--line-2); border-radius: var(--radius-sm); background: var(--surface); }
.check input { width: 20px; height: 20px; accent-color: var(--brand); margin: 0; flex: 0 0 auto; }
.check span { font-weight: 600; font-size: .9rem; }
.check small { display: block; font-weight: 400; color: var(--text-2); font-size: .78rem; }
.check.is-on { border-color: var(--brand); background: var(--brand-50); }

/* ------------------------------------------------------------ Botones */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  font-family: inherit; font-weight: 600; font-size: .9rem;
  padding: .6rem 1rem; min-height: 42px;
  border-radius: var(--radius-sm); border: 1px solid transparent;
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background .12s, border-color .12s;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-lt); }
.btn-accent  { background: var(--brand); color: #fff; box-shadow: 0 2px 10px rgba(62,65,146,.3); }
.btn-accent:hover { background: var(--brand-lt); }
.btn-ok      { background: var(--ok); color: #fff; }
.btn-ok:hover { background: #0b8a4d; }
.btn-danger  { background: var(--err); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-ghost   { background: var(--surface); color: var(--brand); border-color: var(--line-2); }
.btn-ghost:hover { background: var(--brand-50); border-color: var(--brand-lt); }
.btn-sm { padding: .35rem .65rem; min-height: 34px; font-size: .82rem; }
.btn-lg { padding: .85rem 1.4rem; min-height: 52px; font-size: 1rem; }
.btn-block { width: 100%; }
.btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ------------------------------------------------------------ Badges */
.badge {
  display: inline-flex; align-items: center; gap: .25rem;
  font-size: .72rem; font-weight: 700; padding: .18rem .5rem; border-radius: 999px;
  text-transform: uppercase; letter-spacing: .03em; white-space: nowrap;
}
.badge-ok    { background: var(--ok-bg); color: #0b7a45; }
.badge-muted { background: #e6e8f0; color: var(--text-2); }
.badge-info  { background: var(--brand-100); color: var(--brand); }
.badge-warn  { background: var(--warn-bg); color: #92400e; }
.badge-err   { background: var(--err-bg); color: #b91c1c; }
.badge-brand { background: var(--brand); color: #fff; }

/* ------------------------------------------------------------ Tablas */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data { width: 100%; border-collapse: collapse; font-size: .875rem; }
table.data th, table.data td { padding: .6rem .7rem; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.data th { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--text-2); background: var(--surface-2); font-weight: 700; white-space: nowrap; position: sticky; top: 0; }
table.data tbody tr:hover { background: var(--brand-50); }
table.data td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data .actions { text-align: right; white-space: nowrap; }
table.data .actions > * { display: inline-block; vertical-align: middle; margin-left: .3rem; }
table.data .actions form { margin: 0; }
.nowrap { white-space: nowrap; }

/* ------------------------------------------------------------ Listas tipo tarjeta */
.list { display: grid; gap: .6rem; }
.list-item {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: .8rem .9rem; box-shadow: var(--shadow); display: flex; gap: .8rem; align-items: flex-start;
}
.list-item .ava {
  width: 42px; height: 42px; border-radius: 10px; flex: 0 0 auto;
  display: grid; place-items: center; background: var(--brand); color: #fff; font-weight: 700; font-size: .85rem;
  overflow: hidden;
}
.list-item .ava img { width: 100%; height: 100%; object-fit: cover; }
.list-item .body { flex: 1; min-width: 0; }
.list-item .title { font-weight: 700; font-size: .95rem; }
.list-item .meta { font-size: .8rem; color: var(--text-2); margin-top: .1rem; }
.list-item .meta b { color: var(--text); font-weight: 600; }
.list-item .side { display: flex; flex-direction: column; align-items: flex-end; gap: .4rem; flex: 0 0 auto; }

/* ------------------------------------------------------------ Selector de establecimiento */
.pick-grid { display: grid; gap: .75rem; grid-template-columns: 1fr; }
.pick {
  display: flex; align-items: center; gap: .8rem; text-align: left; width: 100%;
  background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--radius);
  padding: 1rem; cursor: pointer; font: inherit; color: var(--text); box-shadow: var(--shadow);
  transition: border-color .12s, transform .06s;
}
.pick:hover { border-color: var(--brand); text-decoration: none; }
.pick:active { transform: scale(.995); }
.pick .icon { width: 44px; height: 44px; border-radius: 11px; background: var(--brand); color: #fff; display: grid; place-items: center; flex: 0 0 auto; }
.pick .icon svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.pick .t { font-weight: 700; }
.pick .s { font-size: .82rem; color: var(--text-2); }
.pick .arrow { margin-left: auto; color: var(--text-3); font-size: 1.3rem; }

/* =========================================== Buscador con lista de resultados */
.searchbox { position: relative; }

.results {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 120;
  background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); max-height: 320px; overflow-y: auto; display: none;
}
.results.show { display: block; }
.results-head { display: none; }
.results button {
  display: block; width: 100%; text-align: left; padding: .6rem .8rem;
  background: none; border: 0; border-bottom: 1px solid var(--line); font: inherit; cursor: pointer;
}
.results button:last-child { border-bottom: 0; }
.results button:hover, .results button.hl { background: var(--brand-50); }
.results .r-title { font-weight: 600; font-size: .9rem; }
.results .r-meta { font-size: .78rem; color: var(--text-2); }
.results .empty { padding: .9rem; color: var(--text-2); font-size: .86rem; text-align: center; }

/* --- En telefono la lista se reemplaza por un selector a pantalla completa,
       con su propio buscador arriba, para que el teclado no tape los resultados. */
@media (max-width: 899px) {
  .results { display: none !important; }
}

.picker {
  position: fixed; inset: 0; z-index: 400;
  background: var(--surface);
  display: flex; flex-direction: column;
}
.picker[hidden] { display: none !important; }

.picker-head {
  display: flex; align-items: center; gap: .5rem;
  padding: .6rem .7rem; background: var(--brand); color: #fff;
  padding-top: calc(.6rem + env(safe-area-inset-top));
  flex: 0 0 auto;
}
.picker-back {
  width: 40px; height: 40px; flex: 0 0 auto;
  border: 0; background: rgba(255,255,255,.14); color: #fff;
  border-radius: 50%; cursor: pointer;
  display: grid; place-items: center;
}
.picker-back svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.picker-title { font-weight: 700; font-size: 1rem; }

.picker-search { padding: .7rem .8rem; border-bottom: 1px solid var(--line); flex: 0 0 auto; }
.picker-search input { font-size: 16px; }

.picker-list { flex: 1 1 auto; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.picker-list button {
  display: block; width: 100%; text-align: left;
  padding: .85rem 1rem; min-height: 62px;
  background: none; border: 0; border-bottom: 1px solid var(--line);
  font: inherit; cursor: pointer;
}
.picker-list button:active { background: var(--brand-50); }
.picker-list .r-title { font-weight: 600; font-size: 1rem; }
.picker-list .r-meta { font-size: .85rem; color: var(--text-2); margin-top: .1rem; }
.picker-list .empty { padding: 2rem 1rem; text-align: center; color: var(--text-2); }
.picker-list .hint-min { padding: 1.5rem 1rem; text-align: center; color: var(--text-3); font-size: .88rem; }

body.picker-open { overflow: hidden; }

@media (min-width: 900px) {
  .picker { display: none !important; }
}

/* ------------------------------------------------------------ Fotos */
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: .5rem; }
.photo {
  position: relative; aspect-ratio: 1; border-radius: var(--radius-sm); overflow: hidden;
  border: 1px solid var(--line-2); background: var(--surface-2);
}
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo .del {
  position: absolute; top: 3px; right: 3px; width: 24px; height: 24px; border-radius: 50%;
  background: rgba(25,27,51,.75); color: #fff; border: 0; cursor: pointer; font-size: 14px; line-height: 1;
  display: grid; place-items: center;
}
.photo-add {
  display: grid; place-items: center; gap: .2rem; aspect-ratio: 1; cursor: pointer;
  border: 2px dashed var(--line-2); border-radius: var(--radius-sm); color: var(--text-2);
  background: var(--surface-2); font-size: .74rem; text-align: center; padding: .3rem;
}
.photo-add:hover { border-color: var(--brand); color: var(--brand); }
.photo-add svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; }

.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: .6rem; }
.gallery a { display: block; aspect-ratio: 1; border-radius: var(--radius-sm); overflow: hidden; border: 1px solid var(--line); }
.gallery img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* ------------------------------------------------------------ Camara */
.cam-modal {
  position: fixed; inset: 0; z-index: 400; background: rgba(25,27,51,.92);
  display: none; align-items: center; justify-content: center; padding: 1rem;
}
.cam-modal.show { display: flex; }
.cam-box { background: #000; border-radius: var(--radius); overflow: hidden; max-width: 560px; width: 100%; }
.cam-box video { width: 100%; display: block; max-height: 65vh; background: #000; }
.cam-actions { display: flex; gap: .5rem; padding: .75rem; background: var(--brand-dker); }
.cam-actions .btn { flex: 1; }

/* ------------------------------------- Vehiculos conocidos de la persona */
.veh-list { display: grid; gap: .4rem; }
.veh-opt {
  display: flex; align-items: center; gap: .6rem;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: .55rem .7rem; cursor: pointer; background: var(--surface);
}
.veh-opt:hover { border-color: var(--line-2); }
.veh-opt.is-on { border-color: var(--brand); background: var(--brand-50); }
.veh-opt input { flex: 0 0 auto; margin: 0; }
.veh-opt .datos { min-width: 0; flex: 1 1 auto; }
.veh-opt .pat { font-family: var(--font-mono); font-weight: 700; }
.veh-opt .det { font-size: .8rem; color: var(--text-2); }

/* En telefono la fila se compacta: el tipo se omite y la poliza pasa a
   ir debajo de la patente, para que Editar/Quitar entren sin scroll. */
.veh-poliza-movil { display: none; }
@media (max-width: 599px) {
  .veh-tipo, .veh-poliza-col, .emp-art-col { display: none; }
  .veh-poliza-movil { display: block; font-family: var(--font); color: var(--text-2); }
}

/* -------------------------------- Resultados de busqueda por nombre (ingreso) */
.dni-results { display: grid; gap: .5rem; margin-top: .6rem; }
.dni-result {
  display: flex; gap: .7rem; align-items: center; width: 100%; text-align: left;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: .55rem .7rem; background: var(--surface); cursor: pointer; font: inherit;
}
.dni-result:hover, .dni-result:active { border-color: var(--brand); background: var(--brand-50); }
.dni-result .ava {
  width: 42px; height: 42px; border-radius: 10px; flex: 0 0 auto; overflow: hidden;
  display: grid; place-items: center; background: var(--brand); color: #fff; font-weight: 700; font-size: .85rem;
}
.dni-result .ava img { width: 100%; height: 100%; object-fit: cover; }
.dni-result .body { min-width: 0; flex: 1 1 auto; }
.dni-result .title { font-weight: 700; font-size: .92rem; }
.dni-result .dni { font-size: .78rem; color: var(--text-2); margin-top: .15rem; }
.dni-results .empty { padding: .7rem; color: var(--text-2); font-size: .85rem; text-align: center; }

/* ------------------------------------------- Grupo familiar de la visita */
.fam-list { display: grid; gap: .6rem; }
.fam-row {
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: .6rem .7rem; background: var(--surface);
}
.fam-row .fam-del { margin-top: .5rem; }

/* ------------------------------------------------------------ Modal generico
   Usado por el historial de la persona en el formulario de ingreso. */
.modal {
  position: fixed; inset: 0; z-index: 400; background: rgba(25,27,51,.6);
  display: none; align-items: flex-end; justify-content: center;
}
.modal.show { display: flex; }
.modal-box {
  background: var(--surface); width: 100%; max-width: 640px;
  max-height: 88vh; display: flex; flex-direction: column;
  border-radius: 18px 18px 0 0; box-shadow: var(--shadow-lg);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between; gap: .8rem;
  padding: .9rem 1rem; border-bottom: 1px solid var(--line); flex: 0 0 auto;
}
.modal-head h3 { margin: 0; font-size: 1rem; font-weight: 700; }
.modal-head .sub { margin: .1rem 0 0; font-size: .82rem; color: var(--text-2); }
.modal-close {
  background: none; border: 0; font-size: 1.6rem; line-height: 1; cursor: pointer;
  color: var(--text-3); padding: 0 .2rem; flex: 0 0 auto;
}
.modal-body { padding: 1rem; overflow-y: auto; -webkit-overflow-scrolling: touch; }

/* Cada ingreso del historial */
.hist-item {
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: .7rem .8rem; margin-bottom: .6rem;
}
.hist-item:last-child { margin-bottom: 0; }
.hist-item .top {
  display: flex; align-items: center; justify-content: space-between;
  gap: .6rem; margin-bottom: .3rem;
}
.hist-item .fecha { font-weight: 700; font-size: .92rem; }
.hist-item .meta { font-size: .84rem; color: var(--text-2); }
.hist-item .tags { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .45rem; }

@media (min-width: 600px) {
  .modal { align-items: center; padding: 1rem; }
  .modal-box { border-radius: 18px; max-height: 82vh; }
}

/* ------------------------------------------------------------ Flash */
.flashes { display: grid; gap: .5rem; margin-bottom: 1rem; }
.flash {
  display: flex; align-items: center; justify-content: space-between; gap: .6rem;
  padding: .7rem .9rem; border-radius: var(--radius-sm); font-size: .9rem; font-weight: 500;
  border: 1px solid transparent;
}
.flash button { background: none; border: 0; font-size: 1.2rem; cursor: pointer; color: inherit; opacity: .6; line-height: 1; }
.flash-block { display: block; }
.flash-ok    { background: var(--ok-bg);   color: #0b7a45; border-color: #b7e2cb; }
.flash-error { background: var(--err-bg);  color: #b91c1c; border-color: #fbc7c7; }
.flash-warn  { background: var(--warn-bg); color: #92400e; border-color: #fbdc9a; }
.flash-info  { background: var(--brand-100); color: var(--brand); border-color: #c6c8e6; }

/* ------------------------------------------------------------ Login */
.login-card {
  width: 100%; max-width: 410px;
  background: var(--surface); border-radius: 18px; box-shadow: 0 24px 60px rgba(15,16,40,.45); overflow: hidden;
}
.login-head { padding: 1.8rem 1.5rem 1.1rem; text-align: center; background: #fff; }
.login-head .mark { width: 104px; margin: 0 auto .9rem; display: block; }
.login-head .mark picture { display: block; }
.login-head .mark img { width: 100%; height: auto; display: block; }
.login-head h1 { font-size: 1.2rem; letter-spacing: .14em; margin: 0; color: var(--brand); font-weight: 800; }
.login-head p { color: var(--text-2); font-size: .68rem; letter-spacing: .3em; margin: .25rem 0 0; text-transform: uppercase; }
.login-body { padding: .5rem 1.5rem 1.6rem; }

/* ------------------------------------------------------------ Detalle */
.dl { display: grid; grid-template-columns: 1fr; gap: .1rem; }
.dl > div { display: flex; justify-content: space-between; gap: 1rem; padding: .5rem 0; border-bottom: 1px solid var(--line); }
.dl > div:last-child { border-bottom: 0; }
.dl dt { color: var(--text-2); font-size: .82rem; font-weight: 600; }
.dl dd { margin: 0; text-align: right; font-size: .9rem; font-weight: 500; word-break: break-word; }

.section-title {
  font-size: .74rem; text-transform: uppercase; letter-spacing: .07em; color: var(--brand);
  font-weight: 700; margin: 1.2rem 0 .5rem; padding-bottom: .3rem; border-bottom: 2px solid var(--brand-100);
}
.section-title:first-child { margin-top: 0; }

.empty-state { text-align: center; padding: 2.5rem 1rem; color: var(--text-2); }
.empty-state svg { width: 46px; height: 46px; stroke: var(--brand-lt); fill: none; stroke-width: 1.4; margin-bottom: .6rem; }
.empty-state h3 { color: var(--text); }

.toolbar { display: flex; gap: .5rem; flex-wrap: wrap; align-items: flex-end; }
.toolbar .field { margin: 0; flex: 1 1 150px; }

.pager { display: flex; gap: .35rem; justify-content: center; margin-top: 1rem; flex-wrap: wrap; }
.pager a, .pager span {
  padding: .4rem .7rem; border-radius: var(--radius-sm); border: 1px solid var(--line-2);
  background: var(--surface); color: var(--text); font-size: .85rem; text-decoration: none;
}
.pager .cur { background: var(--brand); color: #fff; border-color: var(--brand); }

.muted { color: var(--text-2); }
.small { font-size: .82rem; }
.mt { margin-top: 1rem; }
.mb0 { margin-bottom: 0; }
.center { text-align: center; }
.hidden { display: none !important; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: .6rem; flex-wrap: wrap; }

/* Details usado como boton */
summary.btn { display: inline-flex; list-style: none; }
summary.btn::-webkit-details-marker { display: none; }
summary.btn::marker { content: ''; }
details { min-width: 0; max-width: 100%; }
details[open] { width: 100%; }
details[open] > summary.btn { margin-bottom: .6rem; }
details > form { max-width: 100%; }

/* ------------------------------------------------------------ Tabbar movil */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 70;
  display: flex; background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -4px 16px rgba(25,27,51,.08);
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: .5rem .2rem .45rem; color: var(--text-2); text-decoration: none; font-size: .66rem; font-weight: 600;
}
.tabbar a svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.tabbar a.is-active { color: var(--brand); }
.tabbar a.tab-main svg { background: var(--brand); color: #fff; border-radius: 50%; padding: 3px; width: 26px; height: 26px; }
.tabbar a.tab-main.is-active { color: var(--brand); }

/* ------------------------------------------------------------ Responsive */
@media (min-width: 640px) {
  .grid-2 { grid-template-columns: repeat(2, 1fr); }
  .grid-4 { grid-template-columns: repeat(4, 1fr); }
  .row-3 { grid-template-columns: repeat(3, 1fr); }
  .pick-grid { grid-template-columns: repeat(2, 1fr); }
  h1 { font-size: 1.7rem; }
}

@media (min-width: 900px) {
  .grid-3 { grid-template-columns: repeat(3, 1fr); }
  .pick-grid { grid-template-columns: repeat(3, 1fr); }
  .app-main { padding-bottom: 2rem; }
  .tabbar { display: none; }
  .burger { display: none; }
  .nav { display: flex; align-items: center; gap: .1rem; overflow-x: auto; }
  .ctx-chip { display: flex; }
}

/* Drawer en pantallas chicas */
@media (max-width: 899px) {
  .nav {
    position: fixed; top: 0; left: 0; bottom: 0; width: 268px; z-index: 100;
    background: var(--brand); flex-direction: column; align-items: stretch;
    padding: 4.2rem .7rem 1rem; gap: .15rem; overflow-y: auto;
    transform: translateX(-100%); transition: transform .22s ease;
    display: flex;
  }
  body.nav-open .nav { transform: translateX(0); }
  body.nav-open .nav-backdrop {
    display: block; position: fixed; inset: 0; z-index: 90; background: rgba(25,27,51,.5);
  }

  /* El cajon vive dentro de .topbar, que al ser sticky con z-index crea su
     propio contexto de apilamiento: el z-index del cajon queda encerrado ahi.
     Por eso, mientras el menu esta abierto, elevamos toda la barra por encima
     del fondo oscuro. Sin esto el fondo tapa el menu y se come los toques. */
  body.nav-open .topbar { z-index: 110; }

  /* Nada debe quedar por encima del menu abierto */
  body.nav-open .install-card { display: none; }
  body.nav-open { overflow: hidden; }
  .nav a { padding: .7rem .8rem; font-size: .92rem; }
  .nav-sep { width: auto; height: 1px; margin: .4rem .5rem; }
}

@media print {
  .topbar, .tabbar, .page-actions, .card-foot, .flashes { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; border-color: #ccc; }
  .app-main { padding: 0; max-width: none; }
}

/* Campo que en telefono abre el selector a pantalla completa */
input.tap-to-open {
  background: var(--surface) !important;
  color: var(--text) !important;
  cursor: pointer;
}

/* ============================================================ PWA: instalar */
.install-card {
  position: fixed; z-index: 380;
  left: .75rem; right: .75rem;
  bottom: calc(4.6rem + env(safe-area-inset-bottom));
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 18px 50px rgba(25,27,51,.28);
  padding: .9rem 1rem;
  display: grid;
  grid-template-columns: 52px 1fr;
  grid-template-areas: "icono cuerpo" "acciones acciones";
  gap: .5rem .8rem;
  align-items: center;
  opacity: 0; transform: translateY(14px);
  transition: opacity .2s ease, transform .2s ease;
}
.install-card.show { opacity: 1; transform: translateY(0); }

.install-icon {
  grid-area: icono;
  width: 52px; height: 52px; border-radius: 13px;
  border: 1px solid var(--line);
  background: #fff; overflow: hidden;
  display: grid; place-items: center;
}
.install-icon img { width: 100%; height: 100%; object-fit: contain; display: block; }

.install-body { grid-area: cuerpo; min-width: 0; }
.install-title { font-weight: 700; font-size: .95rem; line-height: 1.2; }
.install-text { font-size: .82rem; color: var(--text-2); margin-top: .15rem; }
.install-text b { color: var(--text); font-weight: 600; }

.install-actions {
  grid-area: acciones;
  display: flex; gap: .5rem; justify-content: flex-end;
  margin-top: .2rem;
}
.install-actions .btn { flex: 1 1 auto; }

.install-close {
  position: absolute; top: 6px; right: 8px;
  border: 0; background: none; color: var(--text-3);
  font-size: 1.3rem; line-height: 1; cursor: pointer; padding: 2px 6px;
}
.install-close:hover { color: var(--text); }

@media (min-width: 640px) {
  .install-card {
    left: auto; right: 1.25rem; bottom: 1.25rem;
    width: 384px;
    padding: 1.05rem 1.15rem;
    gap: .7rem .9rem;
  }
  .install-actions { margin-top: .55rem; }
  .install-actions .btn { flex: 0 0 auto; min-width: 108px; }
}

/* Instalada: nada de esto se muestra */
@media (display-mode: standalone) {
  .install-card { display: none !important; }
}

/* Instalada: la barra superior respeta la zona de la barra de estado */
@media (display-mode: standalone) {
  .topbar { padding-top: env(safe-area-inset-top); }
}

/* En el login no hay barra inferior: la tarjeta baja */
body.is-guest .install-card { bottom: calc(1rem + env(safe-area-inset-bottom)); }

/* Submenu de administracion dentro de la barra */
.navmenu { position: relative; }
.navmenu > summary {
  list-style: none; cursor: pointer;
  color: rgba(255,255,255,.78); padding: .45rem .6rem; border-radius: var(--radius-sm);
  font-size: .86rem; font-weight: 500; white-space: nowrap;
  display: inline-flex; align-items: center; gap: .3rem;
}
.navmenu > summary::-webkit-details-marker { display: none; }
.navmenu > summary:hover { background: rgba(255,255,255,.14); color: #fff; }
.navmenu.is-active > summary { background: #fff; color: var(--brand); font-weight: 600; }
.navmenu .caret { font-size: .7em; opacity: .8; }

.navmenu-panel {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 90;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  min-width: 200px; overflow: hidden; display: flex; flex-direction: column;
}
.navmenu-panel a, .navmenu-panel a.nav-link {
  color: var(--text) !important; background: none !important;
  padding: .6rem .85rem; font-size: .88rem; border-radius: 0;
}
.navmenu-panel a:hover { background: var(--brand-50) !important; color: var(--brand) !important; }
.navmenu-panel a.is-active { background: var(--brand-50) !important; color: var(--brand) !important; font-weight: 600; }

/* En el cajon del telefono no hay desplegable: se listan todas y el
   titulo pasa a ser un rotulo de seccion, no un boton.
   La regla necesita mas peso que ".nav .nav-link", que fija inline-flex. */
@media (max-width: 899px) {
  .nav .navmenu > summary {
    display: block; pointer-events: none;
    color: rgba(255,255,255,.45); font-size: .68rem; font-weight: 700;
    text-transform: uppercase; letter-spacing: .09em;
    padding: .8rem .8rem .25rem; background: none;
  }
  .nav .navmenu > summary .caret { display: none; }
  .navmenu-panel {
    position: static; background: none; border: 0; box-shadow: none;
    min-width: 0; border-radius: 0;
  }
  .navmenu-panel a, .navmenu-panel a.nav-link {
    color: rgba(255,255,255,.78) !important;
    padding: .7rem .8rem; font-size: .92rem;
  }
  .navmenu-panel a:hover { background: rgba(255,255,255,.14) !important; color: #fff !important; }
  .navmenu-panel a.is-active { background: #fff !important; color: var(--brand) !important; }
}
