:root {
  --bg-root: #0b0f19;
  --bg-sidebar: #0f1524;
  --bg-panel: #131b2e;
  --bg-elevated: #1b253d;
  --bg-hover: #222f4d;
  --border: #23304f;
  --border-light: #2f4068;
  --text-main: #e8eefc;
  --text-muted: #8ea0c8;
  --text-dim: #5d7099;
  --accent: #4f8cff;
  --accent-hover: #6ba0ff;
  --accent-glow: rgba(79, 140, 255, 0.18);
  --purple: #8b5cf6;
  --green: #10b981;
  --amber: #f59e0b;
  --red: #ef4444;
  --radius: 10px;
  --radius-sm: 6px;
}

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

html, body {
  height: 100%;
  width: 100%;
  background: var(--bg-root);
  color: var(--text-main);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Scrollbars */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #293859; border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: #3b5180; }

/* Login Overlay */
.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: radial-gradient(circle at 50% 20%, #172342 0%, #0b0f19 70%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-overlay.hidden { display: none; }

.login-card {
  width: 100%;
  max-width: 400px;
  background: rgba(19, 27, 46, 0.92);
  border: 1px solid var(--border-light);
  border-radius: 16px;
  padding: 32px 28px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(12px);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.login-brand img { width: 40px; height: 40px; }
.login-brand h1 { font-size: 20px; font-weight: 700; letter-spacing: -0.02em; }
.login-sub { color: var(--text-muted); font-size: 13px; margin-bottom: 24px; line-height: 1.5; }

.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; }
.form-input {
  width: 100%;
  padding: 11px 13px;
  background: var(--bg-root);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  color: var(--text-main);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.form-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.btn-primary {
  width: 100%;
  padding: 11px 16px;
  background: linear-gradient(135deg, #4f8cff 0%, #6d5dfc 100%);
  color: #fff;
  font-weight: 600;
  font-size: 14px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}
.btn-primary:hover { opacity: 0.94; }
.btn-primary:active { transform: scale(0.99); }

.login-error {
  margin-top: 12px;
  color: #fca5a5;
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 12.5px;
  display: none;
}

/* App Shell */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  width: 100vw;
}

/* Topbar */
.topbar {
  height: 52px;
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  gap: 8px;
  flex-shrink: 0;
}

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

.brand-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 14.5px;
  padding-right: 6px;
  white-space: nowrap;
}
.brand-pill img { width: 24px; height: 24px; }

.icon-btn {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  color: var(--text-main);
  height: 34px;
  padding: 0 10px;
  border-radius: 7px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 500;
  transition: background 0.15s, border-color 0.15s;
}
.icon-btn:hover { background: var(--bg-hover); border-color: var(--border-light); }
.icon-btn.active { background: var(--accent-glow); border-color: var(--accent); color: #8ab4ff; }

.select-ctrl {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  color: var(--text-main);
  height: 34px;
  padding: 0 10px;
  border-radius: 7px;
  font-size: 12.5px;
  outline: none;
  max-width: 220px;
}
.select-ctrl:focus { border-color: var(--accent); }

.sys-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.25);
  color: #6ee7b7;
  padding: 4px 10px;
  border-radius: 99px;
  font-size: 11.5px;
  white-space: nowrap;
}
.sys-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 8px var(--green);
}

/* Main Workspace Grid */
.workspace-body {
  flex: 1;
  display: flex;
  min-height: 0;
  position: relative;
}

/* Left Sidebar: Conversations */
.sidebar {
  width: 285px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: transform 0.2s ease;
  z-index: 40;
}

.sidebar.collapsed { display: none; }

.sidebar-header {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.new-chat-btn {
  width: 100%;
  padding: 9px 12px;
  background: linear-gradient(135deg, #4f8cff 0%, #6d5dfc 100%);
  border: none;
  border-radius: 8px;
  color: #fff;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.new-chat-btn:hover { opacity: 0.93; }

.search-box {
  width: 100%;
  background: var(--bg-root);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 7px 10px;
  color: var(--text-main);
  font-size: 12.5px;
  outline: none;
}
.search-box:focus { border-color: var(--accent); }

.conv-filters {
  display: flex;
  gap: 4px;
}
.filter-chip {
  flex: 1;
  text-align: center;
  padding: 4px 6px;
  font-size: 11px;
  border-radius: 6px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
}
.filter-chip.active {
  background: var(--accent-glow);
  border-color: var(--accent);
  color: #9dc0ff;
  font-weight: 600;
}

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

.conv-item {
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.12s;
}
.conv-item:hover { background: var(--bg-panel); }
.conv-item.active {
  background: var(--bg-elevated);
  border-color: var(--border-light);
}

.conv-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 4px;
}
.conv-title {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-meta-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-dim);
}

.badge {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 4px;
  font-weight: 600;
  text-transform: uppercase;
  flex-shrink: 0;
}
.badge-app { background: rgba(139, 92, 246, 0.18); color: #c4b5fd; }
.badge-ide { background: rgba(79, 140, 255, 0.18); color: #93c5fd; }
.badge-cli { background: rgba(16, 185, 129, 0.18); color: #6ee7b7; }
.badge-run { background: rgba(245, 158, 11, 0.22); color: #fcd34d; animation: pulse 1.4s infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

/* Center Chat Canvas */
.chat-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg-root);
}

.chat-subbar {
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  background: rgba(15, 21, 36, 0.65);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.ws-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.ws-label { font-size: 11.5px; color: var(--text-muted); }

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

.empty-hero {
  margin: auto;
  max-width: 540px;
  text-align: center;
  padding: 28px 16px;
}
.empty-hero img { width: 52px; height: 52px; margin-bottom: 12px; }
.empty-hero h2 { font-size: 20px; margin-bottom: 8px; }
.empty-hero p { color: var(--text-muted); font-size: 13.5px; line-height: 1.55; margin-bottom: 20px; }

.quick-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 8px;
  text-align: left;
}
.quick-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 11px 13px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.quick-card:hover { border-color: var(--accent); background: var(--bg-elevated); }
.quick-card strong { display: block; font-size: 12.5px; margin-bottom: 3px; color: #b8d0ff; }
.quick-card span { font-size: 11.5px; color: var(--text-muted); }

/* Messages */
.msg {
  max-width: 880px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.msg-user {
  align-self: flex-end;
  background: linear-gradient(135deg, #1e3a6d 0%, #262b5c 100%);
  border: 1px solid #355494;
  border-radius: 14px 14px 4px 14px;
  padding: 12px 15px;
  max-width: min(720px, 92%);
  margin-right: 0;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.5;
}

.msg-assistant {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
}

.msg-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11.5px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

/* Thinking & Tool Call accordions */
.thought-box, .tool-card {
  background: rgba(11, 15, 25, 0.65);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  font-size: 12px;
}
.thought-box summary, .tool-card summary {
  padding: 7px 11px;
  cursor: pointer;
  color: var(--text-muted);
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
  user-select: none;
  list-style: none;
}
.thought-box summary::-webkit-details-marker, .tool-card summary::-webkit-details-marker { display: none; }
.thought-body, .tool-body {
  padding: 9px 11px;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 11.5px;
  white-space: pre-wrap;
  max-height: 240px;
  overflow-y: auto;
}

.tool-status-active { color: var(--amber); font-weight: 600; }
.tool-status-done { color: var(--green); }

/* Markdown body */
.md-body {
  line-height: 1.62;
  color: var(--text-main);
  word-break: break-word;
}
.md-body p { margin-bottom: 10px; }
.md-body p:last-child { margin-bottom: 0; }
.md-body h1, .md-body h2, .md-body h3 { margin: 14px 0 8px; font-weight: 600; }
.md-body h1 { font-size: 18px; }
.md-body h2 { font-size: 16px; }
.md-body h3 { font-size: 14.5px; }
.md-body ul, .md-body ol { margin: 6px 0 10px 20px; }
.md-body li { margin-bottom: 4px; }
.md-body code {
  background: rgba(79, 140, 255, 0.13);
  color: #a8cbff;
  padding: 1.5px 5px;
  border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 12.5px;
}
.md-body pre {
  background: #080b12;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  overflow-x: auto;
  margin: 10px 0;
}
.md-body pre code {
  background: transparent;
  color: #e5edff;
  padding: 0;
}
.md-body a { color: #6ca4ff; text-decoration: none; }
.md-body a:hover { text-decoration: underline; }
.md-body table { border-collapse: collapse; width: 100%; margin: 10px 0; font-size: 12.5px; }
.md-body th, .md-body td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.md-body th { background: var(--bg-elevated); }

/* Composer */
.composer-wrap {
  padding: 10px 16px 14px;
  border-top: 1px solid var(--border);
  background: var(--bg-sidebar);
}
.composer-box {
  max-width: 880px;
  margin: 0 auto;
  background: var(--bg-root);
  border: 1px solid var(--border-light);
  border-radius: 12px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.composer-box:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

.composer-textarea {
  width: 100%;
  background: transparent;
  border: none;
  color: var(--text-main);
  font-family: inherit;
  font-size: 14px;
  resize: none;
  min-height: 44px;
  max-height: 180px;
  outline: none;
  line-height: 1.45;
}

.composer-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.composer-left {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.send-btn {
  background: linear-gradient(135deg, #4f8cff 0%, #6d5dfc 100%);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 7px 15px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
}
.send-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.stop-btn {
  background: rgba(239, 68, 68, 0.16);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.4);
  border-radius: 8px;
  padding: 7px 14px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  display: none;
}
.stop-btn.visible { display: inline-flex; align-items: center; gap: 5px; }

/* Right Auxiliary Studio Drawer (Files / Monaco / Artifacts / Git / Terminal) */
.aux-pane {
  width: 46%;
  min-width: 360px;
  max-width: 780px;
  background: var(--bg-sidebar);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
.aux-pane.collapsed { display: none; }

.aux-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--bg-root);
  padding: 0 8px;
  gap: 2px;
  overflow-x: auto;
}
.aux-tab {
  padding: 10px 12px;
  font-size: 12.5px;
  color: var(--text-muted);
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  font-weight: 500;
}
.aux-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

.aux-section {
  flex: 1;
  display: none;
  flex-direction: column;
  min-height: 0;
}
.aux-section.active { display: flex; }

/* File explorer + Monaco split */
.files-toolbar {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 6px;
}
.path-input {
  flex: 1;
  background: var(--bg-root);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 8px;
  color: var(--text-main);
  font-family: ui-monospace, Consolas, monospace;
  font-size: 12px;
}

.files-split {
  flex: 1;
  display: flex;
  min-height: 0;
}
.file-tree {
  width: 210px;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 6px;
  flex-shrink: 0;
}
.file-row {
  padding: 5px 8px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.file-row:hover { background: var(--bg-hover); }
.file-row.active { background: var(--accent-glow); color: #9ec2ff; }

.editor-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.editor-bar {
  height: 36px;
  padding: 0 10px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-muted);
}
#monaco-container {
  flex: 1;
  min-height: 0;
}

/* Terminal & Git */
.term-output {
  flex: 1;
  background: #060911;
  padding: 12px;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 12px;
  overflow-y: auto;
  white-space: pre-wrap;
  color: #d1e0ff;
}
.term-input-row {
  display: flex;
  border-top: 1px solid var(--border);
  padding: 8px;
  gap: 6px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--bg-elevated);
  border: 1px solid var(--accent);
  color: var(--text-main);
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13px;
  z-index: 2000;
  box-shadow: 0 10px 30px rgba(0,0,0,0.45);
  display: none;
}

/* Responsive Mobile / Tablet */
@media (max-width: 960px) {
  .sidebar {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    box-shadow: 12px 0 32px rgba(0, 0, 0, 0.65);
  }
  .aux-pane {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 100%;
    min-width: 0;
    z-index: 45;
  }
  .files-split { flex-direction: column; }
  .file-tree { width: 100%; max-height: 165px; border-right: none; border-bottom: 1px solid var(--border); }
  .sys-pill span.hide-sm { display: none; }
}
