/* Layout fixes for dev console open and responsive issues */

/* Mobile menu toggle button - hidden by default on desktop */
.mobile-menu-toggle {
    display: none !important;
    background: none !important;
    border: none !important;
    padding: 8px !important;
    cursor: pointer !important;
    margin-right: 10px !important;
    width: 30px !important;
    height: 30px !important;
    position: relative !important;
    border-radius: 4px !important;
    transition: background-color 0.2s ease !important;
    outline: none !important;
    box-shadow: none !important;
}

.mobile-menu-toggle:hover {
    background-color: rgba(255,255,255,0.1) !important;
}

/* Custom hamburger icon with white lines */
.mobile-menu-toggle .fas {
    display: none;
}

.mobile-menu-toggle::before,
.mobile-menu-toggle::after,
.mobile-menu-toggle {
    position: relative;
}

.mobile-menu-toggle::before {
    content: '';
    position: absolute;
    top: 8px;
    left: 6px;
    width: 18px;
    height: 2px;
    background: white;
    border-radius: 1px;
    box-shadow: 
        0 6px 0 white,
        0 12px 0 white,
        0 1px 2px rgba(0,0,0,0.2),
        0 7px 2px rgba(0,0,0,0.2),
        0 13px 2px rgba(0,0,0,0.2);
    transition: all 0.3s ease;
}

/* Desktop - hide mobile toggle completely */
@media (min-width: 1260px) {
    .mobile-menu-toggle {
        display: none !important;
        visibility: hidden !important;
        opacity: 0 !important;
        position: absolute !important;
        left: -9999px !important;
    }
}

/* Force mobile mode when screen width is less than 1260px */
@media (max-width: 1259px) {
    /* Hide desktop menu */
    .admin-menu {
        display: none !important;
    }

    /* Show mobile menu toggle */
    .mobile-menu-toggle {
        display: block !important;
    }

    /* Full width for content when menu is hidden */
    .col-xl-2, .col-lg-4 {
        display: none !important;
    }

    .col-xl-10, .col-lg-8 {
        flex: 0 0 100% !important;
        max-width: 100% !important;
    }

    /* Remove padding from containers */
    body > div.container-fluid {
        padding-left: 0 !important;
        padding-right: 0 !important;
    }

    body > div.container-fluid div.col-md-12 {
        padding-left: 0 !important;
        padding-right: 0 !important;
    }

    body > div.container-fluid div.container-fluid {
        padding-left: 0 !important;
        padding-right: 0 !important;
    }

    /* Adjust table scroll height for mobile - DISABLED to allow tables to grow naturally */
    /* .admin-table-scroll {
        max-height: calc(100vh - 50px) !important;
    } */

    /* Remove table spacing for mobile */
    .admin-table {
        border-spacing: 0 !important;
        border-collapse: collapse !important;
    }

    /* Mobile menu styles */
    .mobile-menu {
        position: fixed;
        top: 0;
        left: -320px;
        width: 300px;
        height: 100vh;
        background: #fff;
        border-right: 1px solid #ddd;
        z-index: 9999;
        transition: left 0.3s ease;
        overflow-y: auto;
        box-shadow: 2px 0 5px rgba(0,0,0,0.1);
    }
    
    .mobile-menu.active {
        left: 0;
    }
    
    .mobile-menu-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        background: rgba(0,0,0,0.5);
        z-index: 9998;
        display: none;
    }
    
    .mobile-menu-overlay.active {
        display: block;
    }
    
    /* Reset all menu styles for mobile */
    .mobile-menu * {
        box-sizing: border-box;
    }
    
    .mobile-menu ul {
        list-style: none !important;
        padding: 0 !important;
        margin: 0 !important;
    }
    
    .mobile-menu li {
        margin: 0 !important;
        padding: 0 !important;
        border-bottom: 1px solid #eee;
    }
    
    .mobile-menu a {
        display: block !important;
        padding: 15px 20px !important;
        color: #333 !important;
        text-decoration: none !important;
        background: transparent !important;
        border: none !important;
        width: 100% !important;
        text-align: left !important;
        font-size: 14px !important;
        line-height: 1.4 !important;
    }
    
    .mobile-menu a:hover {
        background-color: #f8f9fa !important;
        color: #333 !important;
    }
    
    .mobile-menu a.active {
        background-color: #17564B !important;
        color: white !important;
    }
    
    /* Dropdown styles for mobile */
    .mobile-menu .dropdown-toggle {
        position: relative !important;
        cursor: pointer !important;
    }
    
    .mobile-menu .dropdown-toggle:after {
        content: "+" !important;
        position: absolute !important;
        right: 20px !important;
        top: 50% !important;
        transform: translateY(-50%) !important;
        font-size: 16px !important;
        line-height: 1 !important;
    }
    
    .mobile-menu .dropdown.open .dropdown-toggle:after,
    .mobile-menu .nav-item.dropdown.open .dropdown-toggle:after {
        content: "-" !important;
    }
    
    .mobile-menu .dropdown-menu-admin {
        display: none !important;
        background-color: #f8f9fa !important;
        margin: 0 !important;
        padding: 0 !important;
        border: none !important;
        box-shadow: none !important;
    }
    
    .mobile-menu .dropdown.open .dropdown-menu-admin,
    .mobile-menu .nav-item.dropdown.open .dropdown-menu-admin {
        display: block !important;
    }
    
    .mobile-menu .dropdown-menu-admin a {
        padding-left: 40px !important;
        background-color: #f8f9fa !important;
        font-size: 13px !important;
    }
}

/* Fix layout when dev console is open - height media queries */
@media (min-width: 1260px) and (max-height: 600px) {
    body {
        overflow-x: auto;
    }
    
    .container-fluid {
        max-width: 100vw;
        overflow-x: auto;
    }
    
    .admin-menu {
        max-height: 400px;
        overflow-y: auto;
        overflow-x: hidden;
    }
    
    .dropdown-menu-admin {
        max-height: 200px;
        overflow-y: auto;
    }
    
    header {
        position: sticky;
        top: 0;
        z-index: 1000;
    }
    
    /* Prevent left menu from expanding full width */
    .col-xl-2, .col-lg-4 {
        max-width: 250px !important;
        flex: 0 0 250px !important;
    }
    
    .col-xl-10, .col-lg-8 {
        flex: 1 1 auto !important;
        max-width: calc(100% - 250px) !important;
    }
}

/* Additional fixes for very low height screens */
@media (min-width: 1260px) and (max-height: 400px) {
    .admin-menu {
        max-height: 250px;
    }
    
    .dropdown-menu-admin {
        max-height: 150px;
    }
    
    header {
        padding: 5px 10px;
    }
    
    .breadcrumb {
        padding: 0.25rem 0.5rem;
        margin-bottom: 0.5rem;
    }
}

/* Fix obj-goods layout when dev console is open */
@media (min-width: 1260px) and (max-height: 600px) {
    .obj-goods-page {
        overflow-x: auto;
    }
    
    .obj-goods-cards-container {
        max-width: 100%;
        overflow-x: visible;
    }
    
    .obj-goods-card {
        margin-bottom: 10px;
    }
    
    .obj-goods-details {
        grid-template-columns: 1fr;
    }
    
    .obj-goods-3d-container {
        width: 200px;
        min-width: 200px;
    }
    
    .obj-goods-page .list-item > div {
        width: 180px;
        height: 180px;
    }
}

/* Prevent layout shifts when console is opened */
@media (min-width: 768px) {
    .row {
        margin-right: 0;
        margin-left: 0;
    }

    .container-fluid {
        padding-right: 15px;
        padding-left: 15px;
    }

    /* Fix Bootstrap grid when height is constrained */
    [class*="col-"] {
        padding-right: 7.5px;
        padding-left: 7.5px;
    }
}

/* ============================================
   TOUCH DEVICE CONTROLS FOR TABLE CELLS
   ============================================ */

/* Detect touch devices using media queries */
@media (hover: none) and (pointer: coarse) {
    /* Hide edit pencil button */
    .table_edit_button {
        display: none !important;
    }

    /* Add visible menu icon for touch devices */
    .table_td_with_edit::after,
    .admin-table-info td:has(.table_edit_button)::after {
        content: '⋮';
        position: absolute;
        right: 5px;
        top: 50%;
        transform: translateY(-50%);
        font-size: 18px;
        font-weight: bold;
        color: #17564B;
        cursor: pointer;
        padding: 5px;
        z-index: 5;
        opacity: 0.6;
        transition: opacity 0.2s ease;
    }

    /* Highlight when active */
    .admin-table-info td.controls-visible::after,
    .table_td_with_edit.controls-visible::after {
        opacity: 1;
        color: #fff;
        background: #17564B;
        border-radius: 3px;
    }

    /* Ensure relative positioning for cells with controls */
    .admin-table-info td:has(.table_edit_button),
    .table_td_with_edit {
        position: relative;
    }
}

/* Also apply for narrow screens regardless of touch capability */
@media (max-width: 1259px) {
    /* Hide edit pencil button */
    .table_edit_button {
        display: none !important;
    }

    /* Add visible menu icon for narrow screens */
    .table_td_with_edit::after,
    .admin-table-info td:has(.table_edit_button)::after {
        content: '⋮';
        position: absolute;
        right: 5px;
        top: 50%;
        transform: translateY(-50%);
        font-size: 18px;
        font-weight: bold;
        color: #17564B;
        cursor: pointer;
        padding: 5px;
        z-index: 5;
        opacity: 0.6;
        transition: opacity 0.2s ease;
    }

    /* Highlight when active */
    .admin-table-info td.controls-visible::after,
    .table_td_with_edit.controls-visible::after {
        opacity: 1;
        color: #fff;
        background: #17564B;
        border-radius: 3px;
    }

    /* Ensure relative positioning for cells with controls */
    .admin-table-info td:has(.table_edit_button),
    .table_td_with_edit {
        position: relative;
    }
}

/* Center popups on smaller screens */
@media (max-width: 1023px) {
    /* Custom popups - center on screen */
    .table_td_with_edit_collapse,
    .table_td_with_edit .collapse,
    .table_details_tds_edit_container .card.card-body,
    .materials_filters_container .card.card-body {
        position: fixed !important;
        left: 50% !important;
        top: 50% !important;
        right: auto !important;
        transform: translate(-50%, -50%) !important;
        max-width: calc(100vw - 20px) !important;
        max-height: calc(100vh - 20px) !important;
        overflow-y: auto !important;
        z-index: 1050 !important;
    }
}