/* Widget flotante CodexAeternum — esquina inferior derecha */
#codex-chat-launcher {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  width: 3.75rem;
  height: 3.75rem;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: var(--button-color);
  box-shadow: 0 4px 14px var(--shadow-color);
  cursor: pointer;
  z-index: 1050;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

#codex-chat-launcher:hover {
  transform: scale(1.04);
  box-shadow: 0 6px 18px var(--shadow-color);
}

#codex-chat-launcher img {
  width: 70%;
  height: 70%;
  object-fit: contain;
  pointer-events: none;
}

#codex-chat-panel {
  position: fixed;
  bottom: 5.5rem;
  right: 1.25rem;
  width: min(22rem, calc(100vw - 2rem));
  height: min(28rem, calc(100vh - 8rem));
  background: var(--chat-background-color);
  box-shadow: 0 8px 24px var(--shadow-color);
  border-radius: 12px;
  display: none;
  flex-direction: column;
  z-index: 1050;
  overflow: hidden;
  border: 1px solid rgba(91, 16, 172, 0.2);
}

#codex-chat-panel.is-open {
  display: flex;
}

.codex-chat-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 0.85rem;
  background: var(--button-color);
  color: var(--text-button-color);
}

.codex-chat-header h2 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
}

.codex-chat-close {
  border: none;
  background: transparent;
  color: inherit;
  padding: 0.25rem;
  cursor: pointer;
  border-radius: 6px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.codex-chat-close:hover {
  background: rgba(255, 255, 255, 0.15);
}

#codex-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.codex-chat-msg {
  max-width: 88%;
  padding: 0.5rem 0.75rem;
  border-radius: 12px;
  word-wrap: break-word;
  font-size: 0.9rem;
  line-height: 1.4;
}

.codex-chat-msg.user {
  align-self: flex-end;
  background: var(--button-color);
  color: var(--text-button-color);
}

.codex-chat-msg.bot {
  align-self: flex-start;
  background: var(--chat-input-color);
  color: var(--text-normal-color);
  border: 1px solid rgba(0, 0, 0, 0.06);
}

.codex-chat-msg.loading {
  opacity: 0.75;
  font-style: italic;
}

/* Markdown (respuestas del asistente) */
.codex-chat-msg.codex-chat-md {
  overflow-wrap: break-word;
}

.codex-chat-msg.codex-chat-md p {
  margin: 0 0 0.5em;
}

.codex-chat-msg.codex-chat-md p:last-child {
  margin-bottom: 0;
}

.codex-chat-msg.codex-chat-md ul,
.codex-chat-msg.codex-chat-md ol {
  margin: 0.35em 0 0.5em;
  padding-left: 1.25rem;
}

.codex-chat-msg.codex-chat-md pre {
  margin: 0.5em 0;
  padding: 0.5rem 0.65rem;
  border-radius: 8px;
  overflow-x: auto;
  font-size: 0.82rem;
  background: rgba(0, 0, 0, 0.06);
}

.codex-chat-msg.codex-chat-md code {
  padding: 0.1em 0.35em;
  border-radius: 4px;
  font-size: 0.85em;
  background: rgba(0, 0, 0, 0.07);
}

.codex-chat-msg.codex-chat-md pre code {
  padding: 0;
  background: transparent;
}

.codex-chat-msg.codex-chat-md a {
  color: var(--link-color, #5b10ac);
  word-break: break-word;
}

.codex-chat-msg.codex-chat-md blockquote {
  margin: 0.5em 0;
  padding-left: 0.75rem;
  border-left: 3px solid var(--button-color, #5b10ac);
  opacity: 0.95;
}

.codex-chat-msg.codex-chat-md table {
  width: 100%;
  font-size: 0.82rem;
  border-collapse: collapse;
  margin: 0.5em 0;
}

.codex-chat-msg.codex-chat-md th,
.codex-chat-msg.codex-chat-md td {
  border: 1px solid rgba(0, 0, 0, 0.12);
  padding: 0.25rem 0.4rem;
}

.codex-chat-msg.codex-chat-md h1,
.codex-chat-msg.codex-chat-md h2,
.codex-chat-msg.codex-chat-md h3 {
  font-size: 0.95rem;
  margin: 0.6em 0 0.35em;
  line-height: 1.25;
}

.codex-chat-msg.codex-chat-md h1:first-child,
.codex-chat-msg.codex-chat-md h2:first-child,
.codex-chat-msg.codex-chat-md h3:first-child {
  margin-top: 0;
}

.codex-chat-guest {
  flex-shrink: 0;
  padding: 1rem 0.85rem;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  text-align: center;
  background: var(--chat-input-color);
}

.codex-chat-guest-text {
  margin: 0 0 0.75rem;
  font-size: 0.9rem;
  color: var(--text-normal-color);
}

.codex-chat-login-btn {
  width: 100%;
  border: none;
  border-radius: 8px;
  padding: 0.55rem 1rem;
  background: var(--button-color);
  color: var(--text-button-color);
  font-weight: 500;
  font-size: 0.9rem;
  cursor: pointer;
}

.codex-chat-login-btn:hover {
  filter: brightness(1.05);
}

.codex-chat-input-row {
  flex-shrink: 0;
  display: flex;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
}

#codex-chat-input {
  flex: 1;
  border: none;
  padding: 0.65rem 0.75rem;
  outline: none;
  background: var(--chat-input-color);
  color: var(--text-normal-color);
  font-size: 0.9rem;
}

#codex-chat-send {
  border: none;
  background: var(--button-color);
  color: var(--text-button-color);
  padding: 0 1rem;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
}

#codex-chat-send:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
