* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  /* CAMBIO: Usamos 'dvh' (Dynamic Viewport Height) para corregir el recorte en celulares
     cuando aparece la barra de navegación. */
  height: 100dvh; 
  width: 100%;
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #4abaad;
  /* Evita el rebote elástico en iOS y scroll innecesario en el body */
  overscroll-behavior-y: none; 
  overflow: hidden; 
}

/* Boot overlay (evita flash de login) */
.boot-overlay {
  position: fixed;
  inset: 0;
  background: #ffffff;
  z-index: 99999;

  display: flex;
  align-items: center;
  justify-content: center;
}

.boot-overlay.hidden {
  display: none;
}

.boot-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
}

/* Spinner simple */
.boot-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid #e5e5e5;
  border-top-color: #4ABAAD; /* color MTM */
  border-radius: 50%;
  animation: boot-spin 0.8s linear infinite;
}

@keyframes boot-spin {
  to { transform: rotate(360deg); }
}

.boot-text {
  font-size: 16px;
  font-weight: 500;
  color: #555;
}

#app {
  max-width: 600px;
  margin: 0 auto;
  height: 100%;
  padding: 0.5rem;
  display: flex;
  flex-direction: column;
}

/* =========================================
   MTM Brand global (visible en desktop+mobile)
   Se oculta SOLO en chat mobile
========================================= */

#app-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  /* padding: 12px 12px 6px; */
  padding: 19px 16px 16px;
  flex-shrink: 0;
}

#app-brand-logo {
  width: 84px;
  height: 84px;
  border-radius: 18px;
  object-fit: cover;
}

#app-brand-title {
  margin: 0;
  text-align: center;
  color: #ffffff;
  font-weight: 720;
  font-size: 22px;
  line-height: 1.1;
} 
/**=======**/

/* Pantallas generales (Login, Contactos) */
.screen {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.screen .card {
  background: #fff;
  padding: 1rem;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

input,
textarea {
  width: 100%;
  padding: 0.5rem;
  margin-bottom: 0.75rem;
  border-radius: 6px;
  border: 1px solid #ccc;
  font: inherit;
}

textarea {
  resize: none;
  min-height: 40px;
}

button {
  cursor: pointer;
  border: none;
  border-radius: 6px;
  padding: 0.5rem 0.9rem;
  font: inherit;
  background: #4a6cf7;
  color: #fff;
}

button:disabled {
  opacity: 0.6;
  cursor: default;
}

.subtitle {
  color: #555;
  margin-bottom: 0.75rem;
}

/* CONTACTOS */

.contacts-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.contact-item {
  padding: 0.6rem 0.8rem;
  border-radius: 8px;
  background: #fff;
  border: 1px solid #ddd;
  color: #333;
  text-align: left;
  width: 100%;
}

.logout-btn {
  position: fixed;
  bottom: 16px;
  right: 16px;

  padding: 10px 14px;
  font-size: 14px;

  border: none;
  border-radius: 8px;

  background-color: #e74c3c;
  color: white;

  cursor: pointer;
  z-index: 1000;
}

/* --- ESTILOS DEL CHAT --- */

/*Pautas sesiones*/
.chat-guidelines {
  background: #f7f7f7;
  padding: 18px 20px;
  border-radius: 10px;
  margin-bottom: 15px;
  font-size: 14.5px;
  line-height: 1.45;
  color: #333;
  box-shadow: 0 0 4px rgba(0,0,0,0.05);
}

.chat-guidelines p {
  margin: 10px 0;
}

.chat-guidelines ul {
  padding-left: 18px;
  margin: 10px 0;
}

.chat-guidelines li {
  margin-bottom: 8px;
}
/*Pautas sesiones*/

#chat-screen {
  flex: 1;
  /* CAMBIO: Quitamos el cálculo fijo de altura. Dejamos que Flexbox maneje el espacio */
  height: 100%;
  overflow: hidden; /* Importante para contener el chat */
}

#chat-container {
  background: #fff;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  height: 100%; /* Ocupa todo el espacio disponible del padre */
  /* CAMBIO: Quitamos el margin-bottom forzado para evitar espacios raros */
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  overflow: hidden;
}

#chat-header {
  display: flex;
  align-items: center;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid #eee;
  flex-shrink: 0; /* Evita que el header se aplaste */
}

.back-button {
  background: transparent;
  color: #4a6cf7;
  margin-right: 0.5rem;
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #4a6cf7;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 0.5rem;
  font-weight: bold;
}

.chat-contact-name {
  font-weight: 600;
}

.chat-contact-role {
  font-size: 0.8rem;
  color: #777;
}

#messages-section {
  flex: 1; /* Ocupa todo el espacio restante entre header y footer */
  padding: 0.75rem;
  background: #ece4d6;
  overflow-y: auto; 
  display: flex;
  flex-direction: column;
}

/* Estilos comunes para botones tipo “pill” del chat */
.notify-button,
.load-older-btn {
  font-size: 0.85rem;         /* Unificamos tamaño de fuente */
  padding: 0.35rem 0.6rem;    /* Igual en ambos */
  border-radius: 999px;       /* Pastilla */
  font-weight: 600;
  color: #333;

  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

/* --------------------------------------- */
/* BOTÓN NOTIFICAR                         */
/* --------------------------------------- */

.notify-button {
  margin-left: auto;          /* Lo empuja a la derecha del header */
  background: #f4b400;        /* Amarillo alerta suave */
  border: none;               /* Sin borde, como lo tenías visualmente */
  cursor: pointer;
}

.notify-button:disabled {
  background: #ddd;
  color: #888;
  cursor: default;
}

/* --------------------------------------- */
/* MENÚ DE OPCIONES (3 PUNTITOS)           */
/* --------------------------------------- */

.menu-container {
  position: relative;
  margin-left: 0.5rem;
}

.menu-button {
  background: transparent;
  color: #555;
  font-size: 1.5rem; /* Un poco más grande para el ícono vertical */
  padding: 0 0.5rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  height: 32px; 
  font-weight: bold; 
  cursor: pointer;
}

.menu-button:hover {
  background: #eee;
  color: #333;
}

.menu-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  min-width: 160px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  padding: 0.5rem 0;
  margin-top: 0.5rem;
}

.menu-dropdown.hidden {
  display: none;
}

.menu-option {
  background: transparent;
  color: #333;
  padding: 0.75rem 1rem;
  text-align: left;
  width: 100%;
  border-radius: 0;
  font-size: 0.9rem;
  border-bottom: 1px solid #f0f0f0;
  cursor: pointer;
}

.menu-option:last-child {
  border-bottom: none;
}

.menu-option:hover {
  background: #f7f7f7;
  color: #4a6cf7;
}

/* --------------------------------------- */
/* BANNER FIN DE SESIÓN                    */
/* --------------------------------------- */

.session-end-banner {
  background: #f46060;
  color: #fff;
  text-align: center;
  padding: 0.5rem;
  border-radius: 8px;
  margin: 0.5rem 0;
  font-weight: bold;
}

/* --------------------------------------- */
/* BOTÓN CARGAR MENSAJES ANTERIORES        */
/* --------------------------------------- */

.load-older-btn {
  display: block;
  margin: 8px auto 12px;      /* Centrado en la lista */
  background: #f4c239;        /* Un poquito más claro que notify */
  border: 1px solid #ccc;     /* Borde suave */
  cursor: pointer;
}

.load-older-btn:hover {
  background: #f4b400;        /* Igual que el botón de notificar al hacer hover */
}

/* Burbujas de mensajes */

.message {
  width: fit-content;
  max-width: 75%; /* Un poco más ancho por defecto */
  padding: 0.5rem 0.75rem;
  border-radius: 12px;
  margin-bottom: 0.5rem;
  font-size: 0.95rem; /* Letra un pelín más grande para legibilidad */
}

.message-audio {
  width: 100%;
  max-width: 75%;
}

.message-sent {
  margin-left: auto;
  background: #8adbd1;
  text-align: left;
  border-bottom-right-radius: 2px;
}

.message-received {
  margin-right: auto;
  background: #fff;
  border-bottom-left-radius: 2px;
}

.message small {
  display: block;
  font-size: 0.7rem;
  color: #666;
  margin-top: 0.2rem;
}

.message-text {
  white-space: pre-wrap; /* para respetar saltos de línea */
  word-wrap: break-word; /*para que las palabras largas se dividan*/
}

/* Formatos de texto dentro de los mensajes */
.message-text strong {
  font-weight: bold;
}

.message-text em {
  font-style: italic;
}

.message-text del {
  text-decoration: line-through;
}

.message-text code {
  background: rgba(0, 0, 0, 0.1);
  padding: 0.1rem 0.2rem;
  border-radius: 3px;
  font-family: monospace;
  font-size: 0.9em;
}

.message-text ul {
  margin: 0.5rem 0;
  padding-left: 1rem;
}

.message-text li {
  margin-bottom: 0.25rem;
}

.message-text a {
  color: #4a6cf7;
  text-decoration: underline;
}

.message-text a:hover {
  text-decoration: none;
}

/* Input de chat */

#chat-input-area {
  border-top: 1px solid #eee;
  padding: 0.5rem;
  background: #f7f7f7;
  flex-shrink: 0; /* Evita que el footer desaparezca */
  /* padding-bottom seguro para iPhone modernos sin botón home */
  padding-bottom: max(0.5rem, env(safe-area-inset-bottom)); 
}

#chat-input-row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

#chat-input-row textarea {
  flex: 1;
  margin-bottom: 0;
}

#audio-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.85rem;
}

.audio-buttons button {
  margin-left: 0.25rem;
  background: #6c757d;
}

#recording-status,
#message-status {
  font-size: 0.8rem;
  margin-top: 0.25rem;
}

#recording-status {
  color: #d9534f;
}

#message-status {
  font-weight: 600;
}

/* --------------------------------------- */
/* AJUSTES DE AUDIO (Petición 2)           */
/* --------------------------------------- */

.message-inner {
  width: 100%;
  display: flex;
  flex-direction: column;
}

.message audio {
  width: 100%;
  /* CAMBIO: Aumentamos el ancho máximo permitido para el audio */
  max-width: 100%; 
  min-width: 200px; /* Asegura que no sea demasiado pequeño */
  height: 40px; /* Altura estándar táctil */
  margin-top: 5px;
}

/*OVERLAY PARA GRABAR AUDIO Y QUE NO SE BLOQUEE PANTALLA*/

#recording-overlay {
  background-color: rgba(0, 0, 0, 0.85);
  color: white;
  padding: 0.4rem 0.75rem;
  text-align: center;
  font-size: 0.85rem;
  display: none;
  box-sizing: border-box;

  /* Que ocupe el ancho completo del chat-container */
  width: 100%;
}

/*----------------------------------------------------------- */
/*Modal de pagos*/
/*----------------------------------------------------------- */
/* Backdrop general */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999; /* por encima del chat */
}

/* Oculto por defecto */
.hidden {
  display: none;
}

/* Caja del modal */
.modal {
  background: #ffffff;
  border-radius: 10px;
  max-width: 420px;
  width: 90%;
  padding: 16px 20px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  max-height: 90vh;      /* nunca más alto que el viewport */
  overflow-y: auto;      /* si el contenido se pasa, aparece scroll interno */
}

/* Header del modal */
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.modal-header h2 {
  font-size: 18px;
  margin: 0;
}

/* Botón cerrar */
.modal-close-btn {
  border: none;
  background: transparent;
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
}

/* Cuerpo */
.modal-body {
  font-size: 14px;
  color: #333;
}

/* Bloques */
.payment-section {
  margin-bottom: 16px;
}

.payment-section h3 {
  font-size: 15px;
  margin: 0 0 6px 0;
}

.payment-status-badge {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 8px;
}

.payment-status-pending {
  background: #fff3cd;
  color: #856404;
}

.payment-status-proof {
  background: #cce5ff;
  color: #004085;
}

.payment-status-approved {
  background: #d4edda;
  color: #155724;
}

.payment-status-rejected {
  background: #f8d7da;
  color: #721c24;
}

/* Inputs */
.payment-input-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}

.payment-input-row label {
  font-size: 13px;
}

.payment-input-row input[type="number"],
.payment-input-row input[type="file"] {
  width: 100%;
  padding: 6px 8px;
  font-size: 14px;
}

/* Botones */
.payment-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.btn {
  border: none;
  cursor: pointer;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 14px;
}

.btn-primary {
  background: #4ABAAD;
  color: white;
}

.btn-secondary {
  background: #ECE4D6;
  color: #333;
}

.btn-danger {
  background: #e55353;
  color: white;
}

/* Imagen de comprobante */
.payment-proof-preview {
  margin-top: 8px;
}

.payment-proof-preview img {
  max-width: 100%;
  border-radius: 6px;
}

/*----------------------------------------------------------- */
/*Modal de notas*/
/*----------------------------------------------------------- */
/* ===== Notes: modal list ===== */
.notes-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 55vh;
  overflow-y: auto;
  padding: 0.25rem 0;
}

.note-list-item {
  width: 100%;
  text-align: left;
  padding: 0.75rem;
  border-radius: 10px;
  border: 1px solid #ddd;
  background: #8ADBD1;
  cursor: pointer;
  font-weight: 500;
}

.note-list-item:hover {
  background: #4ABAAD;
}

.notes-new-btn {
  width: 100%;
  margin-top: 0.75rem;
  padding: 0.75rem;
  border-radius: 10px;
  border: none;
  cursor: pointer;
  background: #4ABAAD;
  color: #fff;
  font-weight: 600;
}

/* ===== Notes: panel (half/full) ===== */
.note-panel {
  border-bottom: 1px solid #ddd;
  background: #fff;
}

.note-panel-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0;
  border-bottom: 1px solid #eee;
}

.note-title-input {
  height: 40px;
  flex: 1;
  padding: 0 0.6rem;
  border-radius: 10px;
  border: 1px solid #ddd;
  font-size: 16px;
  margin: 0.6rem 0.75rem 0.6rem 0.75rem;
}

.note-panel-actions {
  display: flex;
  gap: 0.35rem;
  padding: 0.6rem 0.75rem 0.6rem 0;
}

.note-action-btn {
  width: 40px;
  height: 40px;           /* misma altura que el input */
  border-radius: 10px;
  border: 1px solid #ddd;
  background: #fff;
  cursor: pointer;

  display: inline-flex;   /* centra el SVG */
  align-items: center;
  justify-content: center;
  padding: 0;             /* importante: sin padding */
}

.note-icon {
  width: 22px;
  height: 30px;
  fill: #333;
  padding-left: 2.5px; /* ajuste visual */
}

.note-panel-body {
  padding: 0.6rem 0.75rem;
}

.note-content-textarea {
  width: 100%;
  min-height: 160px;
  max-height: 40vh;
  resize: vertical;
  padding: 0.75rem;
  border-radius: 12px;
  border: 1px solid #ddd;
  font-size: 16px;
  line-height: 1.35;
}

.note-save-status {
  display: none;
  /* padding: 0.35rem 0.75rem 0.7rem;
  color: #666;
  font-size: 13px; */
}

.note-panel.saving {
  box-shadow: 0 0 0 2px rgba(74,186,173,0.35);
}

.note-panel.saved {
  box-shadow: none;
}

/* Fullscreen mode */
.note-panel.fullscreen {
  position: fixed;
  top: 16px;
  left: 16px;
  right: 16px;
  bottom: 16px;
  z-index: 9999;

  display: flex;
  flex-direction: column;

  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0,0,0,0.25);
}

.note-panel.fullscreen .note-content-textarea {
  max-height: none;
  min-height: calc(100vh - 140px);
}

/* ----------------------------------------------------------- */
/* MODIFICACIONES ESPECÍFICAS PARA CELULAR */
/* ----------------------------------------------------------- */

@media (max-width: 768px) {
  /* CAMBIO: Hacemos que la App ocupe absolutamente todo el viewport móvil */
  #app {
    padding: 0;
    max-width: 100%;
    height: 100dvh; /* Asegura altura dinámica correcta */
  }

  /* Ajustes específicos si estamos en la pantalla de chat */
  #chat-screen {
    height: 100%;
  }

  body.screen-chat #app-brand {
    display: none;
  }

  /* El contenedor del chat pierde los bordes redondeados y márgenes */
  #chat-container {
    border-radius: 0;
    margin-bottom: 0;
    height: 100%;
    box-shadow: none;
  }

  /* CAMBIO: Hacemos las burbujas de mensaje más anchas en celular para que entre mejor el audio */
  .message {
    width: fit-content;
    max-width: 90%; 
  }

  .message-audio {
    width: 100%;
    max-width: 90%;
  }
  
  /* Hacemos el área de input un poco más amigable al tacto */
  button {
    padding: 0.6rem 1rem;
  }

  #login-screen,
  #contacts-screen {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    max-height: 100dvh; /* mejor que 100vh en móviles modernos */
  }

  .logout-btn {
    padding: 12px 16px;
    font-size: 15px;
  }

  /*Note panel fullscreen ajuste móvil*/
  .note-panel.fullscreen {
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border-radius: 0;
  }
}
/* ----------------------------------------------------------- */