/* Main layout and typography */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap');
body {
    margin: 0;
    font-family: 'Inter', system-ui, sans-serif;
    background: #f7f7f7;
    color: #333;
}
.container {
    max-width: 600px;
    margin: 3rem auto;
    background: #fff;
    padding: 2rem;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
section h2 {
    margin-top: 0;
    font-weight: 600;
    color: #222;
}
.form-group {
    margin-bottom: 1rem;
    display: flex;
    flex-direction: column;
}
label {
    margin-bottom: 0.25rem;
    font-weight: 500;
}
input[type='datetime-local'] {
    padding: 0.5rem;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 1rem;
    width: 100%;
}
.buttons {
    margin-top: 1rem;
    display: flex;
    gap: 1rem;
}
button {
    padding: 0.6rem 1.2rem;
    font-size: 1rem;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 500;
}
#okButton {
    background: #0070f3;
    color: #fff;
}
#okButton:disabled {
    background: #999;
    cursor: default;
}

/* File section styling */
#fileSection {
    margin-top: 1rem;
}

/* Detail overlay and sidebar */
#detailView {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #fff;
    z-index: 999;
    overflow: auto;
}
#backBtn {
    margin: 1rem;
}
#sessionSidebar {
    width: 200px;
    border-right: 1px solid #ccc;
    overflow: auto;
    padding: 1rem;
    list-style: none;
}
#sessionContent {
    flex: 1;
    padding: 1rem;
    overflow: auto;
}

/* Session list buttons */
#sessionSidebar button.session-btn {
    display: block;
    width: 100%;
    margin-bottom: 0.5rem;
}
#sessionSidebar button.session-btn.selected {
    background: #ddd;
}
/* Chat view styling */
.chat-container {
  /* clear floated buttons (summary/JSON toggles) to use full width */
  clear: both;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.bubble {
  max-width: 80%;
  padding: 0.75rem 1rem;
  border-radius: 1rem;
  line-height: 1.4;
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.bubble.user {
  background: #e3eefb;
  align-self: flex-start;
}
.bubble.assistant {
  background: #fff;
  border: 1px solid #ccc;
  align-self: flex-end;
}
/* Completed/"Read" bubbles: subtle highlight and colored border */
.bubble.assistant.read {
  background: #f0f9ff;
  border: 1px solid #0070f3;
}
/* Make images within bubbles responsive */
.bubble img {
  /* constrain images to a reasonable size */
  max-width: 1600px;
  max-height: 700px;
  width: auto;
  height: auto;
  border-radius: 8px;
  display: block;
}
/* Toggle button for JSON view */
.toggle-json-btn {
  float: right;
  margin: 0.6rem;
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  background: #0070f3;
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}
.toggle-json-btn:hover {
  opacity: 0.9;
}
/* Session summary block styling */
.session-summary {
  margin: 0.5rem 0;
  padding: 1rem;
  background: #fafafa;
  border: 1px solid #ddd;
  border-radius: 4px;
}
/* "IN only" checkbox next to back button */
.in-only-checkbox {
  font-size: 0.95rem;
  display: inline-flex;
  align-items: center;
  color: #333;
  cursor: pointer;
}
.in-only-checkbox input {
  margin-right: 0.25rem;
  cursor: pointer;
}
/* TTs count above chat bubbles */
.tts-count {
  /* match View JSON button style and align next to it */
  float: right;
  margin: 0.6rem;
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  background: #239568;
  color: #fff;
  border-radius: 4px;
}
/* Session number badge, same layout as TTs count but distinct color */
.session-num {
  float: right;
  margin: 0.6rem;
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  background: #666;
  color: #fff;
  border-radius: 4px;
}
/* Session ID banner shown at top of chat view */
/* Session ID banner shown at top of chat view */
.session-id-banner {
  /* auto-width box; alignment handled by wrapper */
  display: inline-block;
  margin: 0.6rem 0;
  padding: 0.5rem 1rem;
  background: #eaeaea;
  color: #333;
  font-family: monospace;
  font-size: 0.9rem;
  border-radius: 4px;
}
/* User ID banner same style as session ID, displayed above it */
.user-id-banner {
  display: inline-block;
  margin: 0.6rem 0;
  padding: 0.5rem 1rem;
  background: #e0f7fa;
  color: #333;
  font-family: monospace;
  font-size: 0.9rem;
  border-radius: 4px;
}

/* ===== DASHBOARD STYLES ===== */

/* Dashboard container */
#dashboard {
  max-width: 1400px;
  margin: 2rem auto;
  padding: 2rem;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

/* Dashboard header */
.dashboard-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
  padding-bottom: 1rem;
  border-bottom: 2px solid #f0f0f0;
}

.dashboard-header h1 {
  margin: 0;
  font-size: 2rem;
  font-weight: 600;
  color: #222;
}

.date-range-display {
  font-size: 0.95rem;
  color: #666;
  font-weight: 500;
}

/* Metrics grid */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.metric-card {
  background: linear-gradient(135deg, #0070f3 0%, #0051c7 100%);
  padding: 1.5rem;
  border-radius: 8px;
  text-align: center;
  color: #fff;
  box-shadow: 0 2px 4px rgba(0,112,243,0.2);
}

.metric-value {
  font-size: 2.5rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.metric-label {
  font-size: 0.9rem;
  opacity: 0.9;
  font-weight: 500;
}

/* Charts layout */
.charts-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

.charts-row .full-width {
  grid-column: 1 / -1;
}

.chart-card {
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  padding: 1.5rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.chart-card h3 {
  margin: 0 0 1rem 0;
  font-size: 1.1rem;
  font-weight: 600;
  color: #333;
}

.chart-content {
  min-height: 200px;
}

/* Bar chart styles */
.bar-item {
  display: grid;
  grid-template-columns: 60px 1fr 120px;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.75rem;
}

.bar-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: #666;
  word-break: break-word;
}

/* App chart specific - wider labels for app names */
#appChart .bar-item {
  grid-template-columns: 100px 1fr 120px;
}

#appChart .bar-label {
  font-size: 0.8rem;
}

.bar-wrapper {
  height: 24px;
  background: #f0f0f0;
  border-radius: 4px;
  overflow: hidden;
  position: relative;
}

.bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #0070f3 0%, #00a8ff 100%);
  transition: width 0.3s ease;
  border-radius: 4px;
}

.bar-value {
  font-size: 0.85rem;
  font-weight: 600;
  color: #333;
  text-align: right;
}

/* Time chart (hourly distribution) */
.time-chart {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  height: 200px;
  padding: 1rem 0;
  gap: 2px;
}

.time-bar-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  justify-content: flex-end;
  cursor: pointer;
}

.time-bar {
  width: 100%;
  background: linear-gradient(180deg, #0070f3 0%, #0051c7 100%);
  border-radius: 2px 2px 0 0;
  transition: opacity 0.2s;
  min-height: 2px;
}

.time-bar-wrapper:hover .time-bar {
  opacity: 0.8;
}

.time-label {
  font-size: 0.65rem;
  color: #999;
  margin-top: 0.25rem;
  min-height: 12px;
}

/* Engagement metrics */
.metric-item {
  margin-bottom: 1.5rem;
}

.metric-item-label {
  font-size: 0.9rem;
  font-weight: 600;
  color: #555;
  margin-bottom: 0.5rem;
}

.metric-item-value {
  font-size: 1.2rem;
  font-weight: 700;
  color: #0070f3;
  margin-top: 0.5rem;
}

.progress-bar {
  height: 24px;
  background: #f0f0f0;
  border-radius: 4px;
  overflow: hidden;
  margin: 0.5rem 0;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #239568 0%, #2ecc71 100%);
  transition: width 0.3s ease;
  border-radius: 4px;
}

/* Distribution items */
.dist-item {
  display: flex;
  justify-content: space-between;
  padding: 0.5rem 0;
  border-bottom: 1px solid #f0f0f0;
  font-size: 0.9rem;
}

.dist-item:last-child {
  border-bottom: none;
}

.dist-value {
  font-weight: 600;
  color: #0070f3;
}

/* Quality metrics */
.quality-item {
  display: flex;
  justify-content: space-between;
  padding: 0.75rem 0;
  border-bottom: 1px solid #f0f0f0;
  font-size: 0.95rem;
}

.quality-item:last-child {
  border-bottom: none;
}

.quality-label {
  color: #666;
  font-weight: 500;
}

.quality-value {
  font-weight: 700;
  color: #0070f3;
}

/* Dashboard actions */
.dashboard-actions {
  display: flex;
  gap: 1rem;
  justify-content: center;
  margin-top: 2rem;
  padding-top: 2rem;
  border-top: 2px solid #f0f0f0;
}

.action-btn {
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  background: #f0f0f0;
  color: #333;
}

.action-btn.primary {
  background: #0070f3;
  color: #fff;
}

.action-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.action-btn.primary:hover {
  background: #0051c7;
}

/* TTS Performance Styles */
.tts-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1rem;
}

.tts-metric-box {
  background: #f9f9f9;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  padding: 1.5rem 1rem;
  text-align: center;
  transition: all 0.2s;
}

.tts-metric-box:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.tts-metric-box#ttsUserImpactBox {
  cursor: pointer;
  position: relative;
}

.tts-metric-box#ttsUserImpactBox::after {
  content: '🔍';
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  font-size: 0.9rem;
  opacity: 0.5;
}

.tts-metric-box#ttsUserImpactBox:hover::after {
  opacity: 1;
}

.tts-metric-box.success {
  background: linear-gradient(135deg, #d4edda 0%, #c3e6cb 100%);
  border-color: #28a745;
}

.tts-metric-value {
  font-size: 2.5rem;
  font-weight: 700;
  color: #333;
  margin-bottom: 0.5rem;
}

.tts-metric-box.success .tts-metric-value {
  color: #28a745;
}

.tts-metric-label {
  font-size: 0.9rem;
  color: #666;
  font-weight: 500;
}

.tts-metric-sublabel {
  font-size: 0.75rem;
  color: #999;
  margin-top: 0.25rem;
}

/* AI Performance specific grid - 4 columns layout */
#aiPerformance .tts-summary-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
}

#aiPerformance .tts-metric-value {
  font-size: 1.8rem;
  word-break: break-word;
  overflow: hidden;
  text-overflow: ellipsis;
}

#aiPerformance .tts-metric-label {
  font-size: 0.85rem;
  line-height: 1.3;
}

/* Clickable metric box hover effect */
#aiPerformance .tts-metric-box.clickable:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
}

/* Responsive for AI grid */
@media (max-width: 1200px) {
  #aiPerformance .tts-summary-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 768px) {
  #aiPerformance .tts-summary-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  #aiPerformance .tts-metric-value {
    font-size: 1.5rem;
  }
}

/* AI Performance warning and error states */
#aiPerformance .tts-metric-box.warning {
  background: linear-gradient(135deg, #fff3cd 0%, #ffeaa7 100%);
  border-color: #ffc107;
}

#aiPerformance .tts-metric-box.warning .tts-metric-value {
  color: #856404;
}

#aiPerformance .tts-metric-box.error {
  background: linear-gradient(135deg, #f8d7da 0%, #f5c6cb 100%);
  border-color: #dc3545;
}

#aiPerformance .tts-metric-box.error .tts-metric-value {
  color: #dc3545;
}

.tts-failure-section {
  padding: 1rem;
  background: #fff3cd;
  border: 1px solid #ffc107;
  border-radius: 6px;
}

.tts-failure-label {
  font-size: 0.95rem;
  font-weight: 600;
  color: #856404;
  margin-bottom: 0.5rem;
}

.tts-failure-item {
  display: flex;
  justify-content: space-between;
  padding: 0.5rem 0;
  border-bottom: 1px solid #f0e5c1;
  font-size: 0.9rem;
}

.tts-failure-item:last-child {
  border-bottom: none;
}

.tts-failure-type {
  color: #666;
}

.tts-failure-count {
  font-weight: 700;
  color: #dc3545;
}

/* Modal Styles */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-content {
  background: #fff;
  border-radius: 12px;
  width: 90%;
  max-width: 700px;
  max-height: 80vh;
  overflow: hidden;
  box-shadow: 0 10px 40px rgba(0,0,0,0.3);
  animation: slideUp 0.3s;
}

@keyframes slideUp {
  from { transform: translateY(50px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.5rem;
  border-bottom: 2px solid #f0f0f0;
  background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
}

.modal-header h2 {
  margin: 0;
  font-size: 1.5rem;
  color: #333;
}

.modal-close {
  background: none;
  border: none;
  font-size: 2rem;
  color: #999;
  cursor: pointer;
  padding: 0;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all 0.2s;
}

.modal-close:hover {
  background: #f0f0f0;
  color: #333;
}

.modal-body {
  padding: 1.5rem;
  max-height: calc(80vh - 100px);
  overflow-y: auto;
}

.country-section {
  margin-bottom: 1.5rem;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  overflow: hidden;
}

.country-header {
  background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
  padding: 1rem;
  font-weight: 600;
  font-size: 1.1rem;
  color: #333;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.country-flag {
  font-size: 1.5rem;
  margin-right: 0.5rem;
}

.user-list {
  padding: 0;
  margin: 0;
}

.user-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem;
  border-bottom: 1px solid #f0f0f0;
  transition: background 0.2s;
}

.user-item:last-child {
  border-bottom: none;
}

.user-item:hover {
  background: #f8f9fa;
}

.user-id {
  font-family: monospace;
  color: #666;
  font-size: 0.9rem;
  font-weight: 600;
}

.user-detail {
  font-size: 0.8rem;
  color: #999;
  margin-top: 0.25rem;
}

.failure-badge {
  background: #dc3545;
  color: #fff;
  padding: 0.3rem 0.8rem;
  border-radius: 20px;
  font-weight: 600;
  font-size: 0.85rem;
}

.user-item .failure-badge {
  background: #28a745;
}

/* Failed Text Items Styles */
.failed-text-item {
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 1rem;
  background: #f9f9f9;
  transition: all 0.2s;
}

.failed-text-item:hover {
  background: #fff;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.failed-text-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}

.failed-text-number {
  background: #dc3545;
  color: #fff;
  padding: 0.25rem 0.6rem;
  border-radius: 4px;
  font-weight: 600;
  font-size: 0.85rem;
}

.failed-text-date {
  font-size: 0.8rem;
  color: #999;
}

.failed-text-content {
  padding: 0.75rem;
  background: #fff;
  border-left: 3px solid #dc3545;
  border-radius: 4px;
  margin-bottom: 0.75rem;
  font-family: 'Inter', sans-serif;
  color: #333;
  line-height: 1.5;
}

.failed-text-meta {
  display: flex;
  gap: 1rem;
  font-size: 0.8rem;
  color: #666;
}

.failed-text-meta span {
  font-family: monospace;
}

.tts-failure-item.clickable:hover {
  background: #f8f9fa;
  transform: translateX(2px);
}

/* Question Type Distribution */
.question-type-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.question-type-box {
  background: #fff;
  border-radius: 8px;
  padding: 1rem;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  transition: transform 0.2s, box-shadow 0.2s;
}

.question-type-box:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.question-type-label {
  font-size: 0.9rem;
  color: #666;
  font-weight: 500;
  margin-bottom: 0.5rem;
  text-transform: capitalize;
}

.question-type-value {
  font-size: 2rem;
  font-weight: 700;
  color: #333;
  margin-bottom: 0.25rem;
}

.question-type-percentage {
  font-size: 1rem;
  color: #999;
  font-weight: 500;
}

/* Responsive design */
@media (max-width: 768px) {
  #dashboard {
    padding: 1rem;
  }

  .dashboard-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }

  .metrics-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
  }

  .charts-row {
    grid-template-columns: 1fr;
  }

  .metric-value {
    font-size: 2rem;
  }

  .bar-item {
    grid-template-columns: 50px 1fr 100px;
  }

  #appChart .bar-item {
    grid-template-columns: 80px 1fr 100px;
  }

  .question-type-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .tts-summary-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .tts-metric-value {
    font-size: 2rem;
  }
}
