/* ======================================================
   Main Layout & Structure
   ====================================================== */

.page-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 10px 20px;
    box-sizing: border-box;
    min-height: 0;
}

.container {
    width: 100%;
    max-width: 1600px;
    min-width: 0; /* Remove 800px constraint to support mobile widths */
    margin: 0 auto;
    background: var(--card-background);
    border-radius: var(--radius-large);
    box-shadow: var(--card-shadow);
    padding: 15px 25px;
    box-sizing: border-box;
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

h1 {
    margin-top: 0;
    margin-bottom: 10px;
    font-size: 22px;
}

.page-title {
    margin-bottom: 10px;
}

/* ======================================================
   Header & Navigation
   ====================================================== */

.app-header {
    height: 60px;
    background: var(--primary-color);
    color: var(--header-text);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
    box-sizing: border-box;
    flex-shrink: 0;
}

.app-title-container {
    display: flex;
    align-items: center;
    gap: 15px;
}

.app-title a {
    color: var(--header-text);
    text-decoration: none;
    font-size: 22px;
    font-weight: bold;
}

.page-header-title {
    font-size: 18px;
    border-left: 2px solid rgba(255,255,255,.5);
    padding-left: 15px;
    font-weight: normal;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-back {
    height: 36px;
    padding: 0 12px;
    border: 1px solid rgba(255,255,255,.5);
    border-radius: var(--radius-small);
    background: transparent;
    color: var(--header-text);
    font-size: 14px;
    cursor: pointer;
}

.hamburger {
    background: transparent;
    border: none;
    font-size: 28px;
    color: var(--header-text);
    cursor: pointer;
}

.breadcrumbs {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 10px 25px 0;
    font-size: 13px;
    color: var(--sub-text-color);
    flex-shrink: 0;
}

.breadcrumbs a {
    color: var(--primary-color);
    text-decoration: none;
}

.breadcrumbs .separator {
    color: #999;
}

.breadcrumbs .current {
    font-weight: bold;
    color: var(--text-color);
}

.side-menu {
    position: fixed;
    top: 60px;
    right: -220px;
    width: 200px;
    background: var(--card-background);
    box-shadow: -2px 0 10px rgba(0,0,0,.15);
    transition: right .25s ease;
    z-index: 1000;
    border-left: 1px solid var(--border-color);
}

.side-menu.open {
    right: 0;
}

.side-menu a, .side-menu .menu-item {
    display: block;
    padding: 15px 20px;
    text-decoration: none;
    color: var(--text-color);
    font-weight: bold;
    border-bottom: 1px solid var(--border-color);
}

.side-menu a:hover, .side-menu .menu-item:hover {
    background: var(--table-header-bg);
}

/* Scrollable area for non-table pages */
.scrollable-content {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

/* ======================================================
   Responsive Layout & Media Queries
   ====================================================== */

@media (max-width: 1024px) {
    /* Release overflow hidden to let the page scroll organically if needed */
    html, body {
        height: auto !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        -webkit-overflow-scrolling: touch !important;
    }
    .page-content {
        padding: 5px 10px;
        overflow: visible !important;
        flex: none !important;
        display: block !important;
        min-height: calc(100vh - 60px);
    }
    .container {
        padding: 10px 12px;
        border-radius: var(--radius-medium);
        overflow: visible !important;
        flex: none !important;
        display: block !important;
        min-height: 0;
        box-shadow: none; /* Flatten styling slightly on mobile to feel native */
    }
    .scrollable-content {
        overflow: visible !important;
        overflow-y: visible !important;
        height: auto !important;
        min-height: 0 !important;
        flex: none !important;
    }
    /* Responsive image boxes for mobile/tablet */
    .image-box {
        min-width: 100% !important;
        max-width: 100% !important;
        flex: none !important;
    }
    .image-pair {
        gap: 15px !important;
    }
    .app-header {
        padding: 0 15px;
    }
    .app-title a {
        font-size: 18px;
    }
    .page-header-title {
        font-size: 14px;
        padding-left: 10px;
    }
    .breadcrumbs {
        margin: 5px 12px 0;
        font-size: 12px;
        flex-wrap: wrap;
    }
    /* Hide desktop-only header info */
    .header-actions .header-user-info {
        display: none !important;
    }
    /* Show user info in side menu instead */
    .side-menu .side-menu-user-info {
        display: block !important;
    }

    /* Fixed/Max Heights on Table Container for Mobile to sustain virtual scroll logic */
    .table-container {
        max-height: calc(100vh - 210px) !important;
        min-height: 240px;
        border-radius: var(--radius-small);
        margin-top: 10px;
        overflow: auto !important;
    }
}

@media (max-width: 480px) {
    .page-content {
        padding: 4px 6px;
        min-height: calc(100vh - 50px);
    }
    .container {
        padding: 8px 10px;
        border-radius: var(--radius-small);
    }
    .app-header {
        height: 50px;
        padding: 0 10px;
    }
    .app-title a {
        font-size: 16px;
    }
    .page-header-title {
        display: none; /* Hide sub-title in very small headers */
    }
    .header-actions {
        gap: 6px;
    }
    .header-back, .header-help {
        height: 30px;
        font-size: 12px;
        padding: 0 8px;
    }
    .hamburger {
        font-size: 24px;
    }
    .side-menu {
        top: 50px;
        width: 180px;
    }
    
    .table-container {
        max-height: calc(100vh - 190px) !important;
        min-height: 200px;
    }
}

/* ======================================================
   Landscape & Compact Screen Optimization
   ====================================================== */

/* Target landscape orientation on mobile phones or extra short viewports */
@media (max-height: 520px) {
    .app-header {
        height: 40px !important; /* Extremely thin header */
    }
    .app-title a {
        font-size: 15px !important;
    }
    .header-actions {
        gap: 6px !important;
    }
    .header-back, .header-help {
        height: 26px !important;
        font-size: 11px !important;
        padding: 0 6px !important;
    }
    .hamburger {
        font-size: 20px !important;
    }
    .side-menu {
        top: 40px !important;
    }
    .breadcrumbs {
        margin: 2px 10px 0 !important;
        font-size: 11px !important;
    }
    .page-content {
        padding: 4px 10px !important;
        min-height: calc(100vh - 40px) !important;
    }
    .container {
        padding: 8px 12px !important;
    }
    .page-title {
        font-size: 18px !important;
        margin-bottom: 6px !important;
    }
    
    /* Ensure tables have screen height in landscape without squishing */
    .table-container {
        max-height: calc(100vh - 140px) !important; /* Optimize vertical space */
        min-height: 140px !important;
    }
    
    /* Minimize spacing on user info when height is tight */
    .user-info-row {
        gap: 8px !important;
        margin-bottom: 8px !important;
    }
    .user-info-item {
        min-width: 110px !important;
    }
    .user-info-value {
        font-size: 13px !important;
    }
}

@media (max-width: 960px) and (orientation: landscape) {
    .container {
        padding: 8px 12px;
    }
    .user-info-row {
        gap: 8px;
        margin-bottom: 8px;
    }
    .user-info-item {
        min-width: 120px;
    }
    .user-info-value {
        font-size: 13px;
    }
    .table-container {
        max-height: calc(100vh - 150px) !important;
    }
}

