:root {
  --bg: #0d1117;
  --bg-raised: #161b22;
  --bg-input: #0b0f14;
  --border: #262d36;
  --text: #e2e8ef;
  --text-dim: #8b95a5;
  --accent: #4f9cf9;
  --accent-dim: #1f3a5f;
  --green: #4ec9a5;
  --red: #f4736b;
  --yellow: #e2b341;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  display: grid;
  grid-template-columns: 260px 1fr;
  height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.55;
}

/* ---------- sidebar ---------- */

#sidebar {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--bg-raised);
  min-height: 0;
}

#sidebar header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

#sidebar h1 { font-size: 15px; margin: 0; letter-spacing: .5px; }

#new-session {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 6px;
  width: 26px;
  height: 26px;
  font-size: 16px;
  cursor: pointer;
}
#new-session:hover { color: var(--text); border-color: var(--accent); }

#session-list { flex: 1; overflow-y: auto; padding: 8px; min-height: 0; }

.session {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: var(--text-dim);
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.session:hover { background: #1f242c; color: var(--text); }
.session.active { background: var(--accent-dim); color: var(--text); }

#services {
  border-top: 1px solid var(--border);
  padding: 10px 12px;
  max-height: 34vh;
  overflow-y: auto;
  flex-shrink: 0;
}
#services h2 {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .9px;
  color: var(--text-dim);
  margin: 0 0 8px 4px;
  font-weight: 600;
}
#services:not(:has(.service)) { display: none; }

.service {
  display: flex;
  align-items: baseline;
  gap: 7px;
  padding: 5px 4px;
  font-family: var(--mono);
  font-size: 11px;
  border-radius: 5px;
}
.service:hover { background: #1f242c; }
.service .dot { font-size: 9px; flex-shrink: 0; }
.service .dot.running { color: var(--green); }
.service .dot.unhealthy, .service .dot.starting { color: var(--yellow); }
.service .dot.crashed { color: var(--red); }
.service .dot.stopped { color: var(--text-dim); }
.service .name { color: var(--text); flex: 1; overflow: hidden; text-overflow: ellipsis; }
.service .port { color: var(--text-dim); }
.service a { color: var(--accent); text-decoration: none; }
.service a:hover { text-decoration: underline; }

#app-info {
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-dim);
  font-family: var(--mono);
}
#app-info a { color: var(--accent); text-decoration: none; }

/* ---------- main ---------- */

main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 0 8px;
  min-height: 0;
}

.empty { max-width: 620px; margin: 18vh auto; text-align: center; color: var(--text-dim); padding: 0 24px; }
.empty h2 { color: var(--text); font-weight: 500; margin-bottom: 8px; }

.msg { max-width: 780px; margin: 0 auto 18px; padding: 0 24px; }

.msg.user .bubble {
  background: var(--accent-dim);
  border-radius: 10px;
  padding: 10px 14px;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.assistant .bubble { white-space: pre-wrap; word-break: break-word; }

.msg .role {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.msg.error .bubble {
  border-left: 3px solid var(--red);
  background: #2a1a1a;
  padding: 10px 14px;
  border-radius: 0 8px 8px 0;
  color: #ffc9c4;
}

.msg.note .bubble {
  color: var(--text-dim);
  font-size: 12px;
  font-style: italic;
}

/* ---------- tool calls ---------- */

.tool {
  max-width: 780px;
  margin: 0 auto 10px;
  padding: 0 24px;
}

.tool-box {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-input);
  overflow: hidden;
}

.tool-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  cursor: pointer;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-dim);
  user-select: none;
}
.tool-head:hover { color: var(--text); }
.tool-head .name { color: var(--accent); }
.tool-head .cmd {
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}
.tool-head .spinner { color: var(--yellow); }
.tool-head .ok { color: var(--green); }
.tool-head .fail { color: var(--red); }

.tool-body {
  border-top: 1px solid var(--border);
  padding: 10px 12px;
  margin: 0;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 420px;
  overflow-y: auto;
  color: #c4ccd8;
}
.tool-box[data-open="false"] .tool-body { display: none; }

/* ---------- composer ---------- */

#composer {
  border-top: 1px solid var(--border);
  background: var(--bg-raised);
  padding: 10px 24px 14px;
}

#composer .row {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 780px;
  margin: 0 auto 8px;
  font-size: 11px;
  font-family: var(--mono);
  color: var(--text-dim);
}

#model {
  background: var(--bg-input);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
  font-family: var(--mono);
  font-size: 11px;
  max-width: 340px;
}

#status { flex: 1; }
#status.busy { color: var(--yellow); }

.input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  max-width: 780px;
  margin: 0 auto;
}

#input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 10px 12px;
  font-family: inherit;
  font-size: 14px;
  resize: none;
  max-height: 200px;
  line-height: 1.5;
}
#input:focus { outline: none; border-color: var(--accent); }

#send, #stop {
  border: none;
  border-radius: 8px;
  padding: 10px 18px;
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
}
#send { background: var(--accent); color: #06121f; font-weight: 500; }
#send:disabled { opacity: .4; cursor: not-allowed; }
#stop { background: var(--red); color: #2a0d0b; font-weight: 500; }

@media (max-width: 720px) {
  body { grid-template-columns: 1fr; }
  #sidebar { display: none; }
}

/* ---------- login / projects (pantallas simples, sin sidebar) ---------- */

body.screen {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.card {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  width: 100%;
  max-width: 420px;
}

.card h1 { margin: 0 0 4px; font-size: 20px; }
.card p.hint { margin: 0 0 24px; color: var(--text-dim); font-size: 13px; }

.card input[type="text"] {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  margin-bottom: 14px;
}
.card input[type="text"]:focus { outline: none; border-color: var(--accent); }

.card button.primary {
  width: 100%;
  background: var(--accent);
  color: #06121f;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}

.card .error { color: var(--red); font-size: 13px; margin-top: 10px; min-height: 1em; }

/* ---------- lista de proyectos ---------- */

body.screen.wide { align-items: flex-start; }
.wide .card { max-width: 640px; margin-top: 40px; }

.card header.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.card header.top h1 { margin: 0; }
.card .user-tag { color: var(--text-dim); font-size: 13px; }

#new-project-form { display: flex; gap: 8px; margin-bottom: 20px; }
#new-project-form input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 8px 12px;
  font-family: inherit;
  font-size: 14px;
}
#new-project-form button {
  background: var(--accent);
  color: #06121f;
  border: none;
  border-radius: 8px;
  padding: 8px 16px;
  font-weight: 500;
  cursor: pointer;
}

#project-list { display: flex; flex-direction: column; gap: 8px; }

.project-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-input);
}
.project-row .dot { font-size: 11px; }
.project-row .dot.running { color: var(--green); }
.project-row .dot.exited, .project-row .dot.stopped { color: var(--text-dim); }
.project-row .dot.error, .project-row .dot.missing { color: var(--red); }

.project-row .name {
  flex: 1;
  cursor: pointer;
  font-weight: 500;
}
.project-row .domain {
  color: var(--text-dim);
  font-size: 12px;
  text-decoration: none;
}

.project-row .actions { display: flex; gap: 4px; }
.project-row button {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 12px;
  cursor: pointer;
}
.project-row button:hover { color: var(--text); border-color: var(--accent); }
.project-row button.danger:hover { color: var(--red); border-color: var(--red); }

.empty-hint { color: var(--text-dim); font-size: 13px; text-align: center; padding: 24px 0; }
