:root {
  color-scheme: dark;
  --bg: #0d0c12;
  --card: #17151f;
  --card2: #211e2b;
  --line: #343041;
  --text: #f4f1f8;
  --muted: #aaa3b4;
  --accent: #c6a8ff;
  --accent2: #8f78bf;
  --danger: #ff9b9b;
  --ok: #8ce3ac;
  --warn: #f2ce79;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", sans-serif; }
body { padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom); }
button, textarea, input { font: inherit; }
button { color: inherit; }
.app-shell { width: min(760px, 100%); min-height: 100dvh; margin: 0 auto; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 4; display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 10px; backdrop-filter: blur(18px); background: rgba(13,12,18,.86); border-bottom: 1px solid rgba(255,255,255,.05); }
h1 { font-size: 24px; margin: 2px 0 0; }
.eyebrow { font-size: 10px; letter-spacing: .15em; color: var(--muted); }
.top-actions { display: flex; align-items: center; gap: 10px; }
.api-dot { font-size: 15px; color: #77717f; text-shadow: 0 0 12px currentColor; }
.api-dot.ok { color: var(--ok); }
.api-dot.bad { color: var(--danger); }
.icon-btn { border: 1px solid var(--line); background: var(--card); border-radius: 12px; min-width: 42px; height: 42px; }
.hud { display: flex; gap: 8px; overflow-x: auto; padding: 10px 16px; color: var(--muted); font-size: 13px; scrollbar-width: none; }
.hud span { white-space: nowrap; background: var(--card); border: 1px solid var(--line); padding: 7px 10px; border-radius: 999px; }
.chat { flex: 1; padding: 8px 16px 18px; display: flex; flex-direction: column; gap: 12px; }
.message { border: 1px solid var(--line); border-radius: 18px; padding: 13px 14px; line-height: 1.75; white-space: pre-wrap; overflow-wrap: anywhere; }
.message p { margin: 0; }
.message.user { align-self: flex-end; max-width: 88%; background: #292239; }
.message.assistant { background: var(--card); }
.message.system-card { background: linear-gradient(180deg, rgba(198,168,255,.09), rgba(255,255,255,.02)); }
.message-label { color: var(--accent); font-size: 12px; font-weight: 700; margin-bottom: 5px; }
.updates { margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--line); color: #d7c8f5; font-size: 13px; }
.panels { padding: 0 16px 14px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
details { background: var(--card); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
summary { cursor: pointer; padding: 12px; list-style: none; font-weight: 650; }
summary::-webkit-details-marker { display: none; }
.panel-content { border-top: 1px solid var(--line); padding: 12px; color: #ded9e5; font-size: 14px; line-height: 1.6; }
.tag { display: inline-block; border: 1px solid var(--line); background: var(--card2); padding: 4px 8px; border-radius: 999px; margin: 2px; font-size: 12px; }
.stat { margin: 9px 0; }
.stat-head { display: flex; justify-content: space-between; gap: 8px; }
.bar { height: 7px; margin-top: 5px; border-radius: 99px; background: #302c3b; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: inherit; }
.memory-block + .memory-block { margin-top: 12px; }
.memory-title { font-weight: 700; color: var(--accent); margin-bottom: 4px; }
.item { padding: 6px 0; border-bottom: 1px solid rgba(255,255,255,.055); }
.item:last-child { border-bottom: 0; }
.composer { position: sticky; bottom: 0; z-index: 5; display: grid; grid-template-columns: 1fr auto; gap: 8px; padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); background: rgba(13,12,18,.93); backdrop-filter: blur(18px); border-top: 1px solid rgba(255,255,255,.06); }
textarea, .text-input { width: 100%; border: 1px solid var(--line); border-radius: 14px; padding: 11px 12px; color: var(--text); background: var(--card); outline: none; }
textarea { resize: none; }
textarea:focus, .text-input:focus { border-color: var(--accent2); }
#sendBtn, .dialog-actions button { border: 0; border-radius: 14px; padding: 0 16px; background: var(--accent); color: #17121f; font-weight: 800; }
#sendBtn[disabled] { opacity: .55; }
dialog { width: min(680px, calc(100% - 24px)); max-height: 88dvh; overflow: auto; border: 1px solid var(--line); padding: 0; border-radius: 20px; color: var(--text); background: var(--card); }
dialog::backdrop { background: rgba(0,0,0,.7); backdrop-filter: blur(4px); }
.dialog-card { padding: 16px; }
.dialog-head { display: flex; justify-content: space-between; align-items: center; }
.dialog-head h2 { margin: 0; font-size: 18px; }
.muted { color: var(--muted); font-size: 13px; line-height: 1.5; }
.field-label { display: block; margin: 13px 0 6px; font-size: 13px; font-weight: 700; color: #d8cee8; }
.connection-card { margin-top: 12px; border: 1px solid var(--line); background: var(--card2); padding: 10px 12px; border-radius: 12px; color: var(--muted); font-size: 13px; line-height: 1.55; }
.connection-card.ok { border-color: rgba(140,227,172,.35); color: var(--ok); }
.connection-card.bad { border-color: rgba(255,155,155,.35); color: var(--danger); }
.button-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.secondary { min-height: 42px; border: 1px solid var(--line); border-radius: 12px; background: var(--card2); }
.dialog-actions { display: flex; justify-content: space-between; gap: 8px; margin-top: 10px; }
.dialog-actions button { min-height: 42px; }
.dialog-actions .danger { background: transparent; color: var(--danger); border: 1px solid #633b44; }
@media (max-width: 430px) {
  summary { font-size: 13px; padding: 11px 10px; }
  .message { font-size: 15px; }
}
