/**
 * Layout compartido: sidebar + topbar + variables de marca (teal).
 * Paleta: #00606c · #019391 · #00dfc3 · #ffffff
 */
:root {
  --surface: #e8f2f3;
  --card: #ffffff;
  --text: #0f2a2e;
  --muted: #5a6f72;
  --border: #c0dde1;
  --primary: #00606c;
  --primary-mid: #019391;
  --primary-hover: #004a52;
  --accent-bright: #00dfc3;
  --accent-soft: rgba(0, 223, 195, 0.14);
  --shell-navy: #232f3e;
  --warn-bg: #fef9c3;
  --warn-text: #854d0e;
  --danger-bg: #fee2e2;
  --danger-text: #991b1b;
  --danger: #dc2626;
  --shadow: 0 4px 24px rgba(0, 96, 108, 0.1);
  --radius: 16px;
  --radius-sm: 12px;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --surface: #141c1e;
  --card: #1c2629;
  --text: #e6f4f3;
  --muted: #8aa8ad;
  --border: #2f4248;
  --primary: #00dfc3;
  --primary-mid: #2dd4bf;
  --primary-hover: #14b8a6;
  --accent-bright: #5cf9e4;
  --accent-soft: rgba(0, 223, 195, 0.16);
  --warn-bg: rgba(250, 204, 21, 0.14);
  --warn-text: #fde68a;
  --danger-bg: rgba(220, 38, 38, 0.2);
  --danger-text: #fecaca;
  --danger: #f87171;
  --shadow: 0 4px 28px rgba(0, 0, 0, 0.4);
}

* {
  box-sizing: border-box;
}

html {
  /* Evita franjas del color --surface al hacer scroll / overscroll sobre el topbar */
  background-color: var(--card);
}

body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--surface);
  min-height: 100vh;
  min-height: 100dvh;
}

.layout {
  display: flex;
  align-items: stretch;
  min-height: 100vh;
  min-height: 100dvh;
}
.layout.is-guest .sidebar-auth-only {
  display: none;
}
.layout:not(.is-guest) .sidebar-guest-only {
  display: none;
}
.layout.is-guest .user-menu-wrap {
  display: none;
}

/* Registro público con ?ref= (clientes): solo el formulario, sin shell de asesores */
.layout.is-registro-publico-afiliado {
  display: block;
}

.layout.is-registro-publico-afiliado .sidebar,
.layout.is-registro-publico-afiliado > .main > header.topbar {
  display: none !important;
}

.layout.is-registro-publico-afiliado .main {
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
}

.btn-theme-floating-registro {
  display: none;
  position: fixed;
  bottom: 22px;
  right: 22px;
  z-index: 100;
  box-shadow: var(--shadow);
}

.layout.is-registro-publico-afiliado .btn-theme-floating-registro {
  display: flex;
}

.sidebar {
  width: 258px;
  flex-shrink: 0;
  background: var(--card);
  border-right: 1px solid var(--border);
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: sticky;
  top: 0;
  align-self: flex-start;
  min-height: 100vh;
  min-height: 100dvh;
  max-height: 100vh;
  max-height: 100dvh;
  overflow-y: auto;
  z-index: 30;
}

.logo-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
  padding: 0 6px;
}

.logo-dot {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-mid) 55%, var(--accent-bright) 120%);
  box-shadow: 0 4px 16px rgba(0, 96, 108, 0.35);
}

.logo-text {
  font-weight: 800;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
  color: var(--text);
}

.nav-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 14px 8px 6px;
}

.sidebar a {
  display: block;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
}

.sidebar a:hover {
  background: var(--surface);
  color: var(--text);
}

.sidebar a.active {
  background: var(--accent-soft);
  color: var(--primary);
  font-weight: 600;
}

.sidebar a.sidebar-guest-only {
  margin-top: auto;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  cursor: pointer;
  font-family: inherit;
  text-align: center;
  text-decoration: none;
  display: block;
}

.sidebar a.sidebar-guest-only:hover {
  border-color: var(--primary-mid);
  color: var(--primary);
}

.main {
  flex: 1;
  min-width: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* Anula márgenes de reglas tipo `header { margin: … }` en páginas con formularios */
header.topbar {
  margin: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 24px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 40;
  flex-shrink: 0;
  isolation: isolate;
  backface-visibility: hidden;
  transform: translateZ(0);
}

.search-wrap {
  flex: 1;
  max-width: 420px;
}

.topbar-search-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  margin: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
  box-sizing: border-box;
  flex-shrink: 0;
}

.topbar-search-toggle:focus-visible {
  outline: 2px solid var(--primary-mid);
  outline-offset: 2px;
}

.topbar-search-toggle svg {
  width: 22px;
  height: 22px;
}

.topbar-search-icon-close {
  display: none;
}

.topbar.topbar-search-open .topbar-search-icon-open {
  display: none;
}

.topbar.topbar-search-open .topbar-search-icon-close {
  display: block;
}

/* #appShellSearch: especificidad por id para que estilos globales de formularios en páginas (p. ej. pension.html)
   no pisen padding ni background y la lupa no se superponga al placeholder. */
header.topbar .search-wrap #appShellSearch {
  width: 100%;
  box-sizing: border-box;
  padding: 10px 14px 10px 42px;
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 14px;
  color: var(--text);
  background-color: var(--surface);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' fill='none' stroke='%235a6f72' stroke-width='2'%3E%3Ccircle cx='8' cy='8' r='6'/%3E%3Cpath d='M13 13l4 4'/%3E%3C/svg%3E");
  background-size: 18px 18px;
  background-repeat: no-repeat;
  background-position: 12px center;
}

header.topbar .search-wrap #appShellSearch::placeholder {
  color: var(--muted);
  opacity: 0.85;
}

html[data-theme="dark"] header.topbar .search-wrap #appShellSearch {
  background-color: var(--surface);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' fill='none' stroke='%238aa8ad' stroke-width='2'%3E%3Ccircle cx='8' cy='8' r='6'/%3E%3Cpath d='M13 13l4 4'/%3E%3C/svg%3E");
  background-size: 18px 18px;
  background-repeat: no-repeat;
  background-position: 12px center;
}

.user-menu-wrap {
  position: relative;
  flex-shrink: 0;
}

.user-menu-trigger {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  margin: 0;
  padding: 4px 8px 4px 4px;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
}

.user-menu-trigger:hover {
  background: var(--surface);
}

.user-menu-trigger:focus-visible {
  outline: 2px solid var(--primary-mid);
  outline-offset: 2px;
}

.user-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-mid));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 15px;
}

.user-meta {
  line-height: 1.25;
}

.user-meta .name {
  font-weight: 600;
  color: var(--text);
}

.user-meta .email {
  color: var(--muted);
  font-size: 12px;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-menu-dd {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  min-width: 220px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 6px;
  z-index: 60;
}

.user-menu-dd.open {
  display: block;
}

.user-menu-item {
  display: block;
  width: 100%;
  padding: 10px 12px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
  box-sizing: border-box;
}

a.user-menu-item {
  text-decoration: none;
}

.user-menu-item:hover {
  background: var(--surface);
}

a.user-menu-item.active {
  background: var(--accent-soft);
  color: var(--primary);
  font-weight: 600;
}

.user-menu-logout {
  color: var(--danger);
  font-weight: 600;
}

.user-menu-logout:hover {
  background: var(--danger-bg);
  color: var(--danger-text);
}

.menu-mobile {
  display: none;
  position: relative;
}

.menu-mobile-btn {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  cursor: pointer;
  color: var(--text);
  font-family: inherit;
  box-sizing: border-box;
}

.menu-mobile-btn:focus-visible {
  outline: 2px solid var(--primary-mid);
  outline-offset: 2px;
}

.menu-mobile-btn .menu-hamburger-line {
  display: block;
  width: 18px;
  height: 2px;
  border-radius: 1px;
  background: currentColor;
  flex-shrink: 0;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.menu-mobile-btn[aria-expanded="true"] .menu-hamburger-line:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}

.menu-mobile-btn[aria-expanded="true"] .menu-hamburger-line:nth-child(2) {
  opacity: 0;
}

.menu-mobile-btn[aria-expanded="true"] .menu-hamburger-line:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

.menu-mobile-dd {
  display: none;
  position: absolute;
  left: 0;
  top: 100%;
  margin-top: 6px;
  min-width: 240px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 8px;
  z-index: 50;
}

.menu-mobile-dd.open {
  display: block;
}

.menu-mobile-dd a {
  display: block;
  padding: 8px 10px;
  color: var(--text);
  text-decoration: none;
  border-radius: 8px;
  font-size: 14px;
}

.menu-mobile-dd a:hover {
  background: var(--surface);
}

.menu-mobile-dd a.active {
  background: var(--accent-soft);
  color: var(--primary);
  font-weight: 600;
}

.btn-theme-toggle {
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.btn-theme-toggle:hover {
  border-color: var(--primary-mid);
  color: var(--primary);
}

.btn-theme-toggle:focus-visible {
  outline: 2px solid var(--primary-mid);
  outline-offset: 2px;
}

.btn-theme-toggle svg {
  width: 20px;
  height: 20px;
}

.btn-theme-toggle .theme-icon-sun {
  display: none;
}

html[data-theme="dark"] .btn-theme-toggle .theme-icon-moon {
  display: none;
}

html[data-theme="dark"] .btn-theme-toggle .theme-icon-sun {
  display: block;
}

/* Tema con icono + texto (menú usuario, login, sidebar admin) */
.user-menu-item.user-menu-theme {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-menu-theme-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  color: var(--text);
}

.user-menu-theme-icon svg {
  width: 18px;
  height: 18px;
}

.user-menu-theme-icon .theme-icon-sun {
  display: none;
}

html[data-theme="dark"] .user-menu-theme-icon .theme-icon-moon {
  display: none;
}

html[data-theme="dark"] .user-menu-theme-icon .theme-icon-sun {
  display: block;
}

.user-menu-theme-label {
  flex: 1;
  min-width: 0;
  text-align: left;
}

.sidebar .user-menu-theme {
  margin-top: 12px;
}

.login-theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.login-theme-toggle:hover {
  border-color: var(--primary-mid);
  color: var(--primary);
}

.login-theme-toggle:focus-visible {
  outline: 2px solid var(--primary-mid);
  outline-offset: 2px;
}

.content {
  padding: 24px;
  flex: 1;
  min-height: 0;
  display: flow-root;
}

@media (max-width: 960px) {
  .layout {
    flex-direction: column;
  }
  .sidebar {
    display: none;
  }
  .menu-mobile {
    display: block;
  }
  /* Barra de búsqueda visible en móvil: segunda fila a ancho completo */
  .topbar {
    flex-wrap: wrap;
    row-gap: 10px;
    column-gap: 12px;
  }
  .topbar .menu-mobile {
    order: 1;
    flex-shrink: 0;
  }
  .topbar-search-toggle {
    display: inline-flex;
    order: 2;
    margin-left: auto;
    flex-shrink: 0;
  }
  .topbar .user-menu-wrap {
    order: 3;
    flex-shrink: 0;
  }
  /* Búsqueda global: oculta en móvil hasta pulsar la lupa (mismo hueco que el antiguo tema). */
  .topbar .search-wrap:has(#appShellSearch) {
    order: 4;
    flex: 1 0 100%;
    max-width: none;
    min-width: 0;
    width: 100%;
    display: none;
  }
  .topbar.topbar-search-open .search-wrap:has(#appShellSearch) {
    display: block;
  }
  .topbar .search-wrap:empty {
    display: none;
  }

  /* Solo avatar con iniciales: nombre y email siguen en el menú desplegable */
  .topbar .user-menu-wrap .user-meta {
    display: none;
  }

  .topbar .user-menu-trigger {
    padding: 4px;
  }
}

/* Suscripción cancelada: navegación mínima (pago, soporte, listado solo lectura, dashboard difuminado) */
.hablemos-sub-lock-banner {
  margin: 0;
  padding: 12px 16px;
  background: linear-gradient(135deg, rgba(180, 83, 9, 0.12), rgba(0, 96, 108, 0.08));
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
}
.hablemos-sub-lock-banner p {
  margin: 0;
}
.hablemos-sub-lock-banner a {
  color: var(--primary-mid);
  font-weight: 600;
}

.layout.sub-lock-canceled .sidebar a[href]:not([href="dashboard.html"]):not([href="mi-suscripcion.html"]):not([href="mis-tickets.html"]):not([href="revisar-clientes.html"]) {
  display: none !important;
}

.layout.sub-lock-canceled .menu-mobile-dd a[href]:not([href="dashboard.html"]):not([href="mi-suscripcion.html"]):not([href="mis-tickets.html"]):not([href="revisar-clientes.html"]) {
  display: none !important;
}

.layout.sub-lock-canceled .topbar .search-wrap:has(#appShellSearch),
.layout.sub-lock-canceled .topbar .topbar-search-toggle {
  display: none !important;
}

.layout.sub-lock-canceled #userMenuDd a[href*="mis-datos-mandatario"] {
  display: none !important;
}

.layout.sub-lock-canceled .header-links {
  display: none !important;
}

html[data-shell-page="dashboard.html"] .layout.sub-lock-canceled .main > .content {
  filter: blur(7px);
  pointer-events: none;
  user-select: none;
  position: relative;
}

.layout.sub-lock-canceled .client-row.sub-lock-readonly-row {
  cursor: default;
}
.layout.sub-lock-canceled .client-row.sub-lock-readonly-row:hover {
  background: transparent;
}

/* iOS Safari: reglas tipo `input { width:100%; padding:… }` o `.modal input` no deben aplicarse a radios/checkbox */
input[type="radio"],
input[type="checkbox"] {
  width: auto !important;
  max-width: none;
  flex-shrink: 0;
  min-width: 1.15em;
  min-height: 1.15em;
  margin: 0;
  padding: 0 !important;
  box-sizing: border-box;
  border: none;
  background: transparent;
  box-shadow: none !important;
  vertical-align: middle;
  accent-color: var(--primary-mid);
}

/* Barra flotante inferior: trial / mora (suscripción) */
body.hablemos-has-float-sub {
  padding-bottom: calc(7.5rem + env(safe-area-inset-bottom, 0px));
}

.hablemos-float-sub-wrap {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 9500;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
  pointer-events: none;
  display: flex;
  justify-content: center;
  box-sizing: border-box;
}

.hablemos-float-sub-inner {
  pointer-events: auto;
  max-width: 720px;
  width: 100%;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  font-size: 14px;
  line-height: 1.45;
  color: var(--text);
  background: var(--card);
}

.hablemos-float-sub-trial .hablemos-float-sub-inner {
  background: linear-gradient(135deg, rgba(0, 96, 108, 0.08), rgba(0, 223, 195, 0.1));
  border-color: var(--primary-mid);
}

.hablemos-float-sub-mora .hablemos-float-sub-inner {
  background: var(--warn-bg);
  border-color: rgba(180, 83, 9, 0.35);
  color: var(--text);
}

.hablemos-float-sub-body {
  flex: 1;
  min-width: 0;
}

.hablemos-float-sub-body p {
  margin: 0 0 0.5em;
}

.hablemos-float-sub-body p:last-child {
  margin-bottom: 0;
}

.hablemos-float-sub-meta {
  font-size: 13px;
  color: var(--muted);
}

.hablemos-float-sub-mora .hablemos-float-sub-meta {
  color: var(--text);
  opacity: 0.92;
}

.hablemos-float-sub-actions {
  margin-top: 0.35em !important;
}

.hablemos-float-sub-cta {
  display: inline-block;
  font-weight: 600;
  color: var(--primary-mid);
  text-decoration: underline;
}

.hablemos-float-sub-cta:hover {
  color: var(--primary-hover);
}

.hablemos-float-sub-close {
  flex-shrink: 0;
  margin: -4px -6px 0 0;
  padding: 4px 8px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  border-radius: 8px;
}

.hablemos-float-sub-close:hover {
  color: var(--text);
  background: var(--accent-soft);
}

/* Recordatorios / agenda: aviso de estado Telegram */
.hablemos-telegram-setup-bar {
  margin: 0 0 16px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  line-height: 1.45;
}

.hablemos-telegram-setup-bar-missing {
  border: 1px solid rgba(220, 38, 38, 0.45);
  background: var(--danger-bg);
  color: var(--danger-text);
}

.hablemos-telegram-setup-bar-ok {
  border: 1px solid color-mix(in srgb, var(--primary-mid) 35%, var(--border));
  background: color-mix(in srgb, var(--primary-mid) 12%, transparent);
  color: var(--text);
}

.hablemos-telegram-setup-bar p {
  margin: 0 0 0.5em;
}

.hablemos-telegram-setup-bar p:last-child {
  margin-bottom: 0;
}

.hablemos-telegram-setup-actions {
  margin-top: 0.25em !important;
}

.hablemos-telegram-setup-btn {
  display: inline-block;
  padding: 7px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--primary-mid);
  font-weight: 600;
  text-decoration: none;
}

.hablemos-telegram-setup-btn:hover {
  border-color: var(--primary-mid);
  color: var(--primary-hover);
}
