/* ============================================================================
   Rivi Analytics Response Styling
   ============================================================================ */

/* Analytics Content Container */
.rivi-analytics .analytics-content {
  padding: 15px;
  background: #f8f9fa;
  border-radius: 8px;
  margin-top: 10px;
  animation: rivi-fade-in 0.3s ease-out;
}

@keyframes rivi-fade-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Summary Section */
.rivi-analytics .analytics-summary {
  margin-bottom: 20px;
  padding: 15px;
  background: white;
  border-left: 4px solid #1f77b4;
  border-radius: 4px;
  overflow-x: auto;
}

/* Analytics Header (matches knowledge-header style) */
.rivi-analytics .analytics-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
  color: #1f77b4;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.rivi-analytics .analytics-header svg {
  width: 14px;
  height: 14px;
}

.rivi-analytics .analytics-summary p {
  margin: 0;
  color: #555;
  line-height: 1.6;
}

.rivi-analytics .analytics-summary .analytics-table {
  overflow-x: auto;
  display: block;
}

/* Number Card (for single metrics) */
.rivi-analytics .analytics-number-card {
  background: white;
  border-radius: 8px;
  padding: 20px;
  text-align: center;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  margin-bottom: 20px;
}

.rivi-analytics .analytics-number-card .metric-value {
  font-size: 36px;
  font-weight: bold;
  color: #1f77b4;
  margin: 10px 0;
}

.rivi-analytics .analytics-number-card .metric-label {
  font-size: 14px;
  color: #666;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Visualization Container */
.rivi-analytics .analytics-visualization {
  background: white;
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.rivi-analytics .analytics-visualization .analytics-header {
  margin-bottom: 15px;
}

/* amCharts Container */
.rivi-analytics .amchart {
  width: 100%;
  height: 300px;
  min-height: 250px;
  max-height: 400px;
}

/* Larger charts in maximized chat window */
.ai-chat.maximized .rivi-analytics .amchart {
  height: 400px;
  min-height: 350px;
}

/* Data Table */
.rivi-analytics .analytics-table-container {
  background: white;
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  overflow-x: auto;
}

.rivi-analytics .analytics-table-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 10px;
}

.rivi-analytics .copy-table-btn {
  background: none;
  border: 1px solid #dee2e6;
  border-radius: 4px;
  padding: 5px 12px;
  font-size: 12px;
  color: #6c757d;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.rivi-analytics .copy-table-btn:hover {
  background: #f8f9fa;
  color: #2c3e50;
}

.rivi-analytics .analytics-table {
  width: 100%;
  min-width: max-content;
  border-collapse: collapse;
  font-size: 13px;
}

.rivi-analytics .analytics-table thead {
  background: #f8f9fa;
  border-bottom: 2px solid #dee2e6;
}

.rivi-analytics .analytics-table th {
  padding: 12px 15px;
  text-align: left;
  font-weight: 600;
  color: #2c3e50;
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

.rivi-analytics .analytics-table tbody tr {
  border-bottom: 1px solid #dee2e6;
}

.rivi-analytics .analytics-table tbody tr:hover {
  background: #f8f9fa;
}

.rivi-analytics .analytics-table td {
  padding: 12px 15px;
  color: #555;
}

.rivi-analytics .analytics-table th.numeric,
.rivi-analytics .analytics-table td.numeric {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* SQL Query Display */
.rivi-analytics .analytics-sql {
  background: #2c3e50;
  border-radius: 8px;
  padding: 15px;
  margin-bottom: 20px;
  position: relative;
}

.rivi-analytics .analytics-sql pre {
  margin: 0;
  color: #ecf0f1;
  font-family: 'Courier New', Courier, monospace;
  font-size: 12px;
  overflow-x: auto;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.rivi-analytics .analytics-sql .sql-label {
  display: inline-block;
  background: #34495e;
  color: #ecf0f1;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
}

/* Follow-up Suggestions (pill chips) */
.rivi-analytics .analytics-suggestions {
  margin-top: 15px;
  padding: 0;
  background: transparent;
  border: none;
}

.rivi-analytics .analytics-suggestions .analytics-header {
  margin-bottom: 8px;
}

.rivi-analytics .analytics-suggestions ul {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.rivi-analytics .analytics-suggestions li {
  display: inline-block;
  padding: 6px 12px;
  background: white;
  border: 1px solid #dee2e6;
  border-radius: 16px;
  font-size: 12px;
  color: #495057;
  cursor: pointer;
  transition: all 0.2s;
}

.rivi-analytics .analytics-suggestions li:before {
  content: none;
}

.rivi-analytics .analytics-suggestions li:hover {
  background: #e8f4fd;
  border-color: #1f77b4;
  color: #1f77b4;
  text-decoration: none;
}

/* Metadata Footer */
.rivi-analytics .analytics-metadata {
  padding: 10px 15px;
  background: #f8f9fa;
  border-radius: 4px;
  font-size: 11px;
  color: #6c757d;
  margin-top: 15px;
}

.rivi-analytics .analytics-metadata .metadata-item {
  display: inline-block;
  margin-right: 15px;
}

.rivi-analytics .analytics-metadata .metadata-label {
  font-weight: 600;
  margin-right: 5px;
}

/* Loading State */
.rivi-analytics .analytics-loading {
  text-align: center;
  padding: 40px 20px;
}

.rivi-analytics .analytics-loading .spinner {
  border: 3px solid #f3f3f3;
  border-top: 3px solid #1f77b4;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  animation: rivi-analytics-spin 1s linear infinite;
  margin: 0 auto 15px;
}

@keyframes rivi-analytics-spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Error State */
.rivi-analytics .analytics-error {
  background: #f8d7da;
  border-left: 4px solid #dc3545;
  border-radius: 4px;
  padding: 15px;
  color: #721c24;
}

.rivi-analytics .analytics-error h5 {
  margin: 0 0 10px 0;
  font-size: 14px;
  font-weight: 600;
}

.rivi-analytics .analytics-error p {
  margin: 0;
  font-size: 13px;
}

/* Responsive Design */
@media (max-width: 768px) {
  .rivi-analytics .analytics-content {
    padding: 10px;
  }

  .rivi-analytics .analytics-number-card .metric-value {
    font-size: 28px;
  }

  .rivi-analytics .amchart {
    height: 250px;
    min-height: 200px;
  }

  .rivi-analytics .analytics-table-container {
    padding: 10px;
  }

  .rivi-analytics .analytics-table {
    font-size: 12px;
  }

  .rivi-analytics .analytics-table th,
  .rivi-analytics .analytics-table td {
    padding: 8px 10px;
  }

  .rivi-analytics .analytics-suggestions {
    padding: 10px;
  }
}

/* Integration with existing .qna div */
.rivi-analytics .qna .analytics-content {
  margin: 0;
}

.rivi-analytics .qna .analytics-content:first-child {
  margin-top: 0;
}

/* ==============================================================================
   RIVI KNOWLEDGE SEARCH STYLES
   ============================================================================ */

/* Knowledge Search Content Container */
.rivi-analytics .knowledge-search-content {
  padding: 15px;
  background: #f8f9fa;
  border-radius: 8px;
  margin-bottom: 15px;
  animation: rivi-fade-in 0.3s ease-out;
}

/* Knowledge Base Header */
.rivi-analytics .knowledge-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
  color: #28a745;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.rivi-analytics .knowledge-header svg {
  width: 14px;
  height: 14px;
}

/* Main Answer Section */
.rivi-analytics .knowledge-answer {
  margin-bottom: 15px;
  padding: 15px;
  background: white;
  border-left: 4px solid #28a745;
  border-radius: 4px;
}

.rivi-analytics .knowledge-answer p {
  margin: 0 0 10px 0;
  color: #555;
  line-height: 1.6;
}

.rivi-analytics .knowledge-answer p:last-child {
  margin-bottom: 0;
}

.rivi-analytics .knowledge-answer strong {
  color: #2c3e50;
  font-weight: 600;
}

.rivi-analytics .knowledge-answer em {
  font-style: italic;
  color: #666;
}

/* Code blocks and inline code */
.rivi-analytics .knowledge-answer pre {
  background: #2c3e50;
  border-radius: 6px;
  padding: 12px;
  margin: 10px 0;
  overflow-x: auto;
}

.rivi-analytics .knowledge-answer pre code {
  color: #ecf0f1;
  font-family: 'Courier New', Courier, monospace;
  font-size: 12px;
  white-space: pre-wrap;
  background: none;
  padding: 0;
  border-radius: 0;
}

.rivi-analytics .knowledge-answer code {
  background: #f0f0f0;
  padding: 2px 5px;
  border-radius: 3px;
  font-family: 'Courier New', Courier, monospace;
  font-size: 12px;
  color: #c7254e;
}

/* Lists in knowledge answers */
.rivi-analytics .knowledge-answer ul,
.rivi-analytics .knowledge-answer ol {
  margin: 8px 0;
  padding-left: 20px;
}

.rivi-analytics .knowledge-answer li {
  margin-bottom: 4px;
  line-height: 1.5;
}

/* Headers in knowledge answers */
.rivi-analytics .knowledge-answer h4,
.rivi-analytics .knowledge-answer h5 {
  margin: 12px 0 6px 0;
  color: #2c3e50;
  font-weight: 600;
}

/* No Answer Found Section */
.rivi-analytics .knowledge-no-answer {
  padding: 15px;
  background: #fff3cd;
  border-left: 4px solid #ffc107;
  border-radius: 4px;
}

.rivi-analytics .knowledge-no-answer p {
  margin: 0;
  color: #856404;
  line-height: 1.6;
}

/* Sources Section */
.rivi-analytics .knowledge-sources {
  padding: 15px;
  background: white;
  border-radius: 4px;
  border-top: 1px solid #dee2e6;
}

.rivi-analytics .knowledge-sources h5 {
  margin: 0 0 10px 0;
  color: #2c3e50;
  font-size: 14px;
  font-weight: 600;
}

/* Source chips */
.rivi-analytics .knowledge-sources .source-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.rivi-analytics .knowledge-sources .source-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  background: #f0f7f0;
  border: 1px solid #c3e6c3;
  border-radius: 12px;
  font-size: 12px;
  color: #2d6a2d;
}

.rivi-analytics .knowledge-sources .source-chip svg {
  flex-shrink: 0;
}

/* Responsive Design */
@media (max-width: 768px) {
  .rivi-analytics .knowledge-search-content {
    padding: 10px;
  }

  .rivi-analytics .knowledge-answer,
  .rivi-analytics .knowledge-sources {
    padding: 10px;
  }
}

/* Integration with existing .qna div */
.rivi-analytics .qna .knowledge-search-content {
  margin: 0;
}

.rivi-analytics .qna .knowledge-search-content:first-child {
  margin-top: 0;
}

/* Action Cards (contact, task, email, SMS) */
.rivi-action-card {
  background: #ffffff;
  border: 1px solid #e9ecef;
  border-radius: 6px;
  margin: 6px 0;
  overflow: hidden;
}

.rivi-action-card-header {
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 600;
  color: #28a745;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid #e9ecef;
}

.rivi-action-card-body {
  padding: 10px 12px;
}

.rivi-action-card-error {
  border-color: #f5c6cb;
}

.rivi-action-card-header-error {
  color: #dc3545;
  border-bottom-color: #f5c6cb;
}

/* ==============================================================================
   RIVI VOICE INTEGRATION STYLES (Phase 5)
   ============================================================================ */

/* Voice Button */
.ai-chat #chat-with-ai-window .input-group .input-group-button .voice-btn {
  position: relative;
  cursor: pointer;
}
.ai-chat .voice-btn.connecting svg rect { fill: #FFF3E0; }
.ai-chat .voice-btn.connecting { animation: voice-pulse 1.5s infinite; }
.ai-chat .voice-btn.active svg rect { fill: #FFEBEE; }
.ai-chat .voice-btn.active svg path { fill: #E53935; }
.ai-chat .voice-btn.active { animation: voice-pulse 1s infinite; }
.ai-chat .voice-btn.ai-speaking svg rect { fill: #FFF3E0; }
.ai-chat .voice-btn.ai-speaking svg path { fill: #F15F27; }
.ai-chat .voice-btn.processing svg rect { fill: #EEEEEE; }
.ai-chat .voice-btn.processing svg path { fill: #9E9E9E; }
.ai-chat .voice-btn.unsupported { display: none; }

/* Voice Selector Dropdown */
.ai-chat .voice-selector {
  position: relative;
  display: flex;
  align-items: center;
  gap: 5px;
}
.ai-chat .voice-select-trigger {
  padding: 0;
  margin: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
}
.ai-chat .voice-select-trigger:hover { background: #E8E6E4; }
.ai-chat .voice-dropdown {
  position: absolute;
  bottom: 100%;
  left: 0;
  margin-bottom: 4px;
  background: #ffffff;
  border: 1px solid #d0cbc9;
  border-radius: 4px;
  box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.15);
  z-index: 10;
  min-width: 120px;
  padding: 4px 0;
}
.ai-chat .voice-dropdown a {
  display: block;
  padding: 6px 12px;
  cursor: pointer;
  color: #736d62;
  font-size: 13px;
  text-decoration: none;
  white-space: nowrap;
}
.ai-chat .voice-dropdown a:hover { background: #F4F3F2; }
.ai-chat .voice-dropdown a.selected { color: #F15F27; font-weight: 600; }

@keyframes voice-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* Voice Overlay */
.voice-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: #ffffff;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  border-radius: 8px;
}
.voice-indicator {
  text-align: center;
  padding: 20px;
}
.voice-indicator p {
  margin: 0 0 8px 0;
  font-size: 14px;
  color: #736d62;
}

/* Rivi logo in voice overlay */
.voice-rivi-logo {
  width: 48px;
  height: 48px;
  margin-bottom: 12px;
}
.voice-overlay.connecting .voice-rivi-logo {
  animation: voice-logo-pulse 1.5s ease-in-out infinite;
}
@keyframes voice-logo-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(0.95); }
}
.voice-overlay.connecting .voice-bars {
  display: none;
}

/* Voice Bars Animation */
.voice-bars {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  height: 40px;
  gap: 4px;
  margin-bottom: 16px;
}
.voice-bars span {
  width: 4px;
  background: #F15F27;
  border-radius: 2px;
  animation: voice-bar 0.6s ease-in-out infinite;
}
.voice-bars span:nth-child(1) { animation-delay: 0s; }
.voice-bars span:nth-child(2) { animation-delay: 0.1s; }
.voice-bars span:nth-child(3) { animation-delay: 0.2s; }
.voice-bars span:nth-child(4) { animation-delay: 0.3s; }
.voice-bars span:nth-child(5) { animation-delay: 0.4s; }

@keyframes voice-bar {
  0%, 100% { height: 8px; }
  50% { height: 32px; }
}

.voice-bars.paused span {
  animation: none;
  height: 4px;
}
.voice-bars.ai-speaking span {
  background: #F15F27;
  animation: voice-bar-ai 0.8s ease-in-out infinite;
}
@keyframes voice-bar-ai {
  0%, 100% { height: 6px; }
  50% { height: 24px; }
}

/* Voice Transcript Display */
.voice-transcript {
  font-size: 0.85em;
  color: #736d62;
  margin-top: 8px;
  max-height: 80px;
  overflow-y: auto;
  padding: 0 16px;
  line-height: 1.4;
}

/* Voice Stop Button */
.voice-indicator .button.alert {
  margin-top: 12px;
}