/**
 * SJC Chat Widget — Estilos
 * 
 * Widget de chat flotante para SJ Contadores.
 * Usa variables CSS para fácil personalización del color principal.
 */

/* ============================================
   Variables CSS (se sobreescriben por JS con el color del admin)
   ============================================ */
:root {
    --sjc-primary: #1a365d;
    --sjc-primary-light: #2d5aa0;
    --sjc-primary-dark: #0f2440;
    --sjc-bg-widget: #ffffff;
    --sjc-bg-messages: #f7f8fa;
    --sjc-text-primary: #1a202c;
    --sjc-text-secondary: #718096;
    --sjc-text-light: #a0aec0;
    --sjc-border: #e2e8f0;
    --sjc-bot-bubble: #ffffff;
    --sjc-user-bubble: var(--sjc-primary);
    --sjc-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    --sjc-shadow-bubble: 0 4px 20px rgba(26, 54, 93, 0.3);
    --sjc-radius: 16px;
    --sjc-radius-bubble: 28px;
    --sjc-widget-width: 380px;
    --sjc-widget-height: 560px;
    --sjc-z-index: 999999;
    --sjc-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ============================================
   Reset y base
   ============================================ */
.sjc-chat-widget,
.sjc-chat-widget * {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ============================================
   Container del widget
   ============================================ */
.sjc-chat-widget {
    position: fixed;
    bottom: 20px;
    z-index: var(--sjc-z-index);
}

.sjc-position-right {
    right: 20px;
}

.sjc-position-left {
    left: 20px;
}

/* ============================================
   Burbuja flotante
   ============================================ */
.sjc-chat-bubble {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--sjc-primary) 0%, var(--sjc-primary-light) 100%);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--sjc-shadow-bubble);
    transition: var(--sjc-transition);
    position: relative;
    overflow: hidden;
}

.sjc-chat-bubble::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sjc-chat-bubble:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 28px rgba(26, 54, 93, 0.45);
}

.sjc-chat-bubble:hover::before {
    opacity: 1;
}

.sjc-chat-bubble:active {
    transform: scale(0.95);
}

.sjc-bubble-icon {
    width: 28px;
    height: 28px;
    color: white;
    transition: var(--sjc-transition);
    position: absolute;
}

.sjc-icon-chat {
    opacity: 1;
    transform: scale(1) rotate(0deg);
}

.sjc-icon-close {
    opacity: 0;
    transform: scale(0.5) rotate(-90deg);
}

/* Estado abierto: cambiar iconos */
.sjc-chat-widget.sjc-open .sjc-icon-chat {
    opacity: 0;
    transform: scale(0.5) rotate(90deg);
}

.sjc-chat-widget.sjc-open .sjc-icon-close {
    opacity: 1;
    transform: scale(1) rotate(0deg);
}

/* Animación de pulso inicial */
@keyframes sjc-pulse {
    0% { box-shadow: 0 0 0 0 rgba(26, 54, 93, 0.5); }
    70% { box-shadow: 0 0 0 15px rgba(26, 54, 93, 0); }
    100% { box-shadow: 0 0 0 0 rgba(26, 54, 93, 0); }
}

.sjc-chat-bubble.sjc-pulse {
    animation: sjc-pulse 2s ease-out 3;
}

/* ============================================
   Ventana de chat
   ============================================ */
.sjc-chat-window {
    position: absolute;
    bottom: 75px;
    width: var(--sjc-widget-width);
    height: var(--sjc-widget-height);
    max-height: calc(100vh - 120px);
    background: var(--sjc-bg-widget);
    border-radius: var(--sjc-radius);
    box-shadow: var(--sjc-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
    transform-origin: bottom right;
    transition: var(--sjc-transition);
}

.sjc-position-right .sjc-chat-window {
    right: 0;
    transform-origin: bottom right;
}

.sjc-position-left .sjc-chat-window {
    left: 0;
    transform-origin: bottom left;
}

.sjc-chat-widget.sjc-open .sjc-chat-window {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* ============================================
   Header del chat
   ============================================ */
.sjc-chat-header {
    background: linear-gradient(135deg, var(--sjc-primary) 0%, var(--sjc-primary-light) 100%);
    padding: 16px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.sjc-chat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.sjc-chat-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.sjc-chat-avatar svg {
    width: 24px;
    height: 24px;
    color: white;
}

.sjc-chat-header-name {
    display: block;
    color: white;
    font-size: 15px;
    font-weight: 600;
    line-height: 1.2;
}

.sjc-chat-header-status {
    display: block;
    color: rgba(255, 255, 255, 0.75);
    font-size: 12px;
    line-height: 1.2;
    margin-top: 2px;
}

.sjc-chat-header-status::before {
    content: '';
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #48bb78;
    margin-right: 5px;
    vertical-align: middle;
}

.sjc-chat-minimize {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.15);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
}

.sjc-chat-minimize:hover {
    background: rgba(255, 255, 255, 0.25);
}

.sjc-chat-minimize svg {
    width: 20px;
    height: 20px;
    color: white;
}

/* ============================================
   Área de mensajes
   ============================================ */
.sjc-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: var(--sjc-bg-messages);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Scrollbar personalizado */
.sjc-chat-messages::-webkit-scrollbar {
    width: 5px;
}

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

.sjc-chat-messages::-webkit-scrollbar-thumb {
    background: var(--sjc-border);
    border-radius: 3px;
}

.sjc-chat-messages::-webkit-scrollbar-thumb:hover {
    background: var(--sjc-text-light);
}

/* ============================================
   Burbujas de mensajes
   ============================================ */
.sjc-message {
    display: flex;
    gap: 8px;
    max-width: 85%;
    animation: sjc-fadeIn 0.3s ease;
}

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

/* Mensaje del bot */
.sjc-message-bot {
    align-self: flex-start;
}

.sjc-message-bot .sjc-message-bubble {
    background: var(--sjc-bot-bubble);
    color: var(--sjc-text-primary);
    border-radius: 4px 16px 16px 16px;
    border: 1px solid var(--sjc-border);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

/* Mensaje del usuario */
.sjc-message-user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.sjc-message-user .sjc-message-bubble {
    background: linear-gradient(135deg, var(--sjc-primary) 0%, var(--sjc-primary-light) 100%);
    color: white;
    border-radius: 16px 4px 16px 16px;
}

.sjc-message-bubble {
    padding: 10px 14px;
    font-size: 14px;
    line-height: 1.5;
    word-break: break-word;
}

.sjc-message-time {
    font-size: 11px;
    color: var(--sjc-text-light);
    margin-top: 4px;
    padding: 0 4px;
}

.sjc-message-user .sjc-message-time {
    text-align: right;
}

/* ============================================
   Indicador "escribiendo..."
   ============================================ */
.sjc-typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px 16px;
    background: var(--sjc-bot-bubble);
    border-radius: 4px 16px 16px 16px;
    border: 1px solid var(--sjc-border);
    align-self: flex-start;
    max-width: 70px;
}

.sjc-typing-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--sjc-text-light);
    animation: sjc-typing 1.4s ease-in-out infinite;
}

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

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

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

/* ============================================
   Área de input
   ============================================ */
.sjc-chat-input-area {
    border-top: 1px solid var(--sjc-border);
    background: var(--sjc-bg-widget);
    flex-shrink: 0;
}

.sjc-chat-form {
    display: flex;
    align-items: center;
    padding: 12px 14px;
    gap: 10px;
}

.sjc-chat-input {
    flex: 1;
    border: 1.5px solid var(--sjc-border);
    border-radius: 24px;
    padding: 10px 16px;
    font-size: 14px;
    color: var(--sjc-text-primary);
    background: var(--sjc-bg-messages);
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.sjc-chat-input:focus {
    border-color: var(--sjc-primary-light);
    box-shadow: 0 0 0 3px rgba(45, 90, 160, 0.1);
}

.sjc-chat-input::placeholder {
    color: var(--sjc-text-light);
}

.sjc-chat-send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--sjc-primary) 0%, var(--sjc-primary-light) 100%);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: var(--sjc-transition);
}

.sjc-chat-send:hover {
    transform: scale(1.05);
    box-shadow: 0 2px 10px rgba(26, 54, 93, 0.3);
}

.sjc-chat-send:active {
    transform: scale(0.95);
}

.sjc-chat-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.sjc-chat-send svg {
    width: 18px;
    height: 18px;
    color: white;
}

.sjc-chat-footer {
    text-align: center;
    padding: 6px 0 10px;
}

.sjc-powered-by {
    font-size: 11px;
    color: var(--sjc-text-light);
    text-decoration: none;
    transition: color 0.2s ease;
}

.sjc-powered-by:hover {
    color: var(--sjc-primary);
}

/* ============================================
   Responsive — Móvil
   ============================================ */
@media (max-width: 480px) {
    .sjc-chat-widget {
        bottom: 12px;
    }

    .sjc-position-right {
        right: 12px;
    }

    .sjc-position-left {
        left: 12px;
    }

    .sjc-chat-window {
        width: calc(100vw - 24px);
        height: calc(100vh - 100px);
        max-height: calc(100vh - 100px);
        bottom: 70px;
    }

    .sjc-position-right .sjc-chat-window {
        right: -8px;
    }

    .sjc-position-left .sjc-chat-window {
        left: -8px;
    }

    .sjc-chat-bubble {
        width: 54px;
        height: 54px;
    }

    .sjc-bubble-icon {
        width: 24px;
        height: 24px;
    }
}

/* ============================================
   Animación de entrada del widget
   ============================================ */
@keyframes sjc-slideUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.sjc-chat-widget {
    animation: sjc-slideUp 0.5s ease 1s both;
}

/* ============================================
   Aviso de privacidad
   ============================================ */
.sjc-privacy-notice {
    font-size: 11px;
    color: var(--sjc-text-light);
    text-align: center;
    padding: 8px 16px;
    background: rgba(247, 248, 250, 0.8);
    border-bottom: 1px solid var(--sjc-border);
}

.sjc-privacy-notice a {
    color: var(--sjc-primary-light);
    text-decoration: underline;
}
