/* ==========================================================================
   GenAI Chat — Multi-Model Comparison Styles
   Extends Module 1 base styles with navigation, comparison, and dashboard views.
   ========================================================================== */

/* ---------- Reset & Base ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen,
    Ubuntu, Cantarell, sans-serif;
  background: #f5f7fa;
  color: #1a1a2e;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------- Header ---------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  background: #ffffff;
  border-bottom: 1px solid #e2e8f0;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-left,
.header-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.header-center {
  flex: 1;
  display: flex;
  justify-content: center;
}

.user-label {
  font-weight: 600;
  font-size: 0.875rem;
  color: #4a5568;
}

.model-selector {
  padding: 0.4rem 0.75rem;
  border: 1px solid #cbd5e0;
  border-radius: 6px;
  font-size: 0.875rem;
  background: #fff;
  cursor: pointer;
  min-width: 200px;
}

.model-selector:focus {
  outline: 2px solid #3182ce;
  outline-offset: 1px;
}

/* ---------- Buttons ---------- */
.btn {
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, opacity 0.15s ease;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: #3182ce;
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: #2b6cb0;
}

.btn-secondary {
  background: #edf2f7;
  color: #2d3748;
}

.btn-secondary:hover:not(:disabled) {
  background: #e2e8f0;
}

.btn-filter {
  background: #edf2f7;
  color: #4a5568;
  padding: 0.4rem 0.75rem;
  font-size: 0.8rem;
}

.btn-filter:hover:not(:disabled) {
  background: #e2e8f0;
}

.btn-filter.active {
  background: #3182ce;
  color: #fff;
}

/* ---------- Navigation Tabs ---------- */
.nav-tabs {
  display: flex;
  gap: 0;
  background: #ffffff;
  border-bottom: 2px solid #e2e8f0;
  padding: 0 1.5rem;
}

.nav-tab {
  padding: 0.75rem 1.5rem;
  border: none;
  background: transparent;
  font-size: 0.9rem;
  font-weight: 500;
  color: #718096;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.nav-tab:hover {
  color: #2d3748;
}

.nav-tab:focus-visible {
  outline: 2px solid #3182ce;
  outline-offset: -2px;
}

.nav-tab.active {
  color: #3182ce;
  border-bottom-color: #3182ce;
}

/* ---------- View Sections ---------- */
.view-section {
  display: none;
  flex: 1;
  flex-direction: column;
}

.view-section.active {
  display: flex;
}

/* ---------- Chat View ---------- */
.chat-container {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.5rem;
  max-width: 800px;
  width: 100%;
  margin: 0 auto;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.chat-footer {
  padding: 0.75rem 1.5rem;
  background: #ffffff;
  border-top: 1px solid #e2e8f0;
  max-width: 800px;
  width: 100%;
  margin: 0 auto;
}

.input-row {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
}

.prompt-input {
  flex: 1;
  padding: 0.6rem 0.75rem;
  border: 1px solid #cbd5e0;
  border-radius: 6px;
  font-size: 0.9rem;
  resize: vertical;
  font-family: inherit;
}

.prompt-input:focus {
  outline: 2px solid #3182ce;
  outline-offset: 1px;
}

.send-btn {
  align-self: flex-end;
}

.footer-status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.4rem;
  font-size: 0.8rem;
  color: #718096;
}

.session-total {
  font-size: 0.8rem;
}

.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid #e2e8f0;
  border-top-color: #3182ce;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

.spinner.hidden {
  display: none;
}

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

/* ---------- Metrics Badge ---------- */
.metrics-badge {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  margin-top: 0.4rem;
  padding: 0.35rem 0.5rem;
  font-size: 0.75rem;
  color: #718096;
  background: #f7fafc;
  border-radius: 4px;
  border: 1px solid #e2e8f0;
}

.metric-item {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  white-space: nowrap;
}

.metric-label {
  font-weight: 500;
  color: #4a5568;
}

.metric-value {
  color: #2d3748;
}

/* ---------- Comparison View ---------- */
.comparison-controls {
  padding: 1.5rem;
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
}

.comparison-controls h2 {
  margin: 0 0 0.25rem;
  font-size: 1.25rem;
}

.comparison-instructions {
  margin: 0 0 1rem;
  color: #718096;
  font-size: 0.875rem;
}

.comparison-model-selector {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.comparison-model-option {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.75rem;
  background: #edf2f7;
  border-radius: 6px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.15s ease;
}

.comparison-model-option:hover {
  background: #e2e8f0;
}

.comparison-model-option input[type="checkbox"] {
  accent-color: #3182ce;
}

.comparison-input-group {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
  margin-bottom: 0.75rem;
}

.comparison-prompt {
  flex: 1;
  padding: 0.6rem 0.75rem;
  border: 1px solid #cbd5e0;
  border-radius: 6px;
  font-size: 0.9rem;
  resize: vertical;
  font-family: inherit;
}

.comparison-prompt:focus {
  outline: 2px solid #3182ce;
  outline-offset: 1px;
}

.comparison-submit-btn {
  align-self: flex-end;
}

.comparison-error {
  color: #e53e3e;
  font-size: 0.85rem;
  margin: 0;
  min-height: 1.2em;
}

/* ---------- Comparison Results (side-by-side panels) ---------- */
.comparison-results {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 1rem;
  padding: 0 1.5rem 1.5rem;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

.comparison-panel {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.comparison-panel-heading {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: #2d3748;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid #e2e8f0;
}

.comparison-panel-response {
  font-size: 0.9rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  flex: 1;
}

.comparison-panel-metrics {
  margin-top: auto;
}

/* Error state for failed model panels */
.comparison-panel-error {
  border-color: #feb2b2;
  background: #fff5f5;
}

.comparison-panel-error .comparison-panel-heading {
  color: #c53030;
  border-bottom-color: #feb2b2;
}

.comparison-panel-error-message {
  color: #c53030;
  font-size: 0.85rem;
  font-style: italic;
}

/* ---------- Dashboard View ---------- */
.dashboard-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.5rem 1.5rem 1rem;
  max-width: 1100px;
  margin: 0 auto;
  width: 100%;
}

.dashboard-header h2 {
  margin: 0;
  font-size: 1.25rem;
}

.dashboard-filters {
  display: flex;
  gap: 0.4rem;
}

.dashboard-table-container {
  padding: 0 1.5rem 1.5rem;
  max-width: 1100px;
  margin: 0 auto;
  width: 100%;
  overflow-x: auto;
}

/* ---------- Dashboard Table ---------- */
.dashboard-table,
.metrics-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  background: #ffffff;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #e2e8f0;
}

.dashboard-table thead,
.metrics-table thead {
  background: #f7fafc;
}

.dashboard-table th,
.metrics-table th {
  padding: 0.75rem 1rem;
  text-align: left;
  font-weight: 600;
  color: #4a5568;
  border-bottom: 2px solid #e2e8f0;
  white-space: nowrap;
}

.dashboard-table td,
.metrics-table td {
  padding: 0.65rem 1rem;
  border-bottom: 1px solid #edf2f7;
  color: #2d3748;
}

.dashboard-table tbody tr:last-child td,
.metrics-table tbody tr:last-child td {
  border-bottom: none;
}

.dashboard-table tbody tr:hover,
.metrics-table tbody tr:hover {
  background: #f7fafc;
}

.metrics-empty-state {
  text-align: center;
  color: #a0aec0;
  padding: 2rem 1rem !important;
  font-style: italic;
}

/* ---------- Architecture Log (aside) ---------- */
.architecture-log {
  position: fixed;
  right: 0;
  top: 0;
  bottom: 0;
  width: 320px;
  background: #1a202c;
  color: #e2e8f0;
  padding: 1rem;
  overflow-y: auto;
  font-size: 0.75rem;
  z-index: 200;
  transform: translateX(100%);
  transition: transform 0.2s ease;
}

.architecture-log.visible {
  transform: translateX(0);
}

.architecture-log.hidden {
  display: none;
}

.architecture-log h3 {
  margin: 0 0 0.75rem;
  font-size: 0.9rem;
}

.architecture-log pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.7rem;
  line-height: 1.4;
}

/* ---------- Utility ---------- */
.hidden {
  display: none !important;
}

/* ---------- Responsive: Mobile (<768px) ---------- */
@media (max-width: 768px) {
  .app-header {
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
  }

  .header-center {
    order: 3;
    flex-basis: 100%;
    justify-content: flex-start;
  }

  .model-selector {
    width: 100%;
    min-width: unset;
  }

  .nav-tabs {
    padding: 0 0.75rem;
    overflow-x: auto;
  }

  .nav-tab {
    padding: 0.6rem 1rem;
    font-size: 0.85rem;
  }

  /* Comparison panels stack on mobile */
  .comparison-results {
    grid-template-columns: 1fr;
    padding: 0 1rem 1rem;
  }

  .comparison-controls {
    padding: 1rem;
  }

  .comparison-model-selector {
    flex-direction: column;
  }

  .comparison-input-group {
    flex-direction: column;
  }

  .comparison-submit-btn {
    align-self: stretch;
  }

  /* Dashboard adjustments */
  .dashboard-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 1rem;
  }

  .dashboard-table-container {
    padding: 0 1rem 1rem;
  }

  .chat-container {
    padding: 0.75rem 1rem;
  }

  .chat-footer {
    padding: 0.5rem 1rem;
  }
}
