/* ═══════════════════════════════════════════════════════════════════════════
   CIP — pulido móvil + control de estado (29-oct-2026)
   Pedido de Miguel: que en el teléfono se sienta como WhatsApp/Telegram (nada cortado, iconos con aire) y
   un selector "Disponible" profesional. Se carga DESPUÉS de styles.css y bell.css.

   Causas raíz corregidas aquí:
   1) .chat-app no era un bloque de posicionamiento: los paneles (position:absolute; inset:0) escapaban de su
      overflow:hidden y la PÁGINA se podía desplazar en horizontal -> bordes recortados al abrir un chat.
   2) .toast tenía translateX(-50%) heredado de escritorio mientras en móvil se ancla con left/right:12px ->
      el aviso quedaba corrido media pantalla a la izquierda ("...do y ELA reanudada").
   3) El encabezado de la bandeja metía número + selector + campana + iconos en una fila que no cabía en 390 px y
      el flex-wrap los partía en dos filas con el ⋮ solo.
   4) El encabezado del chat metía nombre + 3 botones + lupa + ⋮: el nombre se quedaba en "O…".
   ═══════════════════════════════════════════════════════════════════════════ */

.chat-app { position: relative; }
html { overscroll-behavior-x: none; }

/* ── Control de estado del asesor (Disponible / Ausente / No molestar) ─────── */
.cipsp-pres { position: relative; }
.cipsp-pres-inline { display: flex; align-items: center; flex: 0 0 auto; margin: 0 0 0 8px; }
/* <select> nativo conservado solo por compatibilidad: oculto, sincronizado con el botón */
.cipsp-pres .cipsp-pres-select {
  position: absolute; width: 1px; height: 1px; max-width: 1px; padding: 0; margin: -1px; border: 0;
  overflow: hidden; clip: rect(0 0 0 0); opacity: 0; pointer-events: none;
}
.cipsp-pres-btn {
  display: inline-flex; align-items: center; gap: 8px; height: 34px; padding: 0 10px 0 12px;
  border-radius: 999px; border: 1px solid rgba(255, 255, 255, .12);
  background: rgba(255, 255, 255, .06); color: var(--text, #e8eaf0);
  font: 600 13px/1 inherit; font-family: inherit; letter-spacing: .01em; white-space: nowrap;
  cursor: pointer; -webkit-tap-highlight-color: transparent;
  transition: background .15s ease, border-color .15s ease, box-shadow .15s ease;
}
.cipsp-pres-btn:hover { background: rgba(255, 255, 255, .1); }
.cipsp-pres-btn:active { transform: scale(.98); }
.cipsp-pres-btn:focus-visible { outline: 2px solid var(--accent, #0aff9d); outline-offset: 2px; }
.cipsp-pres-btn[aria-expanded="true"] { background: rgba(255, 255, 255, .12); border-color: rgba(255, 255, 255, .22); }
.cipsp-pres[data-state="away"] .cipsp-pres-btn { background: rgba(245, 158, 11, .12); border-color: rgba(245, 158, 11, .38); }
.cipsp-pres[data-state="dnd"] .cipsp-pres-btn { background: rgba(239, 68, 68, .12); border-color: rgba(239, 68, 68, .4); }
.cipsp-dot {
  flex: none; width: 9px; height: 9px; border-radius: 50%;
  background: #22c55e; box-shadow: 0 0 0 3px rgba(34, 197, 94, .2);
}
.cipsp-pres[data-state="away"] .cipsp-dot, .cipsp-dot-away { background: #f59e0b; box-shadow: 0 0 0 3px rgba(245, 158, 11, .22); }
.cipsp-pres[data-state="dnd"] .cipsp-dot, .cipsp-dot-dnd { background: #ef4444; box-shadow: 0 0 0 3px rgba(239, 68, 68, .22); }
.cipsp-dot-available { background: #22c55e; box-shadow: 0 0 0 3px rgba(34, 197, 94, .2); }
.cipsp-chev { flex: none; width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; opacity: .6; transition: transform .18s ease; }
.cipsp-pres-btn[aria-expanded="true"] .cipsp-chev { transform: rotate(180deg); }

.cipsp-menu-backdrop { position: fixed; inset: 0; z-index: 9400; background: transparent; }
.cipsp-menu {
  position: fixed; z-index: 9500; width: 330px; max-width: calc(100vw - 16px); box-sizing: border-box;
  padding: 8px; border-radius: 16px; background: var(--bg-soft, #161920); color: var(--text, #e8eaf0);
  border: 1px solid rgba(255, 255, 255, .1); box-shadow: 0 18px 48px rgba(0, 0, 0, .55);
  opacity: 0; transform: translateY(-6px) scale(.98); transform-origin: top left;
  transition: opacity .16s ease, transform .16s ease;
}
.cipsp-menu.open { opacity: 1; transform: none; }
.cipsp-menu-handle { display: none; }
.cipsp-menu-title { padding: 8px 10px 6px; font-size: .72rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--text-muted, #8b92a8); }
.cipsp-menu-sep { height: 1px; margin: 6px 8px; background: rgba(255, 255, 255, .08); }
.cipsp-opt {
  display: flex; align-items: flex-start; gap: 12px; width: 100%; box-sizing: border-box; padding: 10px; border: 0; border-radius: 12px;
  background: transparent; color: inherit; font: inherit; text-align: left; cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.cipsp-opt:hover, .cipsp-opt:focus-visible { background: var(--bg-hover, rgba(255, 255, 255, .06)); outline: none; }
.cipsp-opt.on { background: var(--accent-dim, rgba(10, 255, 157, .13)); }
.cipsp-opt .cipsp-dot { margin-top: 6px; }
.cipsp-opt-txt { display: block; min-width: 0; flex: 1; }
.cipsp-opt-title { display: block; font-size: .92rem; font-weight: 600; line-height: 1.25; }
.cipsp-opt-desc { display: block; margin-top: 2px; font-size: .78rem; line-height: 1.35; color: var(--text-muted, #8b92a8); }
.cipsp-check { flex: none; width: 18px; height: 18px; margin: 2px 0 0 auto; fill: none; stroke: var(--accent, #0aff9d); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.cipsp-menu-foot { margin: 6px 10px 4px; font-size: .72rem; line-height: 1.4; color: var(--text-muted, #8b92a8); }

/* ── Lista de chats (todas las pantallas): nombre/hora arriba, mensaje + insignias abajo ── */
.inbox-list li:not(.loading):not(.empty) { padding: 0; border-bottom: 0; }   /* el <li> sumaba su propio relleno y borde al de la fila: doble espacio y doble línea */
.inbox-item { grid-template-columns: 52px minmax(0, 1fr) !important; gap: 2px 12px !important; position: relative; border-bottom: 0 !important; }
.inbox-item::after { content: ''; position: absolute; left: 76px; right: 0; bottom: 0; height: 1px; background: rgba(255, 255, 255, .07); }
.inbox-avatar { width: 48px !important; height: 48px !important; font-size: .9rem !important; align-self: center; }
.inbox-name-row { min-width: 0; align-self: end; }
.inbox-preview-row { grid-column: 2 !important; min-width: 0; align-self: start; }
.inbox-contact-name { font-size: .98rem; }
.inbox-time { font-size: .72rem; }
.inbox-preview { font-size: .84rem; }
.inbox-preview .channel-dot { display: none; }
/* fila activa: la barra de color no mueve el avatar (antes un borde de 3 px lo desplazaba) */
.inbox-item.active { border-left: 0 !important; box-shadow: inset 3px 0 0 var(--accent, #0aff9d); }
.inbox-item.pending-contact { border-left: 0 !important; box-shadow: inset 3px 0 0 orange; }
.inbox-badges { display: inline-flex; align-items: center; gap: 5px; flex: none; }
.inbox-badges .channel-badge { padding: 2px 5px; }
.inbox-badges .takeover-inbox-chip { margin-left: 0; }
.inbox-badges .inbox-ela-icon { display: inline-flex; align-items: center; }
.inbox-badges .inbox-ela-icon .ci { width: 17px; height: 17px; }

@media (max-width: 768px) {
  /* ── Encabezado de la bandeja: UNA fila, sin recortes ─────────────────── */
  .sidebar-header {
    flex-wrap: nowrap !important; height: 56px !important; min-height: 56px !important;
    padding: 0 6px 0 10px !important; gap: 4px !important; align-items: center; row-gap: 0 !important;
  }
  .sidebar-header .brand { order: 1; min-width: 0; flex: 0 1 auto; overflow: hidden; }
  .system-status-badge { min-width: 0; max-width: 100%; min-height: 32px; font-size: 12.5px; padding: 0 8px 0 10px; gap: 5px; }
  .system-status-text { overflow: visible; text-overflow: clip; letter-spacing: 0; }
  .sidebar-header .brand { flex: 0 0 auto; overflow: visible; }
  .cipsp-pres-inline { order: 2; margin-left: 0; }
  .cipsp-pres-btn { height: 32px; padding: 0 8px 0 10px; gap: 6px; font-size: 12.5px; }
  .system-status-text { font-size: .68rem; }
  .sidebar-header .cip-bell-btn { order: 3; margin-left: auto; }
  .sidebar-header #dashboard-btn { order: 4; }
  .sidebar-header #admin-more-btn { order: 5; }
  .sidebar-header .silence-incidents-badge { order: 6; }
  .sidebar-header .dashboard-toggle {
    width: 38px; height: 38px; padding: 0 !important; flex: none;
    display: inline-flex; align-items: center; justify-content: center; border-radius: 12px !important;
    font-size: 1.3rem; line-height: 1;
  }
  .sidebar-header .dashboard-toggle:active { background: var(--bg-hover) !important; }
  .sidebar-header .cip-bell-btn .ti { font-size: 1.35rem; }
  .cip-bell-badge { top: 1px; right: 1px; }

  /* ── Lista: filas con aire y objetivo táctil cómodo ───────────────────── */
  .inbox-item { padding: 10px 14px 10px 12px !important; }
  #inbox-list { padding-bottom: 88px; }

  /* ── Encabezado del chat: nombre legible; los botones de takeover pasan a su propia fila ── */
  .chat-header {
    flex-wrap: wrap !important; height: auto !important; min-height: 56px;
    padding: 6px 6px 6px 2px !important; gap: 0 2px !important; row-gap: 0 !important; align-items: center;
  }
  .chat-header::after { content: ''; order: 5; flex: 0 0 100%; height: 0; }
  .chat-header .back-btn { order: 1; width: 40px; height: 40px; font-size: 1.35rem; border-radius: 12px; }
  .chat-header .contact-info { order: 2; flex: 1 1 0; min-width: 0; margin: 0; padding: 2px 4px; }
  .chat-header .header-actions { display: contents; }
  .chat-header #conv-search-btn { order: 3; }
  .chat-header .overflow-menu-wrap { order: 4; }
  .chat-header .header-action-btn { width: 40px; height: 40px; font-size: 1.15rem; border-radius: 12px; display: inline-flex; align-items: center; justify-content: center; }
  .chat-header .contact-name { font-size: 1rem; font-weight: 600; }
  .chat-header .contact-meta { flex-wrap: wrap; gap: 4px 6px; overflow: visible; align-items: center; }
  .chat-header .contact-meta > * { flex: none; max-width: 100%; }
  .chat-header .user-role-badge { display: none; }
  .chat-header #takeover-accept-btn, .chat-header #takeover-resolve-btn {
    order: 6; flex: 0 0 auto; height: 34px; margin: 2px 0 6px 6px; padding: 0 14px; box-sizing: border-box;
    border-radius: 17px; font-size: .8rem; line-height: 32px; text-align: center; align-items: center; gap: 5px;
  }
  /* Los botones de takeover van pegados al extremo derecho de su fila (alineados con la lupa y el menu) */
  .chat-header #takeover-accept-btn, .chat-header #takeover-resolve-btn { margin-left: auto; margin-right: 8px; }

  /* ── Aviso (toast): centrado de verdad y sin cortarse ─────────────────── */
  .toast {
    transform: none !important; left: 12px; right: 12px; width: auto; box-sizing: border-box;
    max-width: none; padding: 12px 16px; border-radius: 16px; overflow-wrap: anywhere;
    bottom: calc(78px + var(--safe-bottom, 0px));
  }

  /* ── Hoja de estado: hoja inferior ────────────────────────────────────── */
  .cipsp-menu-backdrop { background: rgba(0, 0, 0, .5); opacity: 0; transition: opacity .2s ease; }
  .cipsp-menu-backdrop.open { opacity: 1; }
  .cipsp-menu {
    left: 0; right: 0; bottom: 0; top: auto; width: auto; max-width: none;
    padding: 6px 12px calc(14px + env(safe-area-inset-bottom, 0px)); border-radius: 20px 20px 0 0; border-width: 1px 0 0;
    transform: translateY(100%); opacity: 1; transform-origin: bottom center; transition: transform .26s cubic-bezier(.2, .8, .2, 1);
  }
  .cipsp-menu.open { transform: none; }
  .cipsp-menu-handle { display: block; width: 38px; height: 4px; margin: 6px auto 4px; border-radius: 2px; background: rgba(255, 255, 255, .25); }
  .cipsp-menu-title { padding-top: 10px; }
  .cipsp-opt { padding: 14px 10px; }
  .cipsp-opt-title { font-size: 1rem; }
  .cipsp-opt-desc { font-size: .82rem; }

  /* Campana: hoja a todo el ancho bajo el encabezado */
  .cip-bell-panel { left: 8px !important; right: 8px; width: auto !important; max-width: none !important; top: 60px !important; max-height: calc(100dvh - 76px) !important; }
}

/* ── Fichas de vista (reemplazan al <select> "Todas" en el teléfono) ── */
.cip-chips { display: none; }
.inbox-filters-bar select.filter-vendor-select, .inbox-filters-bar #filter-view {
  appearance: none; -webkit-appearance: none; height: 34px; padding: 0 32px 0 14px; border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, .12); background-color: rgba(255, 255, 255, .06); color: var(--text, #e8eaf0);
  font: 600 13px/1 inherit; font-family: inherit; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23aab0c0' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; background-size: 14px;
}
.inbox-filters-bar #filter-view:focus-visible { outline: 2px solid var(--accent, #0aff9d); outline-offset: 2px; }
#filter-btn svg { width: 22px; height: 22px; }
@media (max-width: 768px) {
  .inbox-filters-bar { padding: 2px 0 8px !important; }
  .inbox-filters-bar #filter-view { display: none !important; }
  .cip-chips { display: flex; gap: 8px; overflow-x: auto; padding: 6px 12px; scrollbar-width: none; -webkit-overflow-scrolling: touch; width: 100%; box-sizing: border-box; }
  .cip-chips::-webkit-scrollbar { display: none; }
  .cip-chip {
    flex: none; height: 32px; padding: 0 14px; border-radius: 16px; border: 1px solid rgba(255, 255, 255, .1);
    background: rgba(255, 255, 255, .05); color: var(--text-muted, #8b92a8); font: 600 13px/1 inherit; font-family: inherit;
    white-space: nowrap; cursor: pointer; -webkit-tap-highlight-color: transparent; transition: background .15s, color .15s, border-color .15s;
  }
  .cip-chip:active { transform: scale(.97); }
  .cip-chip { display: inline-flex; align-items: center; gap: 6px; }
  /* Contadores: rojos para llamar la atencion y centrados (antes la declaracion font era invalida y el numero quedaba arriba). */
  .cip-chip .cnt { display: inline-flex; align-items: center; justify-content: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; box-sizing: border-box; background: rgba(255, 69, 58, .18); color: #ff6b61; font-family: inherit; font-size: 11px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
  .cip-chip.on .cnt { background: rgba(255, 69, 58, .22); color: #ff6b61; }
  /* "No leidas" resalta: rojo solido, es el numero que importa a simple vista */
  .cip-chip[data-v="unread"] .cnt { background: #ff453a; color: #fff; }
  .cip-chip.on { background: var(--accent-dim, rgba(10, 255, 157, .13)); border-color: rgba(10, 255, 157, .45); color: var(--accent, #0aff9d); }
}

@media (max-width: 350px) {
  .cipsp-pres-label { display: none; }
  .cipsp-pres-btn { padding: 0 9px; gap: 6px; }
}

@media (prefers-reduced-motion: reduce) {
  .cipsp-menu, .cipsp-menu-backdrop, .cipsp-chev, .cipsp-pres-btn { transition: none; }
}

/* Menú ⋮ del chat: "Activar notificaciones" heredaba el estilo de icono (20 px de ancho, texto más chico) */
.overflow-item span#notif-label { font-size: inherit; width: auto; text-align: left; }

/* ── Hoja de filtros (29-oct-2026): rehecha ──────────────────────────────────
   Causa del "no se puede bajar": el panel es flex en columna y sus bloques se COMPRIMÍAN para caber en 80vh
   (min-height:auto de un contenedor con overflow es 0), en vez de desbordar y activar el scroll. */
.filter-sheet-head { display: none; }
@media (max-width: 768px) {
  .filter-panel {
    max-height: min(88vh, 88dvh) !important; padding: 0 16px 0 !important; gap: 0 !important; background: var(--bg-soft);
    overscroll-behavior: contain; -webkit-overflow-scrolling: touch; box-shadow: 0 -12px 40px rgba(0, 0, 0, .5);
  }
  .filter-panel > * { flex-shrink: 0; }
  .filter-panel-handle { margin: 8px auto 0 !important; background: rgba(255, 255, 255, .22) !important; }
  .filter-sheet-head {
    display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 3;
    background: var(--bg-soft); padding: 10px 0 12px;
  }
  .filter-sheet-title { margin: 0; font-size: 1.15rem; font-weight: 700; color: var(--text); letter-spacing: .01em; }
  .filter-sheet-close {
    width: 36px; height: 36px; border-radius: 50%; border: 0; background: rgba(255, 255, 255, .07); color: var(--text-muted);
    font-size: 1.1rem; display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
  }
  .filter-sheet-close:active { background: rgba(255, 255, 255, .14); }

  .filter-panel-section-label, .filter-panel h4 {
    margin: 18px 0 2px !important; font-size: .72rem !important; letter-spacing: .08em; text-transform: uppercase;
    color: var(--accent) !important; font-weight: 700;
  }
  #filter-quick-group { gap: 0 !important; }
  .filter-panel label { display: block; margin: 14px 0 7px; font-size: .8rem; color: var(--text-muted); font-weight: 600; }
  .filter-panel-divider { display: none; }

  /* Selectores: sin la flecha nativa negra; chevron propio y mismo tamaño táctil en todos */
  .filter-panel select:not([multiple]) {
    appearance: none; -webkit-appearance: none; width: 100%; height: 48px; min-height: 48px; padding: 0 42px 0 14px;
    border-radius: 12px; border: 1px solid rgba(255, 255, 255, .12); background-color: rgba(255, 255, 255, .05);
    color: var(--text); font: 500 .95rem/1 inherit; font-family: inherit;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2395a0b8' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 14px center; background-size: 16px;
  }
  .filter-panel select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

  /* Casillas -> fichas tocables (sin scroll interno: la hoja entera se desplaza) */
  .filter-checklist {
    flex-direction: row !important; flex-wrap: wrap; gap: 8px !important; max-height: none !important; overflow: visible !important;
    border: 0 !important; padding: 0 !important; background: none !important;
  }
  .filter-checklist-item {
    position: relative; min-height: 40px !important; padding: 0 16px !important; gap: 0 !important; border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, .12); background: rgba(255, 255, 255, .05); color: var(--text-muted) !important;
    font-size: .88rem !important; font-weight: 600; cursor: pointer; transition: background .15s, border-color .15s, color .15s;
  }
  .filter-checklist-item input[type="checkbox"] { position: absolute; opacity: 0; width: 100% !important; height: 100% !important; inset: 0; margin: 0; cursor: pointer; }
  .filter-checklist-item:has(input:checked) { background: var(--accent-dim, rgba(10, 255, 157, .13)); border-color: rgba(10, 255, 157, .5); color: var(--accent) !important; }
  .filter-checklist-item:has(input:checked)::before { content: '✓'; margin-right: 6px; font-size: .8rem; }
  .filter-checklist-item:active { transform: scale(.97); }
  .filter-checklist:empty::after { content: 'Sin opciones'; color: var(--text-muted); font-size: .85rem; opacity: .7; }

  /* Botones fijos abajo: siempre visibles aunque la lista sea larga */
  .filter-actions {
    position: sticky; bottom: 0; z-index: 3; margin: 18px -16px 0 !important; padding: 12px 16px calc(14px + var(--safe-bottom, 0px));
    background: linear-gradient(to top, var(--bg-soft) 78%, rgba(22, 25, 32, 0)); gap: 10px !important;
  }
  .filter-actions .small-btn { height: 48px; border-radius: 14px; font-size: .98rem; font-weight: 700; flex: 1; }
  .filter-actions #apply-filters { flex: 1.4; background: var(--accent); color: #04130c; border-color: var(--accent); }
  .filter-actions #clear-filters { background: rgba(255, 255, 255, .06); border-color: rgba(255, 255, 255, .12); color: var(--text); }
}

/* ── Zona del indicador de inicio del iPhone (29-oct-2026) ───────────────────────────────────────────────
   Como WhatsApp: el compositor y las hojas dejan un espacio abajo para que la curva de la pantalla y la barra
   del sistema no corten los botones. La página no declara viewport-fit=cover, así que env(safe-area-inset-bottom)
   llega en 0 y todos los "+ var(--safe-bottom)" no hacían nada; --ios-home-gap lo fija mobile_polish.js en el iPhone
   instalado como app. */
:root { --safe-bottom: max(env(safe-area-inset-bottom, 0px), var(--ios-home-gap, 0px)); }

/* ── "Lead" dentro del menú ⋮ (29-oct-2026): fila normal del menú, con el destino a la vista ── */
a.overflow-item-lead { text-decoration: none; color: var(--text); }
.overflow-item span.oi-label { flex: 1; width: auto; text-align: left; font-size: inherit; }
.overflow-item-lead i:first-child { color: var(--accent); }
.overflow-item .oi-ext { width: auto; font-size: 15px; opacity: .55; }
a.overflow-item-lead:active { background: var(--accent-dim) !important; }
/* Las filas del menú ⋮ heredaban width:36px de ".header-actions button" (más específico que .overflow-item):
   el sombreado al tocar solo cubría 36 px. Ahora cada fila ocupa todo el ancho del menú. */
#overflow-menu .overflow-item { width: 100%; box-sizing: border-box; }
/* Las fichas del filtro son <label>: la regla ".filter-panel label" (bloque + márgenes) les quitaba el centrado vertical */
@media (max-width: 768px) {
  .filter-panel label.filter-checklist-item { display: flex; align-items: center; margin: 0; }
}

/* ── Panel del lead (29-oct-2026) ─────────────────────────────────────────── */
.lead-panel {
  position: fixed; inset: 0; z-index: 100000;
  display: flex; flex-direction: column;
  background: var(--bg, #0f1115); color: var(--text, #e8eaf0);
  transform: translateY(100%); visibility: hidden;
  transition: transform .26s cubic-bezier(.2,.8,.2,1), visibility 0s linear .26s;
  will-change: transform;
}
.lead-panel.open { transform: translateY(0); visibility: visible; transition: transform .26s cubic-bezier(.2,.8,.2,1), visibility 0s; }
.lead-panel-bar {
  flex: 0 0 auto; display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top, 0px) + 8px) 10px 8px;
  background: var(--bg-soft, #161920); border-bottom: 1px solid var(--border, #2a2f3a);
  touch-action: pan-x;
}
.lead-panel-back, .lead-panel-ext {
  display: inline-flex; align-items: center; gap: 4px; height: 38px; padding: 0 12px 0 8px;
  border-radius: 999px; border: 1px solid var(--border, #2a2f3a); background: var(--bg-hover, #1e222b);
  color: var(--text, #e8eaf0); font: 600 .86rem/1 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  text-decoration: none; cursor: pointer; flex: 0 0 auto;
}
.lead-panel-back { color: var(--accent, #0aff9d); border-color: rgba(10,255,157,.35); background: rgba(10,255,157,.08); }
.lead-panel-ext { padding: 0 12px; color: var(--text-muted, #8b92a8); }
.lead-panel-back:active, .lead-panel-ext:active { transform: scale(.97); }
.lead-panel-back:focus-visible, .lead-panel-ext:focus-visible, .lead-panel-slowbtn:focus-visible { outline: 2px solid var(--accent, #0aff9d); outline-offset: 2px; }
.lead-panel-title { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; text-align: center; line-height: 1.2; }
.lead-panel-title strong { font-size: .95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lead-panel-title small { font-size: .72rem; color: var(--text-muted, #8b92a8); }
.lead-panel-body { position: relative; flex: 1 1 auto; min-height: 0; background: #fff; }
.lead-panel-frame { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; opacity: 0; transition: opacity .2s ease; background: #fff; }
.lead-panel-frame.lead-ready { opacity: 1; }
.lead-panel-loading, .lead-panel-slow {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: flex-start;
  gap: 14px; padding: 28px 22px; background: var(--bg, #0f1115); color: var(--text-muted, #8b92a8); font-size: .9rem;
}
.lead-panel-slow { inset: auto 0 0 0; padding: 16px 18px calc(env(safe-area-inset-bottom, 0px) + 16px); gap: 10px; align-items: center; text-align: center;
  background: rgba(22,25,32,.96); border-top: 1px solid var(--border, #2a2f3a); backdrop-filter: blur(6px); z-index: 2; }
.lead-panel-slow p { margin: 0; }
.lead-panel-slowbtn { display: inline-flex; align-items: center; height: 40px; padding: 0 18px; border-radius: 999px; background: var(--accent, #0aff9d); color: #04130c; font-weight: 700; text-decoration: none; }
.lead-skel { width: 100%; max-width: 520px; border-radius: 12px; background: linear-gradient(90deg, #1b1f27 25%, #252a35 37%, #1b1f27 63%); background-size: 400% 100%; animation: leadSkel 1.3s ease infinite; }
.lead-skel-a { height: 64px; } .lead-skel-b { height: 140px; } .lead-skel-c { height: 90px; }
@keyframes leadSkel { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }
.lead-hidden { display: none !important; }
html.lead-panel-open, html.lead-panel-open body { overflow: hidden; }
@media (min-width: 900px) {
  .lead-panel { inset: 24px 24px 24px auto; width: min(980px, 72vw); border-radius: 16px; border: 1px solid var(--border, #2a2f3a); box-shadow: 0 20px 60px rgba(0,0,0,.55); overflow: hidden; transform: translateX(110%); }
  .lead-panel.open { transform: translateX(0); }
  .lead-panel-bar { padding-top: 8px; }
}
@media (prefers-reduced-motion: reduce) { .lead-panel, .lead-panel.open { transition: none; } .lead-skel { animation: none; } }

/* ── Encabezado de la bandeja en escritorio (5-nov-2026, pedido de Miguel): MISMA fila unica que en celular.
   [maletin] [numero] [estado] ... [campana] [dashboard] [tres puntos]. Las demas herramientas viven en el menu de tres puntos. */
@media (min-width: 769px) {
  .sidebar-header {
    flex-wrap: nowrap !important; height: 56px !important; min-height: 56px !important;
    padding: 0 6px 0 10px !important; gap: 4px !important; align-items: center; row-gap: 0 !important;
  }
  .sidebar-header .brand { order: 1; flex: 0 0 auto; overflow: visible; }
  .system-status-badge { min-width: 0; max-width: 100%; min-height: 32px; font-size: 12.5px; padding: 0 8px 0 10px; gap: 5px; }
  .system-status-text { overflow: visible; text-overflow: clip; letter-spacing: 0; }
  .cipsp-pres-btn { height: 32px; padding: 0 8px 0 10px; gap: 6px; font-size: 12.5px; }
  .cipsp-pres-inline { order: 2; margin: 0; }
  .sidebar-header .cip-bell-btn { order: 3; margin-left: auto; }
  .sidebar-header #admin-more-btn { order: 5; }
  .sidebar-header .silence-incidents-badge { order: 6; }
  #dashboard-btn, #geo-intelligence-btn, #campaigns-btn, #automations-btn, #workflows-btn, #commercial-context-btn, #waqr-btn { display: none !important; }
  .sidebar-header .dashboard-toggle {
    width: 38px; height: 38px; padding: 0 !important; flex: none;
    display: inline-flex; align-items: center; justify-content: center; border-radius: 12px !important;
  }
}
/* La pildora del numero abre la ventana de numeros de WhatsApp */
#system-status-badge { cursor: pointer; }

/* Teclado abierto (iPhone/Android): la app ocupa solo la zona visible y el campo queda sobre el teclado. */
html.kb-open, html.kb-open body { overflow: hidden; }
html.kb-open .chat-app { position: fixed; top: var(--vv-top, 0px); left: 0; right: 0; height: var(--vvh, 100dvh); }
html.kb-open .modal-overlay { top: var(--vv-top, 0px); bottom: auto; height: var(--vvh, 100dvh); }
html.kb-open .composer { padding-bottom: 8px !important; }
