/* =====================================================================
   app.css — PWA del residente · Microjack "navy modernizado"
   Tokens → cascarón (topbar/bottom-nav) → componentes → utilidades
   Modo oscuro automático (prefers-color-scheme). Sin emojis: iconos SVG.
   ===================================================================== */

:root {
  --navy-900: #0d2c4f;
  --navy-800: #12386a;
  --navy-700: #1a4a8a;
  --navy-600: #2359a5;
  --navy-500: #2f6bb8;
  --navy-100: #e7eef9;
  --navy-50:  #f3f7fd;

  --green: #16a34a;  --green-bg: #e8f7ee;
  --amber: #d97706;  --amber-bg: #fff4e0;
  --red:   #dc2626;  --red-bg:   #fdecec;
  --slate: #64748b;  --slate-bg: #eef1f5;
  --whatsapp: #25d366;

  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-2: #f6f8fb;
  --border: #e4e8ef;
  --text: #0f172a;
  --text-2: #475569;
  --text-3: #7c8797;
  --primary: var(--navy-700);
  --focus: rgba(26, 74, 138, .16);

  --radius: 16px;
  --radius-sm: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 10px 24px -14px rgba(15, 23, 42, .22);
  --topbar-h: 64px;
  --nav-h: 64px;
  --maxw: 560px;
  --font: 'Poppins', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220;
    --surface: #121b2d;
    --surface-2: #182339;
    --border: #243149;
    --text: #e8edf5;
    --text-2: #b6c2d4;
    --text-3: #8391a8;
    --primary: #6b9be6;
    --focus: rgba(107, 155, 230, .22);
    --navy-100: #1c2c49;
    --navy-50: #162238;
    --green-bg: rgba(22, 163, 74, .18);
    --amber-bg: rgba(217, 119, 6, .18);
    --red-bg: rgba(220, 38, 38, .18);
    --slate-bg: rgba(100, 116, 139, .2);
    --green: #34c26a; --amber: #f0a23c; --red: #f06565; --slate: #9aa8bd;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 24px -14px rgba(0, 0, 0, .7);
  }
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; background: var(--bg); overscroll-behavior-y: none; }
body.app {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;   /* iOS: sin rebote elástico que deja ver fondo blanco tras la barra */
}
body.app.no-nav { padding-bottom: env(safe-area-inset-bottom, 0px); }
a { color: var(--primary); }
img { max-width: 100%; display: block; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; line-height: 1.25; }
p { margin: 0; }
.ico { width: 1.25em; height: 1.25em; flex: none; }
.ico-xs { width: 1em; height: 1em; }
.ico-lg { width: 1.75em; height: 1.75em; }
.ico-xl { width: 2.5em; height: 2.5em; }

/* ---------- topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  background: linear-gradient(135deg, var(--navy-900), var(--navy-700));
  color: #fff;
  padding-top: env(safe-area-inset-top, 0px);
  box-shadow: 0 6px 20px -10px rgba(13, 44, 79, .6);
}
.topbar__inner {
  max-width: var(--maxw); margin: 0 auto; min-height: var(--topbar-h);
  display: flex; align-items: center; gap: 10px; padding: 8px 16px;
}
.topbar__brand { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.topbar__kicker { font-size: .74rem; opacity: .78; font-weight: 500; letter-spacing: .02em; }
.topbar__name { font-size: 1.05rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar__title { font-size: 1.08rem; font-weight: 600; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar__actions { margin-left: auto; display: flex; gap: 6px; align-items: center; }
.iconbtn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: 12px; border: 0;
  background: rgba(255, 255, 255, .14); color: #fff; text-decoration: none; cursor: pointer; flex: none;
  transition: background .15s;
}
.iconbtn:hover { background: rgba(255, 255, 255, .24); }
.iconbtn--surface { background: var(--surface-2); color: var(--text-2); }

/* ---------- contenido ---------- */
.content {
  max-width: var(--maxw); margin: 0 auto;
  padding: 16px 16px 28px;
  display: flex; flex-direction: column; gap: 16px;
}
.section-title {
  display: flex; align-items: center; justify-content: space-between;
  margin: 6px 0 -6px; font-size: .95rem; font-weight: 600; color: var(--text-2);
}
.section-title a { font-size: .84rem; font-weight: 500; text-decoration: none; }

/* ---------- tarjetas ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card--pad { padding: 16px; }
.card__title { font-size: 1rem; font-weight: 600; margin-bottom: 2px; }
.card__sub { color: var(--text-3); font-size: .85rem; }

/* ---------- inicio ---------- */
.hero { padding: 18px 16px; display: flex; flex-direction: column; gap: 14px; }
.hero__dom { display: flex; align-items: center; gap: 8px; color: var(--text-2); font-size: .9rem; }
.hero__dom .ico { color: var(--primary); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--surface-2); border-radius: 12px; padding: 10px 8px; text-align: center; }
.stat__num { font-size: 1.45rem; font-weight: 700; line-height: 1.1; }
.stat__label { font-size: .7rem; color: var(--text-3); font-weight: 500; margin-top: 3px; }
.stat--live .stat__num { color: var(--green); }
.stat--warn .stat__num { color: var(--amber); }

.anuncio { display: flex; gap: 12px; padding: 14px 16px; border-left: 4px solid var(--amber); }
.anuncio > .ico { color: var(--amber); margin-top: 2px; }
.anuncio__kicker { font-size: .7rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--amber); margin-bottom: 3px; }
.anuncio p { font-size: .9rem; line-height: 1.5; }
.anuncio img { border-radius: 10px; margin-top: 6px; }

/* ---------- listas ---------- */
.list { display: flex; flex-direction: column; gap: 10px; }
.item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; text-decoration: none; color: inherit; transition: transform .1s; }
a.item:active { transform: scale(.992); }
.avatar {
  width: 44px; height: 44px; border-radius: 14px; flex: none;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: .95rem; background: var(--navy-100); color: var(--navy-700);
}
.avatar .ico { width: 22px; height: 22px; }
.avatar--ingresado { background: var(--green-bg); color: var(--green); }
.avatar--pendiente  { background: var(--amber-bg); color: var(--amber); }
.avatar--finalizado { background: var(--slate-bg); color: var(--slate); }
.avatar--expirado   { background: var(--red-bg);   color: var(--red); }
.item__body { flex: 1; min-width: 0; }
.item__title { font-weight: 600; font-size: .95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item__meta { font-size: .8rem; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.item__right { display: flex; flex-direction: column; align-items: flex-end; gap: 5px; flex: none; }
.item__time { font-size: .72rem; color: var(--text-3); }
.item > .chev { color: var(--text-3); }

/* ---------- chips ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px;
  border-radius: 999px; font-size: .72rem; font-weight: 600; line-height: 1.4; white-space: nowrap;
}
.chip--pendiente  { background: var(--amber-bg); color: var(--amber); }
.chip--ingresado  { background: var(--green-bg); color: var(--green); }
.chip--finalizado { background: var(--slate-bg); color: var(--slate); }
.chip--expirado   { background: var(--red-bg);   color: var(--red); }
.chip--info       { background: var(--navy-100); color: var(--navy-700); }
.chip--live::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; animation: pulse 1.6s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .25; } }

/* ---------- vacío ---------- */
.empty { text-align: center; padding: 30px 16px; color: var(--text-3); }
.empty .ico { width: 44px; height: 44px; margin: 0 auto 10px; }
.empty h3 { font-size: 1rem; color: var(--text); margin-bottom: 4px; }
.empty p { font-size: .88rem; }

/* ---------- formularios ---------- */
.form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.label { font-size: .82rem; font-weight: 600; color: var(--text-2); }
.input, .select, .textarea {
  width: 100%; font: inherit; font-size: 16px; padding: 12px 14px; min-height: 50px;
  border-radius: var(--radius-sm); border: 1.5px solid var(--border);
  background: var(--surface); color: var(--text);
  transition: border-color .15s, box-shadow .15s; -webkit-appearance: none; appearance: none;
}
.textarea { min-height: 90px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px var(--focus); }
.input--upper { text-transform: uppercase; }
.input::placeholder { color: var(--text-3); text-transform: none; }
.select {
  padding-right: 42px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%237c8797' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='m6 9 6 6 6-6'/></svg>");
  background-repeat: no-repeat; background-position: right 12px center;
}
.help { font-size: .78rem; color: var(--text-3); }
.field--error .input { border-color: var(--red); }
.error-text { color: var(--red); font-size: .8rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.readonly-field { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-radius: var(--radius-sm); background: var(--surface-2); color: var(--text-2); font-size: .95rem; }
.readonly-field .ico { color: var(--primary); }

.segmented { position: relative; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 4px; background: var(--surface-2); border-radius: 14px; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label {
  display: flex; align-items: center; justify-content: center; gap: 8px; padding: 12px 8px;
  border-radius: 11px; font-weight: 600; font-size: .9rem; color: var(--text-3); cursor: pointer; user-select: none;
  transition: background .15s, color .15s;
}
.segmented input:checked + label { background: var(--surface); color: var(--navy-700); box-shadow: var(--shadow); }
@media (prefers-color-scheme: dark) { .segmented input:checked + label { color: var(--primary); } }

/* ---------- botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 50px; padding: 0 18px; border-radius: var(--radius-sm);
  border: 1.5px solid transparent; font: inherit; font-size: .95rem; font-weight: 600;
  cursor: pointer; text-decoration: none; user-select: none; white-space: nowrap;
  transition: transform .1s, background .15s, box-shadow .15s, opacity .15s;
}
.btn:active { transform: scale(.98); }
.btn[disabled], .btn.is-loading { opacity: .6; cursor: not-allowed; pointer-events: none; }
.btn--primary { background: linear-gradient(135deg, var(--navy-700), var(--navy-900)); color: #fff; box-shadow: 0 10px 22px -10px rgba(13, 44, 79, .7); }
.btn--secondary { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn--ghost { background: transparent; color: var(--primary); }
.btn--danger { background: var(--red-bg); color: var(--red); }
.btn--whatsapp { background: var(--whatsapp); color: #fff; box-shadow: 0 10px 22px -10px rgba(37, 211, 102, .7); }
.btn--block { width: 100%; }
.btn--xl { min-height: 58px; font-size: 1.05rem; border-radius: 16px; }
.btn--sm { min-height: 38px; padding: 0 12px; font-size: .84rem; border-radius: 10px; }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }

/* ---------- pase / QR ---------- */
.qr-card {
  background: #fff; color: #0f172a; border-radius: var(--radius); padding: 18px 16px 16px;
  text-align: center; border: 1px solid var(--border); box-shadow: var(--shadow);
}
.qr-card__img { width: min(74vw, 300px); height: auto; margin: 4px auto 6px; image-rendering: pixelated; border-radius: 8px; }
.qr-card__name { font-weight: 700; font-size: 1.1rem; margin-top: 4px; }
.qr-card__sub { color: #64748b; font-size: .85rem; margin-top: 2px; }
.qr-card__validity {
  margin-top: 12px; display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px;
  border-radius: 999px; background: #eef1f5; color: #475569; font-size: .8rem; font-weight: 500;
}
.status-banner { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-radius: var(--radius); }
.status-banner > .ico { flex: none; width: 28px; height: 28px; }
.status-banner--pendiente  { background: var(--amber-bg); color: var(--amber); }
.status-banner--ingresado  { background: var(--green-bg); color: var(--green); }
.status-banner--finalizado { background: var(--slate-bg); color: var(--slate); }
.status-banner--expirado   { background: var(--red-bg);   color: var(--red); }
.status-banner strong { display: block; font-size: .95rem; }
.status-banner span { font-size: .82rem; opacity: .9; }

/* ---------- línea de tiempo ---------- */
.timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.tl { display: flex; gap: 12px; padding-bottom: 18px; position: relative; }
.tl::before { content: ""; position: absolute; left: 11px; top: 26px; bottom: 0; width: 2px; background: var(--border); }
.tl:last-child { padding-bottom: 0; }
.tl:last-child::before { display: none; }
.tl__dot {
  width: 24px; height: 24px; border-radius: 50%; flex: none; display: flex; align-items: center; justify-content: center;
  background: var(--surface-2); color: var(--text-3); border: 2px solid var(--border);
}
.tl__dot .ico { width: 13px; height: 13px; }
.tl--done .tl__dot { background: var(--green); border-color: var(--green); color: #fff; }
.tl--current .tl__dot { background: var(--navy-700); border-color: var(--navy-700); color: #fff; }
.tl--off .tl__dot { background: var(--red-bg); border-color: var(--red-bg); color: var(--red); }
.tl__title { font-weight: 600; font-size: .92rem; }
.tl__sub { font-size: .8rem; color: var(--text-3); }

/* ---------- evidencia ---------- */
.evidence { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.evidence figure { margin: 0; }
.evidence img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 12px; border: 1px solid var(--border); background: var(--surface-2); }
.evidence figcaption { font-size: .75rem; color: var(--text-3); margin-top: 5px; text-align: center; }
.evidence__ph { aspect-ratio: 4 / 3; border-radius: 12px; background: var(--surface-2); display: flex; align-items: center; justify-content: center; color: var(--text-3); border: 1px dashed var(--border); }

/* ---------- ajustes / toggles ---------- */
.toggle { position: relative; width: 48px; height: 28px; flex: none; }
.toggle input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.toggle span { position: absolute; inset: 0; border-radius: 999px; background: var(--border); transition: background .2s; }
.toggle span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: transform .2s; }
.toggle input:checked + span { background: var(--green); }
.toggle input:checked + span::after { transform: translateX(20px); }
.toggle input:disabled + span { opacity: .45; }
.setting { display: flex; align-items: center; gap: 12px; padding: 14px 16px; text-decoration: none; color: inherit; border-top: 1px solid var(--border); }
.setting:first-child { border-top: 0; }
.setting > .ico { color: var(--primary); }
.setting__body { flex: 1; min-width: 0; }
.setting__title { font-weight: 600; font-size: .92rem; }
.setting__sub { font-size: .78rem; color: var(--text-3); margin-top: 1px; }
.setting--danger > .ico, .setting--danger .setting__title { color: var(--red); }

/* ---------- barra inferior ---------- */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  display: flex; justify-content: center;
}
.bottom-nav__item {
  flex: 1; max-width: 140px; height: var(--nav-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  text-decoration: none; color: var(--text-3); font-size: .68rem; font-weight: 600; position: relative;
}
.bottom-nav__item .ico { width: 24px; height: 24px; }
.bottom-nav__item.is-active { color: var(--primary); }
.bottom-nav__item.is-active::before { content: ""; position: absolute; top: 0; width: 28px; height: 3px; border-radius: 0 0 3px 3px; background: var(--primary); }

/* ---------- toast ---------- */
.toast-area {
  position: fixed; left: 0; right: 0; bottom: calc(var(--nav-h) + 12px + env(safe-area-inset-bottom, 0px));
  display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 60; pointer-events: none; padding: 0 16px;
}
body.no-nav .toast-area { bottom: calc(16px + env(safe-area-inset-bottom, 0px)); }
.toast { pointer-events: auto; background: #0f172a; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: .88rem; box-shadow: 0 10px 30px rgba(0, 0, 0, .3); max-width: var(--maxw); animation: fadeUp .25s ease; }
.toast--ok { background: var(--green); }
.toast--error { background: var(--red); }
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- hoja inferior ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, .55); z-index: 70; display: none; }
.sheet-backdrop.is-open { display: block; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 71; max-width: var(--maxw); margin: 0 auto;
  background: var(--surface); color: var(--text); border-radius: 20px 20px 0 0;
  padding: 14px 20px calc(20px + env(safe-area-inset-bottom, 0px));
  transform: translateY(105%); transition: transform .25s ease; box-shadow: 0 -10px 40px rgba(0, 0, 0, .25);
}
.sheet.is-open { transform: none; }
.sheet__handle { width: 40px; height: 4px; border-radius: 2px; background: var(--border); margin: 0 auto 12px; }
.sheet h3 { font-size: 1.05rem; margin-bottom: 6px; }
.sheet ol { padding-left: 20px; margin: 8px 0 14px; font-size: .9rem; line-height: 1.6; color: var(--text-2); }
.sheet p { font-size: .88rem; color: var(--text-2); }

/* ---------- banner instalar ---------- */
.banner { display: flex; align-items: center; gap: 12px; padding: 12px 14px; }
.banner > .ico { color: var(--primary); }
.banner__body { flex: 1; min-width: 0; }
.banner strong { display: block; font-size: .9rem; }
.banner small { color: var(--text-3); font-size: .78rem; }

/* ---------- login / auth ---------- */
body.auth {
  margin: 0; font-family: var(--font); min-height: 100dvh; color: var(--text);
  background: linear-gradient(160deg, var(--navy-900) 0%, var(--navy-700) 55%, var(--navy-500) 100%);
  display: flex; align-items: center; justify-content: center;
  padding: 24px 16px calc(24px + env(safe-area-inset-bottom, 0px));
  -webkit-font-smoothing: antialiased;
}
body.auth::before { content: ""; position: fixed; inset: 0; pointer-events: none;
  background: radial-gradient(circle at 15% 15%, rgba(255, 255, 255, .09), transparent 40%), radial-gradient(circle at 85% 85%, rgba(255, 255, 255, .06), transparent 45%); }
.auth-card {
  position: relative; width: 100%; max-width: 400px; background: var(--surface);
  border-radius: 22px; padding: 28px 22px 22px; box-shadow: 0 30px 60px -20px rgba(0, 0, 0, .55);
  animation: fadeUp .4s ease;
}
.auth-logo { margin: 0 auto 12px; max-width: 150px; height: auto; }
.solo-oscuro { display: none; }
@media (prefers-color-scheme: dark) { .solo-claro { display: none; } .solo-oscuro { display: block; } }
.auth-card h1 { text-align: center; font-size: 1.3rem; }
.auth-card .lead { margin: 4px 0 20px; text-align: center; color: var(--text-3); font-size: .9rem; }
.input-icon { position: relative; }
.input-icon > .ico { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }
.input-icon .input { padding-left: 44px; }
.input-icon .toggle-pass {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%); background: none; border: 0;
  color: var(--text-3); width: 38px; height: 38px; border-radius: 10px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 12px; font-size: .88rem; line-height: 1.45; }
.alert > .ico { flex: none; margin-top: 1px; }
.alert--error { background: var(--red-bg); color: var(--red); }
.alert--ok { background: var(--green-bg); color: var(--green); }
.alert--info { background: var(--navy-100); color: var(--navy-700); }
@media (prefers-color-scheme: dark) { .alert--info { color: var(--primary); } }
.auth-foot { margin-top: 18px; text-align: center; font-size: .76rem; color: var(--text-3); }
.auth-links { display: flex; justify-content: center; gap: 16px; margin-top: 14px; font-size: .82rem; }
.auth-links a { text-decoration: none; display: inline-flex; align-items: center; gap: 4px; }

/* ---------- utilidades ---------- */
.muted { color: var(--text-3); }
.small { font-size: .82rem; }
.row { display: flex; align-items: center; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.center { text-align: center; }
.hidden { display: none !important; }
.countdown { font-variant-numeric: tabular-nums; }
.divider { height: 1px; background: var(--border); margin: 4px 0; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
@media (display-mode: standalone) { .pwa-only-browser { display: none !important; } }
