/* ---------- Tokens ---------- */
:root {
  --primario: #003087;
  --sobre-primario: #ffffff;
  --primario-txt: #003087;
  --acento: #cb5600;          /* datos clave; en fondo con texto blanco usar --acento-fuerte */
  --acento-fuerte: #b34c00;
  --acento-txt: #a34200;      /* acento para texto pequeño (AA) */
  --fondo: #faf8f5;
  --superficie: #ffffff;
  --texto: #1d2433;
  --texto-suave: #5d6678;
  --borde: #e6e1d9;
  --exito: #1f7a4d;
  --alerta: #c0262b;
  --n4: #003087; --n3: #5b7fc7; --n2: #cb5600; --n1: #ff5357;           /* barras */
  --n4-t: #003087; --n3-t: #3d5fa8; --n2-t: #a34200; --n1-t: #b42327;   /* texto sobre fondo tintado */
  --sombra: 0 1px 2px rgba(29, 36, 51, .05), 0 6px 20px rgba(29, 36, 51, .06);
  --radio: 16px;
  --serif: "Lora", Georgia, "Times New Roman", serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --alto-tabs: 64px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --primario: #3a63d4;
    --primario-txt: #9db8ff;
    --acento: #ff8a3d;
    --acento-fuerte: #b34c00;
    --acento-txt: #ffa869;
    --fondo: #0e1320;
    --superficie: #171e30;
    --texto: #eef1f8;
    --texto-suave: #a3adc2;
    --borde: #2a3550;
    --exito: #4cc38a;
    --alerta: #ff7a7e;
    --n4: #5b86e8; --n3: #86a6e6; --n2: #ff8a3d; --n1: #ff6a6e;
    --n4-t: #a9c0ff; --n3-t: #b4c9f2; --n2-t: #ffa869; --n1-t: #ff9a9d;
    --sombra: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
  }
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--fondo); color: var(--texto);
  font: 400 16px/1.5 var(--sans);
  padding-bottom: calc(var(--alto-tabs) + env(safe-area-inset-bottom) + 24px);
}
h1, h2 { font-family: var(--serif); font-weight: 600; letter-spacing: -.01em; }
h1 { font-size: 1.875rem; line-height: 1.2; margin: 8px 0 6px; }   /* 30px */
h2 { font-size: 1.25rem; margin: 32px 0 12px; }
p { margin: 0; }
a { color: var(--primario-txt); }
:focus-visible { outline: 3px solid var(--primario-txt); outline-offset: 2px; border-radius: 6px; }
.suave { color: var(--texto-suave); }
.peque { font-size: .875rem; }

/* ---------- Cabecera y navegación ---------- */
.cabecera {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 0 10px;
  background: color-mix(in srgb, var(--fondo) 88%, transparent); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--borde);
}
.cab-in { flex: 1 1 auto; max-width: 720px; margin: 0 auto; padding: 0 20px; box-sizing: border-box; display: flex; align-items: center; justify-content: space-between; gap: 12px; }  /* mismo contenedor que main */
.logo img { display: block; height: 40px; width: auto; }
.pantalla { font: 600 1.0625rem var(--serif); color: var(--texto-suave); }
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; display: flex; justify-content: center; gap: 4px;
  padding: 6px 12px calc(6px + env(safe-area-inset-bottom));
  background: var(--superficie); border-top: 1px solid var(--borde);
}
.tabs[hidden] { display: none; }
.tabs a {
  flex: 1; max-width: 220px; min-height: 52px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border-radius: 14px; text-decoration: none; color: var(--texto-suave); font-size: .75rem; font-weight: 500;
  transition: background .18s, color .18s;
}
.tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabs a.on { background: var(--primario); color: var(--sobre-primario); }

main { max-width: 720px; margin: 0 auto; padding: 24px 20px; animation: entra .2s ease both; }
@keyframes entra { from { opacity: 0; transform: translateY(6px); } }

/* ---------- Componentes ---------- */
.tarjeta {
  background: var(--superficie); border: 1px solid var(--borde); border-radius: var(--radio);
  box-shadow: var(--sombra); padding: 20px; margin-bottom: 16px;
}
label { display: block; font-size: .875rem; font-weight: 500; color: var(--texto-suave); margin: 18px 0 6px; }
label:first-child { margin-top: 0; }
input, select, textarea {
  width: 100%; min-height: 48px; padding: 12px 14px; font: inherit; color: var(--texto);
  background: var(--fondo); border: 1.5px solid var(--borde); border-radius: 12px;
  transition: border-color .15s, box-shadow .15s;
}
textarea { min-height: 88px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primario-txt); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primario-txt) 25%, transparent); }
.btn {
  position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 22px;
  font: 600 1rem var(--sans); color: var(--sobre-primario); background: var(--primario); border: 1.5px solid var(--primario);
  border-radius: 12px; text-decoration: none; cursor: pointer; transition: transform .15s, opacity .15s, background .15s;
}
.btn:active { transform: scale(.98); }
.btn.sec { background: transparent; color: var(--primario-txt); border-color: var(--borde); }
.btn.bloque { width: 100%; }
.btn:disabled, .btn[aria-busy="true"] { opacity: .65; cursor: default; }
.btn[aria-busy="true"]::before {
  content: ""; width: 18px; height: 18px; border: 2.5px solid currentColor; border-right-color: transparent; border-radius: 50%;
  animation: gira .7s linear infinite;
}
@keyframes gira { to { transform: rotate(360deg); } }
.acciones { display: grid; gap: 10px; margin-top: 20px; }
.acciones.tres { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }
.err { color: var(--alerta); margin-top: 14px; font-size: .9375rem; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; min-height: 28px; padding: 2px 10px; border-radius: 999px;
  font-size: .8125rem; font-weight: 600; background: color-mix(in srgb, var(--texto-suave) 14%, transparent); color: var(--texto);
}
.chip.n1 { background: color-mix(in srgb, var(--n1) 16%, transparent); color: var(--n1-t); }
.chip.n2 { background: color-mix(in srgb, var(--n2) 16%, transparent); color: var(--n2-t); }
.chip.n3 { background: color-mix(in srgb, var(--n3) 20%, transparent); color: var(--n3-t); }
.chip.n4 { background: color-mix(in srgb, var(--n4) 16%, transparent); color: var(--n4-t); }

/* ---------- Login ---------- */
body.login .cabecera, body.login .tabs { display: none; }
body.login { padding-bottom: 0; }
.login-caja { min-height: 100svh; display: flex; flex-direction: column; justify-content: center; max-width: 380px; margin: 0 auto; padding: 24px 0; }
.login-logo { display: block; width: 240px; max-width: 70%; height: auto; margin: 0 auto 28px; }
.login-caja h1 { text-align: center; font-size: 1.75rem; }
.login-caja .suave { text-align: center; margin-bottom: 24px; }
.login-caja input { text-align: center; font-size: 1.5rem; letter-spacing: .3em; }
@media (prefers-color-scheme: dark) { .login-logo, .logo img { background: #fff; border-radius: 12px; padding: 6px 12px; } .logo img { padding: 3px 10px; } }

/* ---------- Nueva encuesta / éxito ---------- */
.exito { text-align: center; animation: entra .25s ease both; }
.check { width: 64px; height: 64px; margin: 4px auto 8px; display: block; }
.check circle { fill: none; stroke: var(--acento); stroke-width: 3; stroke-dasharray: 164; stroke-dashoffset: 164; animation: traza .5s ease forwards; }
.check path { fill: none; stroke: var(--acento); stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 40; stroke-dashoffset: 40; animation: traza .35s .35s ease forwards; }
@keyframes traza { to { stroke-dashoffset: 0; } }
.exito h2 { margin: 4px 0 4px; }
.qr-caja { display: grid; place-items: center; width: 100%; max-width: 280px; margin: 20px auto; padding: 18px; background: #fff; border-radius: var(--radio); border: 1px solid var(--borde); }
.qr-caja img, .qr-caja canvas { width: 100% !important; height: auto !important; max-width: 220px; }
.enlace { display: block; max-width: 100%; margin: 0 auto; padding: 10px 14px; background: var(--fondo); border: 1px solid var(--borde); border-radius: 10px; font-size: .875rem; color: var(--texto-suave); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Sesiones ---------- */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 4px 20px 12px; margin: 0 -20px 8px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips button { flex: none; min-height: 44px; padding: 0 18px; font: 500 .9375rem var(--sans); color: var(--texto); background: var(--superficie); border: 1.5px solid var(--borde); border-radius: 999px; cursor: pointer; transition: background .15s, color .15s, border-color .15s; }
.chips button[aria-checked="true"] { background: var(--primario); border-color: var(--primario); color: var(--sobre-primario); }
.sesion { display: flex; gap: 16px; align-items: center; color: inherit; text-decoration: none; padding: 16px; transition: transform .15s, box-shadow .15s; }
.sesion:active { transform: scale(.99); }
.fecha-bloque { flex: none; width: 56px; padding: 8px 0; text-align: center; border-radius: 12px; background: color-mix(in srgb, var(--primario) 9%, transparent); color: var(--primario-txt); line-height: 1.1; }
.fecha-bloque b { display: block; font: 700 1.5rem var(--serif); }
.fecha-bloque span { font-size: .6875rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.sesion .cuerpo { flex: 1; min-width: 0; }
.sesion .t { font-weight: 600; overflow-wrap: anywhere; }
.sesion .chips-fila { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.vacio { text-align: center; padding: 40px 12px; color: var(--texto-suave); }
.vacio svg { width: 112px; height: 112px; margin: 0 auto 12px; display: block; fill: none; stroke: var(--borde); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.vacio svg .ac { stroke: var(--acento); }
.vacio strong { display: block; font: 600 1.125rem var(--serif); color: var(--texto); margin-bottom: 4px; }

/* ---------- Detalle ---------- */
.meta-linea { color: var(--texto-suave); font-size: .9375rem; margin-bottom: 20px; }
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.kpi { background: var(--superficie); border: 1px solid var(--borde); border-radius: var(--radio); box-shadow: var(--sombra); padding: 16px 8px; text-align: center; }
.kpi b { display: block; white-space: nowrap; font: 700 2rem/1.1 var(--serif); }
.kpi.k-resp b { color: var(--primario-txt); }
.kpi.k-media b, .kpi.k-pos b { color: var(--acento); }
.kpi span { display: block; margin-top: 6px; font-size: .75rem; color: var(--texto-suave); line-height: 1.25; }
.kpi small { font-size: .875rem; font-weight: 500; color: var(--texto-suave); }
.barras { width: 100%; height: auto; display: block; }
.barras text { font: 500 13px var(--sans); fill: var(--texto); }
.barras .t-suave { fill: var(--texto-suave); }
.barras .pista { fill: color-mix(in srgb, var(--texto-suave) 15%, transparent); }
.cita { position: relative; margin: 0 0 12px; padding: 16px 18px 14px 20px; background: var(--superficie); border: 1px solid var(--borde); border-left: 4px solid var(--acento); border-radius: 4px var(--radio) var(--radio) 4px; box-shadow: var(--sombra); }
.cita p { font: italic 500 1.0625rem/1.5 var(--serif); overflow-wrap: anywhere; }
.cita footer { margin-top: 10px; font-size: .8125rem; color: var(--texto-suave); }
.cita footer b { color: var(--texto); font-weight: 600; }

/* ---------- Informe ---------- */
.filtros { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; align-items: end; }
.filtros label { margin: 0 0 6px; }
.filtros > div { min-width: 0; }
/* date: iOS Safari ignora el ancho y no pinta placeholder; se fuerza caja y se superpone "dd/mm/aaaa" si está vacío */
input[type="date"] {
  display: block; width: 100%; min-width: 0; max-width: 100%; box-sizing: border-box; height: 48px; min-height: 48px;
  padding-top: 0; padding-bottom: 0; line-height: 46px; text-align: left;
  -webkit-appearance: none; appearance: none; position: relative;
}
input[type="date"]::-webkit-date-and-time-value { text-align: left; min-height: 1.2em; }
input[type="date"].sin-valor { color: transparent; }
input[type="date"].sin-valor::-webkit-datetime-edit { color: transparent; }
.campo-fecha { position: relative; }
.campo-fecha .ph { display: none; position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--texto-suave); pointer-events: none; }  /* Safari no admite ::before en input */
.campo-fecha.sin-valor .ph { display: block; }
.filtros .acciones { grid-column: 1 / -1; grid-template-columns: 1fr 1fr; margin-top: 4px; }
.filtros .ancho, .acciones .ancho { grid-column: 1 / -1; }
.est { color: var(--acento); letter-spacing: .06em; white-space: nowrap; }
.kpi .est { font-size: .9rem; margin-top: 6px; }
table.datos { width: 100%; border-collapse: collapse; }
table.datos th { text-align: left; font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--texto-suave); padding: 0 8px 10px; }
table.datos td { padding: 12px 8px; border-top: 1px solid var(--borde); }
table.datos .n { text-align: right; font-variant-numeric: tabular-nums; }
table.datos td.media .v { color: var(--acento-txt); font-weight: 600; }
@media (max-width: 719px) {
  table.datos, table.datos tbody, table.datos tr, table.datos td { display: block; }
  table.datos thead { display: none; }
  table.datos tr { padding: 14px 0; border-top: 1px solid var(--borde); }
  table.datos tr:first-child { border-top: 0; }
  table.datos td { display: flex; justify-content: space-between; padding: 3px 0; border: 0; }
  table.datos td::before { content: attr(data-l); color: var(--texto-suave); font-size: .875rem; font-weight: 400; }
  table.datos td > .v { text-align: right; }
  table.datos td.media .v { font-weight: 400; }  /* misma tipografía que Sesiones/Respuestas; solo el color resalta */
  table.datos td.nombre { font-weight: 600; font-size: 1.0625rem; padding-bottom: 6px; }
  table.datos td.nombre::before { content: none; }
}

/* ---------- Skeleton y toasts ---------- */
.skel { border-radius: 12px; background: linear-gradient(90deg, color-mix(in srgb, var(--texto-suave) 12%, transparent) 25%, color-mix(in srgb, var(--texto-suave) 22%, transparent) 50%, color-mix(in srgb, var(--texto-suave) 12%, transparent) 75%); background-size: 200% 100%; animation: brilla 1.3s linear infinite; }
@keyframes brilla { to { background-position: -200% 0; } }
.skel-tarjeta { height: 88px; margin-bottom: 16px; border-radius: var(--radio); }
.skel-linea { height: 16px; margin: 10px 0; }
.toasts { position: fixed; left: 0; right: 0; bottom: calc(var(--alto-tabs) + env(safe-area-inset-bottom) + 20px); z-index: 9; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast { padding: 12px 20px; border-radius: 999px; background: var(--texto); color: var(--fondo); font-size: .9375rem; font-weight: 500; box-shadow: var(--sombra); animation: entra .18s ease both; }

/* ---------- Informe imprimible ---------- */
.hoja .hoja-cab { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding-bottom: 16px; margin-bottom: 20px; border-bottom: 2px solid var(--primario); }
.hoja .hoja-cab img { height: 56px; width: auto; }
.hoja .hoja-cab .quien { text-align: right; font-size: .875rem; color: var(--texto-suave); }
.hoja h1 { margin-top: 0; }
.hoja .barras { max-width: 480px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
  .check circle, .check path { stroke-dashoffset: 0; }
}

@media print {
  :root {  /* siempre claro y con colores que imprimen bien */
    --fondo: #fff; --superficie: #fff; --texto: #1d2433; --texto-suave: #4a5262; --borde: #cfd3da; --sombra: none;
    --primario: #003087; --primario-txt: #003087; --acento: #cb5600; --acento-txt: #a34200;
    --n4: #003087; --n3: #5b7fc7; --n2: #cb5600; --n1: #ff5357;
  }
  @page { size: A4; margin: 16mm; }
  html, body { background: #fff; padding: 0; font-size: 12pt; }
  .cabecera, .tabs, .toasts, .no-print { display: none !important; }
  main { max-width: none; padding: 0; animation: none; }
  .tarjeta, .kpi, .cita { box-shadow: none; break-inside: avoid; }
  .kpis, .barras, .chip, .hoja-cab { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .logo img, .login-logo { background: none; padding: 0; }
}
.filtros .btn { padding: 0 12px; white-space: nowrap; }
select { -webkit-appearance: none; appearance: none; padding-right: 40px;
  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 d='M1 1.5l5 5 5-5' fill='none' stroke='%23788094' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 16px center; }
