body {
  background: var(--ink);
  color: var(--cream);
  font-family: var(--sans);
  font-weight: 300;
  font-size: 16px;
  line-height: 1.5;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Mismo rol de layout que antes tenían header/chat-log/chips/chat-input
   como hijos directos de body — ahora anidados para tener un landmark <main>. */
.chat-main {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}

/* ---- Header ---------------------------------------------------- */

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px clamp(16px, 4vw, 28px);
  border-bottom: 1px solid var(--line);
  background: var(--ink-2);
  flex: 0 0 auto;
}

.chat-header__mark img {
  width: 52px;
  height: auto;
  display: block;
}

.chat-header__type {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.chat-header__name {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 17px;
  color: var(--cream);
}

.chat-header__status {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 5px;
}

.chat-header__status::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--gold);
}

.chat-header__status.is-offline::before { background: #b3543f; }

.chat-header__book {
  margin-left: auto;
  flex: 0 0 auto;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--gold-soft);
  color: var(--gold);
  font-size: 13px;
  font-weight: 500;
  border: 1px solid rgba(201, 169, 97, 0.35);
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast);
  white-space: nowrap;
}

.chat-header__book:hover { background: var(--gold); color: var(--ink); }

/* ---- Historial ---------------------------------------------------- */

.chat-log {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 20px clamp(16px, 4vw, 28px);
  display: flex;
  flex-direction: column;
  gap: 14px;
  -webkit-overflow-scrolling: touch;
}

.msg {
  max-width: 84%;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 15px;
  line-height: 1.55;
  word-wrap: break-word;
}

.msg--bot {
  align-self: flex-start;
  background: var(--ink-3);
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
  color: var(--cream);
}

/* Elementos del renderer markdown-lite (ver js/chat.js renderMarkdownLite) */
.msg--bot .md-p { margin: 0 0 10px; }
.msg--bot .md-p:last-child { margin-bottom: 0; }
.msg--bot .md-h { margin: 12px 0 6px; line-height: 1.3; font-family: var(--serif); color: var(--cream); }
.msg--bot .md-h:first-child { margin-top: 0; }
.msg--bot .md-hr { border: none; border-top: 1px solid var(--line); margin: 10px 0; }
.msg--bot .md-quote {
  margin: 8px 0;
  padding: 4px 12px;
  border-left: 3px solid var(--gold);
  color: var(--muted);
  background: rgba(0, 0, 0, 0.2);
  border-radius: 0 6px 6px 0;
}
.msg--bot .md-list { margin: 0 0 10px; padding-left: 22px; }
.msg--bot .md-list li { margin-bottom: 4px; }
.msg--bot code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  background: rgba(0, 0, 0, 0.35);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 13px;
}
.msg--bot pre {
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  overflow-x: auto;
  margin: 6px 0;
}
.msg--bot pre code { background: none; padding: 0; }
.msg--bot table { border-collapse: collapse; width: 100%; margin: 8px 0 12px; font-size: 13.5px; }
.msg--bot th, .msg--bot td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; vertical-align: top; }
.msg--bot th { background: var(--ink-2); font-weight: 600; }

.msg--user {
  align-self: flex-end;
  background: var(--gold);
  color: var(--ink);
  white-space: pre-wrap;
  border-bottom-right-radius: 4px;
  font-weight: 400;
}

.msg--system {
  align-self: center;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  max-width: 100%;
}

.typing {
  align-self: flex-start;
  display: inline-flex;
  gap: 4px;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  border-bottom-left-radius: 4px;
  background: var(--ink-3);
  border: 1px solid var(--line);
}

.typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  animation: typing-bounce 1.2s infinite ease-in-out;
}

.typing span:nth-child(2) { animation-delay: .15s; }
.typing span:nth-child(3) { animation-delay: .3s; }

@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* ---- Chips de preguntas frecuentes -------------------------------- */

.chips {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 clamp(16px, 4vw, 28px) 12px;
}

.chip {
  flex: 0 0 auto;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--ink-2);
  color: var(--cream-2);
  font-size: 13px;
  white-space: normal;
  text-align: left;
  cursor: pointer;
  transition: border-color var(--t-fast), color var(--t-fast);
}

.chip:hover { border-color: var(--gold); color: var(--gold); }

/* ---- Input --------------------------------------------------------- */

.chat-input {
  flex: 0 0 auto;
  display: flex;
  gap: 10px;
  align-items: flex-end;
  padding: 12px clamp(16px, 4vw, 28px) calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--ink-2);
}

.chat-input textarea {
  flex: 1 1 auto;
  resize: none;
  max-height: 120px;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: var(--ink-3);
  color: var(--cream);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.4;
}

.chat-input textarea:focus {
  outline: none;
  border-color: var(--gold);
}

.chat-input textarea::placeholder { color: var(--muted); }

.chat-input button {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--gold);
  color: var(--ink);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--t-fast), opacity var(--t-fast);
}

.chat-input button:hover { background: var(--gold-2); }

.chat-input button:disabled {
  opacity: .4;
  cursor: default;
}

/* ---- Bottom sheet: agendar cita ------------------------------------ */

.sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .6);
  opacity: 0;
  transition: opacity var(--t-base);
  z-index: 40;
}

.sheet-overlay.is-open { opacity: 1; }

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 41;
  max-height: 82vh;
  overflow-y: auto;
  background: var(--ink-2);
  border: 1px solid var(--line);
  border-bottom: none;
  border-radius: 20px 20px 0 0;
  padding: 18px clamp(16px, 4vw, 28px) calc(20px + env(safe-area-inset-bottom));
  transform: translateY(100%);
  transition: transform var(--t-base);
}

.sheet.is-open { transform: translateY(0); }

.sheet__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sheet__title {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 20px;
  color: var(--cream);
}

.sheet__close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
}

.sheet__note {
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
}

.sheet__step { margin-top: 18px; }

.sheet__label {
  font-size: 13px;
  font-weight: 500;
  color: var(--cream-2);
  margin-bottom: 8px;
}

.chips--sheet {
  padding: 0;
}

.chip--active {
  border-color: var(--gold);
  background: var(--gold-soft);
  color: var(--gold);
}

.sheet__loading {
  font-size: 13px;
  color: var(--muted);
}

.sheet__form {
  margin-top: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sheet__form input {
  padding: 12px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: var(--ink-3);
  color: var(--cream);
  font-family: var(--sans);
  font-size: 15px;
}

.sheet__form input:focus {
  outline: none;
  border-color: var(--gold);
}

.sheet__form input::placeholder { color: var(--muted); }

.sheet__confirm {
  margin-top: 4px;
  padding: 13px;
  border-radius: var(--radius-md);
  border: none;
  background: var(--gold);
  color: var(--ink);
  font-weight: 500;
  font-size: 15px;
  cursor: pointer;
  transition: background var(--t-fast), opacity var(--t-fast);
}

.sheet__confirm:hover { background: var(--gold-2); }
.sheet__confirm:disabled { opacity: .5; cursor: default; }

.sheet__error {
  margin-top: 12px;
  font-size: 13px;
  color: #d98a76;
}

.sheet__success {
  margin-top: 18px;
  text-align: center;
  font-size: 15px;
  color: var(--cream);
}
