*, *::before, *::after { box-sizing: border-box; }
:root {
  --bg: #0e1116;
  --bg-2: #161b22;
  --bg-3: #1c232d;
  --border: #2a323d;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #4f9dff;
  --accent-2: #1f6feb;
  --green: #3fb950;
  --gray: #6e7681;
  --user: #23324a;
  --radius: 12px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font-family: var(--sans); font-size: 14px; }

#app { display: grid; grid-template-columns: 288px 1fr; height: 100vh; }
#app[hidden] { display: none; }

/* Login gate */
.login-screen { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; padding: 24px; background: var(--bg); }
.login-card { width: 100%; max-width: 360px; background: var(--bg-2); border: 1px solid var(--border); border-radius: 14px; padding: 26px 24px; display: flex; flex-direction: column; gap: 13px; }
.login-brand { display: flex; align-items: center; gap: 8px; font-size: 15px; }
.login-brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--green); box-shadow: 0 0 10px var(--green); flex: none; }
.login-hint { margin: 0 0 2px; color: var(--muted); font-size: 13px; line-height: 1.4; }
.login-input { background: var(--bg); border: 1px solid var(--border); color: var(--text); border-radius: 9px; padding: 11px 12px; font: inherit; }
.login-input:focus { outline: none; border-color: var(--accent); }
.login-input[readonly] { color: var(--muted); }
.login-error { margin: 0; color: #ffb4b4; font-size: 12.5px; }
.login-btn { background: var(--accent-2); border: none; color: #fff; padding: 11px 0; border-radius: 9px; font: inherit; font-weight: 600; cursor: pointer; }
.login-btn:hover { background: var(--accent); }
.login-btn:disabled { opacity: .5; cursor: not-allowed; }

/* Sidebar */
.sidebar { background: var(--bg-2); border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; }
.brand { display: flex; align-items: center; gap: 10px; padding: 16px; border-bottom: 1px solid var(--border); }
.brand strong { display: block; font-size: 15px; }
.brand small { color: var(--muted); font-size: 12px; }
.brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--green); box-shadow: 0 0 10px var(--green); flex: none; }
.icon-btn { margin-left: auto; background: var(--bg-3); border: 1px solid var(--border); color: var(--text); width: 30px; height: 30px; border-radius: 8px; cursor: pointer; font-size: 15px; }
.icon-btn:hover { border-color: var(--accent); }

.views { display: flex; gap: 6px; padding: 12px 12px 0; }
.view-tab { flex: 1; background: transparent; border: 1px solid var(--border); color: var(--muted); padding: 7px 0; border-radius: 8px; cursor: pointer; font-size: 13px; }
.view-tab.active { background: var(--bg-3); color: var(--text); border-color: var(--accent); }

.profiles { list-style: none; margin: 12px 0 0; padding: 0 8px; overflow-y: auto; flex: 1; min-height: 0; }
.profiles li { padding: 10px 10px; border-radius: 10px; cursor: pointer; border: 1px solid transparent; margin-bottom: 4px; }
.profiles li:hover { background: var(--bg-3); }
.profiles li.active { background: var(--bg-3); border-color: var(--accent); }
.profiles .row1 { display: flex; align-items: center; gap: 8px; }
.profiles .name { font-weight: 600; }
.profiles .tag { font-size: 10px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); border: 1px solid var(--border); border-radius: 6px; padding: 1px 5px; }
.profiles .gw { margin-left: auto; width: 8px; height: 8px; border-radius: 50%; background: var(--gray); flex: none; }
.profiles .gw.running { background: var(--green); box-shadow: 0 0 8px var(--green); }
.profiles .model { color: var(--muted); font-size: 12px; margin-top: 3px; font-family: var(--mono); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.sidebar-foot { padding: 10px 16px; border-top: 1px solid var(--border); color: var(--gray); font-size: 11px; font-family: var(--mono); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Main */
.main { display: flex; flex-direction: column; min-height: 0; }
.main.hidden { display: none; }
.chat-head { display: flex; align-items: flex-start; gap: 16px; padding: 18px 24px; border-bottom: 1px solid var(--border); }
.chat-head h1 { margin: 0; font-size: 17px; }
.sub { margin: 4px 0 0; color: var(--muted); font-size: 12px; font-family: var(--mono); }
.ghost-btn { margin-left: auto; background: transparent; border: 1px solid var(--border); color: var(--text); padding: 8px 12px; border-radius: 8px; cursor: pointer; font-size: 13px; white-space: nowrap; }
.ghost-btn:hover { border-color: var(--accent); }

.messages { flex: 1; overflow-y: auto; padding: 24px; display: flex; flex-direction: column; gap: 16px; }
.empty-state { color: var(--muted); text-align: center; margin: auto; }

.msg { max-width: 780px; display: flex; flex-direction: column; gap: 4px; }
.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.assistant, .msg.system { align-self: flex-start; }
.bubble { padding: 12px 14px; border-radius: var(--radius); line-height: 1.5; white-space: pre-wrap; word-wrap: break-word; }
.msg.user .bubble { background: var(--user); border: 1px solid #33456a; }
.msg.assistant .bubble { background: var(--bg-2); border: 1px solid var(--border); }
.msg.system .bubble { background: #2d1f1f; border: 1px solid #5c2b2b; color: #ffb4b4; font-size: 13px; }
.meta { font-size: 11px; color: var(--gray); font-family: var(--mono); }
.bubble pre { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 10px; overflow-x: auto; font-family: var(--mono); font-size: 12.5px; }
.bubble code { background: var(--bg); border: 1px solid var(--border); border-radius: 4px; padding: 1px 4px; font-family: var(--mono); font-size: 12.5px; }
.bubble pre code { background: none; border: none; padding: 0; }

.typing { display: inline-flex; gap: 4px; align-items: center; }
.typing span { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite ease-in-out; }
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

/* Composer */
.composer { display: flex; gap: 10px; padding: 16px 24px; border-top: 1px solid var(--border); align-items: flex-end; }
.composer.bc { border-top: none; border-bottom: 1px solid var(--border); }
.composer textarea { flex: 1; resize: none; background: var(--bg-2); border: 1px solid var(--border); color: var(--text); border-radius: 10px; padding: 11px 12px; font: inherit; line-height: 1.5; max-height: 200px; }
.composer textarea:focus { outline: none; border-color: var(--accent); }
.composer button { background: var(--accent-2); border: none; color: #fff; padding: 11px 20px; border-radius: 10px; cursor: pointer; font: inherit; font-weight: 600; }
.composer button:hover { background: var(--accent); }
.composer button:disabled { opacity: .45; cursor: not-allowed; }

/* Broadcast grid */
.bc-grid { flex: 1; overflow-y: auto; padding: 20px 24px; display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; align-content: start; }
.bc-card { background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius); display: flex; flex-direction: column; min-height: 140px; }
.bc-card header { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.bc-card header .name { font-weight: 600; }
.bc-card header .model { color: var(--muted); font-size: 11px; font-family: var(--mono); margin-left: auto; }
.bc-card .body { padding: 12px; line-height: 1.5; white-space: pre-wrap; word-wrap: break-word; overflow-y: auto; max-height: 340px; flex: 1; }
.bc-card .body.err { color: #ffb4b4; }
.bc-card footer { padding: 8px 12px; border-top: 1px solid var(--border); font-size: 11px; color: var(--gray); font-family: var(--mono); }

@media (max-width: 720px) {
  #app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 10; width: 260px; height: 100%; transform: translateX(-100%); transition: transform .2s; }
}
