* { margin: 0; padding: 0; box-sizing: border-box; }

/* ===== Paleta: tema claro (default) ===== */
:root {
  --header-fondo: #075e54;
  --verde: #128c7e;
  --acento-texto: #075e54;
  --fondo: #f0f2f5;
  --superficie: #ffffff;
  --superficie-2: #f5f6f6;
  --superficie-3: #e9edef;
  --borde: #e0e0e0;
  --borde-suave: #f0f0f0;
  --texto: #111b21;
  --gris-texto: #667781;
  --fondo-chat: #ece5dd;
  --burbuja-paciente: #ffffff;
  --burbuja-bot: #dcf8c6;
  --burbuja-medico: #d4e9ff;
  --autor-bot: #075e54;
  --autor-medico: #1565c0;
  --hora-burbuja: rgba(0, 0, 0, .45);
  --input-fondo: #ffffff;
  --rojo: #d9534f;
  --sombra: rgba(0, 0, 0, .08);
}

/* ===== Paleta: tema oscuro (estilo WhatsApp dark) ===== */
[data-tema="oscuro"] {
  --header-fondo: #1f2c34;
  --verde: #00a884;
  --acento-texto: #00a884;
  --fondo: #111b21;
  --superficie: #202c33;
  --superficie-2: #2a3942;
  --superficie-3: #2f3b43;
  --borde: #2f3b43;
  --borde-suave: #222e35;
  --texto: #e9edef;
  --gris-texto: #8696a0;
  --fondo-chat: #0b141a;
  --burbuja-paciente: #202c33;
  --burbuja-bot: #005c4b;
  --burbuja-medico: #1e3a5f;
  --autor-bot: #7fd8c8;
  --autor-medico: #8ab4f8;
  --hora-burbuja: rgba(255, 255, 255, .45);
  --input-fondo: #2a3942;
  --rojo: #f27d78;
  --sombra: rgba(0, 0, 0, .4);
}

html, body { height: 100%; }

body {
  font-family: -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--fondo);
  color: var(--texto);
}

.app {
  display: grid;
  /* minmax(0, 1fr) y no 1fr a secas: permite que las columnas se achiquen
     aunque adentro haya textos largos con nowrap (si no, la grilla "explota") */
  grid-template-columns: 340px minmax(0, 1fr);
  height: 100dvh;
  max-width: 1400px;
  margin: 0 auto;
  background: var(--superficie);
  box-shadow: 0 0 12px var(--sombra);
}

.hidden { display: none !important; }

/* ===== Sidebar: lista de chats ===== */
.sidebar {
  border-right: 1px solid var(--borde);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar-header {
  background: var(--header-fondo);
  color: #fff;
  padding: 14px 16px;
}

.sidebar-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.sidebar-botones { display: flex; gap: 6px; align-items: center; }

.logo { font-size: 1.15rem; font-weight: 700; }

.consultorio-nombre { font-size: .85rem; opacity: .85; margin-top: 2px; }

.btn-turnos {
  background: rgba(255,255,255,.15);
  border: 1px solid rgba(255,255,255,.35);
  color: #fff;
  border-radius: 16px;
  padding: 5px 12px;
  font-size: .8rem;
  cursor: pointer;
}

.btn-turnos:hover { background: rgba(255,255,255,.28); }

.btn-tema,
.btn-salir {
  background: none;
  border: 1px solid rgba(255,255,255,.35);
  color: rgba(255,255,255,.85);
  border-radius: 16px;
  padding: 5px 10px;
  font-size: .75rem;
  cursor: pointer;
}

.btn-tema:hover,
.btn-salir:hover { background: rgba(255,255,255,.15); }

.chat-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
}

.chat-item {
  display: flex;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--borde-suave);
  cursor: pointer;
  align-items: center;
}

.chat-item:hover { background: var(--superficie-2); }
.chat-item.activo { background: var(--superficie-3); }

.chat-avatar {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: var(--verde);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
}

.chat-info { flex: 1; min-width: 0; }

.chat-row1 { display: flex; justify-content: space-between; align-items: baseline; }

.chat-nombre { font-weight: 600; font-size: .95rem; }

.chat-hora { font-size: .75rem; color: var(--gris-texto); flex-shrink: 0; }

.chat-preview {
  font-size: .85rem;
  color: var(--gris-texto);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.chat-badge-off {
  font-size: .7rem;
  color: var(--rojo);
  font-weight: 600;
}

/* ===== Panel de conversación ===== */
.chat {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--fondo-chat);
}

.chat-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--gris-texto);
  gap: 8px;
}

.chat-empty-icon { font-size: 3rem; }

.chat-view {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

.chat-header {
  background: var(--header-fondo);
  color: #fff;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.btn-back {
  background: none;
  border: none;
  color: #fff;
  font-size: 1.4rem;
  cursor: pointer;
  display: none;
  padding: 0 4px;
}

.chat-title { flex: 1; font-weight: 600; font-size: .95rem; }

/* Switch bot ON/OFF */
.bot-switch {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}

.bot-switch-label { font-size: .8rem; font-weight: 600; }

.bot-switch input { display: none; }

.slider {
  width: 42px; height: 22px;
  background: #b0b0b0;
  border-radius: 22px;
  position: relative;
  transition: background .2s;
}

.slider::before {
  content: '';
  position: absolute;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: #fff;
  top: 2px; left: 2px;
  transition: left .2s;
}

.bot-switch input:checked + .slider { background: #25d366; }
.bot-switch input:checked + .slider::before { left: 22px; }

/* Mensajes */
.mensajes {
  flex: 1;
  overflow-y: auto;
  padding: 16px 8%;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.burbuja {
  max-width: 75%;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: .9rem;
  line-height: 1.35;
  white-space: pre-wrap;
  word-wrap: break-word;
  box-shadow: 0 1px 1px var(--sombra);
  color: var(--texto);
}

.burbuja .autor {
  font-size: .7rem;
  font-weight: 700;
  margin-bottom: 2px;
}

.burbuja .hora {
  font-size: .68rem;
  color: var(--hora-burbuja);
  text-align: right;
  margin-top: 3px;
}

.burbuja.paciente { align-self: flex-start; background: var(--burbuja-paciente); }
.burbuja.paciente .autor { color: var(--verde); }

.burbuja.bot { align-self: flex-end; background: var(--burbuja-bot); }
.burbuja.bot .autor { color: var(--autor-bot); }

.burbuja.medico { align-self: flex-end; background: var(--burbuja-medico); }
.burbuja.medico .autor { color: var(--autor-medico); }

/* Caja de escribir */
.composer {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  background: var(--fondo);
}

.composer input {
  flex: 1;
  border: none;
  border-radius: 20px;
  padding: 10px 16px;
  font-size: .95rem;
  outline: none;
  background: var(--input-fondo);
  color: var(--texto);
}

.composer button {
  background: var(--verde);
  color: #fff;
  border: none;
  border-radius: 20px;
  padding: 10px 20px;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
}

.composer button:disabled { opacity: .5; cursor: default; }

/* ===== Vista de turnos ===== */
.turnos {
  position: fixed;
  inset: 0;
  background: var(--fondo);
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  z-index: 10;
}

.turnos-header {
  background: var(--header-fondo);
  color: #fff;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.turnos-header h2 { font-size: 1.05rem; }

.btn-back-turnos {
  background: none;
  border: none;
  color: #fff;
  font-size: 1.4rem;
  cursor: pointer;
  padding: 0 4px;
}

.form-turno {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
  padding: 14px 16px;
  background: var(--superficie);
  border-bottom: 1px solid var(--borde);
}

.form-turno input {
  border: 1px solid var(--borde);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: .9rem;
  min-width: 0;
  background: var(--input-fondo);
  color: var(--texto);
}

.form-turno button {
  background: var(--verde);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  font-weight: 600;
  cursor: pointer;
}

.lista-turnos {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px;
}

.turnos-dia {
  font-size: .85rem;
  color: var(--acento-texto);
  text-transform: capitalize;
  margin: 14px 0 6px;
}

.turnos-dia:first-child { margin-top: 0; }

.turno-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--superficie);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 6px;
  box-shadow: 0 1px 2px var(--sombra);
}

.turno-hora {
  font-weight: 700;
  color: var(--acento-texto);
  font-size: 1rem;
  flex-shrink: 0;
}

.turno-info { flex: 1; min-width: 0; }

.turno-nombre { font-weight: 600; font-size: .95rem; }

.turno-motivo { font-weight: 400; color: var(--gris-texto); }

.turno-detalle { font-size: .82rem; color: var(--gris-texto); margin-top: 2px; }

.turno-cancelar {
  background: none;
  border: 1px solid var(--borde);
  color: var(--rojo);
  border-radius: 50%;
  width: 30px; height: 30px;
  cursor: pointer;
  flex-shrink: 0;
  font-size: .9rem;
}

.turno-cancelar:hover { background: rgba(217, 83, 79, .12); border-color: var(--rojo); }

.sin-turnos {
  color: var(--gris-texto);
  text-align: center;
  margin-top: 40px;
}

/* ===== Login ===== */
.login {
  position: fixed;
  inset: 0;
  background: var(--header-fondo);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 30;
  padding: 16px;
}

.login-card {
  background: var(--superficie);
  border-radius: 14px;
  padding: 32px 28px;
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 8px 30px rgba(0,0,0,.25);
}

.login-logo {
  font-size: 1.5rem;
  font-weight: 700;
  text-align: center;
  color: var(--acento-texto);
}

.login-sub {
  text-align: center;
  color: var(--gris-texto);
  font-size: .85rem;
  margin-bottom: 8px;
}

.login-card input {
  border: 1px solid var(--borde);
  border-radius: 8px;
  padding: 11px 14px;
  font-size: .95rem;
  background: var(--input-fondo);
  color: var(--texto);
}

.login-card button {
  background: var(--verde);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 11px;
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  margin-top: 4px;
}

.login-error {
  color: var(--rojo);
  font-size: .85rem;
  text-align: center;
}

/* ===== Celular: una pantalla por vez ===== */
@media (max-width: 768px) {
  .app { grid-template-columns: minmax(0, 1fr); }

  /* por defecto se ve la lista; con .chat-open se ve la conversación */
  .chat { display: none; }
  .app.chat-open .chat { display: flex; }
  .app.chat-open .sidebar { display: none; }

  .btn-back { display: block; }
  .mensajes { padding: 12px 4%; }
  .burbuja { max-width: 85%; }
}
