/* frontend/css/chat.css */

/* ========================================= */
/* === CHAT UI: Modern & Clean (VFinal) === */
/* ========================================= */

/* --- 1. CONTENEDOR PRINCIPAL (Estilo Modal App Móvil) --- */
#chat-modal.chat-fullscreen-modern {
    /* Posición fija centrada */
    position: fixed !important;
    top: 0 !important;
    bottom: 0 !important;
    left: 50% !important; /* Centrar en PC */
    transform: translateX(-50%) !important; /* Centrar en PC */
    
    width: 100% !important;
    max-width: var(--modal-max-width) !important; /* Ancho máximo de celular (500px) */
    height: 100% !important;
    max-height: 100% !important;
    
    margin: 0 !important;
    border-radius: 0 !important;
    padding: 0 !important;
    background-color: #fff;
    display: flex;
    flex-direction: column;
    z-index: 2000; /* Encima de todo */
    overflow: hidden;
    box-shadow: 0 0 50px rgba(0,0,0,0.2); /* Sombra elegante en PC */
}

/* --- 2. HEADER (Barra Superior) --- */
.chat-header-modern {
    display: grid;
    grid-template-columns: 50px 1fr 50px; /* Botón, Info, Botón */
    align-items: center;
    height: 64px;
    padding: 0 10px;
    padding-top: env(safe-area-inset-top);
    background: rgba(255, 255, 255, 0.98);
    border-bottom: 1px solid #f0f0f0;
    z-index: 100;
    flex-shrink: 0;
}

/* Botones Fantasma (Atrás, Cerrar) */
.icon-btn-ghost {
    background: transparent;
    border: none;
    font-size: 1.2rem;
    width: 40px;
    height: 40px;
    cursor: pointer;
    color: #333;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s;
}
.icon-btn-ghost:hover { background-color: #f5f5f5; }
.icon-btn-ghost:active { background-color: #eee; }

/* Alineación de columnas */
.header-left { display: flex; justify-content: flex-start; }
.header-right { display: flex; justify-content: flex-end; }

/* Info Central */
.header-center {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    overflow: hidden;
}

/* Avatar del Header */
.chat-avatar-container {
    position: relative;
    width: 36px;
    height: 36px;
    flex-shrink: 0;
}
.chat-avatar-container img {
    width: 100%; height: 100%;
    border-radius: 50%;
    object-fit: cover;
    border: 1px solid #f0f0f0;
}

/* Bolita de Estado (Online/Offline) */
.status-dot-avatar {
    position: absolute;
    bottom: 0; right: 0;
    width: 10px; height: 10px;
    border-radius: 50%;
    border: 2px solid #fff;
    background-color: #C7C7CC; /* Gris (Offline) */
    z-index: 2;
}
.status-dot-avatar.online { background-color: #34C759; } /* Verde (Online) */

/* Textos Header */
.chat-text-details {
    display: flex;
    flex-direction: column;
    justify-content: center;
    text-align: left;
    overflow: hidden;
}
#chat-header-username {
    font-weight: 700;
    font-size: 0.95rem;
    color: #000;
    margin: 0;
    line-height: 1.1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chat-subtext {
    font-size: 0.7rem;
    color: #8E8E93;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}


/* --- 3. BARRA DE CONTEXTO (Trabajo y Precio) --- */
.chat-context-modern {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 15px;
    background-color: #FAFAFA; /* Gris muy claro */
    border-bottom: 1px solid #eee;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.2s;
}
.chat-context-modern:active { background-color: #f0f0f0; }

.context-icon {
    width: 34px; height: 34px;
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    color: #333; font-size: 0.9rem;
}
.context-icon img { width: 100%; height: 100%; object-fit: contain; }

.context-info {
    flex-grow: 1;
    overflow: hidden;
    display: flex; flex-direction: column;
}
#chat-job-title {
    margin: 0; font-size: 0.9rem; font-weight: 600; color: #333;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
/* Precio bien visible */
#chat-job-price {
    font-size: 0.95rem; 
    font-weight: 800; /* Extra bold */
    color: #000;      /* Negro puro */
    margin-top: 2px;
}
.context-arrow { color: #ccc; font-size: 0.8rem; }


/* --- 4. ÁREA DE MENSAJES --- */
.chat-content-modern {
    flex-grow: 1;
    padding: 15px;
    padding-bottom: 20px;
    overflow-y: auto;
    background: #fff;
    display: flex;
    flex-direction: column;
    gap: 2px; /* Espacio entre mensajes del mismo bloque */
}

/* FILA BASE */
.chat-row {
    display: flex;
    width: 100%;
    margin-bottom: 1px;
    position: relative;
}
/* Separación entre bloques de mensajes */
.chat-row.new-group { margin-top: 12px; }


/* --- MENSAJES RECIBIDOS (Izquierda) --- */
.chat-row.received {
    justify-content: flex-start;
    align-items: flex-end; /* Alinear foto y burbuja abajo */
}

.chat-bubble-avatar {
    width: 28px; height: 28px;
    border-radius: 50%;
    object-fit: cover;
    margin-right: 8px;
    margin-bottom: 0; /* Alinear con la base */
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
    background-color: #eee;
    flex-shrink: 0;
}

/* Espaciador invisible para alinear mensajes sin foto */
.chat-avatar-spacer {
    width: 28px;
    margin-right: 8px;
    flex-shrink: 0;
}

.chat-message.received {
    background-color: #F2F2F7; /* Gris Apple */
    color: #000;
    padding: 8px 14px;
    border-radius: 18px; /* Muy redondo */
    border-bottom-left-radius: 4px; /* Rabito pequeño */
    max-width: 70%;
    font-size: 1rem;
    line-height: 1.35;
    word-wrap: break-word;
}
/* Si está agrupado (no es el último), esquina redonda */
.chat-row.received.grouped .chat-message.received {
    border-bottom-left-radius: 18px;
}


/* --- MENSAJES ENVIADOS (Derecha) --- */
.chat-row.sent {
    justify-content: flex-end;
    align-items: flex-end;
    flex-direction: column; /* Apilar burbuja sobre el estado */
}

.chat-message.sent {
    background-color: #007AFF; /* Azul Apple */
    color: #fff;
    padding: 8px 14px;
    border-radius: 18px;
    border-bottom-right-radius: 4px; /* Rabito pequeño */
    max-width: 75%;
    font-size: 1rem;
    line-height: 1.35;
    word-wrap: break-word;
}
/* Si está agrupado (no es el último), esquina redonda */
.chat-row.sent.grouped .chat-message.sent {
    border-bottom-right-radius: 18px;
}


/* --- 5. ESTADO DEL MENSAJE (Visto/Enviado) --- */
.message-status-area {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    width: 100%;
    margin-top: 3px;
    margin-bottom: 8px; /* Espacio extra después del último mensaje */
    padding-right: 2px;
    min-height: 16px;
}

/* Contenedor Foto + Texto Visto */
.seen-container {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

/* Foto Pequeña del Visto */
.seen-avatar-small {
    width: 14px; height: 14px;
    border-radius: 50%;
    object-fit: cover;
    border: 1px solid #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

/* Texto "Visto hace..." */
.seen-text {
    font-size: 10px;
    color: #8E8E93;
    font-weight: 500;
    margin-top: 2px;
}

/* Checks (Iconos) */
.status-check { font-size: 12px; }
.status-check.sent { color: #C7C7CC; } /* Hueco Gris */
.status-check.delivered { color: #007AFF; } /* Lleno Azul */


/* --- 6. INDICADOR ESCRIBIENDO --- */
#typing-indicator {
    padding: 0 15px;
    margin-bottom: 10px;
}
.typing-bubble {
    background-color: #E9E9EB;
    padding: 10px 14px;
    border-radius: 18px;
    border-bottom-left-radius: 4px;
    margin-left: 36px; /* 28px avatar + 8px gap */
    width: fit-content;
    display: flex;
    align-items: center;
    gap: 4px;
    height: 34px;
}
.typing-bubble span {
    width: 6px; height: 6px;
    background-color: #8E8E93;
    border-radius: 50%;
    display: inline-block;
    animation: typing 1.4s infinite ease-in-out both;
}
.typing-bubble span:nth-child(1) { animation-delay: -0.32s; }
.typing-bubble span:nth-child(2) { animation-delay: -0.16s; }
@keyframes typing { 
    0%, 80%, 100% { transform: scale(0); } 
    40% { transform: scale(1); } 
}


/* --- 7. FOOTER Y MENÚ DE ADJUNTOS (Fixed) --- */
.chat-footer-modern {
    display: flex; 
    flex-direction: column; 
    position: relative;
    z-index: 200;
    padding: 10px 15px;
    /* Subimos un poco más el input para celulares con barra abajo (iPhone X+) */
    padding-bottom: max(20px, env(safe-area-inset-bottom));
    background-color: #ffffff;
    border-top: 1px solid #f0f0f0;
    flex-shrink: 0;
}

.chat-input-row {
    display: flex; 
    width: 100%; 
    /* AQUÍ ESTÁ EL ARREGLO: 'center' alinea el botón + perfectamente al medio */
    align-items: center; 
    gap: 12px; /* Un poco más de espacio entre el + y el input */
}

/* Botón Adjuntar (+) */
.btn-attach {
    width: 36px; /* Un poquito más grande para que sea fácil de tocar */
    height: 36px; 
    border-radius: 50%; 
    background: #f2f2f7; /* Gris muy suave estilo Apple */
    border: none; 
    color: #007AFF; /* Azul iMessage */
    font-size: 1.3rem; 
    cursor: pointer; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    transition: transform 0.2s, background-color 0.2s;
    flex-shrink: 0; /* Evita que se aplaste */
    margin: 0; /* Sin márgenes extraños */
    padding-left: 0.5px; /* Ajuste óptico para centrar el icono + */
}
.btn-attach:active {
    background-color: #e5e5ea;
}
.btn-attach.active { 
    transform: rotate(45deg); 
    background: #007AFF; 
    color: #fff; 
}

/* Wrapper del Input (La pastilla blanca) */
.chat-input-wrapper {
    display: flex;
    align-items: center; /* Centrar texto y botón enviar verticalmente */
    background-color: #fff;
    border: 1px solid #c6c6c8; /* Borde gris clásico de input */
    border-radius: 24px; /* Más redondo (Pill shape) */
    padding: 4px 6px 4px 16px; /* Padding interno balanceado */
    transition: border-color 0.2s, box-shadow 0.2s;
    flex-grow: 1; /* Ocupa todo el espacio restante */
    min-height: 44px; /* Altura mínima cómoda */
}

.chat-input-wrapper:focus-within {
    border-color: #007AFF; /* Azul al escribir */
    box-shadow: 0 0 0 1px #007AFF; /* Glow sutil azul */
}

/* El campo de texto en sí */
#chat-message-input {
    flex-grow: 1;
    border: none;
    background: transparent;
    font-size: 1rem;
    padding: 8px 0;
    outline: none;
    max-height: 100px;
    color: #000;
    resize: none; 
    line-height: 1.4;
}
#chat-message-input::placeholder { color: #8E8E93; }

/* Botón Enviar / Micrófono */
.send-btn-modern {
    width: 34px; 
    height: 34px;
    border-radius: 50%;
    border: none;
    display: flex; 
    align-items: center; 
    justify-content: center;
    font-size: 1rem;
    cursor: pointer;
    transition: transform 0.1s, background-color 0.2s;
    margin-left: 8px;
    flex-shrink: 0;
    
    /* Estado inicial: Micrófono (Gris) */
    background-color: transparent; 
    color: #8E8E93;
}
/* Cuando está azul (Enviar) */
.send-btn-modern[style*="background-color: rgb(0, 122, 255)"] {
     /* Estilos específicos cuando JS lo pone azul */
     box-shadow: 0 2px 4px rgba(0,122,255,0.3);
}

.send-btn-modern:active { transform: scale(0.92); }

/* Menú de Adjuntos (Flotante) */
/* --- MENÚ DE ADJUNTOS PREMIUM --- */
.attachments-menu {
    position: absolute; 
    bottom: 85px; /* Un poco más arriba del input */
    left: 15px; 
    width: calc(100% - 30px); /* Que ocupe casi todo el ancho */
    max-width: 350px; /* Pero no gigante en PC */
    
    background: rgba(255, 255, 255, 0.95); /* Blanco semi-transparente */
    backdrop-filter: blur(20px); /* Efecto vidrio (iOS style) */
    -webkit-backdrop-filter: blur(20px);
    
    border-radius: 24px; 
    box-shadow: 0 10px 40px rgba(0,0,0,0.15);
    border: 1px solid rgba(0,0,0,0.05);
    
    display: none; /* Oculto por defecto */
    /* Grid de 3 columnas para Cámara, Galería, Ubicación */
    grid-template-columns: repeat(3, 1fr); 
    padding: 20px; 
    gap: 15px;
    
    animation: menuPop 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 50;
}

.attachments-menu.visible { display: grid; }

/* Animación de entrada con rebote */
@keyframes menuPop { 
    from { opacity: 0; transform: scale(0.8) translateY(20px); } 
    to { opacity: 1; transform: scale(1) translateY(0); } 
}

/* Opciones individuales */
.attach-option {
    display: flex; 
    flex-direction: column; 
    align-items: center; 
    gap: 8px; 
    background: none; 
    border: none; 
    cursor: pointer; 
    color: #333; 
    font-size: 0.8rem;
    font-weight: 500;
    transition: transform 0.1s;
}

.attach-option:active { transform: scale(0.95); }

/* Círculos de colores (Iconos) */
.attach-icon-circle {
    width: 56px; 
    height: 56px; 
    border-radius: 50%; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    font-size: 1.4rem; 
    color: #fff; 
    box-shadow: 0 4px 10px rgba(0,0,0,0.15);
}

/* Colores específicos profesionales */
.icon-camera { 
    background: linear-gradient(135deg, #FF5E62, #FF9966); /* Naranja/Rojo */
}
.icon-gallery { 
    background: linear-gradient(135deg, #a18cd1, #fbc2eb); /* Violeta/Rosa suave */
}
.icon-location { 
    background: linear-gradient(135deg, #36D1DC, #5B86E5); /* Azul Agua/Profundo */
}

/* El texto debajo del icono */
.attach-option span {
    color: #555;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* Barra de Emojis */
.emoji-bar {
    display: flex; gap: 10px; padding: 8px 0; overflow-x: auto;
    border-top: 1px solid #f0f0f0; width: 100%; display: none;
}
.emoji-bar.visible { display: flex; } /* Se puede activar con JS si quieres */
.emoji-btn { font-size: 1.5rem; background: none; border: none; cursor: pointer; padding: 0 5px; }


/* --- 8. ELEMENTOS MULTIMEDIA (Burbujas) --- */

/* Imágenes y Video */
.chat-media-img, .chat-media-video {
    max-width: 240px; 
    max-height: 300px; 
    border-radius: 16px; 
    display: block; 
    margin-bottom: 4px; 
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}



/* --- 9. TARJETA DE UBICACIÓN (Estilo Apple Maps) --- */
.chat-media-location {
    width: 240px;
    height: 140px;
    background-color: #f2f2f7;
    border-radius: 16px;
    overflow: hidden;
    cursor: pointer;
    position: relative;
    border: 1px solid #e5e5ea;
    transition: transform 0.2s;
    margin-bottom: 4px;
}
.chat-media-location:active { transform: scale(0.98); }

/* Patrón de fondo (Fallback por si no carga la imagen) */
.map-fallback-pattern {
    position: absolute; inset: 0;
    background-image: linear-gradient(#fff 2px, transparent 2px), linear-gradient(90deg, #fff 2px, transparent 2px);
    background-size: 40px 40px;
    background-color: #f2f2f7; opacity: 0.5; z-index: 0;
}

/* Imagen del mapa */
.location-map-snapshot {
    position: absolute; top: 0; left: 0;
    width: 100%; height: 100%;
    object-fit: cover;
    z-index: 1; /* Encima del patrón */
    background-color: transparent;
}

/* Pin Rojo Flotante */
.location-pin-overlay {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -80%); /* Centrado y levantado */
    z-index: 2;
    display: flex; flex-direction: column; align-items: center;
}
.pin-head-mini {
    width: 24px; height: 24px; 
    background: #FF3B30; /* Rojo Apple */
    border-radius: 50%; 
    color: #fff; font-size: 12px; 
    display: flex; align-items: center; justify-content: center; 
    box-shadow: 0 2px 5px rgba(0,0,0,0.3);
}
.pin-stick-mini {
    width: 2px; height: 10px; background: #FF3B30; margin-top: -2px;
}

/* Footer de la tarjeta */
.location-footer-overlay {
    position: absolute; bottom: 0; left: 0; width: 100%;
    background: rgba(255,255,255,0.9);
    backdrop-filter: blur(8px);
    padding: 8px 12px;
    z-index: 3;
    border-top: 1px solid rgba(0,0,0,0.05);
}
.location-title {
    font-size: 0.8rem; font-weight: 700; color: #000; display: block;
}


/* ========================================= */
/* === AUDIO PLAYER PREMIUM (Estilo iMessage) === */
/* ========================================= */

.custom-audio-player {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 220px; /* Ancho fijo elegante */
    padding: 6px 0;
    cursor: pointer;
}

/* Botón Play/Pause */
.audio-play-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    cursor: pointer;
    flex-shrink: 0;
    transition: transform 0.1s;
}
.audio-play-btn:active { transform: scale(0.9); }

/* Línea de Progreso (Track) */
.audio-track-container {
    flex-grow: 1;
    height: 4px;
    border-radius: 2px;
    background-color: rgba(0,0,0,0.1); /* Gris suave base */
    position: relative;
    overflow: hidden;
}

/* Barra de Progreso (Relleno) */
.audio-progress-bar {
    height: 100%;
    width: 0%;
    border-radius: 2px;
    transition: width 0.1s linear;
}

/* Texto de Duración */
.audio-duration {
    font-size: 0.75rem;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
    min-width: 35px;
    text-align: right;
}

/* --- COLORES SEGÚN TIPO DE MENSAJE --- */

/* 1. MENSAJE ENVIADO (Fondo Azul) */
/* El reproductor debe ser BLANCO para contrastar */
.chat-message.sent .audio-play-btn {
    background-color: #fff;
    color: #007AFF; /* Icono azul */
}
.chat-message.sent .audio-track-container {
    background-color: rgba(255, 255, 255, 0.3); /* Track semi-transparente */
}
.chat-message.sent .audio-progress-bar {
    background-color: #fff; /* Progreso blanco */
}
.chat-message.sent .audio-duration {
    color: rgba(255, 255, 255, 0.9);
}

/* 2. MENSAJE RECIBIDO (Fondo Gris) */
/* El reproductor debe ser OSCURO/AZUL */
.chat-message.received .audio-play-btn {
    background-color: #007AFF;
    color: #fff; /* Icono blanco */
}
.chat-message.received .audio-track-container {
    background-color: #d1d1d6; /* Gris más oscuro */
}
.chat-message.received .audio-progress-bar {
    background-color: #007AFF; /* Progreso azul */
}
.chat-message.received .audio-duration {
    color: #8E8E93;
}

/* --- CLASE PARA QUITAR FONDO A MEDIA (FIX) --- */
.chat-message.no-bg {
    background-color: transparent !important;
    padding: 0 !important;
    box-shadow: none !important;
    border: none !important;
    max-width: 100% !important; /* Dejar que la imagen decida el ancho */
}

/* Ajuste para que las imágenes enviadas no tengan esquinas raras por el estilo 'sent' */
.chat-row.sent .chat-message.no-bg {
    border-radius: 0 !important;
}

/* Ajuste para que la ubicación se vea bien alineada */
.chat-media-location {
    margin: 0; /* Quitar margen negativo si hubiera */
}