/* NI Ventas · App layout & components — built on top of brand.css */

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(255,24,48,.06), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(143,212,222,.05), transparent 60%),
    var(--bg);
  min-height: 100vh;
}
a { color: var(--accent-alt); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; cursor: pointer; }

/* ============ APP SHELL ============ */
.app {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
}

/* ============ SIDEBAR ============ */
.sidebar {
  background: var(--ink-100);
  border-right: 1px solid var(--border);
  padding: var(--s-5) var(--s-4);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--s-5);
}
@media (max-width: 900px) {
  .sidebar { position: static; height: auto; }
}
.brand {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  padding: var(--s-2) 0 var(--s-4);
  border-bottom: 1px solid var(--border);
}
.brand-logo {
  width: 100%;
  max-width: 150px;
  height: auto;
  display: block;
  filter: drop-shadow(0 0 6px rgba(255,24,48,.4)) drop-shadow(0 0 10px rgba(42,216,255,.25));
}
.brand .b-sub {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: var(--tr-xwide);
  text-transform: uppercase;
  color: var(--fg-muted);
}
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--r-sm);
  color: var(--fg-muted);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  background: transparent;
  width: 100%;
  text-align: left;
  transition: background var(--dur-fast), color var(--dur-fast);
}
.nav-item:hover { background: var(--ink-200); color: var(--fg); }
.nav-item.active {
  background: var(--ink-200);
  color: var(--fg);
  border-color: var(--border);
  box-shadow: inset 0 0 0 1px rgba(255,24,48,.15);
}
.nav-item .icon { width: 16px; text-align: center; opacity: .85; }
.nav-item .badge {
  margin-left: auto;
  background: var(--neon-red);
  color: white;
  font-size: 10px;
  font-weight: 700;
  font-family: var(--font-mono);
  padding: 1px 7px;
  border-radius: var(--r-pill);
  min-width: 18px;
  text-align: center;
  box-shadow: var(--glow-red-sm);
}
.nav-item .badge.cyan { background: var(--neon-cyan); color: var(--ink-050); box-shadow: var(--glow-cyan-sm); }
.sidebar-foot {
  margin-top: auto;
  padding-top: var(--s-4);
  border-top: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--fg-faint);
  letter-spacing: var(--tr-xwide);
  text-transform: uppercase;
}
.sidebar-foot .status-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--success);
  margin-right: 6px;
  animation: pulse 2s infinite;
}
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .4; } }
/* Badge "✨ Generando IA…" de las brief-cards del kanban. Antes cada card
   inyectaba su propio <style> con esta @keyframes (N cards = N <style> idénticos). */
@keyframes nv-pulse { 0%,100% { opacity: .55; } 50% { opacity: 1; } }

/* ============ MAIN ============ */
.main { padding: var(--s-5) var(--s-6); max-width: 1400px; }
@media (max-width: 900px) { .main { padding: var(--s-4); } }

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: var(--s-5);
  gap: var(--s-4);
  flex-wrap: wrap;
}
.page-head h1 {
  font-family: var(--font-display);
  font-size: var(--t-h1);
  line-height: var(--lh-tight);
  letter-spacing: var(--tr-tight);
  text-transform: uppercase;
  color: var(--fg);
  margin: 0;
}
.page-head .eyebrow {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: var(--tr-xwide);
  text-transform: uppercase;
  color: var(--neon-cyan);
  text-shadow: 0 0 6px rgba(143,212,222,.35);
  margin-bottom: 8px;
  display: inline-block;
  padding: 4px 10px;
  border: 1px solid rgba(143,212,222,.25);
  border-radius: var(--r-pill);
  background: rgba(143,212,222,.06);
}
.page-head .actions { display: flex; gap: var(--s-2); }

/* ============ BUTTONS ============ */
.btn {
  border: 1px solid var(--border);
  background: var(--ink-200);
  color: var(--fg);
  padding: 9px 16px;
  border-radius: var(--r-sm);
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font-sans);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: background var(--dur-fast), border-color var(--dur-fast), box-shadow var(--dur-fast);
}
.btn:hover { background: var(--ink-300); border-color: var(--border-strong); }
.btn-primary {
  background: var(--neon-red);
  color: white;
  border-color: var(--neon-red);
}
.btn-primary:hover { background: var(--neon-red-glow); border-color: var(--neon-red-glow); box-shadow: var(--glow-red-sm); }
.btn-cyan {
  background: var(--neon-cyan);
  color: var(--ink-050);
  border-color: var(--neon-cyan);
}
.btn-cyan:hover { background: var(--neon-cyan-glow); box-shadow: var(--glow-cyan-sm); }
.btn-ghost { background: transparent; }
.btn-ghost.btn-cyan { background: var(--neon-cyan); color: var(--ink-050); border-color: var(--neon-cyan); }
.btn .icon { font-size: 14px; }
.btn-icon { padding: 9px 10px; }
.btn-icon svg { display: block; }

/* ============ CARDS ============ */
/* ===== Panel de Automatizaciones WhatsApp (Fase 1, read-only) ===== */
.auto-banner { padding: 12px 16px; border-radius: 10px; margin-bottom: 18px; font-size: 13px; line-height: 1.4; }
.auto-banner.warn { background: rgba(255,176,32,.12); border: 1px solid rgba(255,176,32,.4); color: #ffce7a; }
.auto-group { margin-bottom: 24px; }
.auto-group-h { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted, #8a93a3); margin: 0 0 12px; font-weight: 600; }
.auto-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 12px; }
.auto-card { padding: 14px 16px; }
.auto-card-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.auto-name { font-weight: 600; font-size: 14px; color: var(--fg, #e8eaed); }
.auto-badge { font-size: 9.5px; padding: 2px 9px; border-radius: 999px; white-space: nowrap; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; }
.auto-badge.on   { background: rgba(46,213,115,.16); color: #2ed573; }
.auto-badge.live { background: rgba(0,210,255,.16); color: #00d2ff; }
.auto-badge.done { background: rgba(120,144,156,.18); color: #b0bec5; }
.auto-badge.warn { background: rgba(255,176,32,.16); color: #ffb020; }
.auto-badge.off  { background: rgba(255,71,87,.14); color: #ff6b78; }
.auto-badge.idle { background: rgba(120,144,156,.12); color: #90a4ae; }
.auto-desc { font-size: 12.5px; color: var(--muted, #8a93a3); line-height: 1.45; margin-bottom: 8px; }
.auto-trigger { font-size: 11px; color: var(--muted, #8a93a3); opacity: .85; margin-bottom: 10px; }
.auto-stats { display: flex; flex-wrap: wrap; gap: 6px; }
.auto-stat { font-size: 11px; padding: 3px 8px; border-radius: 6px; background: rgba(255,255,255,.06); color: var(--fg, #e8eaed); }
.auto-stat b { font-weight: 700; }
.auto-foot { margin-top: 16px; font-size: 11px; color: var(--muted, #8a93a3); }

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--s-4);
  box-shadow: var(--inner-card);
}
.card-h {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--s-3);
  gap: var(--s-2);
}
.card-h h3 {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: var(--tr-snug);
  color: var(--fg);
  text-transform: uppercase;
}
.card-h .meta {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-subtle);
  letter-spacing: var(--tr-wide);
}

/* ============ KPI GRID ============ */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--s-3);
  margin-bottom: var(--s-5);
}
.kpi {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--s-4);
  position: relative;
  overflow: hidden;
}
.kpi::before {
  content: '';
  position: absolute;
  top: 0; right: 0;
  width: 80px; height: 80px;
  background: radial-gradient(circle at center, rgba(255,24,48,.08), transparent 70%);
  pointer-events: none;
}
.kpi.cyan::before { background: radial-gradient(circle at center, rgba(143,212,222,.08), transparent 70%); }
.kpi-label {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: var(--tr-xwide);
  text-transform: uppercase;
  color: var(--fg-subtle);
  margin-bottom: 8px;
}
.kpi-value {
  font-family: var(--font-display);
  font-size: 32px;
  letter-spacing: var(--tr-tight);
  color: var(--fg);
  line-height: 1;
}
.kpi-delta {
  font-family: var(--font-mono);
  font-size: 11px;
  margin-top: 6px;
  color: var(--fg-faint);
}
.kpi-delta.up { color: var(--success); }
.kpi-delta.down { color: var(--neon-red); }

/* ============ TABLE ============ */
.table-wrap {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  overflow: hidden;
}
.table-toolbar {
  display: flex;
  gap: var(--s-2);
  align-items: center;
  padding: var(--s-3) var(--s-4);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.table-toolbar input,
.table-toolbar select {
  background: var(--ink-100);
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 7px 10px;
  border-radius: var(--r-sm);
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color var(--dur-fast);
}
.table-toolbar input:focus,
.table-toolbar select:focus { border-color: var(--neon-cyan); }
.table-toolbar input[type=text] { min-width: 200px; }
.table-toolbar .right { margin-left: auto; display: flex; gap: var(--s-2); align-items: center; font-family: var(--font-mono); font-size: 11px; color: var(--fg-subtle); letter-spacing: var(--tr-wide); }

table.t {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.t th, table.t td {
  text-align: left;
  padding: var(--s-3) var(--s-4);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
table.t th {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: var(--tr-xwide);
  text-transform: uppercase;
  color: var(--fg-subtle);
  font-weight: 500;
  background: var(--ink-100);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
table.t th:hover { color: var(--fg); }
table.t th .sort { font-size: 9px; opacity: .5; margin-left: 4px; }
table.t th.sorted .sort { opacity: 1; color: var(--neon-cyan); }
table.t tr { transition: background var(--dur-fast); }
table.t tbody tr:hover { background: var(--ink-100); cursor: pointer; }
table.t td.num { font-family: var(--font-mono); text-align: right; }
table.t td.cliente { font-weight: 600; }
.empty-row td { text-align: center; color: var(--fg-faint); padding: 40px; font-style: italic; }

/* ============ PILL / BADGE ============ */
.pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: var(--r-pill);
  font-size: 11px;
  font-weight: 600;
  font-family: var(--font-mono);
  letter-spacing: var(--tr-wide);
  text-transform: uppercase;
  border: 1px solid var(--border);
  background: var(--ink-100);
  color: var(--fg-muted);
  white-space: nowrap;
}
.pill.green { background: rgba(74,222,128,.12); color: #6ef0a0; border-color: rgba(74,222,128,.3); }
.pill.amber { background: rgba(255,184,77,.12); color: #ffc97a; border-color: rgba(255,184,77,.3); }
.pill.red   { background: rgba(255,24,48,.12); color: #ff5a6e; border-color: rgba(255,24,48,.35); }
.pill.cyan  { background: rgba(143,212,222,.12); color: var(--neon-cyan); border-color: rgba(143,212,222,.3); }
.pill.muted { background: var(--ink-200); color: var(--fg-subtle); }
.pill.blue   { background: rgba(80,140,255,.14); color: #8ab4ff; border-color: rgba(80,140,255,.32); }
.pill.violet { background: rgba(155,92,255,.14); color: #c4a0ff; border-color: rgba(155,92,255,.32); }

.tag-d30 { background: rgba(74,222,128,.15); color: #6ef0a0; }
.tag-d60 { background: rgba(255,184,77,.15); color: #ffc97a; }
.tag-d90 { background: rgba(255,24,48,.18); color: #ff5a6e; }

/* ============ DRAWER ============ */
.drawer-bg {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-base);
  z-index: 50;
}
.drawer-bg.open { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed;
  top: 0; right: 0;
  height: 100vh;
  width: min(540px, 92vw);
  background: var(--ink-100);
  border-left: 1px solid var(--border);
  transform: translateX(100%);
  transition: transform var(--dur-base) var(--ease-out);
  z-index: 60;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.drawer.open { transform: translateX(0); }
.drawer-h {
  padding: var(--s-4) var(--s-5);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  position: sticky; top: 0; background: var(--ink-100); z-index: 1;
}
.drawer-h h2 { margin: 0; font-family: var(--font-display); font-size: 22px; letter-spacing: var(--tr-tight); text-transform: uppercase; color: var(--fg); }
.drawer-h .close { background: transparent; border: 1px solid var(--border); color: var(--fg); width: 32px; height: 32px; border-radius: var(--r-sm); font-size: 16px; line-height: 1; }
.drawer-h .close:hover { border-color: var(--neon-red); color: var(--neon-red); }
.drawer-body { padding: var(--s-5); flex: 1; }
.drawer-section { margin-bottom: var(--s-5); }
.drawer-section h4 {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: var(--tr-xwide);
  text-transform: uppercase;
  color: var(--fg-subtle);
  margin: 0 0 var(--s-3);
}
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 8px 16px; font-size: 13px; }
.kv dt { color: var(--fg-subtle); font-family: var(--font-mono); font-size: 11px; text-transform: uppercase; letter-spacing: var(--tr-wide); padding-top: 2px; }
.kv dd { margin: 0; color: var(--fg); }

/* ============ TIMELINE ============ */
.timeline { position: relative; padding-left: 26px; }
.timeline::before {
  content: '';
  position: absolute;
  left: 9px;
  top: 6px;
  bottom: 6px;
  width: 1px;
  background: var(--border-strong);
}
.tl-item { position: relative; padding-bottom: var(--s-4); }
.tl-item:last-child { padding-bottom: 0; }
.tl-item::before {
  content: '';
  position: absolute;
  left: -22px;
  top: 4px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--ink-200);
  border: 2px solid var(--border-strong);
}
.tl-item.done::before { background: var(--success); border-color: var(--success); box-shadow: 0 0 8px rgba(74,222,128,.5); }
.tl-item.future::before { background: var(--ink-200); border-color: var(--border); }
.tl-item.now::before { background: var(--neon-red); border-color: var(--neon-red); box-shadow: var(--glow-red-sm); }
.tl-date { font-family: var(--font-mono); font-size: 11px; color: var(--fg-subtle); letter-spacing: var(--tr-wide); text-transform: uppercase; }
.tl-title { font-size: 14px; font-weight: 600; margin: 2px 0; color: var(--fg); }
.tl-desc { font-size: 13px; color: var(--fg-muted); }

/* ============ CHARTS ============ */
.chart-grid {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  gap: var(--s-3);
  margin-bottom: var(--s-5);
}
@media (max-width: 1100px) { .chart-grid { grid-template-columns: 1fr 1fr; } }
@media (max-width: 700px)  { .chart-grid { grid-template-columns: 1fr; } }

.chart-canvas {
  width: 100%;
  height: 240px;
  position: relative;
}
.chart-tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--ink-100);
  border: 1px solid var(--neon-red);
  box-shadow: var(--glow-red-sm);
  padding: 6px 10px;
  border-radius: var(--r-sm);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: var(--tr-wide);
  z-index: 5;
  white-space: nowrap;
}
.chart-tooltip .tt-d { color: var(--fg-subtle); font-size: 10px; text-transform: uppercase; }
.chart-tooltip .tt-v { color: var(--fg); font-weight: 700; font-size: 13px; margin-top: 2px; }
.chart-tooltip .tt-sub { color: var(--neon-cyan); font-size: 10px; margin-top: 2px; }
.chart-svg .hover-line { stroke: var(--neon-red); stroke-width: 1; stroke-dasharray: 3 3; opacity: .6; }
.chart-svg .hover-dot { fill: var(--neon-red); stroke: var(--bg-card); stroke-width: 2; filter: drop-shadow(0 0 6px rgba(255,24,48,.8)); }
.chart-svg .hover-capture { cursor: crosshair; }
.chart-svg .wk-seg { transition: opacity var(--dur-fast); cursor: pointer; }
.chart-svg .wk-seg:hover { opacity: .85; filter: drop-shadow(0 0 6px currentColor); }
.chart-tooltip .tt-row { display: flex; align-items: center; gap: 6px; font-size: 10px; color: var(--fg-muted); margin-top: 2px; }
.chart-tooltip .tt-dot { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }
.chart-legend-row { display: flex; flex-wrap: wrap; gap: 6px 12px; margin-top: 8px; padding: 0 4px; font-size: 11px; color: var(--fg-muted); }
.chart-legend-row .lg-i { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend-row .lg-d { width: 10px; height: 10px; border-radius: 2px; }

/* ============ CHART CAROUSEL ============ */
.chart-card .card-h { gap: var(--s-3); }
.chart-nav { display: flex; align-items: center; gap: 8px; }
.chart-arrow {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg-muted);
  width: 28px; height: 28px;
  border-radius: var(--r-sm);
  font-size: 18px; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
  font-family: var(--font-display);
  padding: 0;
  transition: all var(--dur-fast);
}
.chart-arrow:hover { border-color: var(--neon-cyan); color: var(--neon-cyan); box-shadow: var(--glow-cyan-sm); }
.chart-dots { display: inline-flex; gap: 6px; }
.chart-dots .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--ink-400);
  cursor: pointer;
  transition: all var(--dur-fast);
}
.chart-dots .dot.active { background: var(--neon-red); box-shadow: var(--glow-red-sm); width: 18px; border-radius: 4px; }
.chart-dots .dot:hover:not(.active) { background: var(--ink-600); }
.chart-svg { width: 100%; height: 100%; overflow: visible; }
.chart-svg .axis { stroke: var(--border); stroke-width: 1; }
.chart-svg .grid { stroke: var(--border); stroke-width: 1; stroke-dasharray: 2 4; opacity: .5; }
.chart-svg .label { fill: var(--fg-subtle); font-family: var(--font-mono); font-size: 10px; }
.chart-svg .bar { fill: var(--neon-cyan); }
.chart-svg .bar:hover { fill: var(--neon-cyan-glow); }
.chart-svg .line { fill: none; stroke: var(--neon-red); stroke-width: 2; filter: drop-shadow(0 0 6px rgba(255,24,48,.5)); }
.chart-svg .point { fill: var(--neon-red); }
.chart-svg .area { fill: url(#redGrad); opacity: .85; }
.donut-cy { stroke-width: 18; fill: none; transform: rotate(-90deg); transform-origin: center; }
.donut-center { font-family: var(--font-display); font-size: 22px; fill: var(--fg); text-anchor: middle; dominant-baseline: central; }
.legend { display: flex; flex-wrap: wrap; gap: 8px 12px; margin-top: var(--s-2); font-size: 11px; color: var(--fg-muted); }
.legend .lg-i { display: flex; align-items: center; gap: 6px; }
.legend .lg-d { width: 8px; height: 8px; border-radius: 50%; }

/* ============ ALERTS / SECTIONS ============ */
.alerts-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-3); margin-bottom: var(--s-5); }
@media (max-width: 900px) { .alerts-grid { grid-template-columns: 1fr; } }

.alert-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--s-4);
}
.alert-card .h {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: var(--s-3);
  gap: 8px;
}
.alert-card h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: var(--tr-snug);
}
.alert-card.red h3 { color: var(--neon-red); }
.alert-card.cyan h3 { color: var(--neon-cyan); }
.alert-card .count {
  font-family: var(--font-display);
  font-size: 32px;
  line-height: 1;
}
.alert-list { list-style: none; padding: 0; margin: 0; max-height: 240px; overflow-y: auto; }
.alert-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.alert-list li:last-child { border-bottom: 0; }
.alert-list .who { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--fg); font-weight: 500; }
.alert-list .when { font-family: var(--font-mono); font-size: 11px; color: var(--fg-subtle); }
.alert-list .go {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg-muted);
  padding: 4px 9px;
  border-radius: var(--r-sm);
  font-size: 11px;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: var(--tr-wide);
}
.alert-list .go:hover { border-color: var(--neon-cyan); color: var(--neon-cyan); }

/* ============ STATE ============ */
.loading {
  text-align: center;
  padding: 60px 20px;
  color: var(--fg-subtle);
}
.loading .spinner {
  display: inline-block;
  width: 24px; height: 24px;
  border: 2px solid var(--border);
  border-top-color: var(--neon-cyan);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error {
  background: rgba(255,24,48,.08);
  border: 1px solid rgba(255,24,48,.3);
  color: var(--neon-red-glow);
  padding: var(--s-4);
  border-radius: var(--r-md);
  font-family: var(--font-mono);
  font-size: 13px;
}

/* ============ TOAST ============ */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translate(-50%, 12px);
  background: var(--ink-200);
  color: var(--fg);
  border: 1px solid var(--neon-cyan);
  box-shadow: var(--glow-cyan-sm);
  padding: 12px 18px;
  border-radius: var(--r-pill);
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s, transform .25s;
  z-index: 200;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ============ MODAL (alert/confirm con estética NEON) ============ */
.modal-bg {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s var(--ease-out);
  padding: var(--s-4);
}
.modal-bg.open { opacity: 1; pointer-events: auto; }
.modal {
  background: var(--ink-200);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .55), var(--inner-card);
  width: 100%;
  max-width: 540px;
  max-height: 80vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transform: translateY(8px) scale(.97);
  transition: transform .18s var(--ease-out);
}
.modal-bg.open .modal { transform: translateY(0) scale(1); }
.modal--warn { border-color: var(--neon-red); box-shadow: 0 20px 60px rgba(0,0,0,.55), var(--glow-red-sm); }
.modal--success, .modal--login { border-color: var(--neon-cyan); box-shadow: 0 20px 60px rgba(0,0,0,.55), var(--glow-cyan-sm); }
.modal-h {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-h h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 900;
  letter-spacing: var(--tr-snug);
  text-transform: uppercase;
  color: var(--fg);
}
.modal--warn .modal-h h3 { color: var(--neon-red); }
.modal--success .modal-h h3, .modal--login .modal-h h3 { color: var(--neon-cyan); }
.modal-body {
  padding: 18px 20px;
  font-size: 13px;
  line-height: 1.55;
  color: var(--fg-muted);
  overflow-y: auto;
  flex: 1;
  word-break: break-word;
}
.modal-body::-webkit-scrollbar { width: 6px; }
.modal-body::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }
.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--ink-100);
}

/* ============ Contact pill (Presupuestos: canal + tel/usuario) ============ */
.contact-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-muted);
  padding: 3px 8px;
  border-radius: var(--r-pill);
  border: 1px solid var(--border);
  background: var(--ink-100);
  white-space: nowrap;
}
.contact-pill .contact-icon { font-size: 11px; line-height: 1; }
.contact-pill.wpp { border-color: rgba(74, 222, 128, .35); color: #b8e7c5; }
.contact-pill.ig  { border-color: rgba(255, 24, 48, .4); color: var(--neon-red-glow); }

/* Cell con contacto + botón FUP al lado */
.contact-cell {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.fup-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .5px;
  padding: 3px 8px;
  border-radius: var(--r-pill);
  border: 1px solid rgba(74, 222, 128, .45);
  background: rgba(74, 222, 128, .08);
  color: #4ade80;
  text-decoration: none;
  cursor: pointer;
  transition: all .12s ease;
  user-select: none;
}
.fup-btn:hover {
  background: #25D366;
  color: #000;
  border-color: #25D366;
  box-shadow: 0 0 8px rgba(37, 211, 102, .4);
  transform: translateY(-1px);
}
.fup-btn:active { transform: translateY(0); }

/* ============ PERIOD SELECTOR (dashboard) ============ */
.period-selector {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  margin-bottom: var(--s-4);
  flex-wrap: wrap;
}
.period-selector .ps-label {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: var(--tr-xwide);
  text-transform: uppercase;
  color: var(--fg-subtle);
  padding-right: var(--s-2);
  border-right: 1px solid var(--border);
}
.period-selector .ps-chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  flex: 1;
}
.ps-chip {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg-muted);
  padding: 5px 12px;
  border-radius: var(--r-pill);
  font-size: 11px;
  font-family: var(--font-mono);
  letter-spacing: var(--tr-wide);
  text-transform: uppercase;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--dur-fast), border-color var(--dur-fast), color var(--dur-fast), box-shadow var(--dur-fast);
}
.ps-chip:hover {
  border-color: var(--neon-cyan);
  color: var(--neon-cyan);
}
.ps-chip.active {
  background: rgba(143,212,222,.12);
  border-color: var(--neon-cyan);
  color: var(--neon-cyan);
  box-shadow: var(--glow-cyan-sm);
}
.period-selector .ps-meta {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-muted);
  letter-spacing: var(--tr-wide);
  text-transform: uppercase;
  margin-left: auto;
}

/* ============ USER PICKER ============ */
.user-pick {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.user-pick-label {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: var(--tr-xwide);
  text-transform: uppercase;
  color: var(--fg-faint);
}
.user-pick-chips {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}
.user-chip {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg-muted);
  padding: 4px 9px;
  border-radius: var(--r-pill);
  font-size: 11px;
  font-family: var(--font-mono);
  letter-spacing: var(--tr-wide);
  cursor: pointer;
  transition: all var(--dur-fast);
}
.user-chip:hover { border-color: var(--neon-cyan); color: var(--neon-cyan); }
.user-chip.active {
  background: var(--neon-cyan);
  color: var(--ink-050);
  border-color: var(--neon-cyan);
  box-shadow: var(--glow-cyan-sm);
  font-weight: 700;
}
.user-chip.add { color: var(--fg-faint); padding: 4px 8px; }
.admin-tag {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  font-size: 8px;
  letter-spacing: var(--tr-xwide);
  text-transform: uppercase;
  color: var(--ink-050);
  background: var(--neon-red);
  border-radius: var(--r-pill);
  font-weight: 700;
  box-shadow: var(--glow-red-sm);
}

/* ============ COTIZADOR ============ */
.cot-grid {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr 1fr;
  gap: var(--s-3);
  margin-top: var(--s-2);
}
@media (max-width: 900px) { .cot-grid { grid-template-columns: 1fr 1fr; } }
.cot-grid label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: var(--tr-xwide);
  text-transform: uppercase;
  color: var(--fg-subtle);
}
.cot-grid input, .cot-grid select {
  background: var(--ink-100);
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 8px 10px;
  border-radius: var(--r-sm);
  font-size: 14px;
  font-family: inherit;
  outline: none;
}
.cot-grid input:focus, .cot-grid select:focus { border-color: var(--neon-cyan); }
.cot-results { margin-top: var(--s-3); padding-top: var(--s-3); border-top: 1px solid var(--border); }
.cot-meta { font-family: var(--font-mono); font-size: 11px; color: var(--fg-subtle); margin-bottom: var(--s-2); letter-spacing: var(--tr-wide); }
.cot-meta b { color: var(--fg); }
.cot-result-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: var(--s-2); }
.cot-result {
  background: var(--ink-100);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 10px 12px;
}
.cot-result.muted { opacity: .5; }
.cot-result .lbl { font-family: var(--font-mono); font-size: 9px; letter-spacing: var(--tr-xwide); text-transform: uppercase; color: var(--fg-subtle); }
.cot-result .val { font-family: var(--font-display); font-size: 22px; color: var(--fg); margin-top: 4px; }

.cot-params-group { margin-bottom: var(--s-3); }
.cot-params-title {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: var(--tr-xwide);
  text-transform: uppercase;
  color: var(--fg-subtle);
  margin-bottom: 8px;
}
.cot-params-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--s-2);
}
.cot-param {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--fg-muted);
  background: var(--ink-100);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 8px 10px;
}
.cot-param input {
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--border);
  color: var(--fg);
  padding: 4px 0;
  font-size: 13px;
  font-family: var(--font-mono);
  outline: none;
}
.cot-param input:focus { border-bottom-color: var(--neon-cyan); }

/* ============ HEATMAP ============ */
.heatmap {
  display: grid;
  grid-auto-flow: column;
  grid-template-rows: repeat(1, 1fr);
  gap: 3px;
  padding: 4px 0;
}
.hm-cell {
  width: 100%;
  height: 28px;
  border-radius: 3px;
  border: 1px solid rgba(255,255,255,0.04);
}

/* ============ SEGUIMIENTOS ============ */
.seg-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s-3);
  margin-bottom: var(--s-4);
}
.seg-tab {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--s-4);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  cursor: pointer;
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
  text-align: left;
}
.seg-tab:hover { border-color: var(--neon-cyan); }
.seg-tab.active { border-color: var(--neon-red); box-shadow: var(--glow-red-sm); }
.seg-tab-label {
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: var(--tr-snug);
  color: var(--fg);
}
.seg-tab-count {
  font-family: var(--font-display);
  font-size: 32px;
  line-height: 1;
  color: var(--fg);
}
.seg-tab.active .seg-tab-count { color: var(--neon-red); }

.seg-help {
  font-size: 12px;
  color: var(--fg-subtle);
  background: var(--ink-100);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 10px 14px;
  margin-bottom: var(--s-3);
  font-family: var(--font-mono);
  letter-spacing: var(--tr-wide);
}
.seg-help b { color: var(--fg-muted); }

.seg-filters {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: var(--s-3);
}

.seg-list { display: flex; flex-direction: column; gap: var(--s-2); }
.seg-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left-width: 3px;
  border-radius: var(--r-sm);
  padding: var(--s-3) var(--s-4);
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: border-color var(--dur-fast);
}
.seg-card.tp-overdue { border-left-color: var(--neon-red); }
.seg-card.tp-due { border-left-color: var(--warning); }
.seg-card.tp-future { border-left-color: var(--ink-400); }
.seg-card.tp-done { border-left-color: var(--success); opacity: .7; }

.seg-row-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--s-3);
}
.seg-cliente {
  font-size: 15px;
  font-weight: 700;
  color: var(--fg);
}
.seg-meta {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-subtle);
  margin-top: 3px;
  letter-spacing: var(--tr-wide);
}
.seg-current {
  text-align: right;
  flex-shrink: 0;
  padding: 6px 12px;
  border-radius: var(--r-sm);
  background: var(--ink-100);
  border: 1px solid var(--border);
  min-width: 90px;
}
.seg-current.tp-overdue { background: rgba(255,24,48,.08); border-color: rgba(255,24,48,.35); }
.seg-current.tp-due { background: rgba(255,184,77,.1); border-color: rgba(255,184,77,.35); }
.seg-current.tp-future { background: var(--ink-100); }
.seg-current.tp-done { background: rgba(74,222,128,.1); border-color: rgba(74,222,128,.35); }
.seg-current-id {
  font-family: var(--font-display);
  font-size: 16px;
  letter-spacing: var(--tr-tight);
  color: var(--fg);
}
.seg-current-when {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: var(--tr-xwide);
  text-transform: uppercase;
  color: var(--fg-subtle);
  margin-top: 2px;
}
.seg-current.tp-overdue .seg-current-when { color: var(--neon-red); }
.seg-current.tp-due .seg-current-when { color: var(--warning); font-weight: 700; }

.seg-tps {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.tp-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: var(--r-pill);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: var(--tr-wide);
  border: 1px solid var(--border);
  background: var(--ink-100);
  color: var(--fg-muted);
  cursor: pointer;
  transition: all var(--dur-fast);
  user-select: none;
}
.tp-pill:hover { border-color: var(--neon-cyan); }
.tp-pill .tp-check {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px; height: 14px;
  border-radius: 50%;
  font-size: 10px;
  background: var(--ink-300);
  color: var(--fg);
}
.tp-pill .tp-id { font-weight: 700; color: var(--fg); }
.tp-pill .tp-date { color: var(--fg-subtle); }
.tp-pill.tp-done { background: rgba(74,222,128,.1); border-color: rgba(74,222,128,.4); }
.tp-pill.tp-done .tp-check { background: var(--success); color: var(--ink-050); }
.tp-pill.tp-done .tp-id, .tp-pill.tp-done .tp-date { color: var(--success); text-decoration: line-through; }
.tp-pill.tp-overdue { background: rgba(255,24,48,.08); border-color: rgba(255,24,48,.4); }
.tp-pill.tp-overdue .tp-check { background: var(--neon-red); color: white; }
.tp-pill.tp-due { background: rgba(255,184,77,.1); border-color: rgba(255,184,77,.45); }
.tp-pill.tp-due .tp-check { background: var(--warning); color: var(--ink-050); }
.tp-pill.is-current { box-shadow: 0 0 0 1px var(--neon-red); }
.tp-pill.is-current.tp-due { box-shadow: 0 0 0 1px var(--warning); }

.seg-actions {
  display: flex;
  gap: var(--s-2);
  align-items: center;
  flex-wrap: wrap;
}

/* ============ USER PICKER ============ */
.user-picker-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  /* DEBE quedar por DEBAJO del modal de login (.modal-bg z-index:300) y de los
     toasts (.toast z-index:200). Cuando no hay sesión, este overlay es lo único
     que render() pinta en #app, así que no necesita z-index alto. Antes estaba
     en 9999 y tapaba por completo el prompt de contraseña: el modal se creaba
     y se abría, pero quedaba DETRÁS del overlay opaco → "toco el usuario y no
     aparece para poner la contraseña". Bug latente que solo aparecía al loguear
     sin token (después de limpiar cookies). */
  z-index: 100;
}
.user-picker-box {
  text-align: center;
  padding: var(--s-6);
}
.user-pick-big {
  transition: transform var(--dur-fast), box-shadow var(--dur-fast);
}
.user-pick-big:hover {
  transform: scale(1.05);
  box-shadow: var(--glow-cyan-sm);
}

/* ============ CHAT (WhatsApp Web style) ============ */
/* When chat is active, lock the entire app shell to viewport height */
.app.app--chat {
  /* --vvh la setea syncChatViewportHeight() al alto del viewport REALMENTE
     visible en móvil. El teclado virtual NO achica 100vh → el input quedaría
     tapado detrás del teclado. Fallback a 100vh en desktop / browsers sin
     VisualViewport (sin regresión respecto al comportamiento previo). */
  height: var(--vvh, 100vh);
  max-height: var(--vvh, 100vh);
  overflow: hidden;
}
/* Fullscreen chat: hide sidebar, take full width */
.app.app--chat-full { grid-template-columns: 1fr; }
.app.app--chat-full > .sidebar { display: none; }

/* Fullscreen toggle — NEON dashboard aesthetic, lives top-left of chat header */
.chat-fullscreen-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px; height: 34px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--fg-subtle);
  cursor: pointer;
  padding: 0;
  transition: color var(--dur-fast) var(--ease-out),
              border-color var(--dur-fast) var(--ease-out),
              box-shadow var(--dur-fast) var(--ease-out);
}
.chat-fullscreen-btn:hover {
  color: var(--neon-cyan);
  border-color: var(--neon-cyan-deep);
  box-shadow: var(--glow-cyan-sm);
}
.app--chat-full .chat-fullscreen-btn {
  color: var(--neon-cyan);
  border-color: var(--neon-cyan-deep);
  box-shadow: var(--glow-cyan-sm);
}
.main.main--chat {
  padding: 0 !important;
  max-width: none !important;
  overflow: hidden;
  height: 100%;
}
.chat-layout {
  display: flex;
  height: 100%;
  overflow: hidden;
}
.chat-layout > .chat-contacts { flex: 0 0 30%; max-width: 40%; }
.chat-layout > .chat-main { flex: 1 1 auto; }
@media (max-width: 900px) { .chat-layout { flex-direction: column; } .chat-layout > .chat-contacts { flex: none; max-width: none; } }

/* -- Scrollbar WA-style for chat panels -- */
.chat-contact-list::-webkit-scrollbar,
.chat-messages::-webkit-scrollbar { width: 6px; }
.chat-contact-list::-webkit-scrollbar-track,
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-contact-list::-webkit-scrollbar-thumb { background: #374045; border-radius: 3px; }
.chat-messages::-webkit-scrollbar-thumb { background: #374045; border-radius: 3px; }

/* -- Left panel (contacts) -- */
.chat-contacts {
  background: #111b21;
  border-right: 1px solid #222d34;
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}
.chat-contacts-header {
  padding: 10px 10px 10px 16px;
  background: #202c33;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 59px;
  flex-shrink: 0;
}
.chat-contacts-header .btn-send {
  background: transparent;
  border: none;
  color: #aebac1;
  width: 34px; height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: color .15s, background .15s;
  padding: 0;
  font-size: 14px;
}
.chat-contacts-header .btn-send:hover { color: #e9edef; background: rgba(255,255,255,.06); }
.chat-contacts-header .btn-send.active { color: var(--neon-cyan); background: rgba(143, 212, 222, .12); }
.chat-empty-state {
  padding: 40px 20px;
  text-align: center;
  color: var(--fg-subtle);
  font-size: 13px;
  line-height: 1.5;
}
.chat-empty-emoji { font-size: 36px; margin-bottom: 8px; opacity: .5; }
.archived-banner {
  background: rgba(143, 212, 222, .08);
  border-bottom: 1px solid rgba(143, 212, 222, .2);
  color: var(--neon-cyan);
  font-size: 11px;
  padding: 6px 12px;
  text-align: center;
  letter-spacing: .04em;
  flex-shrink: 0;
}
.chat-contacts-header .btn-send svg { width: 18px; height: 18px; }
.chat-contacts-search {
  padding: 7px 10px;
  background: #111b21;
  flex-shrink: 0;
}
.chat-contacts-search input {
  width: 100%;
  background: #202c33;
  border: none;
  color: #e9edef;
  padding: 7px 12px 7px 32px;
  border-radius: 8px;
  font-size: 14px;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  outline: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238696a0' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 10px center;
  background-size: 14px;
}
.chat-contacts-search input:focus { background-color: #2a3942; }
.chat-contacts-search input::placeholder { color: #8696a0; }
.chat-contact-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
}
.chat-contact {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 14px;
  height: 72px;
  cursor: pointer;
  transition: background .15s;
  /* === PERF: content-visibility skipea layout/paint de items off-screen ===
     El sidebar tiene 1000+ contactos pero solo ~10 son visibles. Sin esto,
     CUALQUIER reflow forzado (tipear en el textarea, polling refresh, etc)
     re-mide los 1000 items → typing lag de cientos de ms.
     Con content-visibility:auto el browser saltea layout/paint de los
     contactos fuera del viewport. contain-intrinsic-size le dice al browser
     qué espacio reservar (alto fijo 72px), así el scrollbar queda correcto.
     Da hasta 7x mejora de rendering según web.dev. */
  content-visibility: auto;
  contain-intrinsic-size: auto 72px;
}
.chat-contact:hover { background: #202c33; }
.chat-contact.active { background: #2a3942; }
/* Bottom border via inner wrapper */
.chat-contact-info {
  flex: 1;
  min-width: 0;
  border-bottom: 1px solid #222d34;
  padding: 13px 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.chat-contact.active .chat-contact-info,
.chat-contact:last-child .chat-contact-info { border-bottom-color: transparent; }

/* Avatar — polished WA Web style */
.chat-avatar {
  border-radius: 50%;
  flex-shrink: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  box-shadow: 0 1px 3px rgba(0,0,0,.25);
}
.chat-avatar-text {
  color: #fff;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  user-select: none;
  text-shadow: 0 1px 2px rgba(0,0,0,.2);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}
.chat-avatar-icon {
  width: 100%; height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.chat-contact-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
}
.chat-contact-name {
  font-size: 16px;
  color: #e9edef;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}
.chat-contact-subname {
  font-size: 12px;
  color: #8696a0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: -1px;
}
/* Unread: bold name + green timestamp */
.chat-contact.has-unread .chat-contact-name { font-weight: 600; }
.chat-contact-time {
  font-size: 12px;
  color: #8696a0;
  flex-shrink: 0;
}
.chat-contact-time.unread { color: #00a884; }
.chat-contact-bottom {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 1px;
}
.chat-contact.has-unread .chat-contact-preview { color: #d1d7db; }
.chat-contact-preview {
  font-size: 14px;
  color: #8696a0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}
.chat-contact-unread {
  background: #00a884;
  color: #111b21;
  font-size: 11px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 12px;
  min-width: 20px;
  text-align: center;
  flex-shrink: 0;
}

/* -- Right panel (conversation) -- */
.chat-main {
  display: flex;
  flex-direction: column;
  background: #0b141a;
  position: relative;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}
/* WA doodle wallpaper */
.chat-main::before {
  content: '';
  position: absolute;
  inset: 0;
  opacity: .06;
  background-color: #0d1418;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cdefs%3E%3Cstyle%3E.a%7Bfill:%23fff;opacity:.4%7D%3C/style%3E%3C/defs%3E%3Cpath class='a' d='M20 5l3 3-3 3-3-3z'/%3E%3Ccircle class='a' cx='80' cy='15' r='2'/%3E%3Cpath class='a' d='M150 8l2 4h-4z'/%3E%3Crect class='a' x='38' y='50' width='4' height='4' rx='1'/%3E%3Ccircle class='a' cx='120' cy='55' r='1.5'/%3E%3Cpath class='a' d='M170 45l3 3-3 3-3-3z'/%3E%3Ccircle class='a' cx='15' cy='95' r='2'/%3E%3Cpath class='a' d='M60 90l2 4h-4z'/%3E%3Crect class='a' x='98' y='88' width='4' height='4' rx='1'/%3E%3Ccircle class='a' cx='160' cy='100' r='1.5'/%3E%3Cpath class='a' d='M30 140l3 3-3 3-3-3z'/%3E%3Ccircle class='a' cx='90' cy='135' r='2'/%3E%3Cpath class='a' d='M140 148l2 4h-4z'/%3E%3Crect class='a' x='178' y='140' width='4' height='4' rx='1'/%3E%3Ccircle class='a' cx='50' cy='180' r='1.5'/%3E%3Cpath class='a' d='M110 185l3 3-3 3-3-3z'/%3E%3Crect class='a' x='168' y='182' width='3' height='3' rx='1'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 0;
}
.chat-main > * { position: relative; z-index: 1; }

.chat-header {
  padding: 10px 16px;
  background: #202c33;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 59px;
  flex-shrink: 0;
}
.chat-header-name {
  font-size: 16px;
  font-weight: 500;
  color: #e9edef;
}
.chat-header-phone {
  font-size: 13px;
  color: #8696a0;
  margin-top: 1px;
}
.chat-header-meta {
  font-size: 12px;
  color: #8696a0;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 6px;
}
.chat-loading {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.chat-loading .spinner {
  width: 30px; height: 30px;
  border-width: 3px;
  display: inline-block;
  border-style: solid;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* Messages area */
.chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 63px 4px;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
@media (max-width: 1100px) { .chat-messages { padding: 12px 16px 4px; } }
.chat-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #8696a0;
  font-size: 14px;
}
.chat-load-older-wrap {
  display: flex;
  justify-content: center;
  padding: 14px 0 8px;
}
.chat-load-older-btn {
  background: rgba(143,212,222,.08);
  border: 1px solid rgba(143,212,222,.25);
  color: var(--accent-cyan, #8FD4DE);
  padding: 8px 18px;
  border-radius: 18px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
  font-family: inherit;
}
.chat-load-older-btn:hover:not(:disabled) {
  background: rgba(143,212,222,.18);
  border-color: var(--accent-cyan, #8FD4DE);
  transform: translateY(-1px);
}
.chat-load-older-btn:disabled { opacity: .6; cursor: wait; }

/* Date separator pill */
.chat-date-sep {
  text-align: center;
  padding: 6px 0 2px;
  align-self: center;
}
.chat-date-sep span {
  display: inline-block;
  background: #182229;
  color: rgba(233,237,239,.75);
  font-size: 12.5px;
  padding: 5px 12px;
  border-radius: 7px;
  box-shadow: 0 1px 0.5px rgba(11,20,26,.13);
}

/* Bubbles */
.chat-msg {
  max-width: 65%;
  padding: 4px 7px 6px 9px;
  border-radius: 7.5px;
  font-size: 14.2px;
  line-height: 19px;
  position: relative;
  word-wrap: break-word;
  box-shadow: 0 1px 0.5px rgba(11,20,26,.13);
  margin-bottom: 1px;
  clear: both;
  /* pan-y: el scroll vertical sigue funcionando, pero el gesto HORIZONTAL queda
     para nuestro handler (swipe-derecha para citar) en vez de que el navegador
     lo trate como scroll/atrás. Clave para que el swipe ande en mobile. */
  touch-action: pan-y;
  /* === PERF: idem .chat-contact — skipear layout de bubbles off-screen ===
     200+ bubbles en el listado, ~10 visibles. contain-intrinsic-size estima
     altura promedio (text: 50px) — el browser ajusta si el bubble entra al
     viewport. Bubbles más altos (imagen/audio/video) tienen su propia altura
     y el layout se corrige al hacer scroll. */
  content-visibility: auto;
  contain-intrinsic-size: auto 50px;
}
.chat-msg.inbound {
  align-self: flex-start;
  background: #202c33;
  color: #e9edef;
}
.chat-msg.inbound.has-tail {
  border-top-left-radius: 0;
  margin-top: 4px;
}
.chat-msg.inbound.has-tail::before {
  content: '';
  position: absolute;
  top: 0; left: -8px;
  width: 0; height: 0;
  border-width: 0 8px 8px 0;
  border-style: solid;
  border-color: transparent #202c33 transparent transparent;
}
.chat-msg.outbound {
  align-self: flex-end;
  background: #005c4b;
  color: #e9edef;
}
.chat-msg.outbound.has-tail {
  border-top-right-radius: 0;
  margin-top: 4px;
}
.chat-msg.outbound.has-tail::before {
  content: '';
  position: absolute;
  top: 0; right: -8px;
  width: 0; height: 0;
  border-width: 0 0 8px 8px;
  border-style: solid;
  border-color: transparent transparent transparent #005c4b;
}

/* Message text */
.chat-msg-body { white-space: pre-wrap; word-break: break-word; }

/* Media in bubbles */
.chat-msg-media {
  margin: -1px -3px 3px -5px;
}
.chat-msg.has-media {
  padding: 3px 3px 4px 3px;
}
.chat-msg.has-media .chat-msg-body {
  padding: 0 6px;
}
.chat-msg.has-media .chat-msg-footer {
  padding-right: 4px;
}
.chat-msg-media img {
  max-width: 330px;
  width: 100%;
  border-radius: 6px;
  cursor: pointer;
  display: block;
}
.chat-msg-media .img-loading {
  width: 330px;
  height: 200px;
  background: rgba(0,0,0,.2);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #8696a0;
  font-size: 13px;
}

/* Audio player WA-style */
.chat-msg-audio {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 4px 2px;
  min-width: 240px;
}
.chat-msg-audio .audio-avatar {
  width: 46px; height: 46px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
.chat-msg-audio .audio-play-btn {
  position: absolute;
  bottom: -2px; right: -4px;
  width: 24px; height: 24px;
  border-radius: 50%;
  background: #00a884;
  border: none;
  color: #111b21;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,.3);
}
.chat-msg-audio .audio-wave {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.chat-msg-audio .audio-bars {
  display: flex;
  align-items: center;
  gap: 1px;
  height: 26px;
}
.chat-msg-audio .audio-bar {
  width: 3px;
  border-radius: 2px;
  background: rgba(255,255,255,.4);
  min-height: 3px;
}
.chat-msg-audio .audio-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.chat-msg-audio .audio-dur {
  font-size: 11px;
  color: rgba(255,255,255,.45);
  font-variant-numeric: tabular-nums;
  flex: 1;
}
.chat-msg-audio .audio-speed,
.chat-msg-audio .audio-toggle-transcript {
  background: transparent;
  border: 1px solid rgba(255,255,255,.18);
  color: rgba(255,255,255,.55);
  font-size: 10px;
  font-weight: 700;
  font-family: var(--font-mono);
  padding: 2px 6px;
  border-radius: 4px;
  cursor: pointer;
  height: 20px;
  line-height: 1;
  transition: color .12s, border-color .12s, background .12s;
}
.chat-msg-audio .audio-speed:hover,
.chat-msg-audio .audio-toggle-transcript:hover {
  color: var(--neon-cyan);
  border-color: var(--neon-cyan);
}
.chat-msg-audio .audio-toggle-transcript.active {
  color: var(--neon-cyan);
  background: rgba(143, 212, 222, .12);
  border-color: var(--neon-cyan);
}
.chat-msg-audio audio { display: none; }
/* Timestamp inline dentro del audio-row, alineado a la derecha (estilo WA Web). */
.chat-msg-audio-bubble .audio-row .chat-msg-footer {
  margin: 0 0 0 auto;
  float: none;
  padding-top: 0;
  flex-shrink: 0;
}
.chat-msg-audio .audio-toggle-transcript {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 2px 5px;
}
/* Caption de imagen: padding correcto para que no se pegue al borde. */
.chat-msg.has-media .chat-msg-body {
  padding: 6px 6px 0;
}
.chat-msg-transcript {
  font-size: 12.5px;
  color: rgba(233,237,239,.65);
  font-style: italic;
  padding: 2px 4px 0;
  border-top: 1px solid rgba(255,255,255,.06);
  margin-top: 4px;
}

/* Video */
.chat-msg-video {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  background: rgba(0,0,0,.15);
  border-radius: 6px;
  min-width: 200px;
}
.chat-msg-video .v-icon {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: rgba(0,168,132,.2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #00a884;
  font-size: 18px;
  flex-shrink: 0;
}
.chat-msg-video a { color: #53bdeb; font-size: 13px; }

/* Document */
.chat-msg-doc {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: rgba(0,0,0,.15);
  border-radius: 6px;
  min-width: 200px;
}
.chat-msg-doc .doc-icon {
  width: 36px; height: 42px;
  background: #8696a0;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  color: #111b21;
  flex-shrink: 0;
  text-transform: uppercase;
}
.chat-msg-doc .doc-name {
  font-size: 13px;
  color: #e9edef;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

/* Sticker */
.chat-msg.sticker-msg {
  background: transparent !important;
  box-shadow: none;
  padding: 0;
}
.chat-msg.sticker-msg::before { display: none; }
.chat-msg.sticker-msg img {
  max-width: 160px;
  max-height: 160px;
}

/* Hover actions: forward + react al lado del bubble (estilo WA Web) */
.chat-msg-actions {
  position: absolute;
  display: flex;
  gap: 4px;
  padding: 2px;
  background: #2a3942;
  border-radius: 18px;
  box-shadow: 0 2px 8px rgba(0,0,0,.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity .12s ease;
  z-index: 6;
}
/* Toolbar SOBRE el bubble, en la esquina superior derecha. Antes iba a -76px al
   costado y en mensajes anchos el borde del contenedor la cortaba (solo se veía
   el primer botón). Ahora flota encima del mensaje y se ven los 3. */
.chat-msg.inbound .chat-msg-actions,
.chat-msg.outbound .chat-msg-actions { top: 4px; right: 6px; left: auto; transform: none; }
.chat-msg-actions::after { display: none; } /* el puente lateral ya no hace falta */
.chat-msg:hover .chat-msg-actions,
.chat-msg-actions:hover { opacity: 1; pointer-events: auto; }
.chat-msg-actions .cma-btn {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 0;
  color: rgba(233,237,239,.85);
  cursor: pointer;
  padding: 0;
}
.chat-msg-actions .cma-btn:hover {
  background: rgba(255,255,255,.08);
  color: #e9edef;
}
.chat-msg-actions .cma-btn svg { display: block; }
/* Chevron (caret) que aparece al hover sobre el bubble y abre el menú de acciones
   (el mismo del click derecho) — estilo WhatsApp Web. Va DENTRO del bubble (no a
   -76px afuera como .chat-msg-actions), así no lo recorta el contenedor del chat. */
.chat-msg-caret {
  position: absolute;
  top: 2px;
  right: 3px;
  width: 26px;
  height: 22px;
  border: 0;
  border-radius: 6px;
  background: rgba(32, 44, 51, .55);
  color: #d1d7db;
  opacity: 0;
  cursor: pointer;
  display: none; /* oculto: la toolbar de acciones ya muestra los botones al hover */
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: opacity .12s, background .12s;
  z-index: 4;
}
.chat-msg:hover .chat-msg-caret { opacity: .92; }
.chat-msg-caret:hover { opacity: 1; color: #fff; background: rgba(32, 44, 51, .8); }
.chat-msg-caret svg { display: block; }

/* Reaction picker — popover de emojis */
.reaction-picker {
  position: fixed;
  display: flex;
  gap: 2px;
  padding: 6px 8px;
  background: #233138;
  border: 1px solid rgba(255,255,255,.06);
  border-radius: 28px;
  box-shadow: 0 6px 20px rgba(0,0,0,.45);
  z-index: 1000;
  opacity: 0;
  transform: translateY(4px) scale(.96);
  transition: opacity .12s ease, transform .12s ease;
}
.reaction-picker.open { opacity: 1; transform: translateY(0) scale(1); }
.reaction-picker .rp-emoji {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 0;
  background: transparent;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform .1s ease, background .1s ease;
  color: #e9edef;
}
.reaction-picker .rp-emoji:hover {
  background: rgba(255,255,255,.08);
  transform: scale(1.2);
}
.reaction-picker .rp-more { font-size: 18px; color: rgba(233,237,239,.7); }

/* === Banner ventana de 24h cerrada — solo informativo === */
.window24-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 16px;
  background: rgba(255, 167, 38, .06);
  border-top: 1px solid rgba(255, 167, 38, .2);
  color: rgba(233,237,239,.75);
  font-size: 12px;
}
.window24-banner svg { color: rgba(255, 167, 38, .85); flex-shrink: 0; }
.window24-banner .w24-text {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.window24-banner .w24-title {
  font-weight: 600;
  color: rgba(255, 167, 38, .9);
}
.window24-banner .w24-sub {
  color: rgba(233,237,239,.55);
}

/* === Quote / cita arriba del bubble (estilo WA Web) === */
.chat-msg-quote {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 5px 8px;
  margin-bottom: 4px;
  border-radius: 4px;
  background: rgba(0,0,0,.18);
  border-left: 4px solid var(--neon-cyan, #8FD4DE);
  font-size: 12.5px;
  cursor: pointer;
  max-width: 100%;
  overflow: hidden;
}
.chat-msg-quote.mine { border-left-color: var(--neon-red, #FF1830); }
.chat-msg-quote .cmq-author {
  font-weight: 600;
  color: var(--neon-cyan, #8FD4DE);
  font-size: 12px;
}
.chat-msg-quote.mine .cmq-author { color: var(--neon-red, #FF1830); }
.chat-msg-quote .cmq-text {
  color: rgba(233,237,239,.75);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* Flash al hacer click en una cita y saltar al original */
.chat-msg.chat-msg-flash {
  animation: msg-flash 1.5s ease;
}
@keyframes msg-flash {
  0%, 100% { background-color: inherit; }
  20% { background-color: rgba(143, 212, 222, .25); }
}

/* === Reply banner (sobre el input cuando estás respondiendo) === */
.reply-banner {
  display: flex;
  align-items: stretch;
  gap: 10px;
  padding: 8px 14px;
  margin: 0 8px;
  background: #1f2c33;
  border-radius: 8px 8px 0 0;
  border-bottom: 1px solid var(--border);
}
.reply-banner-line {
  width: 4px;
  border-radius: 2px;
  background: var(--neon-cyan, #8FD4DE);
  flex-shrink: 0;
}
.reply-banner-content {
  flex: 1;
  min-width: 0;
}
.reply-banner .rb-author {
  font-size: 12px;
  font-weight: 600;
  color: var(--neon-cyan, #8FD4DE);
}
.reply-banner .rb-text {
  font-size: 13px;
  color: rgba(233,237,239,.8);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.reply-banner .rb-close {
  background: transparent;
  border: 0;
  color: rgba(233,237,239,.6);
  font-size: 16px;
  cursor: pointer;
  padding: 0 6px;
  align-self: center;
}
.reply-banner .rb-close:hover { color: #fff; }

/* === Image lightbox === */
.img-lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.92);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity .15s ease;
}
.img-lightbox.open { opacity: 1; }
.img-lightbox .lb-stage {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
  overflow: auto;
}
.img-lightbox #lb-img {
  max-width: 92vw;
  max-height: 92vh;
  object-fit: contain;
  cursor: zoom-in;
  transition: transform .15s ease;
  user-select: none;
}
.img-lightbox #lb-img.zoomed {
  max-width: none;
  max-height: none;
  cursor: zoom-out;
  transform: scale(1.6);
}
.img-lightbox .lb-close,
.img-lightbox .lb-download,
.img-lightbox .lb-nav {
  position: absolute;
  background: rgba(255,255,255,.08);
  border: 0;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background .12s ease, transform .12s ease;
  text-decoration: none;
}
.img-lightbox .lb-close { top: 18px; right: 18px; width: 40px; height: 40px; font-size: 22px; }
.img-lightbox .lb-download { top: 18px; right: 68px; width: 40px; height: 40px; }
.img-lightbox .lb-nav { top: 50%; transform: translateY(-50%); width: 48px; height: 48px; font-size: 30px; line-height: 1; }
.img-lightbox .lb-prev { left: 22px; }
.img-lightbox .lb-next { right: 22px; }
.img-lightbox .lb-close:hover,
.img-lightbox .lb-download:hover,
.img-lightbox .lb-nav:hover { background: rgba(255,255,255,.18); }
.img-lightbox .lb-counter {
  position: absolute;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255,255,255,.85);
  background: rgba(0,0,0,.5);
  padding: 6px 14px;
  border-radius: 14px;
  font-size: 13px;
  pointer-events: none;
}

/* === PDF preview modal === */
.pdf-preview-modal .modal-h {
  padding: 12px 14px !important;
}
.pdf-preview-modal .pdf-close,
.pdf-preview-modal .btn-ghost {
  padding: 6px 10px;
  min-width: 36px;
}
.pdf-preview-modal iframe { background: #525659; }

/* === Media preview modal (drag/paste/attach) === */
.media-preview-modal .mp-stage {
  background: #0b141a;
  min-height: 320px;
  max-height: 60vh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-bottom: 1px solid var(--border);
}
.media-preview-modal .mp-stage img,
.media-preview-modal .mp-stage video {
  max-width: 100%;
  max-height: 60vh;
  object-fit: contain;
  display: block;
}
.media-preview-modal .mp-doc {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 28px 24px;
  width: 100%;
  max-width: 480px;
  background: #182229;
  border-radius: 8px;
  margin: 16px;
}
.media-preview-modal .mp-doc-icon {
  width: 56px;
  height: 56px;
  border-radius: 8px;
  background: var(--neon-red);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
}
.media-preview-modal .mp-doc-name {
  color: var(--fg);
  font-size: 14px;
  font-weight: 500;
  word-break: break-all;
}
.media-preview-modal .mp-doc-sub {
  color: var(--fg-subtle);
  font-size: 12px;
  margin-top: 2px;
}
.media-preview-modal .mp-empty {
  color: var(--fg-subtle);
  padding: 40px;
}
.media-preview-modal .mp-thumbs {
  display: flex;
  gap: 6px;
  padding: 10px 14px;
  background: #111b21;
  overflow-x: auto;
  border-bottom: 1px solid var(--border);
}
.media-preview-modal .mp-thumb {
  position: relative;
  width: 56px;
  height: 56px;
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
  border: 2px solid transparent;
  flex-shrink: 0;
  background: #182229;
  display: flex;
  align-items: center;
  justify-content: center;
}
.media-preview-modal .mp-thumb.active { border-color: var(--neon-cyan, #8FD4DE); }
.media-preview-modal .mp-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.media-preview-modal .mp-th-icon {
  font-size: 22px;
  color: rgba(255,255,255,.7);
}
.media-preview-modal .mp-th-rm {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(0,0,0,.65);
  color: #fff;
  border: 0;
  font-size: 11px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  opacity: 0;
  transition: opacity .1s;
}
.media-preview-modal .mp-thumb:hover .mp-th-rm { opacity: 1; }
.media-preview-modal .mp-caption-wrap {
  padding: 10px 14px;
  background: #1f2c33;
}
.media-preview-modal #mp-caption {
  width: 100%;
  padding: 9px 12px;
  background: var(--ink-100);
  border: 1px solid var(--border);
  border-radius: 18px;
  color: var(--fg);
  font-size: 14px;
  outline: none;
}
.media-preview-modal #mp-caption:focus { border-color: var(--neon-cyan, #8FD4DE); }

/* Reactions chip mostrado en el bubble */
.chat-msg-reactions {
  position: absolute;
  bottom: -10px;
  display: inline-flex;
  gap: 2px;
  padding: 2px 6px;
  background: #2a3942;
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,.4);
  font-size: 12px;
  line-height: 1;
  z-index: 3;
  white-space: nowrap;
}
.chat-msg.inbound .chat-msg-reactions { left: 8px; }
.chat-msg.outbound .chat-msg-reactions { right: 8px; }
.reaction-chip {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-size: 13px;
}
.reaction-chip .rc-num {
  font-size: 11px;
  color: rgba(233,237,239,.75);
  margin-left: 2px;
}
/* Espacio extra abajo cuando el bubble tiene reacciones para que el chip no se solape con el siguiente. */
.chat-msg:has(.chat-msg-reactions) { margin-bottom: 12px; }

/* Timestamp + status */
.chat-msg-footer {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  float: right;
  margin: 0 -1px -3px 8px;
  padding-top: 2px;
}
.chat-msg-time {
  font-size: 11px;
  color: rgba(255,255,255,.45);
  white-space: nowrap;
}
.chat-msg-status { line-height: 1; display: inline-flex; }
.chat-msg-status svg { width: 16px; height: 11px; }
.chat-msg-status.sent svg { fill: rgba(255,255,255,.4); }
.chat-msg-status.delivered svg { fill: rgba(255,255,255,.5); }
.chat-msg-status.read svg { fill: #53bdeb; }
.chat-msg-status.failed { color: #ff4a5e; font-weight: 700; font-size: 11px; }

/* Input bar */
/* Modal "Reenviar a..." — items con avatar + nombre + checkbox */
.fwd-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  cursor: pointer;
  transition: background .12s;
}
.fwd-item:hover { background: var(--ink-100); }
.fwd-item input[type="checkbox"] { accent-color: var(--neon-cyan); width: 16px; height: 16px; flex-shrink: 0; }
.fwd-item-text { flex: 1; min-width: 0; }
.fwd-item-name { color: var(--fg); font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fwd-item-sub { color: var(--fg-subtle); font-size: 11px; margin-top: 2px; }

/* Drop zone overlay cuando arrastrás archivos sobre el chat */
.chat-drop-overlay {
  position: absolute;
  inset: 0;
  background: rgba(143, 212, 222, .12);
  border: 2px dashed var(--neon-cyan);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  backdrop-filter: blur(2px);
}
.chat-drop-inner {
  font-size: 32px;
  color: var(--neon-cyan);
  text-align: center;
  font-family: var(--font-display);
  letter-spacing: var(--tr-snug);
  text-shadow: var(--glow-cyan-sm);
}

.chat-input-bar {
  padding: 5px 10px;
  background: #202c33;
  display: flex;
  gap: 4px;
  align-items: flex-end;
  flex-shrink: 0;
  min-height: 52px;
}
.chat-input-bar .btn-send {
  background: transparent;
  border: none;
  color: #8696a0;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  cursor: pointer;
  transition: color .15s, background .15s;
  padding: 0;
}
.chat-input-bar .btn-send:hover { color: #e9edef; background: rgba(255,255,255,.06); }
.chat-input-bar .btn-send:disabled { opacity: .3; cursor: not-allowed; }
.chat-input-bar .btn-send svg { width: 22px; height: 22px; }

/* Scroll-to-bottom FAB */
.chat-scroll-down {
  position: absolute;
  bottom: 75px;
  right: 20px;
  width: 42px; height: 42px;
  border-radius: 50%;
  background: #202c33;
  border: none;
  color: #8696a0;
  box-shadow: 0 2px 5px rgba(0,0,0,.3);
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2;
  transition: color .15s;
  font-size: 18px;
}
.chat-scroll-down.visible { display: flex; }
.chat-scroll-down:hover { color: #e9edef; }
.chat-scroll-down .unread-count {
  position: absolute;
  top: -6px; right: -2px;
  background: #00a884;
  color: #111b21;
  font-size: 11px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
}

/* No conversation selected */
.chat-no-select {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  gap: 12px;
  color: #8696a0;
  font-size: 14px;
  text-align: center;
  padding: 40px;
  background: #222e35;
  border-bottom: 6px solid #00a884;
}
.chat-no-select h3 {
  color: #e9edef;
  font-size: 32px;
  font-weight: 300;
  margin: 0 0 4px;
}
.chat-no-select p {
  color: #8696a0;
  font-size: 14px;
  margin: 0;
  max-width: 500px;
  line-height: 1.5;
}

/* ============ CHAT INPUT WRAP ============ */
.chat-input-wrap {
  flex: 1;
  position: relative;
  min-width: 0;
}
.chat-input-wrap textarea {
  width: 100%;
  background: #2a3942;
  border: none;
  outline: none;
  color: #e9edef;
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 15px;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  resize: none;
  min-height: 40px;
  max-height: 120px;
  line-height: 1.35;
  /* Auto-resize NATIVO sin JS: el browser ajusta la altura al contenido sin
     forzar reflow. Reemplaza el patrón viejo de `style.height='auto'; el.scrollHeight`
     en cada keystroke, que con DOM grande tardaba 200-3000ms POR TECLA y bloqueaba
     el typing entero. Chrome ≥123 y Safari 17 lo soportan; browsers viejos caen
     a textarea fijo con scroll interno (degradación aceptable). */
  field-sizing: content;
}
.chat-input-wrap textarea::placeholder { color: #8696a0; }

/* Quick replies dropdown */
.qr-dropdown {
  position: absolute;
  bottom: calc(100% + 4px);
  left: 0; right: 0;
  background: #233138;
  border-radius: 10px;
  box-shadow: 0 -4px 16px rgba(0,0,0,.35);
  max-height: 260px;
  overflow-y: auto;
  z-index: 20;
  padding: 4px 0;
}
.qr-item {
  padding: 8px 14px;
  cursor: pointer;
  display: flex;
  gap: 10px;
  align-items: center;
  transition: background .1s;
}
.qr-item:hover, .qr-item.active { background: rgba(255,255,255,.06); }
.qr-shortcut { color: #00a884; font-weight: 600; font-size: 13px; white-space: nowrap; min-width: 60px; }
.qr-preview { color: #8696a0; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }

/* Recording UI */
.rec-indicator {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  color: #e9edef;
  font-size: 16px;
  font-weight: 300;
  padding: 0 16px;
  font-family: 'Segoe UI', system-ui, sans-serif;
}
.rec-dot {
  width: 12px; height: 12px;
  background: #ef5350;
  border-radius: 50%;
  animation: rec-pulse 1s infinite;
  flex-shrink: 0;
}
@keyframes rec-pulse { 0%,100% { opacity: 1; } 50% { opacity: .2; } }

/* Label chips */
.label-chip {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 3px;
  font-size: 11px;
  color: #fff;
  font-weight: 700;
  white-space: nowrap;
  line-height: 16px;
  letter-spacing: .15px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .25);
}
.chat-label-chips {
  display: flex;
  gap: 3px;
  padding: 0 16px 4px;
  flex-wrap: wrap;
  flex-shrink: 0;
}
.chat-header .chat-label-chips { padding: 0; margin-top: 2px; }
.chat-contact-bottom .label-chip { padding: 1px 6px; font-size: 9px; line-height: 14px; }

/* ============================================================
   Label filter bar — diseño tipo WhatsApp Web
   ============================================================
   Una sola fila compacta con chips fijos (Todos, No leídos) +
   un dropdown "Etiquetas ▾" que abre el listado de etiquetas
   custom. Reemplaza al diseño anterior que renderizaba TODAS
   las etiquetas como pills inline, lo cual ocupaba 2-4 filas
   verticales en desktop. */
.label-filter-bar {
  display: flex;
  gap: 8px;
  padding: 8px 12px;
  align-items: center;
  flex-shrink: 0;
  background: #111b21;
  border-bottom: 1px solid #222d34;
  white-space: nowrap;
  overflow-x: auto;
  overflow-y: visible; /* el dropdown sale hacia abajo */
  scrollbar-width: none;
}
.label-filter-bar::-webkit-scrollbar { display: none; }

/* Chip fijo gris (Todos / No leídos) — color uniforme estilo WA Web. */
.label-filter-pill {
  padding: 6px 14px;
  border-radius: 16px;
  font-size: 13px;
  font-weight: 500;
  border: 0;
  color: #aebac1;
  background: rgba(134, 150, 160, .12);
  cursor: pointer;
  font-family: 'Segoe UI', system-ui, sans-serif;
  white-space: nowrap;
  line-height: 1;
  transition: background .12s, color .12s;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.label-filter-pill:hover { background: rgba(134, 150, 160, .2); color: #e9edef; }
.label-filter-pill.active {
  background: rgba(0, 168, 132, .18);
  color: #00d9a3;
}

/* Dropdown "Etiquetas ▾" — pill con caret. */
.label-filter-dd-wrap {
  position: relative;
  flex-shrink: 0;
}
.label-filter-dd-caret {
  font-size: 10px;
  opacity: .7;
  margin-left: 2px;
}
.label-filter-dd-menu {
  /* position: fixed para escapar del overflow:hidden de .chat-contacts.
     El top/left se calculan en JS via getBoundingClientRect del botón.
     z-index alto para quedar arriba de la lista de chats. */
  position: fixed;
  z-index: 9999;
  background: #233138;
  border: 1px solid #2a3942;
  border-radius: 8px;
  padding: 8px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, .65);
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 220px;
  max-height: 360px;
  overflow-y: auto;
}

/* Item de etiqueta dentro del dropdown — fila vertical estilo WhatsApp Web:
   cuadradito de color + nombre + check si está activa. */
.label-filter-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: transparent;
  border: 0;
  color: #e9edef;
  font-size: 14px;
  font-weight: 400;
  cursor: pointer;
  border-radius: 6px;
  width: 100%;
  text-align: left;
  font-family: 'Segoe UI', system-ui, sans-serif;
  transition: background .12s;
  line-height: 1.2;
}
.label-filter-item:hover { background: rgba(255, 255, 255, .04); }
.label-filter-item.active { background: rgba(0, 168, 132, .12); }
.label-filter-item-dot {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  flex-shrink: 0;
  display: inline-block;
}
.label-filter-item-name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.label-filter-item-check {
  color: #00a884;
  font-weight: 700;
  flex-shrink: 0;
  margin-left: 6px;
}

.label-filter-clear {
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 11px;
  border: 1px solid #3b4a54;
  color: #8696a0;
  background: transparent;
  cursor: pointer;
  font-family: 'Segoe UI', system-ui, sans-serif;
  margin-top: 4px;
  text-align: center;
}
.label-filter-clear:hover { background: #2a3942; color: #e9edef; }

/* Label picker popup */
.label-picker-popup {
  position: fixed;
  top: 60px;
  right: 16px;
  background: var(--ink-200);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  padding: 14px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, .55), var(--inner-card);
  z-index: 320;
  min-width: 220px;
  max-width: 280px;
  /* Con muchas etiquetas (20+) la lista crecía más que la pantalla y las de
     abajo quedaban fuera de vista sin scroll. Cap + scroll para verlas todas. */
  max-height: calc(100vh - 90px);
  overflow-y: auto;
}
.label-picker-title {
  color: var(--fg-subtle);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: var(--tr-xwide);
  text-transform: uppercase;
  margin-bottom: 10px;
}

/* ============ Modal Gestionar etiquetas ============ */
.manage-labels {
  display: flex;
  flex-direction: column;
  gap: var(--s-5);
  padding-bottom: var(--s-3);
}
.manage-labels-section {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
}
.manage-labels-section-h {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: var(--tr-wide);
  text-transform: uppercase;
  color: var(--fg-subtle);
}
.manage-labels-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.manage-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  background: var(--ink-100);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  transition: border-color .12s, background .12s;
}
.manage-label-row:hover { border-color: var(--border-strong); }
.manage-label-del {
  width: 24px;
  height: 24px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--r-xs);
  color: var(--fg-subtle);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  transition: all .12s;
  flex-shrink: 0;
}
.manage-label-del:hover {
  background: rgba(255, 24, 48, .12);
  border-color: var(--neon-red);
  color: var(--neon-red);
}
.manage-labels-empty {
  color: var(--fg-subtle);
  font-size: 13px;
  margin: 0;
}
.manage-labels-colors {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.label-color-pick {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
  transition: transform .12s, box-shadow .12s, border-color .12s;
}
.label-color-pick:hover { transform: scale(1.08); }
.label-color-pick.active {
  border-color: var(--fg);
  box-shadow: 0 0 0 2px var(--ink-200), 0 0 0 4px var(--neon-cyan);
  transform: scale(1.1);
}
.manage-labels-add {
  display: flex;
  gap: 8px;
}
.manage-labels-add input {
  flex: 1;
  padding: 9px 12px;
  background: var(--ink-100);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--fg);
  font-size: 13px;
  font-family: var(--font-sans);
  transition: border-color .12s, box-shadow .12s;
}
.manage-labels-add input:focus {
  outline: none;
  border-color: var(--neon-cyan);
  box-shadow: var(--glow-cyan-sm);
}
.manage-labels-add input::placeholder { color: var(--fg-subtle); }
.manage-labels-add .btn { padding: 9px 16px; }

/* ============ Modal Respuestas rápidas ============ */
.manage-qr {
  display: flex;
  flex-direction: column;
  gap: var(--s-5);
  padding-bottom: var(--s-3);
}
.manage-qr-hint {
  font-size: 12px;
  color: var(--fg-subtle);
  line-height: 1.5;
  margin: 0 0 var(--s-3);
}
.manage-qr-section { display: flex; flex-direction: column; gap: var(--s-3); }
.manage-qr-section-h {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: var(--tr-wide);
  text-transform: uppercase;
  color: var(--fg-subtle);
}
.manage-qr-list { display: flex; flex-direction: column; gap: 6px; }
.manage-qr-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  background: var(--ink-100);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
}
.manage-qr-row:hover { border-color: var(--border-strong); }
.manage-qr-thumb {
  width: 44px; height: 44px;
  object-fit: cover;
  border-radius: var(--r-xs);
  flex-shrink: 0;
}
.manage-qr-thumb-empty {
  width: 44px; height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--ink-200);
  border-radius: var(--r-xs);
  font-size: 18px;
  flex-shrink: 0;
  opacity: .5;
}
.manage-qr-text { flex: 1; min-width: 0; }
.manage-qr-shortcut {
  color: var(--neon-cyan);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
}
.manage-qr-body {
  color: var(--fg-muted);
  font-size: 12.5px;
  line-height: 1.4;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.manage-qr-section input[type="text"], .manage-qr-section textarea {
  width: 100%;
  padding: 9px 12px;
  background: var(--ink-100);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--fg);
  font-size: 13px;
  font-family: var(--font-sans);
  resize: vertical;
  transition: border-color .12s, box-shadow .12s;
}
.manage-qr-section input[type="text"]:focus, .manage-qr-section textarea:focus {
  outline: none;
  border-color: var(--neon-cyan);
  box-shadow: var(--glow-cyan-sm);
}
.manage-qr-image {
  display: flex;
  align-items: center;
  gap: 10px;
}
.manage-qr-image-name { font-size: 12px; color: var(--fg-subtle); }

/* QR dropdown items con thumbnail */
.qr-item img.qr-thumb {
  width: 32px; height: 32px;
  object-fit: cover;
  border-radius: var(--r-xs);
  flex-shrink: 0;
}
.qr-item-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* Button label toggle */
.btn-label-toggle {
  background: transparent;
  border: none;
  color: #aebac1;
  cursor: pointer;
  padding: 6px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  transition: color .15s, background .15s;
}
.btn-label-toggle:hover { color: #e9edef; background: rgba(255,255,255,.06); }
/* Tints sutiles para diferenciar los iconos del header del chat de un vistazo */
#btn-note { color: rgba(255, 248, 176, .85); }
#btn-note:hover { color: #fff8b0; background: rgba(255, 248, 176, .12); }
#btn-note.has-note { color: #fff8b0; background: rgba(255, 248, 176, .15); }
#btn-labels { color: rgba(143, 212, 222, .85); }
#btn-labels:hover { color: var(--neon-cyan); background: rgba(143, 212, 222, .12); }

/* ============ POST-IT de notas por contacto ============ */
.chat-main > .chat-postit { z-index: 5; }
.chat-postit {
  position: absolute;
  top: 70px;
  right: 14px;
  z-index: 5;
  background: #fff8b0;
  color: #2a2410;
  border-radius: var(--r-xs);
  padding: 10px 12px;
  width: 240px;
  max-height: 220px;
  overflow-y: auto;
  font-family: var(--font-sans);
  font-size: 12.5px;
  line-height: 1.4;
  box-shadow:
    0 8px 18px rgba(0, 0, 0, .45),
    -2px -2px 0 rgba(0, 0, 0, .04) inset;
  transform: rotate(-1.5deg);
  cursor: pointer;
  user-select: none;
  transition: transform .12s var(--ease-out), box-shadow .12s var(--ease-out);
}
.chat-postit-body { user-select: text; }
.chat-postit:hover { transform: rotate(0); box-shadow: 0 12px 24px rgba(0, 0, 0, .55); }
.chat-postit::before {
  content: '';
  position: absolute;
  top: -8px; left: 50%;
  width: 36px; height: 14px;
  background: rgba(255, 24, 48, .55);
  transform: translateX(-50%) rotate(-3deg);
  border-radius: 2px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .35);
}
.chat-postit-h {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #6b5d2a;
  margin-bottom: 6px;
}
.chat-postit-edit, .chat-postit-close {
  background: transparent;
  border: none;
  color: #6b5d2a;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 0 2px;
}
.chat-postit-close { font-size: 18px; font-weight: 700; }
.chat-postit-edit:hover, .chat-postit-close:hover { color: #2a2410; }
.chat-postit-body {
  white-space: pre-wrap;
  word-break: break-word;
  font-family: 'Caveat', 'Patrick Hand', 'Comic Sans MS', cursive;
  font-size: 16px;
  line-height: 1.3;
}
.chat-postit--editing {
  cursor: default;
  transform: rotate(0);
  width: 280px;
}
.chat-postit-textarea {
  width: 100%;
  min-height: 110px;
  background: rgba(255, 255, 255, .55);
  border: 1px dashed rgba(0, 0, 0, .2);
  border-radius: 3px;
  padding: 8px;
  font-family: 'Caveat', 'Patrick Hand', cursive;
  font-size: 16px;
  color: #2a2410;
  resize: vertical;
}
.chat-postit-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 8px;
}
.chat-postit-btn {
  background: rgba(0, 0, 0, .08);
  border: 1px solid rgba(0, 0, 0, .15);
  color: #2a2410;
  padding: 5px 10px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}
.chat-postit-btn:hover { background: rgba(0, 0, 0, .14); }
.chat-postit-btn--primary { background: #2a2410; color: #fff8b0; border-color: #2a2410; }
.chat-postit-btn--primary:hover { background: #000; }
.chat-postit-btn--danger { color: var(--neon-red-deep); border-color: rgba(255, 24, 48, .35); }

/* ============ Context menu (right-click sobre chat-contact) ============ */
.chat-context-menu {
  position: fixed;
  background: var(--ink-200);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  padding: 4px;
  min-width: 190px;
  z-index: 320;
  box-shadow: 0 12px 32px rgba(0, 0, 0, .55), var(--inner-card);
  opacity: 0;
  transform: scale(.96);
  transform-origin: top left;
  transition: opacity .12s var(--ease-out), transform .12s var(--ease-out);
}
.chat-context-menu.open { opacity: 1; transform: scale(1); }
.chat-context-menu .ccm-h {
  padding: 6px 10px 8px;
  font-size: 11px;
  color: var(--fg-subtle);
  text-transform: uppercase;
  letter-spacing: .06em;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-context-menu .ccm-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  background: transparent;
  border: none;
  color: var(--fg);
  padding: 8px 10px;
  border-radius: 4px;
  font-size: 13px;
  font-family: var(--font-sans);
  text-align: left;
  cursor: pointer;
  transition: background .12s, color .12s;
}
.chat-context-menu .ccm-item:hover { background: var(--ink-300); color: var(--neon-cyan); }
.chat-context-menu .ccm-item svg { flex: 0 0 16px; opacity: .7; }
.chat-context-menu .ccm-item:hover svg { opacity: 1; }

/* Submenú (cascade) */
.chat-context-menu .ccm-item--has-sub { position: relative; }
.chat-context-menu .ccm-chevron {
  font-size: 10px;
  opacity: .6;
  margin-left: 6px;
}
.chat-context-menu .ccm-item--has-sub:hover .ccm-chevron { opacity: 1; }
.chat-context-menu .ccm-submenu {
  position: absolute;
  top: -4px;
  left: calc(100% + 4px);
  min-width: 220px;
  background: var(--ink-200);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  padding: 4px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, .55), var(--inner-card);
  opacity: 0;
  pointer-events: none;
  transform: translateX(-6px);
  transition: opacity .12s var(--ease-out), transform .12s var(--ease-out);
  z-index: 1;
}
.chat-context-menu .ccm-submenu--left {
  left: auto;
  right: calc(100% + 4px);
  transform: translateX(6px);
}
.chat-context-menu .ccm-item--has-sub:hover .ccm-submenu,
.chat-context-menu .ccm-submenu:hover {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(0);
}
.chat-context-menu .ccm-sub-h {
  padding: 4px 8px 6px;
  font-size: 10px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--fg-subtle);
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}
.chat-context-menu .ccm-sub-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 4px;
  cursor: pointer;
  transition: background .1s;
}
.chat-context-menu .ccm-sub-item:hover { background: var(--ink-300); }
.chat-context-menu .ccm-sub-item.active { background: rgba(143, 212, 222, .08); }
.chat-context-menu .ccm-sub-tick {
  margin-left: auto;
  width: 16px;
  text-align: center;
  color: var(--neon-cyan);
  font-weight: 700;
  font-size: 13px;
}
.chat-context-menu .ccm-sub-chip {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--r-pill);
  font-size: 11px;
  font-weight: 700;
  color: #2a2410;
}
.chat-context-menu .ccm-sub-empty {
  font-size: 12px;
  color: var(--fg-subtle);
  padding: 8px;
}

/* Bulk messaging section */
.bulk-section {
  background: #111b21;
  border-top: 1px solid #222d34;
  padding: 14px;
  flex-shrink: 0;
  max-height: 50vh;
  overflow-y: auto;
}
.bulk-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.bulk-header h4 { color: #e9edef; font-size: 15px; font-weight: 500; margin: 0; }
.bulk-labels { margin-bottom: 10px; display: flex; flex-wrap: wrap; gap: 6px; }
.label-picker-chips { display: flex; flex-wrap: wrap; gap: 6px; }

/* Chip toggleable: la etiqueta misma es el botón. Inactiva = opaca y desaturada,
   activa = full color con glow + ✓. Sin pill envolvente, sin checkbox. */
.label-toggle-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--lc, var(--ink-300));
  color: #fff;
  border: 1px solid transparent;
  border-radius: var(--r-pill);
  padding: 4px 12px;
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .2px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .25);
  white-space: nowrap;
  cursor: pointer;
  opacity: .42;
  filter: saturate(.55);
  transition: opacity .12s var(--ease-out), filter .12s var(--ease-out), box-shadow .12s var(--ease-out), transform .12s var(--ease-out);
}
.label-toggle-chip:hover { opacity: .72; filter: saturate(.85); }
.label-toggle-chip.active {
  opacity: 1;
  filter: saturate(1);
  box-shadow: 0 0 0 2px var(--ink-100), 0 0 0 3px var(--lc, var(--neon-cyan));
}
.label-toggle-chip.active::after {
  content: '✓';
  font-size: 11px;
  font-weight: 900;
  margin-left: -2px;
  opacity: .9;
}
.bulk-textarea {
  width: 100%;
  padding: 10px 12px;
  background: #2a3942;
  border: none;
  outline: none;
  color: #e9edef;
  border-radius: 8px;
  font-size: 14px;
  resize: vertical;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  line-height: 1.4;
}
.bulk-textarea::placeholder { color: #8696a0; }

/* Location message */
.chat-msg-location {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 4px;
  cursor: pointer;
}
.chat-msg-location:hover { opacity: .85; }

/* Contact card message */
.chat-msg-contact-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 4px;
}

/* Unsupported message */
.chat-msg-unsupported {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #8696a0;
  font-size: 13px;
  font-style: italic;
  padding: 2px 0;
}

/* Attach & mic & schedule buttons */
.btn-attach, .btn-mic, .btn-schedule { flex-shrink: 0; }
.btn-schedule { color: #8696a0; }
.btn-schedule:hover { color: #00a884 !important; }

/* Schedule modal */
.schedule-modal-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,.6); z-index: 1000;
  display: flex; align-items: center; justify-content: center;
}
.schedule-modal {
  background: #1f2c34; border-radius: 12px; padding: 20px;
  width: 380px; max-width: 90vw; color: #e9edef;
  box-shadow: 0 8px 32px rgba(0,0,0,.5);
}
.schedule-preview {
  background: #005c4b; border-radius: 8px; padding: 8px 12px;
  font-size: 13px; color: #e9edef; max-height: 120px; overflow-y: auto;
  white-space: pre-wrap; word-break: break-word;
}
.schedule-modal label { display: block; margin-bottom: 4px; }
.schedule-modal input[type="date"],
.schedule-modal input[type="time"] { font-family: inherit; font-size: 14px; }
.schedule-modal .btn-action {
  border: none; padding: 8px 18px; border-radius: 8px;
  color: #fff; font-size: 14px; cursor: pointer;
}
.schedule-modal .btn-action:hover { filter: brightness(1.15); }

/* ============ FULL-TEXT SEARCH RESULTS en chat list ============ */
.search-section-header {
  padding: 8px 14px 6px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: rgba(143, 212, 222, .8);
  font-weight: 700;
  border-top: 1px solid rgba(255,255,255,.05);
  background: rgba(143,212,222,.04);
  margin-top: 4px;
}
.search-msg-result {
  padding: 9px 14px;
  border-bottom: 1px solid rgba(255,255,255,.04);
  transition: background .12s;
}
.search-msg-result:hover {
  background: rgba(143,212,222,.08);
}
.search-msg-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 3px;
}
.search-msg-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--fg);
}
.search-msg-date {
  font-size: 10.5px;
  color: rgba(233,237,239,.45);
  font-family: ui-monospace, monospace;
}
.search-msg-body {
  font-size: 12.5px;
  color: rgba(233,237,239,.7);
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.search-msg-dir {
  color: rgba(143,212,222,.7);
  font-weight: 700;
  margin-right: 2px;
}
.search-msg-body mark,
.search-msg-result mark {
  background: rgba(255, 196, 0, .35);
  color: #ffd966;
  padding: 0 2px;
  border-radius: 2px;
}
.search-loading {
  padding: 12px 14px;
  font-size: 12px;
  color: rgba(233,237,239,.5);
  text-align: center;
}

/* ============ PRIVACY TOGGLE (estilo billetera virtual) ============ */
.privacy-toggle {
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  width: auto !important;
  padding: 4px 8px !important;
  color: var(--fg-subtle);
  transition: all .15s ease;
}
.privacy-toggle:hover {
  color: var(--neon-cyan);
  border-color: var(--neon-cyan);
}
.privacy-toggle.on {
  color: var(--neon-cyan);
  background: rgba(143,212,222,.12) !important;
  border-color: var(--neon-cyan) !important;
}
.privacy-toggle.on::after {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  background: var(--neon-cyan);
  border-radius: 50%;
  margin-left: 5px;
  box-shadow: 0 0 6px var(--neon-cyan);
  animation: privacy-pulse 1.4s ease-in-out infinite;
}
@keyframes privacy-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .35; }
}

/* ============ BUSINESS PANEL (Gaspar) ============ */
.bp-charts-row {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: var(--s-4);
  margin-top: var(--s-4);
}
@media (max-width: 1100px) {
  .bp-charts-row { grid-template-columns: 1fr; }
}
.bp-chart-wide #bp-chart-bars-line { height: 260px; }

.bp-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.bp-table th, .bp-table td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.bp-table th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--fg-subtle);
  font-weight: 600;
  background: rgba(255,255,255,.02);
}
.bp-table td.num, .bp-table th.num {
  text-align: right;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-variant-numeric: tabular-nums;
}
.bp-table tbody tr:hover { background: rgba(255,255,255,.02); }
.bp-table tr.total td {
  border-top: 2px solid var(--neon-cyan);
  font-weight: 700;
  background: rgba(143,212,222,.05);
}
.bp-table.compact th, .bp-table.compact td { padding: 7px 12px; }

.bp-vname {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}
.bp-vdot {
  width: 9px; height: 9px;
  border-radius: 50%;
  display: inline-block;
}
.bp-bar-bg {
  background: rgba(255,255,255,.05);
  height: 6px;
  border-radius: 3px;
  overflow: hidden;
}
.bp-bar-fg {
  height: 100%;
  border-radius: 3px;
  transition: width .25s ease;
}
.bp-pill {
  display: inline-block;
  padding: 2px 8px;
  background: rgba(255,255,255,.06);
  border-radius: 10px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .3px;
  color: var(--fg-subtle);
}
.bp-pill.muted { opacity: .5; }

/* Fila clickeable de vertical (drill-down al detalle) */
.bp-vertical-row {
  transition: background .12s ease;
}
.bp-vertical-row:hover {
  background: rgba(143,212,222,.08) !important;
}
.bp-vertical-row .bp-drill-hint {
  margin-left: 4px;
  color: var(--fg-mute, rgba(255,255,255,.35));
  font-weight: 700;
  transition: transform .15s ease, color .15s ease;
  display: inline-block;
}
.bp-vertical-row:hover .bp-drill-hint {
  color: var(--neon-cyan);
  transform: translateX(3px);
}

/* Flag "parcial" en KPIs cuando el tracking no cubre todo el período */
.partial-flag {
  display: inline-block;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: .5px;
  padding: 1px 5px;
  border-radius: 3px;
  background: rgba(255,167,38,.18);
  color: #FFA726;
  margin-left: 4px;
  vertical-align: middle;
}
.bp-partial-banner {
  margin: 0 20px 12px;
  padding: 10px 14px;
  background: rgba(255,167,38,.06);
  border-left: 3px solid #FFA726;
  border-radius: 4px;
  font-size: 12.5px;
  color: rgba(255,225,200,.85);
  line-height: 1.4;
}
.bp-partial-banner b { color: #FFA726; }

/* Funnel del panel */
.bp-funnel {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.bp-funnel-row {
  display: flex;
  align-items: center;
  gap: 14px;
}
.bp-funnel-lbl {
  width: 200px;
  flex-shrink: 0;
  font-size: 13px;
  color: var(--fg-subtle);
}
.bp-funnel-bar-wrap {
  flex: 1;
  background: rgba(255,255,255,.03);
  border-radius: 6px;
  height: 32px;
  overflow: hidden;
  position: relative;
}
.bp-funnel-bar {
  height: 100%;
  border-radius: 6px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  transition: width .3s ease;
  position: relative;
}
.bp-funnel-num {
  font-family: ui-monospace, monospace;
  font-weight: 700;
  font-size: 14px;
  color: #000;
}
.bp-funnel-pct {
  margin-left: auto;
  font-family: ui-monospace, monospace;
  font-weight: 600;
  font-size: 12px;
  color: rgba(0,0,0,.65);
}

/* SVG charts del panel */
.bp-svg .bp-bar { fill: var(--neon-cyan); opacity: .8; }
.bp-svg .bp-bar-g:hover .bp-bar { opacity: 1; }
.bp-svg .bp-bar-lbl,
.bp-svg .bp-bar-total {
  font-size: 10px;
  font-weight: 600;
  fill: rgba(143,212,222,.95);
  font-family: ui-monospace, monospace;
}
.bp-svg .bp-cost-line {
  fill: none;
  stroke: var(--neon-red);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.bp-svg .bp-cost-dot { fill: var(--neon-red); stroke: var(--bg-0, #0A0A0F); stroke-width: 1.5; }
.bp-svg .bp-cost-lbl {
  font-size: 10px;
  fill: rgba(255,180,180,.85);
  font-weight: 600;
  font-family: ui-monospace, monospace;
}
.bp-svg .bp-stack-lbl {
  font-size: 9px;
  font-weight: 700;
  fill: rgba(0,0,0,.65);
  font-family: ui-monospace, monospace;
}
.bp-svg .bp-legend-inline text { font-size: 11px; fill: var(--fg-subtle); }

/* ============ MISC ============ */
.muted { color: var(--fg-subtle); }
.row { display: flex; gap: var(--s-3); align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--ink-050); }
::-webkit-scrollbar-thumb { background: var(--ink-300); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: var(--ink-400); }

/* ============================================================================
   MOBILE RESPONSIVE (iPhone-first, tablet también)
   ============================================================================
   Estrategia: bottom nav bar fija con scroll horizontal + top compact bar.
   Tablas pasan a scroll-x. KPI grid a 2 cols. Modales full-screen.
   Soporte de safe-area-inset para notch + home indicator de iPhone.
*/
@media (max-width: 768px) {
  body {
    /* Permitir text size adjustment al rotar */
    -webkit-text-size-adjust: 100%;
  }

  /* === SHELL: app grid pasa a stack vertical === */
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
  }

  /* === SIDEBAR → bottom nav bar fija === */
  .sidebar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    top: auto;
    height: auto;
    flex-direction: row;
    align-items: center;
    padding: 4px 6px;
    padding-bottom: max(4px, env(safe-area-inset-bottom));
    border-top: 1px solid var(--border);
    border-right: 0;
    z-index: 50;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    background: rgba(17, 17, 24, .92);
    gap: 6px;
    overflow: visible;
  }

  /* Ocultar elementos no esenciales del sidebar */
  .sidebar .brand,
  .sidebar .sidebar-foot { display: none; }

  /* User-pick: compacto, va a la derecha del nav */
  .sidebar .user-pick {
    flex-shrink: 0;
    padding: 0;
    margin: 0 4px 0 0;
    border: 0;
  }
  .sidebar .user-pick-label { display: none; }
  .sidebar .user-pick-chips {
    /* En fila (no columna) para que la barra inferior sea fina (~52px) y no un
       bloque alto. Antes apilaba Abril/ojo/logout verticalmente = barra gorda. */
    flex-direction: row;
    align-items: center;
    gap: 3px;
    padding: 0;
  }
  .sidebar .user-pick-chips .user-chip {
    font-size: 9px;
    padding: 3px 6px;
    line-height: 1.2;
  }
  /* Solo mostrar el user activo + privacy toggle, los demás no caben */
  .sidebar .user-chip:not(.active):not(.privacy-toggle):not([data-logout]) { display: none; }
  .sidebar .user-chip.add[data-add-user] { display: none; }

  /* Nav: en horizontal con scroll si no entran */
  .sidebar .nav {
    flex-direction: row;
    flex: 1;
    justify-content: flex-start;
    align-items: stretch;
    gap: 0;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    scroll-snap-type: x mandatory;
  }
  .sidebar .nav::-webkit-scrollbar { display: none; }
  .nav-item {
    flex-direction: column;
    gap: 2px;
    font-size: 9px;
    padding: 6px 8px;
    min-width: 56px;
    text-align: center;
    white-space: nowrap;
    border-radius: 8px;
    border: 0;
    position: relative;
    scroll-snap-align: start;
  }
  .nav-item .icon {
    font-size: 18px;
    width: auto;
    line-height: 1;
    margin-bottom: 1px;
  }
  .nav-item .badge {
    position: absolute;
    top: 2px;
    right: 4px;
    margin-left: 0;
    font-size: 8px;
    padding: 0 5px;
    min-width: 14px;
    line-height: 1.4;
  }
  .nav-item.active {
    background: rgba(255, 24, 48, .12);
    color: var(--neon-red);
    box-shadow: none;
    border-color: transparent;
  }

  /* === MAIN: padding bottom para no taparse con bottom bar === */
  .main {
    padding: 12px 12px calc(80px + env(safe-area-inset-bottom)) 12px;
    max-width: 100vw;
  }
  .main.main--chat {
    padding: 0;
    padding-bottom: calc(70px + env(safe-area-inset-bottom));
  }

  /* === PAGE HEAD: stack y achicar título === */
  .page-head {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 18px;
  }
  .page-head h1 { font-size: 26px; }
  .page-head .eyebrow { font-size: 9px; }
  .page-head .actions {
    flex-wrap: wrap;
    width: 100%;
    gap: 6px;
  }
  .page-head .actions .btn { font-size: 12px; padding: 6px 10px; }

  /* === KPI GRID: 2 cols en mobile === */
  .kpi-grid {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  .kpi { padding: 12px 14px; }
  .kpi-value { font-size: 18px; }
  .kpi-label { font-size: 9px; }
  .kpi-delta { font-size: 10px; }

  /* === PERIOD SELECTOR: chips en scroll horizontal === */
  .period-selector {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding: 10px 12px;
  }
  .period-selector .ps-label { font-size: 9px; }
  .period-selector .ps-chips {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 4px;
    width: 100%;
  }
  .period-selector .ps-chips::-webkit-scrollbar { display: none; }
  .ps-chip {
    flex-shrink: 0;
    font-size: 11px;
    padding: 5px 12px;
  }
  .period-selector .ps-meta { font-size: 10px; }

  /* === TABLAS GENÉRICAS: scroll horizontal === */
  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .table-wrap table { min-width: 600px; }
  .table-wrap th, .table-wrap td {
    font-size: 11px;
    padding: 6px 8px;
    white-space: nowrap;
  }
  .table-toolbar {
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px;
  }
  .table-toolbar input,
  .table-toolbar select {
    font-size: 12px;
    padding: 6px 8px;
    flex: 1 1 calc(50% - 6px);
    min-width: 0;
  }

  /* === BUSINESS PANEL específico === */
  .bp-charts-row { grid-template-columns: 1fr; gap: 12px; }
  .bp-table {
    font-size: 11px;
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .bp-table thead, .bp-table tbody { min-width: 540px; display: table; width: 100%; }
  .bp-table th, .bp-table td {
    padding: 8px 10px;
    white-space: nowrap;
  }
  .bp-table .num { font-size: 11px; }
  .bp-bar-bg { width: 60px !important; }
  /* Chart canvas más bajo en mobile */
  .chart-card .chart-canvas,
  .bp-chart-wide #bp-chart-bars-line { height: 200px !important; }
  #bp-chart-stacked { height: 220px !important; }
  #bp-chart-donut { height: 180px !important; }
  #bp-vert-chart { height: 200px !important; }

  /* PnL table compacta */
  .pnl-table { font-size: 12px; }
  .pnl-table td { padding: 5px 10px; }

  /* Funnel */
  .bp-funnel-lbl { width: 120px; font-size: 11px; }
  .bp-funnel-bar { padding: 0 10px; }
  .bp-funnel-num { font-size: 12px; }
  .bp-funnel-pct { font-size: 10px; }

  /* Card headers */
  .card-h { padding: 12px 14px; }
  .card-h h3 { font-size: 13px; }
  .card-h .muted, .card-h .badge { font-size: 10px; }

  /* === MODALES: full-screen en mobile === */
  .modal-bg .modal {
    max-width: 100vw !important;
    width: 100vw !important;
    max-height: 100vh !important;
    height: 100vh !important;
    border-radius: 0 !important;
    margin: 0;
  }
  .modal-bg .modal .modal-h { padding: 12px 14px; }
  .modal-bg .modal .modal-h h3 { font-size: 15px; }
  .modal-bg .modal .modal-body { padding: 12px 14px; }
  .modal-bg .modal .modal-actions {
    padding: 10px 14px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
    flex-wrap: wrap;
    gap: 8px;
  }
  .modal-bg .modal .modal-actions .btn { flex: 1; min-width: 0; }

  /* === ALERTS GRID: stack === */
  .alerts-grid { grid-template-columns: 1fr; gap: 12px; }

  /* === CHART GRID dashboard general === */
  .chart-grid { grid-template-columns: 1fr; gap: 12px; }
  .chart-grid .chart-canvas { height: 200px; }

  /* === CHAT: ajustes mobile === */
  .chat-msg { max-width: 88%; font-size: 14px; }
  .chat-input-bar {
    padding: 8px 8px max(8px, env(safe-area-inset-bottom)) 8px;
    gap: 6px;
  }
  .chat-input-wrap textarea {
    font-size: 16px; /* iOS no hace zoom si es ≥16px */
  }
  .chat-header {
    padding: 8px 12px;
  }
  .chat-header-name { font-size: 14px; }
  .chat-header-phone { font-size: 11px; }
  .chat-header-meta { gap: 6px; flex-wrap: wrap; }
  .chat-header-meta span { display: none; } /* "X msgs" se oculta */
  .chat-list { width: 100%; }
  .chat-messages { padding: 10px 12px 4px; }
  /* Hover actions en mobile siempre visibles, más chicas */
  .chat-msg-actions {
    opacity: 1 !important;
    pointer-events: auto !important;
    background: rgba(42, 57, 66, .92) !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
  }
  .chat-msg.inbound .chat-msg-actions { right: auto; left: 100%; margin-left: 6px; }
  .chat-msg.outbound .chat-msg-actions { left: auto; right: 100%; margin-right: 6px; }
  .chat-msg-actions::after { display: none; } /* el puente no hace falta touch */
  /* En mobile el menú se abre con LONG-PRESS (mantener apretado), no con hover.
     Ocultamos el chevron (no hay hover) y matamos la selección/callout nativa de
     iOS para que mantener apretado abra el menú en vez de seleccionar texto.
     "Copiar texto" queda en el menú para no perder el copiar. */
  .chat-msg-caret { display: none; }
  .chat-msg {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
  }

  /* === IMAGE LIGHTBOX === */
  .img-lightbox .lb-nav { width: 40px; height: 40px; font-size: 26px; }
  .img-lightbox .lb-prev { left: 8px; }
  .img-lightbox .lb-next { right: 8px; }
  .img-lightbox .lb-close { top: max(12px, env(safe-area-inset-top)); right: 12px; }
  .img-lightbox .lb-download { top: max(12px, env(safe-area-inset-top)); right: 60px; }

  /* === DRAWER (detalle de pedido) en mobile: full screen === */
  .drawer {
    width: 100vw !important;
    max-width: 100vw !important;
    border-radius: 0;
    padding-bottom: calc(80px + env(safe-area-inset-bottom));
  }

  /* === SVG charts ajustes === */
  .chart-svg .label { font-size: 9px; }

  /* === Notas (post-it) === */
  .chat-postit { padding: 10px 14px; }

  /* === SCROLL TO BOTTOM FAB === */
  .chat-scroll-down { bottom: 80px; right: 12px; }

  /* === LISTA DE CHATS estilo WhatsApp: items más grandes, tipografía más clara === */
  .chat-contact { padding: 0 14px; gap: 12px; height: 78px; }
  .chat-contact-info { padding: 14px 0; }
  .chat-contact-name { font-size: 16px; }
  .chat-contact.has-unread .chat-contact-name { font-weight: 700; }
  .chat-contact-preview { font-size: 14px; }
  .chat-contact-time { font-size: 12px; }
  .chat-contact-unread {
    min-width: 22px;
    height: 22px;
    border-radius: 11px;
    font-size: 12px;
    padding: 0 7px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
  }
  /* Avatar ligeramente más grande en mobile (visual jerarquía WA) — el width
     inline del HTML manda, pero forzamos el .chat-avatar a expandir. */
  .chat-contact .chat-avatar { width: 52px !important; height: 52px !important; }
  .chat-contact .chat-avatar-text { font-size: 19px !important; }

  /* === LABEL FILTER BAR: una sola fila scroll horizontal estilo WA chips === */
  .label-filter-bar {
    padding: 8px 12px;
    gap: 8px;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    max-height: none;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .label-filter-bar::-webkit-scrollbar { display: none; }
}

@media (max-width: 480px) {
  .nav-item { font-size: 8px; min-width: 50px; padding: 5px 6px; }
  .nav-item .icon { font-size: 16px; }
  .kpi-grid { gap: 6px; }
  .kpi { padding: 10px 12px; }
  .kpi-value { font-size: 16px; }
  .kpi-label { font-size: 8px; }
  .page-head h1 { font-size: 22px; }
  .bp-table { font-size: 10px; }
  .bp-table th, .bp-table td { padding: 6px 8px; }
}

/* === Standalone PWA (iOS app instalada) === */
/* Agrega padding al top para evitar overlap con el status bar de iOS */
.pwa-standalone .sidebar {
  padding-top: max(8px, env(safe-area-inset-top));
}
.pwa-standalone .main {
  padding-top: max(12px, env(safe-area-inset-top));
}
@media (max-width: 768px) {
  .pwa-standalone .main {
    padding-top: calc(max(12px, env(safe-area-inset-top)) + 4px);
  }
  /* Chat: sin top bar de pagina, hay que pegar el chat-header al safe-area */
  .pwa-standalone .main.main--chat .chat-header {
    padding-top: max(12px, env(safe-area-inset-top));
  }
}

/* ===========================================================================
   CHAT MOBILE — estilo WhatsApp app (lista full-screen ↔ conversación full-screen)
   ===========================================================================
   En desktop el chat es split-view: lista a la izquierda + conversación a la
   derecha. En mobile (≤768px) eso es inusable: las dos columnas se apilan
   verticalmente y el input queda lejos.

   Solución estilo WhatsApp: en mobile, solo una de las dos vistas está visible
   a la vez. Las classes `chat-mobile-list` y `chat-mobile-conv` van en el `.app`
   raíz desde JS (ver _applyMobileChatClass). El back arrow del header
   (.chat-back-btn) está en el HTML siempre pero solo se ve en mobile.
   =========================================================================== */
/* Defaults — el media query mobile abajo overridea estos a display visible.
   Los dejamos acá (antes del @media) para que la specificity y orden de
   declaración no nos jueguen en contra. */
.chat-back-btn { display: none; }
.chat-mobile-title { display: none; }
.chat-archived-row { display: none; }

@media (max-width: 768px) {
  /* Override del flex-direction: column que pone .chat-layout en max-width: 900px.
     En mobile queremos UNO de los dos paneles ocupando todo, no apilados. */
  .chat-layout {
    flex-direction: row;
    height: 100%;
  }
  .chat-layout > .chat-contacts,
  .chat-layout > .chat-main {
    flex: 1 1 100%;
    max-width: 100%;
    width: 100%;
  }
  /* Por default (chat-mobile-list o sin class), ocultamos la conversación */
  .app.chat-mobile-list .chat-layout > .chat-main,
  .app:not(.chat-mobile-conv):not(.chat-mobile-list) .chat-layout > .chat-main {
    display: none;
  }
  /* En "conversation", ocultamos la lista y el sidebar nav (full-screen focus) */
  .app.chat-mobile-conv .chat-layout > .chat-contacts {
    display: none;
  }
  .app.chat-mobile-conv .sidebar {
    display: none;
  }
  /* Sin sidebar bottom-bar, el main no necesita el padding bottom para no taparse */
  .app.chat-mobile-conv .main,
  .app.chat-mobile-conv .main.main--chat {
    padding-bottom: env(safe-area-inset-bottom);
  }
  /* El back arrow visible solo cuando estás en mobile chat conversation */
  .chat-back-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 0;
    color: #e9edef;
    cursor: pointer;
    padding: 6px;
    margin-right: 4px;
    border-radius: 50%;
    flex-shrink: 0;
  }
  .chat-back-btn:hover,
  .chat-back-btn:active { background: rgba(255,255,255,.08); }
  /* El back arrow queda visible SOLO durante la vista conversación
     (en lista no tiene sentido — ya estás en la "raíz" del chat). */
  .app.chat-mobile-list .chat-back-btn,
  .app:not(.chat-mobile-conv) .chat-back-btn { display: none; }

  /* ----- Título "Chats" estilo WhatsApp ----- */
  .chat-mobile-title {
    display: block;
    font-size: 28px;
    font-weight: 700;
    color: #e9edef;
    margin: 0;
    padding: 14px 16px 6px;
    letter-spacing: -0.4px;
    background: #111b21;
    flex-shrink: 0;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  }

  /* ----- Header del sidebar más compacto en mobile (botones a la derecha) ----- */
  .chat-contacts-header {
    padding: 4px 8px 8px;
    background: #111b21;
    justify-content: flex-end;
    gap: 4px;
  }
  /* El botón fullscreen no tiene sentido en mobile (ya está full). */
  .chat-contacts-header #chat-fullscreen { display: none; }
  .chat-contacts-header .btn-send {
    width: 36px;
    height: 36px;
    border-radius: 50%;
  }

  /* ----- Search más estilo WhatsApp (más redondeado, padding cómodo) ----- */
  .chat-contacts-search { padding: 4px 12px 10px; }
  .chat-contacts-search input {
    border-radius: 22px;
    padding: 10px 14px 10px 38px;
    font-size: 14px;
    background-color: #202c33;
    background-position: 14px center;
    background-size: 16px;
  }

  /* ----- Fila "Archivados · N" estilo WA ----- */
  .chat-archived-row {
    display: flex;
    align-items: center;
    gap: 28px;
    padding: 12px 20px;
    background: transparent;
    border: 0;
    border-bottom: 1px solid #222d34;
    color: #e9edef;
    cursor: pointer;
    width: 100%;
    text-align: left;
    font-size: 15px;
    font-family: inherit;
    transition: background .15s;
  }
  .chat-archived-row:hover,
  .chat-archived-row:active { background: #1f2c33; }
  .chat-archived-label { flex: 1; color: #e9edef; }
  .chat-archived-count { color: #8696a0; font-size: 13px; }
}



/* ===== Insights IA dashboard ===== */
.ins-table { width:100%; border-collapse:collapse; font-size:13px }
.ins-table thead th { text-align:left; padding:6px 8px; border-bottom:1px solid #2a3942; opacity:.7; font-weight:600; font-size:11px; text-transform:uppercase; letter-spacing:.04em }
.ins-table tbody td { padding:8px 8px; border-bottom:1px solid #1a2530; vertical-align:middle }
.ins-table tbody tr:hover { background:#1a2530 }
.ins-rank { list-style:none; padding:0; margin:0; display:flex; flex-direction:column; gap:8px }
.ins-rank li { display:flex; flex-direction:column; gap:4px }
.ins-rank-label { font-size:13px }
.ins-rank-bar { position:relative; height:18px; background:#1a2530; border-radius:4px; overflow:hidden; display:flex; align-items:center }
.ins-rank-fill { position:absolute; left:0; top:0; bottom:0; background:linear-gradient(90deg, #06b6d4, #22c55e); opacity:.5 }
.ins-rank-bar span { position:relative; padding-left:8px; font-size:12px; font-weight:600 }


.ins-tabs { display:flex; gap:4px; margin-bottom:24px; padding-bottom:12px; border-bottom:1px solid #2a3942 }
.ins-tab { padding:8px 16px; background:transparent; border:0; color:#9ca3af; cursor:pointer; font-size:14px; border-radius:6px 6px 0 0; transition:all .15s; font-family:inherit }
.ins-tab:hover { background:#1a2530; color:#e9edef }
.ins-tab.active { background:#06b6d4; color:#fff; font-weight:600 }


/* KPIs clickeables — drill-down zoom */
.kpi-clickable { cursor:pointer; text-align:left; font-family:inherit; transition: all .15s }
.kpi-clickable:hover { background:#1a2530; transform:translateY(-2px) }
.kpi-clickable.kpi-active { background:#0e7490; box-shadow: 0 4px 12px rgba(6,182,212,.3) }
.kpi-clickable.kpi-active .kpi-value { color:#fff !important }
.btn-sm { padding:4px 10px; font-size:12px }
.btn-ghost { background:transparent; border:1px solid #3b4a54; color:#9ca3af }
.btn-ghost:hover { background:#1a2530 }

/* ===== Copiloto: panel de sugerencia (Fase 2B) ===== */
.btn-suggest { font-size:20px; line-height:1 }
.suggest-panel { margin:0 8px 6px; padding:10px 12px; border-radius:10px; background:#1f2c34; border:1px solid #2a3942; color:#e9edef; font-size:14px; box-shadow:0 2px 12px rgba(0,0,0,.35) }
.suggest-loading { color:#8696a0; font-style:italic }
.suggest-head { display:flex; align-items:center; gap:8px; margin-bottom:7px }
.suggest-title { font-weight:600; color:#00a884; flex:1 }
.suggest-conf { font-size:12px; padding:1px 7px; border-radius:10px; font-weight:700 }
.suggest-conf.ok { background:rgba(0,168,132,.18); color:#00d9a3 }
.suggest-conf.warn { background:rgba(255,167,38,.18); color:#ffb74d }
.suggest-x { background:none; border:none; color:#8696a0; cursor:pointer; font-size:15px; padding:2px 6px }
.suggest-warn { background:rgba(255,167,38,.12); border-left:3px solid #ffb74d; color:#ffcc80; padding:7px 9px; border-radius:6px; margin-bottom:8px; font-size:13px; line-height:1.4 }
.suggest-draft { background:#2a3942; padding:9px 11px; border-radius:8px; white-space:pre-wrap; line-height:1.45 }
.suggest-src { color:#667781; font-size:11px; margin-top:6px }
.suggest-actions { display:flex; gap:8px; margin-top:9px }
.suggest-use { background:#00a884; color:#fff; border:none; border-radius:8px; padding:7px 16px; font-weight:600; cursor:pointer; font-size:14px }
.suggest-use:hover { background:#06cf9c }
.suggest-dismiss { background:transparent; color:#8696a0; border:1px solid #2a3942; border-radius:8px; padding:7px 14px; cursor:pointer; font-size:14px }
.suggest-err { color:#ff6b6b }
.suggest-row { display:flex; align-items:center; justify-content:space-between; gap:8px }
.copilot-cost { display:inline-flex; align-items:center; font-size:12px; color:#9ca3af; background:rgba(0,168,132,.12); padding:2px 8px; border-radius:10px; white-space:nowrap; cursor:default }
.copilot-cost:empty { display:none }
/* Fase 2C: propuestas de mejora al playbook */
.improve-item { background:#1f2c34; border:1px solid #2a3942; border-radius:10px; padding:12px 14px; margin-bottom:10px }
.improve-head { display:flex; align-items:center; gap:8px; margin-bottom:6px; flex-wrap:wrap }
.improve-title { font-weight:600; color:#e9edef; flex:1; font-size:14px }
.improve-vert { font-size:10px; text-transform:uppercase; letter-spacing:.05em; padding:2px 8px; border-radius:10px; font-weight:700; background:rgba(143,212,222,.15); color:#8fd4de }
.improve-vert-cursos { background:rgba(255,167,38,.15); color:#ffb74d }
.improve-vert-supernova { background:rgba(186,104,255,.15); color:#c79bff }
.improve-txt { font-size:13px; line-height:1.5; color:#cfd9de; margin-top:3px }
.improve-content { background:#0b141a; border:1px solid #2a3942; border-radius:8px; padding:10px; font-size:12px; white-space:pre-wrap; word-break:break-word; max-height:280px; overflow:auto; margin-top:6px; color:#cfd9de }
.improve-actions { display:flex; gap:8px; margin-top:10px }
/* Panel de costos del sitio */
.cost-item { background:#1f2c34; border:1px solid #2a3942; border-radius:10px; padding:11px 13px; margin-bottom:8px }
.cost-row1 { display:flex; align-items:center; gap:8px; flex-wrap:wrap }
.cost-cat { font-size:10px; text-transform:uppercase; letter-spacing:.04em; padding:2px 7px; border-radius:8px; font-weight:700; background:rgba(143,212,222,.15); color:#8fd4de; white-space:nowrap }
.cost-cat-ia { background:rgba(0,168,132,.18); color:#00d9a3 }
.cost-cat-mensajeria { background:rgba(37,211,102,.15); color:#25d366 }
.cost-cat-ads { background:rgba(255,167,38,.15); color:#ffb74d }
.cost-cat-almacenamiento { background:rgba(186,104,255,.15); color:#c79bff }
.cost-name { font-weight:600; color:#e9edef; flex:1; font-size:14px }
.cost-amt { font-weight:700; color:#e9edef; font-size:14px; white-space:nowrap }
.cost-usage { font-size:12px; color:#aebac1; margin-top:4px; line-height:1.4 }
.cost-cred { font-size:11px; color:#8696a0; margin-top:3px; word-break:break-word }
.cost-notes { font-size:11px; color:#7c8a93; margin-top:4px; font-style:italic; line-height:1.4 }
.cost-actions { display:flex; gap:8px; align-items:center; margin-top:8px; flex-wrap:wrap }
.cost-link { color:#8fd4de; font-size:12px; text-decoration:none }
.cost-btn { background:transparent; border:1px solid #2a3942; color:#aebac1; border-radius:7px; padding:4px 10px; cursor:pointer; font-size:12px }
.cost-btn:hover { background:rgba(255,255,255,.05) }
.cost-btn-del { color:#ff8a8a }
.cost-sep { font-size:11px; text-transform:uppercase; letter-spacing:.05em; color:#667781; margin:14px 0 8px }
.cost-rate { font-size:12px; color:#aebac1; margin-top:12px; display:flex; align-items:center; gap:6px; flex-wrap:wrap }
.cost-rate input, .cost-edit-grid input, .cost-edit-grid select, .cost-full input { background:#2a3942; border:1px solid #3b4a54; color:#e9edef; border-radius:7px; padding:6px 8px; font-size:13px }
.cost-editing { border-color:#00a884 }
.cost-edit-grid { display:grid; grid-template-columns:repeat(auto-fit,minmax(120px,1fr)); gap:8px; margin-top:8px }
.cost-edit-grid label, .cost-full { display:flex; flex-direction:column; gap:3px; font-size:11px; color:#8696a0 }
.cost-full { margin-top:8px }
.cost-full input { width:100% }
.cost-block-banner { background:rgba(255,68,68,.15); border:1px solid rgba(255,68,68,.4); color:#ffb4b4; border-radius:8px; padding:9px 11px; font-size:12px; line-height:1.4; margin-top:var(--s-3) }
.cost-block-banner a { color:#fff; text-decoration:underline }

/* ===== Nuevo chat: botón "+" del header + sugerencia de la barra de búsqueda ===== */
.new-chat-suggest { padding:6px 10px 2px }
.new-chat-suggest-btn { display:flex; align-items:center; gap:10px; width:100%; text-align:left; background:rgba(0,168,132,.10); border:1px solid rgba(0,168,132,.35); color:#e9edef; border-radius:10px; padding:10px 12px; cursor:pointer; font-size:14px; transition:background .12s }
.new-chat-suggest-btn:hover { background:rgba(0,168,132,.18) }
.new-chat-suggest-btn svg { color:#00a884; flex-shrink:0 }
.new-chat-suggest-btn strong { color:#00d9a6 }
.nc-exists { color:#8696a0; font-size:12px }
.new-chat-modal .modal-body { gap:14px }
.nc-note { font-size:12.5px; line-height:1.45; color:#aebac1; background:rgba(255,255,255,.04); border:1px solid #2a3942; border-radius:8px; padding:9px 11px }
.nc-note strong { color:#e9edef }
.nc-field { display:flex; flex-direction:column; gap:5px }
.nc-label { font-size:12px; color:#8696a0 }
.nc-input { background:#2a3942; border:1px solid #3b4a54; color:#e9edef; border-radius:8px; padding:9px 11px; font-size:14px; width:100%; box-sizing:border-box }
.nc-input:focus { outline:none; border-color:#00a884 }
select.nc-input { cursor:pointer }
.nc-hint { font-size:12px; color:#8696a0; min-height:14px }
.nc-hint.ok { color:#8fd4de }
.nc-hint.err { color:#ff8a8a }
/* Listado de plantillas estilo menú "/" dentro del modal de nuevo chat */
.nc-tpl-list { background:#233138; border:1px solid #2a3942; border-radius:10px; max-height:240px; overflow-y:auto; padding:4px 0 }
.nc-tpl-list .qr-item.nc-selected { background:rgba(0,168,132,.16); box-shadow:inset 3px 0 0 #00a884 }
.nc-empty { padding:14px; text-align:center; color:#8696a0; font-size:13px }
.nc-preview { white-space:pre-wrap; word-break:break-word; font-size:13px; line-height:1.45; color:#d7dde0; background:#0b141a; border:1px solid #2a3942; border-left:3px solid #00a884; border-radius:8px; padding:10px 12px; max-height:200px; overflow:auto }

/* ==========================================================================
   ACCESIBILIDAD
   ========================================================================== */
/* Respeta "Reducir movimiento" del SO: corta animaciones/transiciones largas
   (mejora el confort y ahorra CPU/batería en equipos lentos). */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}
/* Foco visible al navegar por TECLADO (no en click/touch). Varios componentes
   hacen outline:none con foco custom; esto garantiza un anillo neón al tabular
   en los que no tienen ninguno, sin cambiar el look con mouse/touch. */
:focus-visible {
  outline: 2px solid var(--neon-cyan);
  outline-offset: 2px;
}
.btn:focus-visible,
button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--neon-cyan);
  outline-offset: 2px;
}

@media (max-width: 768px) {
  /* iOS hace zoom automático al enfocar un campo con font-size < 16px. Forzamos
     16px en todos los campos de texto en móvil → sin zoom molesto al tipear.
     (checkbox/radio/color/range no disparan zoom ni llevan texto: excluidos.) */
  input:not([type="checkbox"]):not([type="radio"]):not([type="color"]):not([type="range"]),
  textarea,
  select {
    font-size: 16px !important;
  }
  /* Stats del business panel (admin): 3 columnas se aprietan en pantalla chica
     → una por fila. El !important gana sobre el grid-template inline. */
  .bp-stat-grid { grid-template-columns: 1fr !important; }
  /* Modal "Cargar pedido" (hecho a mano con estilos inline): fullscreen en móvil
     en vez de tarjeta con márgenes → más espacio útil para el formulario. */
  #pm-backdrop { padding: 0 !important; }
  #pm-backdrop > div {
    max-width: 100vw !important;
    min-height: 100vh;
    border-radius: 0 !important;
    margin: 0 !important;
  }
}

