/* Base Styling */
/* CRITICAL: Fix html and body to prevent outer scrolling */
html, body { 
    height: 100%; 
    margin: 0; 
    padding: 0; 
    overflow: hidden; /* This stops the entire page from sliding up/down */
}

body { 
    font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif; 
    background: #f0f2f5; 
    color: #1c1e21; 
}

/* CRITICAL: Set container to fill the viewport exactly */
.container { 
    max-width: 600px; 
    margin: auto; 
    background: white; 
    padding: 20px; 
    box-shadow: 0 2px 12px rgba(0,0,0,0.1); 
    position: relative; 
    
    /* Flexbox setup to allow internal scrolling */
    display: flex;
    flex-direction: column;
    height: 100vh;      /* Fallback */
    height: 100dvh;     /* Dynamic Viewport Height (handles mobile browser bars) */
    box-sizing: border-box; 
}

/* Header & Menu */
.header-row { 
    display: flex; 
    align-items: center; 
    justify-content: space-between; 
    margin-bottom: 20px; 
    border-bottom: 1px solid #ebedf0; 
    padding-bottom: 10px; 
    flex-shrink: 0; /* Prevents header from squishing */
}

/* CRITICAL: Allow the content area to scroll internally */
.tab-content {
    flex: 1;
    overflow-y: auto; 
    overflow-x: hidden;
    padding-right: 5px; /* Optional: space for scrollbar */
    -webkit-overflow-scrolling: touch; /* Smooth scrolling for iOS */
}



.menu-btn { background: #004085; color: white; border: none; padding: 12px 16px; border-radius: 8px; cursor: pointer; font-size: 24px; line-height: 1; }
h2 { margin: 0; color: #004085; font-size: 1.2rem; flex-grow: 1; text-align: center; }

.dropdown-nav { 
    position: absolute; top: 70px; left: 20px; background: white; width: 250px; 
    box-shadow: 0 4px 20px rgba(0,0,0,0.2); border-radius: 10px; display: none; z-index: 2000; border: 1px solid #ddd;
}
.nav-item { padding: 18px; cursor: pointer; border-bottom: 1px solid #f0f2f5; font-weight: 600; color: #444; font-size: 16px; }
.nav-item:active { background: #e7f3ff; color: #1877f2; }

/* Form Controls */
.form-group { margin-bottom: 15px; position: relative; }
label { display: block; margin-bottom: 5px; font-weight: 600; color: #4b4f56; font-size: 14px; }
input, select { 
    width: 100%; padding: 12px; box-sizing: border-box; border: 1px solid #ccd0d5; 
    border-radius: 8px; font-size: 16px; background-color: #f5f6f7;
}

.dispense-row { display: flex; gap: 10px; align-items: flex-end; }
.flex-grow { flex: 2; position: relative; }
.flex-small { flex: 0.5; }

.add-item-btn { 
    background: #007bff; 
    color: white; 
    border: none; 
    padding: 12px; 
    border-radius: 8px; 
    font-weight: bold; 
    cursor: pointer; 
    height: 46px; /* Matches your catalog buttons */
    font-size: 14px; /* Adjust to match your table buttons */
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
}

/* Search Results & Tables */
#search_results, .search-results-container {
    position: absolute; background: white; border: 1px solid #ddd; width: 100%; 
    max-height: 200px; overflow-y: auto; z-index: 1001; display: none; 
    box-shadow: 0 4px 12px rgba(0,0,0,0.15); border-radius: 8px;
}
.search-item { padding: 12px; border-bottom: 1px solid #f0f2f5; cursor: pointer; }
.search-item:hover { background: #f8f9fa; }

table { width: 100%; border-collapse: collapse; margin-top: 10px; }
th, td { padding: 12px 8px; border: 1px solid #dee2e6; text-align: left; font-size: 13px; }
th { background: #f8f9fa; color: #4b4f56; position: sticky; top: 0; z-index: 2; }

/* Queue & Management Features */
.queued-item { 
    display: flex; justify-content: space-between; background: #f8f9fa; 
    padding: 10px; border-radius: 6px; margin-bottom: 8px; border: 1px solid #eee;
}
.selected-row { background-color: #e7f3ff !important; outline: 2px solid #1877f2; }
#catalog_body tr { cursor: pointer; }

/* Modal Overlay */
#itemModal { 
    display: none; 
    position: fixed; 
    top: 0; 
    left: 0; 
    width: 100%; 
    height: 100%; 
    background: rgba(0,0,0,0.6); /* Slightly darker for better focus */
    z-index: 9999; /* Ensure it is above everything */
    
    /* These two keep the white box centered */
    align-items: center; 
    justify-content: center; 
}

/* Add this to ensure buttons don't grow too large */
.submit-btn {
    padding: 12px; /* Reduced from 16px to fit better in modals */
    font-size: 16px;
}

.message { padding: 15px; margin-bottom: 20px; border-radius: 8px; display: none; text-align: center; font-weight: bold; }

@media (max-width: 480px) {
    /* Remove extra padding and force full screen for mobile apps */
    .container { padding: 15px; border-radius: 0; height: 100dvh; }
    .dropdown-nav { width: calc(100% - 40px); left: 20px; }
}

/* Ensure the tab itself fills the container */
/* Ensure the tab itself fills the container and uses flex */
/* Ensure the tab behaves as a flex container that fills the available height */
#tab-manage {
    display: none; /* Controlled by JS showTab() */
    flex-direction: column;
    height: 100%;
    overflow: hidden; /* Prevents the tab itself from scrolling */
}

/* Explicitly prevent these containers from being pushed or squished */
.manage-header-actions, 
.manage-search-container {
    flex-shrink: 0;
    flex-grow: 0;
}

/* This is the magic part: flex: 1 makes it fill all remaining space */
.catalog-table-wrapper {
    flex: 1; 
    overflow-y: auto; 
    overflow-x: auto; 
    border: 1px solid #ddd; 
    border-radius: 8px;
    background: #fff;
    -webkit-overflow-scrolling: touch;
    min-height: 0; /* CRITICAL for Firefox/Chrome flex behavior */
}


#tab-summary {
    display: none; 
    flex-direction: column;
    height: 100%;
    overflow: hidden; /* <--- THIS MIGHT BE CLIPPING THE EXPANDED ROW */
}

/* Reusable wrapper for scrollable tables */
.table-scroll-wrapper {
    flex: 1;
    overflow-y: auto;
    overflow-x: auto;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    background: #fff;
    -webkit-overflow-scrolling: touch;
    min-height: 0;
}

/* Styling for the clickable parent row */
.inventory-parent-row {
    cursor: pointer;
    transition: background-color 0.2s;
}

.inventory-parent-row:hover {
    background-color: #f8f9fa;
}

/* Visual indicator that a row is expanded */
.row-active {
    background-color: #e7f3ff !important;
    border-left: 4px solid #1877f2;
}

/* The sub-table container */
.batch-container-row {
    display: none; /* Hidden by default */
    background-color: #fdfdfd;
}

.batch-table {
    width: 95%;
    margin: 5px auto 15px auto;
    border: 1px solid #eee;
    border-radius: 8px;
    overflow: hidden;
}

.batch-table th {
    background: #f1f3f5;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.batch-table td {
    font-size: 13px;
    color: #333;
}

/* 1. Styling for the white box inside the modal overlay */
.modal-content {
    background: white; 
    padding: 20px; 
    border-radius: 12px; 
    width: 90%; 
    max-width: 400px; 
    box-shadow: 0 4px 20px rgba(0,0,0,0.3); 
    box-sizing: border-box;
    position: relative; /* Keeps it above the overlay */
}

/* 2. Ensure table headers stick correctly in scrollable areas */
.catalog-table-wrapper, .table-scroll-wrapper {
    position: relative; 
}

/* 3. Better tap targets for the catalog list */
#catalog_body tr td {
    padding: 15px 10px;
    vertical-align: middle;
}