/**
 * Next RV AI Chat Widget Styles
 * Version: 1.0.0
 */

/* CSS Variables - Customizable via admin */
:root {
    --nextrv-primary: #1a1a1a;
    --nextrv-accent: #e63946;
    --nextrv-bg: #ffffff;
    --nextrv-text: #333333;
    --nextrv-light-bg: #f8f9fa;
    --nextrv-border: #e0e0e0;
    --nextrv-shadow: rgba(0, 0, 0, 0.15);
    --nextrv-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
}

/* ============================================
   CHAT WIDGET CONTAINER
   ============================================ */
#nextrv-chat-widget {
    position: fixed;
    z-index: 999999;
    font-family: var(--nextrv-font);
    font-size: 14px;
    line-height: 1.5;
    box-sizing: border-box;
}

#nextrv-chat-widget *,
#nextrv-chat-widget *::before,
#nextrv-chat-widget *::after {
    box-sizing: border-box;
}

/* Position variants */
#nextrv-chat-widget.position-bottom-right {
    bottom: 24px;
    right: 24px;
}

#nextrv-chat-widget.position-bottom-left {
    bottom: 24px;
    left: 24px;
}

/* ============================================
   TOGGLE BUTTON
   ============================================ */
.nextrv-chat-toggle {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--nextrv-primary) 0%, #2d2d2d 100%);
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 20px var(--nextrv-shadow), 0 0 0 0 rgba(230, 57, 70, 0);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.nextrv-chat-toggle::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, var(--nextrv-accent) 0%, #ff6b6b 100%);
    opacity: 0;
    transition: opacity 0.3s ease;
    border-radius: 50%;
}

.nextrv-chat-toggle:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 28px var(--nextrv-shadow);
}

.nextrv-chat-toggle:hover::before {
    opacity: 1;
}

.nextrv-chat-toggle:active {
    transform: scale(0.95);
}

.nextrv-chat-toggle svg {
    width: 28px;
    height: 28px;
    fill: white;
    position: relative;
    z-index: 1;
    transition: transform 0.3s ease;
}

.nextrv-chat-toggle:hover svg {
    transform: scale(1.1);
}

/* Notification badge */
.nextrv-chat-toggle .notification-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 12px;
    height: 12px;
    background: var(--nextrv-accent);
    border-radius: 50%;
    border: 2px solid white;
    animation: pulse-badge 2s infinite;
    display: none;
}

.nextrv-chat-toggle.has-notification .notification-badge {
    display: block;
}

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

/* ============================================
   CHAT WINDOW
   ============================================ */
.nextrv-chat-window {
    position: absolute;
    bottom: 80px;
    width: 400px;
    max-width: calc(100vw - 48px);
    height: 550px;
    max-height: calc(100vh - 120px);
    background: var(--nextrv-bg);
    border-radius: 20px;
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.2), 0 0 0 1px rgba(0, 0, 0, 0.05);
    display: none;
    flex-direction: column;
    overflow: hidden;
    transform: translateY(20px) scale(0.95);
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Position adjustments */
.position-bottom-right .nextrv-chat-window {
    right: 0;
}

.position-bottom-left .nextrv-chat-window {
    left: 0;
}

.nextrv-chat-window.open {
    display: flex;
    transform: translateY(0) scale(1);
    opacity: 1;
}

/* ============================================
   HEADER
   ============================================ */
.nextrv-chat-header {
    background: linear-gradient(135deg, var(--nextrv-primary) 0%, #2d2d2d 100%);
    color: white;
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 14px;
    flex-shrink: 0;
}

.nextrv-chat-header-logo {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    background: white;
    padding: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.nextrv-chat-header-logo img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.nextrv-chat-header-info {
    flex: 1;
}

.nextrv-chat-header-title {
    margin: 0;
    font-size: 17px;
    font-weight: 600;
    letter-spacing: -0.2px;
}

.nextrv-chat-header-status {
    margin: 3px 0 0;
    font-size: 13px;
    opacity: 0.85;
    display: flex;
    align-items: center;
    gap: 6px;
}

.nextrv-chat-header-status::before {
    content: '';
    width: 8px;
    height: 8px;
    background: #4ade80;
    border-radius: 50%;
    animation: pulse-status 2s infinite;
}

@keyframes pulse-status {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.nextrv-chat-close {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    font-size: 20px;
}

.nextrv-chat-close:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: rotate(90deg);
}

/* ============================================
   MESSAGES AREA
   ============================================ */
.nextrv-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: linear-gradient(180deg, #fafafa 0%, white 100%);
    scroll-behavior: smooth;
}

/* Custom scrollbar */
.nextrv-chat-messages::-webkit-scrollbar {
    width: 6px;
}

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

.nextrv-chat-messages::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 3px;
}

.nextrv-chat-messages::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
}

/* ============================================
   MESSAGE BUBBLES
   ============================================ */
.nextrv-message {
    max-width: 85%;
    padding: 14px 18px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.5;
    animation: message-appear 0.3s ease;
    word-wrap: break-word;
}

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

.nextrv-message.bot {
    background: white;
    color: var(--nextrv-text);
    align-self: flex-start;
    border-bottom-left-radius: 6px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    border: 1px solid var(--nextrv-border);
    white-space: pre-line;
    line-height: 1.6;
}

.nextrv-message.bot strong {
    font-weight: 600;
    color: #1a1a1a;
}

.nextrv-message.user {
    background: linear-gradient(135deg, var(--nextrv-primary) 0%, #2d2d2d 100%);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 6px;
    box-shadow: 0 2px 12px rgba(26, 26, 26, 0.3);
}

/* Message with avatar */
.nextrv-message-wrapper {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

.nextrv-message-wrapper.bot {
    flex-direction: row;
}

.nextrv-message-wrapper.user {
    flex-direction: row-reverse;
}

.nextrv-message-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--nextrv-light-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.nextrv-message-avatar img {
    width: 20px;
    height: 20px;
    border-radius: 50%;
}

/* Links in messages */
.nextrv-message a {
    color: var(--nextrv-accent);
    text-decoration: underline;
}

.nextrv-message.user a {
    color: #fca5a5;
}

/* ============================================
   TYPING INDICATOR
   ============================================ */
.nextrv-message.typing {
    display: flex;
    gap: 5px;
    padding: 18px 22px;
    background: white;
    border: 1px solid var(--nextrv-border);
}

.nextrv-message.typing .dot {
    width: 8px;
    height: 8px;
    background: #9ca3af;
    border-radius: 50%;
    animation: typing-bounce 1.4s infinite ease-in-out;
}

.nextrv-message.typing .dot:nth-child(1) { animation-delay: 0s; }
.nextrv-message.typing .dot:nth-child(2) { animation-delay: 0.2s; }
.nextrv-message.typing .dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing-bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-8px); }
}

/* ============================================
   QUICK REPLIES / SUGGESTIONS
   ============================================ */
.nextrv-quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 0 20px 16px;
}

.nextrv-quick-reply {
    padding: 10px 16px;
    background: white;
    border: 1px solid var(--nextrv-border);
    border-radius: 20px;
    font-size: 13px;
    color: var(--nextrv-text);
    cursor: pointer;
    transition: all 0.2s ease;
}

.nextrv-quick-reply:hover {
    background: var(--nextrv-primary);
    color: white;
    border-color: var(--nextrv-primary);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(26, 26, 26, 0.2);
}

/* ============================================
   INPUT AREA
   ============================================ */
.nextrv-chat-input-area {
    padding: 16px 20px;
    background: white;
    border-top: 1px solid var(--nextrv-border);
    flex-shrink: 0;
}

.nextrv-chat-input-wrapper {
    display: flex;
    gap: 10px;
    align-items: center;
}

.nextrv-chat-input {
    flex: 1;
    padding: 14px 20px;
    border: 2px solid var(--nextrv-border);
    border-radius: 28px;
    font-size: 14px;
    font-family: var(--nextrv-font);
    outline: none;
    transition: all 0.2s ease;
    background: var(--nextrv-light-bg);
}

.nextrv-chat-input:focus {
    border-color: var(--nextrv-primary);
    background: white;
    box-shadow: 0 0 0 4px rgba(26, 26, 26, 0.08);
}

.nextrv-chat-input::placeholder {
    color: #9ca3af;
}

.nextrv-chat-send {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--nextrv-primary) 0%, #2d2d2d 100%);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.nextrv-chat-send:hover:not(:disabled) {
    transform: scale(1.08);
    box-shadow: 0 4px 16px rgba(26, 26, 26, 0.3);
}

.nextrv-chat-send:active:not(:disabled) {
    transform: scale(0.95);
}

.nextrv-chat-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.nextrv-chat-send svg {
    width: 22px;
    height: 22px;
    fill: white;
    transform: translateX(2px);
}

/* ============================================
   FOOTER / POWERED BY
   ============================================ */
.nextrv-chat-footer {
    padding: 10px 20px;
    background: var(--nextrv-light-bg);
    text-align: center;
    font-size: 11px;
    color: #9ca3af;
    border-top: 1px solid var(--nextrv-border);
}

.nextrv-chat-footer a {
    color: var(--nextrv-text);
    text-decoration: none;
    font-weight: 500;
}

.nextrv-chat-footer a:hover {
    color: var(--nextrv-accent);
}

/* ============================================
   ERROR STATE
   ============================================ */
.nextrv-message.error {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #dc2626;
}

/* ============================================
   MOBILE RESPONSIVE
   ============================================ */
@media (max-width: 480px) {
    #nextrv-chat-widget {
        bottom: 16px;
        right: 16px;
    }
    
    #nextrv-chat-widget.position-bottom-left {
        left: 16px;
        right: auto;
    }
    
    .nextrv-chat-window {
        width: calc(100vw - 32px);
        height: calc(100vh - 100px);
        max-height: calc(100vh - 100px);
        bottom: 72px;
        border-radius: 16px;
    }
    
    .nextrv-chat-toggle {
        width: 56px;
        height: 56px;
    }
    
    .nextrv-chat-toggle svg {
        width: 24px;
        height: 24px;
    }
    
    .nextrv-chat-header {
        padding: 16px;
    }
    
    .nextrv-chat-header-logo {
        width: 40px;
        height: 40px;
    }
    
    .nextrv-message {
        max-width: 90%;
        padding: 12px 16px;
        font-size: 14px;
    }
    
    .nextrv-chat-input {
        padding: 12px 16px;
    }
    
    .nextrv-chat-send {
        width: 44px;
        height: 44px;
    }
}

/* ============================================
   PRINT - HIDE WIDGET
   ============================================ */
@media print {
    #nextrv-chat-widget {
        display: none !important;
    }
}

/* ============================================
   REDUCED MOTION
   ============================================ */
@media (prefers-reduced-motion: reduce) {
    .nextrv-chat-toggle,
    .nextrv-chat-window,
    .nextrv-message,
    .nextrv-quick-reply,
    .nextrv-chat-send {
        transition: none;
        animation: none;
    }
    
    .nextrv-message.typing .dot {
        animation: none;
        opacity: 0.5;
    }
}
