/* Estilo iOS (Liquid Glass) — tipografía del sistema, listas agrupadas, vidrio translúcido */
:root {
  --bg: #f2f2f7;
  --bg2: #ffffff;
  --bg3: #f2f2f7;
  --label: #000000;
  --label2: rgba(60, 60, 67, 0.6);
  --label3: rgba(60, 60, 67, 0.3);
  --sep: rgba(60, 60, 67, 0.18);
  --fill: rgba(120, 120, 128, 0.12);
  --fill2: rgba(120, 120, 128, 0.2);
  --blue: #007aff;
  --green: #34c759;
  --green-ink: #248a3d;
  --red: #ff3b30;
  --orange: #ff9500;
  --yellow: #ffcc00;
  --indigo: #5856d6;
  --teal: #30b0c7;
  --gray: #8e8e93;
  --glass: rgba(255, 255, 255, 0.62);
  --glass-strong: rgba(255, 255, 255, 0.78);
  --glass-border: rgba(255, 255, 255, 0.7);
  --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.06);
  --radius: 26px;
  --radius-sm: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --bg2: #1c1c1e;
    --bg3: #2c2c2e;
    --label: #ffffff;
    --label2: rgba(235, 235, 245, 0.6);
    --label3: rgba(235, 235, 245, 0.3);
    --sep: rgba(84, 84, 88, 0.6);
    --fill: rgba(120, 120, 128, 0.24);
    --fill2: rgba(120, 120, 128, 0.32);
    --blue: #0a84ff;
    --green: #30d158;
    --green-ink: #30d158;
    --red: #ff453a;
    --orange: #ff9f0a;
    --indigo: #5e5ce6;
    --teal: #40c8e0;
    --glass: rgba(40, 40, 44, 0.55);
    --glass-strong: rgba(44, 44, 48, 0.78);
    --glass-border: rgba(255, 255, 255, 0.12);
    --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Helvetica Neue", "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--label);
  font-size: 17px;
  line-height: 1.35;
  letter-spacing: -0.41px;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  min-height: 100dvh;
}
button, input, select, textarea { font: inherit; color: inherit; letter-spacing: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
a { color: var(--blue); text-decoration: none; }
[hidden] { display: none !important; }
.sf-icon { width: 1em; height: 1em; display: inline-block; vertical-align: -0.125em; flex: none; }

/* ---------- Glass ---------- */
.glass {
  background: var(--glass);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  backdrop-filter: blur(24px) saturate(180%);
  border: 0.5px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
}

/* ---------- Barra de navegación ---------- */
.nav {
  position: sticky; top: 0; z-index: 30;
  padding: calc(var(--safe-t) + 8px) 16px 8px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  min-height: 52px;
  transition: background .2s, border-color .2s;
  border-bottom: 0.5px solid transparent;
}
.nav.scrolled {
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  backdrop-filter: blur(20px) saturate(180%);
  border-bottom-color: var(--sep);
}
.nav-title { font-weight: 600; font-size: 17px; opacity: 0; transition: opacity .2s; position: absolute; left: 50%; transform: translateX(-50%); white-space: nowrap; pointer-events: none; }
.nav.scrolled .nav-title { opacity: 1; }
.nav-actions { display: flex; gap: 8px; align-items: center; margin-left: auto; }
.circle-btn {
  width: 44px; height: 44px; border-radius: 50%;
  display: inline-grid; place-items: center; font-size: 19px; color: var(--label);
}
.circle-btn.tint { color: #fff; background: var(--blue); box-shadow: 0 4px 14px color-mix(in srgb, var(--blue) 40%, transparent); }
.pill-btn {
  height: 44px; padding: 0 18px; border-radius: 22px;
  display: inline-flex; align-items: center; gap: 6px; font-weight: 500;
}

.large-title { font-size: 34px; font-weight: 700; letter-spacing: 0.37px; margin: 2px 20px 10px; line-height: 1.15; }
.subtitle { color: var(--label2); font-size: 15px; margin: -6px 20px 14px; }

/* ---------- Contenedor ---------- */
.content { max-width: 760px; margin: 0 auto; padding-bottom: calc(110px + var(--safe-b)); }

/* ---------- Listas agrupadas (inset grouped) ---------- */
.section { margin: 0 16px 28px; }
.section-header { font-size: 13px; text-transform: uppercase; color: var(--label2); margin: 0 20px 7px; letter-spacing: -0.08px; display: flex; justify-content: space-between; align-items: baseline; }
.section-header .action { text-transform: none; font-size: 15px; color: var(--blue); }
.section-header.big { text-transform: none; font-size: 22px; font-weight: 700; color: var(--label); letter-spacing: 0.35px; margin-left: 4px; margin-bottom: 10px; }
.section-footer { font-size: 13px; color: var(--label2); margin: 7px 20px 0; line-height: 1.4; }
.list { background: var(--bg2); border-radius: var(--radius); overflow: hidden; }
.row {
  display: flex; align-items: center; gap: 12px;
  min-height: 52px; padding: 11px 16px; position: relative;
  width: 100%; text-align: left;
}
.row + .row::before, .row + .field::before, .field + .row::before, .field + .field::before {
  content: ""; position: absolute; top: 0; right: 0; left: var(--inset, 16px); height: 0.5px; background: var(--sep);
}
button.row:active, a.row:active, .row.tap:active { background: var(--fill2); }
.row-icon {
  width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center;
  color: #fff; font-size: 16px; flex: none;
}
.row-body { flex: 1; min-width: 0; }
.row-title { font-size: 17px; line-height: 1.25; }
.row-sub { font-size: 15px; color: var(--label2); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-value { color: var(--label2); font-size: 17px; white-space: nowrap; }
.chev { color: var(--label3); font-size: 14px; }
.row.destructive { color: var(--red); justify-content: center; }
.row.center { justify-content: center; color: var(--blue); }
.row.with-icon { --inset: 58px; }
.list .row.with-icon + .row.with-icon::before { left: 58px; }

/* Campos */
.field { display: flex; align-items: center; padding: 0 16px; min-height: 52px; position: relative; gap: 12px; }
.field label { width: 110px; flex: none; font-size: 17px; }
.field input, .field select {
  flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; padding: 14px 0; font-size: 17px; text-align: right;
}
.field input::placeholder { color: var(--label3); }
.field.stacked { flex-direction: column; align-items: stretch; padding: 10px 16px 6px; gap: 2px; }
.field.stacked label { width: auto; font-size: 13px; color: var(--label2); text-transform: uppercase; letter-spacing: -0.08px; }
.field.stacked input { text-align: left; padding: 6px 0 8px; font-size: 19px; }
.field select { -webkit-appearance: none; appearance: none; color: var(--label2); text-align: right; text-align-last: right; cursor: pointer; }
.field .hint { font-size: 13px; color: var(--label2); }
.field.invalid label { color: var(--red); }

/* ---------- Botones ---------- */
.btn {
  height: 50px; padding: 0 22px; border-radius: 25px; font-weight: 600; font-size: 17px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform .12s, opacity .15s, filter .15s;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; pointer-events: none; }
.btn.filled { background: var(--blue); color: #fff; }
.btn.tinted { background: color-mix(in srgb, var(--blue) 15%, transparent); color: var(--blue); }
.btn.gray { background: var(--fill); color: var(--label); }
.btn.green { background: var(--green); color: #fff; }
.btn.danger { background: color-mix(in srgb, var(--red) 14%, transparent); color: var(--red); }
.btn.block { width: 100%; }
.btn.sm { height: 34px; padding: 0 14px; font-size: 15px; border-radius: 17px; }

/* ---------- Segmented control ---------- */
.segmented {
  display: flex; background: var(--fill); border-radius: 100px; padding: 3px; position: relative; margin: 0 16px 16px;
}
.segmented button {
  flex: 1; height: 34px; border-radius: 100px; font-size: 14px; font-weight: 500; color: var(--label);
  position: relative; z-index: 1; transition: color .2s;
}
.segmented button.on { background: var(--bg2); box-shadow: 0 3px 8px rgba(0,0,0,.12), 0 0 0 0.5px rgba(0,0,0,.04); font-weight: 600; }
@media (prefers-color-scheme: dark) { .segmented button.on { background: #636366; } }
/* Muchas opciones: se deslizan en lugar de apretarse */
.segmented.scroll { overflow-x: auto; scrollbar-width: none; }
.segmented.scroll::-webkit-scrollbar { display: none; }
.segmented.scroll button { flex: 1 0 auto; padding: 0 14px; white-space: nowrap; }

/* ---------- Búsqueda ---------- */
.search {
  display: flex; align-items: center; gap: 6px; margin: 0 16px 14px; padding: 0 12px;
  height: 40px; border-radius: 20px; background: var(--fill); color: var(--label2);
}
.search input { flex: 1; border: 0; outline: 0; background: transparent; font-size: 17px; color: var(--label); }
.search input::placeholder { color: var(--label2); }

/* ---------- Insignias ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px; height: 24px; padding: 0 10px; border-radius: 12px;
  font-size: 13px; font-weight: 600; white-space: nowrap;
}
.badge.pendiente { background: color-mix(in srgb, var(--blue) 14%, transparent); color: var(--blue); }
.badge.en_curso { background: color-mix(in srgb, var(--orange) 16%, transparent); color: var(--orange); }
.badge.contestado { background: color-mix(in srgb, var(--green) 16%, transparent); color: var(--green-ink); }
.badge.revocado, .badge.expirado { background: var(--fill); color: var(--label2); }
.badge.ok { background: color-mix(in srgb, var(--green) 16%, transparent); color: var(--green-ink); }
.badge.bad { background: color-mix(in srgb, var(--red) 14%, transparent); color: var(--red); }

.score-chip {
  min-width: 52px; height: 32px; border-radius: 16px; display: inline-grid; place-items: center;
  font-weight: 700; font-size: 16px; font-variant-numeric: tabular-nums; padding: 0 10px;
}
.score-chip.ok { background: color-mix(in srgb, var(--green) 16%, transparent); color: var(--green-ink); }
.score-chip.bad { background: color-mix(in srgb, var(--red) 14%, transparent); color: var(--red); }

/* ---------- Widgets (resumen) ---------- */
.widgets { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin: 0 16px 28px; }
.widget { background: var(--bg2); border-radius: 22px; padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 6px; min-height: 108px; }
.widget .w-top { display: flex; align-items: center; gap: 8px; font-size: 15px; font-weight: 600; }
.widget .w-dot { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-size: 14px; }
.widget .w-val { font-size: 34px; font-weight: 700; letter-spacing: 0.3px; font-variant-numeric: tabular-nums; margin-top: auto; line-height: 1; }
.widget .w-sub { font-size: 13px; color: var(--label2); }
button.widget { text-align: left; color: inherit; font: inherit; width: 100%; }
button.widget:active { transform: scale(0.97); }
.widget .chev { color: var(--label3); font-size: 14px; }
@media (min-width: 640px) { .widgets { grid-template-columns: repeat(4, 1fr); } }

.ring { --p: 0; width: 64px; height: 64px; border-radius: 50%;
  background: conic-gradient(var(--green) calc(var(--p) * 1%), var(--fill) 0);
  display: grid; place-items: center; flex: none; }
.ring::after { content: attr(data-label); width: 50px; height: 50px; border-radius: 50%; background: var(--bg2); display: grid; place-items: center; font-weight: 700; font-size: 15px; }

.ring.lg { width: 110px; height: 110px; margin: 0 auto 14px; }
.ring.lg::after { width: 92px; height: 92px; font-size: 32px; background: var(--bg); font-variant-numeric: tabular-nums; }

/* ---------- Tab bar flotante (Liquid Glass) ---------- */
.tabbar {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(12px + var(--safe-b)); z-index: 40;
  display: flex; gap: 2px; padding: 4px; border-radius: 34px;
}
.tabbar button {
  /* 5 pestañas: se ajustan al ancho del teléfono sin pasar de 92px */
  width: clamp(58px, calc((100vw - 44px) / 5), 92px); height: 56px; border-radius: 28px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 10.5px; font-weight: 600; color: var(--label); letter-spacing: 0;
  transition: background .2s, color .2s;
}
.tabbar button .sf-icon { font-size: 23px; }
.tabbar button.on { color: var(--blue); background: var(--fill); }

/* Escritorio: barra lateral tipo iPadOS */
@media (min-width: 1000px) {
  .app { display: grid; grid-template-columns: 300px 1fr; min-height: 100vh; }
  .tabbar {
    position: sticky; top: 0; left: auto; bottom: auto; transform: none; height: 100vh; border-radius: 0; flex-direction: column;
    padding: 24px 14px; gap: 4px; background: var(--bg2); box-shadow: none; border: 0; border-right: 0.5px solid var(--sep);
    -webkit-backdrop-filter: none; backdrop-filter: none;
  }
  .tabbar .side-brand { display: block; }
  .tabbar button { width: 100%; height: 44px; flex-direction: row; justify-content: flex-start; gap: 12px; padding: 0 14px; font-size: 17px; font-weight: 500; border-radius: 12px; }
  .tabbar button .sf-icon { font-size: 20px; color: var(--blue); }
  .tabbar button.on { background: var(--blue); color: #fff; }
  .tabbar button.on .sf-icon { color: #fff; }
  .tabbar .side-foot { display: block; margin-top: auto; }
  .content { padding-bottom: 40px; }
}
.side-brand, .side-foot { display: none; }
.side-user { display: flex; align-items: center; gap: 10px; padding: 8px 14px; font-size: 15px; font-weight: 600; color: var(--label2); font-family: ui-monospace, "SF Mono", Menlo, monospace; }
.side-brand { padding: 14px 8px 20px; }
.side-brand img { display: block; width: 100%; max-width: 200px; height: auto; }
/* Ícono de la marca (app-icon.svg ya trae su forma redondeada) */
.brand-icon { display: block; filter: drop-shadow(0 10px 22px rgba(20, 184, 166, .28)); }

/* ---------- Hoja modal (sheet) ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 60; background: rgba(0, 0, 0, 0.32);
  opacity: 0; transition: opacity .3s; display: flex; align-items: flex-end; justify-content: center;
}
.sheet-backdrop.open { opacity: 1; }
.sheet {
  width: 100%; max-width: 640px; max-height: 92dvh; overflow: auto; background: var(--bg);
  border-radius: 34px 34px 0 0; padding-bottom: calc(24px + var(--safe-b));
  transform: translateY(100%); transition: transform .42s cubic-bezier(.2, .9, .25, 1);
  overscroll-behavior: contain;
}
.sheet-backdrop.open .sheet { transform: translateY(0); }
.grabber { width: 36px; height: 5px; border-radius: 3px; background: var(--label3); margin: 6px auto 0; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px 6px; position: sticky; top: 0; background: var(--bg); z-index: 2; }
.sheet-head h2 { font-size: 17px; font-weight: 600; margin: 0; position: absolute; left: 50%; transform: translateX(-50%); white-space: nowrap; }
@media (min-width: 700px) {
  .sheet-backdrop { align-items: center; }
  .sheet { border-radius: 34px; max-height: 86vh; transform: translateY(30px) scale(.98); opacity: 0; transition: transform .35s cubic-bezier(.2,.9,.25,1), opacity .25s; }
  .sheet-backdrop.open .sheet { transform: none; opacity: 1; }
  .grabber { display: none; }
}

/* Botonera de compartir */
.share-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 0 16px 24px; }
.share-grid button { display: flex; flex-direction: column; align-items: center; gap: 8px; font-size: 12px; color: var(--label); }
.share-grid .s-ic { width: 60px; height: 60px; border-radius: 16px; display: grid; place-items: center; font-size: 28px; color: #fff; }

.link-box {
  margin: 0 16px 20px; padding: 14px 16px; background: var(--bg2); border-radius: 18px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 14px; word-break: break-all; color: var(--blue);
}

/* ---------- Splash de inicio (motion.js dibuja el logo animado) ---------- */
#splash {
  position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(180deg, #F7FBF8 0%, #F2F2F7 55%, #EEF5FF 100%);
  transition: opacity .45s ease, visibility .45s;
}
#splash.hide { opacity: 0; visibility: hidden; }
@media (prefers-color-scheme: dark) {
  #splash { background: linear-gradient(180deg, #05110A 0%, #000 55%, #020A16 100%); }
}

/* ---------- Bitácora ---------- */
.audit-row { align-items: flex-start; }
.audit-row .row-icon { margin-top: 2px; }
.audit-detail { white-space: normal; line-height: 1.35; overflow-wrap: anywhere; }

/* ---------- Usuarios ---------- */
.avatar { flex: none; width: 38px; height: 38px; border-radius: 50%; display: inline-grid; place-items: center; font-weight: 700; font-size: 14px; color: #fff; background: linear-gradient(135deg, #34C759, #14B8A6 55%, #0A84FF); }
.avatar.lg { width: 72px; height: 72px; font-size: 26px; }

/* ---------- Pasos para instalar como app ---------- */
.install-step { gap: 12px; align-items: center; }
.step-n { flex: none; width: 26px; height: 26px; border-radius: 50%; background: color-mix(in srgb, var(--blue) 15%, transparent); color: var(--blue); font-weight: 700; font-size: 14px; display: grid; place-items: center; }
.step-ic { flex: none; color: var(--blue); font-size: 22px; display: grid; place-items: center; }

/* ---------- Alerta de confirmación ---------- */
.alert-backdrop {
  position: fixed; inset: 0; z-index: 80; background: rgba(0, 0, 0, 0.32);
  display: flex; align-items: center; justify-content: center; padding: 24px;
  opacity: 0; transition: opacity .2s;
}
.alert-backdrop.open { opacity: 1; }
.alert {
  width: 100%; max-width: 300px; border-radius: 22px; overflow: hidden; text-align: center;
  background: var(--glass-strong); -webkit-backdrop-filter: blur(30px) saturate(180%); backdrop-filter: blur(30px) saturate(180%);
  box-shadow: 0 20px 50px rgba(0,0,0,.25);
  transform: scale(1.12); transition: transform .3s cubic-bezier(.2, .9, .25, 1.15);
}
.alert-backdrop.open .alert { transform: scale(1); }
.alert-body { padding: 22px 18px 18px; }
.alert-ic { width: 46px; height: 46px; border-radius: 50%; margin: 0 auto 10px; display: grid; place-items: center; font-size: 24px; color: #fff; background: var(--blue); }
.alert-ic.danger { background: var(--red); }
.alert h3 { font-size: 17px; font-weight: 600; margin: 0 0 4px; }
.alert p { font-size: 14px; color: var(--label2); margin: 0; line-height: 1.4; }
.alert-actions { display: grid; grid-template-columns: 1fr 1fr; border-top: 0.5px solid var(--sep); }
.alert-actions button { height: 46px; font-size: 17px; color: var(--blue); }
.alert-actions button + button { border-left: 0.5px solid var(--sep); }
.alert-actions button.primary { font-weight: 600; }
.alert-actions button.danger { color: var(--red); font-weight: 600; }
.alert-actions button:active, .alert-actions button:focus-visible { background: var(--fill); }
.alert-actions button:focus { outline: none; }

/* ---------- HUD / Toast ---------- */
.toast {
  position: fixed; left: 50%; top: calc(14px + var(--safe-t)); transform: translate(-50%, -140%); z-index: 90;
  padding: 12px 20px; border-radius: 26px; font-weight: 600; font-size: 15px; display: flex; gap: 8px; align-items: center;
  transition: transform .45s cubic-bezier(.2, .9, .25, 1.15);
  background: var(--glass-strong);
}
.toast.show { transform: translate(-50%, 0); }

/* ---------- Estados vacíos ---------- */
.empty { text-align: center; padding: 48px 32px; color: var(--label2); }
.empty .sf-icon { font-size: 54px; color: var(--label3); margin-bottom: 12px; }
.empty h3 { color: var(--label); font-size: 20px; margin: 0 0 6px; }

/* ---------- Varios ---------- */
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 2.5px solid var(--fill2); border-top-color: var(--label2); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.center-screen { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.center-screen > * { width: 100%; }
.muted { color: var(--label2); }
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: 0.5px; }
.fade-in { animation: fadeIn .35s ease both; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.stack { display: flex; flex-direction: column; gap: 10px; }
.hstack { display: flex; gap: 10px; align-items: center; }
.pad { padding: 0 16px; }

/* Detalle de respuestas */
.q-card { background: var(--bg2); border-radius: 22px; padding: 16px; margin: 0 16px 12px; }
.q-card .q-head { display: flex; gap: 10px; justify-content: space-between; align-items: flex-start; margin-bottom: 10px; }
.q-card .q-num { font-size: 13px; color: var(--label2); font-weight: 600; text-transform: uppercase; }
.q-card .q-text { font-size: 16px; font-weight: 600; line-height: 1.35; }
.q-opt { display: flex; gap: 10px; padding: 9px 12px; border-radius: 12px; font-size: 15px; align-items: flex-start; }
.q-opt + .q-opt { margin-top: 4px; }
.q-opt .dot { width: 20px; height: 20px; border-radius: 50%; border: 1.5px solid var(--label3); flex: none; margin-top: 1px; display: grid; place-items: center; font-size: 12px; color: #fff; }
.q-opt.correct { background: color-mix(in srgb, var(--green) 12%, transparent); }
.q-opt.correct .dot { border-color: var(--green); }
.q-opt.selected .dot { background: var(--red); border-color: var(--red); }
.q-opt.selected.correct .dot { background: var(--green); border-color: var(--green); }
.q-opt.selected:not(.correct) { background: color-mix(in srgb, var(--red) 10%, transparent); }
.q-opt .tag { font-size: 12px; color: var(--label2); display: block; margin-top: 2px; }
