/* ==========================================================================
   COMPONENTS DESIGN SYSTEM
   Buttons, Badges, KPI Cards, Data Tables, Chat Bubbles, Modals
   ========================================================================== */

/* ==========================================================================
   BUTTONS
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.55rem 1.15rem;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all var(--transition-fast);
  text-decoration: none;
  white-space: nowrap;
}

.btn svg {
  width: 16px;
  height: 16px;
}

.btn-primary {
  background: linear-gradient(135deg, #00f59b 0%, #00d984 100%);
  color: #080c14;
  box-shadow: 0 2px 10px rgba(0, 245, 155, 0.3);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  color: #ffffff;
  box-shadow: 0 4px 16px rgba(0, 245, 155, 0.45);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--bg-card-inner);
  border-color: var(--border-subtle);
  color: var(--text-main);
}

.btn-secondary:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-medium);
  color: #ffffff;
}

.btn-outline {
  background: transparent;
  border-color: var(--border-medium);
  color: var(--text-main);
}

.btn-outline:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-subtle);
}

.btn-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.76rem;
  border-radius: var(--radius-sm);
}

.btn-sm svg {
  width: 14px;
  height: 14px;
}

/* ==========================================================================
   BADGES & PILLS
   ========================================================================== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.65rem;
  border-radius: var(--radius-full);
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.badge-success {
  background: var(--success-bg);
  color: var(--success);
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.badge-warning {
  background: var(--warning-bg);
  color: var(--warning);
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.badge-danger {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.badge-info {
  background: var(--info-bg);
  color: var(--info);
  border: 1px solid rgba(14, 165, 233, 0.3);
}

.badge-purple {
  background: rgba(139, 92, 246, 0.15);
  color: #a78bfa;
  border: 1px solid rgba(139, 92, 246, 0.3);
}

/* CHANNEL BADGES */
.channel-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.6rem;
  border-radius: var(--radius-sm);
  font-size: 0.74rem;
  font-weight: 600;
}

.channel-whatsapp {
  background: rgba(37, 211, 102, 0.12);
  color: #25d366;
  border: 1px solid rgba(37, 211, 102, 0.25);
}

.channel-webchat {
  background: rgba(6, 182, 212, 0.12);
  color: #06b6d4;
  border: 1px solid rgba(6, 182, 212, 0.25);
}

.channel-instagram {
  background: rgba(225, 48, 108, 0.12);
  color: #e1306c;
  border: 1px solid rgba(225, 48, 108, 0.25);
}

.channel-facebook {
  background: rgba(24, 119, 242, 0.12);
  color: #1877f2;
  border: 1px solid rgba(24, 119, 242, 0.25);
}

.channel-telegram {
  background: rgba(0, 136, 204, 0.12);
  color: #0088cc;
  border: 1px solid rgba(0, 136, 204, 0.25);
}

/* ==========================================================================
   KPI CARDS
   ========================================================================== */
.kpi-card {
  padding: 1.35rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 0.75rem;
  position: relative;
}

.kpi-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.kpi-title {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.kpi-icon-wrapper {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--primary-subtle);
  color: var(--primary);
  border: 1px solid rgba(0, 245, 155, 0.2);
}

.kpi-value-row {
  display: flex;
  align-items: baseline;
  gap: 0.65rem;
}

.kpi-value {
  font-size: 1.85rem;
  font-weight: 800;
  color: var(--text-main);
  letter-spacing: -0.03em;
  line-height: 1;
}

.kpi-delta {
  font-size: 0.76rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 0.15rem;
}

.kpi-delta.positive { color: var(--success); }
.kpi-delta.negative { color: var(--danger); }

.kpi-subtitle {
  font-size: 0.74rem;
  color: var(--text-dim);
}

/* ==========================================================================
   CHARTS CONTAINER
   ========================================================================== */
.chart-card {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.chart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chart-title-box {
  display: flex;
  flex-direction: column;
}

.chart-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-main);
}

.chart-subtitle {
  font-size: 0.76rem;
  color: var(--text-muted);
}

.chart-canvas-wrapper {
  position: relative;
  width: 100%;
  height: 280px;
}

/* ==========================================================================
   DATA TABLES
   ========================================================================== */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.82rem;
}

.data-table th {
  background: var(--bg-table-header);
  color: var(--text-muted);
  font-weight: 600;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border-subtle);
  text-transform: uppercase;
  font-size: 0.72rem;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

.data-table td {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-main);
  vertical-align: middle;
}

.data-table tr:hover td {
  background: var(--bg-card-hover);
}

/* ==========================================================================
   INTELLIGENCE & PRESCRIPTIONS CARDS
   ========================================================================== */
.alert-card {
  padding: 1.25rem 1.4rem;
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  position: relative;
  border-left: 4px solid var(--primary);
  background: var(--bg-card);
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition-fast);
}

.alert-card:hover {
  transform: translateY(-2px);
}

.alert-card.critico {
  border-left-color: var(--danger);
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.04) 0%, var(--bg-card) 100%);
}

.alert-card.alerta {
  border-left-color: var(--warning);
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.04) 0%, var(--bg-card) 100%);
}

.alert-card.sucesso {
  border-left-color: var(--success);
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.04) 0%, var(--bg-card) 100%);
}

.alert-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.alert-title {
  font-size: 0.96rem;
  font-weight: 700;
  color: var(--text-main);
}

.alert-content {
  font-size: 0.84rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.alert-content strong {
  color: var(--text-main);
}

.alert-prescricao {
  background: var(--bg-card-inner);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.75rem 1rem;
  font-size: 0.8rem;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.playbook-card {
  padding: 1.4rem;
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.playbook-card:hover {
  border-color: rgba(6, 182, 212, 0.4);
}

.playbook-script-box {
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 1rem;
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 0.83rem;
  color: var(--text-main);
  line-height: 1.6;
  position: relative;
}

/* ==========================================================================
   CONVERSATION AUDITOR DRAWER & CHAT BUBBLES
   ========================================================================== */
.drawer-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg-modal-overlay);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  justify-content: flex-end;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-base);
}

.drawer-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.drawer-panel {
  width: 90%;
  max-width: 1050px;
  height: 100%;
  background: var(--bg-app);
  border-left: 1px solid var(--border-medium);
  box-shadow: -10px 0 40px rgba(0, 0, 0, 0.7);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform var(--transition-base);
}

.drawer-overlay.open .drawer-panel {
  transform: translateX(0);
}

.drawer-header {
  padding: 1.25rem 1.75rem;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.drawer-body {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  overflow: hidden;
}

@media (max-width: 860px) {
  .drawer-body {
    grid-template-columns: 1fr;
    overflow-y: auto;
  }
}

.drawer-chat-pane {
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  background: var(--bg-app);
}

.chat-messages-container {
  flex: 1;
  min-height: 0;
  padding: 1.5rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.chat-bubble {
  max-width: 85%;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-lg);
  font-size: 0.84rem;
  line-height: 1.45;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  position: relative;
}

.chat-bubble.customer {
  align-self: flex-start;
  background: var(--bg-chat-customer);
  color: var(--text-main);
  border-bottom-left-radius: 4px;
}

.chat-bubble.agent {
  align-self: flex-end;
  background: var(--bg-chat-agent);
  color: #f8fafc;
  border: 1px solid var(--bg-chat-agent-border);
  border-bottom-right-radius: 4px;
}

.chat-bubble.bot {
  align-self: center;
  background: rgba(14, 165, 233, 0.12);
  color: #38bdf8;
  border: 1px solid rgba(14, 165, 233, 0.25);
  font-size: 0.78rem;
  text-align: center;
}

.bubble-sender {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-dim);
}

.chat-bubble.agent .bubble-sender {
  color: var(--primary);
}

.bubble-time {
  font-size: 0.68rem;
  color: rgba(255, 255, 255, 0.5);
  align-self: flex-end;
}

.drawer-payload-pane {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  overflow-y: auto;
  background: var(--bg-card-inner);
}

/* Modo Claro: Adaptação de alto contraste para o Chat */
body.light-theme .chat-bubble.customer {
  background: #ffffff;
  color: #0f172a;
  border: 1px solid #cbd5e1;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

body.light-theme .chat-bubble.customer .bubble-sender {
  color: #475569;
}

body.light-theme .chat-bubble.customer .bubble-time {
  color: #64748b;
}

body.light-theme .chat-bubble.agent {
  background: #059669;
  color: #ffffff;
  border: 1px solid #047857;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

body.light-theme .chat-bubble.agent .bubble-sender {
  color: #a7f3d0;
}

body.light-theme .chat-bubble.agent .bubble-time {
  color: rgba(255, 255, 255, 0.85);
}

body.light-theme .chat-bubble.bot {
  background: #e0f2fe;
  color: #0369a1;
  border: 1px solid #7dd3fc;
}

body.light-theme .chat-bubble.bot .bubble-sender {
  color: #0284c7;
}

body.light-theme .chat-bubble.bot .bubble-time {
  color: #0369a1;
}

/* ==========================================================================
   BREAKDOWN CARDS (ATENDIMENTOS E CONTATOS POR INTENÇÃO / ORIGEM)
   ========================================================================== */
.grid-breakdown-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.25rem;
}

@media (max-width: 860px) {
  .grid-breakdown-2 {
    grid-template-columns: 1fr;
  }
}

.breakdown-card {
  padding: 1.25rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.breakdown-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.breakdown-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(6, 182, 212, 0.14);
  color: var(--secondary);
}

.breakdown-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-main);
}

.breakdown-list {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  max-height: 280px;
  overflow-y: auto;
  padding-right: 4px;
}

.breakdown-row {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.breakdown-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.84rem;
}

.breakdown-name {
  color: var(--text-main);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 65%;
}

.breakdown-val-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.breakdown-count {
  font-weight: 700;
  color: var(--text-main);
}

.pct-pill {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.15rem 0.45rem;
  border-radius: var(--radius-full);
  background: rgba(59, 130, 246, 0.15);
  color: #60a5fa;
}

.breakdown-bar-bg {
  width: 100%;
  height: 5px;
  background: var(--border-subtle);
  border-radius: 99px;
  overflow: hidden;
}

.breakdown-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--secondary), var(--primary));
  border-radius: 99px;
  transition: width var(--transition-slow);
}

/* ==========================================================================
   MODAL DIALOGS
   ========================================================================== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg-modal-overlay);
  backdrop-filter: blur(6px);
  z-index: 1100;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-base);
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  width: 90%;
  max-width: 600px;
  background: var(--bg-card);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transform: scale(0.95);
  transition: transform var(--transition-base);
}

.modal-overlay.open .modal-card {
  transform: scale(1);
}

.modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-body {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  max-height: 70vh;
  overflow-y: auto;
}

.modal-footer {
  padding: 1rem 1.5rem;
  background: var(--bg-card-inner);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
}

/* TOAST NOTIFICATIONS */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.toast {
  padding: 0.85rem 1.25rem;
  border-radius: var(--radius-md);
  font-size: 0.82rem;
  font-weight: 500;
  background: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--border-medium);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  animation: fadeIn 0.25s ease;
}

.toast.success { border-color: var(--success); color: var(--success); }
.toast.error { border-color: var(--danger); color: var(--danger); }
.toast.info { border-color: var(--info); color: var(--info); }

/* SPINNERS & LOADERS */
.spinner-sm {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(0, 245, 155, 0.25);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
  display: inline-block;
  vertical-align: middle;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ==========================================================================
   LOGIN FLOATING WAVES & USER PROFILE WIDGET
   ========================================================================== */
.login-waves-wrapper {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 260px;
  overflow: hidden;
  pointer-events: none;
  z-index: 1;
}

.login-wave {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 200%;
  height: 100%;
}

.login-wave.wave-1 {
  animation: floatWave1 18s cubic-bezier(0.37, 0, 0.63, 1) infinite alternate;
}

.login-wave.wave-2 {
  animation: floatWave2 13s cubic-bezier(0.37, 0, 0.63, 1) infinite alternate;
}

@keyframes floatWave1 {
  0% { transform: translateX(0) scaleY(1); }
  50% { transform: translateX(-25%) scaleY(1.15); }
  100% { transform: translateX(-50%) scaleY(1); }
}

@keyframes floatWave2 {
  0% { transform: translateX(-50%) scaleY(1.1); }
  50% { transform: translateX(-25%) scaleY(0.9); }
  100% { transform: translateX(0) scaleY(1.1); }
}

.user-profile-widget {
  cursor: pointer;
  transition: transform var(--transition-fast), background var(--transition-fast);
  border-radius: var(--radius-md);
  padding: 0.4rem 0.5rem;
}

.user-profile-widget:hover {
  background: var(--bg-card-hover);
  transform: translateY(-1px);
}
