/* ============================================================
   LUDI PADEL — Estilos globales
   ============================================================ */

/* ---- Reset & base ---- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  /* Paleta de colores — basada en el logo Ludi Padel */
  --color-primary:      #1e2d5a;   /* azul marino oscuro ("Ludi") */
  --color-primary-dark: #131d3d;   /* azul marino más profundo */
  --color-primary-light:#3a5299;   /* azul medio */
  --color-accent:       #f08020;   /* naranja ("PADEL") */
  --color-accent-dark:  #c8660f;   /* naranja oscuro */
  --color-secondary:    #56b4d0;   /* azul cian (robot) */
  --color-bg:           #f0f3f8;   /* fondo ligeramente azulado */
  --color-surface:      #ffffff;
  --color-text:         #1a2035;
  --color-text-muted:   #6b7a99;
  --color-border:       #d8dde8;
  --color-error:        #dc3545;
  --color-success:      #2a9d5c;
  --login-bg-gradient:  linear-gradient(145deg, #131d3d 0%, #1e2d5a 55%, #2e4080 100%);

  /* Tipografía */
  --font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-size-sm:  0.875rem;
  --font-size-base: 1rem;
  --font-size-lg:  1.125rem;
  --font-size-xl:  1.375rem;
  --font-size-2xl: 1.75rem;

  /* Espaciado */
  --space-xs:  0.25rem;
  --space-sm:  0.5rem;
  --space-md:  1rem;
  --space-lg:  1.5rem;
  --space-xl:  2rem;
  --space-2xl: 3rem;

  /* Radios y sombras */
  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --radius-full: 9999px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.10);
  --shadow-md: 0 4px 16px rgba(0,0,0,.12);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.16);

  /* Layout */
  --header-height: 56px;
  --bottom-nav-height: 64px;
}

/* ---- Tema oscuro (TEMA_APP = 6) ---- */
html[data-theme="dark"] {
  --color-bg:           #111318;
  --color-surface:      #1c1f2b;
  --color-text:         #e2e8f4;
  --color-text-muted:   #8896b3;
  --color-border:       #2c3148;
  /* primary-light se sobreescribe para tener contraste legible sobre superficies oscuras */
  --color-primary-light: #7b9fd4;
  --shadow-sm:          0 1px 3px rgba(0,0,0,.35);
  --shadow-md:          0 4px 16px rgba(0,0,0,.50);
  --shadow-lg:          0 8px 32px rgba(0,0,0,.60);
}

/* Alertas inline */
html[data-theme="dark"] .alert-error   { background: rgba(220,53,69,.15);  border-color: rgba(220,53,69,.35);  color: #f87171; }
html[data-theme="dark"] .alert-success { background: rgba(42,157,92,.15);  border-color: rgba(42,157,92,.35);  color: #4ade80; }
html[data-theme="dark"] .alert-info    { background: rgba(28,126,214,.15); border-color: rgba(28,126,214,.35); color: #60a5fa; }

/* Inputs */
html[data-theme="dark"] .form-input { background: #151822; }
html[data-theme="dark"] .form-input:focus { box-shadow: 0 0 0 3px rgba(123,159,212,.25); }

/* Botón secundario: primary demasiado oscuro sobre fondo oscuro */
html[data-theme="dark"] .btn-secondary {
  color: var(--color-primary-light);
  border-color: var(--color-primary-light);
}
html[data-theme="dark"] .btn-secondary:hover {
  background: var(--color-primary-light);
  color: #fff;
}

/* Bottom nav */
html[data-theme="dark"] .bottom-nav { box-shadow: 0 -2px 8px rgba(0,0,0,.35); }
html[data-theme="dark"] .bottom-nav-btn.active { color: var(--color-primary-light); }

/* UI sheets (ui.js) */
html[data-theme="dark"] .ludi-sheet-icon.icon-error            { background: rgba(220,53,69,.20); }
html[data-theme="dark"] .ludi-sheet-icon.icon-error svg        { fill: #f87171; }
html[data-theme="dark"] .ludi-sheet-icon.icon-confirm          { background: rgba(123,159,212,.20); }
html[data-theme="dark"] .ludi-sheet-icon.icon-confirm svg      { fill: var(--color-primary-light); }

html, body {
  height: 100%;
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
}

img { max-width: 100%; display: block; }

button {
  cursor: pointer;
  border: none;
  background: none;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
  outline: none;
}

a { color: inherit; text-decoration: none; }

/* ---- Utilidades ---- */
.hidden { display: none !important; }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
}

/* ---- Shell principal ---- */
#app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

/* ---- Header ---- */
.app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-height);
  background: var(--color-primary-dark);
  color: #fff;
  z-index: 100;
  box-shadow: var(--shadow-md);
}

.header-inner {
  display: flex;
  align-items: center;
  height: 100%;
  padding: 0 var(--space-md);
  gap: var(--space-md);
}

.header-logo {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  flex-shrink: 0;
}

.header-logo img {
  height: 32px;
  width: auto;
}

.header-title {
  font-size: var(--font-size-lg);
  font-weight: 700;
  letter-spacing: .5px;
  white-space: nowrap;
}

/* Nav en header (solo escritorio) */
.header-nav {
  display: none;
  flex: 1;
  justify-content: center;
  gap: var(--space-sm);
}

.nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: var(--space-xs) var(--space-md);
  color: rgba(255,255,255,.75);
  border-radius: var(--radius-sm);
  font-size: var(--font-size-sm);
  transition: background .2s, color .2s;
}

.nav-btn svg {
  width: 20px; height: 20px;
  fill: currentColor;
}

.nav-btn:hover,
.nav-btn.active {
  background: rgba(255,255,255,.12);
  color: #fff;
}

/* Botón de perfil en cabecera (móvil con partidas activo) */
.btn-header-perfil {
  margin-left: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: none;
  border: none;
  padding: 4px;
  cursor: pointer;
  border-radius: 50%;
  color: rgba(255,255,255,.85);
  transition: background .2s, color .2s;
}
.btn-header-perfil:hover { background: rgba(255,255,255,.15); }
.btn-header-perfil .bnav-avatar { width: 30px; height: 30px; font-size: .65rem; }

html[data-theme="dark"] .btn-header-perfil {
  color: var(--color-primary-light);
}
html[data-theme="dark"] .btn-header-perfil:hover {
  background: rgba(123,159,212,.15);
}

/* Ocultar botón perfil del bottom-nav cuando partidas está activo */
.bottom-nav--sin-perfil .bottom-nav-btn[data-section="perfil"] { display: none; }

/* Botón logout */
.btn-logout {
  margin-left: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  border-radius: var(--radius-full);
  color: rgba(255,255,255,.8);
  transition: background .2s, color .2s;
}

.btn-logout svg {
  width: 20px; height: 20px;
  fill: currentColor;
}

.btn-logout:hover {
  background: rgba(255,255,255,.15);
  color: #fff;
}

/* ---- Contenido principal ---- */
.app-content {
  flex: 1;
  /* El padding se ajusta dinámicamente con JS cuando el header/bottomnav están visibles */
}

.app-content.with-header {
  padding-top: var(--header-height);
}

.app-content.with-bottom-nav {
  padding-bottom: var(--bottom-nav-height);
}

/* ---- Bottom nav (móvil) ---- */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--bottom-nav-height);
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  display: flex;
  z-index: 100;
  box-shadow: 0 -2px 8px rgba(0,0,0,.08);
}

.bottom-nav-btn {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--color-text-muted);
  font-size: 0.7rem;
  font-weight: 500;
  transition: color .2s;
  padding-bottom: env(safe-area-inset-bottom, 0);
  overflow: hidden;
}

.bottom-nav-btn > span:last-child {
  width: 100%;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 2px;
}

.bottom-nav-btn svg {
  width: 22px; height: 22px;
  fill: currentColor;
}

.bnav-avatar {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-light));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .6rem;
  font-weight: 800;
  color: #fff;
  letter-spacing: .5px;
  flex-shrink: 0;
  overflow: hidden;
}

.bottom-nav-btn.active {
  color: var(--color-primary);
}

/* ---- Responsive: escritorio ---- */
/* pointer:fine = ratón → escritorio aunque el viewport sea estrecho por zoom del sistema */
@media (pointer: fine), (min-width: 768px) {
  .header-nav   { display: flex; }
  .btn-hamburger { display: none; }
  .bottom-nav   { display: none !important; }

  .app-content.with-bottom-nav {
    padding-bottom: 0;
  }

  /* Tipografía más compacta */
  html {
    font-size: 15px;
  }

  /* Botones no ocupan todo el ancho (excepto en login) */
  .btn-primary,
  .btn-secondary {
    width: auto;
    min-width: 160px;
    padding: .6rem var(--space-lg);
  }

  /* En el login los botones siguen a ancho completo */
  .login-form-wrap .btn-primary,
  .login-form-wrap .btn-secondary {
    width: 100%;
  }

  /* Inputs ligeramente más compactos */
  .form-input {
    padding: .6rem .875rem;
  }

  /* Tarjetas con menos padding */
  .card {
    padding: var(--space-md);
  }

  /* Secciones pueden ser algo más anchas */
  .lp-page,
  .pistas-page,
  .reservas-page,
  .perfil-page,
  .partida-page,
  .clases-page,
  .bonos-page,
  .info-page,
  .donde-page {
    max-width: 860px;
  }
}

/* ---- Componentes compartidos ---- */

/* Tarjeta */
.card {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: var(--space-lg);
}

/* Botón primario */
.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  width: 100%;
  padding: .875rem var(--space-lg);
  background: var(--color-accent);
  color: #fff;
  font-size: var(--font-size-base);
  font-weight: 600;
  border-radius: var(--radius-md);
  transition: background .2s, transform .1s, box-shadow .2s;
  letter-spacing: .3px;
}

.btn-primary:hover  { background: var(--color-accent-dark); box-shadow: var(--shadow-sm); }
.btn-primary:active { transform: scale(.98); }
.btn-primary:disabled {
  opacity: .6;
  cursor: not-allowed;
  transform: none;
}

/* Botón secundario */
.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  width: 100%;
  padding: .875rem var(--space-lg);
  background: transparent;
  color: var(--color-primary);
  font-size: var(--font-size-base);
  font-weight: 600;
  border: 2px solid var(--color-primary);
  border-radius: var(--radius-md);
  transition: background .2s, color .2s;
}

.btn-secondary:hover {
  background: var(--color-primary);
  color: #fff;
}

/* Campo de formulario */
.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.form-label {
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: .5px;
}

.form-input {
  width: 100%;
  padding: .875rem var(--space-md);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: var(--font-size-base);
  font-family: inherit;
  color: var(--color-text);
  background: var(--color-surface);
  transition: border-color .2s, box-shadow .2s;
  outline: none;
  -webkit-appearance: none;
}

.form-input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(30,45,90,.15);
}

.form-input.error {
  border-color: var(--color-error);
  box-shadow: 0 0 0 3px rgba(220,53,69,.12);
}

/* Mensaje de error inline */
.form-error {
  font-size: var(--font-size-sm);
  color: var(--color-error);
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

/* Alerta / toast */
.alert {
  padding: var(--space-md) var(--space-lg);
  border-radius: var(--radius-md);
  font-size: var(--font-size-sm);
  font-weight: 500;
}

.alert-error   { background: #fff0f0; color: var(--color-error);   border: 1px solid #ffc9c9; }
.alert-success { background: #f0fff4; color: var(--color-success);  border: 1px solid #b2f2bb; }
.alert-info    { background: #e7f5ff; color: #1c7ed6;               border: 1px solid #a5d8ff; }

/* Spinner de carga */
.spinner {
  display: inline-block;
  width: 20px; height: 20px;
  border: 2.5px solid rgba(255,255,255,.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Botón hamburguesa ---- */
.btn-hamburger {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  border-radius: var(--radius-full);
  color: rgba(255,255,255,.85);
  flex-shrink: 0;
  transition: background .2s, color .2s;
}

.btn-hamburger:hover {
  background: rgba(255,255,255,.15);
  color: #fff;
}

/* ---- Overlay del drawer ---- */
.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 150;
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s ease;
}

.drawer-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

/* ---- Panel del drawer ---- */
.app-drawer {
  position: fixed;
  top: 0; left: 0;
  width: 280px;
  height: 100%;
  background: var(--color-surface);
  z-index: 160;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  transform: translateX(-100%);
  transition: transform .3s cubic-bezier(.32,1,.6,1);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.app-drawer.open {
  transform: translateX(0);
}

/* ---- Cabecera del drawer ---- */
.drawer-header {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 0 var(--space-md) 0 var(--space-lg);
  height: var(--header-height);
  background: var(--color-primary-dark);
  flex-shrink: 0;
}

.drawer-logo {
  height: 28px;
  width: auto;
}

.drawer-logo-title {
  flex: 1;
  font-size: var(--font-size-base);
  font-weight: 700;
  color: #fff;
  letter-spacing: .4px;
}

.drawer-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px; height: 32px;
  border-radius: var(--radius-full);
  color: rgba(255,255,255,.8);
  transition: background .2s;
  flex-shrink: 0;
}

.drawer-close:hover { background: rgba(255,255,255,.15); }

/* ---- Usuario ---- */
.drawer-user {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-lg);
  border-bottom: 1px solid var(--color-border);
}

.drawer-user-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-light));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .75rem;
  font-weight: 800;
  color: #fff;
  letter-spacing: .5px;
  flex-shrink: 0;
}

.drawer-user-nombre {
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--color-text);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- Navegación del drawer ---- */
.drawer-nav {
  flex: 1;
  padding: var(--space-sm) 0;
}

.drawer-divider {
  height: 1px;
  background: var(--color-border);
  margin: var(--space-sm) var(--space-md);
}

/* ── Badges de notificación ── */

/* Dot inline — aparece al final del texto en el drawer */
.notif-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #e53935;
  flex-shrink: 0;
  margin-left: auto;
  align-self: center;
}
.notif-dot.hidden { display: none; }

/* Dot absoluto en la esquina del botón hamburguesa */
.btn-hamburger {
  position: relative;
}
#hamburger-notif-dot {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 7px;
  height: 7px;
  margin: 0;
}

/* Badge ::after para header-nav y bottom-nav (icono + texto pequeño) */
.nav-btn.has-badge,
.bottom-nav-btn.has-badge {
  position: relative;
}
/* header nav: posición absoluta normal */
.nav-btn.has-badge::after {
  content: '';
  position: absolute;
  top: 2px;
  right: 4px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #e53935;
  pointer-events: none;
}
/* bottom-nav: el botón ocupa todo el ancho, centrar el badge sobre el icono */
.bottom-nav-btn.has-badge:not([data-section="perfil"])::after {
  content: '';
  position: absolute;
  top: 4px;
  left: calc(50% + 6px);
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #e53935;
  pointer-events: none;
  z-index: 1;
}

.bottom-nav-btn[data-section="perfil"].has-badge .bnav-avatar {
  box-shadow: 0 0 0 2.5px #e53935;
  animation: perfil-badge-pulse 1.8s ease-in-out infinite;
}

@keyframes perfil-badge-pulse {
  0%, 100% { box-shadow: 0 0 0 2.5px #e53935; }
  50%       { box-shadow: 0 0 0 4px rgba(229,57,53,.35); }
}

.drawer-group-label {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  padding: var(--space-xs) var(--space-md) var(--space-xs);
  pointer-events: none;
  user-select: none;
}

/* ---- Item del drawer ---- */
.drawer-item {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  width: 100%;
  padding: 9px var(--space-lg);
  background: none;
  border: none;
  color: var(--color-text);
  font-size: var(--font-size-sm);
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  transition: background .15s, color .15s;
}

.drawer-item svg { flex-shrink: 0; fill: var(--color-text-muted); }

.drawer-item:hover,
.drawer-item.active {
  background: var(--color-bg);
  color: var(--color-primary);
}

.drawer-item:hover svg,
.drawer-item.active svg {
  fill: var(--color-primary);
}

.drawer-item span:first-of-type { flex: 1; }

/* Item deshabilitado (Bonos) */
.drawer-item--disabled {
  opacity: .55;
  cursor: default;
}

/* Badge "Próximamente" */
.drawer-soon-badge {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .4px;
  padding: 2px 7px;
  border-radius: var(--radius-full);
  background: var(--color-accent);
  color: #fff;
  flex-shrink: 0;
}

/* Ítem expandible (Contacto) */
.drawer-item--expandable .drawer-chevron {
  fill: var(--color-text-muted);
  transition: transform .25s ease;
  flex-shrink: 0;
}

.drawer-item--expandable[aria-expanded="true"] .drawer-chevron {
  transform: rotate(180deg);
}

/* Ítem externo (Energía) */
.drawer-external-icon {
  fill: var(--color-text-muted);
  flex-shrink: 0;
}

/* ---- Sub-menú (Contacto) ---- */
.drawer-submenu {
  overflow: hidden;
  max-height: 0;
  transition: max-height .3s ease;
}

.drawer-submenu.open {
  max-height: 120px;
}

.drawer-subitem {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: 11px var(--space-lg) 11px calc(var(--space-lg) + 36px);
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
  font-weight: 500;
  transition: background .15s, color .15s;
  text-decoration: none;
}

.drawer-subitem svg { fill: currentColor; flex-shrink: 0; }

.drawer-subitem:hover {
  background: var(--color-bg);
  color: var(--color-text);
}

.drawer-subitem.active {
  color: var(--color-primary);
  font-weight: 600;
}

/* Ítem cerrar sesión */
.drawer-item--logout        { color: var(--color-error); }
.drawer-item--logout svg    { fill: var(--color-error); }
.drawer-item--logout:hover  { background: #fff5f5; color: var(--color-error); }
html[data-theme="dark"] .drawer-item--logout:hover { background: rgba(220,53,69,.12); }

.drawer-version {
  margin-top: auto;
  padding: 8px 16px;
  font-size: 11px;
  color: var(--color-text-muted, #888);
  opacity: 0.6;
  user-select: none;
}

/* ---- Tema oscuro ---- */
html[data-theme="dark"] .app-drawer           { background: var(--color-surface); }
html[data-theme="dark"] .drawer-item:hover,
html[data-theme="dark"] .drawer-item.active   { background: #22253a; color: var(--color-primary-light); }
html[data-theme="dark"] .drawer-item:hover svg,
html[data-theme="dark"] .drawer-item.active svg { fill: var(--color-primary-light); }
html[data-theme="dark"] .drawer-subitem:hover { background: #22253a; }

/* ---- Página vacía / placeholder ---- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-md);
  padding: var(--space-2xl);
  text-align: center;
  color: var(--color-text-muted);
}

.empty-state svg {
  width: 64px; height: 64px;
  fill: var(--color-border);
}

.empty-state h3 {
  font-size: var(--font-size-lg);
  color: var(--color-text);
}
