/* Chat specific styles and responsive behavior */

/* Contenedor principal del chat */
.chat-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    background: #f8fafc;
}

/* Lista de chats */
#chats-list {
    transition: all 0.3s ease;
    background: white;
    border-right: 1px solid #e5e7eb;
}

.chat-item {
    padding: 16px 20px;
    border-bottom: 1px solid #f1f5f9;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}

.chat-item:hover {
    background: #f8fafc;
    transform: translateX(2px);
}

.chat-item.active {
    background: linear-gradient(135deg, #EEF2FF 0%, #E9D5FF 100%);
    border-left: 4px solid #6366F1;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.16);
}

.chat-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    background: linear-gradient(180deg, #6366F1 0%, #8B5CF6 100%);
}

/* Contenedor de mensajes */
#messages-container {
    padding: 24px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
    scroll-behavior: smooth;
}

/* Estilos de mensajes */
.message {
    max-width: 75%;
    padding: 16px 20px;
    border-radius: 20px;
    font-size: 0.95rem;
    line-height: 1.6;
    position: relative;
    margin: 8px 0;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.08);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    backdrop-filter: blur(10px);
}

.message:hover {
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}

/* Mensaje del cliente (estilo WhatsApp) */
.message.from-user {
    align-self: flex-start;
    margin-right: 25%;
    background: #ffffff;
    color: #303030;
    border-radius: 18px 18px 18px 4px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    position: relative;
}

/* Mensaje del negocio/bot (estilo WhatsApp verde) */
.message.from-bot {
    align-self: flex-end;
    margin-left: 25%;
    background: #dcf8c6;
    color: #303030;
    border-radius: 18px 18px 4px 18px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    position: relative;
}

/* Metadatos del mensaje */
.message-meta {
    font-size: 0.75rem;
    margin-top: 6px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.message.from-user .message-meta {
    color: #8e8e93;
    justify-content: flex-start;
}

.message.from-bot .message-meta {
    color: #8e8e93;
    justify-content: flex-end;
}

/* Iconos de estado y hora */
.message-meta i {
    font-size: 0.8rem;
    opacity: 0.8;
}

.message-time {
    font-size: 0.7rem;
    font-weight: 500;
    letter-spacing: 0.5px;
    opacity: 0.9;
}

/* Estado de lectura */
.message-status {
    display: inline-flex;
    align-items: center;
    gap: 2px;
}

/* Efectos de hover para los mensajes (estilo WhatsApp sutil) */
.message.from-user:hover {
    background: #f0f0f0;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
}

.message.from-bot:hover {
    background: #c3e88d;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
}

@media (max-width: 768px) {

    /* Layout responsive - prevent overflow */
    .flex.h-screen {
        height: auto !important;
        min-height: 100vh !important;
    }

    .w-80 {
        width: 100% !important;
        max-width: 100% !important;
    }

    .flex-1 {
        width: 100% !important;
        min-width: 0 !important;
        /* Prevent flex overflow */
    }

    /* Sidebar responsive */
    .sidebar-collapsed {
        display: none
    }

    /* Chat header responsive - prevent overflow and wrapping issues */
    #chat-header {
        padding: 12px !important;
        flex-wrap: wrap !important;
        gap: 8px !important;
        overflow-x: hidden !important;
    }

    #chat-header .flex {
        flex-wrap: wrap !important;
        gap: 6px !important;
        width: 100% !important;
    }

    #chat-header .flex.items-center.space-x-3 {
        width: 100% !important;
        justify-content: flex-start !important;
        margin-top: 8px !important;
    }

    /* Hide address search on mobile to save space */
    #chat-header .hidden.md\\:flex {
        display: none !important;
    }

    /* Make "Crear pedido" button smaller and fit properly */
    #open-manual-order-chat {
        padding: 8px 12px !important;
        font-size: 0.875rem !important;
        white-space: nowrap !important;
        min-width: auto !important;
        flex-shrink: 0 !important;
    }

    #open-manual-order-chat i {
        margin-right: 4px !important;
    }

    /* Adjust other header buttons */
    #chat-header button {
        padding: 8px !important;
        min-width: 40px !important;
        min-height: 40px !important;
    }

    /* Bot toggle area */
    #chat-header .border-r {
        border-right: none !important;
        padding-right: 0 !important;
        margin-right: 0 !important;
    }

    /* Messages responsive */
    #messages-container {
        padding: 12px !important;
        gap: 10px !important;
    }

    .message {
        max-width: 85% !important;
        padding: 10px 14px !important;
        font-size: 0.9rem !important;
    }

    .message.from-user {
        margin-right: 10% !important;
    }

    .message.from-bot {
        margin-left: 10% !important;
    }

    /* Input area responsive - prevent overflow */
    #message-input-area {
        padding: 10px 12px !important;
    }

    #message-input-area>.flex {
        flex-wrap: nowrap !important;
        gap: 6px !important;
        align-items: flex-end !important;
    }

    /* Buttons touch-friendly */
    #message-input-area button {
        padding: 10px !important;
        min-width: 44px !important;
        min-height: 44px !important;
        flex-shrink: 0 !important;
    }

    /* Message input */
    #message-input {
        font-size: 0.9rem !important;
        padding: 10px 12px !important;
    }

    /* Recording indicator responsive */
    #recording-indicator {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 8px !important;
    }

    .recording-dot {
        width: 10px !important;
        height: 10px !important;
    }

    /* Map container */
    #map-container {
        height: 250px !important;
    }

    /* Attach menu positioning */
    #attach-menu {
        min-width: 180px !important;
        font-size: 0.875rem !important;
    }
}

/* Ocultar sidebar de forma global cuando se quiera esconder el CRUD/lista */
.sidebar-hidden {
    display: none !important;
}

/* Input de mensaje mejorado */
#message-input-area {
    position: sticky;
    bottom: 0;
    z-index: 10;
    background: white;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
}

#message-input {
    font-size: 1rem;
    line-height: 1.5;
    border-radius: 12px;
    transition: all 0.2s ease;
}

#message-input:focus {
    box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.1);
}

/* Menú de adjuntos mejorado */
#attach-menu {
    min-width: 200px;
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(10px);
    background: rgba(255, 255, 255, 0.95);
}

#attach-menu button {
    transition: all 0.2s ease;
    border-radius: 8px;
}

#attach-menu button:hover {
    background: #f97316;
    color: white;
    transform: translateX(4px);
}

/* ===== Miniaturas de imágenes en mensajes ===== */
.message-image {
    display: block;
    width: 100%;
    max-width: 220px;
    max-height: 220px;
    height: auto;
    border-radius: 12px;
    object-fit: cover;
    cursor: zoom-in;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.message-image:hover {
    transform: scale(1.02);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
}

@media (max-width: 768px) {
    .message-image {
        max-width: 160px;
        max-height: 160px;
        border-radius: 10px;
    }
}

/* Modal de imagen mejorado */
#image-modal img {
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

/* Mapa responsive */
#map {
    width: 100%;
    height: 100%;
    border-radius: 8px;
}

/* Indicador de grabación mejorado */
.recording-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #ef4444;
    box-shadow: 0 0 0 8px rgba(239, 68, 68, 0.15);
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% {
        transform: scale(1);
        opacity: 1;
    }

    50% {
        transform: scale(1.2);
        opacity: 0.7;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Loading states */
.loading {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

/* Scrollbar personalizado */
#messages-container::-webkit-scrollbar {
    width: 6px;
}

#messages-container::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.05);
    border-radius: 3px;
}

#messages-container::-webkit-scrollbar-thumb {
    background: rgba(249, 115, 22, 0.3);
    border-radius: 3px;
}

#messages-container::-webkit-scrollbar-thumb:hover {
    background: rgba(249, 115, 22, 0.5);
}

/* ===== Audio centrado y visualizador simple ===== */
.message-audio,
.audio-player {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.audio-control {
    width: 100%;
    max-width: 320px;
}

.audio-visualizer {
    display: inline-flex;
    align-items: flex-end;
    gap: 3px;
    height: 16px;
}

.audio-visualizer span {
    display: block;
    width: 3px;
    height: 6px;
    background: #6366F1;
    opacity: 0.6;
}

.audio-visualizer.playing span {
    animation: av-pulse 850ms infinite ease-in-out;
}

.audio-visualizer.playing span:nth-child(2) {
    animation-delay: 120ms;
}

.audio-visualizer.playing span:nth-child(3) {
    animation-delay: 240ms;
}

.audio-visualizer.playing span:nth-child(4) {
    animation-delay: 360ms;
}

@keyframes av-pulse {
    0% {
        height: 6px;
        opacity: 0.6;
    }

    30% {
        height: 16px;
        opacity: 1;
    }

    60% {
        height: 10px;
        opacity: 0.8;
    }

    100% {
        height: 6px;
        opacity: 0.6;
    }
}