/**
 * WP Stories Vue Editor - Mobile Specific Styles
 * Touch-optimized UI for mobile devices
 */

/* Apply mobile styles based on viewport OR mobile class */
@media screen and (max-width: 768px) {
    .wp-stories-vue-editor-modal {
        /* Force mobile layout in responsive mode */
    }
    
    /* Import mobile styles for viewport-based detection */
    .wp-stories-vue-editor-modal .mobile-top-nav,
    .wp-stories-vue-editor-modal .mobile-bottom-nav {
        display: flex !important;
    }
}

/* Mobile Modal - Full Screen */
.wp-stories-vue-editor-modal.mobile,
.wp-stories-vue-editor-modal.mobile-viewport {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 999999;
    display: flex;
    flex-direction: column;
}

.wp-stories-vue-editor-modal.mobile .editor-container {
    width: 100vw;
    height: 100vh;
    max-width: none;
    max-height: none;
    border-radius: 0;
    background: #1a1a1a;
    display: flex;
    flex-direction: column;
}

/* Simple Header Bar */
.wp-stories-vue-editor-modal.mobile .mobile-simple-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 15px;
    background: #222;
    border-bottom: 1px solid #333;
    min-height: 60px;
    flex-shrink: 0;
}

.wp-stories-vue-editor-modal.mobile .mobile-simple-header h3 {
    color: #fff;
    margin: 0;
    font-size: 18px;
    font-weight: 500;
}

.wp-stories-vue-editor-modal.mobile .mobile-simple-header .btn-cancel,
.wp-stories-vue-editor-modal.mobile .mobile-simple-header .btn-save {
    background: transparent;
    border: none;
    color: #fff;
    padding: 8px 12px;
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 14px;
    cursor: pointer;
    border-radius: 4px;
    transition: background 0.2s;
}

.wp-stories-vue-editor-modal.mobile .mobile-simple-header .btn-cancel:hover {
    background: rgba(255, 255, 255, 0.1);
}

.wp-stories-vue-editor-modal.mobile .mobile-simple-header .btn-save {
    background: #007cba;
    color: white;
}

.wp-stories-vue-editor-modal.mobile .mobile-simple-header .btn-save:hover {
    background: #0066a0;
}

/* Editor Body - Let TUI Handle Layout */
.wp-stories-vue-editor-modal.mobile .editor-body {
    flex: 1;
    overflow: hidden;
    position: relative;
    background: #1a1a1a;
    display: flex;
    flex-direction: column;
}

/* TUI Editor Container - Full Size */
.wp-stories-vue-editor-modal.mobile .tui-image-editor-container {
    width: 100% !important;
    height: 100% !important;
    position: relative !important;
}

/* Force TUI controls to be visible on mobile */
.wp-stories-vue-editor-modal.mobile .tui-image-editor {
    width: 100% !important;
    height: 100% !important;
}

.wp-stories-vue-editor-modal.mobile .tui-image-editor-menu {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
    pointer-events: auto !important;
    position: relative !important;
    left: 0 !important;
    bottom: 0 !important;
}

.wp-stories-vue-editor-modal.mobile .tui-image-editor-main {
    top: 0 !important;
}

.wp-stories-vue-editor-modal.mobile .tui-image-editor-wrap {
    bottom: auto !important;
}

.wp-stories-vue-editor-modal.mobile .btn-back {
    background: none;
    border: none;
    color: #fff;
    padding: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
}

.wp-stories-vue-editor-modal.mobile .top-tools {
    display: flex;
    gap: 8px;
    flex: 1;
    justify-content: center;
}

.wp-stories-vue-editor-modal.mobile .tool-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: #fff;
    padding: 10px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
    transition: background 0.2s;
}

.wp-stories-vue-editor-modal.mobile .tool-btn:active {
    background: rgba(255, 255, 255, 0.2);
}

.wp-stories-vue-editor-modal.mobile .tool-btn:disabled {
    opacity: 0.3;
    pointer-events: none;
}

.wp-stories-vue-editor-modal.mobile .btn-save {
    background: #667eea;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 600;
    min-height: 44px;
}

/* Editor Body - Central Image Display Area */
.wp-stories-vue-editor-modal.mobile .editor-body {
    flex: 1;
    overflow: hidden;
    position: relative;
    background: #1a1a1a;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* TUI Container - Mobile */
.wp-stories-vue-editor-modal.mobile .tui-image-editor-container {
    width: 100%;
    height: 100%;
    background: #1a1a1a;
    position: relative;
}

/* Bottom Navigation Bar */
.wp-stories-vue-editor-modal.mobile .mobile-bottom-nav {
    background: #222;
    border-top: 1px solid #333;
    padding: 10px 0;
    flex-shrink: 0;
}

.wp-stories-vue-editor-modal.mobile .tool-menu {
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 0 10px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.wp-stories-vue-editor-modal.mobile .menu-item {
    background: none;
    border: none;
    color: #888;
    padding: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-width: 60px;
    transition: all 0.2s;
    cursor: pointer;
}

.wp-stories-vue-editor-modal.mobile .menu-item.active {
    color: #667eea;
}

.wp-stories-vue-editor-modal.mobile .menu-item .tool-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    margin-bottom: 4px;
}

.wp-stories-vue-editor-modal.mobile .menu-item .tool-label {
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Show TUI's default menu for mobile - removed display:none */
.wp-stories-vue-editor-modal.mobile .tui-image-editor-menu {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
    pointer-events: auto !important;
}

.wp-stories-vue-editor-modal.mobile .tui-image-editor-controls {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    pointer-events: auto !important;
}

/* Menu Items - Larger for Touch */
.wp-stories-vue-editor-modal.mobile .tui-image-editor-item {
    min-width: 60px;
    min-height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    margin: 0 5px;
}

.wp-stories-vue-editor-modal.mobile .tui-image-editor-item svg {
    width: 28px !important;
    height: 28px !important;
}

/* Active state - more visible on mobile */
.wp-stories-vue-editor-modal.mobile .tui-image-editor-item.active {
    background: #667eea;
}

/* Submenu for Mobile - Slide up panel with scroll for ALL submenus */
.wp-stories-vue-editor-modal.mobile .tui-image-editor-submenu {
    position: fixed;
    bottom: 80px;
    left: 10%; /* Add margin from sides */
    right: 10%; /* Add margin from sides */
    width: 80%; /* Reduce width to 80% of viewport */
    height: auto;
    max-height: 35vh; /* Further reduced for better mobile experience */
    background: #2a2a2a;
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.5);
    padding: 15px;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    -webkit-overflow-scrolling: touch;
    z-index: 1000;
    /* Scroll indicator */
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.3) transparent;
    /* Center the submenu */
    margin: 0 auto;
}

/* Ensure the submenu content area is scrollable */
.wp-stories-vue-editor-modal.mobile .tui-image-editor-submenu-style {
    max-height: 100%;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    -webkit-overflow-scrolling: touch;
}

/* Custom scrollbar for webkit browsers */
.wp-stories-vue-editor-modal.mobile .tui-image-editor-submenu::-webkit-scrollbar,
.wp-stories-vue-editor-modal.mobile .tui-image-editor-submenu-style::-webkit-scrollbar {
    width: 6px;
}

.wp-stories-vue-editor-modal.mobile .tui-image-editor-submenu::-webkit-scrollbar-track,
.wp-stories-vue-editor-modal.mobile .tui-image-editor-submenu-style::-webkit-scrollbar-track {
    background: transparent;
}

.wp-stories-vue-editor-modal.mobile .tui-image-editor-submenu::-webkit-scrollbar-thumb,
.wp-stories-vue-editor-modal.mobile .tui-image-editor-submenu-style::-webkit-scrollbar-thumb {
    background-color: rgba(255, 255, 255, 0.3);
    border-radius: 3px;
}

.wp-stories-vue-editor-modal.mobile .tui-image-editor-submenu::-webkit-scrollbar-thumb:hover,
.wp-stories-vue-editor-modal.mobile .tui-image-editor-submenu-style::-webkit-scrollbar-thumb:hover {
    background-color: rgba(255, 255, 255, 0.5);
}

/* Submenu Items - Touch Optimized */
.wp-stories-vue-editor-modal.mobile .tui-image-editor-submenu-item {
    min-height: 50px;
    padding: 12px 16px;
    margin: 5px 0;
    border-radius: 10px;
    font-size: 14px;
}

/* Range Sliders - Bigger for Touch */
.wp-stories-vue-editor-modal.mobile .tui-image-editor-range {
    padding: 15px 0;
}

.wp-stories-vue-editor-modal.mobile .tui-image-editor-range-bar {
    height: 6px;
    border-radius: 3px;
}

.wp-stories-vue-editor-modal.mobile .tui-image-editor-range-pointer {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

/* Buttons - Touch Size */
.wp-stories-vue-editor-modal.mobile .tui-image-editor-button {
    min-height: 44px;
    padding: 12px 20px;
    font-size: 14px;
    border-radius: 8px;
}

/* Color Picker - Mobile Optimized */
.wp-stories-vue-editor-modal.mobile .tui-colorpicker-container {
    padding: 10px;
}

.wp-stories-vue-editor-modal.mobile .tui-colorpicker-palette-button {
    width: 40px;
    height: 40px;
    margin: 4px;
    border-radius: 8px;
}

/* Canvas Container - Mobile */
.wp-stories-vue-editor-modal.mobile .tui-image-editor-canvas-container {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 80px; /* Account for bottom menu */
    background: #1a1a1a;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

/* Loading State - Mobile */
.wp-stories-vue-editor-modal.mobile .editor-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: #fff;
}

/* Prevent body scroll when editor is open */
body.wp-stories-editor-open {
    overflow: hidden;
    position: fixed;
    width: 100%;
    height: 100%;
}

/* Landscape Mode Adjustments */
@media screen and (orientation: landscape) and (max-height: 500px) {
    .wp-stories-vue-editor-modal.mobile .mobile-header {
        min-height: 50px;
        padding: 5px 15px;
    }
    
    .wp-stories-vue-editor-modal.mobile .tui-image-editor-menu {
        height: 60px;
    }
    
    .wp-stories-vue-editor-modal.mobile .tui-image-editor-item {
        min-width: 50px;
        min-height: 50px;
    }
    
    .wp-stories-vue-editor-modal.mobile .tui-image-editor-canvas-container {
        bottom: 60px;
    }
}

/* Small Mobile Screens */
@media screen and (max-width: 360px) {
    .wp-stories-vue-editor-modal.mobile .mobile-header h2 {
        font-size: 16px;
    }
    
    .wp-stories-vue-editor-modal.mobile .btn-save {
        padding: 8px 16px;
        font-size: 13px;
    }
    
    .wp-stories-vue-editor-modal.mobile .tui-image-editor-item {
        min-width: 50px;
        margin: 0 2px;
    }
    
    /* Wider submenu on very small screens */
    .wp-stories-vue-editor-modal.mobile .tui-image-editor-submenu {
        left: 5%;
        right: 5%;
        width: 90%;
    }
}

/* Medium Mobile Screens */
@media screen and (min-width: 375px) and (max-width: 414px) {
    .wp-stories-vue-editor-modal.mobile .tui-image-editor-submenu {
        left: 8%;
        right: 8%;
        width: 84%;
    }
}

/* Larger Mobile Screens / Small Tablets */
@media screen and (min-width: 415px) and (max-width: 768px) {
    .wp-stories-vue-editor-modal.mobile .tui-image-editor-submenu {
        left: 15%;
        right: 15%;
        width: 70%;
    }
}

/* iOS Specific Fixes */
@supports (-webkit-touch-callout: none) {
    .wp-stories-vue-editor-modal.mobile {
        height: -webkit-fill-available;
    }
    
    .wp-stories-vue-editor-modal.mobile .editor-container {
        height: -webkit-fill-available;
    }
    
    /* Prevent iOS bounce scrolling */
    .wp-stories-vue-editor-modal.mobile .tui-image-editor-canvas-container {
        -webkit-overflow-scrolling: auto;
    }
}

/* Touch Selection Handles */
.wp-stories-vue-editor-modal.mobile .canvas-container {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

/* Larger touch targets for control points */
.wp-stories-vue-editor-modal.mobile .canvas-container .upper-canvas {
    touch-action: none;
}

/* Hide desktop-only features on mobile */
.wp-stories-vue-editor-modal.mobile .tui-image-editor-header,
.wp-stories-vue-editor-modal.mobile .tui-image-editor-help-menu {
    display: none !important;
}

/* Ensure TUI controls are touch-friendly and visible */
.wp-stories-vue-editor-modal.mobile .tui-image-editor-submenu {
    z-index: 10001 !important;
}

.wp-stories-vue-editor-modal.mobile .tui-image-editor-menu-mask {
    display: none !important;
}

/* Ensure menu buttons are clickable */
.wp-stories-vue-editor-modal.mobile .tui-image-editor-menu-btn {
    pointer-events: auto !important;
    cursor: pointer !important;
}

/* Ensure submenus are visible when active */
.wp-stories-vue-editor-modal.mobile .tui-image-editor-submenu-style {
    display: block !important;
    visibility: visible !important;
}

/* Visual scroll indicator - gradient fade for overflow content */
.wp-stories-vue-editor-modal.mobile .tui-image-editor-submenu::before {
    content: '';
    position: sticky;
    top: 0;
    left: -15px; /* Extend gradient to cover padding */
    right: -15px; /* Extend gradient to cover padding */
    height: 15px;
    background: linear-gradient(to bottom, #2a2a2a, transparent);
    pointer-events: none;
    z-index: 1;
    margin-bottom: -15px;
}

.wp-stories-vue-editor-modal.mobile .tui-image-editor-submenu::after {
    content: '';
    position: sticky;
    bottom: 0;
    left: -15px; /* Extend gradient to cover padding */
    right: -15px; /* Extend gradient to cover padding */
    height: 15px;
    background: linear-gradient(to top, #2a2a2a, transparent);
    pointer-events: none;
    margin-top: -15px;
}

/* Ensure all submenu content is contained properly */
.wp-stories-vue-editor-modal.mobile .tui-image-editor-submenu-align,
.wp-stories-vue-editor-modal.mobile .tie-text-effect-button,
.wp-stories-vue-editor-modal.mobile .tui-image-editor-checkbox-wrap,
.wp-stories-vue-editor-modal.mobile .tui-image-editor-newline {
    margin-bottom: 10px;
    padding: 5px 0;
}

/* Ensure draw, text, and other tool submenus scroll properly */
.wp-stories-vue-editor-modal.mobile .tie-draw-line-select-button,
.wp-stories-vue-editor-modal.mobile .tie-color-fill-button,
.wp-stories-vue-editor-modal.mobile .tie-text-align-button {
    margin-bottom: 10px;
}

/* Compact the submenu items for better mobile fit */
.wp-stories-vue-editor-modal.mobile .tui-image-editor-submenu-item {
    padding: 8px 12px;
    margin: 3px 0;
}