:root {
  /* Color tokens (styleguide) */
  --bg-primary: #FFFFFF;
  --bg-secondary: #F8FAFC;
  --bg-accent: #F1F5F9;
  --text-primary: #0F172A;
  --text-secondary: #64748B;
  --brand-primary: #2563EB;
  --brand-gradient: linear-gradient(135deg, #3B82F6, #8B5CF6);
  --border-subtle: #E2E8F0;

  /* fonts */
  --font-display: "Space Grotesk", system-ui, -apple-system, "Inter", sans-serif;
  --font-body: "Inter", system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-body);
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  position: relative;
  overflow-x: hidden;
}

/* Subtle CRT-style scanline overlay - quiet ambient texture, not a distraction */
.scanlines {
  display: none;
}

/* ---------- Topbar ---------- */
.topbar {
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 20px;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-primary);
  position: sticky;
  top: 0;
  z-index: 20;
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-mark svg {
  display: block;
}

.sweep {
  transform-origin: 20px 20px;
  animation: sweep 4s linear infinite;
}

@keyframes sweep {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

.logo-text {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}

.logo-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.25rem;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.logo-sub {
  font-family: var(--font-body);
  font-size: 12px;
  color: var(--text-secondary);
}

.status {
  display: none;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--paper-dim);
  transition: background 0.2s ease;
}

.status-dot.connected {
  background: var(--ok);
  box-shadow: 0 0 8px var(--ok);
}

.status-dot.error {
  background: var(--err);
  box-shadow: 0 0 8px var(--err);
}

.status-dot.busy {
  background: var(--signal);
  box-shadow: 0 0 8px var(--signal);
  animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

@media (prefers-reduced-motion: reduce) {
  .sweep,
  .status-dot.busy {
    animation: none;
  }
}

/* ---------- Chat shell ---------- */
.chat-shell {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  max-width: 768px;
  width: 100%;
  margin: 0 auto;
  padding: 20px 18px 100px; /* bottom padding to allow input overlap */
  position: relative;
  z-index: 2;
  min-height: 0;
}

.chat-log {
  flex: 1 1 auto;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding-bottom: 8px;
}

.msg {
  display: flex;
  max-width: 88%;
}

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

.msg-assistant,
.msg-system {
  align-self: flex-start;
}

.msg-bubble {
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.6;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-primary);
  box-shadow: none;
}

.msg-user .msg-bubble {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border-color: var(--border-subtle);
  border-radius: 18px 18px 4px 18px;
}

.msg-assistant .msg-bubble {
  background: var(--bg-primary);
  border-color: var(--border-subtle);
  border-radius: 18px 18px 18px 4px;
}

.msg-system .msg-bubble {
  background: var(--bg-accent);
  border-style: dashed;
  color: var(--text-secondary);
}

.msg-bubble p {
  margin: 0 0 8px;
}

.msg-bubble p:last-child {
  margin-bottom: 0;
}

.msg-bubble .hint {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-secondary);
}

.msg-bubble ol,
.msg-bubble ul {
  margin: 6px 0;
  padding-left: 20px;
}

.msg-bubble strong {
  color: var(--signal);
  font-weight: 600;
}

.msg-assistant .msg-bubble strong {
  color: #2563EB;
}

.meta-line {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.meta-line.fallback {
  color: var(--signal);
}

.meta-line.error {
  color: var(--err);
}

.cursor {
  display: inline-block;
  width: 7px;
  height: 14px;
  background: var(--signal);
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: blink 0.9s steps(1) infinite;
}

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

/* ---------- Composer ---------- */
.composer {
  position: sticky;
  bottom: 20px;
  display: flex;
  gap: 10px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-primary);
  border-radius: 24px;
  padding: 10px 14px;
  box-shadow: 0 4px 20px -2px rgba(16, 24, 40, 0.06);
  max-width: 768px;
  margin: 0 auto;
}

.composer:focus-within {
  box-shadow: 0 6px 30px -6px rgba(37, 99, 235, 0.18);
  border-color: var(--brand-primary);
}

#promptInput {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 1rem;
  padding: 8px 0;
}

#promptInput::placeholder {
  color: var(--text-secondary);
}

#sendBtn {
  background: var(--brand-primary);
  color: #fff;
  border: none;
  width: 44px;
  height: 44px;
  border-radius: 9999px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.12s ease;
  flex-shrink: 0;
}

#sendBtn:hover {
  transform: translateY(-2px);
}

#sendBtn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

/* Scrollbar - keep it quiet */
.chat-log::-webkit-scrollbar {
  width: 8px;
}

.chat-log::-webkit-scrollbar-thumb {
  background: var(--border-subtle);
  border-radius: 6px;
}

@media (max-width: 560px) {
  .chat-shell {
    padding: 14px 12px 120px;
  }
  .logo-sub {
    display: none;
  }
  .msg {
    max-width: 96%;
  }
  .composer {
    bottom: 12px;
    padding: 10px 12px;
  }
}
