:root {
  --bg: #090d16;
  --surface: #111827;
  --surface-alt: #1e293b;
  --border: #243045;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-strong: #0284c7;
  --green: #22c55e;
  --danger: #ef4444;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.tiny { font-size: 0.78rem; }
.stack { display: flex; flex-direction: column; gap: 0.8rem; }
.row-gap { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }

/* Auth */
.auth-shell {
  height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

.auth-card {
  width: 100%;
  max-width: 410px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 2rem;
}

.brand-badge {
  display: inline-block;
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
  background: rgba(56, 189, 248, 0.14);
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.9rem;
}

input, select, textarea {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem 0.75rem;
  font-family: inherit;
  font-size: 0.92rem;
}

input:focus, select:focus, textarea:focus {
  outline: 2px solid rgba(56, 189, 248, 0.35);
  border-color: var(--accent);
}

.btn {
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  border-radius: 8px;
  padding: 0.5rem 0.9rem;
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.btn.primary { background: var(--accent-strong); border-color: var(--accent); }
.btn.secondary { background: var(--surface-alt); }
.btn.ghost { background: transparent; }
.btn.small-btn { padding: 0.35rem 0.65rem; font-size: 0.82rem; }
.btn.full-btn { width: 100%; justify-content: center; margin-top: 0.65rem; }
.btn:disabled, .disabled-link { opacity: 0.45; pointer-events: none; }

.btn.inspect-btn.active {
  background: rgba(34, 197, 94, 0.16);
  border-color: var(--green);
  color: #86efac;
}

/* Workspace Layout */
.workspace {
  display: grid;
  grid-template-columns: 240px minmax(360px, 1fr) minmax(400px, 1.05fr);
  height: 100vh;
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1rem;
  overflow: hidden;
}

.brand-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
}

.sidebar-label {
  margin-top: 1rem;
  margin-bottom: 0.45rem;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.projects-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.project-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.35rem;
  padding: 0.5rem 0.65rem;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  background: transparent;
  color: var(--muted);
}

.project-item:hover { background: var(--surface-alt); color: var(--text); }
.project-item.active {
  background: rgba(56, 189, 248, 0.13);
  border-color: rgba(56, 189, 248, 0.35);
  color: var(--text);
}

.project-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.9rem;
}

.del-proj-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}
.del-proj-btn:hover { color: #fca5a5; }

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

/* Panes */
.chat-pane, .preview-pane {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.chat-pane {
  border-right: 1px solid var(--border);
}

.pane-header {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.pane-header h2 {
  margin: 0;
  font-size: 1rem;
}

.path-chip {
  font-size: 0.76rem;
  font-family: ui-monospace, monospace;
  color: var(--muted);
  background: var(--bg);
  padding: 0.15rem 0.45rem;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.model-select {
  max-width: 245px;
  padding: 0.35rem 0.6rem;
  font-size: 0.84rem;
}

/* Messages */
.messages-feed {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.empty-state {
  margin: auto;
  text-align: center;
  max-width: 440px;
}

.msg-card {
  max-width: 92%;
  border-radius: 12px;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  background: var(--surface);
}

.msg-card.user {
  align-self: flex-end;
  background: rgba(2, 132, 199, 0.18);
  border-color: rgba(56, 189, 248, 0.35);
}

.msg-card.assistant {
  align-self: flex-start;
  width: 100%;
}

.msg-meta {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.76rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
  flex-wrap: wrap;
}

.target-tag {
  color: #86efac;
  background: rgba(34, 197, 94, 0.14);
  border: 1px solid rgba(34, 197, 94, 0.35);
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  font-family: ui-monospace, monospace;
}

.msg-body {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.92rem;
  line-height: 1.55;
}

.thinking-pill {
  align-self: flex-start;
  padding: 0.55rem 0.9rem;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--accent);
  font-size: 0.85rem;
}

/* Composer */
.composer-wrap {
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.selected-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.55rem;
  padding: 0.3rem 0.65rem;
  border-radius: 999px;
  background: rgba(34, 197, 94, 0.14);
  border: 1px solid rgba(34, 197, 94, 0.4);
  color: #86efac;
  font-size: 0.82rem;
  font-family: ui-monospace, monospace;
}

.chip-close {
  background: transparent;
  border: none;
  color: #86efac;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}

.composer-form {
  display: flex;
  gap: 0.6rem;
  align-items: flex-end;
}

.composer-form textarea {
  flex: 1;
  resize: none;
  min-height: 46px;
  max-height: 140px;
}

/* Preview & Files */
.tab-btn {
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0.35rem 0.7rem;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
}

.tab-btn.active {
  background: rgba(56, 189, 248, 0.14);
  border-color: rgba(56, 189, 248, 0.35);
  color: var(--accent);
}

.preview-stage {
  flex: 1;
  background: #060911;
  display: flex;
  justify-content: center;
  padding: 0.75rem;
  overflow: auto;
}

.preview-frame-wrap {
  width: 100%;
  height: 100%;
  background: #fff;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  transition: width 180ms ease;
}

.preview-frame-wrap.mobile {
  width: 390px;
  max-width: 100%;
}

.preview-frame-wrap iframe {
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;
}

.files-stage {
  flex: 1;
  display: grid;
  grid-template-rows: 170px 1fr;
  overflow: hidden;
}

.files-list {
  overflow-y: auto;
  padding: 0.75rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.file-row {
  display: flex;
  justify-content: space-between;
  padding: 0.4rem 0.65rem;
  border-radius: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
  font-family: ui-monospace, monospace;
  font-size: 0.82rem;
}
.file-row:hover { border-color: var(--accent); }

.file-viewer {
  margin: 0;
  padding: 1rem;
  overflow: auto;
  background: var(--bg);
  font-family: ui-monospace, monospace;
  font-size: 0.82rem;
  line-height: 1.5;
}

.alert {
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  background: rgba(239, 68, 68, 0.14);
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: #fecaca;
  font-size: 0.86rem;
}

.toast {
  margin: 0.5rem 1rem 0;
  padding: 0.55rem 0.85rem;
  border-radius: 8px;
  background: rgba(56, 189, 248, 0.14);
  border: 1px solid rgba(56, 189, 248, 0.35);
  font-size: 0.86rem;
}
.toast.error {
  background: rgba(239, 68, 68, 0.14);
  border-color: rgba(239, 68, 68, 0.4);
}

@media (max-width: 1050px) {
  body { overflow: auto; height: auto; }
  .workspace { grid-template-columns: 1fr; height: auto; }
  .chat-pane, .preview-pane { height: 75vh; }
}
