:root {
  --purple-50: #faf5ff;
  --purple-100: #f3e8ff;
  --purple-200: #e9d5ff;
  --purple-300: #d8b4fe;
  --purple-500: #a855f7;
  --purple-600: #8b5cf6;
  --purple-700: #7c3aed;
  --purple-800: #6d28d9;

  --bg: #faf9fc;
  --surface: #ffffff;
  --surface-2: #f4f1f9;
  --border: #e6e1ee;
  --text: #1c1523;
  --text-muted: #6b6478;
  --text-faint: #a39dae;
  --shadow: 0 1px 2px rgba(76, 29, 149, 0.04), 0 8px 24px rgba(76, 29, 149, 0.06);
  --radius: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #120e1a;
    --surface: #1a1425;
    --surface-2: #221b30;
    --border: #2f2740;
    --text: #f1edf7;
    --text-muted: #a79cb8;
    --text-faint: #6f6480;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.2), 0 8px 24px rgba(0, 0, 0, 0.35);
  }
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 720px;
  margin: 0 auto;
  height: 100vh;
  /* dvh tracks the viewport as mobile browser chrome hides and reveals itself;
     with plain vh the composer sits under the address bar on iOS Safari. The
     vh line above stays as the fallback for browsers without dvh. */
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 0 20px;
}

.app-header {
  padding: 28px 4px 16px;
  flex-shrink: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.top-nav {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
  padding-top: 6px;
}

.nav-link {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-decoration: none;
  padding: 7px 12px;
  border-radius: 999px;
  transition: background 0.15s ease, color 0.15s ease;
}

.nav-link:hover {
  color: var(--text);
  background: var(--surface-2);
}

.nav-link.active {
  color: var(--purple-700);
  background: var(--purple-100);
}

@media (prefers-color-scheme: dark) {
  .nav-link.active {
    color: var(--purple-300);
    background: rgba(139, 92, 246, 0.14);
  }
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--purple-500), var(--purple-800));
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 4px 14px rgba(124, 58, 237, 0.35);
}

.brand-mark svg {
  width: 22px;
  height: 22px;
}

.brand-text h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand-text p {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--text-muted);
}

/* The header is a two-column layout (brand | nav) that a phone width cannot
   hold: the nav does not shrink, so the title ends up underneath the first
   pill and the last pill runs off-screen. Below 640px give each its own row
   and let the pills share the width evenly. */
@media (max-width: 640px) {
  .app {
    padding: 0 16px;
  }

  .app-header {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    padding: 18px 0 12px;
  }

  .top-nav {
    padding-top: 0;
    gap: 6px;
  }

  .nav-link {
    flex: 1;
    text-align: center;
    padding: 8px 10px;
  }

  .brand-text p {
    font-size: 12px;
    line-height: 1.4;
  }
}

/* Small phones (iPhone SE and similar): step the brand down so the title and
   the three pills each stay on one line. */
@media (max-width: 380px) {
  .brand {
    gap: 10px;
  }

  .brand-mark {
    width: 36px;
    height: 36px;
    border-radius: 10px;
  }

  .brand-mark svg {
    width: 19px;
    height: 19px;
  }

  .brand-text h1 {
    font-size: 18px;
  }

  .nav-link {
    font-size: 12px;
    padding: 8px 6px;
  }
}

.chat {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  padding-bottom: 12px;
}

.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  text-align: center;
  padding: 24px 0;
}

.empty-title {
  margin: 0;
  color: var(--text-muted);
  font-size: 15px;
}

.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  max-width: 480px;
}

.suggestion-chip {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 9px 14px;
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.1s ease, background 0.15s ease;
}

.suggestion-chip:hover {
  border-color: var(--purple-500);
  background: var(--purple-50);
  color: var(--purple-800);
}

@media (prefers-color-scheme: dark) {
  .suggestion-chip:hover {
    background: rgba(139, 92, 246, 0.12);
    color: var(--purple-300);
  }
}

.suggestion-chip:active {
  transform: scale(0.98);
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 8px 0;
}

.msg {
  max-width: 84%;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.msg.user {
  align-self: flex-end;
  align-items: flex-end;
}

.msg.agent {
  align-self: flex-start;
  align-items: flex-start;
}

.bubble {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 14.5px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.msg.user .bubble {
  background: linear-gradient(135deg, var(--purple-600), var(--purple-800));
  color: white;
  border-bottom-right-radius: 4px;
}

.msg.agent .bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  border-bottom-left-radius: 4px;
}

.bubble a {
  color: var(--purple-700);
  text-decoration: underline;
  text-decoration-color: var(--purple-300);
  text-underline-offset: 2px;
  font-weight: 500;
}

.bubble a:hover {
  color: var(--purple-800);
  text-decoration-color: var(--purple-700);
}

@media (prefers-color-scheme: dark) {
  .bubble a {
    color: var(--purple-300);
    text-decoration-color: var(--purple-600);
  }

  .bubble a:hover {
    color: var(--purple-200);
    text-decoration-color: var(--purple-300);
  }
}

.msg.agent .bubble.error {
  border-color: #f0b3b3;
  color: #a13939;
}

.tool-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 2px;
}

.tool-tag {
  font-size: 11.5px;
  color: var(--purple-700);
  background: var(--purple-100);
  border-radius: 999px;
  padding: 3px 9px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

@media (prefers-color-scheme: dark) {
  .tool-tag {
    color: var(--purple-300);
    background: rgba(139, 92, 246, 0.14);
  }
}

.typing {
  display: inline-flex;
  gap: 4px;
  padding: 4px 2px;
}

.typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--purple-500);
  animation: typing-bounce 1.1s infinite ease-in-out;
}

.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

.composer {
  flex-shrink: 0;
  display: flex;
  gap: 8px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow);
  margin-bottom: 6px;
}

.composer input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-size: 14.5px;
  color: var(--text);
  padding: 8px 10px;
  font-family: inherit;
}

.composer input::placeholder {
  color: var(--text-faint);
}

.composer button {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--purple-600), var(--purple-800));
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.1s ease, opacity 0.15s ease;
}

.composer button svg {
  width: 18px;
  height: 18px;
}

.composer button:hover {
  transform: scale(1.05);
}

.composer button:active {
  transform: scale(0.96);
}

.composer button:disabled {
  opacity: 0.5;
  cursor: default;
  transform: none;
}

.disclaimer {
  text-align: center;
  font-size: 11.5px;
  color: var(--text-faint);
  margin: 0 0 16px;
  flex-shrink: 0;
}

/* --- Backend / architecture page --- */

.arch-app {
  height: auto;
  min-height: 100vh;
  max-width: 840px;
}

.arch-main {
  padding-bottom: 48px;
}

.arch-section {
  margin-top: 36px;
}

.arch-section h2 {
  margin: 0 0 4px;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.arch-sub {
  margin: 0 0 16px;
  font-size: 13px;
  color: var(--text-muted);
}

.arch-sub code {
  background: var(--surface-2);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 12px;
}

.pipeline {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.pipe-node {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 14px 16px;
}

.pipe-node.accent {
  border-color: var(--purple-300);
}

@media (prefers-color-scheme: dark) {
  .pipe-node.accent {
    border-color: var(--purple-600);
  }
}

.pipe-title {
  font-size: 13.5px;
  font-weight: 700;
}

.pipe-detail {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
  line-height: 1.4;
}

.pipe-arrow {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--purple-500);
  font-size: 15px;
  flex-shrink: 0;
  transform: rotate(90deg);
  margin: 2px 0;
}

.tool-grid,
.ops-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
}

.tool-card,
.ops-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 14px 16px;
}

.tool-card-head {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  font-weight: 700;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.tool-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--purple-500);
  flex-shrink: 0;
}

.tool-target {
  margin: 6px 0 10px;
  font-size: 12.5px;
  color: var(--text-muted);
}

.tool-count {
  font-size: 12px;
  font-weight: 600;
  color: var(--purple-700);
}

@media (prefers-color-scheme: dark) {
  .tool-count {
    color: var(--purple-300);
  }
}

.ops-name {
  font-size: 13.5px;
  font-weight: 700;
  margin-bottom: 6px;
}

.ops-card p {
  margin: 0;
  font-size: 12.5px;
  color: var(--text-muted);
  line-height: 1.5;
}

.ops-card code {
  background: var(--surface-2);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 11.5px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 12px;
}

.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 16px;
  text-align: center;
}

.stat-value {
  font-size: 24px;
  font-weight: 800;
  color: var(--purple-700);
  letter-spacing: -0.02em;
}

@media (prefers-color-scheme: dark) {
  .stat-value {
    color: var(--purple-300);
  }
}

.stat-label {
  margin-top: 4px;
  font-size: 12px;
  color: var(--text-muted);
}

/* --- Stack section --- */

.stack-highlight {
  background: linear-gradient(135deg, var(--purple-50), var(--surface));
  border: 1px solid var(--purple-300);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 16px;
}

@media (prefers-color-scheme: dark) {
  .stack-highlight {
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.12), var(--surface));
    border-color: var(--purple-600);
  }
}

.stack-highlight-title {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--purple-800);
  margin-bottom: 10px;
}

@media (prefers-color-scheme: dark) {
  .stack-highlight-title {
    color: var(--purple-200);
  }
}

.stack-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.stack-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: white;
  background: linear-gradient(135deg, var(--purple-600), var(--purple-800));
  border-radius: 999px;
  padding: 6px 12px;
}

.badge-logo {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  border-radius: 4px;
  background: #ffffff;
  padding: 2px;
  object-fit: contain;
  display: block;
}

.stack-columns {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.stack-column {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 14px 16px;
}

.stack-column-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.stack-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.stack-list li {
  display: grid;
  grid-template-columns: 22px 1fr;
  column-gap: 10px;
  row-gap: 2px;
}

.stack-logo {
  grid-column: 1;
  grid-row: 1 / 3;
  align-self: start;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: #ffffff;
  border: 1px solid var(--border);
  padding: 3px;
  object-fit: contain;
  display: block;
}

.stack-name {
  grid-column: 2;
  grid-row: 1;
  font-size: 13px;
  font-weight: 700;
}

.stack-how {
  grid-column: 2;
  grid-row: 2;
  font-size: 11.5px;
  color: var(--text-muted);
  line-height: 1.4;
}

.stack-how code {
  background: var(--surface-2);
  border-radius: 4px;
  padding: 0 4px;
  font-size: 11px;
}

/* --- Red team page --- */

.redteam-main {
  padding-bottom: 48px;
}

.redteam-section {
  margin-top: 36px;
}

.redteam-section h2 {
  margin: 0 0 4px;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.redteam-sub {
  margin: 0 0 16px;
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
}

.redteam-sub code {
  background: var(--surface-2);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 12px;
}

.redteam-controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 14px 16px;
}

.redteam-controls label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
}

.redteam-controls input[type="number"] {
  width: 56px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface-2);
}

.run-btn {
  border: none;
  background: linear-gradient(135deg, var(--purple-600), var(--purple-800));
  color: white;
  font-size: 13px;
  font-weight: 700;
  padding: 9px 18px;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.1s ease, opacity 0.15s ease;
}

.run-btn:hover {
  transform: scale(1.03);
}

.run-btn:active {
  transform: scale(0.97);
}

.run-btn:disabled {
  opacity: 0.55;
  cursor: default;
  transform: none;
}

.run-status {
  font-size: 12.5px;
  color: var(--text-muted);
}

.run-status.running {
  color: var(--purple-700);
}

@media (prefers-color-scheme: dark) {
  .run-status.running {
    color: var(--purple-300);
  }
}

.persona-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.persona-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 14px 16px;
}

.persona-name {
  font-size: 13.5px;
  font-weight: 700;
  margin-bottom: 4px;
}

.persona-goal {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.45;
}

.report-picker {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}

.report-picker select {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 12.5px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface-2);
  max-width: 340px;
}

.report-summary {
  font-size: 12.5px;
  color: var(--text-muted);
}

.session-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 16px;
  margin-top: 14px;
}

.session-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.session-persona {
  font-size: 14px;
  font-weight: 700;
}

.session-goal {
  font-size: 12px;
  color: var(--text-muted);
  margin: 4px 0 12px;
  line-height: 1.45;
}

.issue-count-badge {
  font-size: 11.5px;
  font-weight: 700;
  border-radius: 999px;
  padding: 4px 10px;
  flex-shrink: 0;
}

.issue-count-badge.zero {
  color: var(--text-muted);
  background: var(--surface-2);
}

.issue-count-badge.some {
  color: #a13939;
  background: #fbe3e3;
}

@media (prefers-color-scheme: dark) {
  .issue-count-badge.some {
    color: #f3a9a9;
    background: rgba(220, 90, 90, 0.16);
  }
}

.issue {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  margin-bottom: 8px;
}

.issue-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}

.severity {
  font-size: 10.5px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border-radius: 999px;
  padding: 3px 8px;
}

.severity.high {
  color: #a13939;
  background: #fbe3e3;
}

.severity.medium {
  color: #92600e;
  background: #fdecc8;
}

.severity.low {
  color: var(--text-muted);
  background: var(--surface-2);
}

@media (prefers-color-scheme: dark) {
  .severity.high {
    color: #f3a9a9;
    background: rgba(220, 90, 90, 0.16);
  }

  .severity.medium {
    color: #f0c674;
    background: rgba(217, 160, 40, 0.16);
  }
}

.issue-category {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--purple-700);
}

@media (prefers-color-scheme: dark) {
  .issue-category {
    color: var(--purple-300);
  }
}

.issue-turn {
  font-size: 11px;
  color: var(--text-faint);
}

.issue-problem {
  font-size: 12.5px;
  line-height: 1.5;
  margin: 0 0 6px;
}

.issue-quote {
  font-size: 12px;
  color: var(--text-muted);
  border-left: 2px solid var(--purple-300);
  padding-left: 10px;
  font-style: italic;
  line-height: 1.5;
}

.no-issues {
  font-size: 12.5px;
  color: var(--text-muted);
}

.transcript-toggle {
  margin-top: 10px;
}

.transcript-toggle summary {
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  color: var(--purple-700);
}

@media (prefers-color-scheme: dark) {
  .transcript-toggle summary {
    color: var(--purple-300);
  }
}

.transcript-turn {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.transcript-turn:first-child {
  border-top: none;
  margin-top: 0;
  padding-top: 0;
}

.transcript-role {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-faint);
  margin-bottom: 3px;
}

.transcript-text {
  font-size: 12.5px;
  line-height: 1.55;
  white-space: pre-wrap;
}

.transcript-tools {
  font-size: 10.5px;
  color: var(--text-faint);
  margin-top: 2px;
}

.empty-reports {
  font-size: 13px;
  color: var(--text-muted);
  padding: 24px 0;
  text-align: center;
}

.fix-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 10px;
  font-size: 11.5px;
  color: var(--text-faint);
}

.fix-report-link {
  border: none;
  background: none;
  color: var(--purple-700);
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
}

@media (prefers-color-scheme: dark) {
  .fix-report-link {
    color: var(--purple-300);
  }
}
