/**
 * AI Companion Chat Widget - Complete Styles
 * Properly organized CSS with separation of concerns
 */

/* === CORE LAYOUT === */
.aic-popup {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 50%;
    height: 80%;
    max-width: calc(100vw - 40px);
    max-height: calc(100vh - 40px);
    background: #fff;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
    display: none;
    z-index: 9001;
    border-radius: 4px;
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    transform-origin: bottom right;
    border: #007bff 0.1px solid;
}

.aic-popup.expanded {
    width: 100vw !important;
    height: 100vh !important;
    bottom: 0 !important;
    right: 0 !important;
    border-radius: 0 !important;
    transform: none !important;
}

.aic-popup.mobile {
    width: 100vw !important;
    height: 100vh !important;
    bottom: 0 !important;
    right: 0 !important;
    border-radius: 0 !important;
    transform: none !important;
}

/* === HEADER === */
.aic-header {
    position: relative;
    background: #007bff;
    color: #fff;
    padding: 8px 10px;
    font-size: 12px;
    line-height: 1.2;
    height: 32px;
    display: flex;
    align-items: center;
    border-radius: 4px 4px 0 0;
    box-sizing: border-box;
    flex-shrink: 0;
    font-family: Arial, sans-serif;
}

.aic-controls {
    position: absolute;
    top: 50%;
    right: 8px;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
}

.aic-btn {
    background: transparent;
    color: #fff;
    border: none;
    cursor: pointer;
    font-size: 14px;
    padding: 2px;
    margin-left: 3px;
    line-height: 1;
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.2s ease;
}

.aic-btn:hover {
    opacity: 0.8;
}

.aic-btn:focus {
    outline: 2px solid #fff;
    outline-offset: 2px;
}

/* === BODY CONTENT === */
.aic-body {
    width: 100%;
    height: calc(100% - 32px);
    position: relative;
    overflow: hidden;
}

.aic-iframe {
    width: 100%;
    height: 100%;
    border: none;
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

/* === ERROR STATE === */
.aic-error {
    display: none;
    width: 100%;
    height: 100%;
    background: #f8f9fa;
    padding: 20px;
    box-sizing: border-box;
    text-align: center;
    font-family: Arial, sans-serif;
    position: absolute;
    top: 0;
    left: 0;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.aic-error-icon {
    font-size: 48px;
    color: #dc3545;
    margin-bottom: 16px;
}

.aic-error-title {
    font-size: 18px;
    font-weight: bold;
    color: #212529;
    margin-bottom: 8px;
}

.aic-error-message {
    font-size: 14px;
    color: #6c757d;
    line-height: 1.5;
    margin-bottom: 16px;
}

.aic-error-retry {
    background: #007bff;
    color: #fff;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    transition: background-color 0.2s ease;
}

.aic-error-retry:hover {
    background: #0056b3;
}

.aic-error-retry:focus {
    outline: 2px solid #007bff;
    outline-offset: 2px;
}

/* === CHAT BUTTON === */
.aic-chat-btn {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: #007bff;
    color: #fff;
    border: none;
    width: 60px;
    height: 60px;
    font-size: 32px;
    border-radius: 50%;
    cursor: pointer;
    z-index: 1000;
    transition: all 0.3s ease;
    will-change: transform;
    box-shadow: 0 2px 8px rgba(0, 123, 255, 0.3);
}

.aic-chat-btn:hover {
    background: #0056b3;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 123, 255, 0.4);
}

.aic-chat-btn:active {
    transform: scale(0.95);
}

.aic-chat-btn:focus {
    outline: 2px solid #fff;
    outline-offset: 2px;
}

/* === CALLOUT === */
.aic-callout {
    position: fixed;
    bottom: 90px;
    right: 20px;
    background: rgb(255, 63, 70);
    color: #fff;
    padding: 8px 12px;
    border-radius: 4px;
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
    font-size: 14px;
    text-align: center;
    font-weight: bold;
    display: none;
    z-index: 1000;
    animation: aic-fadeIn 0.3s ease;
    transition: all 0.3s ease;
    will-change: opacity, transform;
    font-family: Arial, sans-serif;
}

.aic-callout::before {
    content: '';
    position: absolute;
    bottom: -5px;
    right: 20px;
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 5px solid rgb(255, 63, 70);
}

/* === ANIMATIONS === */
@keyframes aic-fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* === USER EXPERIENCE === */
.aic-header,
.aic-btn,
.aic-chat-btn,
.aic-callout {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* === RESPONSIVE DESIGN === */
/* Enhanced mobile responsiveness for full-screen experience */
@media (max-width: 768px) {
    .aic-popup {
        width: 100% !important;
        height: 100% !important;
        top: 0 !important;
        left: 0 !important;
        bottom: unset !important;
        right: unset !important;
        border-radius: 0 !important;
        max-width: 100vw !important;
        max-height: 100vh !important;
        border: none !important;
    }
    
    /* Ensure mobile class behavior is consistent */
    .aic-popup.mobile {
        width: 100vw !important;
        height: 100vh !important;
        top: 0 !important;
        left: 0 !important;
        bottom: unset !important;
        right: unset !important;
        border-radius: 0 !important;
        transform: none !important;
        border: none !important;
    }
    
    /* Hide expand/minimize button on mobile - keep only close button */
    .aic-popup #aic-expand,
    .aic-popup.mobile #aic-expand {
        display: none !important;
    }
    
    /* Optimize header for mobile */
    .aic-header {
        padding: 12px 16px;
        font-size: 14px;
        height: auto;
        min-height: 44px; /* Touch-friendly height */
    }
    
    /* Make controls more touch-friendly */
    .aic-btn {
        min-width: 44px;
        min-height: 44px;
        font-size: 16px;
        border-radius: 8px;
        margin-left: 8px;
    }
    
    /* Ensure iframe takes full mobile space */
    .aic-iframe {
        border-radius: 0 !important;
    }
}

/* Additional optimization for smaller mobile devices */
@media (max-width: 430px) {
    .aic-popup {
        width: 100% !important;
        height: 100% !important;
        top: 0 !important;
        left: 0 !important;
        bottom: unset !important;
        right: unset !important;
    }
    
    /* Hide expand/minimize button on smaller mobile devices too */
    .aic-popup #aic-expand,
    .aic-popup.mobile #aic-expand {
        display: none !important;
    }
}

/* === HIGH DPI DISPLAYS === */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .aic-popup {
        box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
    }
}

/* === ACCESSIBILITY === */
@media (prefers-reduced-motion: reduce) {
    .aic-popup,
    .aic-chat-btn,
    .aic-callout {
        transition: none;
        animation: none;
    }
}

/* === DARK MODE SUPPORT === */
@media (prefers-color-scheme: dark) {
    .aic-popup {
        background: #1a1a1a;
        box-shadow: 0 0 10px rgba(255, 255, 255, 0.1);
    }
    
    .aic-error {
        background: #2d3748;
        color: #e2e8f0;
    }
    
    .aic-error-title {
        color: #f7fafc;
    }
    
    .aic-error-message {
        color: #a0aec0;
    }
}