/* ===== Variables base (tema claro por defecto) ===== */
:root {
  --bg: #0ea5e9;
  --bg2: #22d3ee;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --b: #e5e7eb;
  --ring: #93c5fd;
  --user: #346add;
  --bot: #f8fafc;
  --bot-text: #374151;
  --ok: #16a34a;
  --warn: #fef3c7;
  --warnb: #f59e0b;
  --danger: #ef4444;
  --shadow: 0 10px 30px rgba(2, 6, 23, 0.17);
}

/* ===== Respeta el SO sólo si NO hay clase forzada ===== */
@media (prefers-color-scheme: dark) {
  :root:not(.theme-dark):not(.theme-light) {
    --bg: #0b1220;
    --bg2: #0f172a;
    --card: #1e293b;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --b: #334155;
    --ring: #1e40af;
    --user: #3b82f6;
    --bot: #0f172a;
    --bot-text: #e2e8f0;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  }
}

/* ===== Overrides del toggle (AL FINAL para ganar) ===== */
html.theme-dark {
  --bg: #0b1220;
  --bg2: #0f172a;
  --card: #1e293b;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --b: #334155;
  --ring: #1e40af;
  --user: #3b82f6;
  --bot: #0f172a;
  --bot-text: #e2e8f0;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

html.theme-light {
  --bg: #023246;
  --bg2: #056c7c;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --b: #e5e7eb;
  --ring: #93c5fd;
  --user: #2563eb;
  --bot: #f8fafc;
  --bot-text: #374151;
  --shadow: 0 10px 30px rgba(2, 6, 23, 0.12);
}

* {
  box-sizing: border-box;
}
html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial;
  background: linear-gradient(135deg, var(--bg), var(--bg2));
  color: var(--text);
}

.app {
  min-height: 100dvh;
  display: grid;
  grid-template-rows: 1fr auto;
}

.main {
  max-width: 920px;
  margin: 14px auto;
  padding: 0 16px;
  width: 100%;
  display: grid;
  grid-template-columns: 1fr;
}

/* Controles */
.controls {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-bottom: 12px;
}

button.icon {
  border: 1px solid var(--b);
  background: var(--card);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: var(--shadow);
  transition: all 0.2s ease;
}
button.icon:hover {
  background: color-mix(in srgb, var(--card) 90%, var(--muted));
}
button.icon:focus-visible {
  outline: 3px solid var(--ring);
}

/* Switch tema */
.switch {
  position: absolute;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
  user-select: none;
  cursor: pointer;
}
.switch input {
  appearance: none;
  width: 42px;
  height: 24px;
  background: var(--b);
  border-radius: 999px;
  position: relative;
  outline: none;
  transition: 0.2s;
}
.switch input:after {
  content: "";
  width: 18px;
  height: 18px;
  background: var(--card);
  border-radius: 999px;
  position: absolute;
  top: 3px;
  left: 3px;
  transition: 0.2s;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}
.switch input:checked {
  background: var(--user);
}
.switch input:checked:after {
  left: 21px;
}

/* Chat */
.chatwrap {
  background: var(--card);
  border: 1px solid var(--b);
  border-radius: 18px;
  min-height: 70dvh;
  max-height: 92dvh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.messages {
  position: relative;
  padding: 14px;
  overflow: auto;
  flex: 1;
  scroll-behavior: smooth;

  background: url("./img/backgroud_logo_transparency.webp") center center no-repeat;
  background-size: 70%;       /* ajusta el tamaño de la marca de agua */
  background-attachment: fixed; /* evita que se mueva con el scroll */
}

@media (max-width: 840px){
  .messages {
    background-size: 100%; 
  }
}

.messages > * {
  position: relative;
  z-index: 1;
}

.row {
  display: flex;
  gap: 10px;
  margin: 10px 0;
  align-items: flex-end;
}
.row.user {
  justify-content: flex-end;
}

.avatar {
  width: 28px;
  height: 28px;
  border-radius: 10px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 12px;
  color: #fff;
  background: linear-gradient(135deg, #22c55e, #16a34a);
}
.avatar.bot {
  background: linear-gradient(135deg, #a78bfa, #7c3aed);
}

/* Burbujas */
.bubble {
  max-width: 78%;
  padding: 10px 12px;
  border-radius: 14px;
  line-height: 1.4;
  border: 1px solid var(--b);
  background: var(--bot);
  color: var(--bot-text);
  position: relative;
  white-space: pre-wrap; /* respeta los saltos de línea \n */
}

.user .bubble {
  background: #add1ff;
  color: #000000;
  border-color: #bbbbbb;
}
.meta {
  margin-top: 6px;
  font-size: 12px;
  color: #4d4d4d;
  display: flex;
  gap: 10px;
  align-items: center;
}

/* Typing */
.typing {
  display: inline-flex;
  gap: 6px;
  align-items: center;
}
.typing span {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  display: inline-block;
  background: currentColor;
  opacity: 0.55;
  animation: blink 1.2s infinite;
}
.typing span:nth-child(2) {
  animation-delay: 0.15s;
}
.typing span:nth-child(3) {
  animation-delay: 0.3s;
}
@keyframes blink {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.35;
  }
  40% {
    transform: translateY(-3px);
    opacity: 1;
  }
}

/* Avisos */
.warn {
  display: none;
  background: var(--warn);
  border: 1px solid var(--warnb);
  color: #7c2d12;
  padding: 12px 14px;
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.warn code {
  background: rgba(255, 255, 255, 0.2);
  padding: 2px 6px;
  border-radius: 6px;
}

/* Composer */
.composer {
  display: flex;
  gap: 10px;
  padding: 12px;
  border-top: 1px solid var(--b);
  background: color-mix(in srgb, var(--card) 90%, transparent);
  border-radius: 0 0 18px 18px;
}
.field {
  position: relative;
  flex: 1;
  display: flex;
  align-items: flex-end;
  border: 1px solid var(--b);
  border-radius: 14px;
  background: var(--card);
}
textarea {
  width: 100%;
  resize: none;
  max-height: 35dvh;
  min-height: 44px;
  padding: 12px 44px 12px 12px;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  line-height: 1.35;
}
textarea::placeholder {
  color: var(--muted);
}

.send {
  position: absolute;
  right: 6px;
  bottom: 3px;
  border: 0;
  background: var(--user);
  color: white;
  border-radius: 10px;
  cursor: pointer;
  padding: 7px 12px;
  box-shadow: var(--shadow);
  transition: all 0.2s ease;
}
.send:hover:not(:disabled) {
  background: color-mix(in srgb, var(--user) 85%, black);
}
.send:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
.send:focus-visible {
  outline: 3px solid var(--ring);
}

/* Footer */
.foot {
  color: black;
  font-size: 14px;
  text-align: center;
  padding: 12px;
}

:root.theme-dark .foot {
  color: rgb(190, 190, 190);
}

/* Scrollbar */
.messages::-webkit-scrollbar {
  width: 10px;
}
.messages::-webkit-scrollbar-thumb {
  background: var(--muted);
  border-radius: 999px;
  opacity: 0.3;
}
.messages::-webkit-scrollbar-track {
  background: transparent;
}

/* code */
code {
  background: rgba(0, 0, 0, 0.1);
  padding: 2px 6px;
  border-radius: 6px;
}
:root.theme-dark code {
  background: rgba(255, 255, 255, 0.1);
}
