/* Invok — sistema de diseño compartido (las 4 apps: /r/, /g/, /a/, /m/)
   Dirección: General Sans, off-white cálido, acento negro neutro (sin color de marca fijo —
   lo que diferencia es gris, no color, para poder aplicarse a cualquier marca), hairlines 1px,
   tarjetas 20px, bar traslúcida. Estados: skeleton con shimmer, vacío con cara + texto, error con causa.
   Reglas de layout: toda pantalla = bar (header) + main + foot (footer).
   Formularios: campos cortos van en filas (.row), solo lo ancho va a 100%. */

:root {
  --bg: #f7f5ef; --fg: #1c1c1a; --muted: #6e6e66; --card: #fff; --line: #e5e3dc;
  --accent: #1c1c1a; --accent-fg: #fff; --accent-soft: color-mix(in srgb, var(--accent) 8%, transparent);
  --ok: #4b4b46; --ok-soft: color-mix(in srgb, var(--ok) 12%, transparent);
  --danger: #b42318; --danger-soft: color-mix(in srgb, var(--danger) 10%, transparent);
  --radius: 20px; --radius-sm: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 8px 24px -12px rgba(0,0,0,.12);
  --shadow-lift: 0 2px 4px rgba(0,0,0,.05), 0 16px 32px -16px rgba(0,0,0,.18);
  --sidebar-bg: #141413; --sidebar-fg: #ededea; --sidebar-muted: #8a8a85;
  --bar-bg: rgba(255,255,255,.72);
  --ring: color-mix(in srgb, var(--accent) 22%, transparent);
  --space: 12px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #151514; --fg: #ededea; --muted: #a3a39e; --card: #1f1f1d; --line: #34342f;
    --accent: #ededea; --accent-fg: #151514; --danger: #f97066; --ok: #c7c7c0;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px -12px rgba(0,0,0,.5);
    --shadow-lift: 0 2px 6px rgba(0,0,0,.4), 0 20px 40px -20px rgba(0,0,0,.7);
    --bar-bg: rgba(31,31,29,.72); }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; min-height: 100dvh; display: flex; flex-direction: column;
  font: 16px/1.5 'General Sans', system-ui, -apple-system, sans-serif;
  background: var(--bg); color: var(--fg); }

/* ---------- Tipografía: tracking y leading según el tamaño ---------- */
h1, h2, h3 { margin: 0; font-weight: 700; line-height: 1.15; letter-spacing: -0.02em; }
h1 { font-size: clamp(1.5rem, 4vw, 2rem); letter-spacing: -0.03em; }
h2 { font-size: 1.15rem; letter-spacing: -0.01em; }
p { margin: 0; }
.muted { color: var(--muted); font-size: .95rem; }
a { color: var(--accent); text-underline-offset: 2px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* ---------- Layout: bar + main + foot ---------- */
main { flex: 1; width: 100%; max-width: 760px; margin: 0 auto; padding: 24px 16px 32px;
  display: grid; gap: 16px; align-content: start;
  animation: fade-in 220ms cubic-bezier(.2,.8,.2,1) both; }
.center { align-content: center; justify-items: center; }
main > .card, main > .cards, main > .stats { width: 100%; }

.bar { display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; background: var(--bar-bg);
  backdrop-filter: blur(20px) saturate(180%); -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.bar-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.bar .logo { height: 24px; width: auto; display: block; }
.bar-title { font-weight: 600; letter-spacing: -0.01em; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; }
.bar-title .muted { font-weight: 500; }
.bar > button { white-space: nowrap; flex-shrink: 0; }

.foot { margin-top: auto; display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 18px 16px; padding-bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--line); color: var(--muted); font-size: .85rem; }
.foot-row { display: flex; align-items: center; justify-content: center; gap: 16px; flex-wrap: wrap; }
.foot-links { display: flex; gap: 14px; }
.foot-links a { color: var(--muted); text-decoration: none; }
.foot-links a:hover { color: var(--fg); text-decoration: underline; text-underline-offset: 2px; }
.foot-brand { display: inline-flex; align-items: center; gap: 6px; text-decoration: none; color: var(--muted); }
.foot-brand .muted { font-size: .8875rem; } /* 1px menos que el .muted normal (.95rem), solo aquí */
.foot-brand img { height: 17px; width: auto; display: block; opacity: .8; transition: opacity 140ms ease; }
.foot-brand:hover { color: var(--fg); }
.foot-brand:hover img { opacity: 1; }

/* Fondo de marca — landing y pantallas de login de las 4 apps. Siempre cover, nunca
   recortado por scroll (fixed), a media opacidad para no pelear con el contenido. */
.hero-bg { position: relative; }
.hero-bg::before {
  content: ''; position: fixed; inset: 0; z-index: -1;
  background-image: url('/shared/hero-bg.png'); background-repeat: no-repeat;
  background-position: center center; background-size: cover; opacity: .5;
}

/* Logo oficial: es negro por diseño — se invierte en modo oscuro */
@media (prefers-color-scheme: dark) {
  .bar .logo, .logo-xl, .foot img { filter: invert(1); }
}

/* ---------- Marca en pantallas de acceso ---------- */
.auth { max-width: 420px; justify-items: stretch; }
.app-tag { justify-self: center; padding: 4px 14px; border-radius: 999px; font-size: .78rem;
  font-weight: 400; letter-spacing: .03em; background: var(--accent); color: var(--accent-fg); }
.logo-xl { width: min(200px, 60%); height: auto; display: block; margin: 0 auto 4px; }
.tagline { text-align: center; margin-bottom: 8px; }

/* ---------- Tarjetas y listas ---------- */
.cards { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; display: grid; gap: 14px; box-shadow: var(--shadow); }
.card.rowline { display: flex; align-items: baseline; justify-content: space-between;
  gap: 8px; flex-wrap: wrap; padding: 16px 20px; }
@media (hover: hover) {
  .card { transition: box-shadow 180ms ease, transform 180ms ease; }
  .cards > .card:hover { box-shadow: var(--shadow-lift); transform: translateY(-1px); }
}
a.card { transition: box-shadow 180ms ease, transform 120ms cubic-bezier(.2,.8,.2,1); }
a.card:active { transform: scale(.98); transition-duration: 80ms; }
.card .actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Estado vacío: cara + título + texto centrados (helpers emptyState/errState/skeleton en shared/app.js) */
.empty { text-align: center; padding: 24px 8px; display: grid; gap: 8px; justify-items: center; }
.empty .glyph { width: 54px; height: 54px; border-radius: 16px; background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center; }
.empty .glyph .ico { margin: 0; width: 1.5em; height: 1.5em; }
.empty b { font-size: 1rem; }
.empty p { color: var(--muted); font-size: .88rem; max-width: 34ch; }

/* ---------- Formularios: retícula con lógica ---------- */
label { display: grid; gap: 6px; font-weight: 600; font-size: .92rem; letter-spacing: .01em; }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.row > .full, .full { grid-column: 1 / -1; }

input, select, textarea { font: inherit; font-size: 1rem; padding: 12px; width: 100%;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--card); color: var(--fg);
  transition: border-color 140ms ease, box-shadow 140ms ease; }
textarea { min-height: 96px; resize: vertical; line-height: 1.45; }
input:hover, select:hover, textarea:hover { border-color: color-mix(in srgb, var(--fg) 28%, var(--line)); }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring); }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .8; }

/* Selector de archivo: control propio en español (el nativo dice "Choose File") */
.file { position: relative; display: flex; align-items: center; gap: 12px; min-height: 50px;
  padding: 8px 12px; border: 1px dashed var(--line); border-radius: var(--radius-sm);
  background: var(--bg); transition: border-color 140ms ease, box-shadow 140ms ease; }
.file:hover { border-color: color-mix(in srgb, var(--fg) 28%, var(--line)); }
.file:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring); }
.file input[type="file"] { position: absolute; inset: 0; width: 100%; height: 100%;
  opacity: 0; padding: 0; border: 0; cursor: pointer; }
.file-face { font-size: .9rem; font-weight: 600; padding: 8px 14px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--card); color: var(--fg);
  pointer-events: none; white-space: nowrap; }
.file-name { font-size: .9rem; pointer-events: none; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }

/* Campo de contraseña con botón de mostrar/ocultar — todas las pantallas de login. */
.pw-field { position: relative; display: block; }
.pw-field input { padding-right: 46px; }
.pw-toggle { position: absolute; right: 2px; top: 50%; transform: translateY(-50%);
  width: 40px; height: 40px; display: grid; place-items: center; padding: 0;
  border: 0; background: none; color: var(--muted); }
.pw-toggle:hover { color: var(--fg); border-color: transparent; }
.pw-toggle svg { width: 20px; height: 20px; flex: none; }
.pw-toggle .icon-eye-off { display: none; }
.pw-toggle[aria-pressed="true"] .icon-eye { display: none; }
.pw-toggle[aria-pressed="true"] .icon-eye-off { display: block; }

/* ---------- Botones: feedback en el pointer-down ---------- */
button { font: inherit; cursor: pointer; padding: 11px 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--card); color: var(--fg);
  transition: transform 120ms cubic-bezier(.2,.8,.2,1), background-color 140ms ease,
    border-color 140ms ease, filter 140ms ease; }
button:hover:not(:disabled) { border-color: color-mix(in srgb, var(--fg) 28%, var(--line)); }
button:active:not(:disabled) { transform: scale(.97); transition-duration: 60ms; }
button:disabled { opacity: .5; cursor: default; }
button.big { padding: 16px; font-size: 1.05rem; font-weight: 700; width: 100%; }
button.primary { background: var(--accent); color: var(--accent-fg); border-color: transparent; }
button.primary:hover:not(:disabled) { filter: brightness(1.07); border-color: transparent; }
button.link, button.ghost { border: 0; background: none; color: var(--muted); padding: 6px; }
button.link { text-decoration: underline; text-underline-offset: 2px; }
button.link:hover, button.ghost:hover { color: var(--fg); }

/* ---------- Estados ---------- */
.error { color: var(--danger); min-height: 1.2em; margin: 0; font-size: .92rem; }
.error:empty { min-height: 0; }
.ok { color: var(--ok); }
.pill { display: inline-flex; align-items: center; padding: 4px 12px; border-radius: 999px; border: 0;
  font-size: .8rem; font-weight: 600; background: var(--line); color: var(--fg); }
.pill.ok { background: var(--accent); color: var(--accent-fg); }
.pill.warn { background: var(--danger); color: #fff; }
.icon { width: 1.2em; height: 1.2em; vertical-align: -0.25em; margin-right: 4px; flex: none; }

/* Carga: skeleton con shimmer (la forma aproxima el contenido que va a llegar) */
.sk { display: grid; gap: 10px; width: 100%; }
.sk i { display: block; height: 14px; border-radius: 8px;
  background: linear-gradient(90deg, var(--line) 25%, color-mix(in srgb, var(--line) 45%, var(--card)) 37%, var(--line) 63%);
  background-size: 400% 100%; animation: shimmer 1.4s ease infinite; }
.sk.rows { gap: 8px; }
.sk.rows i { height: 44px; border-radius: 12px; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }

/* Error de carga: causa + salida (Reintentar), en soft danger */
.err { display: flex; gap: 10px; align-items: flex-start; background: var(--danger-soft); color: var(--danger);
  border-radius: var(--radius-sm); padding: 12px 14px; font-size: .88rem; font-weight: 600; }
.err .ico { margin: 2px 0 0; }
.err div { display: grid; gap: 2px; min-width: 0; }
.err span { font-weight: 500; opacity: .85; }
.err .ghost { color: var(--danger); text-decoration: underline; text-underline-offset: 2px; padding: 0; flex: none; }
.err .ghost:hover { opacity: .8; }

/* ---------- Datos: tablas, filtros, stats ---------- */
.plate { font-size: 1.4rem; text-transform: uppercase; letter-spacing: 2px; }
table { width: 100%; border-collapse: collapse; font-size: .95rem; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
tbody tr { transition: background 120ms ease; }
tbody tr:hover { background: color-mix(in srgb, var(--fg) 3%, transparent); }
/* La acción de la fila aparece al apuntarla (en táctil queda siempre visible) */
@media (hover: hover) {
  .t-actions button { opacity: 0; transition: opacity 120ms ease; }
  tr:hover .t-actions button, tr:focus-within .t-actions button { opacity: 1; }
}
.table-wrap { overflow-x: auto; }
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; align-items: end; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stats[hidden] { display: none; }
/* Pestañas de Caseta (Por ingresar / Residentes): el id gana por especificidad a
   "main > div:not([class])" de abajo, que si no pisa el [hidden] normal y no oculta nada. */
#view-ingresos[hidden], #view-residentes[hidden] { display: none; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow); display: grid; gap: 4px; align-content: start; }
.stat .top { display: flex; justify-content: space-between; align-items: start; gap: 8px; }
.stat .top .ico-box { width: 34px; height: 34px; border-radius: 10px; background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center; flex: none; }
.stat .top .ico-box .ico { margin: 0; }
.delta { font-size: .74rem; font-weight: 700; padding: 3px 8px; border-radius: 999px; background: var(--ok-soft); color: var(--ok);
  font-variant-numeric: tabular-nums; white-space: nowrap; }
.delta.down { background: var(--danger-soft); color: var(--danger); }
.stat .n { font-size: 1.8rem; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat .l { color: var(--muted); font-size: .85rem; letter-spacing: .02em; }
.stat .spark { margin-top: 6px; display: block; width: 100%; height: 34px; color: var(--accent); }
.stat.dark { background: var(--sidebar-bg); color: var(--sidebar-fg); border-color: transparent; }
.stat.dark .l { color: var(--sidebar-muted); }

/* ---------- Overlay de llamada (voz) ---------- */
.call { position: fixed; inset: 0; z-index: 40; display: grid; place-content: center; gap: 16px;
  padding: 24px; text-align: center; background: var(--accent); color: var(--accent-fg); }
.call button { background: var(--accent-fg); color: var(--accent); }
.call .link { background: none; color: var(--accent-fg); }

/* ---------- Shell con sidebar agrupado (Admin y Plataforma) ----------
   bar (sticky) arriba; la columna izquierda vive oscura de alto a bajo mientras el
   contenido crece; el grupo activo es una píldora con el acento (negro/gris, neutro). */
.shell { display: grid; grid-template-columns: 224px 1fr; flex: 1; width: 100%;
  background: linear-gradient(to right, var(--sidebar-bg) 0 224px, transparent 224px); }
.sidebar { background: transparent; color: var(--sidebar-fg); padding: 18px 12px; display: grid;
  gap: 18px; align-content: start; position: sticky; top: 45px; height: calc(100dvh - 45px);
  overflow-y: auto; }
.sidebar .grp { display: grid; gap: 2px; }
.sidebar .grp > span { font-size: .66rem; font-weight: 700; letter-spacing: .1em; color: var(--sidebar-muted);
  padding: 6px 10px 2px; text-transform: uppercase; }
.sidebar button { width: 100%; text-align: left; background: none; border: 0; color: var(--sidebar-muted);
  padding: 10px 12px; border-radius: 999px; font-weight: 600; position: relative; z-index: 1;
  transition: color 140ms ease; }
.sidebar button:hover { color: var(--sidebar-fg); background: rgba(255,255,255,.06); }
.sidebar button.active { color: var(--accent-fg); }
/* Píldora que se desliza al botón activo (top/height puestos por JS en app.js) en vez de aparecer de golpe. */
.sidebar .pill { position: absolute; top: 0; left: 12px; right: 12px; height: 38px; border-radius: 999px;
  background: var(--accent); z-index: 0; transition: transform 380ms cubic-bezier(.34, 1.56, .64, 1); }
.sidebar .pill[hidden] { display: none; }
.shell > main { max-width: 1100px; width: 100%; margin: 0 auto; padding: 24px; }

/* Hamburguesa (solo ≤720px) y velo del drawer móvil */
.menu-btn { display: none; align-items: center; justify-content: center; flex: none;
  width: 44px; height: 44px; padding: 0; border-radius: 12px;
  background: var(--card); border: 1px solid var(--line); color: var(--fg); }
.menu-btn .ico { width: 22px; height: 22px; margin: 0; }
.side-scrim { position: fixed; inset: 0; z-index: 3; padding: 0; border: 0;
  background: rgba(20, 20, 19, .5); display: none; }

/* ---------- Responsive ---------- */
@media (max-width: 720px) {
  .shell { grid-template-columns: 1fr; background: none; }
  /* El sidebar se convierte en drawer: la hamburguesa de la barra lo abre desde la izquierda. */
  .menu-btn { display: inline-flex; }
  .side-scrim:not([hidden]) { display: block; }
  .sidebar { position: fixed; top: 45px; left: 0; bottom: 0; z-index: 4; width: min(82vw, 300px);
    height: auto; padding: 18px 12px calc(18px + env(safe-area-inset-bottom, 0px));
    background: var(--sidebar-bg); overflow-y: auto;
    transform: translateX(-100%); transition: transform 240ms cubic-bezier(.2, .8, .2, 1);
    box-shadow: none; }
  /* Al abrir, leve rebote (overshoot); al cerrar, el ease normal de arriba — se siente menos mecánico. */
  .sidebar.open { transform: none; transition: transform 360ms cubic-bezier(.34, 1.56, .64, 1);
    box-shadow: 14px 0 40px -14px rgba(0, 0, 0, .55); }
  body.menu-open { overflow: hidden; }
  .shell > main { padding: 16px 14px 28px; }
  .row { grid-template-columns: 1fr; }
  main { padding: 20px 14px 28px; }
}

/* ---------- Movimiento: material que llega, no parpadeo ---------- */
@keyframes fade-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) {
  main { animation: none; }
  button { transition: none; }
  button:active:not(:disabled) { transform: none; }
  .card, .cards > .card:hover, a.card, a.card:active { transition: none; transform: none; }
  .sidebar, .sidebar.open, .sidebar .pill { transition: none; }
}
@media (prefers-reduced-transparency: reduce) {
  .bar { background: var(--card); backdrop-filter: none; -webkit-backdrop-filter: none; }
}
@media (prefers-contrast: more) {
  .bar { border-bottom-color: var(--fg); }
  input, select, textarea, button { border-width: 2px; }
}

/* ---------- Íconos de iconifika y tags de visita ---------- */
.ico { display: inline-block; width: 1.3em; height: 1.3em; vertical-align: -0.28em; margin-right: 8px; flex: none;
  background: currentColor; -webkit-mask: var(--i) center / contain no-repeat; mask: var(--i) center / contain no-repeat; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { display: inline-flex; padding: 3px 10px; border-radius: 999px; font-size: .78rem; font-weight: 600;
  background: var(--line); color: var(--fg); }
.tag[data-g="kind"] { background: var(--accent); color: var(--accent-fg); }
.tag[data-state="in"] { background: transparent; border: 1px solid var(--fg); }
.tag[data-state="expired"], .tag[data-state="cancelled"] { color: var(--muted); text-decoration: line-through; }
.visit-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; }
.chip { white-space: nowrap; border-radius: 999px; padding: 8px 14px; font-size: .9rem; }
.chip.on { background: var(--accent); color: var(--accent-fg); border-color: transparent; }
.grid-gap { display: grid; gap: 14px; }
.weekdays { border: 0; padding: 0; margin: 0; display: flex; gap: 10px; flex-wrap: wrap; }
.weekdays legend { font-weight: 600; font-size: .92rem; margin-bottom: 6px; padding: 0; }
.weekdays label { display: flex; align-items: center; gap: 4px; font-weight: 500; }
.weekdays input { width: auto; }

/* ---------- Residente: instalación obligatoria y pantalla principal ---------- */
.gate { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 20px; overflow-y: auto;
  background: color-mix(in srgb, var(--bg) 78%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); }
.gate-card { width: min(100%, 420px); display: grid; gap: 16px; justify-items: start; padding: 24px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-lift); }
.gate-card #gate-install { width: 100%; }
.gate-steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; }
.gate-steps li { display: flex; gap: 12px; align-items: flex-start; }
.gate-steps .ico { margin: 2px 0 0; }
.home-call { display: grid; gap: 8px; justify-items: center; }
.call-btn { display: flex; align-items: center; justify-content: center; padding: 24px; font-size: 1.2rem; border-radius: 28px; }

/* Bottom nav del residente: píldora en el activo, fija abajo con safe-area */
.bottomnav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px;
  padding: 8px 10px calc(10px + env(safe-area-inset-bottom, 0px));
  background: color-mix(in srgb, var(--card) 88%, transparent);
  backdrop-filter: blur(16px) saturate(160%); -webkit-backdrop-filter: blur(16px) saturate(160%);
  border-top: 1px solid var(--line); }
.bottomnav button { border: 0; background: none; color: var(--muted); font-size: .66rem; font-weight: 600;
  display: grid; gap: 3px; justify-items: center; padding: 6px 4px; border-radius: 14px; min-height: 44px; }
.bottomnav .ico { margin: 0; width: 1.15em; height: 1.15em; }
.bottomnav button.on { color: var(--accent); background: var(--accent-soft); }
body.has-bottomnav { padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px)); }
@media (prefers-reduced-transparency: reduce) {
  .bottomnav { background: var(--card); backdrop-filter: none; -webkit-backdrop-filter: none; }
}

/* ---------- Llamada con el asistente ---------- */
.orb { width: 120px; height: 120px; margin: 0 auto; animation: orb-pop-in 480ms cubic-bezier(.34, 1.56, .64, 1) both; }
.orb.leaving { animation: orb-pop-out 320ms cubic-bezier(.36, 0, .66, -0.56) both; }
@keyframes orb-pop-in { 0% { transform: scale(.25); opacity: 0; } 65% { transform: scale(1.15); opacity: 1; } 100% { transform: scale(1); } }
@keyframes orb-pop-out { 0% { transform: scale(1); opacity: 1; } 35% { transform: scale(1.15); } 100% { transform: scale(.25); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .orb, .orb.leaving { animation: none; } }
.call-status, .call-label { min-height: 1.4em; }
.call-label { opacity: .75; }
.call-chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; max-width: 420px; margin: 0 auto; }
.call-preview { display: grid; gap: 6px; justify-items: center; padding: 14px; border-radius: var(--radius-sm); background: rgba(128,128,128,.22); }
.call .tag { background: rgba(128,128,128,.3); color: inherit; }
.call-type { display: flex; gap: 8px; max-width: 420px; margin: 0 auto; }
.call-type input { background: transparent; color: inherit; border-color: rgba(128,128,128,.6); }

/* Botón con ícono; también para enlaces que hacen de botón */
.btn { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; color: var(--fg);
  padding: 11px 16px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--card); }
a.btn:hover { border-color: color-mix(in srgb, var(--fg) 28%, var(--line)); }

/* Lista larga con scroll propio: la página no crece con cada residente nuevo */
.table-scroll { margin-top: 12px; max-height: min(60vh, 520px); overflow: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.table-scroll table { min-width: 560px; }
.table-scroll thead th { position: sticky; top: 0; z-index: 1; background: var(--card); box-shadow: 0 1px 0 var(--line); }
.table-scroll tbody tr:last-child td { border-bottom: 0; }
.t-actions { text-align: right; white-space: nowrap; }

/* ---------- Diálogos de Invok (confirmDialog / alertDialog) ---------- */
dialog.modal { width: min(92vw, 420px); padding: 24px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--card); color: var(--fg); box-shadow: var(--shadow-lift); animation: fade-in 160ms ease; }
dialog.modal::backdrop { background: rgba(20, 20, 19, .45); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
dialog.modal form { display: grid; gap: 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
@media (max-width: 480px) { .modal-actions { flex-direction: column-reverse; } .modal-actions button { width: 100%; } }
dialog.modal.wide { width: min(94vw, 460px); max-height: 92dvh; overflow-y: auto; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.head-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
@media (prefers-reduced-motion: reduce) { dialog.modal { animation: none; } }

/* ---------- Burbuja de preguntas frecuentes (residente) ---------- */
.faq-fab { position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 30;
  width: 52px; height: 52px; padding: 0; border-radius: 50%; display: grid; place-items: center; font-size: 1.5rem;
  background: var(--accent); color: var(--accent-fg); border-color: transparent; box-shadow: var(--shadow-lift); }
.faq-fab .ico { margin: 0; width: 1.4em; height: 1.4em; }
dialog.faq { font: 16px/1.5 'General Sans', system-ui, -apple-system, sans-serif; /* vive fuera de <body>: no hereda su fuente */
  width: min(94vw, 520px); max-height: min(86vh, 720px); padding: 0; border: 1px solid var(--line);
  border-radius: var(--radius); background: var(--card); color: var(--fg); box-shadow: var(--shadow-lift);
  overflow: hidden; animation: fade-in 160ms ease; }
dialog.faq[open] { display: grid; grid-template-rows: auto auto minmax(0, 1fr); }
dialog.faq::backdrop { background: rgba(20, 20, 19, .45); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.faq-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 18px 20px 8px; }
.faq-head .ghost { padding: 6px; }
.faq-head .ico { margin: 0; }
.faq-search { margin: 4px 20px 12px; width: calc(100% - 40px); }
.faq-body { overflow-y: auto; padding: 0 20px 20px; display: grid; gap: 18px; align-content: start; }
.faq-body h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 6px; }
.faq-body details { border-bottom: 1px solid var(--line); }
.faq-body summary { cursor: pointer; padding: 12px 0; font-weight: 600; list-style: none; display: flex; justify-content: space-between; gap: 12px; }
.faq-body summary::-webkit-details-marker { display: none; }
.faq-body summary::after { content: '+'; color: var(--muted); font-weight: 400; flex: none; }
.faq-body details[open] summary::after { content: '–'; }
.faq-body details p { padding: 0 0 14px; color: var(--muted); line-height: 1.55; }
.faq-body details p b { color: var(--fg); }
@media (prefers-reduced-motion: reduce) { dialog.faq { animation: none; } }

/* ---------- Avisos negros (toast): pila abajo, con entrada y salida animadas ---------- */
#toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(20px + env(safe-area-inset-bottom)); z-index: 50;
  width: min(92vw, 440px); display: grid; gap: 8px; pointer-events: none; }
.toast { pointer-events: auto; cursor: pointer; display: flex; align-items: flex-start; gap: 12px; padding: 14px 18px; border-radius: 18px;
  background: var(--accent); color: var(--accent-fg); box-shadow: var(--shadow-lift); animation: toast-in 260ms cubic-bezier(.2,.8,.2,1) both; }
.toast.out { animation: toast-out 220ms ease-in both; }
.toast .ico { margin: 2px 0 0; flex: none; }
.toast-text { display: grid; gap: 2px; min-width: 0; }
.toast-text span { opacity: .8; font-size: .92rem; }
@keyframes toast-in { from { opacity: 0; transform: translateY(16px) scale(.96); } to { opacity: 1; transform: none; } }
@keyframes toast-out { from { opacity: 1; transform: none; } to { opacity: 0; transform: translateY(12px) scale(.96); } }
@media (prefers-reduced-motion: reduce) { .toast, .toast.out { animation-duration: 1ms; } }

/* ---------- Caseta: barra de turno y lista de ingresados ---------- */
.turn { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 14px 18px; }
.entries { max-height: min(46vh, 380px); overflow-y: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.entries ul { list-style: none; margin: 0; padding: 0; }
.entry { display: grid; grid-template-columns: 5.2rem minmax(0, 1fr) auto; align-items: center; gap: 10px; padding: 9px 16px;
  border-bottom: 1px solid var(--line); font-size: .92rem; }
.entry:last-child { border-bottom: 0; }
.entry-time { font-variant-numeric: tabular-nums; color: var(--muted); }
.entry-main { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-main .muted { font-size: .85rem; margin-left: 6px; }
.entry-guard { font-size: .82rem; white-space: nowrap; }
@media (max-width: 520px) { .entry { grid-template-columns: 4.6rem minmax(0, 1fr); } .entry-guard { display: none; } }

/* "Registrar ingreso": pop de escala + check que se dibuja antes de que la tarjeta desaparezca de la lista. */
.checkin-btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; transition: transform 160ms ease; }
.checkin-btn.pop { transform: scale(1.05); }
.checkin-btn svg { width: 18px; height: 18px; flex: none; }
.checkin-btn svg path { fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round;
  stroke-dasharray: 1; stroke-dashoffset: 1; transition: stroke-dashoffset 260ms ease 100ms; }
.checkin-btn.done svg path { stroke-dashoffset: 0; }
@media (prefers-reduced-motion: reduce) { .checkin-btn, .checkin-btn svg path { transition: none; } }

/* ---------- Admin: pestañas y vistas ---------- */
.tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--line); scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.tabs::-webkit-scrollbar { display: none; }
.tab { flex: none; border: 0; background: none; border-radius: 0; padding: 12px 16px; min-height: 44px; color: var(--muted); font-weight: 600;
  border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab:hover:not(:disabled) { color: var(--fg); border-color: transparent transparent var(--line); }
.tab.on { color: var(--fg); border-bottom-color: var(--accent); }
#view { display: grid; gap: 16px; align-content: start; padding-top: 4px; }
.view { display: grid; gap: 14px; }
.view-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.range { align-items: end; }
.range .quick { align-self: end; flex-wrap: wrap; }
.on-duty ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
@media (max-width: 720px) {
  .view-head .btn { width: 100%; }
  .range .quick { grid-column: 1 / -1; }
}
td.nowrap { white-space: nowrap; }

/* ---------- Ritmo vertical: aire consistente entre títulos, textos y elementos ----------
   Regla de la casa: título → contenido 14px; título → su subtítulo 6px; bloque → bloque 16–24px.
   Todo contenedor con título es una rejilla con `gap`, así nada queda pegado ni se desordena al agregar elementos. */
main section, main > div:not([class]), .view { display: grid; gap: 14px; align-content: start; }
main > section { margin-top: 6px; }
#view { gap: 18px; }
/* El subtítulo se acerca a su título (compensa el gap del contenedor) */
h1 + .muted, h2 + .muted, h3 + .muted { margin-top: -8px; }
dialog.modal h2 + p { margin-top: -4px; }
label { gap: 8px; }
.weekdays legend { margin-bottom: 8px; }
.card h2 { margin-bottom: 0; }
.card p + p, .gate-card p + p { margin-top: 2px; }
/* Textos legales: párrafos y listas con aire */
.legal section { gap: 10px; }
.legal h2 { margin-top: 12px; }
.legal li + li { margin-top: 6px; }
.legal ul { margin: 0; padding-left: 20px; }

/* Visitas archivadas del residente */
.archived summary { cursor: pointer; font-weight: 600; padding: 10px 0; }
.archived .cards { margin-top: 12px; opacity: .9; }

/* Plataforma: links compartibles de cada colonia */
.links { display: grid; gap: 10px; }
.linkrow { display: grid; grid-template-columns: 8rem minmax(0, 1fr) auto; align-items: center; gap: 12px; }
.linkrow .url { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 560px) { .linkrow { grid-template-columns: minmax(0, 1fr) auto; } .linkrow > span { grid-column: 1 / -1; margin-bottom: -6px; } }

/* Plataforma: panel de una colonia y casilla de opción */
dialog.panel { font: 16px/1.5 'General Sans', system-ui, -apple-system, sans-serif; width: min(94vw, 600px); max-height: min(88vh, 720px); padding: 0;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); color: var(--fg); box-shadow: var(--shadow-lift);
  overflow: hidden; animation: fade-in 160ms ease; }
dialog.panel[open] { display: grid; grid-template-rows: auto minmax(0, 1fr); }
dialog.panel::backdrop { background: rgba(20, 20, 19, .45); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; padding: 18px 20px 6px; }
.panel-head .ghost { padding: 6px; }
.panel-head .ico { margin: 0; }
.panel-body { overflow-y: auto; padding: 8px 20px 22px; display: grid; gap: 16px; align-content: start; }
label.check { display: flex; align-items: center; gap: 10px; font-weight: 500; }
label.check input { width: auto; }
@media (prefers-reduced-motion: reduce) { dialog.panel { animation: none; } }
.only-sm { display: none; font-size: .85rem; }
@media (max-width: 560px) { .col-sec { display: none; } .only-sm { display: block; } .table-scroll table { min-width: 0; } }

/* Accesibilidad: texto solo para lectores de pantalla, objetivos táctiles de 44px y casillas legibles */
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.foot-links a, .foot-brand { padding: 10px 6px; }
label.check input, .weekdays input { width: 20px; height: 20px; flex: none; }
dialog.modal label .muted { font-weight: 500; }
