:root {
  --bg: #0b0f12;
  --surface: #11171c;
  --surface-2: #171f26;
  --line: #26323a;
  --line-soft: #1e2830;
  --text: #e9eef0;
  --muted: #97a5ad;
  --accent: #58c7a4;
  --accent-ink: #06251c;
  --warn: #e0a458;
  --danger: #e6897c;
  --radius: 10px;
  --space: 8px;
  --reading: 820px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 var(--font);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button, textarea, input { font: inherit; color: inherit; }
button { cursor: pointer; }

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

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.app {
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 60px;
  padding: 10px 24px;
  border-bottom: 1px solid var(--line-soft);
}

.brand { display: flex; align-items: baseline; gap: 8px; white-space: nowrap; }

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border: 1.5px solid var(--accent);
  border-radius: 7px;
  color: var(--accent);
  font-weight: 700;
  font-size: 15px;
  line-height: 1;
  transform: translateY(3px);
}

.brand-name { font-weight: 650; letter-spacing: -0.02em; font-size: 16px; }
.brand-sub { color: var(--muted); font-size: 12px; letter-spacing: 0.04em; }

.session-info { display: flex; align-items: center; gap: 16px; min-width: 0; }

.bridge-state {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.state-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--muted);
}

.bridge-state.online .state-dot { background: var(--accent); }
.bridge-state.offline .state-dot { background: var(--danger); }

.model-chip {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 5px 11px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  font-family: var(--mono);
  font-size: 12px;
  white-space: nowrap;
}

.chip-divider { width: 1px; height: 13px; background: var(--line); }
#provider-label { color: var(--accent); }

.text-button {
  padding: 5px 2px;
  background: none;
  border: 0;
  color: var(--muted);
  font-size: 13px;
}
.text-button:hover { color: var(--text); }

/* ---------- conversation ---------- */

.chat {
  overflow-y: auto;
  padding: 40px 24px 24px;
  scrollbar-gutter: stable;
}

.thread, .empty-state {
  width: 100%;
  max-width: var(--reading);
  margin: 0 auto;
}

.thread { display: none; }
.thread.visible { display: block; }

.empty-state {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 12px;
}

.empty-state h1 {
  margin: 0;
  font-size: 27px;
  font-weight: 620;
  letter-spacing: -0.03em;
}

.empty-state p { margin: 0; color: var(--muted); }
.empty-state strong { color: var(--text); font-weight: 560; }

.suggestions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

.suggestions button {
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
}
.suggestions button:hover { color: var(--text); border-color: var(--accent); }

.message { margin: 0 0 28px; }
.message:last-child { margin-bottom: 0; }

.message-role {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.message-body {
  max-width: 78%;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message.user { display: flex; flex-direction: column; align-items: flex-end; }
.message.user .message-role { align-self: flex-end; }
.message.user .message-body {
  padding: 11px 15px;
  background: var(--surface-2);
  border-radius: var(--radius);
}

.message.assistant .message-body { color: var(--text); }

.message.error .message-body {
  padding: 11px 15px;
  border-left: 2px solid var(--danger);
  background: rgba(230, 137, 124, 0.07);
  color: var(--danger);
  border-radius: 0 var(--radius) var(--radius) 0;
}

.message-body code {
  font-family: var(--mono);
  font-size: 0.9em;
  background: var(--surface-2);
  padding: 1px 4px;
  border-radius: 4px;
}

.message-body pre {
  margin: 12px 0;
  padding: 13px 15px;
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  overflow-x: auto;
  white-space: pre;
}
.message-body pre code { background: none; padding: 0; }

.reasoning {
  margin-bottom: 10px;
  padding-left: 12px;
  border-left: 2px solid var(--warn);
  color: var(--muted);
  font-size: 13px;
  white-space: pre-wrap;
}
.reasoning summary { cursor: pointer; color: var(--warn); }

.caret::after {
  content: "";
  display: inline-block;
  width: 7px;
  height: 15px;
  margin-left: 2px;
  vertical-align: -2px;
  background: var(--accent);
  animation: blink 1.1s steps(2, start) infinite;
}

@keyframes blink { to { opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  .caret::after { animation: none; }
  * { scroll-behavior: auto !important; transition: none !important; }
}

/* ---------- composer ---------- */

.composer {
  padding: 12px 24px calc(16px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line-soft);
  background: var(--bg);
}

.composer-inner {
  max-width: var(--reading);
  margin: 0 auto;
}

#input {
  display: block;
  width: 100%;
  min-height: 46px;
  max-height: 180px;
  padding: 11px 14px;
  resize: none;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  line-height: 1.5;
}
#input::placeholder { color: var(--muted); }
#input:focus { border-color: var(--accent); outline: none; }

.composer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 8px;
}

.composer-hint { color: var(--muted); font-size: 12px; }
.composer-buttons { display: flex; align-items: center; gap: 12px; }

.primary-button {
  padding: 8px 20px;
  border: 0;
  border-radius: 7px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 620;
}
.primary-button:hover { background: #71d7b6; }
.primary-button:disabled { opacity: 0.45; cursor: not-allowed; }

.secondary-button {
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-2);
}
.secondary-button:hover { border-color: var(--accent); }

.stop-button { color: var(--danger); }

/* ---------- settings ---------- */

.scrim {
  position: fixed;
  inset: 0;
  background: rgba(4, 7, 9, 0.65);
}

.settings {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(380px, 100%);
  padding: 20px;
  background: var(--surface);
  border-left: 1px solid var(--line);
  overflow-y: auto;
  transform: translateX(100%);
  transition: transform 160ms ease;
}

.settings.open { transform: translateX(0); }
.settings[aria-hidden="true"] { visibility: hidden; }
.settings.open[aria-hidden="false"] { visibility: visible; }

.settings-head { display: flex; align-items: center; justify-content: space-between; }
.settings-head h2 { margin: 0; font-size: 16px; font-weight: 620; }

.settings-body { margin-top: 28px; display: grid; gap: 28px; }

.setting { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.setting label, .setting-label { font-weight: 560; }
.setting p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }
.setting input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); margin-top: 3px; }

.connection dl { margin: 12px 0 0; display: grid; gap: 8px; }
.connection dl > div { display: grid; grid-template-columns: 78px 1fr; gap: 8px; font-size: 13px; }
.connection dt { color: var(--muted); }
.connection dd { margin: 0; font-family: var(--mono); font-size: 12px; overflow-wrap: anywhere; }
.connection .note { margin-top: 18px; color: var(--muted); font-size: 12px; }
.connection code { font-family: var(--mono); color: var(--text); }

/* ---------- narrow screens ---------- */

@media (max-width: 720px) {
  .topbar { padding: 8px 14px; gap: 10px; flex-wrap: wrap; min-height: 52px; }
  .brand-sub { display: none; }
  .session-info { gap: 12px; }
  .bridge-state { display: none; }
  .chat { padding: 28px 16px 16px; }
  .composer { padding: 10px 14px calc(12px + env(safe-area-inset-bottom)); }
  .composer-hint { display: none; }
  .composer-row { justify-content: flex-end; }
  .message-body { max-width: 92%; }
  .empty-state h1 { font-size: 23px; }
}
