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

:root {
  --bg: #0d1117;
  --bg-secondary: #161b22;
  --bg-tertiary: #21262d;
  --border: #30363d;
  --text: #c9d1d9;
  --text-secondary: #8b949e;
  --accent: #58a6ff;
  --accent-hover: #79c0ff;
  --green: #3fb950;
  --red: #f85149;
  --yellow: #d2991d;
  --radius: 8px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
}

nav .logo {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--accent);
  text-decoration: none;
}

nav .nav-links { display: flex; gap: 1rem; }
nav .nav-links a {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.9rem;
  transition: color 0.15s;
}
nav .nav-links a:hover { color: var(--text); }

main { max-width: 900px; margin: 0 auto; padding: 2rem 1.5rem; }

/* ─── Hero / Landing ─────────────────────────────────────── */

.hero {
  text-align: center;
  padding: 4rem 0;
}

.hero h1 {
  font-size: 2.5rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent), #a371f7);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 0.75rem;
}

.hero p {
  color: var(--text-secondary);
  font-size: 1.1rem;
  max-width: 500px;
  margin: 0 auto 2rem;
}

.hero-form {
  display: flex;
  gap: 0.5rem;
  max-width: 600px;
  margin: 0 auto;
}

.hero-form input {
  flex: 1;
  padding: 0.75rem 1rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 1rem;
  outline: none;
}

.hero-form input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.15);
}

.hero-form button {
  padding: 0.75rem 1.5rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.hero-form button:hover { background: var(--accent-hover); }
.hero-form button:disabled { opacity: 0.5; cursor: not-allowed; }

#hero-status {
  margin-top: 1rem;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

/* ─── Chat ────────────────────────────────────────────────── */

.chat-container { max-width: 700px; margin: 0 auto; }

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

.chat-message { display: flex; }
.chat-message.user { justify-content: flex-end; }
.chat-message.agent { justify-content: flex-start; }

.chat-bubble {
  max-width: 85%;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  font-size: 0.95rem;
  line-height: 1.5;
  word-wrap: break-word;
}

#status-bubble .chat-bubble {
  max-width: 95%;
}

#status-bubble .status-meta {
  margin-top: 0.3rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.chat-message.user .chat-bubble {
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 2px;
}

.chat-message.agent .chat-bubble {
  background: var(--bg-tertiary);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 2px;
}

.chat-message.agent .chat-bubble a {
  color: var(--accent);
}

.chat-bubble .step-icon { margin-right: 0.4rem; }

.spinner {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  vertical-align: middle;
  margin-right: 0.5rem;
}

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

/* ─── Dashboard ───────────────────────────────────────────── */

.dashboard-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: 1rem;
}

.dashboard-header h1 { font-size: 1.5rem; }

.dashboard-controls {
  display: flex;
  gap: 0.5rem;
}

.dashboard-controls input {
  padding: 0.5rem 0.75rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.9rem;
  width: 250px;
  outline: none;
}

.dashboard-controls input:focus { border-color: var(--accent); }

.dashboard-controls select {
  padding: 0.5rem 0.75rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
  cursor: pointer;
}

.report-list { display: flex; flex-direction: column; gap: 0.5rem; }

.report-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color 0.15s;
}

.report-item:hover { border-color: var(--accent); }

.report-item .report-info { flex: 1; min-width: 0; }
.report-item .report-question {
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.report-item .report-meta {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 0.2rem;
}

.report-item .report-score {
  font-weight: 700;
  margin-left: 1rem;
  white-space: nowrap;
}

.report-item .report-score.high { color: var(--green); }
.report-item .report-score.medium { color: var(--yellow); }
.report-item .report-score.low { color: var(--red); }

.report-item .report-actions {
  display: flex;
  gap: 0.5rem;
  margin-left: 1rem;
}

.report-item .report-actions button {
  padding: 0.3rem 0.6rem;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-secondary);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.15s;
}

.report-item .report-actions button:hover {
  border-color: var(--red);
  color: var(--red);
}

.report-item .phase-badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 10px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  margin-left: 0.5rem;
}

.phase-badge.running { background: rgba(88,166,255,0.15); color: var(--accent); }
.phase-badge.done { background: rgba(63,185,80,0.15); color: var(--green); }
.phase-badge.failed, .phase-badge.incomplete { background: rgba(248,81,73,0.15); color: var(--red); }

.loading { color: var(--text-secondary); text-align: center; padding: 2rem; }

.empty { color: var(--text-secondary); text-align: center; padding: 3rem; }

/* ─── Report viewer ───────────────────────────────────────── */

.report-viewer {
  max-width: 900px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
  color: var(--text);
}

.report-viewer h1 { font-size: 1.5rem; margin-bottom: 1rem; color: var(--accent); }
.report-viewer h2 { font-size: 1.2rem; margin: 1.5rem 0 0.75rem; border-bottom: 1px solid var(--border); padding-bottom: 0.25rem; color: var(--text); }
.report-viewer h3 { font-size: 1rem; margin: 1rem 0 0.5rem; color: var(--text); }
.report-viewer h4, .report-viewer h5, .report-viewer h6 { color: var(--text); }
.report-viewer p { margin-bottom: 0.75rem; color: var(--text); }
.report-viewer a { color: var(--accent); }
.report-viewer ul, .report-viewer ol { margin: 0.5rem 0 0.5rem 1.5rem; }
.report-viewer li { margin-bottom: 0.25rem; color: var(--text); }
.report-viewer strong, .report-viewer b { color: var(--text); font-weight: 700; }
.report-viewer em, .report-viewer i { color: var(--text); }
.report-viewer code { color: var(--accent); background: var(--bg-tertiary); padding: 0.1rem 0.3rem; border-radius: 3px; font-size: 0.85em; }
.report-viewer blockquote { border-left: 3px solid var(--accent); padding-left: 1rem; margin: 1rem 0; color: var(--text-secondary); }
.report-viewer table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
  font-size: 0.9rem;
}
.report-viewer th, .report-viewer td {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  text-align: left;
}
.report-viewer th { background: var(--bg-tertiary); font-weight: 600; }
.report-viewer hr { border: none; border-top: 1px solid var(--border); margin: 2rem 0; }

/* Rendered markdown (engine runs write report.md; the viewer renders it) */
.report-markdown > :first-child { margin-top: 0; }
.report-markdown pre {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  overflow-x: auto;
  margin: 1rem 0;
}
.report-markdown pre code { color: var(--text); background: none; padding: 0; font-size: 0.85rem; }
.report-markdown img { max-width: 100%; border-radius: var(--radius); }
.report-markdown sup.cite { line-height: 0; }
.report-markdown sup.cite a { color: var(--accent); text-decoration: none; font-size: 0.75em; }
.report-markdown sup.cite a:hover { text-decoration: underline; }
.report-markdown .source-num { color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.report-markdown li[id^="source-"] { margin-bottom: 0.35rem; scroll-margin-top: 1rem; }
.report-markdown li[id^="source-"]:target { background: var(--bg-tertiary); border-radius: var(--radius); }

/* ─── Passkey login ────────────────────────────────────────── */

.auth-page {
  display: grid;
  place-items: center;
  min-height: 100vh;
}

.auth-card {
  width: min(360px, 90vw);
  padding: 2.5rem 2rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-align: center;
}

.auth-logo { font-size: 1.4rem; margin-bottom: 0.5rem; color: var(--accent); }
.auth-sub { color: var(--text-secondary); margin-bottom: 1.5rem; }
.auth-hint { color: var(--text-secondary); font-size: 0.85rem; margin-bottom: 1rem; }
.auth-form input {
  width: 100%;
  padding: 0.6rem 0.75rem;
  margin-bottom: 0.75rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font: inherit;
}
.auth-form button, .auth-card > button {
  width: 100%;
  padding: 0.65rem;
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: var(--radius);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.auth-form button:hover, .auth-card > button:hover { background: var(--accent-hover); }
.auth-form button:disabled, .auth-card > button:disabled { opacity: 0.6; cursor: default; }
.auth-status { margin-top: 1rem; min-height: 1.2em; font-size: 0.85rem; color: var(--text-secondary); }
.auth-status.error { color: var(--red); }
.auth-status.ok { color: var(--green); }

.nav-signout button {
  background: none;
  border: none;
  color: var(--text-secondary);
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  padding: 0;
}
.nav-signout button:hover { color: var(--text); }

/* ─── Iteration Chat Panel ─────────────────────────────────── */

.iteration-panel {
  position: fixed;
  right: 0;
  top: 0;
  bottom: 0;
  width: 380px;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transform: translateX(100%);
  transition: transform 0.3s ease;
}

.iteration-panel.open {
  transform: translateX(0);
}

.iteration-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-tertiary);
}

.iteration-header h3 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
}

.iteration-close {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0.25rem;
}

.iteration-close:hover {
  color: var(--text);
}

.iteration-history {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.iteration-message {
  padding: 0.75rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  line-height: 1.5;
}

.iteration-message.user {
  background: rgba(88, 166, 255, 0.1);
  border: 1px solid rgba(88, 166, 255, 0.2);
  align-self: flex-end;
  max-width: 85%;
}

.iteration-message.system {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  align-self: flex-start;
  max-width: 85%;
}

.iteration-message.success {
  background: rgba(63, 185, 80, 0.1);
  border: 1px solid rgba(63, 185, 80, 0.2);
}

.iteration-message.error {
  background: rgba(248, 81, 73, 0.1);
  border: 1px solid rgba(248, 81, 73, 0.2);
}

.iteration-input-area {
  padding: 1rem;
  border-top: 1px solid var(--border);
  background: var(--bg-tertiary);
}

.iteration-input-wrapper {
  display: flex;
  gap: 0.5rem;
}

.iteration-input {
  flex: 1;
  padding: 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.9rem;
  resize: none;
  min-height: 44px;
  max-height: 120px;
  outline: none;
}

.iteration-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.15);
}

.iteration-submit {
  padding: 0.75rem 1rem;
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  color: #fff;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}

.iteration-submit:hover {
  background: var(--accent-hover);
}

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

.iteration-toggle {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  color: #fff;
  font-size: 1.5rem;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  transition: transform 0.2s, background 0.2s;
  z-index: 99;
  display: flex;
  align-items: center;
  justify-content: center;
}

.iteration-toggle:hover {
  background: var(--accent-hover);
  transform: scale(1.05);
}

.iteration-loading {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-secondary);
  font-size: 0.85rem;
}

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

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

/* Adjust main content when iteration panel is open */
body.iteration-open .report-viewer {
  margin-right: 380px;
  transition: margin-right 0.3s ease;
}

body.iteration-open .iteration-toggle {
  right: 396px;
}

/* Model picker (engine rebuild, 2026-07) */
.hero-model-row {
  display: flex;
  flex-wrap: wrap; /* the reading-assistant checkbox drops to its own line on phones */
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 0.75rem;
  font-size: 0.9rem;
}
.hero-model-row label { opacity: 0.7; }
.hero-model-row select {
  min-width: 0;
  padding: 0.35rem 0.6rem;
  border-radius: 6px;
  border: 1px solid var(--border, #ccc);
  background: var(--bg, #fff);
  color: inherit;
  font: inherit;
  max-width: 320px;
}
.hero-worker {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-left: 0.5rem;
  opacity: 0.85;
  cursor: pointer;
  white-space: nowrap;
}
.hero-worker[hidden] { display: none; }
.hero-worker input { margin: 0; }
.report-meta {
  opacity: 0.65;
  font-size: 0.85rem;
  margin: 0.5rem 0 1rem;
}
.report-markdown pre {
  white-space: pre-wrap;
  font-family: system-ui, sans-serif;
  line-height: 1.6;
  max-width: 900px;
}
