/* ============================================================
   layout.css  –  App shell, panels, header
   3 columnas: sidebar (calendario + vías) · lista de conversaciones · detalle
   ============================================================ */

/* ── App shell ──────────────────────────────────────────────── */
.app {
  display: grid;
  grid-template-columns: minmax(var(--sidebar-w), 19%) minmax(var(--list-w), 21%) minmax(0, 1fr);
  grid-template-rows: var(--header-h) 1fr;
  height: 100vh;
  height: 100dvh; /* iPhone/Safari: con 100vh la botonera inferior quedaba fuera de pantalla */
  overflow: hidden;
  grid-template-areas:
    "sidebar  list-hdr  detail-hdr"
    "sidebar  list      detail";
}

/* ── Cabeceras (lista + detalle) ────────────────────────────── */
.list-header,
.detail-header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  padding: 0 16px;
  background: var(--gray-0);
  border-bottom: 1px solid var(--gray-200);
  border-left: 1px solid var(--gray-200);
  gap: 12px;
}
.list-header   { grid-area: list-hdr; }
.detail-header { grid-area: detail-hdr; }
.detail-header-inner { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; }

/* Botón «volver» del detalle (vuelve a la lista en móvil): oculto en
   escritorio, se muestra en la media query de más abajo */
.btn-back {
  display: none;
  flex-shrink: 0;
  width: 34px; height: 34px;
  align-items: center; justify-content: center;
  border-radius: var(--r-md);
  color: var(--gray-600);
}
.btn-back:hover { background: var(--gray-100); color: var(--tinta); }
.btn-back svg { width: 19px; height: 19px; }

.list-title { font-size: .95rem; font-weight: 700; color: var(--petroleo); }
.list-count {
  margin-left: auto;
  font-size: .72rem;
  background: var(--gray-100);
  padding: 2px 8px;
  border-radius: var(--r-full);
  color: var(--gray-600);
  font-weight: 600;
}

/* ── Sidebar (logo + calendario + vías) ─────────────────────── */
.sidebar {
  grid-area: sidebar;
  grid-row: 1 / -1;
  background: var(--petroleo);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sidebar-logo {
  height: var(--header-h);
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  flex-shrink: 0;
}
.sidebar-logo-img { display: block; height: 36px; width: auto; }

.sidebar-user {
  margin-left: auto;
  font-size: .78rem;
  color: var(--on-dark-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 90px;
}
.sidebar-logout-btn {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border: none;
  border-radius: var(--r-md);
  background: transparent;
  color: var(--on-dark-muted);
  cursor: pointer;
}
.sidebar-logout-btn svg { width: 17px; height: 17px; }
.sidebar-logout-btn:hover { background: rgba(255,255,255,.08); color: var(--on-dark); }

/* Envuelve calendario + vías + estadísticas: si no cabe todo, hace scroll
   este contenedor entero en vez de recortar contenido */
.sidebar-scroll {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.sidebar-content { flex-shrink: 0; padding: 10px 12px; }

/* ── Vías de comunicación: justo debajo del calendario ──────── */
.sidebar-canales {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 4px 16px 10px;
  border-top: 1px solid rgba(255,255,255,.08);
}

.btn-canal {
  width: 100%;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(247,244,239,.07);
  border: 1px solid rgba(247,244,239,.1);
  border-radius: var(--r-lg);
  color: var(--on-dark);
  font-size: .88rem;
  font-weight: 600;
  text-align: left;
  position: relative;
  transition: background var(--t-fast), border-color var(--t-fast);
}
.btn-canal:hover { background: rgba(247,244,239,.14); }
.btn-canal.active {
  background: rgba(39,201,178,.16);
  border-color: var(--brand-300);
  /* outline (no border/box-shadow) para que se note seleccionada incluso
     cuando también "tiene-escalado" le pinta el fondo/borde de rojo y
     pulsando - si no, antes se perdía del todo cuál vía estaba activa. */
  outline: 2px solid var(--brand-300);
  outline-offset: 2px;
}
.btn-canal-icon {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: rgba(247,244,239,.1);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.btn-canal-icon svg { width: 20px; height: 20px; }
.btn-canal-label { flex: 1; min-width: 0; }
.btn-canal-sub { font-size: .7rem; font-weight: 500; color: var(--on-dark-muted); margin-top: 1px; }

.btn-canal-badges { display: flex; align-items: center; gap: 5px; flex-shrink: 0; }
.canal-badge {
  min-width: 22px; height: 22px;
  padding: 0 6px;
  border-radius: var(--r-full);
  font-size: .72rem;
  font-weight: 800;
  display: flex; align-items: center; justify-content: center;
}
.canal-badge.pendiente { background: var(--amber-500); color: var(--tinta); }
.canal-badge.escalado  { background: var(--red-500); color: #fff; }
.canal-badge[hidden] { display: none; }

/* Botón con escalados: rojo y parpadeante (llama la atención de verdad) */
.btn-canal.tiene-escalado {
  border-color: var(--red-500);
  animation: canalPulse 1.4s ease-in-out infinite;
}
@keyframes canalPulse {
  0%, 100% { background: rgba(217,80,61,.14); box-shadow: 0 0 0 0 rgba(217,80,61,.35); }
  50%      { background: rgba(217,80,61,.30); box-shadow: 0 0 0 6px rgba(217,80,61,0); }
}

/* ── Estadísticas: totales por vía y por estado (histórico completo) ── */
.sidebar-stats {
  flex-shrink: 0;
  padding: 6px 16px 4px;
  border-top: 1px solid rgba(255,255,255,.08);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stats-title {
  font-size: .6rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--on-dark-muted);
  margin-bottom: 2px;
}
.stats-grid { display: grid; gap: 6px; }
.stats-grid-4 { grid-template-columns: 1fr 1fr 1fr 1fr; }
.stats-grid-3 { grid-template-columns: 1fr 1fr 1fr; }

.stat-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;   /* si el tile de al lado es más alto (p.ej. la
                                 etiqueta "Contento + Neutro" en 2 líneas),
                                 este se queda centrado en vez de pegado arriba */
  gap: 1px;
  padding: 4px 4px;
  border-radius: var(--r-sm);
  background: rgba(247,244,239,.07);
  border: 1px solid rgba(247,244,239,.1);
  min-width: 0;   /* si no, un label largo (p.ej. "Contento + Neutro") fuerza su
                     columna del grid más ancha que las demás y descuadra la fila */
}
.stat-tile-total { background: rgba(39,201,178,.14); border-color: rgba(39,201,178,.25); }
.stat-num { font-size: .92rem; font-weight: 800; color: var(--on-dark); line-height: 1.1; }
.stat-label { font-size: .6rem; font-weight: 600; color: var(--on-dark-muted); white-space: nowrap; }

.stat-pendiente .stat-num { color: var(--amber-300); }
.stat-resuelto  .stat-num { color: var(--brand-300); }
.stat-escalado  .stat-num { color: var(--red-300); }

/* ── Satisfacción (caritas): 3 tiles de % + 1 tile de media con semáforo.
   Fila compacta (mismo alto que las demás) para no añadir scroll al sidebar. ── */
.stat-sat-carita { padding: 2px 2px; }
.stat-sat-carita .stat-num {
  font-size: .78rem;
  white-space: nowrap;   /* la carita y el % siempre en la misma línea,
                            pase lo que pase con la fuente de emojis */
  line-height: 1;         /* algunas fuentes de emoji dejan mucho hueco
                             vertical de más y empujaban el número abajo */
}
/* La etiqueta "Contento + Neutro" no cabe en una sola línea en una columna
   igual a las otras 3 - se deja partir en 2 líneas en vez de desbordar
   (lo que antes descuadraba la fila entera). */
#stat-sat-global-tile .stat-label { white-space: normal; text-align: center; line-height: 1.15; }

.stat-sat-rojo     { background: rgba(217,80,61,.18);  border-color: rgba(217,80,61,.3); }
.stat-sat-rojo .stat-num     { color: var(--red-300); }
.stat-sat-amarillo { background: rgba(232,148,74,.18); border-color: rgba(232,148,74,.3); }
.stat-sat-amarillo .stat-num { color: var(--amber-300); }
.stat-sat-verde    { background: rgba(39,201,178,.18); border-color: rgba(39,201,178,.3); }
.stat-sat-verde .stat-num    { color: var(--brand-300); }

/* ── Panel de lista (conversaciones / llamadas) ─────────────── */
.list-panel {
  grid-area: list;
  background: var(--gray-0);
  border-left: 1px solid var(--gray-200);
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.list-search {
  position: relative;
  padding: 10px 12px;
  border-bottom: 1px solid var(--gray-100);
  flex-shrink: 0;
}
.list-search input {
  width: 100%;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--r-full);
  padding: 8px 34px 8px 36px;
  font-size: .85rem;
  color: var(--tinta);
  background: var(--gray-50);
  transition: border-color var(--t-fast), background var(--t-fast);
}
.list-search input:focus { outline: none; border-color: var(--brand-500); background: #fff; }
.list-search input::placeholder { color: var(--gray-400); }
.list-search input::-webkit-search-cancel-button { display: none; }
.list-search-icon {
  position: absolute; left: 24px; top: 50%;
  width: 16px; height: 16px;
  transform: translateY(-50%);
  color: var(--gray-500);
  pointer-events: none;
}
.list-search-clear {
  position: absolute; right: 20px; top: 50%;
  width: 22px; height: 22px;
  transform: translateY(-50%);
  border-radius: 50%;
  display: none;
  align-items: center; justify-content: center;
  font-size: .7rem;
  color: var(--gray-500);
}
.list-search-clear:hover { background: var(--gray-100); color: var(--tinta); }

/* Filtro por estado (pestañas) */
.estado-tabs {
  display: flex; gap: 6px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--gray-100);
  flex-shrink: 0;
  overflow-x: auto;
}
.estado-tab {
  padding: 5px 12px;
  border-radius: var(--r-full);
  font-size: .76rem;
  font-weight: 700;
  color: var(--gray-600);
  background: var(--gray-100);
  white-space: nowrap;
  flex-shrink: 0;
}
.estado-tab.active { background: var(--petroleo); color: #fff; }

.list-items { flex: 1; overflow-y: auto; display: flex; flex-direction: column; }

/* Filtro de día activo (procedente del calendario) */
.filtro-dia-chip {
  display: none;
  align-items: center; gap: 6px;
  margin: 8px 12px 0;
  padding: 5px 10px;
  border-radius: var(--r-full);
  background: var(--brand-50);
  color: var(--brand-700);
  font-size: .76rem; font-weight: 700;
  flex-shrink: 0;
}
.filtro-dia-chip.show { display: flex; }
.filtro-dia-chip button { color: var(--brand-600); font-weight: 800; }

/* ── Item de conversación / llamada ──────────────────────────── */
.conv-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 16px;
  cursor: pointer;
  transition: background var(--t-fast);
  border-bottom: 1px solid var(--gray-100);
  position: relative;
}
.conv-item:hover  { background: var(--gray-50); }
.conv-item.active { background: var(--brand-50); }
.conv-item.active::before {
  content: '';
  position: absolute; left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--brand-500);
  border-radius: 0 2px 2px 0;
}
.conv-avatar {
  position: relative;
  width: 42px; height: 42px;
  border-radius: 50%;
  background: var(--brand-100);
  color: var(--brand-700);
  font-weight: 700;
  font-size: .82rem;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
/* Icono de la vía (whatsapp/email/llamada) sobre el avatar, solo cuando se
   combinan varias vías a la vez en el panel central */
.conv-avatar-canal {
  position: absolute; right: -3px; bottom: -3px;
  width: 17px; height: 17px;
  border-radius: 50%;
  background: var(--gray-0);
  border: 1.5px solid var(--gray-0);
  box-shadow: 0 0 0 1px var(--gray-200);
  display: flex; align-items: center; justify-content: center;
  color: var(--brand-700);
}
.conv-avatar-canal svg { width: 9px; height: 9px; }
.conv-meta { flex: 1; min-width: 0; }
.conv-row  { display: flex; align-items: center; gap: 8px; min-width: 0; }
.conv-name { font-size: .87rem; font-weight: 600; color: var(--tinta); }
.conv-id   { font-size: .76rem; color: var(--gray-500); }
.conv-time { margin-left: auto; flex-shrink: 0; font-size: .7rem; color: var(--gray-500); }
.conv-preview { flex: 1; min-width: 0; font-size: .78rem; color: var(--gray-500); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

/* Estado pill (reutilizada en lista + cabecera de detalle) */
.estado-pill {
  font-size: .6rem;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: var(--r-full);
  white-space: nowrap;
  flex-shrink: 0;
}
.estado-pill.pendiente { background: var(--amber-100); color: var(--amber-700); }
.estado-pill.resuelto  { background: var(--brand-100); color: var(--petroleo); }
.estado-pill.escalado  { background: var(--red-100);   color: var(--red-600); }

.estado-pill-btn { cursor: pointer; border: 1.5px solid transparent; }
.estado-pill-btn:hover { border-color: currentColor; }

/* Buzón de correo al que llegó la conversación (solo email): color
   calculado por JS a partir del propio correo, así cada cuenta se
   distingue siempre con el mismo color. Ver Bandeja.chip() en data.js */
.bandeja-chip {
  display: inline-flex;
  align-items: center;
  margin-left: 6px;
  padding: 2px 8px;
  border-radius: var(--r-full);
  font-size: .66rem;
  font-weight: 700;
  white-space: nowrap;
  flex-shrink: 0;
  vertical-align: middle;
}

/* ── Lista: estado vacío ─────────────────────────────────────── */
.list-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--gray-400);
  font-size: .85rem;
  padding: 32px;
  text-align: center;
}
.list-empty-icon { font-size: 2.5rem; }

/* ── Panel de detalle ────────────────────────────────────────── */
.detail-panel {
  grid-area: detail;
  background: var(--gray-0);
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}
.detail-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--gray-400);
  text-align: center;
  padding: 32px;
}
.detail-empty-icon { font-size: 2.8rem; }

/* Cabecera de detalle activa */
.detail-header-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.detail-header-name { font-size: .92rem; font-weight: 700; color: var(--tinta); }
.detail-header-sub   { font-size: .74rem; color: var(--gray-500); }
.detail-header-canal {
  width: 36px; height: 36px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  background: var(--brand-100); color: var(--brand-700);
}
.detail-header-canal svg { width: 18px; height: 18px; }

/* Carita de ánimo (1 😡 · 2 😐 · 3 😄), junto al identificador */
.animo { display: inline-block; margin-left: 6px; font-size: 1rem; cursor: help; vertical-align: middle; letter-spacing: 0; }

/* ════════════════════════════════════════════════════════════════
   RESPONSIVE (≤1024px: tablet y móvil)
   Estilo barra inferior, como el resto de proyectos NexaCall: se
   ve una única pantalla a la vez (Calendario, una vía, o el detalle
   de una conversación/llamada) y se navega con 4 pestañas fijas
   abajo. En escritorio (>1024px) todo sigue igual, en 3 columnas.
   ════════════════════════════════════════════════════════════════ */
@media (max-width: 1024px) {
  .app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: var(--header-h) 1fr auto;
    grid-template-areas:
      "hdr"
      "content"
      "tabbar";
  }

  /* Las 3 "pantallas" ocupan el mismo hueco; solo se ve la activa */
  .sidebar      { grid-row: 1 / 3; grid-column: 1; width: 100%; box-shadow: none; }
  .list-header, .detail-header { grid-area: hdr; }
  .list-panel,  .detail-panel  { grid-area: content; }
  /* Sin esto, un grid/flex container no se encoge por debajo del ancho
     mínimo de su contenido (p.ej. una burbuja de mensaje larga) y todo
     el panel se desborda por la derecha, recortado por el overflow:hidden
     del body - que es justo lo que pasaba con los mensajes largos */
  .sidebar, .list-header, .list-panel, .detail-header, .detail-panel { min-width: 0; }

  .sidebar, .list-header, .list-panel, .detail-header, .detail-panel { display: none; }

  .app[data-view="calendario"] .sidebar { display: flex; }

  .app[data-view="whatsapp"] .list-header, .app[data-view="whatsapp"] .list-panel,
  .app[data-view="email"]    .list-header, .app[data-view="email"]    .list-panel,
  .app[data-view="llamada"]  .list-header, .app[data-view="llamada"]  .list-panel {
    display: flex;
  }

  .app[data-view="detail"] .detail-header { display: flex; }
  .app[data-view="detail"] .detail-panel  { display: flex; }
  .app[data-view="detail"] .bottom-tabbar { display: none; }

  .btn-back { display: flex; }

  /* Las vías (botones del sidebar) y los bordes de columna ya no
     hacen falta: la navegación entre vías la da la barra inferior */
  .sidebar-canales { display: none; }
  .list-header, .list-panel, .detail-header, .detail-panel { border-left: none; }

  /* En móvil el truncado de 320px del resumen bajo el nombre no cabe */
  .detail-header-resumen { max-width: 46vw; }
}

/* ── Barra inferior de navegación (Calendario + 3 vías) ─────────── */
.bottom-tabbar {
  grid-area: tabbar;
  display: none;
  background: var(--gray-0);
  border-top: 1px solid var(--gray-200);
  padding-bottom: env(safe-area-inset-bottom);
}
@media (max-width: 1024px) {
  .bottom-tabbar { display: flex; }
}
.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 8px 2px 7px;
  color: var(--gray-500);
  font-size: .64rem;
  font-weight: 600;
}
.tab-btn svg { width: 21px; height: 21px; }
.tab-btn.active { color: var(--petroleo); }
.tab-icon-wrap { position: relative; }
.tab-badge {
  position: absolute; top: -4px; right: -8px;
  min-width: 16px; height: 16px;
  padding: 0 4px;
  border-radius: var(--r-full);
  background: var(--amber-500);
  color: var(--tinta);
  font-size: .6rem;
  font-weight: 800;
  display: flex; align-items: center; justify-content: center;
}
.tab-badge[hidden] { display: none; }
/* Si hay algo escalado en esa vía, la pestaña entera parpadea en rojo
   (misma animación que el botón de vía del sidebar en escritorio) */
.tab-btn.tiene-escalado { color: var(--red-500); animation: canalPulseTab 1.4s ease-in-out infinite; }
@keyframes canalPulseTab {
  0%, 100% { opacity: 1; }
  50%      { opacity: .55; }
}
