/*
 * Novadex — capa móvil del shell (menú drawer, topbar, overflow).
 * Mantener el mismo max-width que: index.html (media del <link>), js/novadex-mobile.js (MOBILE_MAX_WIDTH).
 * Los módulos en js/*.js suelen usar innerWidth <= 900 para plantillas; el shell debe usar el mismo umbral.
 */
@media (max-width: 900px) {
  :root {
    --app-vh: 100dvh;
    /* Altura real la sincroniza JS; fallback un poco mayor para la barra “app” */
    --mobile-footer-h: 76px;
    /* Espacio bajo header fijo + marca que sobresale (solo móvil) */
    --mobile-content-pad-top: calc(108px + env(safe-area-inset-top, 0px));
    --mobile-content-pad-bottom: calc(
      var(--mobile-footer-h, 76px) + 26px + env(safe-area-inset-bottom, 0px)
    );
  }

  html,
  body {
    overflow-x: hidden !important;
    width: 100% !important;
    max-width: 100% !important;
  }

  .app-container,
  .mobile-app-container,
  .mobile-main-layout,
  .mobile-content-area,
  #module-content {
    overflow-x: hidden !important;
    max-width: 100% !important;
    width: 100% !important;
  }

  body.mobile-lock {
    overflow: hidden;
  }

  .mobile-nav-toggle {
    display: none !important;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    position: fixed;
    top: 10px;
    left: 16px;
    border-radius: 10px;
    border: none;
    background: transparent;
    color: #ffffff;
    z-index: 1200;
    box-shadow: none;
    touch-action: manipulation;
  }

  .mobile-nav-logo {
    width: 28px;
    height: 28px;
    object-fit: contain;
  }

  .mobile-nav-overlay {
    display: none !important;
    position: fixed;
    inset: 0;
    background: rgba(3, 0, 20, 0.55);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
    z-index: 1050;
  }

  .mobile-nav-overlay.mobile-active {
    opacity: 1;
    pointer-events: auto;
  }

  .mobile-topbar {
    display: none !important;
    align-items: center;
    justify-content: center;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    min-height: 60px;
    padding: 10px 16px 10px 64px;
    background: linear-gradient(135deg, #2e1065, #0f172a);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 12px 28px rgba(15, 23, 42, 0.4);
    z-index: 1000;
  }

  .mobile-topbar-inner {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    width: 100%;
  }

  .mobile-topbar-title {
    font-size: 0.95rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #ffffff;
    text-shadow: 0 2px 10px rgba(147, 51, 234, 0.45);
  }

  .mobile-app-container {
    flex-direction: column;
  }

  .mobile-sidebar {
    display: none !important;
  }

  .mobile-sidebar.mobile-open {
    transform: translateX(0);
  }

  .mobile-sidebar .sidebar-background {
    display: none;
  }

  .mobile-sidebar .logo-container {
    display: none;
  }

  .mobile-sidebar .logo-img {
    width: 46px;
    height: 46px;
  }

  .mobile-sidebar .logo-text {
    font-size: 1.1rem;
  }

  .mobile-sidebar .nav-item {
    padding: 12px 14px;
    font-size: 0.95rem;
    border-left-width: 0;
    color: rgba(255, 255, 255, 0.88);
  }

  .mobile-sidebar .nav-item span {
    display: inline;
    opacity: 1;
  }

  .mobile-sidebar .nav-item:hover {
    transform: translateX(6px) scale(1.02);
  }

  .mobile-sidebar .nav-item.active {
    transform: translateX(0);
    border-left-width: 0;
    background: rgba(255, 255, 255, 0.08);
    color: #ffffff;
  }

  .mobile-sidebar .sidebar-footer {
    padding-top: 10px;
    margin-top: 10px;
  }

  .mobile-dashboard-bar {
    display: none !important;
  }

  .stats-row {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 12px !important;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
    padding-left: 0 !important;
    padding-right: 0 !important;
    justify-items: stretch !important;
  }

  .stat-card {
    padding: 12px !important;
    border-radius: 22px !important;
    gap: 10px !important;
    min-height: 86px;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
  }

  .stat-icon {
    width: 40px !important;
    height: 40px !important;
    font-size: 1rem !important;
    border-radius: 14px !important;
  }

  .stat-info {
    min-width: 0;
  }

  .stat-info h3 {
    font-size: 1.05rem !important;
    line-height: 1.1 !important;
    margin: 0 !important;
  }

  .stat-info p {
    font-size: 0.65rem !important;
    line-height: 1.1 !important;
    margin: 4px 0 0 0 !important;
  }

  .fin-box {
    padding: 12px !important;
    border-radius: 12px !important;
  }

  .fin-box h3 {
    font-size: 1rem !important;
  }

  .fin-box p {
    font-size: 0.65rem !important;
  }

  #financial-performance-card,
  #team-total-card,
  #quick-actions-card,
  #recent-activity-card {
    padding: 16px !important;
    width: 100% !important;
    box-sizing: border-box !important;
  }

  .financial-inner-grid {
    gap: 12px !important;
  }

  .financial-stats-column {
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: 8px !important;
  }

  .fin-box {
    padding: 10px !important;
    border-radius: 12px !important;
    min-width: 0 !important;
  }

  .fin-box h3 {
    font-size: 1rem !important;
  }

  .fin-box p {
    font-size: 0.62rem !important;
    letter-spacing: 0.08em;
  }

  .team-widget-item {
    padding: 12px !important;
  }

  .team-widget-item > div {
    gap: 10px !important;
  }

  .team-widget-item > div > div:first-child {
    width: 44px !important;
    height: 44px !important;
  }

  .team-widget-item strong {
    font-size: 0.9rem !important;
  }

  .mobile-main-layout {
    margin-left: 0 !important;
    width: 100% !important;
  }

  .mobile-content-area {
    padding: var(--mobile-content-pad-top) 16px var(--mobile-content-pad-bottom);
    max-width: 100%;
    overflow-x: hidden;
  }

  #module-content > *:first-child {
    margin-top: 0;
  }

  /* LiliaDex: quitar bandas laterales en móvil (el modo inmersivo sigue controlando el resto) */
  body.novadex-module-marketing:not(.lilia-mobile-immersive)
    .mobile-content-area.content-area--liliadex {
    padding-left: 0 !important;
    padding-right: 0 !important;
  }

  body.novadex-module-messages .mobile-content-area.content-area--messages {
    padding-left: 0 !important;
    padding-right: 0 !important;
    padding-top: var(--mobile-content-pad-top) !important;
    padding-bottom: var(--mobile-content-pad-bottom) !important;
  }

  .main-header-v2 {
    display: none !important;
  }

  /* Chrome superior por encima del footer fijo (1310); drawer/overlay encima del header */
  .mobile-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    min-height: calc(56px + env(safe-area-inset-top, 0px));
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: calc(10px + env(safe-area-inset-top, 0px)) 12px 20px 12px;
    z-index: 1340;
    border-bottom: 1px solid rgba(168, 85, 247, 0.35);
    box-shadow:
      0 4px 0 rgba(6, 182, 212, 0.12),
      0 16px 40px rgba(15, 23, 42, 0.55),
      inset 0 1px 0 rgba(255, 255, 255, 0.12);
    overflow: visible;
    -webkit-tap-highlight-color: transparent;
    isolation: isolate;
    background: linear-gradient(
      125deg,
      #1e0a4a 0%,
      #312e81 28%,
      #0f172a 55%,
      #1e1b4b 100%
    );
  }

  .mobile-header::before {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    background:
      radial-gradient(ellipse 120% 80% at 50% -20%, rgba(147, 51, 234, 0.45), transparent 55%),
      radial-gradient(ellipse 90% 60% at 100% 50%, rgba(6, 182, 212, 0.18), transparent 45%),
      radial-gradient(ellipse 70% 50% at 0% 80%, rgba(236, 72, 153, 0.15), transparent 50%);
    opacity: 1;
  }

  .mobile-header > * {
    position: relative;
    z-index: 1;
  }

  .mobile-header-spacer {
    display: none;
  }

  /* Solo logotipo, centrado y solapando la franja (sin panel / texto) */
  .mobile-brand-floating {
    position: fixed;
    top: calc(2px + env(safe-area-inset-top, 0px));
    left: 50%;
    transform: translateX(-50%) translateY(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1350;
    padding: 0;
    margin: 0;
    border: none;
    background: none;
    box-shadow: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  .mobile-brand-logo {
    width: 88px;
    height: 88px;
    object-fit: contain;
    border-radius: 18px;
    filter: drop-shadow(0 6px 20px rgba(96, 165, 250, 0.55))
      drop-shadow(0 2px 8px rgba(236, 72, 153, 0.35));
    flex-shrink: 0;
  }

  .mobile-header-nav {
    display: flex;
    align-items: center;
    gap: 7px;
    flex: 1 1 auto;
    justify-content: flex-end;
    min-width: 0;
  }

  .mobile-header-nav .ndq-btn {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    border-radius: 14px;
    border: 1px solid rgba(255, 255, 255, 0.22);
    color: #ffffff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    touch-action: manipulation;
    flex-shrink: 0;
    transition:
      transform 0.15s ease,
      box-shadow 0.15s ease,
      filter 0.15s ease;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35);
  }

  .mobile-header-nav .ndq-btn:active {
    transform: scale(0.92);
  }

  .mobile-header-nav .ndq-btn.ndq-estelares {
    background: linear-gradient(145deg, #ea580c 0%, #f59e0b 50%, #fbbf24 100%);
  }

  .mobile-header-nav .ndq-btn.ndq-leads {
    background: linear-gradient(145deg, #0891b2 0%, #06b6d4 50%, #22d3ee 100%);
  }

  .mobile-header-nav .ndq-btn.ndq-clientes {
    background: linear-gradient(145deg, #4338ca 0%, #6366f1 45%, #3b82f6 100%);
  }

  .mobile-header-nav .ndq-btn.active {
    border-color: rgba(255, 255, 255, 0.55);
    box-shadow:
      0 0 0 2px rgba(255, 255, 255, 0.35),
      0 8px 24px rgba(0, 0, 0, 0.4);
    filter: brightness(1.12) saturate(1.08);
  }

  .mobile-header-hamburger {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    border-radius: 14px;
    border: 1px solid rgba(255, 255, 255, 0.22);
    background: linear-gradient(
      160deg,
      rgba(255, 255, 255, 0.14) 0%,
      rgba(15, 23, 42, 0.65) 100%
    );
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    flex-shrink: 0;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.15);
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    transition: transform 0.15s ease;
    color: #fff;
  }

  .mobile-header-hamburger:active {
    transform: scale(0.94);
  }

  .mobile-header-hamburger span {
    width: 20px;
    height: 2.5px;
    background: #ffffff;
    border-radius: 999px;
  }

  /* Pantallas muy estrechas: logo y accesos un poco más compactos */
  @media (max-width: 360px) {
    :root {
      --mobile-content-pad-top: calc(98px + env(safe-area-inset-top, 0px));
    }

    .mobile-header {
      padding-left: 8px;
      padding-right: 8px;
      gap: 6px;
    }

    .mobile-brand-logo {
      width: 68px;
      height: 68px;
    }

    .mobile-brand-floating {
      transform: translateX(-50%) translateY(4px);
    }

    .mobile-header-nav {
      gap: 4px;
    }

    .mobile-header-nav .ndq-btn {
      width: 40px;
      height: 40px;
      min-width: 40px;
      min-height: 40px;
      font-size: 0.9rem;
    }

    .mobile-header-hamburger {
      width: 40px;
      height: 40px;
      min-width: 40px;
      min-height: 40px;
    }
  }

  .mobile-overlay {
    position: fixed;
    inset: 0;
    background: rgba(3, 0, 20, 0.55);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 1360;
  }

  .mobile-overlay.active {
    opacity: 1;
    pointer-events: auto;
  }

  /* Popup de secciones (hamburguesa móvil; no drawer lateral) */
  .mobile-sections-popup {
    position: fixed;
    inset: 0;
    z-index: 13920;
    display: none;
    pointer-events: none;
  }

  .mobile-sections-popup.active {
    display: block;
    pointer-events: auto;
  }

  .mobile-sections-popup-inner {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: max(16px, env(safe-area-inset-top, 0px)) max(18px, env(safe-area-inset-right, 0px))
      max(22px, calc(env(safe-area-inset-bottom, 0px) + 10px)) max(18px, env(safe-area-inset-left, 0px));
    box-sizing: border-box;
  }

  .mobile-sections-popup-scrim {
    position: absolute;
    inset: 0;
    cursor: pointer;
  }

  .mobile-sections-popup-panel {
    position: relative;
    z-index: 2;
    width: 100%;
    max-width: min(336px, 90vw);
    max-height: min(88dvh, 600px, calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 32px));
    overflow-y: auto;
    overflow-x: hidden;
    border-radius: 17px;
    background: linear-gradient(180deg, rgba(30, 27, 75, 0.98) 0%, rgba(15, 23, 42, 0.99) 100%);
    border: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.42), 0 0 0 1px rgba(99, 102, 241, 0.18);
    padding: 11px 11px 13px;
    -webkit-overflow-scrolling: touch;
  }

  @keyframes mobile-section-tile-press {
    0% {
      transform: scale(1);
    }
    40% {
      transform: scale(0.93);
    }
    100% {
      transform: scale(1);
    }
  }

  .mobile-sections-popup-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    row-gap: 10px;
    column-gap: 10px;
  }

  .mobile-section-tile {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 6px;
    min-height: 0;
    aspect-ratio: 1;
    border-radius: 14px;
    cursor: pointer;
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.18);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.22);
    transition: box-shadow 0.2s ease, filter 0.2s ease;
    -webkit-tap-highlight-color: transparent;
  }

  .mobile-section-tile:active {
    animation: mobile-section-tile-press 0.28s cubic-bezier(0.34, 1.45, 0.64, 1);
    filter: brightness(1.08);
  }

  .mobile-section-tile.active {
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.95), 0 8px 22px rgba(0, 0, 0, 0.35);
    filter: brightness(1.06);
  }

  .mobile-section-tile-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 1.22rem;
    line-height: 1;
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.25));
  }

  .mobile-section-tile-label {
    font-size: 0.58rem;
    font-weight: 800;
    text-align: center;
    line-height: 1.15;
    max-width: 100%;
    word-break: break-word;
    color: rgba(255, 255, 255, 0.95);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    flex-shrink: 1;
    min-height: 0;
  }

  .mobile-section-tile--logout .mobile-section-tile-label {
    color: rgba(255, 255, 255, 0.98);
  }

  @media (max-width: 360px) {
    .mobile-sections-popup-panel {
      max-width: min(312px, 92vw);
      max-height: min(84dvh, 560px, calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 28px));
    }

    .mobile-sections-popup-grid {
      grid-template-columns: repeat(2, minmax(0, 1fr));
      gap: 10px;
      row-gap: 10px;
      column-gap: 10px;
    }
  }

  @media (prefers-reduced-motion: reduce) {
    .mobile-section-tile:active {
      animation: none;
    }
  }

  /* Reproductor listas: por encima del footer y del contenido */
  body.mobile-mode #ndpl-dock {
    z-index: 13840;
  }

  .mobile-drawer {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: 78vw;
    max-width: 320px;
    background: linear-gradient(180deg, #2e1065 0%, #0f172a 100%);
    transform: translateX(-110%);
    transition: transform 0.3s ease;
    z-index: 1370;
    padding: 18px 16px;
    overflow-y: auto;
    overflow-x: hidden;
  }

  .drawer-background {
    position: absolute;
    inset: 0;
    pointer-events: none;
    opacity: 0.15;
  }

  .drawer-background .bg-icon {
    position: absolute;
    font-size: 2.2rem;
    color: rgba(255, 255, 255, 0.12);
  }

  .mobile-drawer.active {
    transform: translateX(0);
  }

  .mobile-drawer-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    margin-bottom: 12px;
  }

  .drawer-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 10px;
    color: rgba(255, 255, 255, 0.9);
  }

  .drawer-item.active {
    background: rgba(255, 255, 255, 0.12);
    color: #ffffff;
  }

  .drawer-divider {
    height: 1px;
    background: rgba(255, 255, 255, 0.08);
    margin: 10px 0;
  }

  .drawer-item-logout {
    color: #f87171;
  }

  .mobile-footer {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: 100vw;
    box-sizing: border-box;
    min-height: calc(72px + env(safe-area-inset-bottom, 0px));
    height: auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 12px 14px calc(12px + env(safe-area-inset-bottom, 0px));
    background: linear-gradient(180deg, #0f172a 0%, #1e1b4b 55%, #172554 100%);
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow:
      0 -12px 40px rgba(0, 0, 0, 0.45),
      0 -1px 0 rgba(99, 102, 241, 0.12);
    z-index: 1310;
    -webkit-tap-highlight-color: transparent;
  }

  .mobile-footer.is-hidden-for-lilia {
    display: none !important;
  }

  .mobile-footer-user {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #ffffff;
    font-size: 0.8125rem;
    font-weight: 700;
    min-width: 0;
    flex: 0 1 auto;
    padding: 6px 12px 6px 8px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.1);
    max-width: 36%;
  }

  .mobile-footer-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid rgba(99, 102, 241, 0.45);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    flex-shrink: 0;
  }

  .mobile-footer-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-footer-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    flex: 1 1 auto;
    min-width: 0;
  }

  .mobile-footer-action-btn,
  .mobile-footer-btn,
  .mobile-footer-chat-btn {
    position: relative;
    width: 48px;
    height: 48px;
    min-width: 48px;
    min-height: 48px;
    border-radius: 14px;
    border: none;
    color: #ffffff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.12rem;
    flex-shrink: 0;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.28);
    touch-action: manipulation;
    transition: transform 0.15s ease;
  }

  .mobile-footer-action-btn:active,
  .mobile-footer-btn:active,
  .mobile-footer-chat-btn:active {
    transform: scale(0.94);
  }

  .mobile-footer-btn {
    background: linear-gradient(135deg, #00b4d8, #ec4899);
    box-shadow:
      0 8px 22px rgba(236, 72, 153, 0.3),
      0 4px 14px rgba(0, 180, 216, 0.22);
  }

  .mobile-footer-chat-btn {
    background: linear-gradient(145deg, #6366f1 0%, #7c3aed 45%, #8b5cf6 100%);
    border: 1px solid rgba(255, 255, 255, 0.22);
    box-shadow:
      0 8px 22px rgba(99, 102, 241, 0.38),
      0 4px 14px rgba(0, 0, 0, 0.22);
  }

  .mobile-footer-chat-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #ef4444;
    color: #ffffff;
    font-size: 0.65rem;
    font-weight: 800;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    border: 2px solid #1e1b4b;
    line-height: 1;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  }

  .mobile-footer-chat-badge.mobile-footer-chat-badge--on {
    display: inline-flex;
  }

  .mobile-footer-btn-label {
    display: none;
  }

  .mobile-footer-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #ef4444;
    color: #ffffff;
    font-size: 0.68rem;
    font-weight: 800;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    border: 2px solid #1e1b4b;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  }

  .estelares-v2-shell {
    flex-direction: column !important;
    height: auto !important;
  }

  .estelares-v2-sidebar {
    width: 100% !important;
    min-width: 100% !important;
    max-width: 100% !important;
    border-right: none !important;
    border-bottom: 1px solid rgba(0, 180, 216, 0.12);
  }

  .estelares-v2-sidebar > div:first-child {
    padding-top: 10px !important;
    padding-bottom: 10px !important;
  }

  .estelares-v2-sidebar #estelaresv2-list {
    max-height: 56vh;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  .estelares-v2-main {
    width: 100% !important;
  }

  .estelares-v2-body {
    padding: 14px !important;
    overflow-x: hidden !important;
  }

  .estelares-v2-tabs {
    width: 100%;
    overflow: hidden;
    padding-bottom: 6px;
    flex-wrap: wrap !important;
    gap: 6px !important;
  }

  .estelares-v2-tabs button {
    flex: 1 1 calc(50% - 6px) !important;
    min-width: 0 !important;
    padding: 7px 8px !important;
    font-size: 0.72rem !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  #estelaresv2-title {
    white-space: normal !important;
    font-size: 1.15rem !important;
    line-height: 1.2 !important;
  }

  #estelaresv2-subtitle {
    white-space: normal !important;
  }

  #estelaresv2-body * {
    max-width: 100% !important;
    box-sizing: border-box !important;
  }

  #estelaresv2-body [style*="grid-template-columns"] {
    display: flex !important;
    flex-direction: column !important;
  }

  .dashboard-grid {
    display: flex !important;
    flex-direction: column !important;
    gap: 11px !important;
    padding-right: 0 !important;
  }

  #module-content .dashboard-grid {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
  }

  #module-content .dashboard-grid > div {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
  }

  #module-content .dashboard-grid .card {
    max-width: 100% !important;
    box-sizing: border-box !important;
  }

  #financial-performance-card {
    order: 1;
  }

  #team-total-card {
    order: 2;
  }

  #recent-activity-card {
    order: 3;
  }

  #quick-actions-card {
    order: 4;
  }

  .mobile-content-area > * {
    content-visibility: auto;
    contain-intrinsic-size: 1px 800px;
  }

  .modal-content {
    max-width: 92vw !important;
    max-height: 72vh !important;
    border-radius: 16px !important;
  }

  .modal-header {
    padding: 14px !important;
  }

  .modal-body {
    padding: 14px !important;
  }

  .modal-footer {
    padding: 12px !important;
  }

  /* Team Messenger: modal más estrecho, más alto, safe area (Novadex) */
  .tm-modal-back.tm-modal-back--nv {
    padding: max(12px, env(safe-area-inset-top, 0px)) max(12px, env(safe-area-inset-right, 0px))
      max(12px, env(safe-area-inset-bottom, 0px)) max(12px, env(safe-area-inset-left, 0px)) !important;
    box-sizing: border-box !important;
    align-items: center !important;
    justify-content: center !important;
  }

  .tm-modal.tm-modal--nv {
    width: min(92vw, 336px) !important;
    max-width: calc(100vw - 24px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px)) !important;
    max-height: calc(
      var(--app-vh, 100dvh) - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 28px
    ) !important;
    display: flex !important;
    flex-direction: column !important;
    min-height: 0 !important;
  }

  .tm-modal.tm-modal--nv .tm-modal-nv-head,
  .tm-modal.tm-modal--nv .tm-modal-actions--nv {
    flex-shrink: 0;
  }

  .tm-modal.tm-modal--nv .tm-dm-list {
    max-height: none !important;
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  .tm-modal.tm-modal--nv .tm-user-pick--nv {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  /* ── LiliaDex mobile ── */
  .ldx-shell {
    margin: 0 !important;
    padding: 0 !important;
  }

  .ldx-chat {
    height: auto !important;
    max-height: none !important;
    flex: 1 1 auto !important;
    min-height: 0 !important;
    border-radius: 0 !important;
    border-left: none !important;
    border-right: none !important;
    overflow-x: hidden !important;
    max-width: 100% !important;
  }

  .ldx-chat-body {
    min-height: 0 !important;
    flex: 1 1 auto !important;
    scroll-padding-bottom: 12px;
  }

  .ldx-chat-header {
    padding: 10px 12px !important;
    flex-wrap: wrap;
    gap: 8px;
  }

  .ldx-chat-header-tools {
    flex: 1 1 100%;
    max-width: 100%;
    min-width: 0;
    display: flex !important;
    align-items: center;
    gap: 6px;
    flex-wrap: nowrap !important;
    justify-content: flex-end;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    padding-bottom: 2px;
    mask-image: linear-gradient(to right, transparent, #000 12px, #000 calc(100% - 12px), transparent);
    mask-size: 100% 100%;
  }

  .ldx-chat-header-tools::-webkit-scrollbar {
    height: 3px;
  }

  .ldx-chat-header-tools::-webkit-scrollbar-thumb {
    background: #4c1d95;
    border-radius: 999px;
  }

  .ldx-chat-header-tools .ldx-galaxy-indicator {
    flex: 1 1 auto;
    min-width: 0;
    max-width: min(46vw, 220px);
  }

  .ldx-chat-header-tools .ldx-actions,
  .ldx-chat-header-tools .ldx-toolbar-toggle {
    flex-shrink: 0;
  }

  #liliadex-quick-bar.ldx-quick-bar {
    flex-wrap: nowrap !important;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    flex-shrink: 0;
    mask-image: linear-gradient(to right, transparent, #000 10px, #000 calc(100% - 10px), transparent);
    mask-size: 100% 100%;
  }

  #liliadex-quick-bar.ldx-quick-bar::-webkit-scrollbar {
    height: 3px;
  }

  #liliadex-quick-bar.ldx-quick-bar::-webkit-scrollbar-thumb {
    background: #4c1d95;
    border-radius: 999px;
  }

  #liliadex-quick-bar.ldx-quick-bar .ldx-qb {
    flex-shrink: 0;
  }

  .ldx-msg .ldx-bubble {
    font-size: 0.86rem !important;
    overflow-wrap: anywhere !important;
    word-break: break-word !important;
  }

  .ldx-msg.user .ldx-bubble {
    max-width: 90% !important;
  }

  .ldx-msg.assistant .ldx-bubble-wrap {
    flex: 1 1 0 !important;
    min-width: 0 !important;
    max-width: none !important;
    width: auto !important;
  }

  .ldx-msg.assistant .ldx-bubble {
    max-width: 100% !important;
  }

  .ldx-msg.assistant .ldx-bubble p,
  .ldx-msg.assistant .ldx-bubble li,
  .ldx-msg.assistant .ldx-bubble h3,
  .ldx-msg.assistant .ldx-bubble h4,
  .ldx-stream-content {
    overflow-wrap: anywhere !important;
    word-break: break-word !important;
  }

  /* Durante escritura en móvil, evita micro-jitter visual. */
  .ldx-msg.assistant[data-typing="1"] {
    animation: none !important;
    transform: none !important;
    opacity: 1 !important;
  }

  .ldx-msg.assistant[data-typing="1"] .ldx-bubble,
  .ldx-msg.assistant[data-typing="1"] .ldx-stream-content {
    transform: none !important;
    opacity: 1 !important;
    backface-visibility: hidden;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
  }

  .ldx-input {
    position: sticky;
    bottom: 0;
    z-index: 2;
    display: grid !important;
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-rows: auto auto;
    align-items: center !important;
    gap: 6px 8px !important;
    flex-wrap: unset !important;
    padding-left: max(8px, env(safe-area-inset-left, 0px)) !important;
    padding-right: max(8px, env(safe-area-inset-right, 0px)) !important;
    box-sizing: border-box !important;
    max-width: 100% !important;
  }

  .ldx-card.ldx-chat .ldx-input-wrap {
    display: contents !important;
    flex: unset !important;
  }

  .ldx-card.ldx-chat .ldx-input textarea {
    grid-column: 1 / -1;
    grid-row: 1;
    width: 100% !important;
    box-sizing: border-box;
    min-height: 120px !important;
    max-height: 220px !important;
    font-size: 16px !important;
    line-height: 1.4 !important;
  }

  .ldx-card.ldx-chat .ldx-attach {
    grid-column: 1;
    grid-row: 2;
    align-self: center;
  }

  .ldx-card.ldx-chat .ldx-input-tools {
    grid-column: 2;
    grid-row: 2;
    justify-self: end;
    padding: 0 2px 0 0 !important;
  }

  .ldx-card.ldx-chat #liliadex-send {
    grid-column: 3;
    grid-row: 2;
    margin: 0 !important;
  }

  .ldx-quick-bar {
    gap: 5px !important;
    padding: 6px 10px !important;
  }

  .ldx-qb {
    padding: 4px 10px !important;
    font-size: 0.68rem !important;
  }

  .ldx-video-options {
    padding: 8px 10px !important;
    gap: 6px !important;
  }

  .ldx-vo-btn {
    padding: 4px 8px !important;
    font-size: 0.66rem !important;
  }

  .ldx-toolbar-dropdown {
    right: 0 !important;
    width: 200px !important;
  }

  .ldx-session-panel {
    position: fixed !important;
    inset: 0 !important;
    left: 0 !important;
    top: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    max-width: none !important;
    border: none !important;
    border-radius: 0 !important;
    z-index: 10120 !important;
    align-items: center !important;
    justify-content: center !important;
    box-sizing: border-box !important;
    padding: max(14px, env(safe-area-inset-top, 0px)) max(18px, env(safe-area-inset-right, 0px))
      max(18px, env(safe-area-inset-bottom, 0px)) max(18px, env(safe-area-inset-left, 0px)) !important;
    background: transparent !important;
    animation: ldx-session-overlay-in 220ms ease both !important;
  }

  @keyframes ldx-session-overlay-in {
    from {
      opacity: 0;
    }
    to {
      opacity: 1;
    }
  }

  .ldx-session-panel-backdrop {
    display: block !important;
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(2px);
  }

  .ldx-session-panel-body {
    position: relative;
    z-index: 1;
    display: flex !important;
    flex-direction: column !important;
    width: 100%;
    max-width: min(420px, calc(100vw - 36px)) !important;
    max-height: min(78vh, 640px) !important;
    margin: 0 auto;
    border-radius: 18px;
    border: 1px solid rgba(124, 90, 180, 0.45);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(0, 0, 0, 0.2);
    overflow: hidden !important;
    animation: ldx-session-pop 260ms ease both;
    background: #13091f !important;
  }

  @keyframes ldx-session-pop {
    from {
      transform: scale(0.94) translateY(10px);
      opacity: 0;
    }
    to {
      transform: scale(1) translateY(0);
      opacity: 1;
    }
  }

  @media (prefers-reduced-motion: reduce) {
    .ldx-session-panel,
    .ldx-session-panel-body {
      animation: none !important;
    }
  }

  .ldx-media-modal-content {
    max-width: min(920px, 96vw) !important;
    max-height: min(88vh, 820px) !important;
    border-radius: 14px !important;
  }

  .ldx-media-modal-body img,
  .ldx-media-modal-body video,
  .ldx-media-modal-body .ldx-media-modal-video {
    max-height: min(62vh, 560px) !important;
  }

  .ldx-media-footer-btn {
    flex: 1 1 auto;
    min-width: 0;
    justify-content: center;
    padding: 10px 12px !important;
    font-size: 0.74rem !important;
  }

  .ldx-msg .ldx-media-thumb {
    max-width: 200px !important;
    max-height: 160px !important;
  }

  .ldx-media-action {
    font-size: 0.66rem !important;
    padding: 4px 8px !important;
  }

  .ldx-code-toolbar {
    flex-direction: column;
    align-items: stretch !important;
  }

  .ldx-code-toolbar-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .ldx-code-tool-btn {
    font-size: 0.64rem !important;
    padding: 8px 9px !important;
  }

  .ldx-msg.assistant .ldx-bubble pre.ldx-code-pre {
    max-height: min(48vh, 420px) !important;
  }

  .ldx-html-preview-modal-inner {
    max-height: min(86vh, 780px) !important;
  }

  .ldx-agent-form-inner {
    max-height: min(90vh, 680px) !important;
  }

  .ldx-agent-form-footer .ldx-media-footer-btn {
    flex: 1 1 auto;
    min-width: 0;
    justify-content: center;
    font-size: 0.72rem !important;
    padding: 9px 10px !important;
  }

  .ldx-actions .ldx-btn {
    padding: 5px 7px !important;
    font-size: 0.66rem !important;
    gap: 4px !important;
    flex-shrink: 0;
    white-space: nowrap;
  }

  .ldx-msg.assistant .ldx-bubble-actions {
    margin-top: 8px;
    display: flex;
    justify-content: flex-end;
  }

  .ldx-msg.assistant .ldx-bubble-copy .ldx-bubble-copy-label {
    display: none;
  }

  .ldx-msg.assistant .ldx-bubble-copy {
    min-width: 40px;
    min-height: 40px;
    width: 40px;
    padding: 0;
    border-radius: 10px;
    border: 1px solid rgba(167, 139, 250, 0.35);
    background: rgba(124, 58, 237, 0.2);
    color: #ddd6fe;
    font-size: 0.72rem;
    font-weight: 800;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    touch-action: manipulation;
  }

  .ldx-msg.assistant .ldx-bubble-copy:active {
    transform: scale(0.98);
  }

  .ldx-input-wrap {
    flex: 1;
    min-width: 0;
  }

  .ldx-input-tools {
    padding: 2px 4px 0 !important;
    gap: 3px !important;
  }

  .ldx-tool-btn {
    width: 28px !important;
    height: 28px !important;
    font-size: 0.72rem !important;
  }

  .ldx-optimize-menu {
    width: 220px !important;
    right: -20px !important;
  }

  .ldx-optimize-item strong {
    font-size: 0.72rem !important;
  }

  .ldx-optimize-item span {
    font-size: 0.6rem !important;
  }

  .ldx-agent-wrap {
    flex: 0 0 auto;
  }

  .ldx-agent-menu {
    min-width: 170px !important;
    left: 0 !important;
  }

  .ldx-agent-action {
    font-size: 0.68rem !important;
    padding: 6px 10px !important;
  }

  .ldx-code-modal-content {
    max-width: 96vw !important;
    max-height: 96vh !important;
    width: auto !important;
    border-radius: 12px !important;
  }

  .ldx-code-modal-body {
    font-size: 0.72rem !important;
    padding: 12px !important;
  }

  .ldx-code-expand-btn {
    font-size: 0.62rem !important;
    padding: 2px 6px !important;
  }

  .ldx-galaxy-modal-content,
  .ldx-gallery-modal-content {
    max-width: 96vw !important;
    max-height: 92vh !important;
    width: auto !important;
    border-radius: 12px !important;
  }

  .ldx-galaxy-modal-body {
    padding: 12px !important;
  }

  .ldx-gx-card {
    padding: 10px !important;
  }

  .ldx-gx-name {
    font-size: 0.76rem !important;
  }

  .ldx-gx-textarea {
    min-height: 60px !important;
  }

  .ldx-gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)) !important;
    gap: 6px !important;
  }

  .ldx-gallery-thumb {
    height: 80px !important;
  }

  .ldx-galaxy-btn {
    font-size: 0.66rem !important;
    padding: 4px 8px !important;
  }

  .ldx-delib-summary {
    font-size: 0.7rem !important;
    padding: 6px 8px !important;
  }

  .ldx-delib-content {
    padding: 8px !important;
    font-size: 0.76rem !important;
  }

  .ldx-delib-synth {
    font-size: 0.8rem !important;
  }

  /* Modales globales por encima del drawer (header 1340, marca 1350, overlay 1360, drawer 1370) */
  #global-modal.modal-overlay {
    z-index: 1400 !important;
  }

  /* Detalle de lead: ocultar top bar y marca mientras el modal está abierto */
  body.lead-detail-modal-open .mobile-header,
  body.lead-detail-modal-open .mobile-brand-floating,
  body.lead-detail-modal-open .mobile-sections-popup {
    visibility: hidden !important;
    pointer-events: none !important;
  }

  /* LiliaDex: modo inmersivo móvil (#marketing) */
  body.lilia-mobile-immersive .mobile-header,
  body.lilia-mobile-immersive .mobile-brand-floating,
  body.lilia-mobile-immersive .mobile-sections-popup {
    visibility: hidden !important;
    pointer-events: none !important;
  }

  body.lilia-mobile-immersive #mobileTopbar {
    display: none !important;
  }

  body.lilia-mobile-immersive #mobile-footer {
    visibility: hidden !important;
    pointer-events: none !important;
    display: none !important;
  }

  body.lilia-mobile-immersive .mobile-content-area {
    padding: env(safe-area-inset-top, 0px) 0
      calc(var(--mobile-footer-h, 76px) + env(safe-area-inset-bottom, 0px)) !important;
  }

  /* Evita pantalla en blanco: content-visibility:auto en hijos del content-area aplastaba el paint de #module-content */
  body.lilia-mobile-immersive .mobile-content-area > #module-content {
    content-visibility: visible !important;
    contain: none !important;
    contain-intrinsic-size: auto !important;
  }

  body.lilia-mobile-immersive #module-content {
    padding: 0 !important;
    margin: 0 !important;
    min-height: calc(var(--app-vh, 100dvh) - var(--mobile-footer-h, 76px)) !important;
    height: calc(var(--app-vh, 100dvh) - var(--mobile-footer-h, 76px)) !important;
  }

  body.lilia-mobile-immersive #module-content .ldx-shell--unified {
    position: fixed;
    z-index: 1250;
    left: env(safe-area-inset-left, 0px);
    right: env(safe-area-inset-right, 0px);
    top: env(safe-area-inset-top, 0px);
    bottom: calc(var(--mobile-footer-h, 76px) + env(safe-area-inset-bottom, 0px));
    width: auto;
    height: auto;
    max-width: min(100%, 100vw);
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    box-sizing: border-box;
  }

  body.lilia-mobile-immersive #module-content .ldx-card.ldx-chat {
    flex: 1 1 auto;
    min-height: 0 !important;
    height: auto !important;
    max-height: none !important;
    border-radius: 0 !important;
  }

  body.lilia-mobile-immersive #module-content .ldx-chat {
    height: 100% !important;
    max-height: none !important;
    min-height: 0 !important;
  }

  body.lilia-mobile-immersive .ldx-mobile-exit {
    position: fixed;
    top: calc(10px + env(safe-area-inset-top, 0px));
    right: calc(10px + env(safe-area-inset-right, 0px));
    z-index: 1320;
    width: 40px;
    height: 40px;
    border-radius: 999px;
    border: 1px solid rgba(167, 139, 250, 0.45);
    background: rgba(23, 16, 40, 0.92);
    color: #e9d5ff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
    touch-action: manipulation;
    padding: 0;
    font-size: 1rem;
  }

  body.lilia-mobile-immersive .ldx-input textarea {
    min-height: 132px !important;
    max-height: 240px !important;
  }

  body.lilia-mobile-immersive #liliadex-send {
    min-width: 44px !important;
    padding: 0 11px !important;
  }

  body.lilia-mobile-immersive #liliadex-send .ldx-send-label {
    display: none !important;
  }

  body.lilia-mobile-immersive #liliadex-send .ldx-send-busy {
    display: inline-block;
    min-width: 1.25rem;
    text-align: center;
  }

  @media (display-mode: standalone) {
    body.mobile-mode .mobile-content-area {
      padding-bottom: calc(var(--mobile-footer-h, 76px) + env(safe-area-inset-bottom, 0px)) !important;
    }

    body.mobile-mode .mobile-footer {
      padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    }

    body.mobile-mode.novadex-module-marketing #content-area.content-area--liliadex {
      padding-bottom: 0 !important;
    }

    body.mobile-mode.novadex-module-messages #content-area.content-area--messages {
      padding-bottom: calc(var(--mobile-footer-h, 76px) + env(safe-area-inset-bottom, 0px)) !important;
    }
  }
}
