/**
 * RIOS Chat Widget FTS5 V2 - Responsive Styles
 * Optimized for Desktop, Tablet, and Mobile devices
 */

/* ========================================
   ROOT VARIABLES
   ======================================== */
:root {
    --rios-primary-color: #8B5CF6;
    --rios-primary-dark: #7C3AED;
    --rios-bg-light: #FFFFFF;
    --rios-bg-dark: #F9FAFB;
    --rios-text-primary: #111827;
    --rios-text-secondary: #6B7280;
    --rios-border-color: #E5E7EB;
    --rios-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
    --rios-shadow-hover: 0 15px 40px rgba(0, 0, 0, 0.2);
    --rios-border-radius: 16px;
    --rios-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Theme variations */
.rios-theme-blue {
    --rios-primary-color: #3B82F6;
    --rios-primary-dark: #2563EB;
}

.rios-theme-green {
    --rios-primary-color: #10B981;
    --rios-primary-dark: #059669;
}

.rios-theme-red {
    --rios-primary-color: #EF4444;
    --rios-primary-dark: #DC2626;
}

.rios-theme-dark {
    --rios-primary-color: #1F2937;
    --rios-primary-dark: #111827;
    --rios-bg-light: #1F2937;
    --rios-bg-dark: #111827;
    --rios-text-primary: #F9FAFB;
    --rios-text-secondary: #D1D5DB;
    --rios-border-color: #374151;
}

/* ========================================
   FLOATING BUTTON (ALL DEVICES)
   ======================================== */
#rios-chat-button {
    position: fixed;
    z-index: 999998;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--rios-primary-color);
    border: none;
    box-shadow: var(--rios-shadow);
    cursor: pointer;
    transition: var(--rios-transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

#rios-chat-button:hover {
    transform: scale(1.05);
    box-shadow: var(--rios-shadow-hover);
    background: var(--rios-primary-dark);
}

#rios-chat-button svg {
    width: 28px;
    height: 28px;
    fill: white;
}

/* Position variants */
.rios-position-bottom-right #rios-chat-button {
    bottom: 20px;
    right: 20px;
}

.rios-position-bottom-left #rios-chat-button {
    bottom: 20px;
    left: 20px;
}

/* Badge for unread messages */
#rios-chat-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #EF4444;
    color: white;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.4);
}

/* ========================================
   CHAT CONTAINER - DESKTOP (> 1024px)
   ======================================== */
#rios-chat-container {
    position: fixed;
    z-index: 999999;
    width: 400px;
    height: 600px;
    max-height: 80vh;
    background: var(--rios-bg-light);
    border-radius: var(--rios-border-radius);
    box-shadow: var(--rios-shadow);
    display: none;
    flex-direction: column;
    overflow: hidden;
    transition: var(--rios-transition);
}

#rios-chat-container.open {
    display: flex;
}

.rios-position-bottom-right #rios-chat-container {
    bottom: 90px;
    right: 20px;
}

.rios-position-bottom-left #rios-chat-container {
    bottom: 90px;
    left: 20px;
}

/* ========================================
   CHAT HEADER
   ======================================== */
#rios-chat-header {
    background: linear-gradient(135deg, var(--rios-primary-color), var(--rios-primary-dark));
    color: white;
    padding: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

#rios-chat-title {
    display: flex;
    align-items: center;
    gap: 12px;
}

#rios-chat-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
}

#rios-chat-avatar svg {
    width: 24px;
    height: 24px;
    fill: white;
}

#rios-chat-info h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

#rios-chat-info p {
    margin: 4px 0 0 0;
    font-size: 12px;
    opacity: 0.9;
}

#rios-chat-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    border-radius: 8px;
    width: 32px;
    height: 32px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--rios-transition);
}

#rios-chat-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

#rios-chat-close svg {
    width: 16px;
    height: 16px;
    fill: white;
}

/* ========================================
   CHAT MESSAGES AREA
   ======================================== */
#rios-chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background: var(--rios-bg-dark);
    scroll-behavior: smooth;
}

/* Custom scrollbar */
#rios-chat-messages::-webkit-scrollbar {
    width: 6px;
}

#rios-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

#rios-chat-messages::-webkit-scrollbar-thumb {
    background: var(--rios-border-color);
    border-radius: 3px;
}

#rios-chat-messages::-webkit-scrollbar-thumb:hover {
    background: var(--rios-text-secondary);
}

/* Message bubbles */
.rios-message {
    margin-bottom: 16px;
    animation: rios-message-fade-in 0.3s ease;
}

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

.rios-message-user {
    display: flex;
    justify-content: flex-end;
}

.rios-message-user .rios-message-bubble {
    background: var(--rios-primary-color);
    color: white;
    border-radius: 18px 18px 4px 18px;
    padding: 12px 16px;
    max-width: 75%;
    word-wrap: break-word;
}

.rios-message-assistant {
    display: flex;
    justify-content: flex-start;
}

.rios-message-assistant .rios-message-bubble {
    background: var(--rios-bg-light);
    color: var(--rios-text-primary);
    border-radius: 18px 18px 18px 4px;
    padding: 12px 16px;
    max-width: 85%;
    word-wrap: break-word;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* Artwork cards */
.rios-artwork-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    margin-top: 12px;
}

.rios-artwork-card {
    background: var(--rios-bg-light);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: var(--rios-transition);
    cursor: pointer;
}

.rios-artwork-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.rios-artwork-image {
    width: 100%;
    height: 200px;
    object-fit: cover;
    background: var(--rios-bg-dark);
}

.rios-artwork-info {
    padding: 12px;
}

.rios-artwork-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--rios-text-primary);
    margin: 0 0 8px 0;
    line-height: 1.4;
}

.rios-artwork-details {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 8px;
}

.rios-artwork-price {
    font-size: 16px;
    font-weight: 700;
    color: var(--rios-primary-color);
}

.rios-artwork-stock {
    font-size: 12px;
    padding: 4px 8px;
    border-radius: 6px;
    background: #10B981;
    color: white;
}

.rios-artwork-stock.out-of-stock {
    background: #EF4444;
}

/* Typing indicator */
.rios-typing-indicator {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background: var(--rios-bg-light);
    border-radius: 18px;
    width: fit-content;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.rios-typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--rios-text-secondary);
    animation: rios-typing 1.4s infinite;
}

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

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

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

/* ========================================
   CHAT INPUT AREA
   ======================================== */
#rios-chat-input-container {
    padding: 16px;
    background: var(--rios-bg-light);
    border-top: 1px solid var(--rios-border-color);
    flex-shrink: 0;
}

#rios-chat-input-wrapper {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

#rios-chat-input {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid var(--rios-border-color);
    border-radius: 24px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    min-height: 40px;
    max-height: 260px;
    transition: var(--rios-transition);
}

#rios-chat-input:focus {
    outline: none;
    border-color: var(--rios-primary-color);
}

#rios-chat-send {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--rios-primary-color);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--rios-transition);
    flex-shrink: 0;
}

#rios-chat-send:hover:not(:disabled) {
    background: var(--rios-primary-dark);
    transform: scale(1.05);
}

#rios-chat-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#rios-chat-send svg {
    width: 20px;
    height: 20px;
    fill: white;
}

/* ========================================
   TABLET STYLES (768px - 1024px)
   ======================================== */
@media (max-width: 1024px) and (min-width: 768px) {
    #rios-chat-container {
        width: 380px;
        height: 550px;
        max-height: 70vh;
    }

    #rios-chat-button {
        width: 56px;
        height: 56px;
    }

    .rios-position-bottom-right #rios-chat-container {
        right: 16px;
        bottom: 80px;
    }

    .rios-position-bottom-left #rios-chat-container {
        left: 16px;
        bottom: 80px;
    }

    .rios-artwork-image {
        height: 180px;
    }
}

/* ========================================
   MOBILE STYLES (< 768px)
   ======================================== */
@media (max-width: 767px) {
    /* Full-screen chat on mobile */
    #rios-chat-container {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        max-height: 100vh;
        border-radius: 0;
    }

    #rios-chat-container.open {
        display: flex;
    }

    /* Mobile button */
    #rios-chat-button {
        width: 56px;
        height: 56px;
        bottom: 16px;
        right: 16px;
    }

    .rios-position-bottom-left #rios-chat-button {
        left: 16px;
        right: auto;
    }

    /* Mobile header */
    #rios-chat-header {
        padding: 16px;
    }

    #rios-chat-avatar {
        width: 36px;
        height: 36px;
    }

    #rios-chat-info h3 {
        font-size: 15px;
    }

    #rios-chat-info p {
        font-size: 11px;
    }

    /* Mobile messages */
    #rios-chat-messages {
        padding: 16px 12px;
    }

    .rios-message-user .rios-message-bubble,
    .rios-message-assistant .rios-message-bubble {
        max-width: 85%;
        font-size: 14px;
    }

    /* Mobile artwork cards */
    .rios-artwork-image {
        height: 160px;
    }

    .rios-artwork-info {
        padding: 10px;
    }

    .rios-artwork-title {
        font-size: 13px;
    }

    .rios-artwork-price {
        font-size: 15px;
    }

    /* Mobile input */
    #rios-chat-input-container {
        padding: 12px;
    }

    #rios-chat-input {
        padding: 10px 14px;
        font-size: 16px; /* Prevent zoom on iOS */
    }

    #rios-chat-send {
        width: 40px;
        height: 40px;
    }
}

/* ========================================
   SMALL MOBILE (< 375px)
   ======================================== */
@media (max-width: 374px) {
    #rios-chat-header {
        padding: 12px;
    }

    #rios-chat-avatar {
        width: 32px;
        height: 32px;
    }

    #rios-chat-info h3 {
        font-size: 14px;
    }

    #rios-chat-messages {
        padding: 12px 8px;
    }

    .rios-artwork-image {
        height: 140px;
    }

    #rios-chat-input-container {
        padding: 10px;
    }
}

/* ========================================
   LANDSCAPE MODE (Mobile)
   ======================================== */
@media (max-width: 767px) and (orientation: landscape) {
    #rios-chat-container {
        height: 100vh;
    }

    #rios-chat-messages {
        padding: 12px;
    }

    .rios-artwork-image {
        height: 120px;
    }
}

/* ========================================
   ACCESSIBILITY
   ======================================== */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* High contrast mode */
@media (prefers-contrast: high) {
    #rios-chat-container {
        border: 2px solid var(--rios-text-primary);
    }

    .rios-message-user .rios-message-bubble,
    .rios-message-assistant .rios-message-bubble {
        border: 1px solid var(--rios-border-color);
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    :root {
        --rios-bg-light: #1F2937;
        --rios-bg-dark: #111827;
        --rios-text-primary: #F9FAFB;
        --rios-text-secondary: #D1D5DB;
        --rios-border-color: #374151;
    }
}

/* ========================================
   LOADING STATE
   ======================================== */
.rios-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.rios-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--rios-border-color);
    border-top-color: var(--rios-primary-color);
    border-radius: 50%;
    animation: rios-spin 1s linear infinite;
}

@keyframes rios-spin {
    to {
        transform: rotate(360deg);
    }
}

/* ========================================
   HIDE ON SPECIFIC DEVICES
   ======================================== */
@media (max-width: 767px) {
    body.rios-hide-mobile #rios-chat-button,
    body.rios-hide-mobile #rios-chat-container {
        display: none !important;
    }
}

@media (min-width: 768px) and (max-width: 1024px) {
    body.rios-hide-tablet #rios-chat-button,
    body.rios-hide-tablet #rios-chat-container {
        display: none !important;
    }
}


#rios-call-operator,
#rios-chat-close {
    background: transparent !important;
    border: none !important;
    padding: 4px !important;
}

#rios-call-operator img,
#rios-chat-close img {
    width: 24px !important;
    height: 24px !important;
    display: block !important;
}


#rios-chat-resize-divider {
    height: 6px;
    cursor: row-resize;
    background: rgba(255, 255, 255, 0.12);
    flex-shrink: 0;
}

#rios-chat-resize-divider:hover {
    background: rgba(255, 255, 255, 0.2);
}
