/* ============================================================
   CHAT - Estilos específicos
   ============================================================ */

/* ---- Modal de selección ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}

.modal-overlay::before {
  content: none;
}

.modal-overlay::after {
  content: none;
}

.modal-card,
.chat-app {
  position: relative;
  z-index: 1;
}

.modal-card {
  background: var(--surface);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow-xl);
  overflow: hidden;
  border: 1px solid var(--border-light);
  animation: modalIn var(--dur-3) cubic-bezier(0.34, 1.56, 0.64, 1);
  backdrop-filter: blur(8px);
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.92) translateY(20px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  background: var(--sidebar-bg);
  padding: 26px 24px 18px;
  text-align: center;
  color: white;
  position: relative;
  overflow: hidden;
}

.modal-header::after {
  content: none;
}

.modal-logo {
  display: flex;
  justify-content: center;
  margin-bottom: 12px;
}

.modal-title {
  font-size: 1.35rem;
  font-weight: 720;
  letter-spacing: -0.5px;
  margin-bottom: 4px;
}

.modal-subtitle {
  font-size: 0.875rem;
  opacity: 0.8;
}

.modal-body {
  padding: 20px 22px 22px;
}

.modal-question {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  text-align: center;
  margin-bottom: 20px;
}

.reglamento-options {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.reglamento-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 18px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  text-align: left;
  transition: transform var(--dur-2) var(--ease), box-shadow var(--dur-2) var(--ease), background var(--dur-2) var(--ease), border-color var(--dur-2) var(--ease);
  font-family: var(--font);
  width: 100%;
}

.reglamento-card:hover {
  border-color: var(--primary);
  background: linear-gradient(
    135deg,
    rgba(var(--primary-rgb), 0.14) 0%,
    rgba(var(--primary-rgb), 0.06) 55%,
    rgba(255,255,255,0.02) 100%
  );
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}
.reglamento-card:active {
  transform: translateY(-1px) scale(0.995);
}

.reglamento-card:nth-child(2):hover {
  border-color: var(--secondary);
  background: linear-gradient(
    135deg,
    rgba(var(--secondary-rgb), 0.18) 0%,
    rgba(var(--secondary-rgb), 0.08) 55%,
    rgba(255,255,255,0.02) 100%
  );
}

.reglamento-icon {
  flex-shrink: 0;
}

.reglamento-info {
  flex: 1;
}

.reglamento-name {
  display: block;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 2px;
}

.reglamento-desc {
  display: block;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.reglamento-arrow {
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
}

.reglamento-card:hover .reglamento-arrow {
  opacity: 1;
  transform: translateX(4px);
}

.modal-footer {
  padding: 0 28px 20px;
  text-align: center;
}

.admin-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.2s;
}

.admin-link:hover {
  color: var(--primary);
}

/* ---- Chat App Layout ---- */
.chat-app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.page-header {
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 60;
  min-height: var(--page-header-h, 64px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px;
  color: white;
  background: linear-gradient(135deg, rgba(15,42,67,0.98) 0%, rgba(var(--primary-rgb), 0.92) 65%, rgba(var(--secondary-rgb), 0.22) 120%);
  border-bottom: 1px solid rgba(255,255,255,0.10);
  backdrop-filter: blur(10px);
}

.page-header::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(900px 120px at 20% 0%, rgba(var(--secondary-rgb), 0.22) 0%, rgba(var(--secondary-rgb), 0) 60%),
    radial-gradient(900px 140px at 85% 10%, rgba(255,255,255,0.10) 0%, rgba(255,255,255,0) 60%);
  opacity: 0.9;
}

.page-header-left {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

.page-header-right {
  display: flex;
  align-items: center;
  gap: 12px;
  position: relative;
  z-index: 1;
}

.page-header-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.page-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.page-header .sidebar-label {
  margin-bottom: 0;
}

.page-header .sidebar-active-reg {
  background: rgba(255,255,255,0.09);
}

.page-header .sidebar-btn {
  width: auto;
  margin-bottom: 0;
  padding: 8px 10px;
  border: 1px solid rgba(255,255,255,0.10);
}

/* (Tema fijo oscuro) Se eliminó el toggle */

.page-header .sidebar-btn:hover {
  background: rgba(255,255,255,0.09);
}

.chat-body {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.hidden {
  display: none !important;
}

/* ---- Sidebar ---- */
.chat-sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  display: none;
  flex-direction: column;
  padding: 0;
  overflow-y: auto;
}

.sidebar-header {
  padding: 18px 16px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.07);
  position: sticky;
  top: 0;
  z-index: 2;
  background: linear-gradient(180deg, rgba(15,42,67,0.98) 0%, rgba(15,42,67,0.92) 70%, rgba(15,42,67,0.0) 100%);
  backdrop-filter: blur(10px);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  color: white;
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.sidebar-header-content {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sidebar-section {
  padding: 20px 16px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.07);
}

.sidebar-section--header {
  padding: 0;
  border-bottom: none;
}

.sidebar-label {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: rgba(255,255,255,0.45);
  margin-bottom: 10px;
}

.sidebar-active-reg {
  background: rgba(255,255,255,0.08);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 0.825rem;
  color: white;
  font-weight: 500;
  line-height: 1.4;
  border: 1px solid rgba(255,255,255,0.10);
}

.sidebar-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 12px;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--sidebar-text);
  font-family: var(--font);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.15s;
  margin-bottom: 4px;
  text-decoration: none;
}

.sidebar-btn:hover {
  background: rgba(255,255,255,0.07);
  color: white;
}

.sidebar-btn--admin {
  background: rgba(var(--secondary-rgb), 0.12);
  color: rgba(255,255,255,0.92);
  border: 1px solid rgba(var(--secondary-rgb), 0.20);
}
.sidebar-btn--admin:hover {
  background: rgba(var(--secondary-rgb), 0.18);
  border-color: rgba(var(--secondary-rgb), 0.30);
}

/* `.sidebar-bottom` ya no se usa (Panel Admin está en el header) */

/* ---- Chat Main ---- */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background:
    radial-gradient(700px 420px at 30% 10%, rgba(var(--secondary-rgb), 0.12) 0%, rgba(var(--secondary-rgb), 0) 58%),
    radial-gradient(900px 520px at 85% 35%, rgba(var(--primary-rgb), 0.10) 0%, rgba(var(--primary-rgb), 0) 62%),
    var(--bg);
}

/* ---- Top Bar ---- */
.chat-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--surface-glass);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-topbar-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-change-reg {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 12px;
  border-radius: 999px;
  background:
    radial-gradient(120px 60px at 20% 30%, rgba(var(--secondary-rgb), 0.16) 0%, rgba(var(--secondary-rgb), 0) 60%),
    radial-gradient(160px 80px at 80% 70%, rgba(var(--primary-rgb), 0.16) 0%, rgba(var(--primary-rgb), 0) 62%),
    var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-primary);
  cursor: pointer;
  transition: transform var(--dur-2) var(--ease), box-shadow var(--dur-2) var(--ease), border-color var(--dur-2) var(--ease), background var(--dur-2) var(--ease);
  white-space: nowrap;
  font-weight: 650;
  letter-spacing: -0.1px;
  box-shadow: 0 1px 0 rgba(255,255,255,0.05) inset;
}

.topbar-change-reg__icon {
  opacity: 0.95;
}

.topbar-change-reg:hover:not(:disabled) {
  transform: translateY(-1px);
  border-color: rgba(var(--secondary-rgb), 0.35);
  box-shadow:
    0 16px 36px rgba(0,0,0,0.45),
    0 10px 26px rgba(var(--primary-rgb), 0.14);
}

.topbar-change-reg:active:not(:disabled) {
  transform: translateY(0px) scale(0.99);
  box-shadow:
    0 10px 24px rgba(0,0,0,0.42),
    0 6px 18px rgba(var(--primary-rgb), 0.10);
}

.topbar-change-reg:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

@media (max-width: 700px) {
  .topbar-change-reg span {
    display: none;
  }
  .topbar-change-reg {
    padding: 9px 10px;
  }
}

.topbar-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
}

.topbar-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
}

.topbar-status {
  font-size: 0.78rem;
  color: var(--secondary);
  display: flex;
  align-items: center;
  gap: 5px;
}

.status-dot {
  width: 7px;
  height: 7px;
  background: var(--secondary);
  border-radius: 50%;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.mobile-menu-btn {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-secondary);
  padding: 4px;
}

/* ---- Mensajes ---- */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.07) 0%, rgba(255,255,255,0.04) 100%);
  border-top: 1px solid rgba(255,255,255,0.06);
  border-bottom: 1px solid rgba(255,255,255,0.06);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.04);
}

/* Bienvenida */
.welcome-msg {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 40px 20px;
  max-width: 500px;
  margin: 0 auto;
}

.welcome-avatar {
  width: 64px;
  height: 64px;
  border-radius: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  margin-bottom: 16px;
}

.welcome-title {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.welcome-text {
  font-size: 0.875rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

/* Burbujas de chat */
.message-row {
  display: flex;
  gap: 10px;
  max-width: 78%;
  animation: msgIn var(--dur-2) var(--ease);
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.message-row.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.message-row.assistant {
  align-self: flex-start;
}

.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 600;
}

.msg-avatar.user-av {
  background: var(--primary);
  color: white;
}

.msg-avatar.bot-av {
  background: var(--sidebar-bg);
  color: white;
}

.msg-bubble {
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  line-height: 1.65;
  max-width: 100%;
  position: relative;
}

.message-row.user .msg-bubble {
  background: var(--primary);
  color: white;
  border-bottom-right-radius: 4px;
  box-shadow: 0 10px 24px rgba(var(--primary-rgb), 0.20);
}

.message-row.user .msg-bubble::after {
  content: "";
  position: absolute;
  right: -6px;
  bottom: 10px;
  width: 12px;
  height: 12px;
  background: var(--primary);
  transform: rotate(45deg);
  border-radius: 2px;
  opacity: 0.95;
}

.message-row.assistant .msg-bubble {
  background: var(--surface);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  box-shadow: 0 10px 24px rgba(0,0,0,0.06);
}

.message-row.assistant .msg-bubble::after {
  content: "";
  position: absolute;
  left: -6px;
  bottom: 10px;
  width: 12px;
  height: 12px;
  background: var(--surface);
  transform: rotate(45deg);
  border-left: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  border-radius: 2px;
  opacity: 0.98;
}

/* Markdown en respuestas */
.msg-bubble strong { font-weight: 600; }
.msg-bubble em { font-style: italic; }
.msg-bubble ul, .msg-bubble ol { padding-left: 18px; margin: 6px 0; }
.msg-bubble li { margin-bottom: 3px; }
.msg-bubble p { margin-bottom: 8px; }
.msg-bubble p:last-child { margin-bottom: 0; }
.msg-bubble code {
  background: rgba(0,0,0,0.10);
  padding: 1px 5px;
  border-radius: 4px;
  font-family: monospace;
  font-size: 0.85em;
}
.msg-bubble h3, .msg-bubble h4 {
  font-size: 0.9rem;
  font-weight: 600;
  margin: 8px 0 4px;
}

.message-row.user .msg-bubble code {
  background: rgba(255,255,255,0.2);
}

/* Typing bubble */
.message-row.typing .msg-bubble {
  padding: 10px 14px;
}

/* ---- Input area ---- */
.chat-input-wrapper {
  padding: 16px 24px 20px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-input-box {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 10px 10px 14px;
  transition: border-color var(--dur-2) var(--ease), box-shadow var(--dur-2) var(--ease), background var(--dur-2) var(--ease);
}

.chat-input-box:focus-within {
  border-color: rgba(var(--primary-rgb), 0.65);
  box-shadow: 0 0 0 4px rgba(var(--primary-rgb), 0.16);
  background: var(--surface);
}

.chat-textarea {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  font-family: var(--font);
  font-size: 0.95rem;
  color: var(--text-primary);
  resize: none;
  max-height: 140px;
  line-height: 1.5;
  padding: 3px 0;
}

.chat-textarea:focus,
.chat-textarea:focus-visible {
  outline: none;
  box-shadow: none;
  border: none;
}

.chat-textarea::placeholder { color: var(--text-muted); }

.send-btn {
  width: 38px;
  height: 38px;
  background:
    radial-gradient(18px 18px at 35% 30%, rgba(255,255,255,0.16) 0%, rgba(255,255,255,0) 60%),
    linear-gradient(135deg, rgba(var(--primary-rgb), 0.95) 0%, rgba(var(--secondary-rgb), 0.55) 140%);
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 10px;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 10px 24px rgba(0,0,0,0.30);
  transition: transform var(--dur-2) var(--ease), box-shadow var(--dur-2) var(--ease), filter var(--dur-2) var(--ease);
}

.send-btn:hover:not(:disabled) {
  transform: scale(1.05);
  filter: brightness(1.06);
  box-shadow: 0 14px 34px rgba(0,0,0,0.36);
}
.send-btn:active:not(:disabled) {
  transform: scale(0.99);
}

.send-btn:disabled {
  background: var(--border);
  cursor: not-allowed;
  transform: none;
}

.input-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 8px;
  text-align: center;
}

.input-hint kbd {
  background: var(--border-light);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-family: monospace;
  font-size: 0.7rem;
}

/* ---- Responsive ---- */
@media (max-width: 700px) {
  .page-header {
    padding: 12px 14px;
  }

  .page-header-actions {
    display: none;
  }

  .chat-sidebar {
    display: flex;
    position: fixed;
    left: -240px;
    top: var(--page-header-h, 64px);
    height: calc(100vh - var(--page-header-h, 64px));
    z-index: 50;
    transition: left 0.25s ease;
  }
  .chat-sidebar.open {
    left: 0;
  }
  .mobile-menu-btn {
    display: flex;
  }
  .chat-messages {
    padding: 16px;
  }
  .chat-input-wrapper {
    padding: 12px 16px 16px;
  }
  .message-row {
    max-width: 90%;
  }
}
