/**
 * Kundeservice Chat Mobile CSS
 * Mobil optimering og touch events
 */

/* ========= Mobile Context Menu ========= */
.mobile-context-menu {
    position: fixed;
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
    padding: 8px 0;
    z-index: 1000000;
    min-width: 160px;
    animation: contextMenuSlide 0.2s ease-out;
}

@keyframes contextMenuSlide {
    from {
        opacity: 0;
        transform: scale(0.9) translateY(-10px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.mobile-context-menu .menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    cursor: pointer;
    font-size: 14px;
    color: var(--ks-text);
    transition: background-color 0.2s ease;
}

.mobile-context-menu .menu-item:hover {
    background: var(--ks-secondary);
}

.mobile-context-menu .menu-item svg {
    width: 16px;
    height: 16px;
    color: var(--ks-primary);
}

/* ========= Mobile Optimizations ========= */
@media (max-width: 768px) {
    /* Touch optimizations */
    .kundeservice-chat-widget * {
        -webkit-tap-highlight-color: transparent;
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        -khtml-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
    }

    /* Allow text selection in input */
    #chat-input {
        -webkit-user-select: text;
        -khtml-user-select: text;
        -moz-user-select: text;
        -ms-user-select: text;
        user-select: text;
    }

    /* Optimize chat container for mobile */
    .chat-container {
        width: 100vw;
        height: 100vh;
        max-width: 100vw;
        max-height: 100vh;
        border-radius: 0;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 999999;
    }

    /* Mobile header optimizations */
    .chat-header {
        padding: 12px 16px;
        border-radius: 0;
        position: sticky;
        top: 0;
        z-index: 10;
    }

    .chat-header-content {
        gap: 8px;
    }

    .chat-header-title {
        gap: 8px;
    }

    .chat-avatar {
        width: 32px;
        height: 32px;
    }

    .chat-title-text h3 {
        font-size: 14px;
    }

    .chat-status-indicator {
        font-size: 11px;
    }

    /* Mobile header buttons */
    .chat-header-controls {
        gap: 4px;
    }

    .header-btn {
        padding: 6px 8px;
        font-size: 11px;
        min-height: 32px;
        min-width: 32px;
    }

    .header-btn span {
        display: none;
    }

    .chat-close {
        width: 28px;
        height: 28px;
    }

    /* Mobile messages */
    .chat-messages {
        padding: 12px 16px;
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .message {
        max-width: 85%;
    }

    .message-content {
        padding: 10px 14px;
        font-size: 14px;
        line-height: 1.4;
    }

    .message-time {
        font-size: 10px;
        margin-top: 2px;
    }

    /* Mobile input */
    .chat-input-container {
        padding: 12px 16px;
        position: sticky;
        bottom: 0;
        background: white;
        border-top: 1px solid var(--ks-border);
    }

    .chat-input-wrapper {
        gap: 8px;
    }

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

    #chat-send {
        width: 36px;
        height: 36px;
        min-width: 36px;
        min-height: 36px;
    }

    /* Mobile toggle button */
    .chat-toggle {
        width: 56px;
        height: 56px;
    }

    .chat-toggle svg {
        width: 22px;
        height: 22px;
    }

    /* Mobile badge */
    .chat-badge {
        width: 18px;
        height: 18px;
        font-size: 11px;
    }
}

/* ========= Small Mobile (≤ 480px) ========= */
@media (max-width: 480px) {
    .small-mobile-optimized {
        /* Extra small mobile optimizations */
    }

    .chat-header {
        padding: 10px 12px;
    }

    .chat-header h3 {
        font-size: 13px;
    }

    .chat-header-controls {
        gap: 2px;
    }

    .header-btn {
        padding: 4px 6px;
        font-size: 10px;
        min-height: 28px;
        min-width: 28px;
    }

    .chat-close {
        width: 24px;
        height: 24px;
    }

    .chat-messages {
        padding: 10px 12px;
    }

    .message-content {
        padding: 8px 12px;
        font-size: 13px;
    }

    .chat-input-container {
        padding: 10px 12px;
    }

    #chat-input {
        padding: 8px 12px;
        font-size: 16px;
    }

    #chat-send {
        width: 32px;
        height: 32px;
        min-width: 32px;
        min-height: 32px;
    }

    .chat-toggle {
        width: 50px;
        height: 50px;
        bottom: 15px;
        right: 15px;
    }

    .chat-toggle svg {
        width: 20px;
        height: 20px;
    }
}

/* ========= Tablet Optimizations ========= */
@media (min-width: 769px) and (max-width: 1024px) {
    .tablet-optimized {
        /* Tablet specific optimizations */
    }

    .chat-container {
        width: 400px;
        height: 650px;
    }

    .chat-toggle {
        width: 58px;
        height: 58px;
    }

    .chat-toggle svg {
        width: 24px;
        height: 24px;
    }
}

/* ========= Landscape Mode ========= */
@media (max-width: 768px) and (orientation: landscape) {
    .landscape-mode {
        /* Landscape specific optimizations */
    }

    .chat-container {
        height: 100vh;
        width: 100vw;
    }

    .chat-header {
        padding: 8px 16px;
    }

    .chat-messages {
        padding: 8px 16px;
    }

    .chat-input-container {
        padding: 8px 16px;
    }

    .chat-toggle {
        width: 48px;
        height: 48px;
        bottom: 15px;
        right: 15px;
    }
}

/* ========= Touch Optimizations ========= */
@media (hover: none) and (pointer: coarse) {
    /* Touch device optimizations */
    
    .chat-toggle:hover {
        transform: none;
    }

    .header-btn:hover {
        background: rgba(255, 255, 255, 0.2);
        transform: none;
    }

    .chat-close:hover {
        background: rgba(255, 255, 255, 0.2);
        transform: none;
    }

    #chat-send:hover:not(:disabled) {
        background: var(--ks-primary);
        transform: none;
    }

    /* Active states for touch */
    .chat-toggle:active {
        transform: scale(0.95);
    }

    .header-btn:active {
        background: rgba(255, 255, 255, 0.3);
        transform: scale(0.95);
    }

    .chat-close:active {
        background: rgba(239, 68, 68, 0.8);
        transform: scale(0.95);
    }

    #chat-send:active:not(:disabled) {
        background: var(--ks-primary-dark);
        transform: scale(0.95);
    }
}

/* ========= iOS Specific ========= */
@supports (-webkit-touch-callout: none) {
    .device-ios {
        /* iOS specific styles */
    }

    .chat-container {
        -webkit-overflow-scrolling: touch;
    }

    .chat-messages {
        -webkit-overflow-scrolling: touch;
    }

    /* Fix iOS input zoom */
    #chat-input {
        font-size: 16px;
    }

    /* iOS safe area support */
    .chat-container {
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
    }
}

/* ========= Android Specific ========= */
.device-android {
    /* Android specific styles */
}

/* ========= High DPI Displays ========= */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .chat-toggle,
    .header-btn,
    .chat-close,
    #chat-send {
        /* Optimize for high DPI displays */
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}

/* ========= Reduced Motion ========= */
@media (prefers-reduced-motion: reduce) {
    .chat-container,
    .chat-toggle,
    .message,
    .header-btn,
    .chat-close,
    #chat-send {
        animation: none !important;
        transition: none !important;
    }

    .mobile-context-menu {
        animation: none !important;
    }
}

/* ========= Dark Mode Mobile ========= */
@media (prefers-color-scheme: dark) and (max-width: 768px) {
    .mobile-context-menu {
        background: #1f2937;
        color: #f9fafb;
    }

    .mobile-context-menu .menu-item {
        color: #f9fafb;
    }

    .mobile-context-menu .menu-item:hover {
        background: #374151;
    }
}

/* ========= Performance Optimizations ========= */
.kundeservice-chat-widget {
    /* Hardware acceleration */
    transform: translateZ(0);
    backface-visibility: hidden;
    perspective: 1000px;
}

.chat-container {
    /* Optimize for mobile rendering */
    will-change: transform, opacity;
    transform: translateZ(0);
}

.chat-messages {
    /* Optimize scrolling performance */
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}

/* ========= Accessibility Mobile ========= */
@media (max-width: 768px) {
    /* Larger touch targets for accessibility */
    .header-btn,
    .chat-close,
    #chat-send {
        min-height: 44px;
        min-width: 44px;
    }

    /* High contrast mode support */
    @media (prefers-contrast: high) {
        .chat-header {
            border-bottom: 2px solid white;
        }

        .message-content {
            border: 1px solid var(--ks-border);
        }

        .header-btn,
        .chat-close,
        #chat-send {
            border: 1px solid rgba(255, 255, 255, 0.3);
        }
    }
}

/* ========= Print Styles ========= */
@media print {
    .kundeservice-chat-widget {
        display: none !important;
    }
}
