* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(1000px 480px at 8% -12%, rgba(198, 255, 61, 0.09) 0%, transparent 55%),
    var(--bg);
  font-family: var(--font);
}

.app {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100dvh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 20px 16px;
  border-right: 1px solid var(--line);
  background: rgba(14, 22, 48, 0.94);
  backdrop-filter: blur(12px);
}

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

.new-chat, .menu, #send {
  border: 0;
  cursor: pointer;
  font: inherit;
}
.new-chat {
  width: 100%;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
  letter-spacing: -0.03em;
}
.new-chat:hover { filter: brightness(1.05); }

.history { flex: 1; overflow: auto; display: flex; flex-direction: column; gap: 6px; }
.history button {
  text-align: left;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  padding: 9px 10px;
  border-radius: 10px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.history button:hover, .history button.active { background: var(--bg-elev); }
.sidebar-note { color: var(--muted); font-size: 0.72rem; line-height: 1.45; margin: 0; }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 20px 8px;
}
.menu { display: none; background: var(--bg-elev); color: var(--text); border-radius: 10px; width: 40px; height: 40px; }
.status p { margin: 0; }
.status .meta, .count { color: var(--muted); font-size: 0.75rem; font-family: var(--mono); }

.thread {
  flex: 1;
  overflow: auto;
  padding: 8px 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.empty {
  margin: auto;
  max-width: 440px;
  text-align: center;
  color: var(--muted);
  padding: 32px 16px;
}
.empty h1 { color: var(--text); font-size: 1.4rem; margin: 0 0 8px; letter-spacing: -0.03em; }
.bubble {
  max-width: min(720px, 92%);
  padding: 12px 14px;
  border-radius: 16px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.bubble.user { margin-left: auto; background: var(--user); }
.bubble.assistant { background: var(--bg-elev); border: 1px solid var(--line); }
.bubble.assistant.pending::after {
  content: "▍";
  color: var(--accent);
  animation: blink 1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.composer {
  margin: 0 20px 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-chat);
  box-shadow: var(--shadow);
}
.composer textarea {
  width: 100%;
  resize: none;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  line-height: 1.45;
  max-height: 160px;
  outline: none;
}
.composer-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
#send {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
  letter-spacing: -0.03em;
  border-radius: 999px;
  padding: 8px 16px;
}
#send:disabled { opacity: 0.5; cursor: not-allowed; }
.form-error { color: var(--danger); font-size: 0.8rem; margin: 8px 0 0; }
.backdrop { display: none; }

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

@media (max-width: 800px) {
  .app { grid-template-columns: 1fr; }
  .menu { display: inline-flex; align-items: center; justify-content: center; }
  .brand-compact { display: flex; flex: 1; min-width: 0; }
  .brand-compact .brand-wordmark { font-size: 0.98rem; }
  .status { display: none; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(320px, 88vw);
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    z-index: 20;
  }
  .sidebar.open { transform: none; }
  .backdrop { display: block; position: fixed; inset: 0; background: rgba(4, 8, 24, 0.55); z-index: 15; }
}
