/* ============================================================================
   BIZANALYZER AI INSIGHTS - ENHANCED CHAT STYLES
   ============================================================================
   Add to: apps/css/bizanalyzer-ai.css
   Load after: bizanalyzer.css
   ============================================================================ */

/* --- Container Enhancement --- */
#biz-ai-chat-container {
  background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
  border: 1px solid var(--gray-200);
  border-radius: 12px;
  overflow: hidden;
}

/* --- Header Redesign --- */
.biz-ai-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.25rem;
  background: linear-gradient(135deg, #002855 0%, #003d7a 100%);
  color: #ffffff;
  border-bottom: none;
}

.biz-ai-header-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.biz-ai-icon {
  width: 40px;
  height: 40px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.875rem;
  backdrop-filter: blur(4px);
}

.biz-ai-title-group h3 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
  color: #ffffff;
}

.biz-ai-status {
  font-size: 0.75rem;
  opacity: 0.8;
  display: flex;
  align-items: center;
  gap: 0.375rem;
}

.biz-ai-status::before {
  content: '';
  width: 6px;
  height: 6px;
  background: #4ade80;
  border-radius: 50%;
  animation: pulse-dot 2s infinite;
}

.biz-ai-status.loading::before {
  background: #fbbf24;
  animation: pulse-dot 0.75s infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.8); }
}

/* --- Model Selector (Light on Dark) --- */
.biz-ai-model-selector {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.biz-ai-model-selector label {
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.7);
}

.biz-ai-model-selector select {
  padding: 0.375rem 0.625rem;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 6px;
  color: #ffffff;
  font-size: 0.8rem;
  cursor: pointer;
}

.biz-ai-model-selector select:focus {
  outline: none;
  border-color: rgba(255, 255, 255, 0.4);
  background: rgba(255, 255, 255, 0.15);
}

/* --- Context Panel (Compact Bar) --- */
.biz-ai-context-panel {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.625rem 1rem;
  background: var(--gray-50);
  border-bottom: 1px solid var(--gray-200);
}

.biz-ai-context-row {
  display: flex;
  gap: 1.5rem;
}

.biz-ai-context-field {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.biz-ai-context-field label {
  font-size: 0.75rem;
  color: var(--gray-600);
  font-weight: 500;
}

.biz-ai-context-field select {
  padding: 0.25rem 0.5rem;
  font-size: 0.8rem;
  border: 1px solid var(--gray-300);
  border-radius: 4px;
  background: #ffffff;
}

/* --- Messages Container --- */
#biz-ai-messages {
  height: 420px;
  overflow-y: auto;
  padding: 1rem;
  background: #ffffff;
  scroll-behavior: smooth;
}

/* --- Message Bubbles --- */
.biz-ai-message {
  margin-bottom: 1rem;
  max-width: 88%;
  animation: slideIn 0.25s ease-out;
}

@keyframes slideIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.biz-ai-user {
  margin-left: auto;
  background: linear-gradient(135deg, #002855 0%, #003d7a 100%);
  color: #ffffff;
  padding: 0.875rem 1rem;
  border-radius: 16px 16px 4px 16px;
}

.biz-ai-assistant {
  margin-right: auto;
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  padding: 1rem 1.125rem;
  border-radius: 16px 16px 16px 4px;
  color: var(--gray-800);
}

/* --- Financial Data Highlighting --- */
.biz-ai-assistant .biz-currency {
  font-weight: 600;
  color: #059669;
  background: rgba(5, 150, 105, 0.08);
  padding: 0.125rem 0.375rem;
  border-radius: 4px;
}

.biz-ai-assistant .biz-currency.negative {
  color: #dc2626;
  background: rgba(220, 38, 38, 0.08);
}

.biz-ai-assistant .biz-percent-up {
  color: #059669;
}

.biz-ai-assistant .biz-percent-up::before {
  content: '\2191 ';  /* Up arrow */
}

.biz-ai-assistant .biz-percent-down {
  color: #dc2626;
}

.biz-ai-assistant .biz-percent-down::before {
  content: '\2193 ';  /* Down arrow */
}

/* --- Ratio Cards in Responses --- */
.biz-ai-ratio-inline {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.25rem 0.5rem;
  background: var(--gray-100);
  border-radius: 4px;
  font-size: 0.875rem;
  font-family: 'SF Mono', Monaco, monospace;
}

/* --- Loading State --- */
.biz-ai-message.biz-loading {
  background: var(--gray-100);
  border: 1px dashed var(--gray-300);
}

.biz-loading-dots {
  display: inline-flex;
  gap: 4px;
}

.biz-loading-dots span {
  width: 6px;
  height: 6px;
  background: var(--gray-400);
  border-radius: 50%;
  animation: bounce 1.4s infinite ease-in-out both;
}

.biz-loading-dots span:nth-child(1) { animation-delay: -0.32s; }
.biz-loading-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

/* --- Input Area --- */
.biz-ai-input-area {
  display: flex;
  gap: 0.75rem;
  padding: 1rem;
  border-top: 1px solid var(--gray-200);
  background: #ffffff;
}

#biz-ai-input {
  flex: 1;
  padding: 0.75rem 1rem;
  border: 1px solid var(--gray-300);
  border-radius: 24px;
  font-size: 0.9375rem;
  resize: none;
  min-height: 44px;
  max-height: 120px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

#biz-ai-input:focus {
  outline: none;
  border-color: #002855;
  box-shadow: 0 0 0 3px rgba(0, 40, 85, 0.1);
}

#biz-ai-send {
  padding: 0.75rem 1.5rem;
  background: #002855;
  color: #ffffff;
  border: none;
  border-radius: 24px;
  font-weight: 600;
  font-size: 0.9375rem;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

#biz-ai-send:hover:not(:disabled) {
  background: #003d7a;
}

#biz-ai-send:active:not(:disabled) {
  transform: scale(0.97);
}

#biz-ai-send:disabled {
  background: var(--gray-300);
  cursor: not-allowed;
}

/* --- Warning/Error States --- */
.biz-warning {
  background: #fef3c7;
  border: 1px solid #f59e0b;
  border-radius: 8px;
  padding: 0.875rem 1rem;
  color: #92400e;
}

.biz-error {
  background: #fee2e2;
  border: 1px solid #ef4444;
  border-radius: 8px;
  padding: 0.875rem 1rem;
  color: #991b1b;
}

.biz-info {
  background: #dbeafe;
  border: 1px solid #3b82f6;
  border-radius: 8px;
  padding: 0.875rem 1rem;
  color: #1e40af;
}

/* --- Quick Actions (Optional Enhancement) --- */
.biz-ai-quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--gray-100);
  background: var(--gray-50);
}

.biz-quick-action {
  padding: 0.375rem 0.75rem;
  background: #ffffff;
  border: 1px solid var(--gray-200);
  border-radius: 16px;
  font-size: 0.8rem;
  color: var(--gray-600);
  cursor: pointer;
  transition: all 0.15s;
}

.biz-quick-action:hover {
  border-color: #002855;
  color: #002855;
  background: rgba(0, 40, 85, 0.04);
}

/* --- Responsive --- */
@media (max-width: 768px) {
  .biz-ai-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }
  
  .biz-ai-model-selector {
    width: 100%;
  }
  
  .biz-ai-model-selector select {
    flex: 1;
  }
  
  .biz-ai-context-row {
    flex-direction: column;
    gap: 0.5rem;
    width: 100%;
  }
  
  #biz-ai-messages {
    height: 350px;
  }
}


/* ============================================================================
   SIDEBAR DATA CONTROLS - Compact Styling
   ============================================================================ */

/* Desktop sidebar controls - compact version */
.sidebar-data-controls {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--gray-200, #e5e7eb);
}

.sidebar-data-controls .sidebar-label {
  display: block;
  font-size: 0.625rem;
  font-weight: 600;
  color: var(--gray-500, #6b7280);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}

.sidebar-data-controls .sidebar-control {
  margin-bottom: 0.75rem;
}

.sidebar-data-controls .sidebar-control:last-child {
  margin-bottom: 0;
}

.sidebar-data-controls label {
  display: block;
  font-size: 0.6875rem;
  font-weight: 500;
  color: var(--gray-600, #4b5563);
  margin-bottom: 0.375rem;
}

/* Compact dropdown selects */
.sidebar-data-controls .control-select {
  width: 100%;
  padding: 0.375rem 0.5rem;
  background: #ffffff;
  border: 1px solid var(--gray-200, #e5e7eb);
  border-radius: 4px;
  color: var(--gray-700, #374151);
  font-size: 0.75rem;
  cursor: pointer;
}

.sidebar-data-controls .control-select:hover {
  border-color: var(--gray-300, #d1d5db);
}

.sidebar-data-controls .control-select:focus {
  outline: 2px solid var(--sds-navy, #002855);
  outline-offset: 1px;
}

/* Compact year pills */
.sidebar-data-controls .cdm-year-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin-bottom: 0.375rem;
}

.sidebar-data-controls .cdm-year-pills .year-pill {
  padding: 0.1875rem 0.375rem;
  font-size: 0.6875rem;
  background: var(--sds-navy, #002855);
  border-color: var(--sds-navy, #002855);
  color: #ffffff;
  border-radius: 10px;
}

.sidebar-data-controls .cdm-year-pills .year-pill .remove-btn {
  width: 12px;
  height: 12px;
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.6);
}

.sidebar-data-controls .cdm-year-pills .year-pill .remove-btn:hover {
  color: #ffffff;
}

/* Compact loading indicator */
.sidebar-data-controls .cdm-loading {
  font-size: 0.625rem;
  color: var(--gray-500, #6b7280);
  margin-top: 0.25rem;
}

/* ============================================================================
   AI CHAT CONTROLS ROW - Expand & Export Buttons
   v2.9.0
   ============================================================================ */

.biz-ai-controls-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 1rem;
  background: var(--gray-50);
  border-top: 1px solid var(--gray-100);
  border-bottom: 1px solid var(--gray-100);
}

.biz-ai-controls-left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.biz-ai-message-count {
  font-size: 0.75rem;
  color: var(--gray-500);
}

.biz-ai-controls-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.biz-ai-control-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.375rem 0.75rem;
  background: #ffffff;
  border: 1px solid var(--gray-300);
  border-radius: 6px;
  font-size: 0.8rem;
  color: var(--gray-700);
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.biz-ai-control-btn:hover {
  background: var(--gray-50);
  border-color: var(--gray-400);
  color: var(--gray-900);
}

.biz-ai-control-btn .btn-icon {
  font-size: 0.9rem;
}

.biz-ai-control-btn-export {
  background: #059669 !important;
  color: #ffffff !important;
  border-color: #059669 !important;
}

.biz-ai-control-btn-export:hover {
  background: #047857 !important;
  border-color: #047857 !important;
}

/* ============================================================================
   AI CHAT MODAL - Full Screen Popout
   ============================================================================ */

.biz-ai-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  z-index: 9998;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.biz-ai-modal-overlay.active {
  opacity: 1;
}

.biz-ai-modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.95);
  width: 90vw;
  max-width: 900px;
  height: 85vh;
  background: #ffffff;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.biz-ai-modal.active {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

/* Maximized (fullscreen) modal state */
.biz-ai-modal.maximized {
  width: 98vw;
  max-width: none;
  height: 96vh;
}

.biz-ai-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.25rem;
  background: linear-gradient(135deg, #002855 0%, #003d7a 100%);
  border-radius: 12px 12px 0 0;
  color: #ffffff;
}

.biz-ai-modal-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin: 0;
}

.biz-ai-modal-subtitle {
  font-size: 0.8rem;
  opacity: 0.8;
  margin: 0.25rem 0 0 0;
}

.biz-ai-modal-close {
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: #ffffff;
  font-size: 1.5rem;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.biz-ai-modal-close:hover {
  background: rgba(255, 255, 255, 0.2);
}

.biz-ai-modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  background: #f9fafb;
}

/* Messages in modal - larger and more readable */
.biz-ai-modal-body .biz-ai-message {
  max-width: 100%;
  margin-bottom: 1.25rem;
}

.biz-ai-modal-body .biz-ai-user {
  max-width: 85%;
  margin-left: auto;
}

.biz-ai-modal-body .biz-ai-assistant {
  max-width: 95%;
  font-size: 0.95rem;
  line-height: 1.7;
}

.biz-ai-modal-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.875rem 1.25rem;
  border-top: 1px solid var(--gray-200);
  background: #ffffff;
  border-radius: 0 0 12px 12px;
}

.biz-ai-modal-footer-left {
  font-size: 0.8rem;
  color: var(--gray-500);
}

.biz-ai-modal-footer-right {
  display: flex;
  gap: 0.5rem;
}

.biz-ai-modal-btn {
  padding: 0.5rem 1rem;
  background: #ffffff;
  border: 1px solid var(--gray-300);
  border-radius: 6px;
  font-size: 0.85rem;
  color: var(--gray-700);
  cursor: pointer;
  transition: all 0.15s;
}

.biz-ai-modal-btn:hover {
  background: var(--gray-50);
  border-color: var(--gray-400);
}

.biz-ai-modal-btn-export {
  background: #059669 !important;
  color: #ffffff !important;
  border-color: #059669 !important;
}

.biz-ai-modal-btn-export:hover {
  background: #047857 !important;
  border-color: #047857 !important;
}

.biz-ai-modal-btn-close {
  background: #fee2e2 !important;
  color: #dc2626 !important;
  border-color: #fca5a5 !important;
}

.biz-ai-modal-btn-close:hover {
  background: #dc2626 !important;
  color: #ffffff !important;
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .biz-ai-controls-row {
    flex-direction: column;
    gap: 0.5rem;
    align-items: stretch;
  }

  .biz-ai-controls-right {
    justify-content: flex-end;
  }

  .biz-ai-modal {
    width: 95vw;
    height: 90vh;
  }

  .biz-ai-control-btn {
    padding: 0.5rem 0.625rem;
    font-size: 0.75rem;
  }
}

