/* =========================================================
   NETHERRACK — Research Agent Interface
   Identity: volcanic rock / ember / editorial ledger.
   Mobile-first. Controlled maximalism — hierarchy over noise.
   ========================================================= */

:root {
  /* ---- Core surfaces (warm near-black, not blue-black) ---- */
  --bg-deep: #0a0807;
  --bg: #0e0b09;
  --bg-elevated: #15100d;
  --surface: #1b1512;
  --surface-2: #241c17;
  --surface-3: #2e2420;
  --border: rgba(247, 232, 216, 0.09);
  --border-strong: rgba(247, 232, 216, 0.16);
  --border-loud: rgba(247, 232, 216, 0.26);

  /* ---- Type colors ---- */
  --text: #f6efe4;
  --text-secondary: #c7b9a9;
  --muted: #8c7d6d;
  --faint: #5b5045;

  /* ---- Brand: ember / rust (warm), with one deliberate cool counter-note ---- */
  --ember: #ff5a2e;
  --ember-2: #ff8a3d;
  --ember-soft: rgba(255, 90, 46, 0.14);
  --ember-glow: rgba(255, 90, 46, 0.38);
  --ember-hover: #ff7448;
  --rust: #a8380f;
  --char: #2b1c14;

  --info: #6f9bc4;
  --info-soft: rgba(111, 155, 196, 0.14);
  --gold: #e2a53d;
  --gold-soft: rgba(226, 165, 61, 0.14);
  --moss: #82a860;
  --moss-soft: rgba(130, 168, 96, 0.14);
  --crimson: #e5555a;
  --crimson-soft: rgba(229, 85, 90, 0.14);

  /* ---- Tier accents (Stone → Netherite) ---- */
  --tier-stone: #9a8f80;
  --tier-iron: #bcc5cc;
  --tier-diamond: #5fd9d1;
  --tier-netherite: #b478e0;

  /* ---- Cream / "report paper" surface — the landing page's signature
     light card, used wherever the app hands over a finished, citable
     result (a completed report, the auth card) rather than live UI chrome. ---- */
  --cream: #f6efe4;
  --cream-2: #efe4d2;
  --ink: #1c130d;
  --ink-soft: #4a3d33;
  --ink-faint: rgba(28, 19, 13, 0.55);

  /* ---- Shape ---- */
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 18px;
  --radius-xl: 24px;
  --radius-pill: 999px;

  /* ---- Type ---- */
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-display: "Space Grotesk", "Inter", sans-serif;
  --font-serif: "Fraunces", Georgia, "Times New Roman", serif;
  --font-mono: "JetBrains Mono", "SF Mono", ui-monospace, Menlo, Consolas, monospace;

  --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.4);
  --shadow: 0 12px 36px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.55);

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --header-h: 56px;

  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

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

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100%;
  min-height: 100dvh;
  background: var(--bg-deep);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

/* Ambient surface: fine grain + one deliberate ember wash (no floating blobs) */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(ellipse 70% 42% at 50% -8%, rgba(255, 90, 46, 0.10), transparent 60%),
    var(--bg-deep);
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.5;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.06'/%3E%3C/svg%3E");
}

a { color: var(--ember-2); text-decoration: none; }
a:hover { text-decoration: underline; }

button { font-family: inherit; }

::selection { background: var(--ember-soft); color: var(--text); }

.hidden { display: none !important; }

:focus-visible {
  outline: 2px solid var(--ember);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  border: 0;
}

/* =========================================================
   BUTTONS — shared vocabulary across auth + app
   ========================================================= */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 13px 18px;
  border-radius: var(--radius-pill);
  border: 1.5px solid transparent;
  font-family: var(--font-display);
  font-size: 14.5px;
  font-weight: 600;
  letter-spacing: -0.01em;
  cursor: pointer;
  transition: background 0.16s var(--ease), border-color 0.16s var(--ease),
              transform 0.12s var(--ease), box-shadow 0.16s var(--ease), color 0.16s var(--ease);
  -webkit-tap-highlight-color: transparent;
}

.btn:active { transform: scale(0.98); }

.btn-google {
  background: #f6efe4;
  color: #1a1310;
  border-color: transparent;
}
.btn-google:hover { background: #fff; box-shadow: var(--shadow-sm); }

.btn-primary {
  background: var(--ember);
  color: #180b06;
  box-shadow: 0 4px 22px var(--ember-glow);
}
.btn-primary:hover { background: var(--ember-hover); }
.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn-text {
  background: transparent;
  color: var(--muted);
  font-weight: 500;
  padding: 8px 12px;
  width: auto;
}
.btn-text:hover { color: var(--text); }

.btn-outline {
  background: transparent;
  border-color: rgba(229, 85, 90, 0.4);
  color: #ffb3b3;
  width: auto;
  padding: 9px 16px;
  font-size: 13px;
}
.btn-outline:hover { background: rgba(229, 85, 90, 0.1); }

.btn-ghost {
  background: var(--surface-2);
  border-color: var(--border-strong);
  color: var(--text-secondary);
  width: auto;
  padding: 9px 16px;
  font-size: 13px;
}
.btn-ghost:hover { color: var(--text); border-color: var(--border-loud); }

/* =========================================================
   AUTH PAGES (login / callback)
   ========================================================= */

.auth-shell {
  position: relative;
  z-index: 1;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  padding-top: calc(24px + var(--safe-top));
  padding-bottom: calc(24px + var(--safe-bottom));
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--cream);
  color: var(--ink);
  border: 1px solid rgba(24, 11, 6, 0.08);
  border-top: 3px solid var(--ember);
  border-radius: var(--radius-xl);
  padding: 34px 26px 28px;
  box-shadow: var(--shadow-lg);
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 11px;
  margin-bottom: 30px;
}

.auth-brand .logo-mark { width: 34px; height: 34px; }

.auth-brand h1 {
  margin: 0;
  color: var(--ink);
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.auth-card h2 {
  margin: 0 0 8px;
  color: var(--ink);
  font-family: var(--font-serif);
  font-size: 26px;
  font-weight: 600;
  font-style: italic;
  letter-spacing: -0.01em;
}

.auth-card .subtitle {
  margin: 0 0 26px;
  color: var(--ink-soft);
  font-size: 14px;
  line-height: 1.5;
}

.status-text {
  text-align: center;
  color: var(--ink-soft);
  font-family: var(--font-mono);
  font-size: 13px;
  margin: 4px 0 0;
}

.error-banner {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  background: rgba(229, 85, 90, 0.12);
  border: 1px solid rgba(229, 85, 90, 0.35);
  border-left: 3px solid var(--crimson);
  color: #9a2f34;
  padding: 11px 13px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  line-height: 1.45;
  margin-bottom: 18px;
}

.auth-card .btn-google {
  background: #fff;
  color: var(--ink);
  border: 1px solid rgba(24, 11, 6, 0.12);
}
.auth-card .btn-google:hover { background: #fff; box-shadow: var(--shadow-sm); }

/* =========================================================
   LOGO MARK — faceted rock glyph (used in header + auth)
   ========================================================= */

.logo-mark {
  border-radius: 8px;
  background: linear-gradient(155deg, var(--rust) 0%, var(--ember) 62%, var(--ember-2) 100%);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  box-shadow: inset 0 0 0 1px rgba(255, 200, 170, 0.25), 0 2px 14px rgba(255, 90, 46, 0.25);
}
.logo-mark svg { display: block; }

/* =========================================================
   APP SHELL
   ========================================================= */

.app {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
}

/* Header — a masthead, not a floating toolbar */
.app-header {
  flex-shrink: 0;
  padding: 0 12px;
  padding-top: var(--safe-top);
  height: calc(var(--header-h) + var(--safe-top));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--bg-elevated);
  border-bottom: 2px solid var(--border-strong);
  z-index: 20;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.logo-mark { width: 28px; height: 28px; }
.logo-mark svg { width: 15px; height: 15px; }

.brand-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.conn-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 9px 4px 7px;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  margin-left: 2px;
}

.conn-pill .dot {
  width: 6px;
  height: 6px;
  border-radius: 1px;
  transform: rotate(45deg);
  background: var(--muted);
  flex-shrink: 0;
}

.conn-pill.connected .dot { background: var(--moss); box-shadow: 0 0 7px var(--moss); }
.conn-pill.connecting .dot { background: var(--gold); animation: pulse-dot 1.1s ease-in-out infinite; }
.conn-pill.offline .dot { background: var(--crimson); box-shadow: 0 0 7px var(--crimson); }

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: rotate(45deg) scale(1); }
  50% { opacity: 0.45; transform: rotate(45deg) scale(0.8); }
}

.header-right {
  display: flex;
  align-items: center;
  gap: 2px;
}

.user-chip {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--muted);
  padding: 4px 8px;
  max-width: 96px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.icon-btn:hover, .icon-btn:focus-visible {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text);
}

/* Main content area */
.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

/* Conversation scroll region */
.chat-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 18px 14px 12px;
  scroll-behavior: smooth;
}

.chat-scroll::-webkit-scrollbar { width: 6px; }
.chat-scroll::-webkit-scrollbar-track { background: transparent; }
.chat-scroll::-webkit-scrollbar-thumb {
  background: var(--border-loud);
  border-radius: 4px;
}

/* =========================================================
   EMPTY STATE
   ========================================================= */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
  padding: 30px 6px 24px;
  max-width: 500px;
  margin: 0 auto;
  animation: fade-up 0.5s var(--ease-out);
}

@keyframes fade-up {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.empty-icon {
  width: 46px;
  height: 46px;
  border-radius: var(--radius);
  background: linear-gradient(155deg, var(--rust), var(--ember));
  border: 1px solid rgba(255, 200, 170, 0.2);
  display: grid;
  place-items: center;
  margin-bottom: 22px;
  box-shadow: 0 6px 24px rgba(255, 90, 46, 0.22);
}
.empty-icon svg { width: 22px; height: 22px; }

.empty-state h2 {
  margin: 0 0 10px;
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 30px;
  font-weight: 500;
  letter-spacing: -0.01em;
  line-height: 1.15;
}

.empty-state p {
  margin: 0 0 26px;
  color: var(--text-secondary);
  font-size: 14.5px;
  line-height: 1.55;
  max-width: 42ch;
}

.prompt-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
  width: 100%;
}

.prompt-card {
  position: relative;
  text-align: left;
  padding: 14px 13px 13px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 2.5px solid var(--border-loud);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  line-height: 1.4;
  cursor: pointer;
  transition: border-color 0.18s, background 0.18s, transform 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.prompt-card:hover, .prompt-card:focus-visible {
  border-left-color: var(--ember);
  background: var(--surface-2);
  transform: translateX(1px);
}
.prompt-card:active { transform: scale(0.98); }

.prompt-card:nth-of-type(1) { border-left-color: var(--ember); }
.prompt-card:nth-of-type(2) { border-left-color: var(--moss); }
.prompt-card:nth-of-type(3) { border-left-color: var(--gold); }
.prompt-card:nth-of-type(4) { border-left-color: var(--info); }

.prompt-card .pc-label {
  display: block;
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  margin-bottom: 6px;
  color: var(--muted);
}
.prompt-card .pc-hint {
  display: block;
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.35;
}

/* =========================================================
   MESSAGES
   ========================================================= */

.msg {
  max-width: 720px;
  margin: 0 auto 20px;
  animation: msg-in 0.32s var(--ease-out);
}

@keyframes msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* User message */
.msg-user {
  display: flex;
  justify-content: flex-end;
}

.msg-user .bubble {
  max-width: 88%;
  padding: 12px 16px;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-right: 2.5px solid var(--ember);
  border-radius: 12px 4px 12px 12px;
  font-size: 14.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Agent message */
.msg-agent {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.agent-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.agent-header .agent-dot {
  width: 7px;
  height: 7px;
  border-radius: 1px;
  transform: rotate(45deg);
  background: var(--ember);
  box-shadow: 0 0 8px var(--ember-glow);
  flex-shrink: 0;
}

.agent-header .agent-dot.working { animation: pulse-dot 1s ease-in-out infinite; }
.agent-header .agent-dot.done { background: var(--moss); box-shadow: 0 0 8px rgba(130, 168, 96, 0.5); }
.agent-header .agent-dot.error { background: var(--crimson); box-shadow: 0 0 8px rgba(229, 85, 90, 0.5); }
.agent-header .agent-dot.cancelled { background: var(--muted); box-shadow: none; }

/* Reusable inline pill — the small rounded ember label used throughout
   the landing page ("Live", "Source", "Structured", "Features"…). */
.pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: var(--radius-pill);
  background: var(--ember);
  color: #180b06;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 11px;
  line-height: 1.6;
  letter-spacing: -0.01em;
  flex-shrink: 0;
}

/* =========================================================
   AGENT ACTIVITY — the live run log. Cream "paper" card while the
   agent is actively working (mirrors the landing page's "Live progress
   tracking" feature card); settles back to a quiet dark log once done,
   so the finished report card below can take the spotlight.
   ========================================================= */

.agent-activity {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-top: 3px solid var(--border-loud);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: background 0.3s var(--ease), color 0.3s var(--ease), border-color 0.3s var(--ease), box-shadow 0.3s var(--ease);
}

.agent-activity.live {
  background: var(--cream);
  color: var(--ink);
  border-color: transparent;
  border-top-color: var(--ember);
  box-shadow: var(--shadow-lg);
}

.live-pill { display: none; }
.agent-activity.live .live-pill { display: inline-flex; }

.activity-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 13px;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.activity-head:hover { background: rgba(255, 255, 255, 0.015); }
.agent-activity.live .activity-head:hover { background: rgba(24, 11, 6, 0.03); }

.activity-title {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.agent-activity.live .activity-title { color: var(--ink); }

.activity-title .status-label {
  color: var(--text-secondary);
  font-weight: 500;
  font-family: var(--font-mono);
  font-size: 12.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.agent-activity.live .activity-title .status-label { color: var(--ink-soft); }

.activity-meta {
  flex-shrink: 0;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--faint);
  font-variant-numeric: tabular-nums;
}
.agent-activity.live .activity-meta { color: var(--ink-faint); }

.chevron {
  width: 15px;
  height: 15px;
  color: var(--muted);
  transition: transform 0.25s var(--ease);
  flex-shrink: 0;
}
.agent-activity.collapsed .chevron { transform: rotate(-90deg); }

.activity-body {
  padding: 2px 13px 13px;
  max-height: 420px;
  overflow-y: auto;
  transition: max-height 0.35s var(--ease), opacity 0.25s, padding 0.25s;
}
.agent-activity.collapsed .activity-body {
  max-height: 0;
  opacity: 0;
  padding-top: 0;
  padding-bottom: 0;
  overflow: hidden;
}

/* Progress — segmented, ledger-style */
.activity-progress {
  height: 3px;
  background: var(--border);
  margin: 0 13px 10px;
  border-radius: 2px;
  overflow: hidden;
}
.agent-activity.live .activity-progress { background: rgba(24, 11, 6, 0.1); }
.activity-progress .bar {
  height: 100%;
  width: 0%;
  background: repeating-linear-gradient(
    90deg,
    var(--ember) 0, var(--ember) 7px, var(--ember-2) 7px, var(--ember-2) 14px
  );
  border-radius: 2px;
  transition: width 0.45s var(--ease);
}
.agent-activity.collapsed .activity-progress { display: none; }

/* Timeline events */
.timeline {
  list-style: none;
  margin: 0;
  padding: 0;
  position: relative;
}

.timeline::before {
  content: "";
  position: absolute;
  left: 9px;
  top: 4px;
  bottom: 4px;
  width: 1px;
  background: linear-gradient(to bottom, var(--border-loud), transparent 96%);
}
.agent-activity.live .timeline::before {
  background: linear-gradient(to bottom, rgba(24, 11, 6, 0.18), transparent 96%);
}

.timeline-item {
  position: relative;
  padding: 7px 0 7px 30px;
  font-size: 13px;
  color: var(--text-secondary);
  animation: event-in 0.28s var(--ease-out);
}
.agent-activity.live .timeline-item { color: var(--ink-soft); }

@keyframes event-in {
  from { opacity: 0; transform: translateX(-5px); }
  to { opacity: 1; transform: translateX(0); }
}

.timeline-item .ti-icon {
  position: absolute;
  left: 0;
  top: 6px;
  width: 19px;
  height: 19px;
  border-radius: 5px;
  display: grid;
  place-items: center;
  background: var(--surface-2);
  border: 1.5px solid var(--border-strong);
  color: var(--muted);
  z-index: 1;
}
.agent-activity.live .timeline-item .ti-icon {
  background: rgba(24, 11, 6, 0.05);
  border-color: rgba(24, 11, 6, 0.14);
  color: var(--ink-faint);
}
.timeline-item .ti-icon svg { width: 11px; height: 11px; }

.timeline-item.completed .ti-icon {
  background: var(--moss-soft);
  border-color: rgba(130, 168, 96, 0.5);
  color: var(--moss);
}
.timeline-item.running .ti-icon {
  background: var(--ember-soft);
  border-color: var(--ember);
  color: var(--ember-2);
  animation: pulse-dot 1.1s ease-in-out infinite;
}
.timeline-item.failed .ti-icon {
  background: var(--crimson-soft);
  border-color: rgba(229, 85, 90, 0.5);
  color: var(--crimson);
}
.timeline-item.cancelled .ti-icon {
  background: var(--surface-2);
  border-color: var(--border-strong);
  color: var(--faint);
}
.timeline-item.queued .ti-icon {
  background: var(--surface);
  border-color: var(--faint);
  color: var(--muted);
}
.agent-activity.live .timeline-item.completed .ti-icon {
  background: rgba(130, 168, 96, 0.18);
  border-color: rgba(96, 140, 68, 0.55);
  color: #3f6b2a;
}
.agent-activity.live .timeline-item.running .ti-icon {
  background: rgba(255, 90, 46, 0.16);
  border-color: var(--ember);
  color: var(--rust);
}
.agent-activity.live .timeline-item.failed .ti-icon {
  background: rgba(229, 85, 90, 0.16);
  border-color: rgba(200, 60, 65, 0.5);
  color: #a8323a;
}
.agent-activity.live .timeline-item.cancelled .ti-icon,
.agent-activity.live .timeline-item.queued .ti-icon {
  background: rgba(24, 11, 6, 0.05);
  border-color: rgba(24, 11, 6, 0.14);
  color: var(--ink-faint);
}

.ti-main {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 7px;
}

.ti-desc { color: var(--text); font-weight: 500; }
.agent-activity.live .ti-desc { color: var(--ink); }

.ti-url {
  display: block;
  margin-top: 3px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--info);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}
.agent-activity.live .ti-url { color: var(--rust); }
.ti-url:hover { text-decoration: underline; }

.ti-time {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--faint);
  font-variant-numeric: tabular-nums;
}
.agent-activity.live .ti-time { color: var(--ink-faint); }


/* =========================================================
   AGENT RESPONSE — editorial markdown body
   ========================================================= */

.agent-response {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 17px 15px;
  font-size: 14.5px;
  line-height: 1.65;
  word-break: break-word;
}

/* Finished result — the cream "report" card, echoing the landing page's
   central promise of a structured, source-backed report. Only applied
   once a response settles (never during streaming or on error). */
.agent-response.report {
  background: var(--cream);
  color: var(--ink);
  border: none;
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  padding: 20px 19px 19px;
}

.report-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: -2px 0 14px;
  padding-bottom: 13px;
  border-bottom: 1px solid rgba(24, 11, 6, 0.1);
}
.report-meta .report-label {
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.report-meta .report-time {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--ink-faint);
  letter-spacing: 0.03em;
}

.agent-response.report .md-h { color: var(--ink); }
.agent-response.report .md-p,
.agent-response.report .md-list li { color: var(--ink); }
.agent-response.report a { color: var(--rust); }
.agent-response.report a:hover { color: var(--ember); }
.agent-response.report .md-quote {
  background: rgba(255, 90, 46, 0.09);
  color: var(--ink-soft);
  border-left-color: var(--ember);
}
.agent-response.report .md-hr { border-top-color: rgba(24, 11, 6, 0.12); }
.agent-response.report .md-inline-code {
  background: rgba(24, 11, 6, 0.06);
  color: var(--rust);
}
.agent-response.report .md-code-block {
  background: #fffdf9;
  border-color: rgba(24, 11, 6, 0.1);
}
.agent-response.report .md-code-header {
  background: rgba(24, 11, 6, 0.04);
  border-bottom-color: rgba(24, 11, 6, 0.08);
  color: var(--ink-faint);
}
.agent-response.report .md-copy-btn {
  border-color: rgba(24, 11, 6, 0.14);
  color: var(--ink-faint);
}
.agent-response.report .md-copy-btn:hover { color: var(--ink); border-color: rgba(24,11,6,0.3); }
.agent-response.report .md-code-block pre { color: var(--ink); }
.agent-response.report .md-table-wrap { border-color: rgba(24, 11, 6, 0.1); }
.agent-response.report .md-table th {
  background: rgba(24, 11, 6, 0.04);
  color: var(--ink-soft);
}
.agent-response.report .md-table th,
.agent-response.report .md-table td { border-bottom-color: rgba(24, 11, 6, 0.08); }

.agent-response.streaming::after {
  content: "";
  display: inline-block;
  width: 7px;
  height: 14px;
  margin-left: 2px;
  vertical-align: text-bottom;
  background: var(--ember);
  border-radius: 1px;
  animation: blink 0.9s step-end infinite;
}

@keyframes blink { 50% { opacity: 0; } }

.agent-response .md-p { margin: 0 0 0.75em; }
.agent-response .md-p:last-child { margin-bottom: 0; }
.agent-response .md-h {
  font-family: var(--font-serif);
  margin: 1.15em 0 0.4em;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.28;
  color: var(--text);
}
.agent-response h1.md-h { font-size: 1.5em; font-style: italic; }
.agent-response h2.md-h { font-size: 1.25em; }
.agent-response h3.md-h { font-size: 1.08em; font-family: var(--font-display); font-style: normal; }
.agent-response .md-list {
  margin: 0.4em 0 0.85em;
  padding-left: 1.3em;
}
.agent-response .md-list li { margin: 0.28em 0; }
.agent-response .md-quote {
  margin: 0.7em 0;
  padding: 9px 15px;
  border-left: 3px solid var(--ember);
  background: var(--ember-soft);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-secondary);
  font-style: italic;
}
.agent-response .md-hr {
  border: none;
  border-top: 1px solid var(--border-strong);
  margin: 1.1em 0;
}
.agent-response .md-inline-code {
  font-family: var(--font-mono);
  font-size: 0.87em;
  padding: 2px 6px;
  background: var(--surface-3);
  border-radius: 4px;
  color: var(--ember-2);
}
.agent-response a { color: var(--info); }

.md-code-block {
  margin: 0.8em 0;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  overflow: hidden;
  background: #0b0906;
}
.md-code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 12px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--muted);
}
.md-copy-btn {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10.5px;
  padding: 3px 9px;
  border-radius: 5px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.md-copy-btn:hover { color: var(--text); border-color: var(--border-loud); }
.md-copy-btn.copied { color: var(--moss); border-color: rgba(130, 168, 96, 0.4); }
.md-code-block pre {
  margin: 0;
  padding: 13px 14px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.6;
  color: #e6ddd0;
}
.md-code-block code { font-family: inherit; background: none; padding: 0; }

.md-table-wrap {
  overflow-x: auto;
  margin: 0.8em 0;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
}
.md-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.md-table th, .md-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
.md-table th {
  background: var(--surface-2);
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-weight: 600;
  color: var(--text-secondary);
}
.md-table tr:last-child td { border-bottom: none; }

/* Error card inside conversation */
.error-card {
  background: var(--crimson-soft);
  border: 1px solid rgba(229, 85, 90, 0.3);
  border-left: 3px solid var(--crimson);
  border-radius: var(--radius-lg);
  padding: 16px;
}
.error-card h3 {
  margin: 0 0 6px;
  font-family: var(--font-display);
  font-size: 15px;
  color: #ffc4c4;
}
.error-card p {
  margin: 0 0 14px;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
}
.error-card .btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* =========================================================
   TIER SELECT — Stone / Iron / Diamond / Netherite
   ========================================================= */

.tier-row {
  display: flex;
  gap: 6px;
  max-width: 720px;
  margin: 0 auto 8px;
  padding: 0 2px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.tier-row::-webkit-scrollbar { display: none; }

.tier-chip {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s, opacity 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.tier-chip:hover:not(:disabled) { border-color: var(--border-strong); background: var(--surface-2); }
.tier-chip:disabled { opacity: 0.45; cursor: not-allowed; }

.tier-chip .tier-chip-dot {
  width: 7px;
  height: 7px;
  border-radius: 1px;
  transform: rotate(45deg);
  flex-shrink: 0;
  background: var(--muted);
}
.tier-chip[data-tier="stone"] .tier-chip-dot { background: var(--tier-stone); }
.tier-chip[data-tier="iron"] .tier-chip-dot { background: var(--tier-iron); }
.tier-chip[data-tier="diamond"] .tier-chip-dot { background: var(--tier-diamond); }
.tier-chip[data-tier="netherite"] .tier-chip-dot { background: var(--tier-netherite); }

.tier-chip.active {
  color: var(--text);
  border-color: var(--ember);
  background: var(--ember-soft);
  box-shadow: 0 0 0 1px var(--ember-soft);
}
.tier-chip.active .tier-chip-dot { box-shadow: 0 0 6px currentColor; }
.tier-chip[data-tier="stone"].active .tier-chip-dot { box-shadow: 0 0 6px var(--tier-stone); }
.tier-chip[data-tier="iron"].active .tier-chip-dot { box-shadow: 0 0 6px var(--tier-iron); }
.tier-chip[data-tier="diamond"].active .tier-chip-dot { box-shadow: 0 0 6px var(--tier-diamond); }
.tier-chip[data-tier="netherite"].active .tier-chip-dot { box-shadow: 0 0 6px var(--tier-netherite); }

.tier-caption {
  max-width: 720px;
  margin: 0 auto 8px;
  padding: 0 6px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--faint);
  line-height: 1.4;
}

@media (min-width: 720px) {
  .tier-chip { font-size: 12.5px; padding: 6px 13px; }
}

/* =========================================================
   COMPOSER
   ========================================================= */

.composer-wrap {
  flex-shrink: 0;
  padding: 10px 12px;
  padding-bottom: calc(10px + var(--safe-bottom));
  background: linear-gradient(to top, var(--bg-deep) 65%, transparent);
  z-index: 15;
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 720px;
  margin: 0 auto;
  background: var(--surface);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 8px 8px 8px 15px;
  box-shadow: var(--shadow);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.composer:focus-within {
  border-color: var(--ember);
  box-shadow: var(--shadow), 0 0 0 3px var(--ember-soft);
}

.composer textarea {
  flex: 1;
  min-height: 24px;
  max-height: 140px;
  resize: none;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  line-height: 1.45;
  padding: 6px 0;
  overflow-y: auto;
}
.composer textarea:disabled { color: var(--muted); }

.composer textarea::placeholder { color: var(--muted); }

.send-btn {
  flex-shrink: 0;
  position: relative;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--ember);
  color: #180b06;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.15s, transform 0.15s, box-shadow 0.2s;
  box-shadow: 0 2px 14px var(--ember-glow);
  -webkit-tap-highlight-color: transparent;
}
.send-btn:hover:not(:disabled) { background: var(--ember-hover); }
.send-btn:active:not(:disabled) { transform: scale(0.94); }
.send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  box-shadow: none;
}
.send-btn svg { width: 18px; height: 18px; grid-area: 1 / 1; }
.send-btn .icon-send { display: block; }
.send-btn .icon-stop { display: none; }
.send-btn.working {
  background: var(--surface-3);
  color: var(--text);
  box-shadow: none;
}
.send-btn.working:hover { background: var(--surface-2); }
.send-btn.working .icon-send { display: none; }
.send-btn.working .icon-stop { display: block; }

.composer-hint {
  text-align: center;
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--faint);
  margin-top: 7px;
}

/* =========================================================
   MOBILE MENU — bottom sheet on phones, drawer from tablet up
   ========================================================= */

.menu-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(6, 4, 3, 0.6);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s, visibility 0.25s;
}
.menu-overlay.open {
  opacity: 1;
  visibility: visible;
}

.side-menu {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  background: var(--bg-elevated);
  border-top: 1px solid var(--border-strong);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  padding: 14px 14px calc(16px + var(--safe-bottom));
  transform: translateY(100%);
  transition: transform 0.32s var(--ease);
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: 0 -16px 50px rgba(0,0,0,0.5);
}
.side-menu::before {
  content: "";
  display: block;
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--border-loud);
  margin: 0 auto 14px;
}
.side-menu.open { transform: translateY(0); }

.side-menu h3 {
  margin: 0 0 10px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 13px 12px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  width: 100%;
  transition: background 0.15s, border-color 0.15s;
}
.menu-item:hover { border-color: var(--border-strong); }
.menu-item.danger { color: #ffb3b3; }
.menu-item svg { flex-shrink: 0; color: var(--muted); }
.menu-item.danger svg { color: #ffb3b3; }

/* =========================================================
   RESPONSIVE
   ========================================================= */

@media (min-width: 640px) {
  .chat-scroll { padding: 26px 22px 16px; }
  .composer-wrap { padding: 12px 22px; padding-bottom: calc(14px + var(--safe-bottom)); }
  .empty-state { padding-top: 46px; align-items: flex-start; }
  .empty-state h2 { font-size: 34px; }
  .prompt-grid { grid-template-columns: 1fr 1fr; gap: 11px; }
  .msg-user .bubble { max-width: 70%; }
  .conn-pill .conn-label { display: inline; }

  /* Drawer from the right instead of a bottom sheet */
  .side-menu {
    top: 0;
    left: auto;
    right: 0;
    bottom: 0;
    width: min(300px, 85vw);
    border-radius: 0;
    border-top: none;
    border-left: 1px solid var(--border-strong);
    padding: calc(18px + var(--safe-top)) 16px calc(16px + var(--safe-bottom));
    transform: translateX(100%);
    box-shadow: -16px 0 50px rgba(0,0,0,0.5);
  }
  .side-menu::before { display: none; }
  .side-menu.open { transform: translateX(0); }
}

@media (min-width: 900px) {
  .app-header { padding-left: 24px; padding-right: 24px; }
  .chat-scroll { padding: 32px 36px 20px; }
  .composer-wrap { padding-left: 36px; padding-right: 36px; }
  .empty-state { max-width: 560px; }
  .empty-state h2 { font-size: 38px; }
}

@media (max-width: 400px) {
  .prompt-grid { grid-template-columns: 1fr; }
  .conn-pill .conn-label { display: none; }
}
