:root {
  --bg: #0b0e14;
  --bg-elev: #111622;
  --bg-card: #161c2b;
  --bg-hover: #1d2538;
  --border: rgba(148, 163, 184, 0.14);
  --border-strong: rgba(148, 163, 184, 0.28);
  --text: #e6edf7;
  --muted: #8b9bb4;
  --accent: #60a5fa;
  --accent-strong: #3b82f6;
  --indigo: #818cf8;
  --green: #34d399;
  --amber: #fbbf24;
  --red: #f87171;
  --radius: 12px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  --sans: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: var(--mono); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Buttons & Inputs */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 9px;
  border: 1px solid transparent;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
  color: var(--text);
  background: var(--bg-card);
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
  background: linear-gradient(135deg, var(--accent-strong), #6366f1);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}
.btn-ghost:hover:not(:disabled) { background: var(--bg-hover); border-color: var(--border-strong); }
.btn-danger {
  background: rgba(248, 113, 113, 0.16);
  border-color: rgba(248, 113, 113, 0.4);
  color: #fecaca;
}
.btn-danger:hover:not(:disabled) { background: rgba(248, 113, 113, 0.28); }
.btn-sm { padding: 6px 10px; font-size: 13px; border-radius: 8px; }
.btn-full { width: 100%; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font-size: 16px;
}
.icon-btn:hover { background: var(--bg-hover); }

.input-text, .input-select {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
  font-size: 13px;
}
.input-text:focus, .input-select:focus {
  outline: none;
  border-color: var(--accent);
}

/* Brand Orb */
.brand-row { display: flex; align-items: center; gap: 12px; }
.brand-row.compact { gap: 9px; }
.brand-title { display: flex; align-items: center; gap: 8px; font-size: 15px; }
.brand-orb {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #93c5fd, #6366f1 55%, #1e1b4b 100%);
  box-shadow: 0 0 24px rgba(99, 102, 241, 0.45);
  flex-shrink: 0;
}
.brand-orb.sm { width: 24px; height: 24px; }
.brand-orb.lg { width: 52px; height: 52px; margin-bottom: 8px; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}
.badge-indigo {
  background: rgba(129, 140, 248, 0.18);
  color: #c7d2fe;
  border: 1px solid rgba(129, 140, 248, 0.35);
}

/* Login */
.login-view {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 20px;
  background: radial-gradient(ellipse at top, rgba(59, 130, 246, 0.16), transparent 60%), var(--bg);
}
.login-card {
  width: 100%;
  max-width: 390px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
}
.login-card h1 { margin: 0; font-size: 20px; }
.login-card p { margin: 2px 0 0; font-size: 13px; }
.login-card form { margin-top: 22px; display: flex; flex-direction: column; gap: 14px; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.login-card input {
  padding: 10px 12px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
.login-card input:focus { outline: none; border-color: var(--accent); }
.error-banner {
  padding: 9px 12px;
  border-radius: 8px;
  background: rgba(248, 113, 113, 0.14);
  border: 1px solid rgba(248, 113, 113, 0.35);
  color: #fecaca;
  font-size: 13px;
}

/* App Shell */
.app-shell {
  display: flex;
  height: 100dvh;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: 280px;
  flex-shrink: 0;
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100%;
  z-index: 30;
}
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 14px 10px;
  border-bottom: 1px solid var(--border);
}
.sidebar-actions { padding: 12px 14px 8px; }
.sidebar-section { padding: 8px 14px; display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 600; }
.settings-grid { gap: 8px; border-bottom: 1px solid var(--border); padding-bottom: 12px; }
.toggles-col { display: flex; gap: 12px; flex-wrap: wrap; }
.toggle-item { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); cursor: pointer; }
.toggle-item input { accent-color: var(--accent); }
.sidebar-list-header { padding: 10px 14px 4px; }

.conv-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.conv-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 10px;
  border-radius: 9px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.12s;
}
.conv-item:hover { background: var(--bg-hover); }
.conv-item.active {
  background: rgba(96, 165, 250, 0.13);
  border-color: rgba(96, 165, 250, 0.3);
}
.conv-info { min-width: 0; flex: 1; }
.conv-title { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-meta { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-del {
  opacity: 0;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
  font-size: 13px;
}
.conv-item:hover .conv-del, .conv-item.active .conv-del { opacity: 1; }
.conv-del:hover { color: var(--red); background: rgba(248, 113, 113, 0.15); }

.sidebar-footer {
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Main Column */
.main-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(17, 22, 34, 0.85);
  backdrop-filter: blur(10px);
  flex-shrink: 0;
}
.topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.status-cluster { display: flex; align-items: center; gap: 10px; min-width: 0; }
.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.status-dot.online { background: var(--green); box-shadow: 0 0 10px rgba(52, 211, 153, 0.6); }
.status-dot.standby { background: var(--amber); box-shadow: 0 0 10px rgba(251, 191, 36, 0.5); }
.status-dot.offline { background: var(--red); }
.status-text { min-width: 0; }
.status-primary { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status-secondary { font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; align-items: center; gap: 6px; flex-wrap: nowrap; flex-shrink: 0; }

/* Content Split */
.content-split {
  flex: 1;
  min-height: 0;
  display: flex;
}
.chat-pane {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* Messages */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.empty-state {
  margin: auto;
  max-width: 560px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 24px 12px;
}
.empty-state h2 { margin: 0; font-size: 22px; }
.empty-state p { margin: 0 0 12px; font-size: 14px; }
.quick-chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.chip {
  padding: 8px 13px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}
.chip:hover { border-color: var(--accent); background: var(--bg-hover); }

.msg-row {
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.msg-row.user { align-items: flex-end; }
.msg-bubble.user {
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.24), rgba(99, 102, 241, 0.22));
  border: 1px solid rgba(96, 165, 250, 0.35);
  border-radius: 14px 14px 4px 14px;
  padding: 11px 15px;
  max-width: 85%;
  white-space: pre-wrap;
  word-break: break-word;
}
.msg-assistant {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Thought & Tool Cards (Antigravity Remote style) */
.thought-card, .tool-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.thought-card summary, .tool-card summary {
  list-style: none;
  cursor: pointer;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12.5px;
  color: var(--muted);
  user-select: none;
}
.thought-card summary::-webkit-details-marker,
.tool-card summary::-webkit-details-marker { display: none; }
.thought-card summary:hover, .tool-card summary:hover { background: var(--bg-hover); }
.thought-body {
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: #a6b4cc;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 260px;
  overflow-y: auto;
}
.tool-left { display: flex; align-items: center; gap: 8px; min-width: 0; }
.tool-name {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--accent);
  background: rgba(96, 165, 250, 0.12);
  padding: 2px 7px;
  border-radius: 6px;
  flex-shrink: 0;
}
.tool-summary { font-family: var(--mono); font-size: 12px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tool-status { font-size: 11.5px; flex-shrink: 0; }
.tool-status.running { color: var(--amber); }
.tool-status.done { color: var(--green); }
.tool-status.error { color: var(--red); }
.tool-body {
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.tool-pre {
  margin: 0;
  padding: 8px 10px;
  border-radius: 7px;
  background: #090c11;
  border: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 12px;
  overflow-x: auto;
  max-height: 280px;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Markdown Body */
.md-body { word-break: break-word; }
.md-body p { margin: 0 0 10px; }
.md-body p:last-child { margin-bottom: 0; }
.md-body h1, .md-body h2, .md-body h3 { margin: 14px 0 8px; line-height: 1.3; }
.md-body h1 { font-size: 1.3em; }
.md-body h2 { font-size: 1.15em; }
.md-body h3 { font-size: 1.03em; }
.md-body ul, .md-body ol { margin: 6px 0 10px; padding-left: 22px; }
.md-body li { margin: 3px 0; }
.md-body code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: rgba(148, 163, 184, 0.14);
  padding: 2px 5px;
  border-radius: 5px;
}
.md-body a { color: var(--accent); text-decoration: none; }
.md-body a:hover { text-decoration: underline; }
.code-block {
  margin: 10px 0;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #080b10;
  overflow: hidden;
}
.code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  background: rgba(255, 255, 255, 0.03);
  border-bottom: 1px solid var(--border);
  font-size: 11.5px;
  color: var(--muted);
  font-family: var(--mono);
}
.code-copy {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 5px;
  cursor: pointer;
}
.code-copy:hover { background: var(--bg-hover); }
.code-block pre {
  margin: 0;
  padding: 12px;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.45;
}
.code-block pre code { background: none; padding: 0; }

/* Stream Banner */
.stream-banner {
  max-width: 860px;
  width: calc(100% - 36px);
  margin: 0 auto 6px;
  padding: 7px 12px;
  border-radius: 8px;
  background: rgba(96, 165, 250, 0.1);
  border: 1px solid rgba(96, 165, 250, 0.25);
  font-size: 12.5px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.2s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 0.35; transform: scale(0.85); }
  50% { opacity: 1; transform: scale(1.15); }
}

/* Composer */
.composer {
  padding: 10px 16px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--bg-elev);
  flex-shrink: 0;
}
.composer-box {
  max-width: 860px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  padding: 8px 10px;
}
.composer-box:focus-within { border-color: var(--accent); }
.composer-box textarea {
  flex: 1;
  resize: none;
  border: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  max-height: 180px;
  min-height: 24px;
  padding: 4px 2px;
}
.composer-box textarea:focus { outline: none; }
.composer-buttons { display: flex; gap: 6px; flex-shrink: 0; }
.composer-meta {
  max-width: 860px;
  margin: 6px auto 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.meta-pill {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  background: rgba(148, 163, 184, 0.1);
  padding: 2px 8px;
  border-radius: 999px;
}

/* Tools Drawer (Terminal + Files) */
.tools-drawer {
  width: 380px;
  flex-shrink: 0;
  border-left: 1px solid var(--border);
  background: var(--bg-elev);
  display: flex;
  flex-direction: column;
  height: 100%;
}
.drawer-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
.tab-btn {
  flex: 1;
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.tab-btn.active {
  background: var(--bg-card);
  border-color: var(--border);
  color: var(--text);
  font-weight: 600;
}
.tab-panel { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.term-output {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  font-family: var(--mono);
  font-size: 12.5px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.term-entry {
  background: #080b10;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
}
.term-cmd { color: var(--accent); margin-bottom: 4px; word-break: break-all; }
.term-stdout { white-space: pre-wrap; word-break: break-word; color: var(--text); margin: 0; }
.term-stderr { white-space: pre-wrap; word-break: break-word; color: var(--red); margin: 4px 0 0; }
.term-form {
  display: flex;
  gap: 6px;
  padding: 10px;
  border-top: 1px solid var(--border);
}
.files-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
.files-list { flex: 1; overflow-y: auto; padding: 6px; display: flex; flex-direction: column; gap: 2px; }
.file-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 9px;
  border-radius: 7px;
  font-size: 13px;
  cursor: pointer;
}
.file-row:hover { background: var(--bg-hover); }

/* Toast */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 100;
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
}

/* Mobile Responsive */
.mobile-only { display: none; }
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 25;
}

@media (max-width: 900px) {
  .mobile-only { display: inline-flex; }
  .desktop-only { display: none; }
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    width: min(85vw, 310px);
  }
  .sidebar.open { transform: translateX(0); }
  .topbar { padding: 8px 10px; }
  .topbar-actions .btn-sm { padding: 6px 8px; font-size: 12px; }
  #btn-wake, #btn-load, #btn-unload { padding: 6px 7px; }
  .tools-drawer {
    position: fixed;
    inset: 0;
    width: 100%;
    z-index: 40;
  }
  .messages { padding: 14px 12px; }
  .msg-bubble.user { max-width: 92%; }
}
