/* =====================================================================
   TU KIOSKO — panel.css
   Estilos compartidos por auth.html, panel-negocio.html y panel-admin.html.
   Reusa los tokens de styles.css (:root, .btn, .icon-btn, .sr-only,
   .skip-link, :focus-visible) — este archivo NO redefine tokens, solo
   agrega los componentes que el sitio público no necesita: layout de
   login (Centered Card), sidebar de dashboard, tablas, modal, toasts,
   estados de carga/vacío/error.
   Cargar SIEMPRE después de styles.css.
   ===================================================================== */

/* ---------- 0. Loader de página completa (evita flash de contenido) ----------
   Mientras auth-guard.js resuelve si hay sesión, se muestra esto y el
   contenido real queda con [hidden] — nunca se pinta un dashboard vacío
   ni un formulario que luego hay que ocultar de golpe. */
.page-loader {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  background: var(--bg-primary);
}
.page-loader__spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--border-color);
  border-top-color: var(--brand-primary);
  border-radius: 50%;
  animation: girar 0.8s linear infinite;
}
.page-loader__text { color: var(--text-secondary); font-size: 0.95rem; }
@keyframes girar { to { transform: rotate(360deg); } }

/* ---------- 1. Layout general de panel (header simple + main) ---------- */
.panel-body { background: var(--bg-secondary); min-height: 100vh; }

.panel-topbar {
  position: sticky;
  top: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  min-height: var(--header-h);
  padding: var(--space-2) var(--space-4);
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border-color);
}
.panel-topbar .brand__name { font-size: 1.05rem; }

.panel-layout {
  display: flex;
  min-height: calc(100vh - var(--header-h));
}

/* Sidebar clásico (FRONTEND_SIDEBAR_PATTERNS 2.1): <7 ítems, sin jerarquía
   interna → no hace falta agrupar ni colapsar. En mobile se convierte en
   una barra horizontal de pestañas (no un drawer superpuesto): evita el
   anti-patrón de "sidebar fijo ocupando media pantalla en mobile" sin
   sumar la complejidad de un overlay para un panel de 2-4 secciones. */
.panel-sidebar {
  flex-shrink: 0;
  display: flex;
  flex-direction: row;
  gap: var(--space-1);
  overflow-x: auto;
  padding: var(--space-2) var(--space-3);
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border-color);
}
.panel-sidebar__link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 44px;
  padding: 0 var(--space-4);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
  border: 0;
  background: transparent;
}
.panel-sidebar__link:hover { background: var(--bg-secondary); color: var(--text-primary); }
.panel-sidebar__link.is-active { background: var(--brand-primary); color: var(--text-on-brand); }
.panel-sidebar__spacer { flex: 1; }
.panel-sidebar__signout {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 44px;
  padding: 0 var(--space-4);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
}
.panel-sidebar__signout:hover { background: var(--bg-secondary); }

.panel-main {
  flex: 1;
  min-width: 0;
  padding: var(--space-5) var(--space-4) var(--space-10);
}
.panel-main__inner { max-width: 960px; margin: 0 auto; display: flex; flex-direction: column; gap: var(--space-6); }

.panel-section-title {
  font-size: 1.3rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  margin-bottom: var(--space-1);
}
.panel-section-subtitle { color: var(--text-secondary); font-size: 0.95rem; }

@media (min-width: 1024px) {
  .panel-layout { display: flex; }
  .panel-sidebar {
    flex-direction: column;
    align-items: stretch;
    width: 240px;
    height: calc(100vh - var(--header-h));
    position: sticky;
    top: var(--header-h);
    border-bottom: 0;
    border-right: 1px solid var(--border-color);
    padding: var(--space-4) var(--space-3);
    overflow-y: auto;
  }
  .panel-sidebar__link { justify-content: flex-start; }
  .panel-main { padding: var(--space-6) var(--space-6) var(--space-10); }
}

/* ---------- 2. Auth (Centered Card — FRONTEND_AUTH_PATTERNS 2.2) ---------- */
.auth-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-secondary);
  padding: var(--space-5) var(--space-4);
}
.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: var(--space-6) var(--space-5);
}
.auth-card__brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  margin-bottom: var(--space-5);
}
.auth-card__title {
  font-size: 1.4rem;
  font-weight: 800;
  text-align: center;
  letter-spacing: -0.01em;
  margin-bottom: var(--space-1);
}
.auth-card__subtitle {
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: var(--space-5);
}

/* Tabs Login/Registro */
.auth-tabs {
  display: flex;
  gap: var(--space-1);
  background: var(--bg-secondary);
  border-radius: var(--radius-pill);
  padding: 4px;
  margin-bottom: var(--space-5);
}
.auth-tabs__btn {
  flex: 1;
  min-height: 40px;
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text-secondary);
  font-weight: 700;
  font-size: 0.9rem;
}
.auth-tabs__btn[aria-selected="true"] {
  background: var(--bg-primary);
  color: var(--brand-primary);
  box-shadow: var(--shadow-sm);
}

.auth-form { display: flex; flex-direction: column; gap: var(--space-4); }
.auth-form[hidden] { display: none; }

/* ---------- 3. Campos de formulario (compartido por auth + paneles) ---------- */
.field { display: flex; flex-direction: column; gap: var(--space-1); }
.field__label { font-weight: 700; font-size: 0.88rem; color: var(--text-primary); }
.field__hint { font-size: 0.8rem; color: var(--text-secondary); }
.field__input,
.field__select,
.field__textarea {
  min-height: 44px;
  padding: 0 var(--space-4);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-family: inherit;
  color: var(--text-primary);
  background: var(--bg-primary);
}
.field__textarea { min-height: 88px; padding: var(--space-3) var(--space-4); resize: vertical; }
.field__input:focus-visible,
.field__select:focus-visible,
.field__textarea:focus-visible {
  outline: 3px solid var(--brand-primary);
  outline-offset: 1px;
}
.field__input[aria-invalid="true"],
.field__select[aria-invalid="true"],
.field__textarea[aria-invalid="true"] {
  border-color: var(--brand-primary);
}
.field__error {
  font-size: 0.82rem;
  color: var(--brand-primary-dark);
  font-weight: 600;
}
.field__error:empty { display: none; }

/* Password con botón mostrar/ocultar */
.field__password-wrap { position: relative; }
.field__password-wrap .field__input { width: 100%; padding-right: var(--space-8); }
.field__toggle-pw {
  position: absolute;
  right: var(--space-1);
  top: 50%;
  transform: translateY(-50%);
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  background: transparent;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
}
.field__toggle-pw:hover { background: var(--bg-secondary); }

/* Checklist de requisitos de password (AUTH_PATTERNS 6) */
.pw-requisitos { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.pw-requisitos li { font-size: 0.82rem; color: var(--text-secondary); }
.pw-requisitos li.is-ok { color: #15803D; }
.pw-requisitos li .req-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1.5px solid var(--border-strong);
  flex-shrink: 0;
  vertical-align: -4px;
}
.pw-requisitos li .req-icon .icon { width: 11px; height: 11px; opacity: 0; transition: opacity 0.15s ease; }
.pw-requisitos li.is-ok .req-icon { border-color: #15803D; background: #15803D; }
.pw-requisitos li.is-ok .req-icon .icon { opacity: 1; color: #fff; }

/* Error / mensaje de formulario a nivel general (aria-live) */
.form-alert {
  border-radius: var(--radius-sm);
  padding: var(--space-3) var(--space-4);
  font-size: 0.88rem;
  font-weight: 600;
}
.form-alert--error { background: #FEF2F2; color: #B91C1C; border: 1px solid #FECACA; }
.form-alert--success { background: #F0FDF4; color: #15803D; border: 1px solid #BBF7D0; }
.form-alert--info { background: #EFF6FF; color: #1D4ED8; border: 1px solid #BFDBFE; }
.form-alert:empty { display: none; }

.auth-form__submit { width: 100%; }
.auth-form__switch { text-align: center; font-size: 0.88rem; color: var(--text-secondary); }
.auth-form__switch button {
  border: 0;
  background: transparent;
  color: var(--brand-primary);
  font-weight: 700;
}

/* ---------- 4. Estado de negocio (badges de status) ---------- */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-pill);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.status-badge--pending { background: #FEF3C7; color: #92400E; }
.status-badge--approved,
.status-badge--published { background: #DCFCE7; color: #15803D; }
.status-badge--rejected { background: #FEE2E2; color: #B91C1C; }
.status-badge--draft { background: #E5E7EB; color: #374151; }
.status-badge--expired { background: #E5E7EB; color: #6B7280; }

.info-card {
  background: var(--surface-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-sm);
}
.info-card__row { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); flex-wrap: wrap; }
.info-card__title { font-size: 1.1rem; font-weight: 800; }
.info-card__meta { color: var(--text-secondary); font-size: 0.88rem; margin-top: var(--space-1); }

/* ---------- 5. Tablas (FRONTEND_CRUD_PATTERNS 1/2 — nunca cards para listados) ---------- */
.data-table-wrap {
  background: var(--surface-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  overflow: auto;
  box-shadow: var(--shadow-sm);
}
.data-table { width: 100%; border-collapse: collapse; min-width: 560px; }
.data-table th,
.data-table td {
  text-align: left;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-color);
  font-size: 0.9rem;
}
.data-table th {
  color: var(--text-secondary);
  font-weight: 700;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  background: var(--bg-secondary);
}
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover { background: var(--bg-secondary); }
.data-table__actions { display: flex; gap: var(--space-2); flex-wrap: wrap; }

.table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
}

.btn--sm { min-height: 36px; padding: 0 var(--space-4); font-size: 0.85rem; border-radius: var(--radius-sm); }
.btn--outline { background: transparent; border: 1px solid var(--border-strong); color: var(--text-primary); }
.btn--outline:hover { background: var(--bg-secondary); }
.btn--danger { background: #FFF; border: 1px solid #FCA5A5; color: #B91C1C; }
.btn--danger:hover { background: #FEF2F2; }
.btn--ghost { background: transparent; border: 0; color: var(--text-secondary); }
.btn--ghost:hover { background: var(--bg-secondary); color: var(--text-primary); }
.btn[disabled] { opacity: 0.6; cursor: not-allowed; }

/* ---------- 6. Modal (<dialog>) — CRUD_PATTERNS 3/5 ---------- */
dialog.modal {
  border: 0;
  border-radius: var(--radius-lg);
  padding: 0;
  width: min(560px, 92vw);
  box-shadow: var(--shadow-lg);
}
dialog.modal::backdrop { background: rgba(17, 24, 39, 0.5); }
.modal__inner { padding: var(--space-5); display: flex; flex-direction: column; gap: var(--space-4); }
.modal__title { font-size: 1.15rem; font-weight: 800; }
.modal__body-text { color: var(--text-secondary); font-size: 0.92rem; }
.modal__footer { display: flex; justify-content: flex-end; gap: var(--space-3); }

/* ---------- 7. Estados: loading / empty / error (FRONTEND_STATES_PATTERNS) ---------- */
.state-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  text-align: center;
  padding: var(--space-8) var(--space-4);
  color: var(--text-secondary);
}
.state-block__icon { width: 32px; height: 32px; }
.state-block__title { font-weight: 700; color: var(--text-primary); }

/* Skeleton para filas de tabla */
.skeleton-row td { padding: var(--space-4); }
.skeleton-bar {
  height: 14px;
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--border-color) 25%, var(--bg-secondary) 50%, var(--border-color) 75%);
  background-size: 200% 100%;
  animation: skeleton-shine 1.2s ease-in-out infinite;
}
@keyframes skeleton-shine { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ---------- 8. Toasts ---------- */
.toast-region {
  position: fixed;
  bottom: var(--space-5);
  right: var(--space-5);
  z-index: 250;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  max-width: min(360px, calc(100vw - 2 * var(--space-5)));
}
.toast {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  font-size: 0.88rem;
  font-weight: 600;
  color: #fff;
  background: var(--text-primary);
  opacity: 1;
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.toast--success { background: #15803D; }
.toast--error { background: #B91C1C; }
.toast--info { background: #1D4ED8; }
.toast--out { opacity: 0; transform: translateY(6px); }

/* ---------- 9. Sin acceso (admin) ---------- */
.no-access {
  max-width: 480px;
  margin: var(--space-10) auto;
  text-align: center;
  padding: var(--space-6);
  background: var(--surface-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.no-access__icon { display: block; width: 40px; height: 40px; margin: 0 auto var(--space-3); color: var(--text-secondary); }

/* ---------- 10. Warning box (RPC sensible) ---------- */
.warning-box {
  border: 1px solid #FDE68A;
  background: #FFFBEB;
  color: #92400E;
  border-radius: var(--radius-sm);
  padding: var(--space-3) var(--space-4);
  font-size: 0.85rem;
}

/* ---------- 11. Grid de 2 columnas para formularios cortos en desktop ---------- */
.form-grid { display: grid; gap: var(--space-4); grid-template-columns: 1fr; }
@media (min-width: 640px) {
  .form-grid--2col { grid-template-columns: 1fr 1fr; }
}
