: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;
  --global-radius: 40px;

  /* 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;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

*::-webkit-scrollbar {
  display: none;
  width: 0;
  height: 0;
}

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,
  .loading-orbit,
  .loading-dots {
    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-system {
  flex-direction: column;
}

.msg-bubble {
  min-width: 0;
  max-width: 100%;
  padding: 12px 16px;
  border-radius: var(--global-radius);
  font-size: 15px;
  line-height: 1.6;
  border: none;
  background: transparent;
  color: var(--text-primary);
  box-shadow: none;
}

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

.msg-assistant .msg-bubble {
  background: var(--bg-primary);
  border-radius: var(--global-radius);
}

.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;
}

.app-suggestion {
  display: block;
  width: 100%;
  margin: 8px 0;
  padding: 11px 14px;
  border: 1px solid #bfdbfe;
  border-radius: var(--global-radius);
  background: #eff6ff;
  color: #1d4ed8;
  font: inherit;
  line-height: 1.45;
  text-align: left;
  cursor: pointer;
  transition:
    background 0.15s ease,
    border-color 0.15s ease,
    transform 0.15s ease;
}

.app-suggestion:hover,
.app-suggestion:focus-visible {
  background: #dbeafe;
  border-color: #60a5fa;
  outline: none;
  transform: translateY(-1px);
}

.recovery-message {
  margin-bottom: 12px !important;
}

.keyword-suggestions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  width: 100%;
  margin-top: 14px;
}

.keyword-suggestion {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 100%;
  padding: 9px 12px;
  border: 1px solid #bfdbfe;
  border-radius: var(--global-radius);
  background: #eff6ff;
  color: #1d4ed8;
  font: inherit;
  line-height: 1.3;
  white-space: normal;
  cursor: pointer;
}

.keyword-suggestion:hover,
.keyword-suggestion:focus-visible {
  background: #dbeafe;
  border-color: #60a5fa;
  outline: none;
}

.loading-state {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 30px;
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.02em;
}

.loading-orbit {
  position: relative;
  display: inline-block;
  width: 24px;
  height: 24px;
  border: 1px solid #bfdbfe;
  border-radius: 50%;
  animation: loading-spin 1.8s linear infinite;
}

.loading-orbit::after {
  content: "";
  position: absolute;
  inset: 7px;
  border-radius: 50%;
  background: var(--brand-primary);
  box-shadow: 0 0 10px rgba(37, 99, 235, 0.45);
}

.loading-orbit span {
  position: absolute;
  top: -3px;
  left: 9px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #60a5fa;
}

.loading-orbit span:nth-child(2) {
  top: 17px;
  left: 1px;
  background: #93c5fd;
}

.loading-orbit span:nth-child(3) {
  top: 17px;
  left: 17px;
  background: #2563eb;
}

.loading-dots {
  display: inline-block;
  width: 18px;
  overflow: hidden;
  vertical-align: bottom;
  animation: loading-dots 1.2s steps(4, end) infinite;
}

@keyframes loading-spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes loading-dots {
  0%,
  20% {
    width: 0;
  }
  50% {
    width: 9px;
  }
  80%,
  100% {
    width: 18px;
  }
}

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

.meta-line {
  display: none;
  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: var(--global-radius);
  padding: 10px 14px;
  box-shadow: 0 4px 20px -2px rgba(16, 24, 40, 0.06);
  max-width: 768px;
}

.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;
}

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