:root {
  --bg: #0e1017;
  --bg-elev: #151822;
  --bg-card: #1c202e;
  --bg-hover: #242a3b;
  --border: #2a3144;
  --text: #e8ecf5;
  --text-muted: #939db5;
  --accent: #4c82fb;
  --accent-hover: #3b71ec;
  --claude: #f59e0b;
  --gemini: #38bdf8;
  --success: #2ecc71;
  --warn: #f1c40f;
  --danger: #e74c3c;
  --code-bg: #10131b;
  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Segoe UI", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%; width: 100%;
  background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: 14px; line-height: 1.55;
  overflow: hidden;
}
.hidden { display: none !important; }

/* Login Screen */
.login-screen {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 25% 20%, rgba(245, 158, 11, 0.12), transparent 45%),
              radial-gradient(circle at 75% 80%, rgba(56, 189, 248, 0.12), transparent 45%), var(--bg);
}
.login-card {
  width: min(400px, 92vw); padding: 28px 26px; border-radius: 14px;
  background: var(--bg-elev); border: 1px solid var(--border);
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.45);
}
.login-brand { display: flex; align-items: center; gap: 8px; }
.login-brand h1 { margin: 0; font-size: 20px; }
.login-sub { margin: 8px 0 20px; font-size: 13px; color: var(--text-muted); }
.login-form { display: flex; flex-direction: column; gap: 14px; }
.login-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-muted); }
.login-form input {
  background: var(--bg-card); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 12px; font-size: 14px; outline: none;
}
.login-form input:focus { border-color: var(--accent); }
.login-error { color: #ff9c92; font-size: 13px; }

.app-shell { display: flex; height: 100vh; width: 100vw; overflow: hidden; }

/* Sidebar */
.sidebar {
  width: 285px; min-width: 250px; max-width: 320px;
  background: var(--bg-elev); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 14px 12px; gap: 10px;
}
.sidebar-header { display: flex; flex-direction: column; gap: 8px; }
.brand-row { display: flex; align-items: center; gap: 6px; }
.brand-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.brand-dot.claude { background: var(--claude); box-shadow: 0 0 8px rgba(245, 158, 11, 0.5); }
.brand-dot.gemini { background: var(--gemini); box-shadow: 0 0 8px rgba(56, 189, 248, 0.5); }
.brand-title { font-weight: 700; font-size: 15px; }
.user-badge {
  margin-left: auto; font-size: 12px; padding: 2px 8px; border-radius: 999px;
  background: rgba(76, 130, 251, 0.16); color: #9ec0ff;
}
.ws-row { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.ws-pill { font-size: 11px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border); color: var(--text-muted); }
.ws-pill.online { border-color: rgba(46, 204, 113, 0.45); color: #6ee7a8; background: rgba(46, 204, 113, 0.1); }
.ws-pill.offline { border-color: rgba(231, 76, 60, 0.45); color: #f59b91; background: rgba(231, 76, 60, 0.1); }

.section-label { font-size: 11px; color: var(--text-muted); letter-spacing: 0.4px; }
.control-block { display: flex; flex-direction: column; gap: 5px; }
.select-input, .inline-model-select {
  background: var(--bg-card); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 10px; font-size: 13px; outline: none;
}
.inline-model-select { padding: 4px 8px; font-size: 12px; }
.node-meta { font-size: 11.5px; color: var(--text-muted); line-height: 1.45; }

.btn-primary {
  background: var(--accent); color: #fff; border: none; border-radius: 8px;
  padding: 8px 14px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.btn-primary:hover { background: var(--accent-hover); }
.full-width { width: 100%; }
.btn-danger {
  background: rgba(231, 76, 60, 0.18); color: #ff8c80;
  border: 1px solid rgba(231, 76, 60, 0.5); border-radius: 8px;
  padding: 8px 14px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.btn-ghost {
  background: transparent; color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 5px 10px; font-size: 12px; cursor: pointer;
}
.btn-ghost:hover { background: var(--bg-hover); }
.btn-mini {
  background: var(--bg-card); color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; padding: 3px 8px; font-size: 12px; cursor: pointer;
  text-decoration: none; display: inline-flex; align-items: center;
}
.btn-mini:hover { background: var(--bg-hover); }

.platform-badge {
  font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 6px; flex-shrink: 0;
}
.platform-badge.claude { background: rgba(245, 158, 11, 0.18); color: #fbbf24; border: 1px solid rgba(245, 158, 11, 0.4); }
.platform-badge.antigravity { background: rgba(56, 189, 248, 0.18); color: #7dd3fc; border: 1px solid rgba(56, 189, 248, 0.4); }

.session-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.session-item {
  display: flex; align-items: center; gap: 8px; padding: 8px 9px;
  border-radius: 8px; cursor: pointer; border: 1px solid transparent;
}
.session-item:hover { background: var(--bg-hover); }
.session-item.active { background: rgba(76, 130, 251, 0.16); border-color: rgba(76, 130, 251, 0.45); }
.session-item-info { flex: 1; min-width: 0; }
.session-item-title { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session-item-sub { font-size: 11px; color: var(--text-muted); display: flex; align-items: center; gap: 5px; margin-top: 2px; }
.session-del {
  opacity: 0; background: transparent; border: none; color: var(--text-muted);
  cursor: pointer; padding: 2px 5px; border-radius: 4px; font-size: 12px;
}
.session-item:hover .session-del { opacity: 1; }
.session-del:hover { color: #ff8c80; }
.pulse-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--success); flex-shrink: 0; animation: pulse 1.2s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.35; } }

/* Main Pane */
.main-pane { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }
.topbar {
  height: 52px; padding: 0 16px; border-bottom: 1px solid var(--border);
  background: var(--bg-elev); display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.topbar-left { display: flex; align-items: center; gap: 8px; min-width: 0; }
.session-title { margin: 0; font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meta-pill { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--bg-card); border: 1px solid var(--border); color: var(--text-muted); white-space: nowrap; }
.meta-pill.running { color: #6ee7a8; border-color: rgba(46, 204, 113, 0.45); }
.meta-pill.queued { color: #f6d365; border-color: rgba(241, 196, 15, 0.45); }
.topbar-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.messages-scroll { flex: 1; overflow-y: auto; padding: 20px 18px 28px; }
.messages-container { max-width: 900px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; }
.empty-state { text-align: center; padding: 72px 20px; color: var(--text-muted); }
.empty-title { font-size: 20px; font-weight: 700; color: var(--text); margin-bottom: 8px; }
.empty-desc { max-width: 560px; margin: 0 auto; line-height: 1.7; }

.msg-row { display: flex; flex-direction: column; gap: 6px; }
.msg-row.user { align-items: flex-end; }
.msg-row.assistant, .msg-row.tool, .msg-row.system { align-items: flex-start; }
.msg-bubble { max-width: 88%; padding: 11px 15px; border-radius: 12px; word-break: break-word; overflow-wrap: anywhere; }
.msg-row.user .msg-bubble { background: #233b6c; border: 1px solid rgba(76, 130, 251, 0.45); color: #f2f6ff; }
.msg-row.assistant .msg-bubble { background: var(--bg-card); border: 1px solid var(--border); width: 100%; max-width: 100%; }
.msg-row.system .msg-bubble { background: rgba(231, 76, 60, 0.14); border: 1px solid rgba(231, 76, 60, 0.45); color: #ffb0a8; font-size: 13px; }
.msg-attachments { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.att-chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 9px; border-radius: 7px; background: rgba(0,0,0,0.25); border: 1px solid rgba(255,255,255,0.14); font-size: 12px; color: #dbe7ff; text-decoration: none; }
.att-thumb { max-width: 180px; max-height: 130px; border-radius: 8px; border: 1px solid rgba(255,255,255,0.18); display: block; cursor: pointer; }

.tool-card { width: 100%; background: #141824; border: 1px solid var(--border); border-radius: 9px; overflow: hidden; font-size: 12.5px; }
.tool-card summary { padding: 7px 12px; cursor: pointer; color: var(--text-muted); display: flex; align-items: center; gap: 8px; list-style: none; }
.tool-card summary::-webkit-details-marker { display: none; }
.tool-badge { font-family: var(--mono); font-size: 11px; padding: 1px 6px; border-radius: 5px; background: rgba(76,130,251,0.18); color: #9ec0ff; font-weight: 600; }
.tool-badge.err { background: rgba(231,76,60,0.2); color: #ff9c92; }
.tool-badge.think { background: rgba(168,85,247,0.2); color: #d4b3ff; }
.tool-summary-text { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-family: var(--mono); font-size: 12px; color: #b8c2d8; }
.tool-body { padding: 10px 12px; border-top: 1px solid var(--border); background: var(--code-bg); font-family: var(--mono); font-size: 12px; white-space: pre-wrap; max-height: 360px; overflow: auto; }

.live-preview { width: 100%; background: var(--bg-card); border: 1px dashed rgba(76,130,251,0.55); border-radius: 12px; padding: 11px 15px; }
.live-header { display: flex; align-items: center; gap: 8px; font-size: 12px; color: #9ec0ff; margin-bottom: 6px; }

.md p { margin: 0 0 8px; } .md p:last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3, .md h4 { margin: 12px 0 6px; }
.md ul, .md ol { margin: 6px 0 8px; padding-left: 22px; }
.md blockquote { margin: 8px 0; padding: 4px 12px; border-left: 3px solid var(--accent); color: var(--text-muted); }
.md code { font-family: var(--mono); font-size: 0.9em; background: rgba(255,255,255,0.08); padding: 1px 5px; border-radius: 4px; }
.md .code-block { margin: 8px 0; border-radius: 8px; overflow: hidden; border: 1px solid var(--border); background: var(--code-bg); }
.md .code-header { display: flex; align-items: center; justify-content: space-between; padding: 5px 10px; background: #181c28; border-bottom: 1px solid var(--border); font-size: 11px; color: var(--text-muted); font-family: var(--mono); }
.md .code-copy { background: transparent; border: 1px solid var(--border); color: var(--text-muted); border-radius: 4px; padding: 1px 7px; font-size: 11px; cursor: pointer; }
.md pre { margin: 0; padding: 10px 12px; overflow-x: auto; font-family: var(--mono); font-size: 12.5px; }
.md pre code { background: transparent; padding: 0; }
.md a { color: #7cb0ff; }

.composer-wrap { border-top: 1px solid var(--border); background: var(--bg-elev); padding: 12px 18px 16px; position: relative; }
.drop-overlay { position: absolute; inset: 0; background: rgba(76,130,251,0.22); border: 2px dashed var(--accent); display: flex; align-items: center; justify-content: center; font-size: 15px; font-weight: 600; color: #fff; z-index: 20; pointer-events: none; }
.attachment-bar { max-width: 900px; margin: 0 auto 8px; display: flex; flex-wrap: wrap; gap: 8px; }
.pending-att { display: inline-flex; align-items: center; gap: 6px; padding: 4px 8px; border-radius: 7px; background: var(--bg-card); border: 1px solid var(--border); font-size: 12px; }
.pending-att button { background: transparent; border: none; color: var(--text-muted); cursor: pointer; }
.composer-box { max-width: 900px; margin: 0 auto; display: flex; align-items: flex-end; gap: 8px; background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px; padding: 8px 10px; }
.composer-box:focus-within { border-color: var(--accent); }
.btn-icon { background: transparent; border: none; font-size: 18px; cursor: pointer; padding: 4px 6px; border-radius: 6px; color: var(--text-muted); }
#prompt-input { flex: 1; background: transparent; border: none; outline: none; resize: none; color: var(--text); font-family: var(--font); font-size: 14px; line-height: 1.5; max-height: 200px; padding: 4px 2px; }

/* Files Drawer */
.files-drawer { width: 300px; min-width: 250px; background: var(--bg-elev); border-left: 1px solid var(--border); display: flex; flex-direction: column; }
.files-drawer.collapsed { display: none; }
.drawer-header { height: 52px; padding: 0 12px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.drawer-title { font-weight: 600; font-size: 14px; }
.drawer-actions { display: flex; gap: 6px; }
.files-breadcrumb { padding: 8px 12px; border-bottom: 1px solid var(--border); font-size: 12px; color: var(--text-muted); display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.crumb-btn { background: transparent; border: none; color: #8db5ff; cursor: pointer; padding: 1px 3px; font-size: 12px; }
.files-list { flex: 1; overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 3px; }
.files-empty { text-align: center; color: var(--text-muted); padding: 28px 12px; font-size: 13px; }
.file-row { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 7px; cursor: pointer; font-size: 13px; }
.file-row:hover { background: var(--bg-hover); }
.file-name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-size { font-size: 11px; color: var(--text-muted); }
.file-dl { opacity: 0.75; text-decoration: none; color: #8db5ff; padding: 2px 5px; }

/* Modals */
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.68); }
.modal-card { position: relative; width: min(920px, 92vw); max-height: 88vh; background: var(--bg-elev); border: 1px solid var(--border); border-radius: 12px; display: flex; flex-direction: column; overflow: hidden; }
.modal-header { padding: 10px 14px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-title { font-weight: 600; font-size: 14px; }
.modal-actions { display: flex; gap: 8px; }
.modal-body { padding: 14px; overflow: auto; flex: 1; background: var(--code-bg); }
.modal-body pre { margin: 0; font-family: var(--mono); font-size: 12.5px; white-space: pre-wrap; }
.modal-body img { max-width: 100%; max-height: 70vh; display: block; margin: 10px auto 0; border-radius: 8px; border: 1px solid var(--border); }
.diag-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; margin-bottom: 12px; }
.diag-item { padding: 10px 12px; border-radius: 8px; background: var(--bg-card); border: 1px solid var(--border); font-size: 13px; }
.diag-item strong { display: block; font-size: 11.5px; color: var(--text-muted); margin-bottom: 4px; }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #222838; color: var(--text); border: 1px solid var(--border); padding: 8px 16px; border-radius: 8px; font-size: 13px; z-index: 200; }
