body {
    margin: 0;
    font-family: Arial, sans-serif;
    overflow: hidden;
}

#crm-container {
    display: flex;
    height: 100vh;
}

/* --- ESTRUCTURA DE 3 COLUMNAS --- */
#col-chats {
    flex: 0 0 280px;
    display: flex;
    flex-direction: column;
    border-right: 1px solid #ddd;
    background-color: #f7f7f7;
}

#col-management {
    flex: 0 0 320px;
    display: flex;
    flex-direction: column;
    border-right: 1px solid #ddd;
    background-color: #f7f7f7;
}

#col-conversation {
    flex-grow: 1;
    display: flex;
}

/* --- AJUSTES A COMPONENTES HIJOS --- */

/* Columna 1 */
#col-chats h2 {
    padding: 15px 10px;
    margin: 0;
    font-size: 1.2em;
    background-color: #128C7E;
    color: white;
    flex-shrink: 0;
}

#clients-ul {
    flex-grow: 1;
    overflow-y: auto;
    padding: 0;
    margin: 0;
}

/* Columna 2 */
#filter-controls {
    flex-shrink: 0;
    padding: 10px;
    background-color: #f0f2f5;
    border-bottom: 1px solid #ddd;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

#customer-panel {
    flex-grow: 1;
    padding: 15px;
    background-color: #f8f9fa;
    overflow-y: auto;
}

/* Columna 3 */
#chat-window {
    width: 100%;
    display: flex;
    flex-direction: column;
}

/* --- ESTILOS DE LOS ITEMS DE CLIENTE --- */
.client-item { 
    list-style: none; 
    padding: 10px; 
    border-bottom: 1px solid #eee; 
    cursor: pointer; 
    transition: background-color 0.2s; 
    display: flex;
    flex-direction: column;
    gap: 2px; /* ✨ Espaciado entre elementos */
}

.client-item:hover { 
    background-color: #e9e9e9; 
}

.client-item.active { 
    background-color: #e1ffc7; 
    font-weight: bold;
    border-right: 4px solid #00a884;
}

/* --- Datos dentro del client-item --- */
.client-name {
    font-weight: bold;
    color: #111;
    font-size: 1em;
}

.client-number {
    font-size: 0.85em;
    color: #666;
}

.client-status {
    font-size: 0.8em;
    padding: 3px 10px;
    border-radius: 12px;
    background-color: #e0e0e0;
    color: #333;
    width: fit-content;
    margin-top: 2px;
    font-weight: 500;
}

/* ✨ NUEVO: Tag de ubicación */
.client-location {
    font-size: 0.75em;
    padding: 3px 8px;
    border-radius: 10px;
    width: fit-content;
    margin-top: 2px;
    font-weight: 600;
    display: inline-block;
}

.client-location.location-lima {
    background-color: #e3f2fd;
    color: #1565c0;
    border: 1px solid #90caf9;
}

.client-location.location-provincia {
    background-color: #e8f5e9;
    color: #2e7d32;
    border: 1px solid #a5d6a7;
}

/* --- Resto de estilos --- */
.status-tag, .tag-item { 
    font-size: 0.8em; 
    padding: 2px 8px; 
    border-radius: 12px; 
}

.status-tag { 
    font-weight: bold; 
    background-color: #e0e0e0; 
    color: #333; 
}

.tag-item { 
    background-color: #d1e7dd; 
    color: #0f5132; 
    border: 1px solid #a3cfbb; 
}

#client-header { 
    padding: 15px 20px; 
    border-bottom: 1px solid #ddd; 
    background-color: #f0f0f0; 
}

#response-area { 
    padding: 15px 20px; 
    border-top: 1px solid #ddd; 
    background-color: #f0f0f0; 
}

#messages-display { 
    flex-grow: 1; 
    overflow-y: auto; 
    padding: 20px; 
    background-color: #e5ddd5; 
    display: flex; 
    flex-direction: column; 
    gap: 8px; 
}

#customer-panel h4 { 
    margin-top: 0; 
    margin-bottom: 15px; 
    font-size: 1.1em; 
    color: #333; 
}

.panel-section { 
    margin-bottom: 15px; 
}

.panel-section label { 
    font-weight: bold; 
    font-size: 0.9em; 
    margin-bottom: 5px; 
    display: block; 
}

#customer-panel select, 
#customer-panel input[type="text"], 
#customer-panel textarea { 
    width: 100%; 
    padding: 8px; 
    border-radius: 5px; 
    border: 1px solid #ccc; 
    box-sizing: border-box; 
}

.add-tag-wrapper { 
    display: flex; 
    gap: 5px; 
    margin-top: 5px; 
}

#save-changes-button { 
    width: 100%; 
    padding: 10px; 
    background-color: #007bff; 
    color: white; 
    border: none; 
    border-radius: 5px; 
    font-weight: bold; 
    cursor: pointer; 
    margin-top: 10px; 
}

#customer-panel *:disabled { 
    background-color: #e9ecef; 
    cursor: not-allowed; 
    opacity: 0.7; 
}

.tag-item.protected { 
    cursor: not-allowed; 
}

.tag-item.tag-lima { 
    background-color: #fff3cd; 
    color: #664d03; 
    border: 1px solid #ffecb5; 
}

.tag-item.tag-provincia { 
    background-color: #d1e7dd; 
    color: #0f5132; 
    border: 1px solid #a3cfbb; 
}

.remove-tag-btn { 
    margin-left: 5px; 
    border: none; 
    background: none; 
    cursor: pointer; 
    font-weight: bold; 
    color: #0f5132; 
    opacity: 0.6; 
    padding: 0 2px; 
}

.remove-tag-btn:hover { 
    opacity: 1; 
}

.message { 
    padding: 8px 12px; 
    padding-right: 60px; 
    border-radius: 18px; 
    max-width: 70%; 
    line-height: 1.4; 
    position: relative; 
    word-wrap: break-word; 
    font-size: 0.9em; 
}

.message-time { 
    font-size: 0.75em; 
    color: #888; 
    position: absolute; 
    bottom: 5px; 
    right: 12px; 
    cursor: help; /* 👈 NUEVO: Cambia el cursor para indicar que hay tooltip */
}

/* 🆕 NUEVO: Estilos para el tooltip de fecha completa */
.message-time-tooltip {
    position: absolute;
    bottom: 30px; /* Aparece arriba del timestamp */
    right: 0;
    background-color: rgba(0, 0, 0, 0.85);
    color: white;
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 0.85em;
    white-space: pre-wrap;
    z-index: 1000;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    pointer-events: none; /* No interfiere con el mouse */
    opacity: 0;
    transition: opacity 0.2s ease;
}

.message-time:hover .message-time-tooltip {
    opacity: 1;
}

/* 🆕 NUEVO: Separadores de fecha */
.date-separator {
    text-align: center;
    margin: 20px auto 15px;
    padding: 6px 16px;
    background: linear-gradient(135deg, #e3f2fd 0%, #e1f5fe 100%);
    border-radius: 20px;
    font-size: 0.85em;
    color: #1565c0;
    font-weight: 600;
    letter-spacing: 0.5px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.08);
    width: fit-content;
    max-width: 200px;
}

.date-separator::before {
    content: "📅 ";
}

.message.agente-bot { 
    background-color: #ffffff; 
    align-self: flex-start; 
    border: 1px solid #eee; 
}

.message.agente { 
    background-color: #cfe2ff; 
    align-self: flex-start; 
    border: 1px solid #b6d4fe; 
}

.message.cliente { 
    background-color: #dcf8c6; 
    align-self: flex-end; 
}

.date-divider { 
    text-align: center; 
    margin: 15px auto; 
    padding: 2px 12px; 
    background-color: #e1f2fb; 
    border-radius: 12px; 
    font-size: 0.8em; 
    color: #555e63; 
}

#response-area { 
    display: flex; 
    align-items: flex-end; 
    gap: 10px; 
}

#response-area textarea { 
    flex-grow: 1; 
    border-radius: 18px; 
    padding: 10px 15px; 
    border: 1px solid #ccc; 
    resize: vertical; 
    font-family: Arial, sans-serif; 
    font-size: 1em; 
    line-height: 1.4; 
}

#response-area button { 
    border-radius: 50%; 
    width: 45px; 
    height: 45px; 
    font-weight: bold; 
    background-color: #128C7E; 
    color: white; 
    border: none; 
    cursor: pointer; 
    flex-shrink: 0; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
}

#search-input { 
    width: 100%; 
    padding: 8px 12px; 
    border-radius: 18px; 
    border: 1px solid #ccc; 
    box-sizing: border-box; 
}

.filter-row { 
    display: flex; 
    gap: 10px; 
    align-items: center; 
}

#status-filter, #manual-tag-filter { 
    flex-grow: 1; 
    padding: 8px; 
    border-radius: 8px; 
    border: 1px solid #ccc; 
    background-color: white; 
}

#location-filters { 
    display: flex; 
    justify-content: flex-end; 
}

#location-filters .filter-btn { 
    padding: 8px 12px; 
    border: 1px solid #ccc; 
    background-color: #fff; 
    cursor: pointer; 
    border-radius: 8px; 
}

#location-filters .filter-btn.active { 
    background-color: #128C7E; 
    color: white; 
    border-color: #128C7E; 
    font-weight: bold; 
}

/* ✨ NUEVO: Contador de resultados */
#results-counter { 
    font-size: 0.85em; 
    color: #555; 
    text-align: center; 
    font-weight: bold; 
    padding: 8px 10px; 
    margin-top: 5px;
    border-radius: 8px; 
    background-color: #f0f2f5; 
    border: 1px solid #ddd; 
}

#results-counter:empty {
    display: none;
}

.client-item.hidden { 
    display: none; 
}

/* ==========================================================
   ESTILOS PARA LA OPCIÓN C: REACTIVACIÓN DEL BOT
   ========================================================== */

/* Botón de Finalizar Atención */
#finalize-attention-button {
    width: 100%;
    padding: 12px;
    background-color: #28a745; /* Verde */
    color: white;
    border: none;
    border-radius: 5px;
    font-weight: bold;
    cursor: pointer;
    margin-top: 15px;
    transition: all 0.3s ease;
    font-size: 0.95em;
    display: none; /* Oculto por defecto */
}

#finalize-attention-button:hover:not(:disabled) {
    background-color: #218838; /* Verde más oscuro */
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}

#finalize-attention-button:disabled {
    background-color: #6c757d; /* Gris */
    cursor: not-allowed;
    opacity: 0.6;
}

/* Banner de "Bot Pausado" */
.bot-paused-indicator {
    background-color: #fff3cd;
    border: 2px solid #ffc107;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 15px;
    text-align: center;
    font-weight: bold;
    color: #856404;
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% {
        border-color: #ffc107;
    }
    50% {
        border-color: #ff9800;
    }
}

.bot-paused-indicator::before {
    content: "⚠️ ";
}

/* Indicador de estado en la lista de clientes */
.client-item.manual-attention {
    border-left: 4px solid #ffc107;
    background-color: #fffbea;
}

.client-item.manual-attention:hover {
    background-color: #fff3cd;
}

/* ============================================ */
/* 🆕 MODAL 2: ADELANTO */
/* ============================================ */

.adelanto-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.85);
    z-index: 10003;
    display: none;
    justify-content: center;
    align-items: center;
    padding: 15px;
    animation: fadeIn 0.3s ease;
    overflow-y: auto;
}

.adelanto-modal {
    background: white;
    border-radius: 16px;
    max-width: 500px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    animation: slideUp 0.3s ease;
}

.adelanto-header {
    background: linear-gradient(135deg, #4285F4 0%, #34A853 100%);
    color: white;
    text-align: center;
    padding: 20px;
    border-radius: 16px 16px 0 0;
}

.adelanto-header h2 {
    margin: 0;
    font-size: 1.4em;
}

.adelanto-body {
    padding: 20px;
}

/* 🆕 MENSAJE ROTATIVO DE URGENCIA */
.urgencia-rotating {
    background: linear-gradient(135deg, #ff6b6b 0%, #ee5a6f 100%);
    color: white;
    text-align: center;
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 20px;
    box-shadow: 0 4px 12px rgba(255, 107, 107, 0.3);
}

.mensaje-urgencia {
    margin: 0;
    font-weight: bold;
    font-size: 1em;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.02); }
}

/* TEXTO INTRODUCTORIO */
.adelanto-intro {
    color: #606770;
    line-height: 1.6;
    margin-bottom: 15px;
    text-align: center;
}

/* MONTO DEL ADELANTO */
.adelanto-monto {
    background: #f0f7ff;
    border-left: 4px solid #4285F4;
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 20px;
    text-align: center;
}

.adelanto-monto p {
    margin: 0;
    font-size: 1.2em;
    color: #1c1e21;
}

/* BENEFICIOS */
.adelanto-benefits {
    margin-bottom: 20px;
}

.adelanto-benefits h3 {
    margin: 0 0 10px 0;
    font-size: 1.1em;
    color: #1c1e21;
}

.adelanto-benefits ul {
    margin: 0;
    padding-left: 20px;
    color: #606770;
}

.adelanto-benefits li {
    margin: 8px 0;
    line-height: 1.5;
}

/* DATOS DE PAGO */
.adelanto-payment-info {
    background: #f9f9f9;
    border: 2px solid #e0e0e0;
    padding: 16px;
    border-radius: 8px;
    margin-bottom: 20px;
}

.adelanto-payment-info h3 {
    margin: 0 0 12px 0;
    font-size: 1.1em;
    color: #1c1e21;
}

.payment-details p {
    margin: 6px 0;
    color: #606770;
}

.payment-details strong {
    color: #1c1e21;
}

.btn-copiar {
    width: 100%;
    padding: 10px;
    margin-top: 10px;
    background: #4285F4;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 0.95em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-copiar:hover {
    background: #1a73e8;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(66, 133, 244, 0.3);
}

.btn-copiar:active {
    transform: translateY(0);
}

/* 🆕 ADVERTENCIA DE TIEMPO */
.adelanto-warning {
    background: #fff3cd;
    border: 2px solid #ffc107;
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 20px;
}

.warning-title {
    margin: 0 0 12px 0;
    font-size: 1em;
    font-weight: bold;
    color: #856404;
    text-align: center;
    line-height: 1.4;
}

.warning-list p {
    margin: 0 0 8px 0;
    font-weight: 600;
    color: #856404;
}

.warning-list ul {
    margin: 0;
    padding-left: 20px;
    color: #856404;
}

.warning-list li {
    margin: 6px 0;
    line-height: 1.5;
}

/* BOTONES */
.adelanto-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 0 20px 20px 20px;
}

.btn-adelanto-proceed {
    width: 100%;
    padding: 16px;
    background: linear-gradient(135deg, #34A853 0%, #0F9D58 100%);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1.05em;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-adelanto-proceed:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(52, 168, 83, 0.4);
}

.btn-adelanto-cancel {
    width: 100%;
    padding: 14px;
    background: #f0f2f5;
    color: #606770;
    border: 2px solid #ccd0d5;
    border-radius: 8px;
    font-size: 1em;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-adelanto-cancel:hover {
    background: #e4e6eb;
    border-color: #8a8d91;
}

/* 📱 RESPONSIVE */
@media (max-width: 600px) {
    .adelanto-header h2 {
        font-size: 1.2em;
    }

    .mensaje-urgencia {
        font-size: 0.9em;
    }

    .adelanto-monto p {
        font-size: 1.1em;
    }

    .warning-title {
        font-size: 0.95em;
    }

    .adelanto-buttons {
        gap: 10px;
    }
}