/* ==========================================================================
   PezControl — copiloto.css
   Estilos del Botón Flotante (FAB), Ventana de Chat del Copiloto IA
   y Tarjetas de Diagnóstico Ejecutivo para Dirección.
   Totalmente compatible con modo claro y oscuro de PezControl.
   Todos los selectores de primer nivel llevan el prefijo .copiloto-
   para garantizar cero colisiones con otras hojas de estilo.
   ========================================================================== */

/* 1. Botón Flotante de Acción (FAB) */
.copiloto-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: linear-gradient(135deg, #F37329 0%, #D85610 100%);
  color: #FFFFFF;
  border: none;
  box-shadow: 0 6px 20px rgba(243, 115, 41, 0.45), 0 2px 6px rgba(0, 0, 0, 0.25);
  cursor: pointer;
  z-index: var(--z-modal, 200);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.2s ease, box-shadow 0.2s ease;
  user-select: none;
  outline: none;
}

.copiloto-fab:hover {
  transform: scale(1.08) translateY(-2px);
  box-shadow: 0 10px 28px rgba(243, 115, 41, 0.6), 0 3px 8px rgba(0, 0, 0, 0.3);
}

.copiloto-fab:active {
  transform: scale(0.96) translateY(0);
}

.copiloto-fab.copiloto-fab-hidden {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.6);
}

.copiloto-fab-pulse {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  border-radius: 50%;
  border: 2px solid #F37329;
  animation: copiloto-ping 2s cubic-bezier(0, 0, 0.2, 1) infinite;
  pointer-events: none;
  opacity: 0.7;
}

@keyframes copiloto-ping {
  75%, 100% {
    transform: scale(1.4);
    opacity: 0;
  }
}

.copiloto-fab-badge {
  position: absolute;
  top: -3px;
  right: -3px;
  background: #0F172A;
  color: #38BDF8;
  border: 1.5px solid #38BDF8;
  font-size: 9px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 10px;
  letter-spacing: 0.5px;
  font-family: var(--font-mono, monospace);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}

/* 2. Tarjeta / Ventana de Consulta (Drawer flotante) */
.copiloto-drawer {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 430px;
  max-width: calc(100vw - 32px);
  height: 580px;
  max-height: calc(100vh - 48px);
  background: var(--bg-surface, #FFFFFF);
  border: 1px solid var(--border-color, #D4D4D4);
  border-radius: 12px;
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.28), 0 4px 12px rgba(0, 0, 0, 0.12);
  display: flex;
  flex-direction: column;
  z-index: var(--z-modal, 200);
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  transform: translateY(16px) scale(0.97);
  transition: all 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

.copiloto-drawer.copiloto-open {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

/* 3. Cabecera del Copiloto (Siempre oscura con texto blanco nítido) */
.copiloto-header {
  padding: 12px 16px;
  background: #1A2535;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
}

.copiloto-header-title-box {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.copiloto-header-avatar {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: rgba(243, 115, 41, 0.2);
  border: 1px solid rgba(243, 115, 41, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}

.copiloto-header-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.copiloto-header-title {
  font-size: 13px;
  font-weight: 700;
  color: #FFFFFF;
  display: flex;
  align-items: center;
  gap: 6px;
}

.copiloto-header-tag {
  font-size: 9px;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(243, 115, 41, 0.2);
  color: #F9A65C;
  border: 1px solid rgba(243, 115, 41, 0.4);
  font-weight: 700;
}

.copiloto-header-sub {
  font-size: 11px;
  color: #94A3B8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}

.copiloto-header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.copiloto-btn-icon {
  background: none;
  border: none;
  color: #CBD5E1;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  transition: all 0.15s ease;
}

.copiloto-btn-icon:hover {
  background: rgba(255, 255, 255, 0.15);
  color: #FFFFFF;
}

/* 4. Barra de Cuota / Límite de Consultas */
.copiloto-quota-bar {
  padding: 7px 14px;
  background: var(--bg-surface-subtle, #F0F1F2);
  border-bottom: 1px solid var(--border-color, #D4D4D4);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-secondary, #485A6C);
  flex-shrink: 0;
  font-weight: 500;
}

.copiloto-quota-badge {
  font-family: var(--font-mono, monospace);
  font-weight: 700;
  color: var(--color-brand, #F37329);
}

/* 5. Chips de Preguntas Rápidas */
.copiloto-quick-chips {
  padding: 8px 12px;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  border-bottom: 1px solid var(--border-color, #D4D4D4);
  background: var(--bg-surface-alt, #F8F9FA);
  scrollbar-width: none;
  flex-shrink: 0;
}

.copiloto-quick-chips::-webkit-scrollbar {
  display: none;
}

.copiloto-chip {
  flex-shrink: 0;
  background: var(--bg-surface, #FFFFFF);
  border: 1px solid var(--border-color, #D4D4D4);
  color: var(--text-primary, #273445);
  padding: 5px 11px;
  border-radius: 14px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: all 0.15s ease;
  white-space: nowrap;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.copiloto-chip:hover {
  background: var(--color-orange-50, #FEF5EB);
  border-color: var(--color-brand, #F37329);
  color: var(--color-brand-dark, #7A3800);
}

/* 6. Cuerpo de Mensajes */
.copiloto-messages {
  flex: 1;
  padding: 14px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  font-size: 13px;
  line-height: 1.5;
  background: var(--bg-surface, #FFFFFF);
  color: var(--text-primary, #273445);
}

.copiloto-msg {
  display: flex;
  flex-direction: column;
  max-width: 88%;
  animation: copiloto-fadeIn 0.2s ease;
}

@keyframes copiloto-fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.copiloto-msg-user {
  align-self: flex-end;
}

.copiloto-msg-user .copiloto-msg-bubble {
  background: linear-gradient(135deg, #F37329 0%, #D85610 100%);
  color: #FFFFFF;
  border-radius: 14px 14px 2px 14px;
  padding: 9px 13px;
  box-shadow: 0 2px 8px rgba(243, 115, 41, 0.25);
  font-weight: 500;
}

.copiloto-msg-ai {
  align-self: flex-start;
  max-width: 95%;
}

.copiloto-msg-ai .copiloto-msg-bubble {
  background: var(--bg-surface-subtle, #F0F1F2);
  color: var(--text-primary, #273445);
  border: 1px solid var(--border-color, #D4D4D4);
  border-radius: 14px 14px 14px 2px;
  padding: 12px 14px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  line-height: 1.55;
}

.copiloto-msg-ai .copiloto-msg-bubble strong {
  color: var(--text-primary, #273445);
  font-weight: 700;
}

.copiloto-msg-meta {
  font-size: 10px;
  color: var(--text-muted, #667885);
  margin-top: 3px;
  padding: 0 4px;
}

/* 7. Estructura de Reportes y Tablas dentro de los Mensajes */
.copiloto-report-box {
  background: var(--bg-surface, #FFFFFF);
  border-radius: 8px;
  border: 1px solid var(--border-color, #D4D4D4);
  border-left: 4px solid var(--color-brand, #F37329);
  padding: 10px 12px;
  margin: 6px 0;
}

.copiloto-report-box.copiloto-status-red {
  border-left-color: #EF4444;
}

.copiloto-report-box.copiloto-status-amber {
  border-left-color: #F59E0B;
}

.copiloto-report-box.copiloto-status-green {
  border-left-color: #10B981;
}

.copiloto-report-title {
  font-weight: 700;
  font-size: 12px;
  margin: 8px 0 4px 0;
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-primary, #273445);
}

.copiloto-btn-whatsapp {
  margin-top: 10px;
  background: #128C7E;
  color: #FFFFFF;
  border: none;
  padding: 7px 13px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s ease;
  box-shadow: 0 2px 4px rgba(18, 140, 126, 0.25);
}

.copiloto-btn-whatsapp:hover {
  background: #075E54;
}

/* 8. Animación de "Pensando..." */
.copiloto-typing {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 14px;
  background: var(--bg-surface-subtle, #F0F1F2);
  border: 1px solid var(--border-color, #D4D4D4);
  border-radius: 14px;
  width: fit-content;
  color: var(--text-secondary, #485A6C);
  font-size: 11px;
  font-weight: 500;
}

.copiloto-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-brand, #F37329);
  animation: copiloto-bounce 1.4s infinite ease-in-out both;
}

.copiloto-dot:nth-child(1) { animation-delay: -0.32s; }
.copiloto-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes copiloto-bounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

/* 9. Barra Inferior de Entrada */
.copiloto-footer {
  padding: 10px 12px;
  background: var(--bg-surface-subtle, #F0F1F2);
  border-top: 1px solid var(--border-color, #D4D4D4);
  display: flex;
  align-items: flex-end;
  gap: 8px;
  flex-shrink: 0;
}

.copiloto-input-box {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
}

.copiloto-textarea {
  width: 100%;
  max-height: 100px;
  min-height: 38px;
  background: var(--bg-surface, #FFFFFF);
  border: 1px solid var(--border-color, #D4D4D4);
  border-radius: 8px;
  padding: 8px 12px;
  color: var(--text-primary, #273445);
  font-family: inherit;
  font-size: 13px;
  line-height: 1.4;
  resize: none;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.copiloto-textarea:focus {
  border-color: var(--color-brand, #F37329);
  box-shadow: 0 0 0 2px rgba(243, 115, 41, 0.15);
}

.copiloto-btn-mic {
  background: var(--bg-surface, #FFFFFF);
  border: 1px solid var(--border-color, #D4D4D4);
  color: var(--text-secondary, #485A6C);
  width: 38px;
  height: 38px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.copiloto-btn-mic:hover {
  background: var(--bg-surface-subtle, #F0F1F2);
  color: var(--color-brand, #F37329);
  border-color: var(--color-brand, #F37329);
}

.copiloto-btn-mic.copiloto-mic-recording {
  color: #EF4444;
  animation: copiloto-pulse-red 1s infinite;
  background: rgba(239, 68, 68, 0.12);
  border-color: #EF4444;
}

@keyframes copiloto-pulse-red {
  0% { transform: scale(1); }
  50% { transform: scale(1.1); }
  100% { transform: scale(1); }
}

.copiloto-btn-send {
  background: var(--color-brand, #F37329);
  color: #FFFFFF;
  border: none;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: all 0.15s ease;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(243, 115, 41, 0.3);
}

.copiloto-btn-send:hover {
  background: #D85610;
  transform: translateY(-1px);
}

.copiloto-btn-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

/* 10. Tarjeta Destacada de Diagnóstico IA en la Vista de Reporte Semanal */
.copiloto-semanal-banner {
  background: var(--bg-surface, #FFFFFF);
  border: 1px solid var(--border-color, #D4D4D4);
  border-left: 5px solid var(--color-brand, #F37329);
  border-radius: 8px;
  padding: 16px 20px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm, 0 2px 8px rgba(0, 0, 0, 0.08));
}

.copiloto-semanal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-color, #D4D4D4);
}

.copiloto-semanal-title-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.copiloto-semanal-badge {
  background: rgba(243, 115, 41, 0.15);
  color: var(--color-brand, #F37329);
  font-weight: 700;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 6px;
  border: 1px solid rgba(243, 115, 41, 0.3);
}

.copiloto-semanal-body {
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-primary, #273445);
}

.copiloto-semanal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 14px;
  margin-top: 14px;
}

.copiloto-semanal-card {
  background: var(--bg-surface-subtle, #F0F1F2);
  border: 1px solid var(--border-color, #D4D4D4);
  border-radius: 8px;
  padding: 12px 14px;
}

.copiloto-semanal-card-title {
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-primary, #273445);
}

/* 11. Vista Dedicada: Reporte Ejecutivo de Dirección con IA */
.copiloto-view-wrap {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 16px 20px 64px 20px;
  max-width: 1300px;
  margin: 0 auto;
  width: 100%;
  box-sizing: border-box;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}

.copiloto-view-wrap > * {
  flex-shrink: 0;
}

.copiloto-view-wrap::-webkit-scrollbar {
  width: 8px;
}

.copiloto-view-wrap::-webkit-scrollbar-track {
  background: transparent;
}

.copiloto-view-wrap::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.4);
  border-radius: 4px;
}

.copiloto-view-wrap::-webkit-scrollbar-thumb:hover {
  background: rgba(148, 163, 184, 0.7);
}

.copiloto-view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border-color, #E2E8F0);
}

.copiloto-view-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary, #0F172A);
  margin: 0 0 4px 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.copiloto-view-desc {
  font-size: 13px;
  color: var(--text-secondary, #64748B);
  margin: 0;
}

.copiloto-quota-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(243, 115, 41, 0.1);
  color: var(--color-brand, #F37329);
  border: 1px solid rgba(243, 115, 41, 0.3);
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}

.copiloto-config-panel {
  background: var(--bg-surface, #FFFFFF);
  border: 1px solid var(--border-color, #E2E8F0);
  border-radius: 12px;
  padding: 20px;
  box-shadow: var(--shadow-sm, 0 1px 3px rgba(0,0,0,0.05));
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.copiloto-pills-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.copiloto-pill-btn {
  background: var(--bg-surface-subtle, #F1F5F9);
  color: var(--text-secondary, #475569);
  border: 1px solid var(--border-color, #CBD5E1);
  border-radius: 8px;
  padding: 7px 14px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
}

.copiloto-pill-btn:hover {
  background: rgba(243, 115, 41, 0.08);
  color: var(--color-brand, #F37329);
  border-color: rgba(243, 115, 41, 0.4);
}

.copiloto-pill-btn.copiloto-pill-active {
  background: var(--color-brand, #F37329);
  color: #FFFFFF;
  border-color: var(--color-brand, #F37329);
  box-shadow: 0 2px 6px rgba(243, 115, 41, 0.35);
}

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

.copiloto-focus-card {
  border: 1.5px solid var(--border-color, #E2E8F0);
  background: var(--bg-surface, #FFFFFF);
  border-radius: 10px;
  padding: 12px 14px;
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.copiloto-focus-card:hover {
  border-color: var(--color-brand, #F37329);
  background: rgba(243, 115, 41, 0.03);
}

.copiloto-focus-card.copiloto-focus-active {
  border-color: var(--color-brand, #F37329);
  background: rgba(243, 115, 41, 0.07);
  box-shadow: 0 0 0 1px var(--color-brand, #F37329);
}

.copiloto-focus-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary, #0F172A);
  display: flex;
  align-items: center;
  gap: 6px;
}

.copiloto-focus-desc {
  font-size: 11px;
  color: var(--text-secondary, #64748B);
  line-height: 1.35;
}

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

.copiloto-kpi-card {
  background: var(--bg-surface, #FFFFFF);
  border: 1px solid var(--border-color, #E2E8F0);
  border-radius: 10px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.copiloto-kpi-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary, #64748B);
}

.copiloto-kpi-val {
  font-size: 22px;
  font-weight: 800;
  color: var(--text-primary, #0F172A);
  font-family: var(--font-mono, monospace);
  display: flex;
  align-items: center;
  gap: 8px;
}

.copiloto-kpi-sub {
  font-size: 11px;
  color: var(--text-secondary, #64748B);
}

.copiloto-report-doc {
  background: var(--bg-surface, #FFFFFF);
  border: 1px solid var(--border-color, #E2E8F0);
  border-radius: 12px;
  padding: 28px;
  box-shadow: var(--shadow-sm, 0 2px 8px rgba(0, 0, 0, 0.05));
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.copiloto-report-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-color, #E2E8F0);
}

.copiloto-block-section {
  background: var(--bg-surface-subtle, #F8FAFC);
  border: 1px solid var(--border-color, #E2E8F0);
  border-radius: 10px;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  border-left: 4px solid var(--border-color, #CBD5E1);
}

.copiloto-block-section.copiloto-b-semaforo {
  border-left-color: #10B981;
}

.copiloto-block-section.copiloto-b-alertas {
  border-left-color: #EF4444;
}

.copiloto-block-section.copiloto-b-aciertos {
  border-left-color: #3B82F6;
}

.copiloto-block-section.copiloto-b-compras {
  border-left-color: #F59E0B;
}

.copiloto-block-section.copiloto-b-estrategia {
  border-left-color: #8B5CF6;
}

.copiloto-block-header {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary, #0F172A);
  display: flex;
  align-items: center;
  gap: 8px;
}

.copiloto-block-content {
  font-size: 13px;
  line-height: 1.65;
  color: var(--text-primary, #334155);
}

.copiloto-block-content ul {
  padding-left: 18px;
  margin: 6px 0;
}

.copiloto-block-content li {
  margin-bottom: 5px;
}

.copiloto-loading-box {
  background: var(--bg-surface, #FFFFFF);
  border: 1px solid var(--border-color, #E2E8F0);
  border-radius: 12px;
  padding: 48px 24px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.copiloto-empty-state {
  background: var(--bg-surface, #FFFFFF);
  border: 1px dashed var(--border-color, #CBD5E1);
  border-radius: 12px;
  padding: 48px 24px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

@media print {
  .sidebar,
  .topbar,
  .tabsv-bar,
  .copiloto-config-panel,
  .copiloto-report-toolbar,
  .copiloto-fab,
  .copiloto-drawer {
    display: none !important;
  }
  .app-main {
    display: block !important;
    padding: 0 !important;
    margin: 0 !important;
  }
  .copiloto-view-wrap {
    max-width: 100% !important;
    padding: 0 !important;
  }
  .copiloto-report-doc {
    box-shadow: none !important;
    border: none !important;
    padding: 0 !important;
  }
}

