:root {
  --bg: #f6f4ee;
  --surface: #ffffff;
  --surface-2: #efece3;
  --ink: #1d231f;
  --ink-2: #5d665f;
  --line: #e1ddd1;
  --brand: #1f7a4d;
  --brand-ink: #ffffff;
  --brand-soft: #dff0e6;
  --warn: #a15c00;
  --warn-soft: #fbeed6;
  --radius: 16px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131714;
    --surface: #1c221e;
    --surface-2: #252c27;
    --ink: #e9ede9;
    --ink-2: #9aa59d;
    --line: #2f3832;
    --brand: #4fbf86;
    --brand-ink: #0c1a12;
    --brand-soft: #1d3327;
    --warn: #f0b860;
    --warn-soft: #3a2e17;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}

/* ---------- Barra superior ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand h1, .brand .name { display: block; margin: 0; font-weight: 700; font-size: 18px; letter-spacing: 0.04em; }
.brand p { margin: 0; font-size: 13px; color: var(--ink-2); }
.avatar {
  display: grid;
  place-items: center;
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--brand-soft);
  font-size: 20px;
}

.avatar.logo { background: none; border-radius: 0; }

.steps {
  display: flex;
  gap: 6px;
  margin: 0 0 0 auto;
  padding: 0;
  list-style: none;
  counter-reset: step;
  font-size: 13px;
  color: var(--ink-2);
}
.steps li {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 4px 4px;
  border-radius: 999px;
  counter-increment: step;
}
.steps li::before {
  content: counter(step);
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--surface-2);
  font-size: 12px;
  font-weight: 600;
}
.steps li.done::before { content: "✓"; background: var(--brand-soft); color: var(--brand); }
.steps li.current { background: var(--brand-soft); color: var(--ink); font-weight: 600; }
.steps li.current::before { background: var(--brand); color: var(--brand-ink); }

.panel-toggle {
  display: none;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}

/* ---------- Layout ---------- */
.layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
}
.chat { display: flex; flex-direction: column; min-height: 0; }
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px 8px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.messages > * { width: 100%; max-width: 720px; margin-inline: auto; }

.msg { display: flex; gap: 10px; align-items: flex-end; }
.msg .avatar { width: 32px; height: 32px; font-size: 16px; }
.bubble {
  max-width: min(100%, 600px);
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
  overflow-wrap: anywhere;
}
.msg.user { justify-content: flex-end; }
.msg.user .bubble { max-width: min(85%, 600px); }
.msg.user .bubble {
  background: var(--brand);
  color: var(--brand-ink);
  border-color: transparent;
  border-radius: var(--radius);
  border-bottom-right-radius: 4px;
  white-space: pre-wrap;
}
.bubble > :first-child { margin-top: 0; }
.bubble > :last-child { margin-bottom: 0; }
.bubble p, .bubble ul, .bubble ol { margin: 0 0 10px; }
.bubble ul, .bubble ol { padding-left: 20px; }
.bubble h3 { margin: 14px 0 6px; font-size: 15px; }
.bubble .table-wrap { overflow-x: auto; margin: 0 0 10px; }
.bubble table { border-collapse: collapse; font-size: 14px; min-width: 100%; }
.bubble th, .bubble td { padding: 5px 10px; border-bottom: 1px solid var(--line); text-align: left; }
.bubble th { color: var(--ink-2); font-weight: 600; white-space: nowrap; }

.status { display: flex; align-items: center; gap: 10px; color: var(--ink-2); font-size: 14px; }
.dots { display: inline-flex; gap: 4px; }
.dots i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  animation: blink 1.2s infinite both;
}
.dots i:nth-child(2) { animation-delay: 0.2s; }
.dots i:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .dots i { animation: none; opacity: 0.6; } }

.confirm {
  padding: 14px;
  border-radius: var(--radius);
  background: var(--warn-soft);
  border: 1px solid transparent;
}
.confirm p { margin: 0 0 10px; }
.confirm .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn {
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: transparent; font-weight: 600; }

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  width: calc(100% - 40px);
  max-width: 720px;
  margin: 8px auto max(16px, env(safe-area-inset-bottom));
  padding: 8px 8px 8px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 24px;
}
.composer:focus-within { border-color: var(--brand); }
.composer textarea {
  flex: 1;
  max-height: 160px;
  padding: 6px 0;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  color: inherit;
  font: inherit;
}
.composer button {
  display: grid;
  place-items: center;
  flex: none;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 50%;
  background: var(--brand);
  color: var(--brand-ink);
  cursor: pointer;
}
.composer button:disabled { opacity: 0.4; cursor: default; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.composer textarea:focus-visible { outline: 0; }

/* ---------- Panel "Mi compra" ---------- */
.panel {
  overflow-y: auto;
  padding: 20px;
  background: var(--surface);
  border-left: 1px solid var(--line);
  font-size: 14px;
}
.panel h2 { margin: 0 0 4px; font-size: 16px; }
.panel .sub { margin: 0 0 16px; color: var(--ink-2); }
.panel section + section { margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--line); }
.panel h3 {
  margin: 16px 0 6px;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-2);
}
.rows { margin: 0; padding: 0; list-style: none; }
.rows li { display: flex; justify-content: space-between; gap: 12px; padding: 5px 0; }
.rows li span:last-child { flex: none; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.rows a { color: inherit; text-decoration-color: var(--line); text-underline-offset: 3px; }
.rows a:hover { text-decoration-color: currentColor; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--brand);
  font-size: 12px;
  font-weight: 600;
}
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.cart { margin-top: 12px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; }
.cart header { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-weight: 600; }
.cart .totals { margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--line); }
.rows.opened a { color: var(--ink-2); text-decoration: line-through; }
.rows .mark { margin-left: 8px; padding: 0; border: 0; background: none; color: var(--brand); font: inherit; font-size: 12px; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.cart-open { display: block; margin-top: 12px; text-align: center; text-decoration: none; }
.grand { display: flex; justify-content: space-between; margin-top: 14px; font-size: 16px; font-weight: 700; }
.note { margin: 8px 0 0; color: var(--ink-2); }
.empty { color: var(--ink-2); }

/* ---------- Móvil ---------- */
@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .steps li:not(.current) { padding-right: 4px; font-size: 0; gap: 0; }
  .steps { margin-left: auto; }
  .panel-toggle { display: block; }
  .topbar { gap: 12px; padding: 10px 16px; }
  .brand p { display: none; }
  .panel {
    position: fixed;
    inset: 61px 0 0 0;
    z-index: 5;
    border-left: 0;
    display: none;
  }
  .panel.open { display: block; }
  .messages { padding: 16px 16px 8px; }
  .composer { width: calc(100% - 32px); }
}
@media (max-width: 480px) {
  /* Ocultos pero contando, para que el paso actual conserve su número. */
  .steps li:not(.current) { position: absolute; visibility: hidden; }
}
