/* ============================================================
   ECGAgent — Cyberpunk / neon-lime HUD theme.
   Restyle only: every class name here is referenced by index.html
   or app.js. Visual language = pure-black base, neon-lime accent,
   angular clip-path corners, mono HUD labels. One accent (lime),
   mint reserved for the SEND action only. Shapes are all-angular.
   ============================================================ */

@import url("https://fonts.googleapis.com/css2?family=Chakra+Petch:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap");

:root {
  color-scheme: dark;
  --display: "Chakra Petch", "Rajdhani", "Bai Jamjuree", system-ui, sans-serif;
  --mono: "JetBrains Mono", "Space Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  /* Pure-black base with a faint green-black panel surface. */
  --bg: #050505;
  --bg-2: #0a0b0a;
  --panel: rgba(15, 18, 15, 0.72);
  --panel-solid: rgba(13, 16, 13, 0.96);
  --panel-2: rgba(20, 24, 19, 0.55);

  --text: #ededed;
  --text-strong: #f6fbf0;
  --muted: #8a8f88;
  --faint: #5f655d;

  /* One accent: neon lime. Mint is for the SEND action only. */
  --lime: #c6ff1a;
  --lime-2: #9eff00;
  --lime-3: #7fff3c;
  --mint: #2bffc6;
  --on-accent: #07140a;

  --line: rgba(198, 255, 26, 0.22);
  --line-soft: rgba(198, 255, 26, 0.12);
  --hairline: rgba(160, 180, 150, 0.14);

  --ok: #7fff3c;
  --warn: #ffd23c;
  --err: #ff4d57;

  /* Angular clipped corners (HUD notches). clip-path values as tokens. */
  --notch-lg: polygon(16px 0, 100% 0, 100% calc(100% - 16px), calc(100% - 16px) 100%, 0 100%, 0 16px);
  --notch-md: polygon(12px 0, 100% 0, 100% calc(100% - 12px), calc(100% - 12px) 100%, 0 100%, 0 12px);
  --notch-sm: polygon(8px 0, 100% 0, 100% calc(100% - 8px), calc(100% - 8px) 100%, 0 100%, 0 8px);
  --notch-tr: polygon(0 0, calc(100% - 9px) 0, 100% 9px, 100% 100%, 0 100%);

  --thread-max: 860px;
  --thread-width: min(var(--thread-max), calc(100vw - 26px));
  --thread-gutter: max(18px, calc((100vw - var(--thread-max)) / 2));
  --scrollbar-compensation: 10px;
  --composer-welcome-width: min(780px, calc(100vw - 34px));
  --composer-docked-width: var(--thread-width);
  --message-bottom-space: 250px;
}

/* Light theme: clean white background with a readable medium-green accent
   (bright lime is unreadable as text on white, so the accent darkens; fills
   use the same green with white text). Toggled from the top-right button. */
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #eef2e8;
  --bg-2: #ffffff;
  --panel: rgba(255, 255, 255, 0.86);
  --panel-solid: #ffffff;
  --panel-2: rgba(20, 50, 0, 0.03);

  --text: #1b2016;
  --text-strong: #0c1207;
  --muted: #5c6353;
  --faint: #8b917f;

  --lime: #3c7d0e;
  --lime-2: #2f6a08;
  --lime-3: #4e9a18;
  --mint: #0c8f72;
  --on-accent: #ffffff;

  --line: rgba(60, 125, 14, 0.36);
  --line-soft: rgba(60, 125, 14, 0.18);
  --hairline: rgba(40, 60, 20, 0.16);

  --ok: #2f8f1a;
  --warn: #a8780a;
  --err: #cf3640;
}

/* Light-mode overrides for the few surfaces that hardcode dark values. */
:root[data-theme="light"] body {
  background:
    radial-gradient(40vw 40vw at 12% 14%, rgba(60, 125, 14, 0.08), transparent 70%),
    radial-gradient(34vw 34vw at 88% 10%, rgba(12, 143, 114, 0.06), transparent 70%),
    radial-gradient(circle, rgba(60, 125, 14, 0.06) 1px, transparent 1.4px),
    linear-gradient(180deg, var(--bg-2), var(--bg) 70%);
  background-size: auto, auto, 24px 24px, auto;
  background-attachment: fixed;
}

:root[data-theme="light"] .scanlines {
  display: none;
}

:root[data-theme="light"] .final-answer pre {
  color: var(--text);
  background: rgba(20, 50, 0, 0.05);
  border-color: var(--line-soft);
}

:root[data-theme="light"] .json-number {
  color: #9a6b00;
}

:root[data-theme="light"] .json-bool,
:root[data-theme="light"] .json-null {
  color: #b3306a;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
}

html {
  background: var(--bg);
}

body {
  min-height: 100dvh;
  overflow: hidden;
  color: var(--text);
  font: 400 16px/1.58 var(--mono);
  letter-spacing: 0.01em;
  background:
    /* two soft green radial glows */
    radial-gradient(38vw 38vw at 14% 16%, rgba(126, 255, 60, 0.10), transparent 70%),
    radial-gradient(34vw 34vw at 86% 12%, rgba(43, 255, 198, 0.07), transparent 70%),
    /* dotted grid texture */
    radial-gradient(circle, rgba(198, 255, 26, 0.05) 1px, transparent 1.4px),
    /* vignette + base */
    radial-gradient(120vw 120vh at 50% 30%, transparent 55%, rgba(0, 0, 0, 0.6) 100%),
    linear-gradient(180deg, var(--bg-2), var(--bg) 60%);
  background-size: auto, auto, 24px 24px, auto, auto;
  background-attachment: fixed;
}

button,
textarea,
input {
  font: inherit;
}

button,
label {
  -webkit-tap-highlight-color: transparent;
}

button {
  border: 0;
  cursor: pointer;
}

svg {
  display: block;
}

/* --- Background decoration --------------------------------------------- */

.ambient {
  position: fixed;
  z-index: 0;
  border-radius: 50%;
  pointer-events: none;
  filter: blur(60px);
  opacity: 0.5;
  animation: ambient-drift 22s ease-in-out infinite alternate;
}

.ambient-a {
  width: 36vw;
  height: 36vw;
  left: -8vw;
  top: 8vh;
  background: rgba(126, 255, 60, 0.14);
}

.ambient-b {
  width: 26vw;
  height: 26vw;
  right: 2vw;
  top: 4vh;
  background: rgba(43, 255, 198, 0.10);
  animation-delay: -7s;
}

.ambient-c {
  width: 30vw;
  height: 30vw;
  left: 40vw;
  bottom: -16vw;
  background: rgba(198, 255, 26, 0.08);
  animation-delay: -13s;
}

/* Slow-scrolling scanline overlay across the whole viewport. */
.scanlines {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0) 0,
    rgba(0, 0, 0, 0) 2px,
    rgba(0, 0, 0, 0.16) 3px,
    rgba(0, 0, 0, 0) 4px
  );
  background-size: 100% 4px;
  opacity: 0.5;
  animation: scan-scroll 9s linear infinite;
}

/* --- Top bar / brand --------------------------------------------------- */

.topbar {
  position: fixed;
  z-index: 20;
  top: 16px;
  left: 18px;
  right: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
}

.brand {
  display: flex;
  align-items: center;
  min-width: 0;
  pointer-events: auto;
}

.brand h1 {
  margin: 0;
  white-space: nowrap;
  color: var(--text-strong);
  font-family: var(--display);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

/* "ECG" rendered in the theme accent; "Agent" stays the normal text colour
   in the top-left brand. */
.brand-accent {
  color: var(--lime);
  text-shadow: 0 0 10px rgba(198, 255, 26, 0.4);
}

/* "Agent" half of the centre hero — neutral (black on the light background,
   near-white on the dark one) so only "ECG" carries the theme colour. */
.brand-accent-2 {
  color: var(--text-strong);
  text-shadow: none;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  pointer-events: auto;
}

/* --- Angular icon buttons --------------------------------------------- */

.glass-icon-btn {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  clip-path: var(--notch-sm);
  color: var(--lime);
  background: var(--panel);
  border: 1px solid var(--line);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  pointer-events: auto;
  user-select: none;
  transition: background 150ms ease, color 150ms ease, transform 140ms ease,
    filter 150ms ease;
}

.glass-icon-btn:hover {
  background: rgba(198, 255, 26, 0.1);
  filter: drop-shadow(0 0 8px rgba(198, 255, 26, 0.45));
}

.glass-icon-btn:focus-visible {
  outline: none;
  filter: drop-shadow(0 0 9px rgba(198, 255, 26, 0.6));
  background: rgba(198, 255, 26, 0.12);
}

.glass-icon-btn:active {
  transform: scale(0.94);
}

.icon {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

#theme-toggle .sun {
  display: none;
}

:root[data-theme="dark"] #theme-toggle .sun {
  display: block;
}

:root[data-theme="dark"] #theme-toggle .moon {
  display: none;
}

/* --- App shell --------------------------------------------------------- */

.app {
  position: relative;
  z-index: 2;
  width: 100%;
  height: 100dvh;
  overflow: hidden;
}

.welcome-panel {
  position: fixed;
  z-index: 4;
  /* Lifted higher than half the composer height so the hero doesn't hug the
     input box's top edge. */
  top: calc(50% - 252px);
  left: 50%;
  width: min(820px, calc(100vw - 34px));
  transform: translateX(-50%);
  text-align: center;
  transition: opacity 420ms ease, transform 560ms cubic-bezier(0.2, 0.9, 0.2, 1);
}

.welcome-panel h2 {
  position: relative;
  margin: 0;
  color: var(--text-strong);
  font-family: var(--display);
  font-size: clamp(30px, 5.4vw, 60px);
  font-weight: 700;
  line-height: 1.04;
  letter-spacing: -0.01em;
  text-transform: uppercase;
  text-shadow: 0 0 22px rgba(198, 255, 26, 0.22);
}

/* Subtle scan sweep over the hero heading — stays fully readable. */
.welcome-panel h2::after {
  content: attr(data-text);
  position: absolute;
  inset: 0;
  color: var(--lime);
  clip-path: inset(0 0 80% 0);
  opacity: 0.16;
  animation: hero-scan 4.6s ease-in-out infinite;
  pointer-events: none;
}

/* Fade the centered name out the moment the composer is used, so a growing
   composer (typed text + attachment chips) never slices through it. The
   top-left brand keeps "ECGAgent" visible at all times. */
.app.active .welcome-panel,
.app:has(.composer:focus-within) .welcome-panel,
.app:has(.preview-tray:not(.hidden)) .welcome-panel {
  opacity: 0;
  transform: translate(-50%, -28px) scale(0.98);
  pointer-events: none;
}

.messages {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  gap: 18px;
  overflow-y: auto;
  padding: 112px var(--thread-gutter) 24px;
  scroll-padding: 112px 0 var(--message-bottom-space);
  scroll-behavior: smooth;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  opacity: 0;
  transform: translateY(22px);
  transition: opacity 360ms ease 120ms, transform 460ms cubic-bezier(0.2, 0.9, 0.2, 1) 120ms;
}

.messages::after {
  content: "";
  flex: 0 0 var(--message-bottom-space);
}

.app.active .messages {
  opacity: 1;
  transform: translateY(0);
}

/* Composer is hidden once active, so the thread no longer reserves room for it. */
.app.active {
  --message-bottom-space: 48px;
}

@supports selector(.app:has(.composer:focus-within)) {
  .app.active:has(.composer:focus-within) {
    --message-bottom-space: 286px;
  }
}

.messages::-webkit-scrollbar,
.code-wrap::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

.messages::-webkit-scrollbar-thumb,
.code-wrap::-webkit-scrollbar-thumb {
  border: 3px solid transparent;
  background: rgba(198, 255, 26, 0.28);
  background-clip: padding-box;
}

.messages::-webkit-scrollbar-thumb:hover,
.code-wrap::-webkit-scrollbar-thumb:hover {
  background: rgba(198, 255, 26, 0.5);
  background-clip: padding-box;
}

/* --- Composer (visual centerpiece) ------------------------------------ */

.composer {
  position: fixed;
  z-index: 10;
  left: 50%;
  bottom: 50%;
  width: var(--composer-welcome-width);
  padding: 9px;
  clip-path: var(--notch-lg);
  border: 1px solid var(--line);
  background: var(--panel);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  transform: translate(-50%, 50%);
  transition: width 560ms cubic-bezier(0.2, 0.9, 0.2, 1),
    bottom 560ms cubic-bezier(0.2, 0.9, 0.2, 1),
    transform 560ms cubic-bezier(0.2, 0.9, 0.2, 1),
    border-color 200ms ease, filter 200ms ease;
}

/* HUD corner brackets: top-left + bottom-right. */
.composer::before,
.composer::after {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  border: 1.5px solid var(--lime);
  opacity: 0.55;
  pointer-events: none;
  transition: opacity 200ms ease;
}

.composer::before {
  top: 5px;
  left: 5px;
  border-right: 0;
  border-bottom: 0;
}

.composer::after {
  right: 5px;
  bottom: 5px;
  border-left: 0;
  border-top: 0;
}

/* One-shot flow: once the first question is submitted, the composer (input +
   upload) disappears so the user focuses on the live pipeline + result. A new
   question is started via the top-right "+" (new chat). */
.app.active .composer {
  display: none;
}

.composer:focus-within {
  border-color: var(--lime);
  filter: drop-shadow(0 0 16px rgba(198, 255, 26, 0.28));
}

.composer:focus-within::before,
.composer:focus-within::after {
  opacity: 1;
}

.composer-shell {
  position: relative;
  display: block;
  min-height: 104px;
  padding: 16px 16px 60px;
  overflow: hidden;
  clip-path: var(--notch-md);
  background: var(--panel-2);
  box-shadow: inset 0 0 0 1px rgba(198, 255, 26, 0.08);
  transition: min-height 420ms cubic-bezier(0.2, 0.9, 0.2, 1), padding 420ms ease;
}

.app.active .composer-shell {
  min-height: 76px;
  padding-bottom: 54px;
}

.composer:focus-within .composer-shell {
  min-height: 120px;
}

.app.active .composer:focus-within .composer-shell {
  min-height: 92px;
}

/* Top scan line that lights up on focus. */
.composer-shell::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--lime), transparent);
  opacity: 0;
  transition: opacity 200ms ease;
}

.composer:focus-within .composer-shell::before {
  opacity: 0.9;
  animation: line-sweep 2.4s ease-in-out infinite;
}

textarea {
  position: relative;
  z-index: 1;
  width: 100%;
  min-height: 52px;
  max-height: 180px;
  margin-top: 6px;
  resize: none;
  border: 0;
  outline: 0;
  color: var(--text-strong);
  background: transparent;
  font-family: var(--mono);
  font-size: 15px;
  font-weight: 400;
  line-height: 1.55;
  letter-spacing: 0.01em;
  caret-color: var(--lime);
}

.app.active textarea {
  min-height: 40px;
  max-height: 130px;
  font-size: 14.5px;
}

textarea::placeholder {
  color: var(--faint);
}

.composer-actions {
  position: absolute;
  z-index: 2;
  right: 14px;
  bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Attach button: clipped pill, lime outline, icon + label. */
.upload-btn {
  position: absolute;
  z-index: 2;
  left: 14px;
  bottom: 12px;
  width: auto;
  height: 34px;
  gap: 7px;
  grid-auto-flow: column;
  padding: 0 12px;
  clip-path: var(--notch-sm);
}

.upload-btn .icon {
  width: 17px;
  height: 17px;
}

.upload-label {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.14em;
}

.upload-btn input {
  display: none;
}

/* Send: filled lime->mint gradient, dark glyph, strong glow on hover. */
.send-btn {
  width: 44px;
  height: 34px;
  color: var(--on-accent);
  background: linear-gradient(135deg, var(--lime), var(--mint));
  border-color: transparent;
}

.send-btn .icon {
  stroke-width: 2.4;
}

.send-btn:hover {
  background: linear-gradient(135deg, var(--lime), var(--mint));
  filter: drop-shadow(0 0 12px rgba(43, 255, 198, 0.6));
}

.send-btn:disabled {
  cursor: not-allowed;
  opacity: 0.4;
  filter: none;
  transform: none;
}

/* --- Suggested questions (click to populate the composer) -------------- */

.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin: 9px 7px 3px;
}

.suggestion {
  padding: 7px 12px;
  clip-path: var(--notch-sm);
  border: 1px solid var(--line);
  background: rgba(198, 255, 26, 0.04);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11.5px;
  letter-spacing: 0.02em;
  text-align: left;
  transition: color 150ms ease, background 150ms ease, border-color 150ms ease, transform 140ms ease;
}

.suggestion:hover {
  color: var(--lime);
  background: rgba(198, 255, 26, 0.1);
  border-color: var(--lime);
}

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

.suggestion:focus-visible {
  outline: none;
  color: var(--lime);
  border-color: var(--lime);
}

/* Suggestions are a welcome-screen aid; hide them once the thread is active. */
.app.active .suggestions {
  display: none;
}

/* --- Attachment chips (one per uploaded file, wrap) -------------------- */

.preview-tray {
  position: relative;
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 12px 2px;
}

.preview-tray.hidden {
  display: none;
}

.preview {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6px 6px 6px 9px;
  clip-path: var(--notch-sm);
  border: 1px solid var(--line);
  background: rgba(198, 255, 26, 0.05);
  max-width: 100%;
}

.chip-file {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
  color: var(--lime);
}

.chip-file svg {
  width: 18px;
  height: 18px;
}

.chip-thumb {
  flex: 0 0 auto;
  padding: 0;
  background: transparent;
  clip-path: var(--notch-sm);
  transition: filter 150ms ease;
}

.chip-thumb:hover {
  filter: brightness(1.08);
}

.preview img {
  display: block;
  width: 52px;
  height: 36px;
  object-fit: cover;
  clip-path: var(--notch-sm);
  border: 1px solid var(--line);
  background: #000;
}

.chip-meta {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.chip-name {
  color: var(--text-strong);
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 30vw;
}

.chip-size {
  color: var(--muted);
  font-size: 10.5px;
  letter-spacing: 0.04em;
}

.chip-remove.glass-chip {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  flex: 0 0 auto;
  padding: 0;
  clip-path: var(--notch-sm);
  color: var(--lime);
  background: transparent;
  border: 1px solid var(--line);
  font-size: 15px;
  line-height: 1;
  transition: background 150ms ease, color 150ms ease, border-color 150ms ease, transform 140ms ease;
}

.chip-remove.glass-chip:hover {
  background: rgba(255, 77, 87, 0.12);
  color: var(--err);
  border-color: rgba(255, 77, 87, 0.5);
}

.chip-remove.glass-chip:active {
  transform: scale(0.92);
}

/* Incomplete-WFDB warning shown in the attachment tray. */
.attach-warning {
  flex: 1 1 100%;
  padding: 7px 11px;
  clip-path: var(--notch-sm);
  border: 1px solid rgba(255, 210, 60, 0.5);
  background: rgba(255, 210, 60, 0.08);
  color: var(--warn);
  font-family: var(--mono);
  font-size: 11.5px;
  letter-spacing: 0.02em;
}

.attach-warning.flash {
  animation: warn-flash 0.5s ease;
}

@keyframes warn-flash {
  0%, 100% { background: rgba(255, 210, 60, 0.08); }
  40% { background: rgba(255, 210, 60, 0.28); }
}

/* Transient note in the tray (e.g. "skipped 1 image"). */
.attach-note {
  flex: 1 1 100%;
  padding: 7px 11px;
  clip-path: var(--notch-sm);
  border: 1px solid rgba(43, 255, 198, 0.35);
  background: rgba(43, 255, 198, 0.06);
  color: var(--mint);
  font-family: var(--mono);
  font-size: 11.5px;
  letter-spacing: 0.02em;
}

/* Hint under the composer: what can be dragged in. */
.composer-hint {
  margin: 10px 2px 0;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.03em;
  color: var(--text);
  opacity: 0.55;
  text-align: center;
}

.composer-hint strong {
  color: var(--lime);
  font-weight: 600;
}

.app.active .composer-hint { display: none; }

/* Queued-on-busy-server banner (shown until the first agent step starts). */
.queued-banner {
  align-self: flex-start;
  margin: 4px 0 2px;
  padding: 8px 13px;
  clip-path: var(--notch-sm);
  border: 1px solid rgba(43, 255, 198, 0.4);
  background: rgba(43, 255, 198, 0.07);
  color: var(--mint);
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.02em;
  animation: queued-pulse 1.6s ease-in-out infinite;
}

@keyframes queued-pulse {
  0%, 100% { opacity: 0.65; }
  50% { opacity: 1; }
}

/* --- Access gate (test password lock screen) -------------------------- */

.gate {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
  background-image:
    radial-gradient(820px 520px at 50% 18%, rgba(198, 255, 26, 0.1), transparent 60%),
    linear-gradient(180deg, var(--bg-2), var(--bg) 70%);
}

.gate[hidden] { display: none; }

.gate-card {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 14px;
  width: min(380px, 100%);
  padding: 34px 30px;
  clip-path: var(--notch-lg);
  border: 1px solid var(--line);
  background: var(--panel-solid);
  filter: drop-shadow(0 0 26px rgba(198, 255, 26, 0.14));
}

.gate-card.shake {
  animation: gate-shake 0.4s ease;
}

@keyframes gate-shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-7px); }
  40%, 80% { transform: translateX(7px); }
}

.gate-brand {
  font-family: var(--display);
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.01em;
  text-transform: uppercase;
  text-align: center;
  color: var(--text-strong);
}

.gate-sub {
  margin: 0;
  text-align: center;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.03em;
  color: var(--text);
  opacity: 0.7;
}

.gate-input {
  width: 100%;
  padding: 12px 14px;
  clip-path: var(--notch-sm);
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text-strong);
  font-family: var(--mono);
  font-size: 14px;
  letter-spacing: 0.08em;
  outline: none;
}

.gate-input:focus {
  border-color: var(--lime);
}

.gate-btn {
  padding: 11px 14px;
  clip-path: var(--notch-sm);
  border: 1px solid var(--lime);
  background: var(--lime);
  color: var(--on-accent, #050505);
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
  transition: filter 160ms ease, transform 120ms ease;
}

.gate-btn:hover { filter: brightness(1.08); }
.gate-btn:active { transform: translateY(1px); }

.gate-error {
  margin: 0;
  text-align: center;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.02em;
  color: var(--warn);
}

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

/* --- Drag & drop overlay ---------------------------------------------- */

.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(5, 5, 5, 0.78);
  backdrop-filter: blur(3px);
  pointer-events: none;
}

.drop-overlay.hidden { display: none; }

.drop-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 40px 56px;
  clip-path: var(--notch-lg);
  border: 2px dashed var(--lime);
  background: rgba(198, 255, 26, 0.06);
  color: var(--text-strong);
  text-align: center;
  filter: drop-shadow(0 0 22px rgba(198, 255, 26, 0.25));
}

.drop-card .icon {
  width: 40px;
  height: 40px;
  fill: none;
  stroke: var(--lime);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.drop-title {
  font-family: var(--mono);
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--lime);
}

.drop-sub {
  font-family: var(--mono);
  font-size: 11.5px;
  letter-spacing: 0.02em;
  color: var(--text);
  opacity: 0.8;
}

/* Subtle highlight on the composer while dragging. */
.app.dropping .composer-shell {
  border-color: var(--lime);
}

/* --- Turns / messages -------------------------------------------------- */

.turn {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
}

.message-row {
  display: flex;
  width: 100%;
}

.message-row.user {
  justify-content: flex-end;
}

.message-row.assistant {
  justify-content: flex-start;
}

.message-bubble {
  position: relative;
  max-width: min(78%, 760px);
  overflow: hidden;
  clip-path: var(--notch-md);
  padding: 15px 19px;
  font-family: var(--mono);
  font-size: 14.5px;
  font-weight: 400;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
}

.message-row.user .message-bubble {
  color: var(--on-accent);
  background: linear-gradient(135deg, var(--lime), var(--lime-3));
  font-weight: 500;
}

.message-row.assistant .message-bubble {
  width: 100%;
  max-width: none;
  color: var(--text);
  border: 1px solid var(--line-soft);
  background: var(--panel);
}

.message-bubble img.thumb {
  display: block;
  width: 132px;
  max-width: 42vw;
  height: 92px;
  object-fit: cover;
  clip-path: var(--notch-sm);
  border: 1px solid rgba(7, 20, 10, 0.4);
}

.user-image-button {
  display: block;
  width: max-content;
  max-width: 100%;
  margin: 0 0 10px;
  padding: 0;
  overflow: hidden;
  clip-path: var(--notch-sm);
  background: transparent;
  transition: filter 150ms ease;
}

.user-image-button:hover {
  filter: brightness(1.06);
}

.user-message-text {
  white-space: pre-wrap;
  word-break: break-word;
  color: inherit;
}

/* Uploaded signal/record files shown inside the (lime) user bubble. */
.user-attach-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 10px;
}

.user-attach {
  display: inline-flex;
  align-items: baseline;
  gap: 7px;
  padding: 4px 9px;
  clip-path: var(--notch-sm);
  background: rgba(7, 20, 10, 0.18);
  border: 1px solid rgba(7, 20, 10, 0.35);
}

.user-attach-name {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
  color: var(--on-accent);
}

.user-attach-size {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.04em;
  color: rgba(7, 20, 10, 0.7);
}

.assistant-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: var(--thread-width);
  max-width: 100%;
}

/* --- Pipeline strip (one chip per agent role) -------------------------- */

.pipeline-strip {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 10px 12px;
  margin-bottom: 6px;
  clip-path: var(--notch-md);
  background: var(--panel);
  border: 1px solid var(--line-soft);
}

.pipeline-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  clip-path: var(--notch-sm);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--hairline);
  transition: background 0.18s, color 0.18s, transform 0.2s, border-color 0.18s;
}

.pipeline-chip .icon {
  width: 13px;
  height: 13px;
  fill: currentColor;
  stroke: none;
}

.pipeline-chip.state-idle {
  opacity: 0.5;
}

.pipeline-chip.state-running {
  color: var(--lime);
  background: rgba(198, 255, 26, 0.1);
  border-color: var(--line);
  transform: translateY(-1px);
}

.pipeline-chip.state-success {
  color: var(--ok);
  background: rgba(127, 255, 60, 0.08);
  border-color: rgba(127, 255, 60, 0.3);
}

.pipeline-chip.state-error {
  color: var(--err);
  background: rgba(255, 77, 87, 0.1);
  border-color: rgba(255, 77, 87, 0.4);
}

.chip-label {
  line-height: 1;
}

/* --- Agent cards ------------------------------------------------------- */

.agent-card {
  position: relative;
  margin-top: 10px;
  clip-path: var(--notch-md);
  background: var(--panel);
  border: 1px solid var(--line-soft);
  overflow: hidden;
  transition: border-color 0.2s;
}

.agent-card.state-running {
  border-color: var(--line);
}

.agent-card.state-success {
  border-color: rgba(127, 255, 60, 0.32);
}

.agent-card.state-error {
  border-color: rgba(255, 77, 87, 0.45);
}

.agent-head {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 14px;
  background: transparent;
  border: 0;
  cursor: pointer;
  font: inherit;
  color: inherit;
  text-align: left;
  transition: background 0.16s ease;
}

.agent-head:hover {
  background: rgba(198, 255, 26, 0.04);
}

.agent-head .chevron {
  width: 18px;
  height: 18px;
  margin-left: auto;
  color: var(--muted);
  transition: transform 0.2s, color 0.16s;
}

.agent-head:hover .chevron {
  color: var(--lime);
}

.agent-card.is-open .agent-head .chevron {
  transform: rotate(180deg);
}

.agent-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  clip-path: var(--notch-sm);
  background: rgba(198, 255, 26, 0.06);
  border: 1px solid var(--line-soft);
  flex-shrink: 0;
  color: var(--lime);
}

.agent-icon .icon {
  width: 18px;
  height: 18px;
  fill: currentColor;
  stroke: none;
}

/* One accent, lime, applied to every role icon (Color Consistency Lock).
   Roles are differentiated by their glyph + label, not by hue. */
.agent-card .agent-icon,
.pipeline-chip.state-idle {
  color: var(--lime);
}

.pipeline-chip.accent-analyzer.state-idle,
.pipeline-chip.accent-planner.state-idle,
.pipeline-chip.accent-executor.state-idle,
.pipeline-chip.accent-tool.state-idle,
.pipeline-chip.accent-verifier.state-idle,
.pipeline-chip.accent-finalizer.state-idle {
  color: rgba(198, 255, 26, 0.5);
}

.agent-title {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;
}

.agent-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  color: var(--text-strong);
  font-family: var(--display);
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.step-badge {
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 2px 7px;
  clip-path: var(--notch-sm);
  background: rgba(198, 255, 26, 0.1);
  color: var(--lime);
}

.tool-badge {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 2px 7px;
  clip-path: var(--notch-sm);
  background: rgba(43, 255, 198, 0.08);
  color: var(--mint);
  border: 1px solid rgba(43, 255, 198, 0.25);
  font-family: var(--mono);
}

.agent-sub {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--muted);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 9px;
  clip-path: var(--notch-sm);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.status-pill .status-dot {
  width: 6px;
  height: 6px;
}

.status-pill.running {
  color: var(--lime);
  background: rgba(198, 255, 26, 0.1);
}

.status-pill.running .status-dot {
  background: var(--lime);
  animation: agent-pulse 1.4s ease-in-out infinite;
}

.status-pill.success {
  color: var(--ok);
  background: rgba(127, 255, 60, 0.1);
}

.status-pill.success .status-dot {
  background: var(--ok);
}

.status-pill.error {
  color: var(--err);
  background: rgba(255, 77, 87, 0.1);
}

.status-pill.error .status-dot {
  background: var(--err);
}

.agent-elapsed {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.04em;
}

.agent-progress {
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--lime), transparent);
  background-size: 200% 100%;
  animation: agent-progress-shift 1.6s linear infinite;
}

.agent-card.state-success .agent-progress,
.agent-card.state-error .agent-progress {
  display: none;
}

.agent-body {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.25s ease;
}

.agent-card.is-open .agent-body {
  grid-template-rows: 1fr;
}

.agent-body-inner {
  overflow: hidden;
  padding: 0 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* --- I/O + reasoning sections ----------------------------------------- */

.agent-section {
  clip-path: var(--notch-sm);
  border: 1px solid var(--line-soft);
  background: rgba(255, 255, 255, 0.015);
  overflow: hidden;
}

.agent-section.is-pending {
  opacity: 0.6;
}

.agent-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  background: rgba(198, 255, 26, 0.04);
  border-bottom: 1px solid var(--line-soft);
}

.agent-section-head h4 {
  margin: 0;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.14em;
}

.agent-section .code-wrap {
  padding: 12px 14px;
  overflow: auto;
  max-height: 360px;
}

.agent-section pre {
  margin: 0;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.62;
  font-weight: 400;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}

/* DeepSeek "thinking" section: distinct lime-tinted treatment so the hidden
   chain-of-thought is visually separated from the structured I/O. */
.agent-section.reasoning-io {
  border-color: var(--line);
  background: rgba(198, 255, 26, 0.035);
}

.agent-section.reasoning-io .agent-section-head {
  color: var(--lime);
  background: rgba(198, 255, 26, 0.07);
  border-bottom-color: var(--line);
}

.agent-section.reasoning-io pre {
  color: var(--text);
  font-style: italic;
}

.agent-section.reasoning-io .think-cursor {
  color: var(--lime);
  font-style: normal;
  animation: blink 1.1s step-end infinite;
}

.code-wrap {
  max-height: 360px;
  overflow: auto;
}

.code-wrap pre {
  margin: 0;
  padding: 0;
  color: var(--text);
  font: 12.5px/1.6 var(--mono);
  white-space: pre-wrap;
  word-break: break-word;
}

/* JSON syntax tint (lime family). */
.json-key {
  color: var(--lime);
}

.json-string {
  color: var(--mint);
}

.json-number {
  color: #ffd23c;
}

.json-bool,
.json-null {
  color: #ff8aa3;
}

.copy-btn {
  flex: 0 0 auto;
  color: var(--muted);
  background: transparent;
}

.copy-icon-btn {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  clip-path: var(--notch-sm);
  border: 1px solid var(--hairline);
  transition: color 180ms ease, background 180ms ease, border-color 180ms ease;
}

.copy-icon-btn .icon {
  width: 14px;
  height: 14px;
  stroke-width: 1.8;
}

.copy-icon-btn:hover {
  color: var(--lime);
  background: rgba(198, 255, 26, 0.08);
  border-color: var(--line);
}

.copy-icon-btn.copied {
  color: var(--ok);
  background: rgba(127, 255, 60, 0.14);
  border-color: rgba(127, 255, 60, 0.4);
}

.tool-output-image {
  display: block;
  width: 100%;
  max-height: 280px;
  object-fit: contain;
  clip-path: var(--notch-sm);
  border: 1px solid var(--line-soft);
  background: rgba(0, 0, 0, 0.4);
}

/* --- Image modal ------------------------------------------------------- */

.image-modal {
  position: fixed;
  z-index: 80;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 34px;
  background: rgba(3, 5, 3, 0.82);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
}

.image-modal.hidden {
  display: none;
}

.image-modal img {
  max-width: min(1120px, 92vw);
  max-height: 86vh;
  object-fit: contain;
  clip-path: var(--notch-lg);
  border: 1px solid var(--line);
  background: #000;
  box-shadow: 0 0 40px rgba(198, 255, 26, 0.18);
}

.image-modal-close {
  position: fixed;
  top: 20px;
  right: 20px;
}

/* --- Final answer markdown -------------------------------------------- */

.final-answer {
  color: var(--text);
  white-space: normal;
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.72;
}

.final-answer > :first-child {
  margin-top: 0;
}

.final-answer > :last-child {
  margin-bottom: 0;
}

.final-answer p,
.final-answer ul,
.final-answer ol,
.final-answer table,
.final-answer pre {
  margin: 0.62em 0;
}

.final-answer h1,
.final-answer h2,
.final-answer h3 {
  margin: 1em 0 0.45em;
  color: var(--text-strong);
  font-family: var(--display);
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  line-height: 1.2;
}

.final-answer h1 {
  font-size: 1.4em;
}

.final-answer h2 {
  font-size: 1.2em;
}

.final-answer h3 {
  font-size: 1.05em;
}

.final-answer code {
  padding: 0.12em 0.4em;
  clip-path: var(--notch-sm);
  color: var(--lime);
  background: rgba(198, 255, 26, 0.1);
  font-family: var(--mono);
  font-size: 0.92em;
}

.final-answer a {
  color: var(--mint);
  text-decoration: none;
  border-bottom: 1px solid rgba(43, 255, 198, 0.45);
}

.final-answer a:hover {
  border-bottom-color: currentColor;
}

.math {
  padding: 0.05em 0.3em;
  color: var(--lime);
  background: rgba(198, 255, 26, 0.08);
  font-family: var(--mono);
}

.final-answer pre {
  overflow: auto;
  padding: 13px 14px;
  clip-path: var(--notch-md);
  color: var(--text);
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid var(--line-soft);
}

.final-answer pre code {
  padding: 0;
  color: inherit;
  background: transparent;
  clip-path: none;
}

.final-answer table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.94em;
}

.final-answer th,
.final-answer td {
  padding: 8px 10px;
  border: 1px solid var(--line-soft);
  text-align: left;
}

.final-answer th {
  color: var(--lime);
  background: rgba(198, 255, 26, 0.06);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.error-bubble {
  border-color: rgba(255, 77, 87, 0.5) !important;
}

.error-bubble p {
  color: var(--err);
}

.empty-note {
  color: var(--faint);
  font-size: 12px;
}

/* --- Keyframes --------------------------------------------------------- */

@keyframes agent-pulse {
  0%, 100% { opacity: 0.6; transform: scale(1); }
  50%      { opacity: 1;   transform: scale(1.35); }
}

@keyframes agent-progress-shift {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

@keyframes ambient-drift {
  0%   { transform: translate3d(0, 0, 0) scale(1); }
  50%  { transform: translate3d(2.5vw, -1.5vh, 0) scale(1.06); }
  100% { transform: translate3d(-1.5vw, 2vh, 0) scale(0.97); }
}

@keyframes scan-scroll {
  0%   { background-position: 0 0; }
  100% { background-position: 0 100%; }
}

@keyframes hero-scan {
  0%, 100% { clip-path: inset(0 0 92% 0); opacity: 0.05; }
  50%      { clip-path: inset(86% 0 0 0); opacity: 0.2; }
}

@keyframes line-sweep {
  0%, 100% { opacity: 0.4; }
  50%      { opacity: 1; }
}

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

/* --- Responsive -------------------------------------------------------- */

@media (max-width: 760px) {
  .topbar {
    top: 10px;
    left: 10px;
    right: 10px;
  }

  .brand {
    max-width: calc(100vw - 100px);
  }

  .brand p {
    display: none;
  }

  .messages {
    gap: 14px;
    padding: 92px 12px 18px;
    scroll-padding: 92px 0 var(--message-bottom-space);
  }

  .app.active {
    --message-bottom-space: 40px;
  }

  .welcome-panel {
    top: calc(50% - 228px);
  }

  .composer,
  .app.active .composer {
    left: 12px;
    width: calc(100vw - 24px);
    bottom: 10px;
    transform: none;
  }

  .app.welcome .composer {
    left: 50%;
    bottom: 50%;
    transform: translate(-50%, 50%);
  }

  .composer-shell,
  .composer:focus-within .composer-shell {
    min-height: 104px;
    padding-bottom: 58px;
  }

  .app.active .composer-shell,
  .app.active .composer:focus-within .composer-shell {
    min-height: 80px;
    padding-bottom: 54px;
  }

  .message-row.user .message-bubble {
    max-width: 91%;
  }

  .message-row.assistant .message-bubble {
    max-width: none;
  }

  .chip-name {
    max-width: 52vw;
  }
}

/* Honor reduced motion: kill the scan / sweep / pulse / drift animations. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .scanlines {
    display: none;
  }

  .welcome-panel h2::after {
    display: none;
  }
}

/* Solid fallback when transparency/backdrop-filter is unavailable. */
@media (prefers-reduced-transparency: reduce) {
  .brand,
  .glass-icon-btn,
  .composer,
  .agent-card,
  .pipeline-strip,
  .message-row.assistant .message-bubble {
    background: var(--panel-solid);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
}

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .brand,
  .glass-icon-btn,
  .composer,
  .image-modal {
    background: var(--panel-solid);
  }
}
