/*
 * Attic ChatKit Widget Styles
 * Matches landing page design system with gradient theme and glassmorphism
 */

/* Widget Container */
#attic-chat-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* Floating Action Button (FAB) */
.chat-fab {
    position: relative;
    width: 64px;
    height: 64px;
    border-radius: 9999px;
    background: linear-gradient(135deg, #FF3C68 0%, #FF7130 50%, #872B97 100%);
    border: none;
    cursor: pointer;
    box-shadow: 0 20px 25px -5px rgba(255, 60, 104, 0.4),
                0 8px 10px -6px rgba(255, 60, 104, 0.3);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: slideInUp 0.6s ease-out 1s backwards, pulse-slow 3s ease-in-out 2s infinite;
}

.chat-fab:hover {
    transform: scale(1.1);
    box-shadow: 0 25px 30px -5px rgba(255, 60, 104, 0.5),
                0 10px 15px -6px rgba(255, 60, 104, 0.4);
}

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

.chat-fab.expanded {
    transform: scale(0);
    opacity: 0;
    pointer-events: none;
}

/* Chat Icon */
.chat-icon {
    font-size: 28px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s ease;
}

.chat-fab:hover .chat-icon {
    transform: scale(1.1);
}

/* Notification Badge */
.notification-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 24px;
    height: 24px;
    background: #EF4444;
    color: white;
    border-radius: 9999px;
    font-size: 12px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
    border: 3px solid #171721;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
    animation: bounceIn 0.5s ease-out;
}

.notification-badge.hidden {
    display: none;
}

.notification-badge.pulse {
    animation: badgePulse 1.5s ease-in-out infinite;
}

/* Chat Window Container */
.chat-window {
    position: fixed;
    bottom: 96px;
    right: 24px;
    width: 400px;
    height: 600px;
    background: rgba(23, 23, 33, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 24px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transform-origin: bottom right;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.chat-window.collapsed {
    transform: scale(0);
    opacity: 0;
    pointer-events: none;
}

.chat-window.expanded {
    animation: scaleIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Chat Header */
.chat-header {
    background: #FF3C68;
    padding: 20px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    flex-shrink: 0;
}

.chat-header-content {
    flex: 1;
}

.chat-header-title {
    font-size: 18px;
    font-weight: 700;
    color: white;
    margin: 0;
    line-height: 1.2;
}

.chat-header-subtitle {
    font-size: 13px;
    color: rgba(255, 255, 255, 0.8);
    margin: 4px 0 0 0;
    display: flex;
    align-items: center;
    gap: 6px;
}

.status-dot {
    width: 8px;
    height: 8px;
    background: #10B981;
    border-radius: 50%;
    display: inline-block;
    animation: pulse 2s ease-in-out infinite;
}

.chat-header-actions {
    display: flex;
    gap: 8px;
}

.chat-header-button {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    font-size: 18px;
    line-height: 1;
}

.chat-header-button:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

.chat-header-button:active {
    transform: scale(0.95);
}

/* Chat Body (ChatKit Container) */
.chat-body {
    flex: 1;
    overflow: hidden;
    position: relative;
    background: #171721;
}

#chatkit-container {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
}

#chatkit-container openai-chatkit {
    width: 100%;
    height: 100%;
    display: block;
}

#chatkit-container iframe {
    width: 100%;
    height: 100%;
    border: none;
}

/* Loading State */
.chat-loading {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: #171721;
    color: white;
    gap: 16px;
}

.chat-loading.hidden {
    display: none;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(255, 255, 255, 0.1);
    border-top-color: #FF3C68;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.loading-text {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.6);
}

/* Text Bubble (Main Feature) */
.chat-bubble {
    position: absolute;
    bottom: 16px;
    right: 80px;
    background: white;
    color: #171721;
    padding: 14px 20px;
    border-radius: 20px;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15),
                0 2px 6px rgba(0, 0, 0, 0.1);
    font-size: 15px;
    font-weight: 500;
    line-height: 1.4;
    white-space: nowrap;
    animation: bubbleSlideIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) backwards,
               bubblePulse 2s ease-in-out 3s infinite;
    transform-origin: right center;
    z-index: 9998;
    pointer-events: none;
    user-select: none;
}

.chat-bubble::after {
    content: '';
    position: absolute;
    right: -6px;
    top: 50%;
    transform: translateY(-50%) rotate(45deg);
    width: 14px;
    height: 14px;
    background: white;
    box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.08);
}

.chat-bubble.hidden {
    display: none;
}

.chat-bubble-text {
    position: relative;
    z-index: 1;
}

/* First Time Visitor Tooltip (Secondary Feature) */
.chat-tooltip {
    position: absolute;
    bottom: 80px;
    right: 0;
    background: white;
    color: #171721;
    padding: 16px 20px;
    border-radius: 16px;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.2);
    max-width: 280px;
    animation: slideInRight 0.4s ease-out;
    pointer-events: none;
}

.chat-tooltip::after {
    content: '';
    position: absolute;
    bottom: -8px;
    right: 24px;
    width: 16px;
    height: 16px;
    background: white;
    transform: rotate(45deg);
}

.chat-tooltip.hidden {
    display: none;
}

.tooltip-close {
    position: absolute;
    top: 8px;
    right: 8px;
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: #6B7280;
    line-height: 1;
    padding: 4px;
    pointer-events: auto;
}

.tooltip-close:hover {
    color: #171721;
}

.tooltip-text {
    font-size: 14px;
    line-height: 1.5;
    margin: 0;
    padding-right: 20px;
}

.tooltip-text strong {
    color: #FF3C68;
    font-weight: 600;
}

/* Animations */
@keyframes bubbleSlideIn {
    from {
        transform: translateX(20px) scale(0.8);
        opacity: 0;
    }
    to {
        transform: translateX(0) scale(1);
        opacity: 1;
    }
}

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

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

@keyframes slideInRight {
    from {
        transform: translateX(20px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes scaleIn {
    from {
        transform: scale(0);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

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

@keyframes pulse-slow {
    0%, 100% {
        box-shadow: 0 20px 25px -5px rgba(255, 60, 104, 0.4),
                    0 8px 10px -6px rgba(255, 60, 104, 0.3),
                    0 0 0 0 rgba(255, 60, 104, 0.5);
    }
    50% {
        box-shadow: 0 20px 25px -5px rgba(255, 60, 104, 0.4),
                    0 8px 10px -6px rgba(255, 60, 104, 0.3),
                    0 0 0 20px rgba(255, 60, 104, 0);
    }
}

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

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

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

@keyframes wiggle {
    0%, 100% {
        transform: rotate(0deg);
    }
    25% {
        transform: rotate(5deg);
    }
    75% {
        transform: rotate(-5deg);
    }
}

/* ===========================================
   MOBILE RESPONSIVE - Stunning Bottom Sheet Design
   =========================================== */

@media (max-width: 768px) {
    /* Widget Container - Premium Positioning */
    #attic-chat-widget {
        bottom: 20px;
        right: 20px;
    }

    /* FAB Button - Refined Mobile Size */
    .chat-fab {
        width: 60px;
        height: 60px;
        box-shadow:
            0 8px 32px -4px rgba(255, 60, 104, 0.5),
            0 4px 16px -2px rgba(255, 60, 104, 0.3),
            0 0 0 1px rgba(255, 255, 255, 0.1) inset;
    }

    .chat-fab:hover {
        transform: scale(1.05);
    }

    .chat-icon {
        font-size: 26px;
    }

    /* Text Bubble - Elegant Mobile Positioning */
    .chat-bubble {
        right: 76px;
        bottom: 12px;
        max-width: min(calc(100vw - 120px), 260px);
        font-size: 14px;
        padding: 14px 18px;
        border-radius: 18px;
        box-shadow:
            0 12px 32px rgba(0, 0, 0, 0.12),
            0 4px 12px rgba(0, 0, 0, 0.08);
        background: linear-gradient(135deg, #ffffff 0%, #fafafa 100%);
    }

    .chat-bubble::after {
        right: -5px;
        width: 12px;
        height: 12px;
        background: linear-gradient(135deg, #fafafa 0%, #ffffff 100%);
    }

    /* Chat Window - Premium Bottom Sheet Style */
    .chat-window {
        bottom: 0;
        right: 0;
        left: 0;
        top: auto;
        width: 100%;
        height: 92vh;
        max-height: 92vh;
        border-radius: 24px 24px 0 0;
        background: rgba(23, 23, 33, 0.98);
        backdrop-filter: blur(40px);
        -webkit-backdrop-filter: blur(40px);
        box-shadow:
            0 -20px 60px rgba(0, 0, 0, 0.4),
            0 -8px 32px rgba(0, 0, 0, 0.2),
            0 0 0 1px rgba(255, 255, 255, 0.08) inset;
        transform-origin: bottom center;
    }

    .chat-window.expanded {
        animation: mobileSheetSlideIn 0.4s cubic-bezier(0.32, 0.72, 0, 1);
    }

    .chat-window.collapsed {
        transform: translateY(100%);
        opacity: 0;
    }

    /* Sheet Handle Indicator */
    .chat-window::before {
        content: '';
        position: absolute;
        top: 8px;
        left: 50%;
        transform: translateX(-50%);
        width: 36px;
        height: 4px;
        background: rgba(255, 255, 255, 0.3);
        border-radius: 2px;
        z-index: 10;
    }

    /* Chat Header - Mobile Optimized */
    .chat-header {
        padding: 24px 20px 16px;
        background: linear-gradient(180deg, #FF3C68 0%, #FF3C68 90%, rgba(255, 60, 104, 0.95) 100%);
        border-radius: 24px 24px 0 0;
        position: relative;
    }

    .chat-header-title {
        font-size: 17px;
        font-weight: 700;
        letter-spacing: -0.01em;
    }

    .chat-header-subtitle {
        font-size: 13px;
        margin-top: 2px;
        opacity: 0.9;
    }

    .chat-header-button {
        width: 36px;
        height: 36px;
        border-radius: 10px;
        font-size: 20px;
        background: rgba(255, 255, 255, 0.15);
        backdrop-filter: blur(8px);
        -webkit-backdrop-filter: blur(8px);
    }

    .chat-header-button:hover {
        background: rgba(255, 255, 255, 0.25);
        transform: scale(1.05);
    }

    /* Chat Body - Clean Mobile Experience */
    .chat-body {
        background: linear-gradient(180deg, #171721 0%, #1a1a26 100%);
        border-radius: 0;
    }

    /* Loading State - Mobile Polish */
    .chat-loading {
        background: linear-gradient(180deg, #171721 0%, #1a1a26 100%);
    }

    .loading-spinner {
        width: 44px;
        height: 44px;
        border-width: 3px;
    }

    .loading-text {
        font-size: 13px;
        letter-spacing: 0.02em;
    }

    /* Tooltip - Mobile Friendly */
    .chat-tooltip {
        right: auto;
        left: 16px;
        right: 16px;
        bottom: 90px;
        max-width: none;
        border-radius: 16px;
        padding: 14px 18px;
        box-shadow:
            0 16px 40px rgba(0, 0, 0, 0.2),
            0 4px 12px rgba(0, 0, 0, 0.1);
    }

    .chat-tooltip::after {
        bottom: -6px;
        right: auto;
        left: 50%;
        transform: translateX(-50%) rotate(45deg);
    }

    /* Notification Badge - Mobile Size */
    .notification-badge {
        min-width: 22px;
        height: 22px;
        font-size: 11px;
        top: -3px;
        right: -3px;
        border-width: 2px;
    }
}

/* Tablet Breakpoint - Refined */
@media (min-width: 769px) and (max-width: 1024px) {
    .chat-window {
        width: 380px;
        height: 580px;
        border-radius: 20px;
    }

    .chat-header {
        padding: 18px 20px;
    }
}

/* Mobile Bottom Sheet Animations */
@keyframes mobileSheetSlideIn {
    0% {
        transform: translateY(100%);
        opacity: 0;
    }
    40% {
        opacity: 1;
    }
    100% {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes mobileSheetSlideOut {
    0% {
        transform: translateY(0);
        opacity: 1;
    }
    100% {
        transform: translateY(100%);
        opacity: 0;
    }
}

/* Small Mobile Devices */
@media (max-width: 374px) {
    #attic-chat-widget {
        bottom: 16px;
        right: 16px;
    }

    .chat-fab {
        width: 54px;
        height: 54px;
    }

    .chat-icon {
        font-size: 22px;
    }

    .chat-bubble {
        right: 68px;
        max-width: calc(100vw - 100px);
        font-size: 13px;
        padding: 12px 14px;
    }

    .chat-window {
        height: 94vh;
        max-height: 94vh;
        border-radius: 20px 20px 0 0;
    }

    .chat-header {
        padding: 20px 16px 14px;
    }

    .chat-header-title {
        font-size: 16px;
    }

    .chat-header-subtitle {
        font-size: 12px;
    }

    .chat-header-button {
        width: 32px;
        height: 32px;
        font-size: 18px;
    }
}

/* Landscape Mode on Mobile */
@media (max-width: 768px) and (orientation: landscape) {
    .chat-window {
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
    }

    .chat-window::before {
        display: none;
    }

    .chat-header {
        padding: 12px 16px;
        border-radius: 0;
    }
}

/* Safe Area Support for notched devices */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    @media (max-width: 768px) {
        .chat-window {
            padding-bottom: env(safe-area-inset-bottom);
        }

        #attic-chat-widget {
            bottom: calc(20px + env(safe-area-inset-bottom));
        }
    }
}

/* Dark mode support (if needed) */
@media (prefers-color-scheme: light) {
    .chat-window {
        background: rgba(255, 255, 255, 0.95);
    }

    .chat-body {
        background: #FFFFFF;
    }

    .chat-loading {
        background: #FFFFFF;
        color: #171721;
    }
}

/* Accessibility */
.chat-fab:focus-visible,
.chat-header-button:focus-visible {
    outline: 2px solid #FF3C68;
    outline-offset: 2px;
}

/* Print styles */
@media print {
    #attic-chat-widget {
        display: none !important;
    }
}
