/* ============================================
   VARIABLES Y RESET - VERSIÓN PREMIUM FUNCIONAL
============================================ */
:root {
    --smartchat-primary: #88008a;
    --smartchat-primary-light: #9d009f;
    --smartchat-primary-dark: #720073;
    --smartchat-primary-gradient: linear-gradient(135deg, #88008a 0%, #9d009f 100%);
    --smartchat-primary-gradient-hover: linear-gradient(135deg, #9d009f 0%, #88008a 100%);
    
    --smartchat-bg: #ffffff;
    --smartchat-bg-soft: #f9f7fa;
    --smartchat-bg-input: #fcfbfd;
    --smartchat-bg-chat: #f8f5ff;
    
    --smartchat-border: #e8e0e9;
    --smartchat-border-light: #f0ebf1;
    --smartchat-border-hover: #d8d0d9;
    
    --smartchat-text: #2d1b2e;
    --smartchat-text-secondary: #7a6a7b;
    --smartchat-text-muted: #a99baa;
    
    --smartchat-success: #10b981;
    --smartchat-error: #ef4444;
    --smartchat-warning: #f59e0b;
    
    --smartchat-shadow: 0 20px 50px rgba(136, 0, 138, 0.15);
    --smartchat-shadow-light: 0 10px 30px rgba(136, 0, 138, 0.1);
    --smartchat-shadow-hover: 0 25px 60px rgba(136, 0, 138, 0.2);
    --smartchat-shadow-inner: inset 0 2px 8px rgba(136, 0, 138, 0.05);
    
    --smartchat-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --smartchat-transition-slow: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    
    --smartchat-radius: 20px;
    --smartchat-radius-md: 16px;
    --smartchat-radius-sm: 12px;
    --smartchat-radius-xs: 8px;
    --smartchat-radius-full: 50%;
}

/* ============================================
   TEXTO FLOTANTE DE AYUDA - PREMIUM
============================================ */
.smartchat-helper {
    position: fixed;
    bottom: 150px;
    right: 24px;
    background: linear-gradient(135deg, #ffffff, #fdfcff);
    color: var(--smartchat-primary);
    border-radius: var(--smartchat-radius-md);
    padding: 20px 24px;
    box-shadow: var(--smartchat-shadow);
    z-index: 10000;
    max-width: 280px;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    transition: var(--smartchat-transition-slow);
    pointer-events: none;
    border: 1px solid var(--smartchat-border);
    backdrop-filter: blur(10px);
}

.smartchat-helper.show {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

.helper-content {
    position: relative;
}

.helper-content p {
    margin: 0;
    font-size: 15px;
    font-weight: 500;
    text-align: left;
    color: var(--smartchat-text);
    line-height: 1.5;
}

/* ============================================
   BOTÓN FLOTANTE - PREMIUM
============================================ */
.smartchat-toggle-btn {
    position: fixed;
    bottom: 85px;
    right: 20px;
    width: 55px;
    height: 55px;
    border-radius: var(--smartchat-radius-full);
    background: var(--smartchat-primary-gradient);
    color: white;
    border: none;
    box-shadow: var(--smartchat-shadow);
    cursor: pointer;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 26px;
    transition: var(--smartchat-transition);
    outline: none;
    overflow: hidden;
}

.smartchat-toggle-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: var(--smartchat-transition-slow);
}

.smartchat-toggle-btn:hover {
    background: var(--smartchat-primary-gradient-hover);
    transform: translateY(-3px) scale(1.05);
    box-shadow: var(--smartchat-shadow-hover);
}

.smartchat-toggle-btn:hover::before {
    left: 100%;
}

.smartchat-toggle-btn:active {
    transform: translateY(-1px) scale(0.98);
}

/* ============================================
   CONTENEDOR PRINCIPAL - PREMIUM
============================================ */
.smartchat-container {
    max-height: 700px;
    min-height: 520px;
    background: var(--smartchat-bg);
    border-radius: var(--smartchat-radius);
    box-shadow: var(--smartchat-shadow);
    z-index: 9999;
    display: none;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.97);
    transition: var(--smartchat-transition-slow);
    pointer-events: none;
    border: 1px solid var(--smartchat-border);
}

.smartchat-container.active {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
    position: fixed;
    bottom: 108px;
    right: 24px;
    width: 420px;
    height: 75vh;
    display: flex;
}

/* Versión móvil */
@media (max-width: 768px) {
    .smartchat-container {
        width: 100% !important;
        height: 100vh !important;
        max-height: 100vh;
        min-height: 100vh;
        bottom: 0 !important;
        right: 0 !important;
        border-radius: 0;
        box-shadow: none;
        border: none;
    }
    
    .smartchat-toggle-btn {
        bottom: 85px;
        right: 20px;
        width: 64px;
        height: 64px;
        font-size: 24px;
    }
    
    .smartchat-helper {
        bottom: 96px;
        right: 20px;
        max-width: calc(100% - 40px);
    }
}

/* ============================================
   VISTAS (Lista de chats / Chat activo)
============================================ */
.chat-view {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    opacity: 0;
    transform: translateX(30px);
    pointer-events: none;
    transition: var(--smartchat-transition-slow);
}

.chat-view.active {
    opacity: 1;
    transform: translateX(0);
    pointer-events: auto;
}

/* Transición entre vistas */
.chat-view.slide-left {
    transform: translateX(-30px);
}

.chat-view.slide-right {
    transform: translateX(30px);
}

/* ============================================
   HEADER - PREMIUM
============================================ */
.smartchat-header {
    height: 72px;
    background: var(--smartchat-bg);
    border-bottom: 1px solid var(--smartchat-border-light);
    display: flex;
    align-items: center;
    padding: 0 24px;
    flex-shrink: 0;
    z-index: 10;
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
}

.header-title {
    flex: 1;
    text-align: center;
    padding: 0 16px;
}

.header-title h5 {
    color: var(--smartchat-text);
    font-weight: 600;
    font-size: 18px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 4px;
}

.header-title small {
    font-size: 12px;
    color: var(--smartchat-text-secondary);
    font-weight: 400;
}

/* Botones del header */
.back-btn, .close-btn {
    width: 44px;
    height: 44px;
    border-radius: var(--smartchat-radius-full);
    background: var(--smartchat-bg);
    border: 1px solid var(--smartchat-border);
    color: var(--smartchat-text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    transition: var(--smartchat-transition);
    outline: none;
    flex-shrink: 0;
}

.back-btn:hover, .close-btn:hover {
    background: var(--smartchat-primary);
    border-color: var(--smartchat-primary);
    color: white;
    transform: translateY(-1px);
    box-shadow: 0 8px 20px rgba(136, 0, 138, 0.2);
}

.back-btn:active, .close-btn:active {
    transform: translateY(0);
}

/* ============================================
   BUSCADOR - PREMIUM
============================================ */
.search-container {
    padding: 20px 24px;
    border-bottom: 1px solid var(--smartchat-border-light);
    flex-shrink: 0;
    background: var(--smartchat-bg-soft);
}

.search-container .input-group {
    border-radius: var(--smartchat-radius-sm);
    overflow: hidden;
    border: 1px solid var(--smartchat-border);
    background: var(--smartchat-bg);
    transition: var(--smartchat-transition);
    box-shadow: var(--smartchat-shadow-inner);
}

.search-container .input-group:focus-within {
    border-color: var(--smartchat-primary);
    box-shadow: 0 0 0 3px rgba(136, 0, 138, 0.1), var(--smartchat-shadow-inner);
}

.search-container .input-group-text {
    border: none;
    background: var(--smartchat-bg);
    color: var(--smartchat-text-secondary);
    padding: 0 16px;
}

.search-container .form-control {
    border: none !important;
    background: var(--smartchat-bg) !important;
    color: var(--smartchat-text) !important;
    font-size: 14px !important;
    padding: 14px 0 !important;
    font-weight: 400 !important;
    border: 0px !important;
}

.search-container .form-control::placeholder {
    color: var(--smartchat-text-muted);
}

.search-container .form-control:focus {
    box-shadow: none;
    background: var(--smartchat-bg);
}

/* ============================================
   BOTÓN NUEVA CONVERSACIÓN - PREMIUM
============================================ */
.new-chat-container {
    padding: 16px 24px;
    flex-shrink: 0;
    background: var(--smartchat-bg-soft);
    border-bottom: 1px solid var(--smartchat-border-light);
}

.new-chat-btn {
    background: var(--smartchat-primary-gradient);
    color: white;
    border: none;
    border-radius: var(--smartchat-radius-sm);
    padding: 16px 24px;
    font-weight: 600;
    font-size: 15px;
    cursor: pointer;
    transition: var(--smartchat-transition);
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    position: relative;
    overflow: hidden;
    box-shadow: 0 8px 25px rgba(136, 0, 138, 0.2);
}

.new-chat-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: var(--smartchat-transition-slow);
}

.new-chat-btn:hover {
    background: var(--smartchat-primary-gradient-hover);
    transform: translateY(-2px);
    box-shadow: 0 12px 35px rgba(136, 0, 138, 0.3);
}

.new-chat-btn:hover::before {
    left: 100%;
}

.new-chat-btn:active {
    transform: translateY(0);
}

.new-chat-btn i {
    margin-right: 10px;
    font-size: 16px;
}

/* ============================================
   LISTA DE CONVERSACIONES - PREMIUM
============================================ */
.chats-list-container {
    flex: 1;
    overflow: hidden;
    position: relative;
    background: var(--smartchat-bg-soft);
}

.chats-list {
    height: 100%;
    overflow-y: auto;
    padding: 16px 0;
}

/* Scrollbar personalizado */
.chats-list::-webkit-scrollbar,
.messages-list::-webkit-scrollbar {
    width: 8px;
}

.chats-list::-webkit-scrollbar-track,
.messages-list::-webkit-scrollbar-track {
    background: transparent;
}

.chats-list::-webkit-scrollbar-thumb,
.messages-list::-webkit-scrollbar-thumb {
    background-color: var(--smartchat-border);
    border-radius: 4px;
    transition: var(--smartchat-transition);
}

.chats-list::-webkit-scrollbar-thumb:hover,
.messages-list::-webkit-scrollbar-thumb:hover {
    background-color: var(--smartchat-primary);
}

/* Tarjeta de chat individual */
.chat-item {
    display: flex;
    align-items: center;
    padding: 16px 24px;
    cursor: pointer;
    transition: var(--smartchat-transition);
    border-left: 4px solid transparent;
    position: relative;
    margin: 0 20px 8px 20px;
    border-radius: var(--smartchat-radius-sm);
    background: var(--smartchat-bg);
    border: 1px solid transparent;
}

.chat-item:hover {
    background: var(--smartchat-bg);
    border-color: var(--smartchat-border);
    transform: translateX(4px);
    box-shadow: 0 8px 25px rgba(136, 0, 138, 0.1);
}

.chat-item.active {
    background: var(--smartchat-bg);
    border-left-color: var(--smartchat-primary);
    border-color: var(--smartchat-border);
    box-shadow: 0 8px 25px rgba(136, 0, 138, 0.15);
}

.chat-item-content {
    flex: 1;
    min-width: 0;
    margin-right: 16px;
}

.chat-item-title {
    font-weight: 600;
    color: var(--smartchat-text);
    font-size: 15px;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
}

.chat-item-preview {
    color: var(--smartchat-text-secondary);
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.4;
    margin-top: 2px;
}

.chat-item-count {
    color: var(--smartchat-text-secondary);
    font-size: 12px;
    margin-top: 1px;
    font-weight: 600;
}

.chat-item-time {
    color: var(--smartchat-text-muted);
    font-size: 12px;
    white-space: nowrap;
    flex-shrink: 0;
    font-weight: 400;
}

/* ============================================
   ESTADOS VACÍOS - PREMIUM
============================================ */
.empty-state {
    position: absolute;
    top: 40%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    padding: 0 32px;
    width: 100%;
}

.empty-state-icon {
    font-size: 56px;
    color: var(--smartchat-border);
    margin-bottom: 20px;
    opacity: 0.5;
}

.empty-state h5 {
    color: var(--smartchat-text);
    font-weight: 600;
    margin-bottom: 12px;
    font-size: 18px;
}

.empty-state p {
    font-size: 14px;
    color: var(--smartchat-text-secondary);
    margin-bottom: 0;
    line-height: 1.5;
}

/* ============================================
   ÁREA DE MENSAJES - PREMIUM
============================================ */
.messages-container {
    flex: 1;
    overflow: hidden;
    position: relative;
    background: var(--smartchat-bg-chat);
}

.messages-list {
    height: 100%;
    overflow-y: auto;
    padding: 24px 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* ============================================
   BURBUJAS DE MENSAJE - PREMIUM
============================================ */
.message {
    max-width: 82%;
    animation: messageAppear 0.4s cubic-bezier(0.4, 0, 0.2, 1) forwards;
    opacity: 0;
    transform: translateY(15px);
}

@keyframes messageAppear {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-user {
    align-self: flex-end;
}

.message-system {
    align-self: flex-start;
}

.message-bubble {
    padding: 16px 20px;
    border-radius: var(--smartchat-radius-md);
    position: relative;
    font-size: 15px;
    line-height: 1.5;
    word-wrap: break-word;
    font-weight: 400;
}

.message-user .message-bubble {
    background: var(--smartchat-primary-gradient);
    color: white;
    border-bottom-right-radius: 8px;
    box-shadow: 0 8px 25px rgba(136, 0, 138, 0.2);
}

.message-system .message-bubble {
    background: var(--smartchat-bg);
    color: var(--smartchat-text);
    border-bottom-left-radius: 8px;
    border: 1px solid var(--smartchat-border-light);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.04);
}

.message-time {
    font-size: 12px;
    color: var(--smartchat-text-secondary);
    margin-top: 8px;
    text-align: right;
    font-weight: 400;
}

.message-user .message-time {
    color: rgba(255, 255, 255, 0.85);
}

/* Enlaces en mensajes */
.message-bubble a {
    color: var(--smartchat-primary);
    text-decoration: none;
    font-weight: 500;
    border-bottom: 1px solid transparent;
    transition: var(--smartchat-transition);
}

.message-bubble a:hover {
    border-bottom-color: var(--smartchat-primary);
}

.message-user .message-bubble a {
    color: white;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.message-bubble h1 {
    font-size: 24px;
    line-height: 34px;
    text-transform: uppercase;
    margin-bottom: 15px;
}

.message-bubble h2 {
    font-size: 22px;
    line-height: 32px;
    margin-bottom: 15px;
}

.message-bubble h3 {
    font-size: 20px;
    line-height: 30px;
    margin-bottom: 15px;
}

.message-bubble h4 {
    font-size: 18px;
    line-height: 28px;
    margin-bottom: 15px;
}

.message-bubble h5 {
    font-size: 16px;
    line-height: 26px;
    margin-bottom: 15px;
}

.message-bubble h6 {
    font-size: 14px;
    line-height: 24px;
    margin-bottom: 15px;
}

.message-bubble p, .message-bubble ul {
    margin-bottom: 22px;
}

/* ============================================
   ANIMACIÓN "ESCRIBIENDO" - PREMIUM
============================================ */
.typing-indicator {
    padding: 0 24px 24px;
    display: flex;
    align-items: center;
    animation: typingAppear 0.3s cubic-bezier(0.4, 0, 0.2, 1) forwards;
    background: #f8f5ff;
}

@keyframes typingAppear {
    from {
        opacity: 0;
        transform: translateY(15px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.typing-bubble {
    background: var(--smartchat-bg);
    border: 1px solid var(--smartchat-border-light);
    border-radius: var(--smartchat-radius-md);
    padding: 16px 20px;
    margin-right: 16px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.04);
}

.dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: var(--smartchat-radius-full);
    background: var(--smartchat-primary);
    margin: 0 3px;
    opacity: 0.7;
}

.dot:nth-child(1) {
    animation: dotPulse 1.6s infinite;
}

.dot:nth-child(2) {
    animation: dotPulse 1.6s infinite 0.2s;
}

.dot:nth-child(3) {
    animation: dotPulse 1.6s infinite 0.4s;
}

@keyframes dotPulse {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.6;
    }
    30% {
        transform: translateY(-5px);
        opacity: 1;
    }
}

/* ============================================
   ÁREA DE ESCRITURA - PREMIUM
============================================ */
.input-container {
    border-top: 1px solid var(--smartchat-border-light);
    padding: 24px;
    background: var(--smartchat-bg);
    flex-shrink: 0;
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    margin-bottom: 12px;
    gap: 16px;
}

.message-input {
    flex: 1;
    border: 1px solid var(--smartchat-border);
    border-radius: var(--smartchat-radius-sm);
    background: var(--smartchat-bg-input);
    color: var(--smartchat-text);
    font-size: 15px;
    padding: 16px 20px;
    resize: none;
    min-height: 52px;
    max-height: 140px;
    line-height: 1.5;
    transition: var(--smartchat-transition);
    font-weight: 400;
    box-shadow: var(--smartchat-shadow-inner);
}

.message-input::placeholder {
    color: var(--smartchat-text-muted);
}

.message-input:focus {
    outline: none;
    border-color: var(--smartchat-primary);
    background: var(--smartchat-bg);
    box-shadow: 0 0 0 3px rgba(136, 0, 138, 0.1), var(--smartchat-shadow-inner);
}

.send-btn {
    width: 52px;
    height: 52px;
    border-radius: var(--smartchat-radius-full);
    background: var(--smartchat-primary-gradient);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    transition: var(--smartchat-transition);
    flex-shrink: 0;
    outline: none;
    position: relative;
    overflow: hidden;
}

.send-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: var(--smartchat-transition-slow);
}

.send-btn:hover:not(:disabled) {
    background: var(--smartchat-primary-gradient-hover);
    transform: translateY(-2px);
    box-shadow: 0 12px 35px rgba(136, 0, 138, 0.3);
}

.send-btn:hover:not(:disabled)::before {
    left: 100%;
}

.send-btn:active:not(:disabled) {
    transform: translateY(0);
}

.send-btn:disabled {
    background: var(--smartchat-border);
    cursor: not-allowed;
    opacity: 0.6;
    transform: none !important;
}

.input-hint {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    padding: 0 4px;
    color: var(--smartchat-text-muted);
    font-weight: 400;
}

/* ============================================
   LOADER GLOBAL - PREMIUM
============================================ */
.global-loader {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    backdrop-filter: blur(5px);
}

.loader-spinner {
    width: 56px;
    height: 56px;
    border: 3px solid var(--smartchat-border);
    border-top-color: var(--smartchat-primary);
    border-radius: var(--smartchat-radius-full);
    animation: spin 1s ease-in-out infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ============================================
   UTILIDADES
============================================ */
.d-none {
    display: none !important;
}

.text-muted {
    color: var(--smartchat-text-secondary) !important;
}

/* Responsive adicional */
@media (max-width: 576px) {
    .smartchat-container {
        width: 100%;
        right: 0;
    }
    
    .message {
        max-width: 90%;
    }
    
    .input-hint {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }
    
    .input-hint span:last-child {
        margin-left: 0;
        margin-top: 4px;
    }
    
    .smartchat-header,
    .search-container,
    .new-chat-container,
    .input-container {
        padding-left: 20px;
        padding-right: 20px;
    }
    
    .chat-item {
        padding: 16px 20px;
        margin: 0 4px;
    }
    
    .messages-list {
        padding: 20px;
    }
}

/* ============================================
   EFECTOS ESPECIALES ADICIONALES
============================================ */
@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOutLeft {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(-100%);
        opacity: 0;
    }
}

/* Efecto de brillo sutil en hover */
.chat-item:hover .chat-item-title {
    color: var(--smartchat-primary);
}

.chat-item.active .chat-item-title {
    color: var(--smartchat-primary);
    font-weight: 700;
}

/* Mejoras de foco para accesibilidad */
.back-btn:focus,
.close-btn:focus,
.new-chat-btn:focus,
.send-btn:focus,
.message-input:focus {
    outline: 2px solid var(--smartchat-primary);
    outline-offset: 2px;
}