*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #06080f;
  --panel: #0b0f1c;
  --surface: rgba(255, 255, 255, 0.045);
  --surface-hover: rgba(255, 255, 255, 0.08);
  --border: rgba(255, 255, 255, 0.08);
  --accent: #6366f1;
  --accent-dim: rgba(99, 102, 241, 0.16);
  --text: #e2e8f0;
  --muted: #64748b;
  --green: #22c55e;
  --amber: #f59e0b;
  --red: #ef4444;
  --cyan: #06b6d4;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 13px;
  overflow: hidden;
}

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* Offline Banner */
.offline-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: rgba(245, 158, 11, 0.12);
  border-bottom: 1px solid rgba(245, 158, 11, 0.35);
  font-size: 12px;
  flex-shrink: 0;
}
.offline-banner[hidden] { display: none; }
.offline-text { display: flex; flex-direction: column; gap: 2px; }
.offline-text strong { color: #fde68a; }
.offline-text code { background: rgba(0, 0, 0, 0.35); padding: 1px 5px; border-radius: 4px; }
.offline-actions { display: flex; align-items: center; gap: 6px; }
.offline-actions input {
  width: 72px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 5px 8px;
  border-radius: 6px;
  font-size: 12px;
}

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: rgba(11, 15, 28, 0.96);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--red);
  transition: background 0.3s;
}

.brand-dot.online { background: var(--green); box-shadow: 0 0 8px var(--green); }
.brand-name { font-weight: 700; letter-spacing: 3px; font-size: 14px; }
.brand-sub { font-size: 10px; color: var(--muted); letter-spacing: 1px; }

.state-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.5px;
}

.state-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--cyan); }
.state-pill[data-state="SPEAKING"] .state-dot { background: var(--green); }
.state-pill[data-state="THINKING"] .state-dot { background: var(--amber); }
.state-pill[data-state="SLEEPING"] .state-dot { background: var(--muted); }

.topbar-actions {
  margin-left: auto;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.btn-chip {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 11px;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: 0.15s;
}
.btn-chip:hover { border-color: var(--accent); background: var(--accent-dim); }
.btn-chip.active { border-color: var(--accent); background: var(--accent-dim); color: #fff; }
.btn-chip.muted { border-color: var(--red); color: #fca5a5; background: rgba(239, 68, 68, 0.14); }
.btn-chip.btn-warn:hover { border-color: var(--amber); color: #fde68a; }
.btn-chip.btn-danger { border-color: var(--red); background: rgba(239, 68, 68, 0.2); color: #fecaca; }

.btn-icon {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  width: 26px;
  height: 26px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
}
.btn-icon:hover { border-color: var(--accent); }

/* 3-Column Workspace */
.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 220px 1fr 360px;
}

.sidebar, .inspector {
  background: var(--panel);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.sidebar { border-right: 1px solid var(--border); }
.inspector { border-left: 1px solid var(--border); }

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}

.chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.chat-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid transparent;
  color: var(--text);
}
.chat-item:hover { background: var(--surface); }
.chat-item.active { background: var(--accent-dim); border-color: rgba(99, 102, 241, 0.35); }
.chat-item-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.chat-item-del {
  opacity: 0;
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
}
.chat-item:hover .chat-item-del { opacity: 1; }
.chat-item-del:hover { color: var(--red); }

/* Center Stage */
.center-stage {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: radial-gradient(circle at 50% 15%, rgba(99, 102, 241, 0.08), transparent 60%);
}

.orb-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 10px 16px 4px;
  flex-shrink: 0;
}

.orb-meta { text-align: center; margin-top: -6px; }
.orb-title { font-size: 11px; letter-spacing: 1.8px; text-transform: uppercase; color: var(--muted); }
.orb-sub { font-size: 10px; color: var(--green); margin-top: 2px; }

.chat-feed {
  flex: 1;
  overflow-y: auto;
  padding: 12px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}
.msg-u { align-self: flex-end; background: var(--surface); border: 1px solid var(--border); }
.msg-j { align-self: flex-start; background: var(--accent-dim); border: 1px solid rgba(99, 102, 241, 0.25); }
.msg-sys { align-self: center; font-size: 11px; color: var(--muted); padding: 2px 6px; }
.msg-lbl { font-size: 9px; font-weight: 700; letter-spacing: 1.5px; text-transform: uppercase; color: var(--muted); margin-bottom: 3px; }

.composer {
  padding: 10px 16px 14px;
  border-top: 1px solid var(--border);
  background: rgba(6, 8, 15, 0.85);
}

.file-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  margin-bottom: 8px;
  border-radius: 999px;
  background: var(--accent-dim);
  border: 1px solid var(--accent);
  font-size: 11px;
}
.file-pill button { background: none; border: none; color: var(--text); cursor: pointer; font-size: 14px; }

.composer-row { display: flex; gap: 8px; align-items: center; }

.btn-attach {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 12px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
}
.btn-attach:hover { border-color: var(--accent); }

#cmd-input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 10px;
  outline: none;
  font-size: 13px;
}
#cmd-input:focus { border-color: var(--accent); }

.btn-send {
  background: var(--accent);
  border: none;
  color: #fff;
  padding: 10px 18px;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
}
.btn-send:hover { filter: brightness(1.1); }

/* Right Inspector */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
}
.tab {
  flex: 1;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  padding: 11px 6px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  cursor: pointer;
}
.tab.active { color: var(--text); border-bottom-color: var(--accent); }

.tab-pane { display: none; flex: 1; flex-direction: column; min-height: 0; padding: 10px; gap: 10px; }
.tab-pane.active { display: flex; }

.viewer-media img, .viewer-media video {
  width: 100%;
  max-height: 220px;
  object-fit: contain;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #000;
}

.viewer-content {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.content-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
}
.content-card h4 { font-size: 12px; color: var(--accent); margin-bottom: 6px; }
.content-card pre { white-space: pre-wrap; font-family: inherit; line-height: 1.5; font-size: 12px; }

.empty-state { color: var(--muted); text-align: center; margin-top: 32px; font-size: 12px; }

/* Tasks */
.task-toolbar, .log-toolbar { display: flex; gap: 6px; }
.task-toolbar input, .log-toolbar input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 7px 10px;
  border-radius: 8px;
  outline: none;
  font-size: 12px;
}
.btn-small {
  background: var(--accent);
  border: none;
  color: #fff;
  padding: 7px 11px;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}
.btn-small.btn-ghost { background: var(--surface); border: 1px solid var(--border); color: var(--text); }

.task-list, .plugin-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.task-card, .plugin-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.task-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.task-title { font-weight: 600; font-size: 12px; }
.badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--surface-hover);
  text-transform: uppercase;
}
.badge.running { color: var(--cyan); }
.badge.completed, .badge.done { color: var(--green); }
.badge.failed, .badge.cancelled { color: var(--red); }
.task-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* Logs */
.log-box {
  flex: 1;
  overflow-y: auto;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  font-family: Consolas, "Cascadia Code", monospace;
  font-size: 11px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  color: #cbd5e1;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(2, 4, 10, 0.78);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal-backdrop[hidden] { display: none; }

.modal {
  width: 440px;
  max-width: 92vw;
  background: #0f1526;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.modal-header { display: flex; justify-content: space-between; align-items: center; }
.modal-badge { font-size: 10px; font-weight: 700; letter-spacing: 1.6px; color: var(--amber); }
.form-grid { display: flex; flex-direction: column; gap: 10px; }
.form-grid label { display: flex; flex-direction: column; gap: 5px; font-size: 11px; color: var(--muted); }
.form-grid input, .form-grid select {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 8px;
  outline: none;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

@media (max-width: 1024px) {
  .workspace { grid-template-columns: 1fr; }
  .sidebar, .inspector { display: none; }
}
