@charset "UTF-8";

/* ================= VARIABLES & RESET ================= */
:root {
  --primary: #2A9D8F;
  --primary-dark: #21867a;
  --secondary: #264653;
  --accent: #E9C46A;
  --bg-body: #F4F6F8;
  --bg-panel: #FFFFFF;

  --msg-company-bg: #E1FFC7;
  --msg-company-text: #111b21;
  --msg-client-bg: #FFFFFF;
  --msg-client-text: #111b21;
  --chat-bg: #EFE7DD;

  --text-main: #333333;
  --text-muted: #666666;
  --text-light: #FFFFFF;

  --border-radius: 12px;
  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
  --transition: all 0.3s ease;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  font-family: 'Inter', sans-serif;
  background-color: var(--bg-body);
  color: var(--text-main);
  height: 100vh;
  overflow: hidden;
}

::-webkit-scrollbar {
  width: 8px;
}

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

::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: #bbb;
}

/* ================= LOGIN (CORREGIDO) ================= */
/* El ID #login-container ahora es el wrapper de fondo para que el JS lo borre entero */
#login-container {
  height: 100vh;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  background: linear-gradient(135deg, var(--secondary), var(--primary));
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1000;
}

/* Nueva clase para la caja blanca interior */
.login-box {
  width: 100%;
  max-width: 400px;
  background: var(--bg-panel);
  padding: 2.5rem;
  border-radius: var(--border-radius);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
  text-align: center;
}

.login-header h2 {
  margin-bottom: 0.5rem;
  color: var(--secondary);
}

.login-header p {
  margin-top: 0;
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 2rem;
}

.input-group {
  position: relative;
  margin-bottom: 1rem;
}

.input-group i {
  position: absolute;
  left: 15px;
  top: 50%;
  transform: translateY(-50%);
  color: #aaa;
}

.input-group input {
  width: 100%;
  padding: 12px 12px 12px 40px;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 1rem;
  outline: none;
  transition: var(--transition);
}

.input-group input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(42, 157, 143, 0.1);
}

button {
  cursor: pointer;
  font-family: inherit;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  transition: var(--transition);
}

.btn-primary {
  background-color: var(--primary);
  color: white;
  padding: 12px;
  width: 100%;
  font-size: 1rem;
}

.btn-primary:hover {
  background-color: var(--primary-dark);
}

.btn-danger {
  background-color: #E76F51;
  color: white;
  padding: 8px 15px;
  font-size: 0.9rem;
}

.btn-danger:hover {
  background-color: #d65a3b;
}

.error {
  color: #e63946;
  margin-top: 10px;
  font-size: 0.9rem;
}

/* ================= MAIN LAYOUT ================= */
#main-container {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

#header {
  background-color: var(--bg-panel);
  height: 70px;
  padding: 0 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #eee;
  box-shadow: var(--shadow-sm);
  z-index: 10;
}

#logo {
  height: 45px;
  object-fit: contain;
}

#content {
  display: flex;
  overflow: hidden;
  /* CAMBIO CLAVE: Forzamos la altura exacta restando el header (70px) */
  height: calc(100vh - 70px);
  position: relative;
  width: 100%;
}

/* ================= CHAT LIST ================= */
#chat-list {
  width: 320px;
  background-color: var(--bg-panel);
  border-right: 1px solid #ddd;
  display: flex;
  flex-direction: column;
  /* CAMBIOS CLAVE PARA EL SCROLL: */
  height: 100%;
  /* Ocupa todo el alto del #content */
  overflow: hidden;
  /* Evita que se estire más de la cuenta */
  min-height: 0;
  /* Truco vital para Firefox/Chrome en flexbox anidados */
}

.chat-list-header {
  padding: 15px;
  background-color: #f8f9fa;
  border-bottom: 1px solid #eee;
}

.chat-list-header h3 {
  margin: 0;
  color: var(--secondary);
  font-size: 1.1rem;
}

#users-list {
  list-style: none;
  padding: 0;
  margin: 0;
  /* ESTOS 3 SON VITALES: */
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

#users-list li {
  padding: 15px;
  border-bottom: 1px solid #f1f1f1;
  cursor: pointer;
  display: flex;
  align-items: center;
  transition: background 0.2s;
  position: relative;
  font-weight: 500;
}

#users-list li:hover {
  background-color: #f8f9fa;
}

#users-list li.active-chat {
  background-color: #e8f5f3;
  border-left: 4px solid var(--primary);
}

#users-list li.unread {
  font-weight: 700;
  color: #000;
}

.unread-indicator {
  background-color: var(--primary);
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-left: auto;
  box-shadow: 0 0 5px var(--primary);
}

/* ================= CHAT WINDOW ================= */
#chat-window {
  flex: 1;
  display: flex;
  flex-direction: column;
  background-color: var(--chat-bg);
  background-image: radial-gradient(#ddd 1px, transparent 1px);
  background-size: 20px 20px;
  position: relative;
  /* CAMBIOS CLAVE: */
  height: 100%;
  /* Ocupa todo el alto del #content */
  overflow: hidden;
  /* Obligatorio para que aparezca el scroll interno */
  min-height: 0;
}

#chat-header {
  background-color: #f0f2f5;
  padding: 15px 20px;
  border-bottom: 1px solid #ddd;
  display: flex;
  align-items: center;
}

#chat-header h3 {
  margin: 0;
  color: var(--text-main);
  font-size: 1.1rem;
}

#messages {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  /* CRUCIAL */

  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#messages p {
  max-width: 65%;
  padding: 10px 15px;
  border-radius: 8px;
  font-size: 0.95rem;
  line-height: 1.4;
  position: relative;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
  word-wrap: break-word;
  margin: 0;
}

.timestamp {
  display: block;
  font-size: 0.7rem;
  margin-top: 4px;
  text-align: right;
  opacity: 0.7;
}

.company-message {
  background-color: var(--msg-company-bg);
  color: var(--msg-company-text);
  align-self: flex-end;
  border-top-right-radius: 0 !important;
}

.client-message {
  background-color: var(--msg-client-bg);
  color: var(--msg-client-text);
  align-self: flex-start;
  border-top-left-radius: 0 !important;
}

.empty-state {
  text-align: center;
  color: #999;
  margin-top: 20%;
}

.empty-state i {
  font-size: 3rem;
  margin-bottom: 1rem;
}

/* ================= ADMIN PANEL ================= */
#admin-panel {
  width: 300px;
  background-color: var(--bg-panel);
  border-left: 1px solid #ddd;
  overflow-y: auto;
  padding: 20px;
  box-shadow: -2px 0 5px rgba(0, 0, 0, 0.02);
}

#admin-panel h3 {
  margin-top: 0;
  color: var(--secondary);
  border-bottom: 2px solid var(--primary);
  padding-bottom: 10px;
  margin-bottom: 20px;
  font-size: 1.2rem;
}

.admin-grid {
  display: grid;
  gap: 10px;
}

#admin-panel button {
  width: 100%;
  padding: 10px;
  background-color: #fff;
  border: 1px solid var(--primary);
  color: var(--primary);
  border-radius: 6px;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 10px;
}

#admin-panel button:hover {
  background-color: var(--primary);
  color: white;
}

#admin-panel button.btn-warning {
  border-color: #E76F51;
  color: #E76F51;
}

#admin-panel button.btn-warning:hover {
  background-color: #E76F51;
  color: white;
}

/* ================= MODALS ================= */
.modal {
  position: fixed;
  z-index: 2000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  display: flex;
  justify-content: center;
  align-items: center;
}

.modal-content {
  background-color: #fff;
  padding: 25px;
  border-radius: var(--border-radius);
  width: 90%;
  max-width: 500px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  max-height: 90vh;
  overflow-y: auto;
  animation: modalPop 0.3s ease-out;
}

.wide-modal .modal-content {
  max-width: 800px;
}

@keyframes modalPop {
  from {
    transform: scale(0.9);
    opacity: 0;
  }

  to {
    transform: scale(1);
    opacity: 1;
  }
}

.modal h2,
.modal h3 {
  margin-top: 0;
  color: var(--secondary);
  margin-bottom: 20px;
}

.form-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal input,
.modal textarea,
.modal select {
  width: 100%;
  padding: 10px;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-family: inherit;
}

.modal textarea {
  resize: vertical;
}

.modal-actions {
  margin-top: 20px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  border-top: 1px solid #eee;
  padding-top: 15px;
}

.close-btn {
  background-color: #e0e0e0;
  color: #333;
  padding: 10px 20px;
}

.close-btn:hover {
  background-color: #d0d0d0;
}

.file-input {
  margin-top: 10px;
  padding: 10px;
  background: #f9f9f9;
  border-radius: 6px;
  width: 100%;
}

.scrollable-list,
.button-list {
  max-height: 300px;
  overflow-y: auto;
  border: 1px solid #eee;
  border-radius: 6px;
  padding: 10px;
}

.empresa-item,
.usuario-item {
  background: #f9f9f9;
  padding: 10px;
  margin-bottom: 8px;
  border-radius: 6px;
  border-left: 3px solid var(--primary);
}

.category-button {
  width: 100%;
  padding: 10px;
  margin-bottom: 5px;
  background: white;
  border: 1px solid #ddd;
  text-align: left;
  border-radius: 4px;
}

.category-button:hover {
  border-color: var(--primary);
  color: var(--primary);
}

/* ================= GOD MODE ================= */
#dios-panel {
  background-color: #121212;
  color: #00FF9D;
  height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: 'Courier New', monospace;
}

.dios-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px;
  border-bottom: 1px solid #333;
}

.dios-title {
  margin: 0;
  font-size: 2rem;
  text-transform: uppercase;
  letter-spacing: 4px;
  text-shadow: 0 0 10px #00FF9D;
}

.logout-dios-btn {
  background: transparent;
  border: 1px solid #ff4444;
  color: #ff4444;
}

.logout-dios-btn:hover {
  background: #ff4444;
  color: white;
}

.dios-container {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 40px;
}

.dios-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
  max-width: 1000px;
  width: 100%;
}

.dios-grid button {
  background: #1e1e1e;
  border: 1px solid #00FF9D;
  color: #00FF9D;
  padding: 20px;
  font-size: 1.1rem;
  text-transform: uppercase;
  border-radius: 4px;
  transition: all 0.2s;
}

.dios-grid button:hover {
  background: #00FF9D;
  color: #000;
  box-shadow: 0 0 15px #00FF9D;
  transform: translateY(-2px);
}

.dios-grid button:disabled {
  border-color: #555;
  color: #555;
  cursor: not-allowed;
  box-shadow: none;
}

/* ================= RESPONSIVE ================= */
@media (max-width: 768px) {
  #content {
    flex-direction: column;
  }

  #chat-list {
    width: 320px;
    background-color: var(--bg-panel);
    border-right: 1px solid #ddd;
    display: flex;
    flex-direction: column;
    /* CAMBIOS CLAVE PARA EL SCROLL: */
    height: 100%;
    /* Ocupa todo el alto del #content */
    overflow: hidden;
    /* Evita que se estire más de la cuenta */
    min-height: 0;
    /* Truco vital para Firefox/Chrome en flexbox anidados */
  }

  #chat-window {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: var(--chat-bg);
    background-image: radial-gradient(#ddd 1px, transparent 1px);
    background-size: 20px 20px;
    position: relative;
    /* CAMBIOS CLAVE: */
    height: 100%;
    /* Ocupa todo el alto del #content */
    overflow: hidden;
    /* Obligatorio para que aparezca el scroll interno */
    min-height: 0;
  }

  #admin-panel {
    position: absolute;
    right: 0;
    top: 70px;
    bottom: 0;
    width: 80%;
    transform: translateX(100%);
    z-index: 100;
  }

  #admin-panel[style="display: block;"] {
    width: 100%;
    transform: translateX(0);
  }
}


/* ================= TABS MODAL DIOS ================= */
.nav-tabs {
  display: flex;
  list-style: none;
  padding: 0;
  margin: 0 0 20px 0;
  border-bottom: 2px solid #ddd;
}

.nav-tabs li {
  margin-right: 5px;
}

.nav-tabs li a {
  text-decoration: none;
  padding: 10px 20px;
  display: block;
  background: #f1f1f1;
  color: #333;
  border-radius: 5px 5px 0 0;
  font-weight: 600;
  transition: all 0.3s;
}

.nav-tabs li.active a {
  background: var(--primary);
  color: white;
}

.nav-tabs li a:hover {
  background: #ddd;
}

/* Tablas dentro del modal */
.table {
  width: 100%;
  border-collapse: collapse;
}

.table th,
.table td {
  padding: 10px;
  text-align: left;
  border-bottom: 1px solid #eee;
}

.table th {
  background-color: #f9f9f9;
  color: var(--secondary);
}

.btn-icon {
  background: none;
  border: 1px solid #ccc;
  border-radius: 50%;
  width: 30px;
  height: 30px;
  cursor: pointer;
  font-size: 1.2rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-icon:hover {
  background: #eee;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 0.8rem;
  margin-right: 5px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
}

.header-buttons {
  display: flex;
  gap: 10px;
}