/* ============ RESET & BASE ============ */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --green: #16a34a;
    --green-light: #22c55e;
    --green-dark: #14532d;
    --mango: #f59e0b;
    --bg: #f8fdf9;
    --card: #ffffff;
    --text: #1a2e1a;
    --muted: #6b7280;
}

/* ============ CRITICAL LAYOUT ============ */
html, body {
    height: 100vh;
    max-height: 100vh;
    overflow: hidden;
    margin: 0;
    padding: 0;
    background: var(--bg);
    font-family: 'Nunito', sans-serif;
}

#app {
    height: 100vh;
    max-height: 100vh;
    width: 100%;
    overflow: hidden !important;
    display: flex;
    flex-direction: column;
    margin: 0;
    padding: 0;
    position: relative;
}

/* ============ SCREEN MANAGEMENT ============ */
.screen {
    display: none;
    min-height: 100vh;
    background: #f0fdf4;
}

.screen.active {
    display: block;
}

#screen-welcome:not(.active),
#screen-setup:not(.active) {
    display: none !important;
}

/* ============ MAIN SCREEN ============ */
#screen-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding-top: 70px;
    padding-bottom: 0;
    background: #f0fdf4;
}

/* ============ PRODUCTS CONTAINER ============ */
#products-grid-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding-bottom: 10px;
    -webkit-overflow-scrolling: touch;
}

/* ============ HEADER ============ */
.main-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 200;
    background: linear-gradient(135deg, #14532d, #16a34a, #22c55e);
    padding: 12px;
    color: white;
}

/* ============ FOOTER ============ */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 200;
    background: white;
    border-top: 1px solid #e5e7eb;
    padding: 5px 0;
    display: flex;
}

/* ============ TAB PANELS ============ */
.tab-panel {
    position: fixed;
    top: 70px;
    left: 0;
    right: 0;
    bottom: 0;
    background: #f0fdf4;
    z-index: 100;
    display: none;
    overflow-y: auto;
}

.tab-panel.active {
    display: block !important;
}

/* ============ CART SIDEBAR ============ */
.cart-sidebar {
    position: fixed;
    top: 0;
    right: -380px;
    width: 360px;
    height: 100vh;
    background: white;
    z-index: 1002;
    transition: right 0.3s ease;
    box-shadow: -2px 0 10px rgba(0,0,0,0.2);
}

.cart-sidebar.open {
    right: 0;
}

/* ============ PRODUCTS GRID ============ */
#products-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    padding: 12px;
}

/* ============ SCROLLBAR ============ */
::-webkit-scrollbar {
    width: 3px;
    height: 3px;
}

::-webkit-scrollbar-thumb {
    background: #bbf7d0;
    border-radius: 999px;
}

/* ============ UTILITY CLASSES ============ */
.hidden {
    display: none !important;
}

.sticky-search {
    position: sticky;
    top: 0;
    z-index: 10;
    background: #f0fdf4;
}

/* ============ NAVIGATION BUTTONS ============ */
.nav-btn {
    flex: 1;
    text-align: center;
    padding: 10px 0;
    cursor: pointer;
    border-radius: 12px;
    color: #6b7280;
    background: transparent;
    border: none;
}

.nav-btn.active {
    background: #f0fdf4;
    color: var(--green) !important;
}

/* ============ CATEGORY PILLS ============ */
.cat-pill {
    padding: 6px 12px;
    border-radius: 9999px;
    cursor: pointer;
    font-size: 12px;
    font-weight: bold;
    white-space: nowrap;
}

.cat-pill.active {
    background: var(--green);
    color: white;
}

.cat-pill.inactive {
    background: #e5e7eb;
    color: #4b5563;
}

/* ============ PRODUCT CARD ============ */
.product-card {
    background: white;
    border-radius: 12px;
    padding: 10px 5px;
    text-align: center;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    cursor: pointer;
}

.product-card:active {
    transform: scale(0.96);
}

/* ============ TOAST NOTIFICATIONS ============ */
.toast, #global-toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: #14532d;
    color: white;
    padding: 8px 18px;
    border-radius: 999px;
    font-weight: 700;
    font-size: 0.85rem;
    z-index: 10001;
}

.toast.error {
    background: #dc2626;
}

/* ============ LOADING OVERLAY ============ */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 99999;
}

.loading-overlay.show {
    display: flex;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid white;
    border-top-color: var(--green);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ============ ADMIN SIDEBAR - COMPLETE FIX ============ */

#adminSidebar {
    position: fixed !important;
    top: 0 !important;
    right: 0 !important;
    width: 280px !important;
    max-width: 85% !important;
    height: 100% !important;
    background: white !important;
    box-shadow: -2px 0 10px rgba(0,0,0,0.2) !important;
    z-index: 10000 !important;
    overflow-y: auto !important;
    /* Start hidden - off screen to the right */
    transform: translateX(100%) !important;
    transition: transform 0.3s ease-out !important;
}

/* When open - slide into view */
#adminSidebar.open {
    transform: translateX(0) !important;
}

/* Sidebar header */
#adminSidebar .admin-sidebar-header {
    padding: 16px;
    background: #16a34a;
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}

#adminSidebar .admin-sidebar-header h3 {
    margin: 0;
    font-size: 18px;
    flex: 1;
    text-align: center;
}

/* Back button (←) */
#adminSidebar .back-sidebar-btn {
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    font-size: 18px;
    cursor: pointer;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

#adminSidebar .back-sidebar-btn:active {
    background: rgba(255,255,255,0.4);
    transform: scale(0.95);
}

/* Close button (✕) */
#adminSidebar .close-sidebar {
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    font-size: 18px;
    cursor: pointer;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

#adminSidebar .close-sidebar:active {
    background: rgba(255,255,255,0.4);
    transform: scale(0.95);
}

/* Navigation links */
#adminSidebar .nav-link {
    padding: 14px 16px;
    cursor: pointer;
    border-bottom: 1px solid #e5e7eb;
    font-size: 15px;
    color: #374151;
}

#adminSidebar .nav-link:active {
    background: #f0fdf4;
}

#adminSidebar .nav-link.active {
    background: #dcfce7;
    color: #166534;
    border-left: 3px solid #22c55e;
}

/* Overlay */
#adminOverlay {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    background: rgba(0,0,0,0.5) !important;
    z-index: 9999 !important;
    opacity: 0 !important;
    visibility: hidden !important;
    transition: opacity 0.3s ease !important;
}

#adminOverlay.visible {
    opacity: 1 !important;
    visibility: visible !important;
}

/* Content Panel */
#adminContentPanel {
    position: fixed !important;
    top: 0 !important;
    right: 0 !important;
    width: 100% !important;
    max-width: 500px !important;
    height: 100% !important;
    background: #f9fafb !important;
    z-index: 10001 !important;
    transform: translateX(100%) !important;
    transition: transform 0.3s ease-out !important;
    overflow-y: auto !important;
}

#adminContentPanel.visible {
    transform: translateX(0) !important;
}

/* Admin button active state */
.admin-btn-active {
    background: #16a34a !important;
    color: white !important;
}

/* Mobile optimizations */
@media (max-width: 640px) {
    #adminSidebar {
        width: 85% !important;
        max-width: 280px !important;
    }
    #adminContentPanel {
        max-width: 100% !important;
    }
    #adminSidebar .nav-link {
        padding: 12px 16px;
        font-size: 14px;
    }
}

/* Ensure admin elements are above everything */
#adminOverlay,
#adminSidebar,
#adminContentPanel {
    position: fixed;
}

/* Make sure they are not affected by any parent */
body > #adminOverlay,
body > #adminSidebar,
body > #adminContentPanel {
    z-index: 10000;
}

/* Ensure buttons are clickable */
#screen-welcome button,
#screen-welcome div[onclick] {
    cursor: pointer;
    pointer-events: auto !important;
    position: relative;
    z-index: 10;
}

/* Ensure no overlay is blocking clicks */
#screen-welcome {
    position: relative;
    z-index: 1;
}

.modal-overlay {
    z-index: 10000;
}