/* ========================================
   ENHANCED MOBILE ADMIN STYLES (RESPONSIVE)
   ======================================== */

/* Admin Toolbar Styles */
.page-header-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    gap: 1rem;
    flex-wrap: wrap;
}

.toolbar-actions {
    display: flex;
    gap: 1rem;
    align-items: center;
    flex-wrap: wrap;
}

.search-wrapper {
    position: relative;
    flex: 1;
}

.search-icon {
    position: absolute;
    left: 15px;
    top: 50%;
    transform: translateY(-50%);
    color: #ffffff;
    pointer-events: none;
}

.search-input {
    padding-left: 40px !important;
    width: 300px;
    transition: width 0.3s ease;
}

/* Mobile Adjustments */
@media (max-width: 900px) {

    /* Header & Layout Fixes */
    .main-content {
        padding-top: 80px !important;
        /* Ensure space for fixed toggler */
        padding-left: 15px !important;
        padding-right: 15px !important;
    }

    .page-header-toolbar {
        flex-direction: column;
        align-items: stretch;
        gap: 1rem;
        margin-top: 1rem;
        /* Push down to avoid overlap if any */
    }

    /* Search Bar Compactness */
    .toolbar-actions {
        flex-direction: column;
        width: 100%;
        gap: 0.8rem;
    }

    .search-wrapper {
        width: 100%;
    }

    .search-input {
        width: 100% !important;
        font-size: 14px;
        /* Prevent zoom */
        margin-top: 0.5rem;
        /* Extra buffer from top elements */
    }

    .btn-add-item {
        width: 100% !important;
        text-align: center;
        justify-content: center;
    }

    /* COMPACT CARD VIEW FOR MENU ITEMS */
    .mobile-card-view {
        display: block;
        /* Break table structure */
        width: 100%;
    }

    .mobile-card-view thead {
        display: none;
    }

    .mobile-card-view tbody {
        display: block;
        width: 100%;
    }

    .mobile-card-view tr {
        display: grid;
        grid-template-columns: 70px 1fr 1fr;
        /* Image | Name/Price | Status */
        grid-template-rows: auto auto auto;
        gap: 5px 10px;

        background: var(--glass-dark);
        border: 1px solid var(--glass-border);
        border-radius: 12px;
        padding: 10px;
        margin-bottom: 10px;
        position: relative;
        box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
    }

    /* Highlight Strip */
    .mobile-card-view tr::after {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        width: 4px;
        height: 100%;
        background: var(--primary);
        border-radius: 12px 0 0 12px;
    }

    /* 1. Image (Left Column, Spans Top 2 Rows) */
    .mobile-card-view td:first-child {
        grid-column: 1;
        grid-row: 1 / 3;
        display: flex;
        justify-content: center;
        align-items: center;
        padding: 0;
        border: none;
        height: 100%;
    }

    .mobile-card-view td:first-child img {
        width: 60px !important;
        height: 60px !important;
        object-fit: cover;
        border-radius: 8px !important;
        border: 1px solid var(--glass-border);
    }

    /* 2. Name (Right Top, Spans 2 Columns) */
    .mobile-card-view td:nth-child(2) {
        grid-column: 2 / 4;
        grid-row: 1;
        display: flex;
        flex-direction: column;
        justify-content: center;
        padding: 0;
        border: none;
        text-align: left;
    }

    .mobile-card-view td:nth-child(2) strong {
        font-size: 1rem;
        color: #fff;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 100%;
    }

    .mobile-card-view td:nth-child(2) small {
        display: none;
        /* Hide description on mobile to save space */
    }

    /* 3. Price (Row 2, Col 2) */
    .mobile-card-view td:nth-child(3) {
        grid-column: 2;
        grid-row: 2;
        padding: 0;
        border: none;
        align-self: start;
        text-align: left;
        font-size: 0.95rem;
    }

    /* Remove 'Price' Label */
    .mobile-card-view td:nth-child(3)::before {
        content: none !important;
    }

    /* 4. Status (Row 2, Col 3) */
    .mobile-card-view td:nth-child(4) {
        grid-column: 3;
        grid-row: 2;
        padding: 0;
        border: none;
        align-self: start;
        text-align: right;
    }

    /* Remove 'Status' Label */
    .mobile-card-view td:nth-child(4)::before {
        content: none !important;
    }

    .mobile-card-view .status-badge {
        font-size: 0.7rem;
        padding: 2px 6px;
    }

    /* 5. Actions (Row 3, Full Width) */
    .mobile-card-view td:last-child {
        grid-column: 1 / 4;
        grid-row: 3;
        padding: 8px 0 0 0;
        border: none;
        border-top: 1px solid rgba(255, 255, 255, 0.1);
        display: flex;
        gap: 8px;
    }

    .mobile-card-view td:last-child div {
        display: flex;
        width: 100%;
        gap: 8px;
    }

    .mobile-card-view td:last-child .btn-secondary {
        flex: 1;
        padding: 8px 0;
        display: flex;
        justify-content: center;
        align-items: center;
        background: rgba(255, 255, 255, 0.08);
        border-radius: 6px;
        border: none;
        color: var(--text-muted);
    }

    .mobile-card-view td:last-child .btn-secondary i {
        font-size: 1rem;
    }

    /* Modal Tweaks */
    #stockModal .btn-secondary {
        font-size: 0.8rem !important;
        padding: 8px 5px !important;
    }

    /* Category Header Stack */
    .category-header {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 0.5rem;
        margin-bottom: 0.5rem;
    }

    .category-title {
        font-size: 1.2rem;
        margin-bottom: 5px;
    }

    .category-header .btn {
        width: 100%;
        display: block;
        text-align: center;
        padding: 8px;
        font-size: 0.9rem;
    }
}

/* ========================================
   USER SIDE MENU FIXES (MOBILE GRID)
   ======================================== */
@media (max-width: 768px) {

    /* Ensure 2 columns */
    .menu-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px !important;
        padding-bottom: 2rem !important;
    }

    /* Compact Card */
    .menu-card {
        border-radius: 12px !important;
    }

    /* Smaller Image */
    .menu-img {
        height: 120px !important;
    }

    /* Compact Price Tag */
    .menu-price {
        font-size: 0.75rem !important;
        padding: 3px 8px !important;
        top: 8px !important;
        right: 8px !important;
        box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2) !important;
    }

    /* Compact Info */
    .menu-info {
        padding: 0.8rem !important;
    }

    .menu-info h4 {
        font-size: 0.95rem !important;
        margin-bottom: 4px !important;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .menu-info p {
        display: none !important;
        /* Hide description */
    }

    /* Compact Variants */
    .variant-group {
        gap: 5px !important;
        margin-bottom: 8px !important;
    }

    .radio-label {
        padding: 6px 4px !important;
        border-radius: 8px !important;
        font-size: 0.7rem !important;
        display: flex !important;
        flex-direction: column;
        justify-content: center;
        align-items: center;
    }

    .radio-label small {
        font-size: 0.65rem !important;
        margin-top: 1px !important;
    }

    .oos-tag {
        font-size: 0.5rem !important;
        padding: 1px 3px !important;
    }

    /* Compact 'Add to Cart' Button */
    .menu-info .btn {
        padding: 8px 0 !important;
        font-size: 0.8rem !important;
    }

    /* Category Header Compact */
    .category-section h3 {
        font-size: 1.4rem !important;
        margin-bottom: 1rem !important;
        padding-left: 0.8rem !important;
        margin-top: 1rem;
    }

    /* Search Bar Wrap */
    .hero {
        height: auto !important;
        padding: 80px 20px 40px !important;
        min-height: 50vh;
    }

    .section-title>div {
        flex-direction: column;
    }
}

/* ========================================
   TABLET & LANDSCAPE MOBILE OPTIMIZATIONS
   ======================================== */
@media (min-width: 481px) and (max-width: 1024px) {

    /* 1. Menu Grid - Restore Columns for Tablet/Landscape */
    .menu-grid {
        grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)) !important;
        gap: 1.5rem !important;
    }

    /* Restore fuller menu card for tablet (revert compact mobile styles if needed) */
    .menu-img {
        height: 180px !important;
    }

    .menu-info {
        padding: 1.2rem !important;
    }

    .menu-info p {
        display: block !important;
        /* Show description again if space permits */
        font-size: 0.85rem;
        margin-bottom: 0.5rem;
        display: -webkit-box !important;
        -webkit-line-clamp: 2;
        line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }

    .menu-price {
        font-size: 0.9rem !important;
        padding: 5px 12px !important;
    }

    .menu-info h4 {
        white-space: normal !important;
        /* Allow wrapping */
        font-size: 1.1rem !important;
    }

    /* 2. Admin Stats Grid - 2 Columns instead of stacked 1 */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    /* 3. Admin Grid Layout - 2 Columns */
    .admin-grid-layout {
        grid-template-columns: 1fr 1fr !important;
        gap: 2rem !important;
    }
}

/* Specific Fix for Admin Sidebar in Landscape Mobile */
@media (max-height: 600px) and (orientation: landscape) {
    .sidebar {
        z-index: 10001 !important;
        /* Ensure on top */
    }

    .sidebar.active {
        width: 100% !important;
        /* Full width menu on short screens for easier scrolling */
        max-width: 300px;
        /* But keep max width */
    }

    /* Fix Login/Center layouts */
    .login-card {
        margin: 20px auto;
        max-height: 90vh;
        overflow-y: auto;
    }

    .hero {
        min-height: 100vh !important;
        height: auto !important;
    }
}

/* Ensure Admin Tables Scroll nicely on Tablet */
@media (max-width: 1024px) {
    .table-container {
        overflow-x: auto;
        /* Scroll hint shadows */
        background: linear-gradient(to right, var(--glass-dark) 30%, rgba(255, 255, 255, 0)),
            linear-gradient(to right, rgba(255, 255, 255, 0), var(--glass-dark) 70%) 0 100%,
            radial-gradient(farthest-side at 0 50%, rgba(0, 0, 0, .4), rgba(0, 0, 0, 0)),
            radial-gradient(farthest-side at 100% 50%, rgba(0, 0, 0, .4), rgba(0, 0, 0, 0)) 0 100%;
        background-repeat: no-repeat;
        background-color: var(--glass-dark);
        background-size: 40px 100%, 40px 100%, 14px 100%, 14px 100%;
        background-position: 0 0, 100% 0, 0 0, 100% 0;
        background-attachment: local, local, scroll, scroll;
    }

    /* Relax the forced mobile card view if screen is wide enough */
    @media (min-width: 700px) {
        .mobile-card-view {
            display: none !important;
            /* Hide mobile cards */
        }

        /* Show normal table */
        table.table {
            display: table !important;
        }

        .table thead {
            display: table-header-group !important;
        }

        .table tbody {
            display: table-row-group !important;
        }

        .table tr {
            display: table-row !important;
            background: transparent !important;
            border: none !important;
            padding: 0 !important;
            margin: 0 !important;
            box-shadow: none !important;
        }

        .table td {
            display: table-cell !important;
            text-align: left !important;
            border-bottom: 1px solid var(--glass-border) !important;
            padding: 1rem 1.5rem !important;
        }

        .table tr::after {
            display: none !important;
        }
    }
}