/*
 * qAccess — componentes del portal (Thymeleaf + htmx).
 * Requiere tokens.css y base.css. Clases con convención BEM ligera: .bloque, .bloque__parte, .bloque--variante.
 * Estados con atributos nativos cuando existen: aria-current, aria-invalid, aria-selected, disabled, [open].
 */

/* =========================================================================
   Estructura de la aplicación
   ========================================================================= */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow-y: auto;
  background: var(--sidebar-bg);
  border-right: var(--border-width) solid var(--sidebar-border);
  color: var(--sidebar-text);
}
.sidebar__brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  height: var(--topbar-height);
  padding: 0 var(--space-5);
  color: var(--brand-orange);
  text-decoration: none;
}
.sidebar__brand svg { height: 1.25rem; width: auto; }
.sidebar__product {
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  color: var(--sidebar-text-active);
  letter-spacing: -0.01em;
}
.sidebar__tenant {
  margin: 0 var(--space-3) var(--space-4);
  padding: var(--space-2) var(--space-3);
  border: var(--border-width) solid var(--sidebar-border);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
}
.sidebar__tenant strong { display: block; color: var(--sidebar-text-active); font-weight: var(--weight-semibold); }
.sidebar__section {
  padding: var(--space-4) var(--space-5) var(--space-2);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #6F7891;
}
.sidebar__footer { margin-top: auto; padding: var(--space-4) 0; border-top: var(--border-width) solid var(--sidebar-border); }

.nav { display: flex; flex-direction: column; gap: 2px; padding: 0 var(--space-3); list-style: none; }
.nav__item {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  color: var(--sidebar-text);
  font-size: var(--text-md);
  font-weight: var(--weight-medium);
  text-decoration: none;
  transition: background var(--duration-fast) var(--ease), color var(--duration-fast) var(--ease);
}
button.nav__item { width: 100%; border: 0; background: none; font-family: inherit; text-align: left; cursor: pointer; }
.nav__item:hover { background: var(--sidebar-item-hover); color: var(--sidebar-text-active); }
.nav__item[aria-current="page"] { background: var(--sidebar-item-active); color: var(--sidebar-text-active); }
.nav__item[aria-current="page"]::before {
  content: "";
  position: absolute;
  left: calc(-1 * var(--space-3));
  top: 6px;
  bottom: 6px;
  width: 3px;
  background: var(--sidebar-indicator);
}
.nav__item[aria-current="page"] .icon { color: var(--sidebar-indicator); }
.nav__count {
  margin-left: auto;
  padding: 0 var(--space-2);
  border-radius: var(--radius-sm);
  background: var(--brand-orange);
  color: var(--brand-dark);
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
}

.main { display: flex; flex-direction: column; min-width: 0; }

.topbar {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  display: flex;
  align-items: center;
  gap: var(--space-4);
  height: var(--topbar-height);
  padding: 0 var(--space-8);
  background: color-mix(in srgb, var(--color-bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: var(--border-width) solid var(--color-border);
}
.topbar .topbar__menu { display: none; }
.topbar__search { flex: 1 1 10rem; max-width: 22rem; }

.content {
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--space-8);
}

.content--notice { padding-bottom: 0; }

.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}
.page-header__subtitle { margin-top: var(--space-1); color: var(--color-text-muted); }

.breadcrumb { display: flex; flex-wrap: wrap; gap: var(--space-2); list-style: none; padding: 0; font-size: var(--text-sm); color: var(--color-text-muted); }
.breadcrumb li + li::before { content: "/"; margin-right: var(--space-2); color: var(--color-text-subtle); }
.breadcrumb a { color: inherit; text-decoration: none; }
.breadcrumb a:hover { color: var(--color-text); text-decoration: underline; }

/* Pantallas sin barra lateral: inicio de sesión, recuperación, invitación */
.auth {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: var(--space-6);
  background: var(--brand-dark);
}
.auth__card { width: min(100%, 26rem); }
.auth__logo { height: 4.5rem; width: auto; margin: 0 auto var(--space-8); color: var(--brand-orange); }
.auth__card--wide { width: min(100%, 30rem); }
.auth__footer { text-align: center; color: #A2A9BC; font-size: var(--text-sm); }
.auth__links { display: flex; flex-direction: column; gap: var(--space-2); text-align: center; font-size: var(--text-sm); }
/* QR del segundo factor (SVG generado por el servidor) */
.qr { display: block; width: 10rem; height: auto; flex: none; border: var(--border-width) solid var(--color-border); border-radius: var(--radius-md); }
.secret-key { font-family: var(--font-mono); letter-spacing: 0.08em; }

@media (max-width: 64rem) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: var(--z-modal);
    width: min(85vw, var(--sidebar-width));
    transform: translateX(-100%);
    transition: transform var(--duration-normal) var(--ease);
  }
  .sidebar[data-open="true"] { transform: none; box-shadow: var(--shadow-lg); }
  .topbar { padding: 0 var(--space-4); }
  .topbar .topbar__menu { display: inline-flex; }
  .content { padding: var(--space-5) var(--space-4); }
}

/* =========================================================================
   Botones
   ========================================================================= */
.btn {
  --btn-bg: var(--color-surface);
  --btn-fg: var(--color-text);
  --btn-border: var(--color-border-strong);
  --btn-bg-hover: var(--color-surface-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 2.5rem;
  padding: 0 var(--space-4);
  border: var(--border-width) solid var(--btn-border);
  border-radius: var(--radius-md);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
  transition: background var(--duration-fast) var(--ease), border-color var(--duration-fast) var(--ease);
}
.btn:hover { background: var(--btn-bg-hover); text-decoration: none; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }
.btn .icon { width: 1.125rem; height: 1.125rem; }

.btn--primary {
  --btn-bg: var(--color-accent);
  --btn-fg: var(--color-on-accent);
  --btn-border: var(--color-accent);
  --btn-bg-hover: var(--color-accent-hover);
}
.btn--ghost {
  --btn-bg: transparent;
  --btn-border: transparent;
  --btn-bg-hover: var(--color-surface-2);
}
.btn--danger {
  --btn-bg: var(--color-danger);
  --btn-fg: #FFFFFF;
  --btn-border: var(--color-danger);
  --btn-bg-hover: var(--color-danger-hover);
}
:root[data-theme="dark"] .btn--danger { --btn-fg: var(--brand-dark); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn--danger { --btn-fg: var(--brand-dark); } }

.btn--sm { min-height: 2rem; padding: 0 var(--space-3); font-size: var(--text-sm); }
.btn--lg { min-height: 3rem; padding: 0 var(--space-6); font-size: var(--text-lg); }
.btn--block { width: 100%; }
.btn--icon { width: 2.5rem; padding: 0; }
.btn--icon.btn--sm { width: 2rem; }

/* htmx: indicador de carga dentro del botón (<button hx-post ...><span class="spinner htmx-indicator"></span>) */
.spinner {
  width: 1em;
  height: 1em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { display: inline-block; }
.htmx-request.btn, .htmx-request .btn[type="submit"] { pointer-events: none; opacity: 0.75; }

/* =========================================================================
   Formularios
   ========================================================================= */
.field { display: flex; flex-direction: column; gap: var(--space-1); }
.label { font-size: var(--text-sm); font-weight: var(--weight-semibold); color: var(--color-text); }
.label__optional { font-weight: var(--weight-regular); color: var(--color-text-muted); }
.hint { font-size: var(--text-sm); color: var(--color-text-muted); }
.field-error { display: flex; gap: var(--space-1); align-items: center; font-size: var(--text-sm); color: var(--color-danger); }

.input, .select, .textarea {
  width: 100%;
  min-height: 2.5rem;
  padding: var(--space-2) var(--space-3);
  border: var(--border-width) solid var(--color-border-strong);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
  transition: border-color var(--duration-fast) var(--ease), box-shadow var(--duration-fast) var(--ease);
}
.textarea { min-height: 6rem; resize: vertical; }
.input::placeholder, .textarea::placeholder { color: var(--color-text-subtle); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--color-text-muted); }
.input:focus-visible, .select:focus-visible, .textarea:focus-visible {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-accent) 30%, transparent);
}
.input[aria-invalid="true"], .select[aria-invalid="true"], .textarea[aria-invalid="true"] { border-color: var(--color-danger); }
.input:disabled, .select:disabled, .textarea:disabled { background: var(--color-surface-2); color: var(--color-text-subtle); cursor: not-allowed; }
.input--mono { font-family: var(--font-mono); letter-spacing: 0.08em; }
.input--code { font-family: var(--font-mono); font-size: var(--text-2xl); text-align: center; letter-spacing: 0.4em; }

.select {
  appearance: none;
  padding-right: var(--space-8);
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 1.05rem) 52%, calc(100% - 0.75rem) 52%;
  background-size: 0.3rem 0.3rem;
  background-repeat: no-repeat;
}

.input-icon { position: relative; }
.input-icon > .icon { position: absolute; left: var(--space-3); top: 50%; transform: translateY(-50%); color: var(--color-text-muted); pointer-events: none; }
.input-icon > .input { padding-left: 2.5rem; }

.check { display: inline-flex; align-items: center; gap: var(--space-2); cursor: pointer; }
.check input { flex: none; width: 1.125rem; height: 1.125rem; margin: 0; accent-color: var(--color-accent); }
/* Opción con descripción debajo del título: el control se alinea con la primera línea */
.check--block { display: flex; align-items: flex-start; }
.check--block input { margin-top: 0.2rem; }

.switch { display: inline-flex; align-items: center; gap: var(--space-3); cursor: pointer; }
.switch input {
  appearance: none;
  position: relative;
  width: 2.5rem;
  height: 1.375rem;
  margin: 0;
  border-radius: var(--radius-full);
  background: var(--color-border-strong);
  transition: background var(--duration-fast) var(--ease);
  cursor: pointer;
}
.switch input::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 1rem;
  height: 1rem;
  border-radius: 50%;
  background: #FFFFFF;
  transition: transform var(--duration-fast) var(--ease);
}
.switch input:checked { background: var(--color-accent); }
.switch input:checked::after { transform: translateX(1.125rem); }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); gap: var(--space-5); }
.form-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--space-3); padding-top: var(--space-4); border-top: var(--border-width) solid var(--color-border); }

/* =========================================================================
   Superficies
   ========================================================================= */
.card {
  background: var(--color-surface);
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.card__header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-bottom: var(--border-width) solid var(--color-border);
}
.card__title { font-size: var(--text-lg); font-weight: var(--weight-semibold); }
.card__body { padding: var(--space-5); }
.card__footer { padding: var(--space-3) var(--space-5); border-top: var(--border-width) solid var(--color-border); background: var(--color-surface-2); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }

/* Indicador (KPI): cifra grande, etiqueta y variación */
.kpi {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-5);
  background: var(--color-surface);
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.kpi::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 3px; background: var(--kpi-color, var(--color-border-strong)); }
.kpi--accent { --kpi-color: var(--color-accent); }
.kpi--success { --kpi-color: var(--color-success); }
.kpi--warning { --kpi-color: var(--color-warning); }
.kpi--danger { --kpi-color: var(--color-danger); }
.kpi__label { display: flex; align-items: center; gap: var(--space-2); font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--color-text-muted); }
.kpi__value { font-size: var(--text-4xl); font-weight: var(--weight-semibold); line-height: 1.1; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.kpi__meta { font-size: var(--text-sm); color: var(--color-text-muted); }

/* =========================================================================
   Tablas
   ========================================================================= */
.table-wrap { overflow-x: auto; }
.table { width: 100%; font-size: var(--text-md); }
.table th, .table td { padding: var(--space-3) var(--space-4); text-align: left; vertical-align: middle; }
.table thead th {
  position: sticky;
  top: 0;
  background: var(--color-surface-2);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  white-space: nowrap;
  border-bottom: var(--border-width) solid var(--color-border);
}
.table tbody tr { border-bottom: var(--border-width) solid var(--color-border); }
.table tbody tr:last-child { border-bottom: 0; }
.table tbody tr:hover { background: color-mix(in srgb, var(--color-surface-2) 60%, transparent); }
.table .num { text-align: right; }
.table--compact th, .table--compact td { padding: var(--space-2) var(--space-3); }
.table__sort { display: inline-flex; align-items: center; gap: var(--space-1); padding: 0; border: 0; background: none; color: inherit; font: inherit; letter-spacing: inherit; text-transform: inherit; text-decoration: none; }
.table__sort[aria-sort], th[aria-sort] .table__sort { color: var(--color-text); }
th[aria-sort="ascending"] .table__sort::after { content: "↑"; }
th[aria-sort="descending"] .table__sort::after { content: "↓"; }
.table .person__name { white-space: nowrap; }

.person { display: flex; align-items: center; gap: var(--space-3); min-width: 0; }
.person__name { font-weight: var(--weight-semibold); }
.person__meta { font-size: var(--text-sm); color: var(--color-text-muted); }

.avatar {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: var(--radius-md);
  background: var(--color-surface-2);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar--sm { width: 1.75rem; height: 1.75rem; font-size: var(--text-xs); }

/* =========================================================================
   Insignias, chips, alertas
   ========================================================================= */
.badge {
  --badge-fg: var(--color-text-muted);
  --badge-bg: var(--color-surface-2);
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 0.125rem var(--space-2);
  border-radius: var(--radius-sm);
  background: var(--badge-bg);
  color: var(--badge-fg);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  line-height: 1.5;
  white-space: nowrap;
}
.badge--dot::before { content: ""; width: 0.4rem; height: 0.4rem; border-radius: 50%; background: currentColor; }
.badge--accent { --badge-fg: var(--color-accent-text); --badge-bg: var(--color-accent-soft); }
.badge--success { --badge-fg: var(--color-success); --badge-bg: var(--color-success-soft); }
.badge--warning { --badge-fg: var(--color-warning); --badge-bg: var(--color-warning-soft); }
.badge--danger { --badge-fg: var(--color-danger); --badge-bg: var(--color-danger-soft); }
.badge--info { --badge-fg: var(--color-info); --badge-bg: var(--color-info-soft); }
.badge--code { font-family: var(--font-mono); font-weight: var(--weight-medium); letter-spacing: 0.02em; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 2rem;
  padding: 0 var(--space-3);
  border: var(--border-width) solid var(--color-border-strong);
  border-radius: var(--radius-full);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  text-decoration: none;
}
.chip:hover { background: var(--color-surface-2); }
.chip[aria-pressed="true"], .chip[aria-selected="true"] { background: var(--color-accent-soft); border-color: var(--color-accent); color: var(--color-accent-text); }

.alert {
  --alert-fg: var(--color-info);
  --alert-bg: var(--color-info-soft);
  display: flex;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-left: 3px solid var(--alert-fg);
  border-radius: var(--radius-md);
  background: var(--alert-bg);
  color: var(--color-text);
}
.alert > .icon { color: var(--alert-fg); margin-top: 0.1rem; }
.alert__title { font-weight: var(--weight-semibold); }
.alert--success { --alert-fg: var(--color-success); --alert-bg: var(--color-success-soft); }
.alert--warning { --alert-fg: var(--color-warning); --alert-bg: var(--color-warning-soft); }
.alert--danger { --alert-fg: var(--color-danger); --alert-bg: var(--color-danger-soft); }

/* =========================================================================
   Navegación secundaria
   ========================================================================= */
.tabs { display: flex; gap: var(--space-1); border-bottom: var(--border-width) solid var(--color-border); overflow-x: auto; }
.tabs__tab {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border: 0;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  background: none;
  color: var(--color-text-muted);
  font-weight: var(--weight-semibold);
  text-decoration: none;
  white-space: nowrap;
}
.tabs__tab:hover { color: var(--color-text); }
.tabs__tab[aria-selected="true"], .tabs__tab[aria-current="page"] { color: var(--color-text); border-bottom-color: var(--color-accent); }
/* Contenido bajo las pestañas (Mi cuenta) */
.tab-panel { margin-top: var(--space-6); }
.tab-panel--narrow { max-width: 40rem; }
.grid--cards { --grid-min: 22rem; align-items: start; }
.audit-pagination { padding: var(--space-3) var(--space-5); }
.page-header--flush { margin-bottom: 0; } /* dentro de un .stack, que ya pone el espacio */

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--space-5); border-bottom: var(--border-width) solid var(--color-border); }
.toolbar .input-icon { flex: 1 1 16rem; max-width: 24rem; }

.pagination { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); font-size: var(--text-sm); color: var(--color-text-muted); }
.pagination__pages { display: flex; gap: var(--space-1); }

.segmented { display: inline-flex; padding: 2px; border: var(--border-width) solid var(--color-border); border-radius: var(--radius-md); background: var(--color-surface-2); }
.segmented__item { padding: var(--space-1) var(--space-3); border: 0; border-radius: var(--radius-sm); background: none; color: var(--color-text-muted); font-size: var(--text-sm); font-weight: var(--weight-semibold); }
.segmented__item[aria-pressed="true"] { background: var(--color-surface); color: var(--color-text); box-shadow: var(--shadow-sm); }

/* Menú desplegable con <details> (sin JavaScript) */
.menu { position: relative; }
.menu > summary { list-style: none; }
.menu > summary::-webkit-details-marker { display: none; }
.menu__list {
  position: absolute;
  right: 0;
  top: calc(100% + var(--space-1));
  z-index: var(--z-overlay);
  min-width: 12rem;
  padding: var(--space-1);
  background: var(--color-surface);
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
}
/* Menú dentro de una tabla con desplazamiento: se coloca sobre la página para que la tabla no lo recorte
   (lo posiciona static/app/dialogs.js). */
.menu__list--floating { position: fixed; right: auto; top: auto; }
.menu__item {
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  padding: var(--space-2) var(--space-3);
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--color-text);
  font-size: var(--text-md);
  text-align: left;
  text-decoration: none;
}
.menu__item:hover { background: var(--color-surface-2); }
.menu__item--danger { color: var(--color-danger); }

/* =========================================================================
   Diálogos y avisos
   ========================================================================= */
.dialog {
  width: min(100% - 2rem, 32rem);
  max-height: calc(100dvh - 2rem);
  margin: auto; /* el reset quita el centrado nativo de <dialog> */
  padding: 0;
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  color: var(--color-text);
  box-shadow: var(--shadow-lg);
}
.dialog::backdrop { background: var(--overlay); }
.dialog__header { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); padding: var(--space-4) var(--space-5); border-bottom: var(--border-width) solid var(--color-border); }
.dialog__body { padding: var(--space-5); }
.dialog__footer { display: flex; justify-content: flex-end; gap: var(--space-3); padding: var(--space-4) var(--space-5); border-top: var(--border-width) solid var(--color-border); }

.toast-region { position: fixed; right: var(--space-6); bottom: var(--space-6); z-index: var(--z-toast); display: flex; flex-direction: column; gap: var(--space-2); }
.toast {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 18rem;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  background: var(--color-surface-inverse);
  color: var(--color-text-inverse);
  box-shadow: var(--shadow-lg);
  animation: toast-in var(--duration-normal) var(--ease);
}
.toast .icon { color: var(--brand-orange); }
@keyframes toast-in { from { opacity: 0; transform: translateY(0.5rem); } }

/* =========================================================================
   Estados vacíos, carga y progreso
   ========================================================================= */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-12) var(--space-6);
  text-align: center;
  color: var(--color-text-muted);
}
.empty__icon {
  display: grid;
  place-items: center;
  width: 3rem;
  height: 3rem;
  border-radius: var(--radius-md);
  background: var(--color-accent-soft);
  color: var(--color-accent-text);
}
.empty__title { font-size: var(--text-lg); font-weight: var(--weight-semibold); color: var(--color-text); }

.skeleton {
  display: block;
  height: 1em;
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--color-surface-2) 25%, var(--color-border) 50%, var(--color-surface-2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite linear;
}
@keyframes shimmer { to { background-position: -200% 0; } }

.progress { height: 0.5rem; border-radius: var(--radius-full); background: var(--color-surface-2); overflow: hidden; }
.progress__bar { height: 100%; background: var(--progress-color, var(--color-accent)); border-radius: inherit; }

/* Barra horizontal simple para listas con proporción (motivos de rechazo, sitios) */
.bar-list { display: flex; flex-direction: column; gap: var(--space-3); list-style: none; padding: 0; }
.bar-list__row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--space-1) var(--space-3); font-size: var(--text-sm); }
.bar-list__row .progress { grid-column: 1 / -1; }

/* Definiciones clave: valor (fichas de empleado, detalle de registro) */
.dl { display: grid; grid-template-columns: minmax(8rem, max-content) 1fr; gap: var(--space-2) var(--space-6); }
.dl dt { color: var(--color-text-muted); font-size: var(--text-sm); }
.dl dd { min-width: 0; margin: 0; font-weight: var(--weight-medium); overflow-wrap: anywhere; }

/* Muestra de código QR / código de activación */
.code-box {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border: 1px dashed var(--color-border-strong);
  border-radius: var(--radius-md);
  font-family: var(--font-mono);
  font-size: var(--text-xl);
  letter-spacing: 0.15em;
}

/* =========================================================================
   Componentes agregados en el entregable 2 (mockups del portal)
   ========================================================================= */

/* Panel lateral (detalle de registro, detalle por día). Es un <dialog> abierto con showModal(). */
.drawer {
  position: fixed;
  inset: 0 0 0 auto;
  width: min(100%, 34rem);
  max-width: 100%;
  height: 100dvh;
  max-height: 100dvh;
  margin: 0;
  padding: 0;
  border: 0;
  border-left: var(--border-width) solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  box-shadow: var(--shadow-lg);
}
.drawer[open] { display: flex; flex-direction: column; animation: drawer-in var(--duration-normal) var(--ease); }
.drawer::backdrop { background: var(--overlay); }
.drawer__header { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-3); padding: var(--space-4) var(--space-5); border-bottom: var(--border-width) solid var(--color-border); }
.drawer__body { flex: 1; overflow-y: auto; padding: var(--space-5); }
.drawer__footer { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--space-3); padding: var(--space-4) var(--space-5); border-top: var(--border-width) solid var(--color-border); }
@keyframes drawer-in { from { transform: translateX(2rem); opacity: 0; } }

/* Sección con título pequeño dentro de paneles y tarjetas */
.section-title { margin-bottom: var(--space-3); font-size: var(--text-xs); font-weight: var(--weight-semibold); letter-spacing: 0.08em; text-transform: uppercase; color: var(--color-text-muted); }

/* Zona para soltar un archivo (carga masiva, foto de rostro) */
.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-8) var(--space-6);
  border: 2px dashed var(--color-border-strong);
  border-radius: var(--radius-lg);
  background: var(--color-surface-2);
  color: var(--color-text-muted);
  text-align: center;
}
.dropzone:hover, .dropzone:focus-within { border-color: var(--color-accent); }
.dropzone .icon { color: var(--color-accent-text); }

/* Pasos numerados (carga masiva) */
.steps { display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-6); padding: 0; list-style: none; counter-reset: step; }
.steps__item { display: flex; align-items: center; gap: var(--space-2); color: var(--color-text-muted); font-size: var(--text-sm); font-weight: var(--weight-semibold); counter-increment: step; }
.steps__item::before {
  content: counter(step);
  display: grid;
  place-items: center;
  width: 1.5rem;
  height: 1.5rem;
  border: var(--border-width) solid var(--color-border-strong);
  border-radius: 50%;
  font-size: var(--text-xs);
}
.steps__item[aria-current="step"] { color: var(--color-text); }
.steps__item[aria-current="step"]::before { background: var(--color-accent); border-color: var(--color-accent); color: var(--color-on-accent); }
.steps__item[data-done]::before { content: "✓"; background: var(--color-success-soft); border-color: var(--color-success); color: var(--color-success); }

/* Ranura de foto de referencia: sin mostrar la imagen (datos biométricos) */
.stack > .section-title { margin-bottom: 0; } /* dentro de .stack el espacio lo pone el gap */
.segmented { align-self: flex-start; }

.slots { display: grid; gap: var(--space-3); grid-template-columns: repeat(auto-fill, minmax(10.5rem, 1fr)); }
.slot {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  min-height: 8.5rem;
  padding: var(--space-4);
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
}
.slot__icon { display: grid; place-items: center; width: 2.25rem; height: 2.25rem; border-radius: var(--radius-md); background: var(--color-surface-2); color: var(--color-text-muted); }
.slot__title { font-weight: var(--weight-semibold); }
.slot__meta { font-size: var(--text-sm); color: var(--color-text-muted); }
.slot--empty { align-items: center; justify-content: center; border-style: dashed; background: none; color: var(--color-text-muted); font-size: var(--text-sm); }

/* Días de la semana como casillas (calendario, sitio) */
.weekdays { display: inline-flex; flex-wrap: wrap; gap: var(--space-1); }
.weekdays label { position: relative; }
.weekdays input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.weekdays span {
  display: grid;
  place-items: center;
  min-width: 2.5rem;
  height: 2rem;
  padding: 0 var(--space-2);
  border: var(--border-width) solid var(--color-border-strong);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--color-text-muted);
}
.weekdays input:checked + span { background: var(--color-accent-soft); border-color: var(--color-accent); color: var(--color-accent-text); }
.weekdays input:focus-visible + span { outline: var(--focus-width) solid var(--color-accent); outline-offset: 2px; }
.weekdays input:disabled + span { opacity: 0.6; }

/* Fila de tabla anulada: queda visible, tachada y fuera de los cálculos */
.table tr.is-void td { color: var(--color-text-subtle); }
.table tr.is-void td .strike { text-decoration: line-through; }
.table tbody tr[data-href] { cursor: pointer; }
.table tr.is-error td { background: var(--color-danger-soft); }
.table .cell-error { display: block; margin-top: var(--space-1); color: var(--color-danger); font-size: var(--text-xs); font-weight: var(--weight-semibold); }

/* Barra de filtros sobre una lista */
.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--space-3); padding: var(--space-4) var(--space-5); border-bottom: var(--border-width) solid var(--color-border); }
.filters .field { min-width: 9rem; }
.filters .input-icon { flex: 1 1 16rem; max-width: 22rem; }
.filters .select, .filters .input { min-height: 2.25rem; }

/* Gráficas con SVG en línea (sin librerías) */
.chart { width: 100%; height: auto; overflow: visible; font-size: 13px; }
.chart .chart__grid { stroke: var(--chart-grid); stroke-width: 1; }
.chart .chart__axis { fill: var(--chart-axis); }
.chart .chart__line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .chart__dot { stroke: var(--color-surface); stroke-width: 2; }
.legend { display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-4); font-size: var(--text-sm); color: var(--color-text-muted); }
.legend__key { display: inline-block; width: 0.75rem; height: 0.75rem; margin-right: var(--space-1); border-radius: 2px; vertical-align: -0.1rem; background: var(--key, var(--chart-1)); }

/* Mapa de calor (día × hora) */
.heatmap { display: grid; grid-template-columns: 2.5rem repeat(var(--cols, 24), minmax(0, 1fr)); gap: 2px; font-size: var(--text-xs); color: var(--color-text-muted); }
.heatmap__cell { aspect-ratio: 1; min-height: 0.9rem; border-radius: 2px; background: color-mix(in srgb, var(--chart-1) calc(var(--v, 0) * 100%), var(--color-surface-2)); }
.heatmap__label { display: flex; align-items: center; }
.heatmap__hour { text-align: center; }

/* Cifra grande con etiqueta, dentro de tarjetas o paneles */
.stat { display: flex; flex-direction: column; gap: var(--space-1); }
.stat__value { font-size: var(--text-2xl); font-weight: var(--weight-semibold); font-variant-numeric: tabular-nums; }
.stat__label { font-size: var(--text-sm); color: var(--color-text-muted); }

/* Fotos de evidencia y comparación con la referencia (se muestran 60 s) */
.photo { position: relative; aspect-ratio: 3 / 4; overflow: hidden; border: var(--border-width) solid var(--color-border); border-radius: var(--radius-lg); background: var(--color-surface-2); }
.photo img { width: 100%; height: 100%; object-fit: cover; }
.photo__timer { position: absolute; left: var(--space-2); bottom: var(--space-2); padding: 0.1rem var(--space-2); border-radius: var(--radius-sm); background: rgb(4 9 24 / 0.75); color: #ECEEF4; font-size: var(--text-xs); font-variant-numeric: tabular-nums; }
.compare { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-4); }
.compare figcaption { margin-top: var(--space-2); font-size: var(--text-sm); color: var(--color-text-muted); }
.compare figcaption strong { display: block; color: var(--color-text); }

/* Página de estado: errores 404/403/500, enlace vencido, mantenimiento */
.status-page { display: grid; place-items: center; min-height: 100vh; padding: var(--space-6); background: var(--color-bg); }
.status-page__card { display: flex; flex-direction: column; align-items: center; gap: var(--space-4); width: min(100%, 32rem); text-align: center; }
.status-page__logo { height: 2rem; width: auto; color: var(--brand-orange); }
.status-page__code { font-size: var(--text-4xl); font-weight: var(--weight-semibold); color: var(--color-accent-text); font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.status-page__card p { color: var(--color-text-muted); }
.status-page__actions { justify-content: center; }

/* Códigos de recuperación (se muestran una sola vez) */
.recovery-codes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-2) var(--space-6); padding: var(--space-4); border: 1px dashed var(--color-border-strong); border-radius: var(--radius-md); font-family: var(--font-mono); font-size: var(--text-md); letter-spacing: 0.08em; list-style: none; }

/* Lista de verificación con resultado (integridad, prueba de vida) */
.checklist { display: flex; flex-direction: column; gap: var(--space-2); padding: 0; list-style: none; font-size: var(--text-sm); }
.checklist li { display: flex; align-items: center; gap: var(--space-2); }
.checklist .icon { flex: none; }

@media (max-width: 40rem) {
  .drawer { width: 100%; border-left: 0; }
  .filters { padding: var(--space-3); }
  .heatmap { --cols: 12; }
}

/* Botón de tema: muestra el ícono del estado actual (lo fija theme.js) */
[data-theme-toggle] .theme-icon { display: none; }
[data-theme-toggle][data-theme-state="system"] .theme-icon--system,
[data-theme-toggle]:not([data-theme-state]) .theme-icon--system,
[data-theme-toggle][data-theme-state="light"] .theme-icon--light,
[data-theme-toggle][data-theme-state="dark"] .theme-icon--dark { display: block; }

@media (max-width: 40rem) {
  .hide-sm { display: none !important; }
  .kpi { padding: var(--space-4); }
  .kpi__value { font-size: var(--text-3xl); }
}
