/* Reset y Base */
* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Inter', sans-serif; }
body { height: 100vh; background-color: #f0f2f5; overflow: hidden; }

.app-container {
    display: flex;
    height: 100vh;
    width: 100%;
    background: white;
}

/* SIDEBAR */
.sidebar {
    width: 380px;
    border-right: 1px solid #e1e4e8;
    display: flex;
    flex-direction: column;
    background: white;
}

.sidebar-header {
    padding: 20px;
    background: #008069;
    color: white;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    z-index: 10;
}

.sidebar-header h2 { font-size: 1.2rem; margin-bottom: 15px; }

/* Grupo de título con contador */
.header-title-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Contador de usuarios urgentes */
.urgent-counter {
    background: #ff5252;
    color: white;
    font-size: 0.75rem;
    font-weight: 700;
    padding: 3px 8px;
    border-radius: 12px;
    min-width: 20px;
    text-align: center;
    animation: bounce 0.5s ease;
}

@keyframes bounce {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.2); }
}

/* PESTAÑAS DE FILTRO */
.status-tabs {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    padding-bottom: 5px;
}

.tab {
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    padding: 5px 10px;
    border-radius: 16px;
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    flex-shrink: 0;
}

.tab:hover { background: rgba(255,255,255,0.3); }
.tab.active { background: white; color: #008069; font-weight: 600; }

/* Tab de urgentes con estilo especial */
.tab-urgent {
    background: rgba(255, 82, 82, 0.2) !important;
    border: 1px solid rgba(255, 82, 82, 0.3);
}

.tab-urgent:hover {
    background: rgba(255, 82, 82, 0.3) !important;
}

.tab-urgent.active {
    background: #ff5252 !important;
    color: white !important;
    border-color: #ff5252;
}

/* LISTA DE USUARIOS */
.user-list { flex: 1; overflow-y: auto; }

.user-item {
    padding: 14px 20px;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
}

.user-item:hover {
    background-color: #f5f6f6;
}

.user-item.active {
    background-color: #f0f2f5;
    border-left: 4px solid #008069;
    box-shadow: inset 0 0 0 1px rgba(0,128,105,0.1);
}

/* Usuario esperando atención humana */
.user-item.needs-attention {
    background-color: #fff3e0;
    border-left: 4px solid #ff9800;
    animation: pulse-attention 2s ease-in-out infinite;
}

.user-item.needs-attention:hover {
    background-color: #ffe0b2;
}

.user-item.needs-attention.active {
    background-color: #ffe0b2;
    border-left: 4px solid #ff9800;
    box-shadow: inset 0 0 0 1px rgba(255, 152, 0, 0.2);
}

@keyframes pulse-attention {
    0%, 100% { box-shadow: 0 0 0 0 rgba(255, 152, 0, 0); }
    50% { box-shadow: 0 0 8px 2px rgba(255, 152, 0, 0.4); }
}

/* Indicador visual "URGENTE" */
.user-item.needs-attention::before {
    content: '🔔';
    position: absolute;
    left: 8px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 1.2rem;
    animation: ring 1s ease-in-out infinite;
}

@keyframes ring {
    0%, 100% { transform: translateY(-50%) rotate(0deg); }
    10%, 30% { transform: translateY(-50%) rotate(-10deg); }
    20%, 40% { transform: translateY(-50%) rotate(10deg); }
}

.user-item.needs-attention .user-info {
    margin-left: 20px;
}

.user-info { display: flex; flex-direction: column; gap: 4px; }
.user-name { font-weight: 600; color: #111b21; font-size: 0.95rem; }
.user-last { font-size: 0.8rem; color: #667781; }

/* Razón de escalamiento */
.escalation-reason {
    font-size: 0.72rem;
    color: #ff6f00;
    font-weight: 600;
    background: rgba(255, 152, 0, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
    width: fit-content;
    cursor: help;
}

/* BADGES (Etiquetas de Estado) */
.status-badge {
    font-size: 0.7rem;
    padding: 4px 8px;
    border-radius: 4px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Colores según estado */
.badge-incoming { background-color: #e0e0e0; color: #555; }
.badge-initial { background-color: #e3f2fd; color: #1976d2; }
.badge-quoting { background-color: #fff3e0; color: #f57c00; } /* Naranja cotizando */
.badge-booking { background-color: #e8f5e9; color: #2e7d32; } /* Verde cierre */

/* CHAT AREA */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-image: url('https://user-images.githubusercontent.com/15075759/28719144-86dc0f70-73b1-11e7-911d-60d70fcded21.png');
    background-color: #efeae2;
}

.chat-header {
    padding: 12px 20px;
    background: #f0f2f5;
    border-bottom: 1px solid #d1d7db;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.chat-header h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: #111b21;
}

.user-info-header { display: flex; align-items: center; gap: 10px; }
.phone-number { color: #54656f; font-size: 0.9rem; }

/* Badge urgente en el header del chat */
.urgent-badge {
    background: linear-gradient(135deg, #ff5252 0%, #ff9800 100%);
    color: white;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 6px 12px;
    border-radius: 20px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    animation: pulse-badge 1.5s ease-in-out infinite;
    box-shadow: 0 2px 8px rgba(255, 82, 82, 0.4);
    cursor: help;
}

@keyframes pulse-badge {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.hidden { display: none !important; }

.messages-container {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
    scroll-behavior: smooth;
}

.messages-container::-webkit-scrollbar {
    width: 6px;
}

.messages-container::-webkit-scrollbar-track {
    background: transparent;
}

.messages-container::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.2);
    border-radius: 3px;
}

.messages-container::-webkit-scrollbar-thumb:hover {
    background: rgba(0,0,0,0.3);
}

.message {
    max-width: 65%;
    padding: 6px 10px 8px 10px;
    border-radius: 8px;
    font-size: 0.95rem;
    line-height: 1.4;
    position: relative;
    word-wrap: break-word;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
    gap: 4px;
    animation: fadeIn 0.2s ease-in;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.message.user {
    align-self: flex-start;
    background: white;
    border-top-left-radius: 0;
}

.message.assistant {
    align-self: flex-end;
    background: #d9fdd3;
    border-top-right-radius: 0;
}

/* Contenedor de texto y metadata */
.message-text {
    display: block;
    word-wrap: break-word;
    white-space: pre-wrap;
    margin-bottom: 2px;
}

.message-time {
    font-size: 0.68rem;
    color: #667781;
    align-self: flex-end;
    margin-top: -2px;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Double check para mensajes del asistente */
.message.assistant .message-time::after {
    content: '✓✓';
    color: #53bdeb;
    font-size: 0.85rem;
    font-weight: bold;
}

/* Separador de fecha estilo WhatsApp */
.date-separator {
    text-align: center;
    margin: 16px 0 12px 0;
    display: flex;
    justify-content: center;
}

.date-separator span {
    background: rgba(225, 245, 254, 0.92);
    color: #54656f;
    padding: 5px 12px;
    border-radius: 8px;
    font-size: 0.75rem;
    font-weight: 500;
    box-shadow: 0 1px 1px rgba(0,0,0,0.06);
    letter-spacing: 0.3px;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #54656f;
    text-align: center;
}
.empty-icon { font-size: 4rem; margin-bottom: 20px; }

/* Loading dots indicator */
.loading {
    text-align: center;
    padding: 20px;
    color: #667781;
    font-size: 0.9rem;
}

.typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px 16px;
    background: white;
    border-radius: 8px;
    width: fit-content;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #90949c;
    animation: typing 1.4s infinite;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.7; }
    30% { transform: translateY(-10px); opacity: 1; }
}

.input-area {
    padding: 12px 16px;
    background: #f0f2f5;
    display: flex;
    gap: 10px;
    align-items: center;
    box-shadow: 0 -1px 2px rgba(0,0,0,0.05);
    flex-wrap: wrap;
}

/* Botón Reactivar Bot */
.reactivate-bot-btn {
    padding: 8px 16px;
    background: linear-gradient(135deg, #4caf50 0%, #66bb6a 100%);
    color: white;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.85rem;
    transition: all 0.3s;
    box-shadow: 0 2px 4px rgba(76, 175, 80, 0.3);
    width: 100%;
    order: -1;
}

.reactivate-bot-btn:hover {
    background: linear-gradient(135deg, #43a047 0%, #66bb6a 100%);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(76, 175, 80, 0.4);
}

.reactivate-bot-btn:active {
    transform: translateY(0);
}

#message-input {
    flex: 1;
    padding: 10px 15px;
    border: none;
    border-radius: 20px;
    outline: none;
    font-size: 0.95rem;
    background: white;
    transition: box-shadow 0.2s;
}

#message-input:focus {
    box-shadow: 0 0 0 2px rgba(0, 128, 105, 0.2);
}

#send-btn {
    padding: 10px 24px;
    background: #008069;
    color: white;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
    transition: all 0.2s;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

#send-btn:hover {
    background: #006c59;
    transform: translateY(-1px);
    box-shadow: 0 3px 6px rgba(0,0,0,0.15);
}

#send-btn:active {
    transform: translateY(0);
}
/* ... (Todo tu CSS anterior) ... */

/* ESTILOS DE LOGIN */
.login-body {
    background: #008069;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
}

.login-container {
    background: white;
    padding: 40px;
    border-radius: 10px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
    text-align: center;
}

.login-header h1 { color: #008069; margin-bottom: 5px; }
.login-header p { color: #666; margin-bottom: 30px; }

.form-group { margin-bottom: 20px; text-align: left; }
.form-group label { display: block; font-size: 0.9rem; margin-bottom: 5px; color: #333; font-weight: 600; }
.form-group input { 
    width: 100%; padding: 12px; border: 1px solid #ccc; border-radius: 6px; font-size: 1rem;
}

#login-btn {
    width: 100%;
    padding: 12px;
    background: #008069;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
}
#login-btn:hover { background: #006c59; }

.error-msg { color: #d32f2f; font-size: 0.9rem; margin-top: 15px; min-height: 20px; }

/* ETIQUETA DE AGENTE EN EL CHAT */
.agent-label {
    font-size: 0.68rem;
    color: #008069;
    font-weight: 600;
    margin-bottom: 3px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.9;
}
/* ... (Estilos anteriores) ... */

/* NUEVOS ESTILOS PARA CABECERA */
/* CABECERA LATERAL */
.header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.header-actions {
    display: flex;
    gap: 8px; /* Espacio entre los dos iconos */
}

.icon-btn {
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.7);
    cursor: pointer;
    padding: 6px;
    border-radius: 50%; /* Redondos */
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

/* Efecto especial para el logout si quieres */
.icon-btn.logout:hover {
    background: rgba(255, 80, 80, 0.3); /* Rojo suave al pasar el mouse */
}

/* Animación de rotación al actualizar */
@keyframes spin { 100% { transform: rotate(360deg); } }
.spinning svg { animation: spin 1s linear infinite; }

.logout-btn {
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.8);
    cursor: pointer;
    padding: 5px;
    border-radius: 5px;
    display: flex;
    align-items: center;
    transition: all 0.2s;
}

.logout-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}