:root {
  --bg: #0f1420;
  --panel: #171e2e;
  --bubble-user: #1d4ed8;
  --bubble-assistant: #1e2638;
  --text: #e6e9f0;
  --muted: #8b93a7;
  --accent: #3b82f6;
  --ok: #22c55e;
  --bad: #ef4444;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}

body {
  display: flex;
  flex-direction: column;
}

header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--panel);
  border-bottom: 1px solid #232c42;
  flex: none;
}

header h1 {
  font-size: 17px;
  font-weight: 600;
  margin: 0;
  flex: 1;
}

#token-btn {
  background: none;
  border: 1px solid #2a3550;
  color: var(--muted);
  border-radius: 8px;
  padding: 4px 10px;
  font-size: 13px;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: none;
}
.dot.on  { background: var(--ok); box-shadow: 0 0 6px var(--ok); }
.dot.off { background: var(--bad); }
.dot.busy { background: #eab308; }

main {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.msg {
  max-width: 86%;
  padding: 10px 13px;
  border-radius: 16px;
  white-space: pre-wrap;
  word-wrap: break-word;
  font-size: 16px;
}
.msg.user {
  align-self: flex-end;
  background: var(--bubble-user);
  border-bottom-right-radius: 4px;
}
.msg.assistant {
  align-self: flex-start;
  background: var(--bubble-assistant);
  border-bottom-left-radius: 4px;
}
.msg.meta {
  align-self: center;
  background: none;
  color: var(--muted);
  font-size: 13px;
  padding: 2px 8px;
}
.msg code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 14px;
  background: #0b101c;
  border-radius: 4px;
  padding: 1px 5px;
}
.msg pre {
  background: #0b101c;
  border-radius: 8px;
  padding: 8px 10px;
  overflow-x: auto;
  margin: 6px 0;
}
.msg pre code { background: none; padding: 0; }

footer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
  background: var(--panel);
  border-top: 1px solid #232c42;
  flex: none;
}

#input {
  flex: 1;
  resize: none;
  border: 1px solid #2a3550;
  background: var(--bg);
  color: var(--text);
  border-radius: 18px;
  padding: 10px 14px;
  font: inherit;
  font-size: 16px; /* >=16px stops iOS zoom-on-focus */
  max-height: 40vh;
  outline: none;
}
#input:focus { border-color: var(--accent); }

footer button {
  flex: none;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 17px;
  display: flex;
  align-items: center;
  justify-content: center;
}
footer button:disabled {
  background: #232c42;
  color: var(--muted);
}
