:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1d222c;
  --border: #2a3040;
  --text: #e6e9ef;
  --muted: #8b93a7;
  --accent: #5b9dff;
  --user-bubble: #2b4a7a;
  --assistant-bubble: #232836;
  --ok: #3fb96f;
  --bad: #e05661;
}
* { box-sizing: border-box; }
/* author display rules would otherwise beat the UA [hidden] rule and keep
   "hidden" panels visible — this is the real fix for that class of bug */
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
.app {
  max-width: 820px;
  height: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding: 0 16px;
}
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 4px;
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo { font-size: 28px; }
h1 { font-size: 17px; margin: 0; }
.brand p { margin: 0; font-size: 12px; color: var(--muted); }
.header-actions { display: flex; align-items: center; gap: 10px; }
.status { font-size: 12px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status.up .dot { background: var(--ok); box-shadow: 0 0 6px var(--ok); }
.status.down .dot { background: var(--bad); }
.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 22px;
  padding: 8px 4px 10px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}
.stat { display: inline-flex; align-items: center; gap: 6px; }
.stat-label { color: var(--muted); }
.stat-value { font-variant-numeric: tabular-nums; }
.ctxwrap { display: inline-flex; align-items: center; gap: 8px; }
.ctxbar {
  display: inline-block;
  width: 110px;
  height: 5px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 3px;
  overflow: hidden;
}
#ctxFill {
  display: block;
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.25s ease;
}
#ctxFill.warn { background: #d9a13f; }
#ctxFill.danger { background: var(--bad); }
@media (prefers-reduced-motion: reduce) { #ctxFill { transition: none; } }
.chat {
  flex: 1;
  overflow-y: auto;
  padding: 20px 4px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.msg { display: flex; }
.msg.user { justify-content: flex-end; }
.msg.assistant { flex-direction: column; align-items: flex-start; }
.meta { font-size: 11px; color: var(--muted); margin: 4px 2px 0; font-variant-numeric: tabular-nums; }
.bubble {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: 14px;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.msg.user .bubble { background: var(--user-bubble); border-bottom-right-radius: 4px; }
.msg.assistant .bubble { background: var(--assistant-bubble); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.bubble.typing::after {
  content: "▍";
  animation: blink 1s steps(1) infinite;
  color: var(--muted);
}
@keyframes blink { 50% { opacity: 0; } }
#composer {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding: 12px 0 18px;
  border-top: 1px solid var(--border);
}
#input {
  flex: 1;
  resize: none;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px 14px;
  font: inherit;
  outline: none;
  max-height: 160px;
}
#input:focus { border-color: var(--accent); }
button {
  border: none;
  border-radius: 12px;
  padding: 11px 16px;
  font: inherit;
  cursor: pointer;
}
#sendBtn { background: var(--accent); color: #fff; }
#sendBtn:disabled { opacity: 0.5; cursor: default; }
.ghost {
  background: var(--panel-2);
  color: var(--muted);
  border: 1px solid var(--border);
}
.ghost:hover { color: var(--text); }
.ghost.active { color: var(--accent); border-color: var(--accent); }
.remember {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  padding-right: 16px;
  border-right: 1px solid var(--border);
}
.remember input { position: absolute; opacity: 0; pointer-events: none; }
.remember .track {
  position: relative;
  width: 28px;
  height: 15px;
  border-radius: 8px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  transition: background 0.15s ease;
}
.remember .knob {
  position: absolute;
  top: 1px;
  left: 1px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--muted);
  transition: left 0.15s ease, background 0.15s ease;
}
.remember input:checked + .track { background: var(--accent); }
.remember input:checked + .track .knob { left: 14px; background: #fff; }
.remember-label { font-variant-numeric: tabular-nums; }
@media (prefers-reduced-motion: reduce) {
  .remember .track, .remember .knob { transition: none; }
}
