/* ══════════════════════════════════════════════════════════════
   CBL Copilot — Assistente IA Unificado
   FAB + Painel com 3 abas: Chat, Guia, Tour
   ══════════════════════════════════════════════════════════════ */

/* ── FAB ──────────────────────────────────────────────────── */
.cpl-fab {
  position: fixed; bottom: 24px; right: 24px;
  width: 52px; height: 52px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent, #1d6ce0), var(--gold, #d97706));
  color: #fff; border: none; cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,0,0,.25);
  z-index: 9000;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
  transition: transform .2s, box-shadow .2s;
}
.cpl-fab:hover { transform: scale(1.08); box-shadow: 0 6px 24px rgba(0,0,0,.35); }
.cpl-fab.open { transform: rotate(45deg); }
body.embedded .cpl-fab { display: none; }

/* Esconder FAB e painel enquanto a tela de login estiver visível */
body:has(#login-screen:not([style*="display: none"]):not([style*="display:none"])) .cpl-fab,
body:has(#login-screen:not([style*="display: none"]):not([style*="display:none"])) .cpl-panel { display: none !important; }

/* badge de notificação no FAB */
.cpl-fab-badge {
  position: absolute; top: -2px; right: -2px;
  width: 12px; height: 12px; border-radius: 50%;
  background: #ef4444; border: 2px solid var(--card-bg, #fff);
  display: none;
}

/* ── Painel principal ─────────────────────────────────────── */
.cpl-panel {
  display: none; position: fixed;
  bottom: 88px; right: 24px;
  width: 420px; max-width: calc(100vw - 48px);
  height: 560px; max-height: calc(100vh - 120px);
  background: var(--card-bg, #fff);
  border: 1px solid var(--card-border, #e5e7eb);
  border-radius: 16px;
  box-shadow: 0 8px 40px rgba(0,0,0,.2);
  z-index: 9001;
  flex-direction: column;
  overflow: hidden;
  animation: cplSlideUp .25s ease;
}
.cpl-panel.open { display: flex; }
@keyframes cplSlideUp {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Header ───────────────────────────────────────────────── */
.cpl-header {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px;
  background: linear-gradient(135deg, var(--accent, #1d6ce0), var(--gold, #d97706));
  color: #fff;
  border-radius: 16px 16px 0 0;
  flex-shrink: 0;
}
.cpl-header-info { flex: 1; }
.cpl-header-title { font-size: 14px; font-weight: 700; }
.cpl-header-sub { font-size: 10px; opacity: .8; }
.cpl-hbtn {
  background: none; border: none; color: #fff;
  cursor: pointer; font-size: 16px;
  padding: 4px 6px; border-radius: 6px; opacity: .8;
}
.cpl-hbtn:hover { opacity: 1; background: rgba(255,255,255,.15); }

/* ── Tabs ─────────────────────────────────────────────────── */
.cpl-tabs {
  display: flex; border-bottom: 1px solid var(--card-border, #e5e7eb);
  flex-shrink: 0;
}
.cpl-tab {
  flex: 1; padding: 8px 0; text-align: center;
  font-size: 12px; font-weight: 600;
  color: var(--text-muted, #9ca3af);
  background: none; border: none; cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all .15s;
  font-family: inherit;
}
.cpl-tab:hover { color: var(--text-primary, #1a1a1a); }
.cpl-tab.active {
  color: var(--accent, #1d6ce0);
  border-bottom-color: var(--accent, #1d6ce0);
}

/* ── Tab content ──────────────────────────────────────────── */
.cpl-tab-content { flex: 1; overflow: hidden; display: flex; flex-direction: column; }
.cpl-tab-pane { display: none; flex: 1; overflow: hidden; flex-direction: column; }
.cpl-tab-pane.active { display: flex; }

/* ── Chat ─────────────────────────────────────────────────── */
.cpl-messages {
  flex: 1; overflow-y: auto;
  padding: 16px; display: flex;
  flex-direction: column; gap: 10px;
}
.cpl-msg {
  max-width: 85%; padding: 10px 14px;
  border-radius: 12px; font-size: 13px;
  line-height: 1.55; word-break: break-word;
  animation: cplFadeUp .2s ease;
}
@keyframes cplFadeUp {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.cpl-msg.user {
  align-self: flex-end;
  background: var(--accent, #1d6ce0); color: #fff;
  border-bottom-right-radius: 4px;
}
.cpl-msg.assistant {
  align-self: flex-start;
  background: var(--page-bg, #f3f4f6);
  color: var(--text-primary, #1a1a1a);
  border: 1px solid var(--card-border, #e5e7eb);
  border-bottom-left-radius: 4px;
}
.cpl-msg.assistant strong { font-weight: 600; }
.cpl-msg.assistant code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  background: var(--card-bg, #e5e7eb);
  padding: 1px 4px; border-radius: 3px;
}
.cpl-msg.assistant pre {
  background: var(--sidebar-bg, #1a1d26);
  color: var(--text-primary, #e1e4ea);
  padding: 8px; border-radius: 6px;
  overflow-x: auto; font-size: 11px;
  margin: 6px 0;
  font-family: 'JetBrains Mono', monospace;
}
.cpl-msg.system {
  align-self: center; font-size: 11px;
  color: var(--text-muted, #9ca3af);
  font-style: italic; max-width: 100%;
}
.cpl-msg .cpl-meta {
  font-size: 9px; color: var(--text-muted, #9ca3af);
  margin-top: 4px;
}

/* typing indicator */
.cpl-typing {
  align-self: flex-start; padding: 10px 14px;
  font-size: 12px; color: var(--text-muted, #6b7280);
  display: none; align-items: center; gap: 6px;
}
.cpl-typing.show { display: flex; }
.cpl-dots { display: flex; gap: 3px; }
.cpl-dots span {
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--accent, #1d6ce0);
  animation: cplBlink 1.4s infinite both;
}
.cpl-dots span:nth-child(2) { animation-delay: .2s; }
.cpl-dots span:nth-child(3) { animation-delay: .4s; }
@keyframes cplBlink { 0%,80%,100% { opacity: .3; } 40% { opacity: 1; } }

/* welcome */
.cpl-welcome {
  text-align: center; padding: 24px 16px;
  color: var(--text-muted, #6b7280);
  font-size: 13px; line-height: 1.6;
}
.cpl-welcome-icon { font-size: 28px; margin-bottom: 8px; }
.cpl-welcome-name {
  font-weight: 600; color: var(--text-primary, #1a1a1a);
  font-size: 15px; margin-bottom: 4px;
}

/* suggestions */
.cpl-suggestions {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 10px 16px;
  border-top: 1px solid var(--card-border, #e5e7eb);
  flex-shrink: 0;
}
.cpl-sug {
  padding: 5px 12px; border-radius: 14px;
  font-size: 11px; border: 1px solid var(--card-border, #e5e7eb);
  background: none; cursor: pointer;
  color: var(--text-secondary, #6b7280);
  font-family: inherit; transition: all .15s;
}
.cpl-sug:hover {
  border-color: var(--accent, #1d6ce0);
  color: var(--accent, #1d6ce0);
  background: var(--accent-soft, #eef4fc);
}

/* input area */
.cpl-input-area {
  display: flex; gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--card-border, #e5e7eb);
  background: var(--card-bg, #fff);
  flex-shrink: 0;
}
.cpl-input-area input {
  flex: 1; padding: 8px 12px;
  border: 1px solid var(--input-border, #e5e7eb);
  border-radius: 8px; font-size: 13px;
  font-family: inherit;
  background: var(--input-bg, #fff);
  color: var(--text-primary, #1a1a1a);
  outline: none;
}
.cpl-input-area input:focus {
  border-color: var(--accent, #1d6ce0);
  box-shadow: 0 0 0 2px rgba(29,108,224,.1);
}
.cpl-input-area button {
  padding: 8px 14px; border-radius: 8px;
  background: var(--accent, #1d6ce0); color: #fff;
  border: none; cursor: pointer;
  font-family: inherit; font-size: 13px; font-weight: 600;
  transition: opacity .15s;
}
.cpl-input-area button:hover { opacity: .9; }
.cpl-input-area button:disabled { opacity: .4; cursor: default; }

/* ── Guia (aba docs) ──────────────────────────────────────── */
.cpl-guia {
  flex: 1; overflow-y: auto; padding: 16px;
  font-size: 13px; line-height: 1.6;
  color: var(--text-primary, #1a1a1a);
}
.cpl-guia-loading {
  text-align: center; padding: 32px;
  color: var(--text-muted, #9ca3af);
}
.cpl-guia-section {
  margin-bottom: 16px;
  border: 1px solid var(--card-border, #e5e7eb);
  border-radius: 10px; overflow: hidden;
}
.cpl-guia-section-header {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px; cursor: pointer;
  background: var(--page-bg, #f9fafb);
  font-weight: 600; font-size: 12px;
  color: var(--text-primary, #1a1a1a);
  border: none; width: 100%; text-align: left;
  font-family: inherit;
}
.cpl-guia-section-header:hover { background: var(--hover, #f3f4f6); }
.cpl-guia-section-header .cpl-chevron {
  margin-left: auto; transition: transform .2s;
  font-size: 10px; color: var(--text-muted, #9ca3af);
}
.cpl-guia-section.open .cpl-chevron { transform: rotate(90deg); }
.cpl-guia-section-body {
  display: none; padding: 12px 14px;
  font-size: 12px; line-height: 1.6;
}
.cpl-guia-section.open .cpl-guia-section-body { display: block; }
.cpl-guia-section-body ul { padding-left: 16px; margin: 4px 0; }
.cpl-guia-section-body li { margin-bottom: 4px; }
.cpl-guia-section-body table { width: 100%; border-collapse: collapse; font-size: 11px; margin: 6px 0; }
.cpl-guia-section-body th, .cpl-guia-section-body td {
  padding: 5px 8px; border: 1px solid var(--card-border, #e5e7eb); text-align: left;
}
.cpl-guia-section-body th { background: var(--page-bg, #f3f4f6); font-weight: 600; }

/* faq */
.cpl-faq-item { margin-bottom: 10px; }
.cpl-faq-q {
  font-weight: 600; font-size: 12px;
  color: var(--accent, #1d6ce0);
  cursor: pointer; padding: 4px 0;
}
.cpl-faq-a {
  display: none; font-size: 12px; padding: 4px 0 4px 12px;
  border-left: 2px solid var(--accent-soft, #eef4fc);
  color: var(--text-secondary, #6b7280);
}
.cpl-faq-item.open .cpl-faq-a { display: block; }

/* ── Tour (aba tour) ──────────────────────────────────────── */
.cpl-tour-list {
  flex: 1; overflow-y: auto; padding: 16px;
}
.cpl-tour-card {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; margin-bottom: 8px;
  border: 1px solid var(--card-border, #e5e7eb);
  border-radius: 10px; cursor: pointer;
  transition: all .15s;
}
.cpl-tour-card:hover {
  border-color: var(--accent, #1d6ce0);
  background: var(--accent-soft, #eef4fc);
}
.cpl-tour-card-icon { font-size: 20px; flex-shrink: 0; }
.cpl-tour-card-info { flex: 1; }
.cpl-tour-card-title { font-size: 13px; font-weight: 600; color: var(--text-primary, #1a1a1a); }
.cpl-tour-card-desc { font-size: 11px; color: var(--text-muted, #9ca3af); margin-top: 2px; }
.cpl-tour-card-badge {
  font-size: 10px; padding: 2px 8px;
  border-radius: 10px; font-weight: 600; flex-shrink: 0;
}
.cpl-tour-card-badge.done { background: #dcfce7; color: #16a34a; }
.cpl-tour-card-badge.pending { background: var(--accent-soft, #eef4fc); color: var(--accent, #1d6ce0); }

.cpl-tour-empty {
  text-align: center; padding: 32px;
  color: var(--text-muted, #9ca3af); font-size: 13px;
}

/* ── Highlight overlay (actions visuais) ──────────────────── */
.cpl-highlight-overlay {
  position: fixed; z-index: 8999;
  border: 2px solid var(--accent, #1d6ce0);
  border-radius: 6px;
  box-shadow: 0 0 0 4000px rgba(0,0,0,.25), 0 0 16px var(--accent, #1d6ce0);
  pointer-events: auto; cursor: pointer;
  animation: cplPulse 1.5s ease-in-out infinite;
  transition: all .3s;
}
.cpl-tooltip {
  position: fixed; z-index: 9002;
  background: var(--accent, #1d6ce0); color: #fff;
  padding: 6px 12px; border-radius: 6px;
  font-size: 11px; font-family: 'DM Sans', sans-serif;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
  pointer-events: none; max-width: 220px;
}
@keyframes cplPulse {
  0%,100% { box-shadow: 0 0 0 4000px rgba(0,0,0,.25), 0 0 8px var(--accent, #1d6ce0); }
  50%     { box-shadow: 0 0 0 4000px rgba(0,0,0,.25), 0 0 20px var(--accent, #1d6ce0); }
}

/* ── Provider badge ───────────────────────────────────────── */
.cpl-provider {
  display: inline-flex; align-items: center; gap: 3px;
  font-size: 9px; padding: 1px 5px;
  border-radius: 4px; font-weight: 600;
  margin-top: 4px;
}
.cpl-provider.gemini { background: #e8f5e9; color: #2e7d32; }
.cpl-provider.anthropic { background: #fce4ec; color: #c62828; }
.cpl-provider.cache { background: #fff3e0; color: #e65100; }

/* ── Tour tooltip ─────────────────────────────────────────── */
.cpl-tour-tooltip {
  position: fixed; z-index: 9003;
  background: var(--card-bg, #fff);
  border: 2px solid var(--accent, #1d6ce0);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,.2);
  padding: 16px 20px;
  max-width: 360px; min-width: 260px;
  font-family: 'DM Sans', sans-serif;
  animation: cplFadeUp .25s ease;
}
.cpl-tour-progress {
  font-size: 10px; font-weight: 700;
  color: var(--accent, #1d6ce0);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 6px;
}
.cpl-tour-title {
  font-size: 15px; font-weight: 700;
  color: var(--text-primary, #1a1a1a);
  margin-bottom: 6px;
}
.cpl-tour-text {
  font-size: 13px; line-height: 1.5;
  color: var(--text-secondary, #6b7280);
  margin-bottom: 14px;
}
.cpl-tour-buttons {
  display: flex; gap: 8px; justify-content: flex-end;
}
.cpl-tour-btn {
  padding: 6px 14px; border-radius: 6px;
  font-size: 12px; font-weight: 600;
  cursor: pointer; border: none;
  font-family: inherit; transition: all .15s;
}
.cpl-tour-btn.next {
  background: var(--accent, #1d6ce0); color: #fff;
}
.cpl-tour-btn.next:hover { opacity: .9; }
.cpl-tour-btn.prev {
  background: var(--page-bg, #f3f4f6);
  color: var(--text-primary, #1a1a1a);
  border: 1px solid var(--card-border, #e5e7eb);
}
.cpl-tour-btn.prev:hover { background: var(--hover, #e5e7eb); }
.cpl-tour-btn.skip {
  background: none; color: var(--text-muted, #9ca3af);
  border: none;
}
.cpl-tour-btn.skip:hover { color: var(--text-primary, #1a1a1a); }

/* ── Responsivo ───────────────────────────────────────────── */
@media (max-width: 600px) {
  .cpl-panel {
    right: 8px; bottom: 76px;
    width: calc(100vw - 16px);
    height: calc(100vh - 100px);
  }
  .cpl-fab { bottom: 16px; right: 16px; width: 48px; height: 48px; }
}
