/* ============================================================
   SIAB · Capa de apariencia y escala adaptable
   ------------------------------------------------------------
   - La raíz crece con la pantalla; todo el texto del sistema se
     expresa en rem, así que la interfaz completa se mantiene
     legible desde un teléfono hasta un kiosco 4K.
   - Los controles usan em/rem para conservar áreas táctiles.
   - Solo se ajustan tamaños, espaciados y detalles visuales:
     los colores siguen viniendo de styles.css y themes.css.
   ============================================================ */

/* Escala fluida: 18 px en pantallas pequeñas y hasta 34 px en 4K. */
html {
  font-size: clamp(18px, 0.62vw + 9px, 34px);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  font-size: 1rem;
  line-height: 1.5;
}

/* Foco visible y consistente en toda la interfaz. */
:where(a, button, input, select, textarea, [tabindex]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Estructura general ---------- */
.view {
  width: 100%;
  max-width: 100rem;
  padding: clamp(0.9rem, 1.6vw, 1.6rem);
}

.grid {
  gap: clamp(0.75rem, 1vw, 1.1rem);
}

.card {
  padding: clamp(1rem, 1.3vw, 1.5rem);
  border-radius: 1.15rem;
}

.app-footer {
  gap: 0.6rem 1.2rem;
  padding: 1rem clamp(0.9rem, 2vw, 2rem);
  font-size: 0.8rem;
}

.app-footer p {
  font-size: 0.78rem;
}

.footer-brand img {
  width: 1.5rem;
  height: 1.5rem;
}

.footer-brand strong {
  font-size: 0.85rem;
}

.footer-inst img {
  width: 1.65rem;
  height: 1.65rem;
}

.footer-link,
.secondary-link {
  font-size: 0.85rem;
}

.theme-picker,
.theme-picker select {
  font-size: 0.78rem;
}

/* ---------- Barra superior ---------- */
.topbar {
  gap: 0.9rem;
  padding: 0.55rem clamp(0.9rem, 2vw, 1.5rem);
  min-height: 4.1rem;
}

.topbar::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 1px;
  pointer-events: none;
  background: linear-gradient(
    90deg,
    transparent,
    color-mix(in srgb, var(--accent) 55%, transparent),
    transparent
  );
}

.brand {
  gap: 0.65rem;
}

.brand-mark {
  width: 2.6rem;
  height: 2.6rem;
  border-radius: 0.8rem;
}

.brand-mark img {
  padding: 0.28rem;
}

.brand-text strong {
  font-size: 1.12rem;
  letter-spacing: 0.13em;
}

.brand-text small {
  font-size: 0.66rem;
  max-width: 24rem;
}

.main-nav {
  gap: 0.15rem;
}

.main-nav a {
  padding: 0.48em 0.8em;
  font-size: 0.9rem;
}

.main-nav a.active {
  box-shadow: 0 0.35rem 1.1rem color-mix(in srgb, var(--accent) 30%, transparent);
}

.user-box {
  gap: 0.5rem;
  font-size: 0.85rem;
}

.user-chip strong {
  font-size: 0.9rem;
  max-width: 12rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-chip span {
  font-size: 0.68rem;
}

.nav-toggle {
  width: 2.7rem;
  height: 2.7rem;
  border-radius: 0.75rem;
}

.nav-toggle span {
  width: 1.15rem;
  height: 2px;
}

/* ---------- Tipografía ---------- */
.page-head {
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.page-head h1 {
  font-size: clamp(1.7rem, 1.4vw + 1.1rem, 2.7rem);
  line-height: 1.12;
  margin-bottom: 0.2rem;
}

.page-head p {
  font-size: 0.98rem;
  line-height: 1.55;
}

.eyebrow {
  font-size: 0.72rem;
  letter-spacing: 0.16em;
  margin-bottom: 0.35rem;
}

.card h2 {
  font-size: 1.28rem;
}

.card h3 {
  font-size: 1.08rem;
}

.card h2,
.card h3 {
  margin-bottom: 0.5rem;
}

.help,
.card p.help {
  font-size: 0.9rem;
  line-height: 1.55;
}

.stat {
  gap: 0.25rem;
}

.stat .label {
  font-size: 0.72rem;
  letter-spacing: 0.1em;
}

.stat .value {
  font-size: clamp(1.9rem, 2.4vw, 2.8rem);
}

.stat .value small {
  font-size: 0.95rem;
}

.small-note {
  font-size: 0.82rem;
  line-height: 1.5;
}

.mono,
.kbd {
  font-size: 0.8rem;
}

/* ---------- Controles ---------- */
.btn {
  gap: 0.5em;
  padding: 0.6em 1.05em;
  min-height: 2.65em;
  border-radius: 0.7rem;
  font-size: 0.92rem;
  transition: 0.16s ease;
}

.btn:hover:not(:disabled) {
  transform: translateY(-1px);
}

.btn:active:not(:disabled) {
  transform: translateY(0);
}

.btn.primary {
  box-shadow: 0 0.45rem 1.2rem color-mix(in srgb, var(--accent) 28%, transparent);
}

.btn.small {
  padding: 0.42em 0.8em;
  min-height: 2.35em;
  font-size: 0.82rem;
  border-radius: 0.55rem;
}

.field {
  gap: 0.3rem;
  margin-bottom: 0.85rem;
}

.field label {
  font-size: 0.82rem;
  letter-spacing: 0.02em;
}

.field input,
.field select,
.field textarea,
.inline-input input {
  padding: 0.56em 0.7em;
  min-height: 2.6em;
  border-radius: 0.6rem;
  font-size: 1rem;
}

/* Con la escala fluida, ningún campo debe desbordar su tarjeta. */
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]),
select,
textarea {
  max-width: 100%;
  min-width: 0;
}

.field .help {
  font-size: 0.8rem;
}

.inline {
  gap: 0.55rem;
}

.badge {
  padding: 0.32em 0.7em;
  gap: 0.35em;
  font-size: 0.74rem;
  max-width: 100%;
}

/* En listas y sobre la cámara, las etiquetas cortas no deben partirse. */
.list-item .badge,
.kiosk-badges .badge {
  white-space: nowrap;
  flex: 0 0 auto;
}

.pill {
  padding: 0.22em 0.65em;
  font-size: 0.72rem;
  white-space: nowrap;
}

/* ---------- Listas y tablas ---------- */
.list {
  gap: 0.5rem;
}

.list-item {
  padding: 0.7rem 0.85rem;
  border-radius: 0.8rem;
  gap: 0.7rem;
  transition: border-color 0.16s ease, background 0.16s ease;
}

.list-item:hover {
  border-color: var(--line-strong);
}

.list-item .meta strong {
  font-size: 0.98rem;
}

.list-item .meta small {
  font-size: 0.8rem;
}

.table-wrap {
  border-radius: 0.85rem;
}

table {
  font-size: 0.88rem;
}

thead th {
  padding: 0.65em 0.8em;
  font-size: 0.72rem;
  letter-spacing: 0.07em;
}

tbody td {
  padding: 0.65em 0.8em;
}

.empty {
  padding: 1.4rem;
  font-size: 0.88rem;
  border-radius: 0.8rem;
}

/* ---------- Login ---------- */
.login-wrap {
  position: relative;
  min-height: calc(100dvh - 11rem);
  padding: 1.5rem 1rem;
}

/* Marca de agua discreta: llena el vacío de las pantallas grandes. */
@media (min-width: 900px) {
  .login-wrap::before {
    content: "SIAB";
    position: fixed;
    left: 50%;
    top: 46%;
    transform: translate(-50%, -50%);
    z-index: 0;
    pointer-events: none;
    font-size: min(24vw, 22rem);
    font-weight: 800;
    letter-spacing: 0.06em;
    line-height: 1;
    color: var(--accent);
    opacity: 0.055;
    user-select: none;
  }
}

.login-stack {
  position: relative;
  z-index: 1;
  width: min(33rem, 100%);
  gap: 0.85rem;
}

.login-inst {
  gap: 0.6rem;
  padding: 0.35rem 0.9rem 0.35rem 0.35rem;
  border-radius: 0.95rem;
  margin-bottom: 0.4rem;
}

.login-inst-logo {
  width: 2.7rem;
  height: 2.7rem;
  border-radius: 0.7rem;
}

.login-inst-text small {
  font-size: 0.62rem;
}

.login-inst-text strong {
  font-size: 0.92rem;
}

.login-card {
  position: relative;
  width: min(33rem, 100%);
  padding: clamp(1.5rem, 2.2vw, 2.4rem);
  border-radius: 1.35rem;
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--accent) 30%, var(--line));
  box-shadow:
    var(--shadow),
    0 0 0 1px color-mix(in srgb, var(--accent) 12%, transparent);
}

.login-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 0.22rem;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  opacity: 0.9;
}

.login-card .brand {
  margin-bottom: 1.1rem;
}

.login-card .brand-text strong {
  font-size: 1.02rem;
  letter-spacing: 0.24em;
  color: var(--accent);
}

.login-card h1 {
  font-size: clamp(1.9rem, 1.5vw + 1.2rem, 2.55rem);
  line-height: 1.1;
  margin: 0 0 0.4rem;
}

.login-card p {
  font-size: 0.98rem;
  line-height: 1.55;
  margin: 0 0 1.2rem;
}

.login-card .btn.primary.block {
  margin-top: 0.35rem;
  padding: 0.78em 1em;
  font-size: 1rem;
  font-weight: 700;
}

.login-copyright {
  font-size: 0.74rem;
}

.demo-accounts p {
  font-size: 0.82rem;
}

/* ---------- Kiosco ---------- */
.kiosk-stage {
  width: 100%;
  height: clamp(17rem, 56vh, 42rem);
  aspect-ratio: auto;
  border-radius: 1.15rem;
}

@media (max-width: 720px) {
  .kiosk-stage {
    height: auto;
    aspect-ratio: 4 / 3;
  }
}

.grid.kiosk-layout > .card {
  padding: clamp(0.9rem, 1.2vw, 1.3rem) !important;
}

.kiosk-prompt {
  padding: 0.55em 1.15em;
  font-size: clamp(1.02rem, 0.8vw + 0.65rem, 1.7rem);
}

.kiosk-legend {
  font-size: 0.78rem;
  gap: 0.4rem 1rem;
}

.kiosk-badges .badge {
  font-size: 0.78rem;
}

.kiosk-bottom .small-note {
  font-size: 0.76rem;
}

.result-card {
  left: 1rem;
  right: 1rem;
  bottom: 3.8rem;
  padding: 0.85rem 1rem;
  gap: 0.8rem;
  border-radius: 0.95rem;
}

.result-avatar {
  width: 3rem;
  height: 3rem;
  border-radius: 0.85rem;
  font-size: 1.3rem;
}

.result-copy strong {
  font-size: 1.2rem;
}

.result-copy span {
  font-size: 0.9rem;
}

.result-copy .result-greeting {
  font-size: 0.85rem;
}

.faceid-step-count {
  font-size: 0.7rem;
}

.faceid-pose-hint {
  font-size: clamp(1rem, 1vw + 0.75rem, 1.6rem);
}

.faceid-headline strong {
  font-size: clamp(1.2rem, 1.1vw + 0.9rem, 1.8rem);
}

.faceid-headline span {
  font-size: 0.85rem;
}

.faceid-placeholder {
  font-size: 0.82rem;
}

.simple-time {
  font-size: clamp(2.6rem, 8vw, 8rem);
}

.simple-clock {
  top: 1.2rem;
}

/* Kiosco simple: sin barra ni pie, el aviso debe quedar dentro de pantalla. */
body.siab-simple .kiosk-prompt {
  position: absolute !important;
  left: 50%;
  bottom: 12% !important;
  transform: translateX(-50%);
  z-index: 12;
  max-width: min(90vw, 60rem);
  font-size: clamp(1.15rem, 1.2vh + 1rem, 2.2rem);
}

/* ---------- Ajustes por tamaño de pantalla ---------- */
@media (max-width: 1600px) {
  .brand-text small {
    display: none;
  }
  .main-nav a {
    padding: 0.45em 0.68em;
  }
}

@media (max-width: 1200px) {
  .main-nav a {
    font-size: 0.92rem;
  }
  .user-chip {
    display: none;
  }
}

@media (max-width: 720px) {
  .view {
    padding: 0.8rem;
  }
  .card {
    padding: 0.9rem;
    border-radius: 1rem;
  }
  .page-head h1 {
    font-size: clamp(1.5rem, 4.5vw, 2rem);
  }
  .page-head p {
    font-size: 0.92rem;
  }
  .grid.kiosk-layout > .card {
    padding: 0.75rem !important;
  }
  .kiosk-prompt {
    font-size: clamp(1rem, 3.6vw, 1.35rem);
  }
  .result-card {
    left: 0.6rem;
    right: 0.6rem;
    bottom: 3.2rem;
    padding: 0.7rem 0.8rem;
  }
  .login-wrap {
    min-height: auto;
    padding: 1rem 0.75rem 1.5rem;
  }
  .login-card {
    padding: 1.25rem;
    border-radius: 1.1rem;
  }
  .topbar {
    padding: 0.5rem 0.75rem;
    gap: 0.6rem;
  }
  .brand-mark {
    width: 2.35rem;
    height: 2.35rem;
  }
  .brand-text strong {
    font-size: 1.02rem;
  }
  .btn {
    font-size: 0.9rem;
  }
  .btn.small {
    font-size: 0.8rem;
  }
}

@media (max-width: 430px) {
  .view {
    padding: 0.65rem;
  }
  .app-footer {
    padding: 0.8rem;
  }
  .page-head h1 {
    font-size: 1.45rem;
  }
  .login-card {
    padding: 1.1rem;
  }
  .result-avatar {
    width: 2.5rem;
    height: 2.5rem;
    font-size: 1.05rem;
  }
  .result-copy strong {
    font-size: 1.02rem;
  }
}

@media (min-width: 2200px) {
  .view {
    padding: 2rem;
  }
  .grid {
    gap: 1.4rem;
  }
  /* En pantallas muy grandes, la barra y el pie se alinean con el contenido. */
  .topbar {
    padding-left: max(2rem, calc((100vw - 100rem) / 2 + 2rem));
    padding-right: max(2rem, calc((100vw - 100rem) / 2 + 2rem));
  }
  .app-footer {
    padding-left: max(2rem, calc((100vw - 100rem) / 2 + 2rem));
    padding-right: max(2rem, calc((100vw - 100rem) / 2 + 2rem));
  }
  .main-nav {
    justify-content: center;
  }
}

/* Respeta la preferencia de menos movimiento. */
@media (prefers-reduced-motion: reduce) {
  .btn:hover:not(:disabled) {
    transform: none;
  }
}

/* Impresión: mantiene tamaños legibles en papel. */
@media print {
  html {
    font-size: 11px;
  }
}

/* ---------- Ojo para mostrar/ocultar contraseñas ---------- */
.password-wrap {
  position: relative;
  display: block;
  width: 100%;
}

.password-wrap > input {
  width: 100%;
  padding-right: 2.9em;
}

.password-toggle {
  position: absolute;
  top: 50%;
  right: 0.25rem;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.2em;
  height: 2.2em;
  padding: 0;
  border: 0;
  border-radius: 0.5rem;
  background: transparent;
  color: inherit;
  opacity: 0.72;
  cursor: pointer;
}

.password-toggle:hover {
  opacity: 1;
  background: color-mix(in srgb, currentColor 14%, transparent);
}

.password-toggle[aria-pressed="true"] {
  opacity: 1;
  color: var(--accent);
}

.password-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Flujo obligatorio de seguridad ---------- */
.security-wrap {
  display: flex;
  justify-content: center;
  padding: clamp(0.4rem, 2vw, 2rem) 0;
}

.security-card {
  width: min(54rem, 100%);
}

.security-head h1 {
  font-size: clamp(1.5rem, 1.3vw + 1rem, 2.3rem);
  line-height: 1.15;
  margin: 0.15rem 0 0.5rem;
}

.security-steps {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.5rem;
  margin: 1.1rem 0 1.4rem;
  padding: 0;
  list-style: none;
}

.security-steps li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.86rem;
  opacity: 0.62;
}

.security-steps li.current,
.security-steps li.done {
  opacity: 1;
}

.security-steps li.current {
  font-weight: 700;
}

.security-steps li.done {
  color: var(--accent);
}

.security-step-dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.9em;
  height: 1.9em;
  border: 1px solid var(--line-strong, rgba(127, 127, 127, 0.5));
  border-radius: 50%;
  font-size: 0.8rem;
}

.security-steps li.current .security-step-dot,
.security-steps li.done .security-step-dot {
  border-color: var(--accent);
}

/* Alta de TOTP: QR + instrucciones */
.mfa-setup {
  display: grid;
  grid-template-columns: minmax(13rem, 17rem) minmax(0, 1fr);
  gap: 1.25rem;
  align-items: start;
}

.mfa-qr-card {
  display: flex;
  justify-content: center;
  padding: 0.7rem;
  border-radius: 0.9rem;
  background: #fff;
}

.mfa-qr svg {
  display: block;
  width: 100%;
  height: auto;
  max-width: 16rem;
}

.mfa-setup-info h2 {
  font-size: 1rem;
  margin: 0.9rem 0 0.35rem;
}

.mfa-setup-info h2:first-child {
  margin-top: 0;
}

.mfa-secret {
  display: inline-block;
  margin: 0.35rem 0 0.5rem;
  padding: 0.5em 0.7em;
  border-radius: 0.5rem;
  background: color-mix(in srgb, currentColor 12%, transparent);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 1.02rem;
  letter-spacing: 0.12em;
  overflow-wrap: anywhere;
}

.mfa-secret + .btn {
  margin-bottom: 0.5rem;
}

/* Códigos de recuperación */
.recovery-box {
  padding: clamp(0.8rem, 1.4vw, 1.2rem);
  margin-bottom: 1rem;
  border: 1px solid color-mix(in srgb, var(--accent) 34%, transparent);
  border-radius: 0.9rem;
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}

.recovery-codes {
  margin: 0 0 0.8rem;
  padding: 0.9rem 1rem;
  border-radius: 0.7rem;
  background: color-mix(in srgb, currentColor 10%, transparent);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 1.02rem;
  line-height: 1.85;
  letter-spacing: 0.1em;
  white-space: pre;
  overflow-auto;
}

@media (max-width: 760px) {
  .mfa-setup {
    grid-template-columns: 1fr;
  }

  .mfa-qr-card {
    max-width: 15rem;
  }
}

@media print {
  .security-steps,
  .security-wrap .btn {
    display: none !important;
  }

  .security-card {
    width: 100%;
    border: 0;
    box-shadow: none;
  }

  .recovery-codes {
    font-size: 12pt;
  }
}

/* ---------- Compactación: flujo de seguridad en pantallas bajas ---------- */
/* El cambio forzado de contraseña y el alta de 2FA deben verse completos sin
   desplazar contenido. En alturas reducidas se compacta la tarjeta en vez de
   encender la barra de desplazamiento. */
@media (max-height: 900px) {
  .security-wrap {
    padding: 0.2rem 0;
  }

  .security-card {
    padding: clamp(12px, 1.5vw, 18px);
  }

  .security-head h1 {
    font-size: clamp(1.3rem, 1vw + 0.9rem, 1.75rem);
  }

  .security-head .help {
    margin: 0.3rem 0 0;
    font-size: 0.86rem;
    line-height: 1.35;
  }

  .security-steps {
    margin: 0.5rem 0 0.7rem;
    gap: 0.35rem 1rem;
  }

  .security-step-dot {
    width: 1.55em;
    height: 1.55em;
    font-size: 0.72rem;
  }

  .security-card .field {
    margin-bottom: 8px;
    gap: 4px;
  }

  .security-card .field input {
    padding: 0.5rem 0.7rem;
  }

  .security-card .btn {
    padding-top: 0.6rem;
    padding-bottom: 0.6rem;
  }
}

@media (max-height: 800px) {
  .security-head h1 {
    font-size: 1.2rem;
  }

  .security-head .help {
    display: none;
  }

  .security-steps {
    margin: 0.35rem 0 0.55rem;
    font-size: 0.78rem;
  }

  .security-card .field label {
    font-size: 0.82rem;
  }
}

/* ---------- Kiosco: la cámara ocupa el alto disponible, sin barras ---------- */
/* En el equipo del kiosco (pantalla 1080p y portátiles) la vista completa debe
   caber sin desplazamiento: el escenario de cámara absorbe el alto restante y
   el panel lateral es el único que puede desplazarse por dentro. */
@media (min-width: 901px) {
  #view:has(.kiosk-layout) {
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  #view:has(.kiosk-layout) > .page-head {
    flex: 0 0 auto;
  }

  #view:has(.kiosk-layout) > .kiosk-layout {
    flex: 1 1 auto;
    min-height: 0;
    align-items: stretch;
  }

  #view:has(.kiosk-layout) .kiosk-layout > section.card {
    display: flex;
    flex-direction: column;
    min-height: 0;
  }

  #view:has(.kiosk-layout) .kiosk-stage {
    flex: 1 1 auto;
    min-height: 13rem;
    height: auto;
  }

  #view:has(.kiosk-layout) #kiosk-session-aside {
    min-height: 0;
    overflow-y: auto;
    padding-right: 2px;
  }
}


/* El flujo de seguridad nunca enciende la barra de la página. */
@media (max-height: 1100px) {
  .security-wrap {
    padding: 0.35rem 0;
  }
}

/* Kiosco en alturas cortas: cabecera compacta y escenario más pequeño. */
@media (min-width: 901px) and (max-height: 820px) {
  #view:has(.kiosk-layout) > .page-head {
    margin-bottom: 0.5rem;
  }

  #view:has(.kiosk-layout) > .page-head h1 {
    font-size: 1.45rem;
    line-height: 1.15;
  }

  #view:has(.kiosk-layout) > .page-head .help {
    margin-top: 2px;
    font-size: 0.82rem;
  }

  #view:has(.kiosk-layout) .kiosk-stage {
    min-height: 8.5rem;
  }
}
