/* ==========================================================================
   Variables y Configuración Global (Verde Pistacho Theme)
   ========================================================================== */
:root {
  /* Paleta Verde Pistacho */
  --pistachio-primary: #8fb935;
  --pistachio-hover: #7fa82b;
  --pistachio-active: #6e9422;
  --pistachio-light: #f2f8e8;
  --pistachio-border: #d1e5a5;
  --pistachio-dark: #3f5218;

  /* Colores Neutros */
  --bg-body: #f5f7f3;
  --bg-card: #ffffff;
  --text-main: #2c3523;
  --text-muted: #707a68;
  --border-light: #e4e9de;
  --shadow-soft: 0 8px 24px rgba(44, 53, 35, 0.08);
  --shadow-focus: 0 0 0 3px rgba(143, 185, 53, 0.25);

  /* Fuents y Transiciones */
  --font-family:
    system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen,
    Ubuntu, Cantarell, sans-serif;
  --transition-fast: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Soporte para Modo Oscuro Suave */
@media (prefers-color-scheme: dark) {
  :root {
    --bg-body: #161a14;
    --bg-card: #20261d;
    --text-main: #e8efe2;
    --text-muted: #9aa592;
    --border-light: #2e382a;
    --pistachio-light: #283321;
    --shadow-soft: 0 8px 24px rgba(0, 0, 0, 0.4);
  }
}

/* Reset Global */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-body);
  color: var(--text-main);
  display: grid;
  place-content: center;
  min-height: 100vh;
  padding: 1.5rem;
}

/* ==========================================================================
   Contenedor Principal del Chat (#chat)
   ========================================================================== */
#chat {
  width: 380px;
  height: 550px;
  max-width: 100%;
  background-color: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 16px;
  box-shadow: var(--shadow-soft);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  transition: var(--transition-fast);
}

/* Encabezado Opcional del Chat */
#chat-header {
  padding: 1rem 1.25rem;
  background-color: var(--pistachio-light);
  border-bottom: 1px solid var(--pistachio-border);
  display: flex;
  align-items: center;
  gap: 10px;
}

#chat-header h2 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--pistachio-dark);
}

#chat-header .status-dot {
  width: 8px;
  height: 8px;
  background-color: var(--pistachio-primary);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--pistachio-primary);
}

/* ==========================================================================
   Lista de Mensajes (#messages)
   ========================================================================== */
#messages {
  list-style: none;
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  scroll-behavior: smooth;
}

/* Personalización de la barra de desplazamiento (Scrollbar) */
#messages::-webkit-scrollbar {
  width: 6px;
}

#messages::-webkit-scrollbar-track {
  background: transparent;
}

#messages::-webkit-scrollbar-thumb {
  background-color: rgba(0, 0, 0, 0.1);
  border-radius: 10px;
}

#messages::-webkit-scrollbar-thumb:hover {
  background-color: var(--pistachio-primary);
}

/* Burbujas de Mensaje */
#messages > li {
  padding: 0.65rem 1rem;
  border-radius: 14px;
  font-size: 0.925rem;
  line-height: 1.4;
  max-width: 85%;
  word-wrap: break-word;
  background-color: var(--pistachio-light);
  color: var(--text-main);
  border: 1px solid var(--pistachio-border);
  align-self: flex-start;
  transition: var(--transition-fast);
}

/* Efecto Hover en los mensajes */
#messages > li:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

/* Diferenciación visual para mensajes enviados (si añades la clase .me) */
#messages > li.me {
  align-self: flex-end;
  background-color: var(--pistachio-primary);
  color: #ffffff;
  border: none;
}

#messages > li.me:hover {
  background-color: var(--pistachio-hover);
}

/* ==========================================================================
   Formulario de Entrada (#form)
   ========================================================================== */
#form {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0.75rem 1rem;
  background-color: var(--bg-card);
  border-top: 1px solid var(--border-light);
}

/* Campo de Texto (#input) */
#input {
  flex: 1;
  border-radius: 24px;
  border: 1.5px solid var(--border-light);
  background-color: var(--bg-body);
  color: var(--text-main);
  padding: 0.65rem 1.1rem;
  font-size: 0.9rem;
  outline: none;
  transition: var(--transition-fast);
}

#input::placeholder {
  color: var(--text-muted);
}

#input:hover {
  border-color: var(--pistachio-primary);
}

#input:focus {
  border-color: var(--pistachio-primary);
  background-color: var(--bg-card);
  box-shadow: var(--shadow-focus);
}

/* Botón de Envío */
#form > button {
  background-color: var(--pistachio-primary);
  color: #ffffff;
  border: none;
  border-radius: 20px;
  padding: 0.65rem 1.25rem;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition-fast);
  display: flex;
  align-items: center;
  justify-content: center;
}

#form > button:hover {
  background-color: var(--pistachio-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(143, 185, 53, 0.3);
}

#form > button:active {
  background-color: var(--pistachio-active);
  transform: translateY(0);
}
