/* GenAI Chat - minimal styling (Module 1)
   No external CDNs or frameworks. */

*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #d6d9de;
  --text: #1f2329;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --error: #b91c1c;
  --user-bubble: #e8f0fe;
  --model-bubble: #f1f3f5;
  --radius: 8px;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.chat-app {
  max-width: 760px;
  margin: 0 auto;
  padding: 1.5rem 1rem;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.chat-header h1 {
  margin: 0 0 0.25rem;
  font-size: 1.5rem;
}

.chat-subtitle {
  margin: 0 0 1rem;
  color: var(--muted);
  font-size: 0.95rem;
}

/* Scrollable response display area */
.response-area {
  flex: 1 1 auto;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
  min-height: 200px;
}

.response-area:empty::before {
  content: "Responses will appear here.";
  color: var(--muted);
}

/* Message bubbles rendered by app.js */
.message {
  margin: 0 0 0.75rem;
  padding: 0.6rem 0.8rem;
  border-radius: var(--radius);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message:last-child {
  margin-bottom: 0;
}

.message--user {
  background: var(--user-bubble);
}

.message--model {
  background: var(--model-bubble);
}

/* Pending indicator */
.pending-indicator {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 0.75rem;
}

.pending-indicator[hidden] {
  display: none;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Composition form */
.chat-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.message-label {
  font-weight: 600;
  font-size: 0.9rem;
}

.message-input {
  width: 100%;
  resize: vertical;
  font: inherit;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}

.message-input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}

.form-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.char-counter {
  color: var(--muted);
  font-size: 0.8rem;
}

.send-button {
  font: inherit;
  font-weight: 600;
  padding: 0.55rem 1.25rem;
  color: #ffffff;
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
}

.send-button:hover:not(:disabled) {
  background: var(--accent-hover);
}

.send-button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Inline validation and error messages */
.validation-message,
.error-message {
  margin: 0;
  font-size: 0.85rem;
  color: var(--error);
}

.validation-message[hidden],
.error-message[hidden] {
  display: none;
}

/* ---- Login view ---- */
.login-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem 1rem;
}

.login-view[hidden],
.chat-app[hidden] {
  display: none;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.login-header h1 {
  margin: 0 0 0.25rem;
  font-size: 1.4rem;
}

.login-subtitle {
  margin: 0 0 1.25rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.login-label {
  font-weight: 600;
  font-size: 0.85rem;
}

.login-input {
  width: 100%;
  font: inherit;
  padding: 0.55rem 0.7rem;
  margin-bottom: 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}

.login-input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}

.login-button {
  font: inherit;
  font-weight: 600;
  margin-top: 0.25rem;
  padding: 0.6rem 1.25rem;
  color: #ffffff;
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
}

.login-button:hover:not(:disabled) {
  background: var(--accent-hover);
}

.login-button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.login-error {
  margin: 0.75rem 0 0;
  font-size: 0.85rem;
  color: var(--error);
}

.login-error[hidden] {
  display: none;
}

/* ---- Chat header / sign-out ---- */
.chat-header {
  position: relative;
}

.logout-button {
  position: absolute;
  top: 0;
  right: 0;
  font: inherit;
  font-size: 0.85rem;
  padding: 0.35rem 0.8rem;
  color: var(--accent);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
}

.logout-button:hover {
  background: var(--model-bubble);
}

/* ---- Module 2: model selector + performance metrics ---- */

.model-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem 0.75rem;
  margin-bottom: 0.75rem;
}

.model-label {
  font-weight: 600;
  font-size: 0.9rem;
}

.model-select {
  font: inherit;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}

.model-select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}

.model-select:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.selected-model-id {
  color: var(--muted);
  font-size: 0.8rem;
}

.selected-model-id[hidden] {
  display: none;
}

.model-error {
  margin: 0 0 0.75rem;
  font-size: 0.85rem;
  color: var(--error);
}

.model-error[hidden] {
  display: none;
}

/* ---- Module 4 (L200): Document_Upload bar ---- */

.document-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem 0.75rem;
  margin-bottom: 0.75rem;
}

.document-label {
  font-weight: 600;
  font-size: 0.9rem;
}

.document-input {
  font: inherit;
  font-size: 0.85rem;
}

.document-input:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.document-upload-button {
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.4rem 0.9rem;
  color: #ffffff;
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
}

.document-upload-button:hover:not(:disabled) {
  background: var(--accent-hover);
}

.document-upload-button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Readiness badge: shown only after a successful upload (R2.3). */
.document-status {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: #166534;
  background: #dcfce7;
  border: 1px solid #86efac;
  border-radius: var(--radius);
  padding: 0.2rem 0.6rem;
}

.document-status[hidden] {
  display: none;
}

.document-error {
  margin: 0 0 0.75rem;
  font-size: 0.85rem;
  color: var(--error);
}

.document-error[hidden] {
  display: none;
}

/* ---- Module 4 (L250): cache UI (config-gated) ---- */

/* The whole panel is hidden unless caching is enabled in config (R13.4). */
.cache-panel {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-bottom: 0.75rem;
  padding: 0.7rem 0.8rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.cache-panel[hidden] {
  display: none;
}

/* Family_Toggle: Anthropic vs Nova (R10.3). */
.cache-family-toggle {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.4rem 0.6rem;
}

.cache-family-label {
  font-weight: 600;
  font-size: 0.85rem;
}

.cache-family-button {
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.3rem 0.85rem;
  color: var(--accent);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
}

.cache-family-button:hover:not(:disabled) {
  background: var(--model-bubble);
}

/* The active family's button is visually pressed (aria-pressed mirrors it). */
.cache-family-button--active {
  color: #ffffff;
  background: var(--accent);
  border-color: var(--accent);
}

.cache-family-button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Cumulative Cache_Metrics block reuses the .metrics / .metric-row styling. */
.cache-metrics-block {
  margin: 0;
}

/* Per-request Cache_Hit/Cache_Miss badge inside a metric row (R9.1). */
.cache-badge {
  display: inline-flex;
  align-items: center;
  font-weight: 600;
  font-size: 0.78rem;
  border-radius: var(--radius);
  padding: 0.05rem 0.5rem;
}

.cache-badge--hit {
  color: #166534;
  background: #dcfce7;
  border: 1px solid #86efac;
}

.cache-badge--miss {
  color: #92400e;
  background: #fef3c7;
  border: 1px solid #fcd34d;
}

.cache-badge--indeterminate {
  color: var(--muted);
  background: var(--model-bubble);
  border: 1px solid var(--border);
  font-style: italic;
}

/* Per-family comparison table: rows = metrics, columns = families (R10.6). */
.cache-comparison {
  overflow-x: auto;
}

.cache-comparison-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.8rem;
}

.cache-comparison-table th,
.cache-comparison-table td {
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.cache-comparison-corner,
.cache-comparison-family-head {
  background: var(--model-bubble);
  font-weight: 600;
}

.cache-comparison-metric-label {
  font-weight: 600;
  white-space: nowrap;
}

.cache-comparison-cell {
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

/* Per-response performance metrics block (rendered by app.js) */
.metrics {
  margin: 0 0 0.75rem;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 0.8rem;
  color: var(--muted);
}

.metric-row {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.1rem 0;
}

.metric-label {
  font-weight: 600;
}

.metric-value {
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

/* Explicit, non-numeric "unavailable" indicator (Requirements 8.3 / 8.4 / 9.4) */
.metric-unavailable {
  font-style: italic;
  color: var(--muted);
}

.metrics-none {
  margin: 0;
  font-style: italic;
}

/* ---- Module 2: Comparison_View (Requirement 11) ---- */

.comparison-app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem 1rem;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.comparison-app[hidden] {
  display: none;
}

/* View-switch navigation (chat <-> comparison) */
.view-nav {
  margin-top: 0.5rem;
}

.nav-button {
  font: inherit;
  font-size: 0.85rem;
  padding: 0.35rem 0.8rem;
  color: var(--accent);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  /* Anchors using .nav-button (deliverable doc links) match the buttons. */
  display: inline-block;
  text-decoration: none;
}

.nav-button:hover {
  background: var(--model-bubble);
}

.comparison-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

/* Multi-select of models (2-4) */
.comparison-models {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.6rem 0.8rem;
  margin: 0;
}

.comparison-legend {
  font-weight: 600;
  font-size: 0.9rem;
  padding: 0 0.25rem;
}

.comparison-model {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.9rem;
  cursor: pointer;
}

.comparison-model-checkbox {
  cursor: pointer;
}

/* Adjacent response panels, one per selected model (Requirement 11.3) */
.comparison-results {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
  align-items: start;
}

.comparison-panel {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.8rem;
  min-width: 0;
}

.comparison-panel--error {
  border-color: var(--error);
}

.comparison-panel-header {
  font-weight: 600;
  font-size: 0.95rem;
}

.comparison-panel-modelid {
  color: var(--muted);
  font-size: 0.75rem;
  overflow-wrap: anywhere;
}

.comparison-panel-status {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
  font-style: italic;
}

.comparison-reply {
  margin: 0;
}

.comparison-panel-error {
  margin: 0;
  color: var(--error);
  font-size: 0.85rem;
}

/* ---- Module 2: Metrics_Dashboard (Requirement 12) ---- */

.dashboard-app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem 1rem;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.dashboard-app[hidden] {
  display: none;
}

/* Empty-state shown when no metrics have been recorded yet (R12.3) */
.dashboard-empty {
  margin: 1rem 0 0;
  padding: 1rem;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  font-style: italic;
}

.dashboard-empty[hidden] {
  display: none;
}

/* Aligned-by-metric table: rows = metrics, columns = models (R12.2) */
.dashboard-table-container {
  margin-top: 1rem;
  overflow-x: auto;
}

.dashboard-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.85rem;
}

.dashboard-table th,
.dashboard-table td {
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.dashboard-corner,
.dashboard-model-head {
  background: var(--model-bubble);
  font-weight: 600;
}

.dashboard-model-head {
  overflow-wrap: anywhere;
}

.dashboard-metric-label {
  font-weight: 600;
  white-space: nowrap;
}

.dashboard-metric-value {
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

/* ---- Module 2: Evaluation view (L250, Requirement 14) ---- */

.evaluation-app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem 1rem;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.evaluation-app[hidden] {
  display: none;
}

/* Run-trigger status (POST /api/evaluation/run accepted). */
.evaluation-run-status {
  margin: 1rem 0 0;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.9rem;
}

.evaluation-run-status[hidden] {
  display: none;
}

/* Empty-state shown when no evaluation has been run yet (report: null). */
.evaluation-empty {
  margin: 1rem 0 0;
  padding: 1rem;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  font-style: italic;
}

.evaluation-empty[hidden] {
  display: none;
}

/* Report metadata header (run date, judge model, scale note). */
.evaluation-meta:empty {
  display: none;
}

.evaluation-meta-list {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.15rem 0.75rem;
  margin: 1rem 0 0.25rem;
  font-size: 0.85rem;
}

.evaluation-meta-list dt {
  font-weight: 600;
  color: var(--muted);
}

.evaluation-meta-list dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.evaluation-scale-note {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.8rem;
  font-style: italic;
}

.evaluation-section-heading {
  margin: 1.25rem 0 0.5rem;
  font-size: 1.05rem;
}

/* Aligned tables: rows = metrics, columns = models (R14.2). */
.evaluation-results {
  margin-top: 0.5rem;
  overflow-x: auto;
}

.evaluation-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

.evaluation-table th,
.evaluation-table td {
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.evaluation-corner,
.evaluation-model-head {
  background: var(--model-bubble);
  font-weight: 600;
}

.evaluation-model-head {
  overflow-wrap: anywhere;
}

.evaluation-metric-label {
  font-weight: 600;
  white-space: nowrap;
}

.evaluation-cell {
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

/* Quality rows get a subtle tint to separate them from performance rows. */
.evaluation-quality-row .evaluation-metric-label {
  color: var(--accent);
}

.evaluation-cell--failed {
  color: var(--error);
  font-weight: 600;
}

/* Per-test-case detail sections. */
.evaluation-case {
  margin-bottom: 1.25rem;
}

.evaluation-case-heading {
  margin: 0 0 0.25rem;
  font-size: 0.95rem;
}

.evaluation-case-prompt {
  margin: 0 0 0.5rem;
  color: var(--muted);
  font-size: 0.85rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
