:root {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1f232c;
  --border: #2a2f3a;
  --text: #e7e9ee;
  --text-muted: #9aa2b1;
  --accent: #4f8cff;
  --accent-2: #a56bff;
  --accent-text: #ffffff;
  --error: #ff6b6b;
  --ok: #3ddc84;
  --radius: 12px;
  --footer-h: 34px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --surface-2: #f0f1f4;
    --border: #e1e3e8;
    --text: #1a1d23;
    --text-muted: #666d7a;
    --accent: #2f6fed;
    --accent-2: #8b5cf6;
    --accent-text: #ffffff;
  }
}

* {
  box-sizing: border-box;
}

/* .tab-panel/.builder-panel fuerzan display:flex, lo que pisa el
   comportamiento nativo de [hidden] (display:none tiene menor
   especificidad que una regla de clase). Sin esto, los paneles ocultos
   igual se muestran apilados. */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app {
  display: flex;
  flex-direction: column;
  height: calc(100dvh - var(--footer-h));
  max-width: 820px;
  margin: 0 auto;
}

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

.app-header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
}

.btn-back {
  border: 1px solid var(--border);
  background: none;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.btn-back:hover {
  border-color: var(--accent);
  color: var(--text);
}

.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}

.status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
}

.dot.ok {
  background: var(--ok);
}

.dot.error {
  background: var(--error);
}

.tabs {
  display: flex;
  gap: 4px;
  padding: 10px 20px 0;
  border-bottom: 1px solid var(--border);
}

.tab {
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  padding: 8px 14px;
  cursor: pointer;
  border-radius: 8px 8px 0 0;
}

.tab:hover {
  color: var(--text);
}

.tab.active {
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-color: var(--surface);
  margin-bottom: -1px;
}

.tab-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.empty-state {
  margin: auto;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
  max-width: 340px;
  line-height: 1.5;
}

.msg {
  max-width: 85%;
  padding: 12px 14px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
}

/* user/error quedan como texto plano (textContent); assistant se llena con
   HTML de marked.js, así que necesita whitespace normal + estilos propios. */
.msg.user,
.msg.error,
.msg.pending {
  white-space: pre-wrap;
}

.msg.assistant :first-child {
  margin-top: 0;
}

.msg.assistant :last-child {
  margin-bottom: 0;
}

.msg.assistant p {
  margin: 0 0 10px;
}

.msg.assistant ul,
.msg.assistant ol {
  margin: 0 0 10px;
  padding-left: 22px;
}

.msg.assistant li {
  margin-bottom: 4px;
}

.msg.assistant code {
  background: var(--surface-2);
  padding: 2px 5px;
  border-radius: 4px;
  font-size: 12.5px;
}

.msg.assistant pre {
  background: var(--surface-2);
  padding: 10px 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 0 0 10px;
}

.msg.assistant pre code {
  background: none;
  padding: 0;
}

.msg.assistant table {
  border-collapse: collapse;
  width: 100%;
  margin: 0 0 10px;
  font-size: 13px;
}

.msg.assistant th,
.msg.assistant td {
  border: 1px solid var(--border);
  padding: 6px 8px;
  text-align: left;
}

.msg.user {
  align-self: flex-end;
  background: var(--accent);
  color: var(--accent-text);
  border-bottom-right-radius: 4px;
}

.msg.assistant {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.msg.error {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--error);
  color: var(--error);
}

.msg .meta {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-muted);
  white-space: normal;
}

.msg.pending {
  color: var(--text-muted);
  font-style: italic;
}

.composer {
  display: flex;
  gap: 10px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg);
}

.composer textarea {
  flex: 1;
  resize: none;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 10px 14px;
  font-size: 14px;
  font-family: inherit;
  max-height: 140px;
}

.composer textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

.composer button {
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-text);
  padding: 0 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.composer button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.composer button:not(:disabled):hover {
  filter: brightness(1.1);
}

/* --- Construcción de agentes --- */

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

.builder-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.builder-intro {
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.5;
  margin: 0;
}

#builder-start-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.builder textarea {
  width: 100%;
  resize: vertical;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 10px 14px;
  font-size: 14px;
  font-family: inherit;
}

.builder textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

.btn-primary,
.btn-secondary,
.btn-ghost {
  border: none;
  border-radius: var(--radius);
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  align-self: flex-start;
  transition: transform 0.15s ease, filter 0.15s ease;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-text);
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-ghost {
  background: none;
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.btn-primary:disabled,
.btn-secondary:disabled,
.btn-ghost:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.builder-review-header {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.phase-badge {
  background: var(--accent);
  color: var(--accent-text);
  font-size: 11px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
}

.build-dir {
  font-size: 12px;
  color: var(--text-muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.builder-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  font-size: 14px;
  line-height: 1.6;
  max-height: 50vh;
  overflow-y: auto;
}

.builder-content :first-child {
  margin-top: 0;
}

.builder-content p {
  margin: 0 0 10px;
}

.builder-content ul,
.builder-content ol {
  margin: 0 0 10px;
  padding-left: 22px;
}

.builder-content h1,
.builder-content h2,
.builder-content h3 {
  margin: 16px 0 8px;
}

.builder-content code {
  background: var(--surface-2);
  padding: 2px 5px;
  border-radius: 4px;
  font-size: 12.5px;
}

.builder-content img {
  max-width: 100%;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.builder-actions {
  display: flex;
  gap: 10px;
}

.builder-feedback {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.builder-done-msg {
  font-size: 14px;
  line-height: 1.6;
}

.builder-done-msg code {
  background: var(--surface-2);
  padding: 2px 6px;
  border-radius: 4px;
}

.builder-error {
  color: var(--error);
  font-size: 13px;
  border: 1px solid var(--error);
  border-radius: var(--radius);
  padding: 10px 14px;
}

/* --- Landing --- */

.landing {
  position: relative;
  height: calc(100dvh - var(--footer-h));
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 24px;
}

.landing-bg {
  position: absolute;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(600px circle at 20% 15%, color-mix(in srgb, var(--accent) 22%, transparent), transparent 60%),
    radial-gradient(600px circle at 85% 80%, color-mix(in srgb, var(--accent-2) 20%, transparent), transparent 60%);
}

.landing-content {
  position: relative;
  z-index: 1;
  max-width: 620px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  animation: landing-in 0.5s ease both;
}

@keyframes landing-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.landing-logo {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 8px 30px color-mix(in srgb, var(--accent) 35%, transparent);
}

.landing-title {
  font-size: clamp(32px, 6vw, 48px);
  font-weight: 800;
  margin: 0;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--text), var(--text) 40%, var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.landing-subtitle {
  margin: 0;
  color: var(--text-muted);
  font-size: 15px;
  line-height: 1.6;
  max-width: 480px;
}

.landing-demo {
  width: 560px;
  max-width: 100%;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: 0 12px 40px rgb(0 0 0 / 0.35);
}

.landing-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 4px;
}

.chip {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 5px 12px;
  border-radius: 999px;
}

.landing-cta {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  margin-top: 10px;
}

.btn-lg {
  padding: 13px 22px;
  font-size: 14px;
  border-radius: 12px;
}

.btn-primary.btn-lg {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 6px 20px color-mix(in srgb, var(--accent) 30%, transparent);
}

.btn-primary.btn-lg:hover,
.btn-secondary.btn-lg:hover {
  transform: translateY(-1px);
}

.landing-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 8px;
}

/* --- Transiciones de mensajes --- */

.msg {
  animation: msg-in 0.25s ease both;
}

@keyframes msg-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.site-footer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--footer-h);
  z-index: 20;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 16px;
  font-size: 12px;
  color: var(--text-muted);
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.site-footer a {
  color: var(--text-muted);
  text-decoration: none;
}

.site-footer a:hover {
  color: var(--accent);
  text-decoration: underline;
}
