/* ==========================================
   MOBILE STYLES - VANÄHLISMUS LIVE SHOP
   FÜR ALLE MOBILE GERÄTE (inkl. Samsung)
   ========================================== */

/* ==========================================
   KRITISCHER FIX: Erweiterte Mobile Detection
   - max-width: 1024px für moderne Smartphones
   - touch detection als Backup
   ========================================== */

@media (max-width: 1024px), (hover: none) and (pointer: coarse) {
    /* ==========================================
       FORCE HIDE DESKTOP SIDEBARS
       ========================================== */
    
    .sidebar-left,
    .sidebar-right,
    aside.sidebar-left,
    aside.sidebar-right,
    .desktop-only {
        display: none !important;
        visibility: hidden !important;
        width: 0 !important;
        height: 0 !important;
        overflow: hidden !important;
        position: absolute !important;
        left: -9999px !important;
    }
    
    /* ==========================================
       BASE MOBILE LAYOUT
       ========================================== */
    
    html, body {
        position: fixed;
        width: 100%;
        height: 100dvh;
        overflow: hidden;
    }
    
    body {
        display: flex;
        flex-direction: column;
    }
    
    /* ==========================================
       MAIN CONTENT - FULL WIDTH ON MOBILE
       ========================================== */
    
    .main-content {
        position: fixed !important;
        top: 72px !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100% !important;
        height: calc(100dvh - 72px) !important;
        display: flex;
        flex-direction: column;
        overflow: hidden;
        z-index: 5;
        margin: 0 !important;
        padding: 0 !important;
    }
    
    /* Adjust for header when user is logged in */
    body.admin-mode .main-content,
    body.user-mode .main-content {
        top: 72px !important;
        height: calc(100dvh - 72px) !important;
    }
    
    body:not(.admin-mode):not(.user-mode) .main-content {
        top: 0 !important;
        height: 100dvh !important;
    }
    
    /* ==========================================
       CHAT CONTAINER - MOBILE OPTIMIZED
       ========================================== */
    
    .chat-container {
        display: flex;
        flex-direction: column;
        height: 100%;
        width: 100%;
        overflow: hidden;
        flex: 1;
    }
    
    .chat-header {
        flex-shrink: 0;
        z-index: 100;
        padding: 12px 16px;
        background: rgba(255, 255, 255, 0.95);
        backdrop-filter: blur(20px);
        border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    }
    
    .chat-product-name {
        font-size: 16px;
    }
    
    .chat-product-description {
        font-size: 13px;
    }
    
    /* ==========================================
       CHAT MESSAGES - SCROLLABLE AREA
       ========================================== */
    
    .chat-messages {
        flex: 1;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        padding: 16px;
        padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px));
        min-height: 0;
        display: flex;
        flex-direction: column;
        gap: 12px;
    }
    
    /* ==========================================
       CHAT INPUT - STICKY BOTTOM
       ========================================== */
    
    .chat-input {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        padding: 12px 16px;
        padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
        background: rgba(255, 255, 255, 0.98);
        backdrop-filter: blur(40px);
        border-top: 1px solid rgba(0, 0, 0, 0.05);
        z-index: 1998;
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
        min-height: calc(68px + env(safe-area-inset-bottom, 0px));
    }
    
    body.admin-mode .chat-input,
    body.user-mode .chat-input {
        bottom: 0;
    }
    
    .chat-input-wrapper {
        display: flex;
        align-items: center;
        gap: 8px;
        width: 100%;
    }
    
    .chat-input-field {
        flex: 1;
        min-width: 0;
        padding: 12px 16px;
        border: 2px solid #e5e7eb;
        border-radius: 20px;
        font-size: 16px;
        background: white;
        outline: none;
    }
    
    .chat-send-btn {
        flex-shrink: 0;
        width: 44px;
        height: 44px;
    }
    
    .chat-input-btn {
        flex-shrink: 0;
        width: 40px;
        height: 40px;
    }
    
    #reply-preview {
        margin: 0 0 8px 0;
        width: 100%;
    }
    
    /* ==========================================
       MESSAGES - MOBILE OPTIMIZED
       ========================================== */
    
    .message {
        max-width: 80%;
        font-size: 14px;
    }
    
    .message-wrapper:hover .message {
        transform: none;
    }
    
    .message-actions {
        position: relative;
        top: auto;
        right: auto;
        display: flex;
        margin-top: 8px;
    }
    
    .message-wrapper:hover .message-actions {
        display: flex;
    }
    
    /* ==========================================
       MOBILE SIDEBAR PANEL
       ========================================== */
    
    .mobile-sidebar-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        backdrop-filter: blur(4px);
        z-index: 2999;
        opacity: 0;
        visibility: hidden;
        transition: all 0.3s ease;
    }
    
    .mobile-sidebar-overlay.active {
        opacity: 1;
        visibility: visible;
    }
    
    .mobile-sidebar-panel {
        position: fixed;
        top: 0;
        right: -100%;
        width: 85%;
        max-width: 360px;
        height: 100dvh;
        background: white;
        z-index: 3000;
        display: flex;
        flex-direction: column;
        box-shadow: -4px 0 20px rgba(0, 0, 0, 0.2);
        transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }
    
    body.admin-mode .mobile-sidebar-panel,
    body.user-mode .mobile-sidebar-panel {
        top: 72px;
        height: calc(100dvh - 72px);
    }
    
    .mobile-sidebar-panel.active {
        right: 0;
    }
    
    /* ==========================================
       MOBILE SIDEBAR HEADER
       ========================================== */
    
    .mobile-sidebar-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 20px;
        border-bottom: 2px solid #f1f5f9;
        background: #ffffff;
        flex-shrink: 0;
    }
    
    .mobile-sidebar-title {
        font-size: 18px;
        font-weight: 700;
        color: #1e293b;
        display: flex;
        align-items: center;
        gap: 10px;
    }
    
    .mobile-sidebar-title .icon {
        width: 22px;
        height: 22px;
        color: #8b5cf6;
    }
    
    .mobile-sidebar-close {
        width: 40px;
        height: 40px;
        border-radius: 50%;
        border: none;
        background: #f1f5f9;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        transition: all 0.2s;
    }
    
    .mobile-sidebar-close:active {
        transform: scale(0.95);
        background: #e2e8f0;
    }
    
    .mobile-sidebar-close .icon {
        width: 20px;
        height: 20px;
        color: #64748b;
    }
    
    /* ==========================================
       MOBILE SIDEBAR CONTENT
       ========================================== */
    
    .mobile-sidebar-content {
        flex: 1;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        padding: 20px;
    }
    
    /* Cart in Mobile Sidebar */
    .mobile-cart-items {
        display: flex;
        flex-direction: column;
        gap: 12px;
        margin-bottom: 20px;
    }
    
    .mobile-cart-total {
        border-top: 2px solid #f1f5f9;
        padding-top: 16px;
        margin-top: auto;
    }
    
    /* Products in Mobile Sidebar */
    .mobile-products-grid {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }
    
    .mobile-product-card {
        background: white;
        border-radius: 12px;
        overflow: hidden;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
        border: 1px solid #e5e7eb;
        cursor: pointer;
        transition: all 0.2s;
        position: relative;
    }
    
    .mobile-product-card:active {
        transform: scale(0.98);
    }
    
    .mobile-product-image {
        width: 100%;
        height: 140px;
        object-fit: cover;
        background: white;
    }
    
    .mobile-product-info {
        padding: 12px;
    }
    
    .mobile-product-name {
        font-size: 13px;
        font-weight: 600;
        color: #1f2937;
        margin-bottom: 6px;
        line-height: 1.3;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }
    
    .mobile-product-price {
        font-size: 15px;
        font-weight: 700;
        color: #ec4899;
    }
    
    /* ==========================================
       EMOJI PICKER - MOBILE
       ========================================== */
    
    .emoji-picker {
        position: fixed;
        width: 90vw;
        max-width: 340px;
        height: 60vh;
        max-height: 450px;
        bottom: calc(80px + env(safe-area-inset-bottom, 0px));
        left: 50%;
        transform: translateX(-50%);
        z-index: 99999;
    }
    
    /* ==========================================
       PRODUCT MODAL - MOBILE
       ========================================== */
    
    .modal-overlay {
        padding: 0;
    }
    
    .modal-content {
        max-width: 100%;
        width: 100%;
        max-height: 100vh;
        height: 100vh;
        border-radius: 0;
        margin: 0;
    }
    
    .modal-header {
        padding: 16px 20px;
    }
    
    .modal-header h2 {
        font-size: 18px;
    }
    
    .modal-body {
        padding: 20px;
        padding-bottom: calc(100px + env(safe-area-inset-bottom, 0px));
    }
    
    .product-modal-image {
        max-height: 250px;
        object-fit: contain;
    }
    
    .product-modal-price {
        font-size: 26px;
    }
    
    .variant-buttons {
        display: flex;
        flex-direction: column;
        gap: 8px;
    }
    
    .modal-variant-btn {
        width: 100%;
        text-align: left;
    }
    
    /* ==========================================
       NO EVENT MESSAGE - MOBILE
       ========================================== */
    
    .no-event-container {
        padding: 32px 20px;
    }
    
    .no-event-icon {
        font-size: 64px;
    }
    
    .no-event-title {
        font-size: 24px;
    }
    
    .no-event-text {
        font-size: 15px;
    }
    
    /* ==========================================
       CART NOTIFICATION - MOBILE
       ========================================== */
    
    .cart-notification-message {
        font-size: 12px;
        padding: 10px 12px;
    }
    
    /* ==========================================
       TOAST NOTIFICATIONS - MOBILE
       ========================================== */
    
    #toast-container {
        top: calc(80px + env(safe-area-inset-top, 0px)) !important;
        right: 16px !important;
        left: 16px !important;
    }
    
    body.admin-mode #toast-container,
    body.user-mode #toast-container {
        top: calc(80px + env(safe-area-inset-top, 0px)) !important;
    }
    
    .toast {
        max-width: 100% !important;
    }
    
    /* ==========================================
       EVENT INFO WIDGET - MOBILE
       ========================================== */
    
    .mobile-event-info {
        background: white;
        border-radius: 16px;
        padding: 16px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
        border: 1px solid #e5e7eb;
        margin-bottom: 16px;
    }
    
    .mobile-event-title {
        font-size: 16px;
        font-weight: 700;
        color: #1e293b;
        margin-bottom: 12px;
    }
    
    .mobile-event-meta {
        display: flex;
        flex-direction: column;
        gap: 8px;
        font-size: 13px;
        color: #64748b;
    }
    
    .mobile-event-meta-item {
        display: flex;
        align-items: center;
        gap: 8px;
    }
    
    .mobile-event-meta-item .icon {
        width: 16px;
        height: 16px;
        color: #8b5cf6;
    }
    
    .mobile-event-status-active {
        display: inline-flex;
        align-items: center;
        gap: 8px;
        padding: 8px 12px;
        background: linear-gradient(135deg, #10b981 0%, #059669 100%);
        color: white;
        border-radius: 10px;
        font-size: 12px;
        font-weight: 700;
        margin-top: 12px;
    }
    
    .mobile-event-status-active .status-indicator {
        width: 8px;
        height: 8px;
        background: white;
        border-radius: 50%;
        animation: blink 1s infinite;
    }
    
    .mobile-event-status-upcoming {
        display: inline-flex;
        align-items: center;
        gap: 8px;
        padding: 8px 12px;
        background: rgba(59, 130, 246, 0.1);
        color: #2563eb;
        border-radius: 10px;
        font-size: 12px;
        font-weight: 700;
        margin-top: 12px;
    }
    
    .mobile-event-status-upcoming .icon {
        width: 16px;
        height: 16px;
    }
    
    .mobile-event-status-none {
        text-align: center;
        padding: 20px;
        color: #9ca3af;
        font-size: 14px;
    }
    
    /* ==========================================
       MOBILE COUNTDOWN
       ========================================== */
    
    .mobile-countdown {
        background: white;
        border-radius: 12px;
        padding: 16px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
        border: 1px solid #e5e7eb;
        text-align: center;
    }
    
    .mobile-countdown-title {
        font-size: 12px;
        font-weight: 700;
        color: #64748b;
        margin-bottom: 8px;
        text-transform: uppercase;
        letter-spacing: 0.5px;
    }
    
    .mobile-countdown-display {
        font-size: 18px;
        font-weight: 800;
        color: #ec4899;
    }
    
    /* ==========================================
       UTILITY CLASSES
       ========================================== */
    
    .mobile-only {
        display: block !important;
    }
    
    .hide-on-mobile {
        display: none !important;
    }
}

/* ==========================================
   LANDSCAPE MODE - SPECIAL HANDLING
   ========================================== */

@media (max-width: 1024px) and (orientation: landscape) {
    .chat-messages {
        padding-bottom: calc(70px + env(safe-area-inset-bottom, 0px));
    }
    
    .emoji-picker {
        height: 80vh;
        max-height: 500px;
    }
}

/* ==========================================
   SAFE AREA INSETS FOR NOTCHED DEVICES
   ========================================== */

@supports (padding: max(0px)) {
    @media (max-width: 1024px) {
        .chat-input {
            padding-left: max(16px, env(safe-area-inset-left));
            padding-right: max(16px, env(safe-area-inset-right));
            padding-bottom: max(12px, env(safe-area-inset-bottom));
        }
        
        .mobile-sidebar-panel {
            padding-left: env(safe-area-inset-left);
            padding-right: env(safe-area-inset-right);
        }
    }
}