:root {
  --bg: #0f1117; --panel: #171a23; --panel2: #1f2330; --line: #2a2f3d;
  --text: #e8eaf0; --muted: #8b91a3; --accent: #6ea8fe; --accent2: #8ce0c1;
  --red: #ff5c5c; --orange: #ffb347; --green: #5fd38d;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
[hidden] { display: none !important; }
button { font: inherit; cursor: pointer; border: 0; border-radius: 10px; padding: 10px 16px;
  background: var(--accent); color: #0b1020; font-weight: 600; }
button.link { background: none; color: var(--muted); text-decoration: underline; font-weight: 400; }
button.danger { background: var(--red); color: #fff; }
button.icon-btn { background: none; color: var(--text); font-size: 20px; padding: 4px 10px; }
input, textarea { width: 100%; font: inherit; color: var(--text); background: var(--panel2);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
textarea { resize: vertical; }
.muted { color: var(--muted); } .small { font-size: 13px; } .error { color: var(--red); }
.screen { min-height: 100%; }

/* login */
#login { display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-box { width: 100%; max-width: 360px; text-align: center; }
.login-box form { display: grid; gap: 10px; margin: 16px 0; }
.logo { width: 64px; height: 64px; margin: 0 auto 12px; border-radius: 18px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #0b1020; font-weight: 800; font-size: 32px; }

/* app frame */
#app { display: flex; flex-direction: column; height: 100dvh; }
header { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top));
  background: var(--panel); border-bottom: 1px solid var(--line); }
header .title { flex: 1; display: flex; align-items: center; gap: 8px; font-weight: 700; }
nav { display: flex; gap: 4px; }
.tab { background: none; color: var(--muted); padding: 6px 10px; font-weight: 500; }
.tab.active { color: var(--text); background: var(--panel2); }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--panel2); color: var(--muted); font-weight: 600; }
.badge.online { color: var(--green); } .badge.offline { color: var(--orange); }
.badge.sec.GREEN { background: #16382a; color: var(--green); }
.badge.sec.ORANGE { background: #3d2e12; color: var(--orange); }
.badge.sec.RED { background: #3f1717; color: var(--red); }
#drawer { position: absolute; top: 52px; left: 0; bottom: 0; width: 280px; z-index: 5; background: var(--panel);
  border-right: 1px solid var(--line); padding: 12px; overflow: auto; }
#drawer ul { list-style: none; padding: 0; margin: 12px 0; }
#drawer li { padding: 8px 10px; border-radius: 8px; cursor: pointer; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#drawer li.active, #drawer li:hover { background: var(--panel2); color: var(--text); }
#drawer > button { width: 100%; }
.view { flex: 1; overflow: auto; display: flex; flex-direction: column; }

/* chat */
.banner { background: #3d2e12; color: var(--orange); padding: 8px 14px; font-size: 13px; }
#messages { flex: 1; overflow: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.msg { max-width: 820px; padding: 10px 14px; border-radius: 14px; white-space: pre-wrap; word-wrap: break-word; }
.msg.user { align-self: flex-end; background: #253a5e; }
.msg.assistant { align-self: flex-start; background: var(--panel); border: 1px solid var(--line); }
.msg.assistant .md h1, .msg.assistant .md h2, .msg.assistant .md h3 { margin: 8px 0 4px; font-size: 1.05em; }
.msg .changes { margin-top: 8px; font-size: 12px; color: var(--accent2); }
.msg .working { margin-top: 6px; font-size: 12px; }
.msg .working summary { color: var(--muted); cursor: pointer; }
.msg .working pre { white-space: pre-wrap; font-size: 12px; background: var(--bg); padding: 8px; border-radius: 8px; max-height: 400px; overflow: auto; }
#chat-form { padding: 8px 12px; padding-bottom: max(8px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--panel); }
#chat-form .row { display: flex; gap: 8px; align-items: flex-end; }
#chat-form textarea { max-height: 160px; }
#send { height: 42px; width: 48px; padding: 0; }
.mode { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.mode input { width: auto; margin-right: 4px; }
#status { min-height: 18px; margin-top: 4px; }
.typing::after { content: "…"; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .3; } }

/* library */
.lib-layout { display: grid; grid-template-columns: 280px 1fr; flex: 1; min-height: 0; }
.lib-list { border-right: 1px solid var(--line); padding: 12px; overflow: auto; background: var(--panel); }
.lib-list ul { list-style: none; padding: 0; margin: 10px 0; }
.lib-list li { padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.lib-list li.active, .lib-list li:hover { background: var(--panel2); }
.lib-list li small { display: block; color: var(--muted); }
.doc { padding: 20px 24px; overflow: auto; max-width: 820px; }
.doc h1 { font-size: 1.5em; } .doc h2 { font-size: 1.2em; margin-top: 1.4em; }
.doc code { background: var(--panel2); padding: 1px 5px; border-radius: 4px; }
@media (max-width: 720px) {
  .lib-layout { grid-template-columns: 1fr; }
  .lib-list { border-right: 0; border-bottom: 1px solid var(--line); max-height: 40vh; }
  nav { width: 100%; justify-content: space-around; }
  nav .tab { padding: 6px 8px; font-size: 13px; flex: 1; }
  #drawer { top: 96px; }
}

/* settings */
#view-settings { padding: 16px; gap: 12px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; max-width: 820px; }
.card h2 { margin: 0 0 6px; font-size: 1.05em; display: flex; align-items: center; gap: 8px; }
.card textarea, .card input { margin: 8px 0; }
.checks { list-style: none; padding: 0; margin: 8px 0 0; }
.checks li { padding: 4px 0; font-size: 14px; }
.checks li::before { content: "● "; color: var(--green); }
.checks li.bad::before { color: var(--orange); }
