:root {
  --bg: #0c100e;
  --bg-elevated: #141a16;
  --bg-panel: rgba(20, 28, 23, 0.82);
  --border: rgba(125, 206, 160, 0.14);
  --text: #e8f0ea;
  --text-muted: #93a399;
  --accent: #7dcea0;
  --accent-strong: #5fbf86;
  --accent-dim: rgba(125, 206, 160, 0.12);
  --user-bubble: #1e3a2c;
  --assistant-bubble: #171d19;
  --danger: #e07a7a;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  --radius: 18px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Menlo, monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.bg-glow {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(900px 500px at 15% -10%, rgba(95, 191, 134, 0.16), transparent 60%),
    radial-gradient(700px 420px at 90% 10%, rgba(88, 140, 180, 0.1), transparent 55%),
    radial-gradient(600px 400px at 50% 110%, rgba(125, 206, 160, 0.08), transparent 50%);
  z-index: 0;
}

.app {
  position: relative;
  z-index: 1;
  max-width: 860px;
  margin: 0 auto;
  min-height: 100%;
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: 0 14px env(safe-area-inset-bottom);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 4px 12px;
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  background: rgba(12, 16, 14, 0.75);
  z-index: 5;
}

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

.logo {
  color: var(--accent);
  flex-shrink: 0;
}

.brand h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.tagline {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.78rem;
}

.status-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  font-size: 0.82rem;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #888;
  box-shadow: 0 0 0 3px rgba(136, 136, 136, 0.15);
}

.status-dot.ready {
  background: var(--accent-strong);
  box-shadow: 0 0 0 3px rgba(95, 191, 134, 0.18);
}

.status-dot.degraded {
  background: #d4a017;
  box-shadow: 0 0 0 3px rgba(212, 160, 23, 0.18);
}

.status-dot.down {
  background: var(--danger);
  box-shadow: 0 0 0 3px rgba(224, 122, 122, 0.18);
}

.ghost-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  border-radius: 999px;
  padding: 6px 12px;
  font: inherit;
  font-size: 0.78rem;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.ghost-btn:hover {
  color: var(--text);
  border-color: rgba(125, 206, 160, 0.35);
  background: var(--accent-dim);
}

.messages {
  overflow-y: auto;
  padding: 18px 2px 12px;
  scroll-behavior: smooth;
}

.welcome {
  margin: 28px auto 12px;
  max-width: 560px;
  text-align: center;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 4px);
  padding: 28px 22px;
  box-shadow: var(--shadow);
}

.welcome h2 {
  margin: 0 0 8px;
  font-size: 1.35rem;
}

.welcome p {
  margin: 0 auto 18px;
  color: var(--text-muted);
  max-width: 42ch;
}

.suggestions {
  display: grid;
  gap: 8px;
}

@media (min-width: 560px) {
  .suggestions {
    grid-template-columns: 1fr 1fr;
  }
}

.suggestions button {
  appearance: none;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.02);
  color: var(--text);
  border-radius: 14px;
  padding: 12px 14px;
  font: inherit;
  font-size: 0.88rem;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.15s;
}

.suggestions button:hover {
  border-color: rgba(125, 206, 160, 0.4);
  background: var(--accent-dim);
  transform: translateY(-1px);
}

.row {
  display: flex;
  margin: 0 0 14px;
}

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

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

.bubble {
  max-width: min(92%, 640px);
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px solid var(--border);
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.95rem;
}

.row.user .bubble {
  background: var(--user-bubble);
  border-color: rgba(125, 206, 160, 0.22);
  border-bottom-right-radius: 6px;
}

.row.assistant .bubble {
  background: var(--assistant-bubble);
  border-bottom-left-radius: 6px;
}

.bubble .role {
  display: block;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.bubble.error {
  border-color: rgba(224, 122, 122, 0.4);
  color: #ffc9c9;
}

.bubble .cursor {
  display: inline-block;
  width: 0.5ch;
  margin-left: 1px;
  background: var(--accent);
  animation: blink 1s steps(1) infinite;
}

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

.composer {
  padding: 8px 0 14px;
  position: sticky;
  bottom: 0;
  background: linear-gradient(to top, rgba(12, 16, 14, 0.96) 70%, rgba(12, 16, 14, 0));
}

#chat-form {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 10px 10px 10px 14px;
  box-shadow: var(--shadow);
}

#prompt {
  flex: 1;
  resize: none;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.98rem;
  line-height: 1.45;
  max-height: 160px;
  min-height: 24px;
  padding: 6px 0;
}

#prompt::placeholder {
  color: #6f7d74;
}

#btn-send {
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 14px;
  background: var(--accent-strong);
  color: #0b140f;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform 0.12s, filter 0.12s, opacity 0.12s;
}

#btn-send:hover:not(:disabled) {
  filter: brightness(1.06);
  transform: translateY(-1px);
}

#btn-send:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.footnote {
  margin: 8px 4px 0;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.72rem;
}

.sources {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
}

.sources-label {
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.68rem;
  margin-bottom: 6px;
}

.sources ol {
  margin: 0;
  padding-left: 1.2rem;
  color: var(--text-muted);
}

.sources a {
  color: var(--accent);
  text-decoration: none;
}

.sources a:hover {
  text-decoration: underline;
}

.sources-error {
  color: #e8b4b4;
  border-top: 1px solid rgba(224, 122, 122, 0.35);
}

#search-toggle[data-mode="on"] {
  color: var(--accent);
  border-color: rgba(125, 206, 160, 0.45);
}

#search-toggle[data-mode="off"] {
  opacity: 0.75;
}

.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: 520px) {
  .status-text {
    display: none;
  }

  .brand h1 {
    font-size: 1.05rem;
  }
}
