:root {
  --bg: #0b0e14;
  --glass: rgba(17, 22, 31, 0.55);
  --glass-2: rgba(22, 29, 41, 0.6);
  --line: rgba(255, 255, 255, 0.09);
  --text: #e6eaf2;
  --muted: #8b94a7;
  --accent: #e8a93c;
  --accent-2: #4f8cff;
  --user: rgba(30, 42, 68, 0.85);
  --bot: rgba(20, 26, 38, 0.88);
  --error: #ff5c5c;
  --ok: #3ecf6e;
  --radius: 12px;
}

* { box-sizing: border-box; }

/* ---------- dark scrollbars ---------- */
* {
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.18) transparent;
}
*::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
*::-webkit-scrollbar-track {
  background: transparent;
}
*::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.16);
  border-radius: 999px;
  border: 2px solid rgba(11, 14, 20, 0.9);
}
*::-webkit-scrollbar-thumb:hover {
  background: rgba(232, 169, 60, 0.45);
}
*::-webkit-scrollbar-corner {
  background: transparent;
}

html, body {
  margin: 0;
  height: 100%;
  background: #0b0e14;
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

body { display: flex; flex-direction: column; }

button, input, textarea, select { font: inherit; color: inherit; }

/* ---------- topbar: all controls live here ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  flex: 0 0 auto;
  padding: 8px 16px;
  background: rgba(11, 14, 20, 0.72);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 9px; white-space: nowrap; }
.brand-mark {
  display: grid; place-items: center;
  width: 28px; height: 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, #1a2333, #0e141f);
  border: 1px solid var(--line);
  font-family: ui-monospace, monospace;
  font-weight: 700;
  font-size: 13px;
  color: var(--accent);
}
.brand strong { font-size: 14px; letter-spacing: -0.02em; }

.tabs {
  display: flex;
  gap: 2px;
  margin-left: auto;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.03);
}
.tab {
  background: transparent; border: none;
  color: var(--muted);
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 12.5px;
  transition: color 0.15s ease, background 0.15s ease;
}
.tab:hover { color: var(--text); }
.tab.is-active { color: #141414; background: var(--accent); font-weight: 600; }

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

.status-pill, .pill {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 12px; color: var(--muted);
  padding: 5px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
}
.status-pill i, .pill i {
  width: 8px; height: 8px; border-radius: 50%; background: var(--muted);
}
.status-pill[data-state="online"] i { background: var(--ok); }
.status-pill[data-state="online"] { color: var(--ok); }
.status-pill[data-state="error"] i { background: var(--error); }
.status-pill[data-state="error"] { color: var(--error); }
.status-pill[data-state="busy"] i { background: var(--accent); animation: pulse 0.9s ease-in-out infinite; }
.pill i { background: var(--accent-2); }
.pill { color: var(--text); }

@keyframes pulse { 50% { opacity: 0.25; } }

/* ---------- layout ---------- */
.app {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 0;
}

/* LEFT: team chat — transparent, floats over the page */
.left {
  grid-column: 1;
  grid-row: 1;
  border-right: 1px solid var(--line);
  background: var(--glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.scroll {
  flex: 1; overflow-y: auto;
  padding: 12px;
  display: flex; flex-direction: column; gap: 8px;
  min-height: 0;
}

/* CENTER: the actual content */
.center {
  grid-column: 2;
  grid-row: 1;
  background: transparent;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}
.tab-pane { display: none; flex: 1; min-height: 0; }
.tab-pane.is-active { display: flex; flex-direction: column; }

.preview-frame {
  flex: 1;
  width: 100%;
  border: 0;
  background: #ffffff;
}

.files-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
  background: var(--glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}
.btn-group { display: flex; gap: 8px; align-items: center; }

.files-split { display: flex; flex: 1; min-height: 0; }
.file-tree {
  list-style: none; margin: 0; padding: 10px;
  width: 42%; max-width: 400px;
  overflow-y: auto;
  border-right: 1px solid var(--line);
  font-family: ui-monospace, Menlo, monospace;
  font-size: 12.5px;
  display: flex; flex-direction: column; gap: 2px;
  background: var(--glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}
.file-tree li { padding: 4px 8px; border-radius: 6px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-tree li:hover { background: rgba(255, 255, 255, 0.07); }
.file-tree li.is-active { background: rgba(255, 255, 255, 0.09); color: var(--accent); }
.file-tree li.dir { color: var(--muted); cursor: default; }

.file-editor { flex: 1; min-width: 0; display: flex; flex-direction: column; background: rgba(11, 14, 20, 0.5); }
.editor-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
  background: var(--glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}
#editor-input {
  flex: 1;
  margin: 0;
  padding: 12px;
  border: 0;
  background: rgba(11, 14, 20, 0.4);
  color: var(--text);
  resize: none;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  line-height: 1.55;
  outline: none;
}

/* ---------- DeepSeek chat (bottom) — no header, transparent ---------- */
.agent-chat {
  grid-column: 2;
  grid-row: 2;
  display: flex;
  flex-direction: column;
  background: var(--glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
  max-height: 40vh;
  min-height: 160px;
}
.agent-messages {
  flex: 1; min-height: 0;
  overflow-y: auto;
  padding: 12px;
  display: flex; flex-direction: column; gap: 8px;
}
.composer {
  display: flex; gap: 8px;
  padding: 10px 14px;
  padding-right: 72px; /* keep clear of the bottom-right UI toggle */
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.02);
}
.composer input, .composer textarea {
  flex: 1;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(11, 14, 20, 0.8);
  color: var(--text);
  outline: none;
  resize: none;
}
.agent-select {
  flex: 0 0 auto;
  min-width: 120px;
  max-width: 200px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(11, 14, 20, 0.8);
  color: var(--text);
  font-size: 12.5px;
  outline: none;
  cursor: pointer;
}
.agent-select:focus { border-color: var(--accent); }
#agent-new {
  flex: 0 0 auto;
  align-self: center;
  padding: 8px 10px;
  line-height: 1;
}
.composer input:focus, .composer textarea:focus { border-color: var(--accent); }
.composer textarea { min-height: 42px; max-height: 140px; }
.send {
  width: 42px; height: 42px;
  border-radius: 10px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #141414;
  font-weight: 700;
  cursor: pointer;
  align-self: center;
}
.send:disabled { opacity: 0.45; cursor: default; }
.composer-note { padding: 4px 14px 8px; font-size: 12px; color: var(--muted); min-height: 18px; }

/* ---------- messages: solid so they stand out on the glass ---------- */
.msg { display: flex; gap: 10px; align-items: flex-start; }
.msg .avatar {
  width: 26px; height: 26px; flex: none;
  display: grid; place-items: center;
  border-radius: 8px;
  font-size: 10px; font-weight: 700;
  text-transform: uppercase;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--line);
  color: var(--muted);
}
.msg.player .avatar { background: rgba(201, 162, 255, 0.16); color: #c9a2ff; border-color: rgba(74, 59, 107, 0.8); }
.msg.agent .avatar { background: rgba(127, 224, 160, 0.14); color: #7fe0a0; border-color: rgba(47, 90, 60, 0.8); }
.msg .bubble {
  background: var(--bot);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 9px 12px;
  font-size: 13.5px;
  line-height: 1.5;
  min-width: 0;
  max-width: 100%;
  white-space: pre-wrap;
  word-break: break-word;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
}
.msg.player .bubble { background: var(--user); }
.msg .who { display: block; font-size: 11px; color: var(--muted); margin-bottom: 3px; }
.msg .model-tag {
  display: inline-block;
  font-size: 10px;
  color: var(--accent);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 1px 8px;
  margin: 0 0 6px;
}
.msg .cursor { color: var(--accent); animation: blink 0.8s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.msg .tool-call {
  display: block;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 11px;
  color: var(--accent-2);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 5px 9px;
  margin-top: 6px;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---------- buttons ---------- */
button.ghost {
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  cursor: pointer;
  font-size: 12.5px;
  white-space: nowrap;
  transition: border-color 0.15s ease, background 0.15s ease;
}
button.ghost:hover { border-color: var(--accent); background: rgba(232, 169, 60, 0.08); }
button.ghost:disabled { opacity: 0.5; cursor: default; }

.muted { color: var(--muted); }

.toast {
  position: fixed;
  bottom: 24px; left: 50%;
  transform: translateX(-50%);
  background: rgba(22, 29, 41, 0.92);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 13px;
  z-index: 60;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

/* ---------- bottom-right controls toggle ---------- */
.ui-toggle {
  position: fixed;
  right: 18px;
  bottom: 18px;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(17, 22, 31, 0.82);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  z-index: 55;
  display: grid;
  place-items: center;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease, transform 0.18s ease;
}
.ui-toggle:hover { color: var(--accent); border-color: var(--accent); background: rgba(232, 169, 60, 0.1); }
.ui-toggle[aria-expanded="true"] { transform: rotate(180deg); color: var(--accent); border-color: var(--accent); }

[hidden] { display: none !important; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) auto; }
  .left { grid-column: 1; grid-row: 1; border-right: none; border-bottom: 1px solid var(--line); max-height: 34vh; }
  .center { grid-column: 1; grid-row: 1; }
  .agent-chat { grid-column: 1; grid-row: 2; }
  .topbar { flex-wrap: wrap; gap: 8px; }
  .tabs { margin-left: 0; }
  .file-tree { width: 55%; }
}
