* { box-sizing: border-box; margin: 0; }
:root {
  --bg: #f5f4f0;
  --panel: #ffffff;
  --ink: #1f2328;
  --muted: #6b7280;
  --accent: #b4432f;
  --accent-ink: #ffffff;
  --border: #e3e1da;
  --user-bubble: #eef0f4;
}
body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
  height: 100dvh;
}
.hidden { display: none !important; }
.screen { height: 100dvh; display: flex; flex-direction: column; }
.center {
  margin: auto;
  max-width: 440px;
  text-align: left;
}
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.card h1 { font-size: 22px; }
.steps { padding-left: 20px; display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.muted { color: var(--muted); font-size: 13px; }
.error { color: #b4432f; font-size: 14px; }

.btn {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--ink);
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 14px;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: 0.5; cursor: default; }

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 650; }
.tag {
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 11px;
  border-radius: 6px;
  padding: 2px 7px;
  vertical-align: 2px;
}
.actions { display: flex; align-items: center; gap: 10px; }

main#messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.bubble {
  padding: 12px 15px;
  border-radius: 12px;
  max-width: 100%;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  line-height: 1.45;
  font-size: 15px;
}
.bubble.user { background: var(--user-bubble); align-self: flex-end; max-width: 70%; }
.bubble.assistant { background: var(--panel); border: 1px solid var(--border); align-self: flex-start; }
.bubble.error { background: #fdecea; border: 1px solid #f5c6c0; align-self: stretch; }
.toolchip {
  align-self: flex-start;
  font-size: 12px;
  color: var(--muted);
  background: var(--panel);
  border: 1px dashed var(--border);
  border-radius: 999px;
  padding: 3px 10px;
}
.confirm-card {
  align-self: stretch;
  background: #fff8ef;
  border: 1px solid #eeddc2;
  border-radius: 12px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.confirm-card .title { font-weight: 650; font-size: 14px; }
.confirm-card pre {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  font-size: 12.5px;
  overflow-x: auto;
}
.confirm-card .row { display: flex; gap: 10px; }
.confirm-card .estado { font-size: 13px; color: var(--muted); }

footer {
  background: var(--panel);
  border-top: 1px solid var(--border);
  padding: 12px 18px;
}
footer form {
  display: flex;
  gap: 10px;
}
footer textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font: inherit;
  font-size: 15px;
  max-height: 140px;
}
#keyForm { display: flex; gap: 10px; }
#keyForm input {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  font: inherit;
}
/* ---------- layout con sidebar ---------- */
.layout { flex: 1; display: flex; min-height: 0; }
.chat-col { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#sidebar {
  width: 250px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
}
#convList { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 2px; }
#convList li {
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 13.5px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#convList li:hover { background: var(--bg); }
#convList li.active { background: var(--user-bubble); font-weight: 600; }

/* ---------- markdown en burbujas ---------- */
.bubble.md { white-space: normal; }
.bubble.md p { margin: 0 0 8px; }
.bubble.md p:last-child { margin-bottom: 0; }
.bubble.md h1, .bubble.md h2, .bubble.md h3 { margin: 12px 0 6px; line-height: 1.25; }
.bubble.md h1 { font-size: 19px; } .bubble.md h2 { font-size: 17px; } .bubble.md h3 { font-size: 15.5px; }
.bubble.md ul, .bubble.md ol { margin: 4px 0 10px; padding-left: 22px; }
.bubble.md li { margin: 2px 0; }
.bubble.md code {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 13px;
}
.bubble.md pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  overflow-x: auto;
  margin: 8px 0;
}
.bubble.md pre code { background: none; border: none; padding: 0; }
.bubble.md table { border-collapse: collapse; margin: 10px 0; max-width: 100%; display: block; overflow-x: auto; }
.bubble.md th, .bubble.md td { border: 1px solid var(--border); padding: 6px 10px; font-size: 13.5px; text-align: left; }
.bubble.md th { background: var(--bg); font-weight: 650; }
.bubble.md blockquote { border-left: 3px solid var(--border); margin: 8px 0; padding: 2px 12px; color: var(--muted); }
.bubble.md hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }

/* ---------- documentos HTML (artifacts) ---------- */
.doc-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  margin: 10px 0;
  background: var(--panel);
}
.doc-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
  font-weight: 600;
}
.doc-head .row { display: flex; gap: 8px; }
.doc-card iframe { width: 100%; height: clamp(440px, 60vh, 760px); border: none; background: #fff; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}
.modal-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}
.modal-bar .row { display: flex; gap: 8px; }
.modal iframe { flex: 1; border: none; background: #fff; }

@media (max-width: 700px) {
  .bubble { max-width: 95%; }
  #userEmail { display: none; }
  #sidebar {
    position: absolute;
    top: 53px;
    bottom: 0;
    left: 0;
    z-index: 20;
    transform: translateX(-100%);
    transition: transform 0.15s ease;
    box-shadow: 4px 0 14px rgba(0, 0, 0, 0.12);
  }
  #sidebar.open { transform: translateX(0); }
}
