/* ==========================================================================
   ELECTRONICAT OS v3 — Responsive Application Stylesheet
   Mobile-First (<768px) -> Tablet Rail (768–1023px) -> Desktop Sidebar (≥1024px)
   ========================================================================== */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea {
  font-family: inherit;
  color: inherit;
  touch-action: manipulation;
}

.mono, .num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

/* ================= APP SHELL (3 BREAKPOINTS) ================= */
.app-shell {
  display: flex;
  flex-direction: column;
  height: var(--vvh, 100dvh);
  width: 100%;
  background: var(--bg);
  overflow: hidden;
}

/* Sidebar oculto en móvil (<768px) */
.sidebar {
  display: none;
}

.main-area {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ================= TOPBAR ================= */
.topbar {
  min-height: var(--topbar-h);
  padding: max(8px, env(safe-area-inset-top)) 14px 8px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-shrink: 0;
  z-index: 10;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.mobile-brand {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}
.mobile-brand img {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.mobile-brand-txt {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.mobile-brand-txt strong {
  font-size: 0.92rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  line-height: 1.15;
}
.mobile-brand-txt small {
  font-size: 0.7rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 5px;
}

.page-title-desktop {
  display: none;
  font-size: 0.98rem;
  font-weight: 800;
  letter-spacing: 0.01em;
}

.topbar-kpis {
  display: none;
  align-items: center;
  gap: 8px;
}

.kpi-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: border-color 140ms var(--ease);
}
.kpi-chip:hover { border-color: var(--accent-border); }
.kpi-chip strong { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-weight: 700; }
.kpi-chip.ok strong { color: var(--ok); }
.kpi-chip.warn strong { color: var(--warn); }
.kpi-chip.accent strong { color: var(--accent); }

.topbar-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ok);
  display: inline-block;
  flex-shrink: 0;
}
.status-dot.warn { background: var(--warn); }
.status-dot.off { background: var(--danger); }

.btn-icon-sm {
  min-width: 38px;
  min-height: 38px;
  padding: 0 9px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  transition: border-color 140ms var(--ease), color 140ms var(--ease), background 140ms var(--ease);
}
.btn-icon-sm:hover {
  border-color: var(--accent-border);
  color: var(--text);
}
.btn-icon-sm svg { width: 17px; height: 17px; flex-shrink: 0; }

.user-pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 38px;
  padding: 4px 10px 4px 5px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 700;
}
.user-pill-btn:hover { border-color: var(--accent-border); }

.avatar-circle {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 0.74rem;
  font-weight: 800;
  color: #ffffff;
  flex-shrink: 0;
}

/* Update Banner (PWA Auto-Update no intrusivo) */
.update-banner {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 14px;
  background: var(--accent-soft);
  border-bottom: 1px solid var(--accent-border);
  font-size: 0.8rem;
  font-weight: 600;
  flex-shrink: 0;
}
.update-banner.show { display: flex; }

/* ================= VIEWS CONTAINER ================= */
.views-container {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.view {
  display: none;
  flex: 1;
  min-height: 0;
  flex-direction: column;
  overflow: hidden;
}
.view.active {
  display: flex;
  animation: viewEnter 150ms var(--ease);
}
@keyframes viewEnter {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ================= BUTTONS & CONTROLS ================= */
.btn-primary {
  min-height: 40px;
  padding: 8px 15px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--accent);
  color: #ffffff;
  font-size: 0.84rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background 140ms var(--ease), transform 120ms var(--ease);
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:active { transform: scale(0.98); }

.btn-secondary {
  min-height: 40px;
  padding: 8px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: border-color 140ms var(--ease), color 140ms var(--ease);
}
.btn-secondary:hover { border-color: var(--accent-border); color: var(--accent); }

.btn-danger {
  min-height: 40px;
  padding: 8px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(239, 68, 68, 0.45);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
}
.btn-danger:hover { background: var(--danger); color: #ffffff; }

.btn-ok {
  min-height: 38px;
  padding: 7px 13px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--ok);
  color: #052e16;
  font-size: 0.82rem;
  font-weight: 800;
  cursor: pointer;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.b-ok { background: var(--ok-soft); color: var(--ok); }
.b-warn { background: var(--warn-soft); color: var(--warn); }
.b-danger { background: var(--danger-soft); color: var(--danger); }
.b-accent { background: var(--accent-soft); color: var(--accent); }
.b-violet { background: var(--violet-soft); color: var(--violet); }
.b-muted { background: var(--surface-3); color: var(--muted); }

/* ================= TAB 1: SALA ESTILO WHATSAPP NATIVO ================= */
.sala-layout {
  flex: 1;
  min-height: 0;
  display: flex;
  overflow: hidden;
}

.sala-main {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background-color: var(--wa-wall-bg);
  background-image:
    radial-gradient(var(--wa-wall-dot) 1.25px, transparent 1.25px),
    radial-gradient(var(--wa-wall-dot) 1.25px, transparent 1.25px);
  background-size: 28px 28px;
  background-position: 0 0, 14px 14px;
  position: relative;
}

.sala-aside {
  display: none;
}

/* Cabecera estilo grupo WhatsApp */
.wa-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 14px;
  background: var(--wa-header-bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 6;
}

.wa-chat-head-left {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}

.wa-group-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.wa-group-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.wa-group-meta strong {
  font-size: 0.94rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.wa-group-sub {
  font-size: 0.74rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.wa-group-sub.typing-live {
  color: var(--wa-green);
  font-weight: 700;
}

.wa-chat-head-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.wa-head-pill {
  min-height: 32px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.74rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 140ms var(--ease), background 140ms var(--ease);
}
.wa-head-pill:hover { border-color: var(--wa-green); }
.wa-head-pill.council { border-color: rgba(139, 92, 246, 0.5); color: var(--text); }

/* Lienzo de mensajes WhatsApp */
.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 12px clamp(12px, 4vw, 48px) 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Separador de fecha estilo WhatsApp (HOY / AYER) */
.wa-date-sep {
  align-self: center;
  margin: 6px 0 4px;
  padding: 5px 12px;
  border-radius: 8px;
  background: var(--wa-date-pill);
  color: var(--wa-date-text);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.16);
}

/* Burbuja estilo WhatsApp */
.msg {
  position: relative;
  max-width: min(86%, 68ch);
  min-width: 112px;
  padding: 7px 10px 7px 11px;
  border-radius: 9px;
  background: var(--wa-in-bg);
  color: var(--wa-in-text);
  box-shadow: 0 1px 1.5px rgba(0, 0, 0, 0.22);
  align-self: flex-start;
  word-wrap: break-word;
  white-space: pre-wrap;
  font-size: 0.91rem;
  line-height: 1.42;
  animation: msgIn 140ms var(--ease);
}
@keyframes msgIn {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg.grouped {
  margin-top: -5px;
}

/* Cola superior izquierda (mensajes entrantes / agentes) */
.msg:not(.me):not(.grouped) {
  border-top-left-radius: 0;
}
.msg:not(.me):not(.grouped)::before {
  content: '';
  position: absolute;
  top: 0;
  left: -8px;
  width: 0;
  height: 0;
  border-top: 9px solid var(--wa-in-bg);
  border-left: 8px solid transparent;
}

/* Mensajes propios salientes (verde WhatsApp) */
.msg.me {
  align-self: flex-end;
  background: var(--wa-out-bg);
  color: var(--wa-out-text);
}
.msg.me:not(.grouped) {
  border-top-right-radius: 0;
}
.msg.me:not(.grouped)::after {
  content: '';
  position: absolute;
  top: 0;
  right: -8px;
  width: 0;
  height: 0;
  border-top: 9px solid var(--wa-out-bg);
  border-right: 8px solid transparent;
}

/* Sutil acento de borde para Consejo x5 y Leads externos */
.msg.ai.fam-council {
  box-shadow: inset 3px 0 0 var(--violet), 0 1px 2px rgba(0, 0, 0, 0.24);
}
.msg.ai.fam-lead {
  box-shadow: inset 3px 0 0 var(--danger), 0 1px 2px rgba(0, 0, 0, 0.24);
}

.msg-sender-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 3px;
  font-size: 0.77rem;
  font-weight: 800;
  line-height: 1.2;
}

.ch-tag {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 4px;
  opacity: 0.85;
}
.ch-wa { background: rgba(0, 168, 132, 0.18); color: var(--wa-green); }
.ch-pwa { background: rgba(134, 150, 160, 0.16); color: var(--wa-date-text); }

.msg-body {
  display: inline;
}
.msg-body strong { font-weight: 800; }
.msg-body code {
  font-family: var(--font-mono);
  font-size: 0.84em;
  background: rgba(0, 0, 0, 0.18);
  padding: 1px 5px;
  border-radius: 4px;
}

/* Timestamp + Doble Check Azul flotante abajo a la derecha (idéntico a WhatsApp) */
.wa-meta-footer {
  float: right;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin: 4px 0 -2px 10px;
  font-size: 0.68rem;
  color: var(--wa-meta);
  font-family: var(--font-sans);
  font-variant-numeric: tabular-nums;
  line-height: 1;
  user-select: none;
}
.wa-checks {
  display: inline-flex;
  align-items: center;
  color: var(--wa-check-blue);
}
.wa-checks svg { width: 15px; height: 11px; }

.msg img.attachment {
  display: block;
  max-width: 100%;
  max-height: 290px;
  border-radius: 7px;
  margin: 4px 0 4px;
}

/* Tarjeta 1-tap Confirmación Sí/No estilo banner flotante WhatsApp */
.pending-bar {
  display: none;
  margin: 0 clamp(10px, 3vw, 24px) 8px;
  padding: 10px 13px;
  border-radius: 11px;
  background: var(--wa-header-bg);
  border-left: 4px solid var(--wa-green);
  box-shadow: var(--shadow-md);
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}
.pending-bar.show { display: flex; }
.pending-bar-txt {
  font-size: 0.82rem;
  line-height: 1.4;
  color: var(--text);
}
.pending-bar-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* Popover de los 9 Agentes */
.agents-popover {
  display: none;
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 70px;
  max-width: 520px;
  background: var(--wa-header-bg);
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  padding: 10px;
  z-index: 35;
  grid-template-columns: repeat(auto-fill, minmax(146px, 1fr));
  gap: 6px;
}
.agents-popover.show { display: grid; }

.agent-opt {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 8px 10px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--wa-input-pill);
  text-align: left;
  cursor: pointer;
  transition: border-color 140ms var(--ease);
}
.agent-opt:hover { border-color: var(--wa-green); }
.agent-opt strong { font-size: 0.8rem; color: var(--text); }
.agent-opt span { font-size: 0.69rem; color: var(--muted); }

/* Preview de Foto */
.preview-bar {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: var(--wa-header-bg);
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
  flex-shrink: 0;
}
.preview-bar.show { display: flex; }
.preview-bar img { height: 48px; width: 48px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); }

/* Barra inferior de escritura idéntica a WhatsApp */
.composer-wrap {
  background: var(--wa-input-bar);
  padding: 8px 10px;
  border-top: 1px solid var(--hairline);
  flex-shrink: 0;
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.wa-input-pill {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: flex-end;
  gap: 2px;
  background: var(--wa-input-pill);
  border-radius: 24px;
  padding: 3px 6px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.14);
}

.wa-input-pill textarea {
  flex: 1;
  min-width: 0;
  min-height: 38px;
  max-height: 120px;
  padding: 8px 6px;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 16px; /* evita zoom en iOS Safari */
  line-height: 1.35;
  resize: none;
  outline: none;
}
.wa-input-pill textarea::placeholder {
  color: var(--wa-date-text);
}

.wa-pill-icon {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--wa-date-text);
  display: grid;
  place-items: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: color 140ms var(--ease), background 140ms var(--ease);
}
.wa-pill-icon:hover { color: var(--text); background: rgba(255, 255, 255, 0.06); }
.wa-pill-icon svg { width: 20px; height: 20px; }
.wa-pill-icon.aisha-on { color: var(--wa-green); }

/* Botón circular verde WhatsApp (Micrófono ↔ Enviar dinámico) */
.wa-action-fab {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: none;
  background: var(--wa-green);
  color: #ffffff;
  display: grid;
  place-items: center;
  cursor: pointer;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.28);
  transition: background 140ms var(--ease), transform 110ms var(--ease);
}
.wa-action-fab:hover { background: var(--wa-green-hover); }
.wa-action-fab:active { transform: scale(0.95); }
.wa-action-fab svg { width: 21px; height: 21px; }

/* Barra de Grabación de Audio estilo WhatsApp */
.rec-bar {
  display: none;
  align-items: center;
  gap: 10px;
  min-height: 46px;
  padding: 3px 6px;
  border-radius: 24px;
  background: var(--wa-input-pill);
}
.rec-bar.show { display: flex; }

.rec-wave {
  display: flex;
  align-items: center;
  gap: 3px;
  height: 22px;
  flex: 1;
}
.rec-wave span {
  width: 3px;
  height: 100%;
  border-radius: 2px;
  background: var(--wa-green);
  animation: waveBar 0.8s ease-in-out infinite;
}
.rec-wave span:nth-child(2) { animation-delay: 0.12s; }
.rec-wave span:nth-child(3) { animation-delay: 0.24s; }
.rec-wave span:nth-child(4) { animation-delay: 0.36s; }
.rec-wave span:nth-child(5) { animation-delay: 0.48s; }
@keyframes waveBar {
  0%, 100% { transform: scaleY(0.28); opacity: 0.55; }
  50% { transform: scaleY(1); opacity: 1; }
}
.rec-timer {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 0.88rem;
  font-weight: 800;
  color: var(--danger);
}

.agent-mono {
  width: 24px;
  height: 24px;
  border-radius: 7px;
  display: inline-grid;
  place-items: center;
  font-family: var(--font-mono);
  font-size: 0.66rem;
  font-weight: 800;
  background: var(--accent-soft);
  color: var(--accent);
  flex-shrink: 0;
}

/* ================= SCROLL PANELS (SILPHY, TALLER, WA) ================= */
.panel-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.section-header h2 {
  font-size: 1.05rem;
  font-weight: 800;
}

.sec-label {
  font-size: 0.74rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-top: 2px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 13px 14px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.card-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

/* ================= TAB 2: PIPELINE KANBAN (MÓVIL SEGMENTADO + PC 4 COLS) ================= */
.pipeline-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 12px 14px;
  gap: 10px;
  overflow: hidden;
}

.filter-row {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  flex-shrink: 0;
  padding-bottom: 2px;
}

.f-chip {
  min-height: 34px;
  padding: 4px 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
}
.f-chip.active {
  background: var(--accent-soft);
  border-color: var(--accent-border);
  color: var(--accent);
}

/* Segmented Tabs (Solo móvil <768px) */
.mobile-kanban-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  flex-shrink: 0;
}
.mk-tab {
  min-height: 38px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
}
.mk-tab.active {
  background: var(--accent-soft);
  color: var(--accent);
}
.mk-tab span.cnt {
  font-family: var(--font-mono);
  font-size: 0.68rem;
}

.kanban-board {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.kanban-col {
  display: none;
  flex: 1;
  min-height: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  flex-direction: column;
  overflow: hidden;
}
.kanban-col.mobile-active { display: flex; }
.kanban-col.drag-over { border-color: var(--accent); }

.col-head {
  padding: 11px 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  border-bottom: 1px solid var(--border);
}
.col-PENDIENTE .col-head { border-top: 3px solid var(--muted); }
.col-EN_PROCESO .col-head { border-top: 3px solid var(--accent); }
.col-BLOQUEADO .col-head { border-top: 3px solid var(--warn); }
.col-LISTO .col-head { border-top: 3px solid var(--ok); }

.col-count {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.col-body {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.task-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
  padding: 11px 12px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  cursor: grab;
  transition: transform 120ms var(--ease), border-color 140ms var(--ease);
}
.task-card:hover { border-color: var(--accent-border); }
.task-card.prio-ALTA { border-left-color: var(--danger); }
.task-card.prio-MEDIA { border-left-color: var(--warn); }
.task-card.prio-BAJA { border-left-color: var(--ok); }

.task-title { font-size: 0.89rem; font-weight: 700; line-height: 1.38; }
.task-meta { display: flex; justify-content: space-between; align-items: center; font-size: 0.72rem; color: var(--muted); }
.task-tags { display: flex; flex-wrap: wrap; gap: 5px; }
.agent-tag {
  font-size: 0.69rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 5px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--accent);
}
.task-deliv {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--muted);
  background: var(--surface);
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px dashed var(--border);
  word-break: break-word;
}
.task-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  padding-top: 6px;
  border-top: 1px solid var(--border);
}
.btn-mini {
  min-height: 34px;
  padding: 5px 10px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.74rem;
  font-weight: 700;
  cursor: pointer;
}
.btn-mini:hover { border-color: var(--accent); color: var(--accent); }
.btn-mini.del:hover { border-color: var(--danger); color: var(--danger); }

/* ================= TAB 3: CAJA SILPHY ================= */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 13px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.kpi-card span { font-size: 0.74rem; color: var(--muted); font-weight: 700; }
.kpi-card strong {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 1.24rem;
  font-weight: 800;
}
.kpi-card strong.ok { color: var(--ok); }
.kpi-card strong.accent { color: var(--accent); }
.kpi-card strong.warn { color: var(--warn); }
.kpi-card strong.danger { color: var(--danger); }

.wallets-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}

.wallet-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 3px solid var(--accent);
  border-radius: var(--radius-md);
  padding: 12px 13px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.wallet-alias-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 5px 8px;
  border-radius: 7px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 0.76rem;
}

.calc-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
}
.calc-grid input {
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-family: var(--font-mono);
  font-size: 0.92rem;
}
.calc-results {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 7px;
  margin-top: 4px;
}
.calc-pill {
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.78rem;
}
.calc-pill strong { font-family: var(--font-mono); color: var(--ok); }

.two-col-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

/* ================= TAB 4: TALLER & BOM ELECTROHOBBIE ================= */
.progress-track {
  height: 8px;
  border-radius: 999px;
  background: var(--surface-3);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--ok);
  border-radius: 999px;
  transition: width 220ms var(--ease);
}

.check-item {
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 44px;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
  cursor: pointer;
  font-size: 0.85rem;
  line-height: 1.35;
}
.check-item input[type="checkbox"] {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  cursor: pointer;
}
.check-item.done {
  opacity: 0.62;
  text-decoration: line-through;
}

.warn-callout {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--warn-soft);
  border: 1px solid rgba(245, 158, 11, 0.45);
  color: var(--warn);
  font-size: 0.82rem;
  font-weight: 700;
}

/* ================= TAB 5: WHATSAPP & RED ================= */
.wa-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(290px, 1fr));
  gap: 12px;
}
.qr-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 16px;
  border-radius: var(--radius-md);
  border: 1px dashed var(--border-strong);
  background: var(--surface-2);
  text-align: center;
  min-height: 150px;
}
.qr-box img { width: 210px; height: 210px; border-radius: 10px; background: #fff; padding: 8px; }
.pair-code {
  font-family: var(--font-mono);
  font-size: 1.85rem;
  font-weight: 900;
  letter-spacing: 0.16em;
  color: var(--accent);
  background: var(--surface);
  padding: 10px 18px;
  border-radius: 10px;
  border: 1px solid var(--accent-border);
  user-select: all;
}
.inline-form {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.inline-form input {
  flex: 1;
  min-width: 130px;
  min-height: 40px;
  padding: 8px 11px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 0.86rem;
}
.owner-row, .key-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 0.82rem;
}
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 40px;
  font-size: 0.84rem;
}
.toggle-row input { width: 19px; height: 19px; cursor: pointer; }

/* ================= SEGMENTED SUB-TABS & CLEAN DASHBOARD ================= */
.seg-tabs {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 4px;
  padding: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 13px;
}
.seg-btn {
  min-height: 36px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 6px 8px;
  transition: background 0.16s ease, color 0.16s ease, box-shadow 0.16s ease;
}
.seg-btn.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
}
.sub-pane {
  display: none;
  flex-direction: column;
  gap: 14px;
}
.sub-pane.active {
  display: flex;
}
.hero-balance-card {
  background: linear-gradient(145deg, var(--surface) 0%, var(--surface-2) 100%);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.hero-balance-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}
.hero-balance-val {
  font-size: 1.85rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--ok);
  line-height: 1.1;
  margin-top: 3px;
}
.hero-sub-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.hero-metric {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.hero-metric span {
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 600;
}
.hero-metric strong {
  font-size: 1.02rem;
  font-weight: 800;
}

/* ================= BOTTOM NAV (MÓVIL <768px · 5 ÍTEMS CON PÍLDORA ACTIVA) ================= */
@media (max-width: 767px) {
  #btnQuickPalette { display: none !important; }
  .mobile-brand-txt strong { white-space: nowrap; font-size: 0.84rem; }
  .user-pill-btn #topUserName { display: none; }
  .user-pill-btn { padding: 3px; }
}
.bottom-nav {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 5px 6px max(8px, env(safe-area-inset-bottom));
  gap: 2px;
  flex-shrink: 0;
  z-index: 15;
}
.app-shell.kb-open .bottom-nav,
.app-shell.kb-open .sala-quickbar {
  display: none !important;
}

.bnav-btn {
  min-height: 54px;
  background: none;
  border: none;
  color: var(--muted);
  padding: 4px 2px;
  font-size: 0.68rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  position: relative;
  transition: color 0.16s ease;
}
.bnav-ico {
  width: 46px;
  height: 28px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.18s ease, transform 0.16s ease;
}
.bnav-btn svg { width: 20px; height: 20px; }
.bnav-btn.active {
  color: var(--accent);
}
.bnav-btn.active .bnav-ico {
  background: rgba(0, 153, 220, 0.16);
}
.bnav-dot {
  position: absolute;
  top: 5px;
  right: calc(50% - 17px);
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--warn);
}
.bnav-dot.on { background: var(--ok); }
.bnav-badge {
  position: absolute;
  top: 2px;
  right: calc(50% - 22px);
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 0.62rem;
  font-weight: 800;
  display: none;
  align-items: center;
  justify-content: center;
}
.bnav-badge.show { display: inline-flex; }

/* ================= DIALOGS & LOGIN SCREEN ================= */
dialog {
  margin: auto;
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text);
  width: min(460px, 94vw);
  box-shadow: var(--shadow-lg);
}
dialog[open] { display: flex; flex-direction: column; animation: viewEnter 150ms var(--ease); }
dialog::backdrop { background: rgba(6, 11, 18, 0.78); }

.dlg-h {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.94rem;
  font-weight: 800;
}
.dlg-b {
  padding: 15px 16px;
  display: flex;
  flex-direction: column;
  gap: 11px;
  max-height: 74dvh;
  overflow-y: auto;
}
.dlg-b label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
}
.dlg-b input, .dlg-b select, .dlg-b textarea {
  min-height: 42px;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.92rem;
}
.dlg-f {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* Auth Overlay (Email + Contraseña Cifrada Individual) */
.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: var(--bg);
}
.auth-overlay.show { display: flex; }

.auth-card {
  width: min(410px, 94vw);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 18px;
  padding: 26px 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: var(--shadow-lg);
}
.auth-card.shake { animation: authShake 240ms var(--ease); }
@keyframes authShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-7px); }
  75% { transform: translateX(7px); }
}
.auth-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
}
.auth-logo img {
  height: 46px;
  width: auto;
  border-radius: 8px;
}
.auth-logo p { font-size: 0.8rem; color: var(--muted); }

.field-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
}
.pwd-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.field-group input {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 16px;
}
.pwd-wrap input { padding-right: 44px; }
.pwd-toggle {
  position: absolute;
  right: 4px;
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  display: grid;
  place-items: center;
}
.auth-err {
  color: var(--danger);
  font-size: 0.8rem;
  font-weight: 700;
  min-height: 18px;
  text-align: center;
}

/* Council Live Preview Modal */
.council-roster {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 7px;
}
.c-member {
  padding: 8px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 0.74rem;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.c-member.voting {
  border-color: var(--violet);
  animation: pulseSoft 1s infinite ease-in-out;
}
@keyframes pulseSoft {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

/* Skeleton Loader */
.skeleton {
  height: 54px;
  border-radius: 10px;
  background: var(--surface-2);
  animation: pulseSoft 1.2s infinite ease-in-out;
}

/* Toast */
.toast {
  position: fixed;
  bottom: calc(var(--bottom-nav-h) + 14px);
  right: 16px;
  max-width: min(340px, 90vw);
  background: var(--surface);
  border: 1px solid var(--accent-border);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 0.82rem;
  font-weight: 700;
  box-shadow: var(--shadow-md);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 180ms var(--ease), transform 180ms var(--ease);
  z-index: 250;
}
.toast.show { opacity: 1; transform: translateY(0); }

/* ================= TABLET BREAKPOINT (768px – 1023px) ================= */
@media (min-width: 768px) {
  .app-shell {
    display: grid;
    grid-template-columns: var(--sidebar-rail-w) 1fr;
  }

  .bottom-nav { display: none !important; }
  .mobile-brand { display: none; }
  .page-title-desktop { display: block; }
  .toast { bottom: 20px; }

  .sidebar {
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 12px 10px;
    gap: 12px;
    overflow: hidden;
    z-index: 20;
  }

  .sb-head {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 42px;
  }
  .sb-logo-full { display: none; height: 28px; width: auto; }
  .sb-logo-sq { width: 34px; height: 34px; border-radius: 9px; border: 1px solid var(--border); }
  .sb-collapse-btn { display: none; }

  .sb-nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
  }
  .sb-btn {
    min-height: 44px;
    padding: 8px 10px;
    border-radius: 10px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--muted);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 11px;
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    position: relative;
    transition: background 140ms var(--ease), color 140ms var(--ease), border-color 140ms var(--ease);
  }
  .sb-btn svg { width: 20px; height: 20px; flex-shrink: 0; }
  .sb-btn span.sb-lbl { display: none; white-space: nowrap; }
  .sb-btn:hover { background: var(--surface-2); color: var(--text); }
  .sb-btn.active {
    background: var(--accent-soft);
    border-color: var(--accent-border);
    color: var(--accent);
  }

  .sb-foot {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
  }
  .sb-user-card {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 7px;
    border-radius: 10px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    cursor: pointer;
    text-align: left;
  }
  .sb-user-info { display: none; min-width: 0; }
  .sb-user-info strong { display: block; font-size: 0.82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .sb-user-info small { display: block; font-size: 0.69rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

  /* Tablet Kanban 2x2 */
  .mobile-kanban-tabs { display: none; }
  .kanban-board {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    overflow-y: auto;
  }
  .kanban-col { display: flex; min-height: 280px; }
  .two-col-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ================= DESKTOP BREAKPOINT (≥1024px) ================= */
@media (min-width: 1024px) {
  .app-shell {
    grid-template-columns: var(--sidebar-w) 1fr;
  }
  .app-shell.sb-collapsed {
    grid-template-columns: var(--sidebar-rail-w) 1fr;
  }

  .topbar-kpis { display: flex; }

  .sb-head { justify-content: space-between; padding: 0 4px; }
  .sb-logo-full { display: block; }
  .sb-logo-sq { display: none; }
  .sb-collapse-btn { display: inline-flex; }

  .sb-btn { justify-content: flex-start; padding: 9px 12px; }
  .sb-btn span.sb-lbl { display: inline; }
  .sb-user-card { justify-content: flex-start; padding: 8px 10px; }
  .sb-user-info { display: block; }

  /* Collapsed Sidebar override */
  .app-shell.sb-collapsed .sb-head { justify-content: center; }
  .app-shell.sb-collapsed .sb-logo-full { display: none; }
  .app-shell.sb-collapsed .sb-logo-sq { display: block; }
  .app-shell.sb-collapsed .sb-collapse-btn { display: none; }
  .app-shell.sb-collapsed .sb-btn { justify-content: center; padding: 9px; }
  .app-shell.sb-collapsed .sb-btn span.sb-lbl { display: none; }
  .app-shell.sb-collapsed .sb-user-card { justify-content: center; padding: 7px; }
  .app-shell.sb-collapsed .sb-user-info { display: none; }

  /* Desktop Kanban 4 columnas reales */
  .kanban-board {
    grid-template-columns: repeat(4, minmax(230px, 1fr));
    overflow-x: auto;
    overflow-y: hidden;
  }
  .kanban-col { min-height: 0; }
}

/* ================= DESKTOP WIDE: SALA DUAL (≥1280px) ================= */
@media (min-width: 1280px) {
  .sala-aside {
    display: flex;
    flex-direction: column;
    width: 312px;
    flex-shrink: 0;
    background: var(--bg-elevated);
    border-left: 1px solid var(--border);
    padding: 14px;
    gap: 12px;
    overflow-y: auto;
  }

  .aside-agents-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
  }
  .aside-agent-btn {
    padding: 8px 6px;
    border-radius: 9px;
    border: 1px solid var(--border);
    background: var(--surface);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    cursor: pointer;
    text-align: center;
    transition: border-color 140ms var(--ease), transform 120ms var(--ease);
  }
  .aside-agent-btn:hover { border-color: var(--accent); transform: translateY(-1px); }
  .aside-agent-btn strong { font-size: 0.72rem; }
  .aside-agent-btn small { font-size: 0.62rem; color: var(--muted); }
}
