body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-weight: 400;
  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;
}

.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(--bg-2);
  flex: 0 0 auto;
}

.chat-header__mark {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  overflow: hidden;
  background: #fff;
  border: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}

.chat-header__mark img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.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(--text);
}

.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(--accent);
}

.chat-header__status.is-offline::before { background: var(--danger); }

/* ---- 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: #fff;
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
  color: var(--text);
}

.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(--text); }
.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(--accent);
  color: var(--muted);
  background: var(--bg-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: var(--bg-2);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 13px;
}
.msg--bot pre {
  background: var(--bg-2);
  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(--bg-2); font-weight: 600; }

.msg--user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  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: #fff;
  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: #fff;
  color: var(--text-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(--accent); color: var(--accent-2); }

/* ---- 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(--bg-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: #fff;
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.4;
}

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

.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(--accent);
  color: #fff;
  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(--accent-2); }

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