/* ============================================================
   WORMGPT — Dark Red Terminal Theme
   ============================================================ */
:root {
  --bg-void: #070101;
  --bg-deep: #0d0303;
  --bg-panel: #140404;
  --bg-raised: #1c0707;
  --bg-hover: #260a0a;

  --red-blood: #8a0f0f;
  --red-core: #e11d2e;
  --red-neon: #ff2a2a;
  --red-soft: #ff6b5e;
  --amber: #ff9d45;

  --text-hi: #ffe9e6;
  --text-mid: #e8a9a0;
  --text-low: #b07a72;

  --line: #3a0f0f;
  --line-soft: #2a0909;

  --glow: 0 0 14px rgba(255, 42, 42, 0.35);
  --glow-strong: 0 0 24px rgba(255, 42, 42, 0.55), 0 0 60px rgba(225, 29, 46, 0.25);

  --radius: 10px;
  --mono: "JetBrains Mono", "Cascadia Code", Consolas, monospace;
  --display: "Share Tech Mono", var(--mono);

  --z-overlay: 30;
  --z-top: 50;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

body {
  background: var(--bg-void);
  color: var(--text-hi);
  font-family: var(--mono);
  font-size: 16px;
  line-height: 1.65;
  overflow: hidden;
}

/* ---------- Ambience layers ---------- */
.scanlines {
  position: fixed; inset: 0; pointer-events: none; z-index: var(--z-overlay);
  background: repeating-linear-gradient(
    to bottom,
    transparent 0 2px,
    rgba(255, 20, 20, 0.02) 2px 4px
  );
}
.vignette {
  position: fixed; inset: 0; pointer-events: none; z-index: var(--z-overlay);
  background: radial-gradient(ellipse at 50% 35%, transparent 40%, rgba(0, 0, 0, 0.55) 100%);
}

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* ---------- Layout ---------- */
.app {
  display: grid;
  grid-template-columns: 290px 1fr;
  height: 100dvh;
}

/* ---------- Sidebar ---------- */
.sidebar {
  background: linear-gradient(180deg, var(--bg-deep) 0%, var(--bg-void) 100%);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 20px 16px;
  gap: 18px;
  min-height: 0;
  transition: margin-left 0.25s ease;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-icon { width: 40px; height: 40px; color: var(--red-neon); filter: drop-shadow(0 0 8px rgba(255,42,42,.6)); }
.brand-text { display: flex; flex-direction: column; }
.brand-name {
  font-family: var(--display);
  font-size: 24px; font-weight: 800; letter-spacing: 2px;
  color: var(--text-hi);
  text-shadow: var(--glow);
}
.brand-name em { font-style: normal; color: var(--red-neon); }
.brand-tag { font-size: 10px; letter-spacing: 4px; color: var(--text-low); }

.side-actions { display: flex; flex-direction: column; gap: 8px; }

.side-btn {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text-mid);
  font-family: var(--mono); font-size: 14px;
  cursor: pointer;
  transition: background-color 0.18s ease, color 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}
.side-btn svg { width: 18px; height: 18px; flex: none; }
.side-btn:hover, .side-btn:focus-visible {
  background: var(--bg-hover);
  border-color: var(--red-blood);
  color: var(--red-soft);
  box-shadow: var(--glow);
}

.side-panel {
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: var(--bg-panel);
  padding: 14px;
}
.panel-title {
  display: flex; align-items: center; gap: 8px;
  font-family: var(--display);
  font-size: 12px; letter-spacing: 3px;
  color: var(--red-soft);
  margin-bottom: 10px;
}
.panel-title svg { width: 14px; height: 14px; }

.stat-list { list-style: none; display: grid; gap: 6px; font-size: 13px; }
.stat-list li { display: flex; justify-content: space-between; gap: 10px; color: var(--text-low); }
.stat-list b { color: var(--text-mid); font-weight: 600; text-align: right; }
.stat-list b.ok { color: #57d98a; }
.stat-list b.busy { color: var(--amber); }
.panel-note { margin-top: 10px; font-size: 11px; color: var(--text-low); line-height: 1.5; }

.side-foot {
  margin-top: auto;
  display: flex; align-items: center; gap: 8px;
  font-size: 11px; color: var(--text-low);
  border-top: 1px solid var(--line-soft);
  padding-top: 12px;
}
.pulse-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--red-neon);
  box-shadow: var(--glow);
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; box-shadow: 0 0 8px rgba(255,42,42,.5); }
  50% { opacity: .45; box-shadow: 0 0 16px rgba(255,42,42,.9); }
}

/* ---------- Main ---------- */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }

.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(13, 3, 3, 0.85);
  backdrop-filter: blur(6px);
  z-index: 10;
}
.topbar-title {
  font-family: var(--display); font-size: 14px; letter-spacing: 1px;
  color: var(--text-mid);
  display: flex; align-items: center; gap: 8px;
}
.terminal-prompt { color: var(--red-neon); text-shadow: var(--glow); }
.topbar-badges { margin-left: auto; display: flex; gap: 8px; }

.badge {
  font-size: 10px; letter-spacing: 2px;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text-low);
  background: var(--bg-panel);
  white-space: nowrap;
}
.badge-red {
  color: var(--red-soft);
  border-color: var(--red-blood);
  text-shadow: 0 0 8px rgba(255,42,42,.5);
}
.badge.offline { color: #ff5b5b; border-color: #6b1414; }

.icon-btn {
  display: grid; place-items: center;
  width: 38px; height: 38px;
  background: transparent; border: 1px solid var(--line);
  border-radius: 8px; color: var(--text-mid);
  cursor: pointer;
  transition: background-color 0.18s ease, color 0.18s ease;
}
.icon-btn:hover, .icon-btn:focus-visible { background: var(--bg-hover); color: var(--red-soft); }
.icon-btn svg { width: 18px; height: 18px; }

/* ---------- Chat ---------- */
.chat { flex: 1; min-height: 0; overflow-y: auto; }
.chat-inner {
  max-width: 860px; margin: 0 auto;
  padding: 28px 24px 12px;
  display: flex; flex-direction: column; gap: 18px;
}

.welcome {
  text-align: center;
  padding: 8vh 16px 4vh;
  display: flex; flex-direction: column; align-items: center; gap: 16px;
}
.welcome-glyph svg {
  width: 96px; height: 96px;
  color: var(--red-neon);
  filter: drop-shadow(0 0 18px rgba(255, 42, 42, 0.55));
  animation: breathe 5s ease-in-out infinite;
}
@keyframes breathe {
  0%, 100% { filter: drop-shadow(0 0 12px rgba(255,42,42,.35)); transform: scale(1); }
  50% { filter: drop-shadow(0 0 26px rgba(255,42,42,.7)); transform: scale(1.03); }
}
.welcome-title {
  font-family: var(--display);
  font-size: clamp(40px, 7vw, 64px);
  letter-spacing: 8px;
  text-shadow: var(--glow-strong);
  animation: flicker 4s linear infinite;
}
.welcome-title em { font-style: normal; color: var(--red-neon); }
@keyframes flicker {
  0%, 92%, 96%, 100% { opacity: 1; }
  93%, 95% { opacity: 0.72; }
  94% { opacity: 0.9; }
}
.welcome-sub { color: var(--text-low); font-size: 14px; max-width: 60ch; }

.suggestions {
  display: grid; grid-template-columns: repeat(2, 1fr);
  gap: 12px; margin-top: 16px; width: 100%; max-width: 720px;
}
.suggestion {
  text-align: left;
  padding: 14px 16px;
  background: var(--bg-panel);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  color: var(--text-mid);
  font-family: var(--mono); font-size: 13.5px;
  cursor: pointer;
  transition: border-color 0.18s ease, background-color 0.18s ease, color 0.18s ease, box-shadow 0.18s ease;
}
.suggestion:hover, .suggestion:focus-visible {
  border-color: var(--red-blood);
  background: var(--bg-raised);
  color: var(--text-hi);
  box-shadow: var(--glow);
}


/* ---------- Messages ---------- */
.msg { display: flex; flex-direction: column; gap: 6px; }
.msg-header {
  display: flex; align-items: center; gap: 8px;
  font-family: var(--display); font-size: 11px; letter-spacing: 2px;
}
.msg-user { align-self: flex-end; max-width: 85%; }
.msg-user .msg-header { color: var(--amber); flex-direction: row-reverse; }
.msg-assistant { max-width: 92%; }
.msg-assistant .msg-header { color: var(--red-neon); }
.msg-avatar {
  width: 22px; height: 22px;
  display: grid; place-items: center;
  border: 1px solid currentColor; border-radius: 6px;
  font-size: 10px;
}
.msg-body {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 15px;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}
.msg-user .msg-body {
  background: linear-gradient(135deg, #2a0d02, #1f0808);
  border: 1px solid #4a1d08;
  border-bottom-right-radius: 2px;
}
.msg-assistant .msg-body {
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-bottom-left-radius: 2px;
  box-shadow: inset 0 0 30px rgba(120, 10, 10, 0.08);
}
.msg-body code {
  background: #1a0505; border: 1px solid var(--line-soft);
  padding: 1px 6px; border-radius: 5px;
  color: var(--red-soft); font-size: 0.92em;
}
.msg-body pre {
  background: #0c0202; border: 1px solid var(--line);
  border-radius: 8px; padding: 14px; overflow-x: auto;
  margin: 10px 0; line-height: 1.55;
}
.msg-body pre code { background: none; border: none; padding: 0; color: #ffb3ab; }
.msg-body strong { color: #ffd9d4; }
.msg.error .msg-body { border-color: #6b1414; color: #ff8a8a; background: #1c0404; }

.typing-dots { display: inline-flex; gap: 5px; align-items: center; padding: 4px 0; }
.typing-dots i {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--red-neon);
  animation: blink 1.2s infinite;
}
.typing-dots i:nth-child(2) { animation-delay: 0.2s; }
.typing-dots i:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

.caret::after {
  content: "▊";
  color: var(--red-neon);
  animation: blink 1s steps(1) infinite;
}

/* ---------- Composer ---------- */
.composer { padding: 14px 24px 20px; border-top: 1px solid var(--line-soft); background: var(--bg-deep); }
.composer-box {
  max-width: 860px; margin: 0 auto;
  display: flex; align-items: flex-end; gap: 10px;
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 10px 10px 18px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.composer-box:focus-within { border-color: var(--red-blood); box-shadow: var(--glow); }
#input {
  flex: 1; resize: none;
  background: transparent; border: none; outline: none;
  color: var(--text-hi);
  font-family: var(--mono); font-size: 15.5px; line-height: 1.6;
  max-height: 180px; padding: 6px 0;
}
#input::placeholder { color: var(--text-low); }
.send-btn {
  flex: none;
  width: 44px; height: 44px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--red-core), #7a0c14);
  border: none; border-radius: 10px;
  color: #fff;
  cursor: pointer;
  box-shadow: 0 0 14px rgba(225, 29, 46, 0.4);
  transition: box-shadow 0.2s ease, opacity 0.2s ease, transform 0.15s ease;
}
.send-btn svg { width: 20px; height: 20px; }
.send-btn:hover:not(:disabled), .send-btn:focus-visible:not(:disabled) {
  box-shadow: 0 0 24px rgba(255, 42, 42, 0.75);
}
.send-btn:active:not(:disabled) { transform: translateY(1px); }
.send-btn:disabled { opacity: 0.35; cursor: not-allowed; box-shadow: none; }

.composer-meta {
  max-width: 860px; margin: 8px auto 0;
  display: flex; justify-content: space-between; gap: 12px;
  font-size: 11px; color: var(--text-low);
}
.kbd-hint kbd {
  border: 1px solid var(--line); border-bottom-width: 2px;
  border-radius: 4px; padding: 0 5px;
  font-family: var(--mono); font-size: 10px;
  background: var(--bg-panel);
}
.composer-error { color: #ff6b6b; }

/* ---------- Scrollbar ---------- */
.chat::-webkit-scrollbar, .msg-body pre::-webkit-scrollbar { width: 8px; height: 8px; }
.chat::-webkit-scrollbar-thumb, .msg-body pre::-webkit-scrollbar-thumb {
  background: var(--line); border-radius: 4px;
}
.chat::-webkit-scrollbar-thumb:hover { background: var(--red-blood); }

/* ---------- Focus visibility ---------- */
:where(button, textarea, [tabindex]):focus-visible {
  outline: 2px solid var(--red-neon);
  outline-offset: 2px;
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: 290px; z-index: var(--z-top);
    box-shadow: 8px 0 40px rgba(0, 0, 0, 0.7);
  }
  .sidebar.collapsed { margin-left: -290px; }
  .suggestions { grid-template-columns: 1fr; }
  .msg-user, .msg-assistant { max-width: 100%; }
}
@media (min-width: 901px) {
  .sidebar.collapsed { display: none; }
}

