/* ============================================
   Main Layout Styles
   ============================================ */

.app-layout {
    display: flex;
    min-height: 100vh;
}

/* Sidebar overlay for mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    opacity: 0;
    transition: opacity var(--ias-transition-slow);
}

.sidebar-overlay.show {
    opacity: 1;
}

.sidebar {
    width: var(--ias-sidebar-width);
    background: var(--ias-sidebar-bg);
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 1000;
    overflow-y: auto;
    transition: transform var(--ias-transition-slow);
}

.main-content {
    flex: 1;
    margin-left: var(--ias-sidebar-width);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.top-bar {
    height: var(--ias-topbar-height);
    background: var(--ias-bg-surface);
    border-bottom: 1px solid var(--ias-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    position: sticky;
    top: 0;
    z-index: 100;
    transition: background-color var(--ias-transition), border-color var(--ias-transition);
}

.sidebar-toggle {
    padding: 0.25rem;
    border-radius: var(--ias-radius);
}

.sidebar-toggle:hover {
    background: var(--ias-primary-light);
}

.brand-text {
    font-weight: 600;
    color: var(--ias-text-primary);
    font-size: 1rem;
}

.user-dropdown {
    color: var(--ias-text-primary);
}

.user-dropdown:hover {
    color: var(--ias-primary);
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--ias-primary-light);
    color: var(--ias-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
}

.user-name {
    font-weight: 500;
    font-size: 0.875rem;
}

.content-area {
    flex: 1;
    padding: 1.5rem;
    background: var(--ias-bg-body);
    overflow: hidden;
    height: calc(100vh - var(--ias-topbar-height));
    max-height: calc(100vh - var(--ias-topbar-height));
    transition: background-color var(--ias-transition);
    display: flex;
    flex-direction: column;
}

/* Direct children of content-area should fill it */
.content-area > div {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Ensure dashboard-page also follows the pattern */
.content-area > .dashboard-page {
    overflow: hidden;
}

/* Not Signed In State */
.not-signed-in-container {
    max-width: 400px;
    padding: 2rem;
}

.not-signed-in-icon {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: var(--ias-primary-light);
    color: var(--ias-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    margin: 0 auto;
}

/* ============================================
   Page Header
   ============================================ */

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1rem;
    flex-shrink: 0;
}

.page-header .page-title {
    margin-bottom: 0;
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--ias-text-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.page-header .page-title i {
    color: var(--ias-primary);
}

.page-header .page-subtitle {
    color: var(--ias-text-muted);
    font-size: 0.875rem;
    margin-top: 0.25rem;
}

.page-header-content {
    flex: 1;
}

.page-header-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

/* Page title styling */
.page-title {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--ias-text-primary);
}

/* ============================================
   Page Content Sections (scrollable)
   ============================================ */

/* Filter card stays fixed size */
.filter-card {
    flex-shrink: 0;
    margin-bottom: 1rem;
}

/* Page header stays fixed */
.page-header {
    flex-shrink: 0;
}

/* Dashboard stats stay fixed */
.dashboard-stats {
    flex-shrink: 0;
}

/* Data cards that should scroll */
.data-card {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* But data-cards with h-100 on dashboard should not flex-grow */
.data-card.h-100 {
    flex: none;
}

.data-card .table-responsive,
.data-card .resizable-table-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: auto;
}

/* Card body inside data-card should grow and scroll */
.data-card > .card-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}

/* Scrollable content area for card grids on specific pages */
.pending-page > .row.g-4,
.admin-page > .row.g-4 {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
    align-content: flex-start;
}

/* Dashboard content should scroll as a whole */
.dashboard-page > .row.g-4 {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
    padding-right: 0.5rem;
}

/* Badge/summary lines stay fixed */
.pending-page > .mb-3,
.audit-logs-page > .mb-3,
.invoices-page > .mb-3,
.dashboard-page > .mb-3 {
    flex-shrink: 0;
}

/* Pagination stays fixed at bottom */
.audit-logs-page > .d-flex.justify-content-between,
.invoices-page > .d-flex.justify-content-between {
    flex-shrink: 0;
    margin-top: 1rem;
}

/* Empty state doesn't need to scroll */
.empty-state {
    flex-shrink: 0;
}

/* Loading spinner stays fixed */
.loading-spinner {
    flex-shrink: 0;
}

/* Error display stays fixed */
.pending-page > .alert,
.audit-logs-page > .alert {
    flex-shrink: 0;
}

/* ============================================
   Scrollable Container Utilities
   ============================================ */

/* Container that takes up remaining viewport height and scrolls internally */
.scrollable-container {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 180px);
    min-height: 400px;
}

.scrollable-container .scrollable-header {
    flex-shrink: 0;
}

.scrollable-container .scrollable-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    min-height: 0;
}

/* Scrollable card/item list within a container */
.scrollable-list {
    overflow-y: auto;
    overflow-x: hidden;
    max-height: calc(100vh - 280px);
    min-height: 200px;
    padding-right: 0.25rem;
}

/* Scrollable table container */
.scrollable-table-container {
    overflow-y: auto;
    overflow-x: auto;
    max-height: calc(100vh - 280px);
    min-height: 200px;
}

.scrollable-table-container .table {
    margin-bottom: 0;
}

.scrollable-table-container thead th {
    position: sticky;
    top: 0;
    background: var(--ias-bg-surface);
    z-index: 10;
    box-shadow: 0 1px 0 var(--ias-border);
}

/* Custom scrollbar styling */
.scrollable-content::-webkit-scrollbar,
.scrollable-list::-webkit-scrollbar,
.scrollable-table-container::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.scrollable-content::-webkit-scrollbar-track,
.scrollable-list::-webkit-scrollbar-track,
.scrollable-table-container::-webkit-scrollbar-track {
    background: var(--ias-bg-muted);
    border-radius: 4px;
}

.scrollable-content::-webkit-scrollbar-thumb,
.scrollable-list::-webkit-scrollbar-thumb,
.scrollable-table-container::-webkit-scrollbar-thumb {
    background: var(--ias-text-muted);
    border-radius: 4px;
}

.scrollable-content::-webkit-scrollbar-thumb:hover,
.scrollable-list::-webkit-scrollbar-thumb:hover,
.scrollable-table-container::-webkit-scrollbar-thumb:hover {
    background: var(--ias-text-secondary);
}


.row {
    margin-right: 0;
}

/* ============================================
   Layout Responsive Styles
   ============================================ */

@media (max-width: 991.98px) {
    .sidebar-overlay {
        display: block;
        pointer-events: none;
    }

    .sidebar-overlay.show {
        pointer-events: auto;
    }

    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.show {
        transform: translateX(0);
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.15);
    }

    .main-content {
        margin-left: 0;
    }

    .top-bar {
        padding: 0 1rem;
    }

    .content-area {
        padding: 1rem;
        height: calc(100vh - var(--ias-topbar-height));
        max-height: calc(100vh - var(--ias-topbar-height));
    }

    .page-header {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
    }

    .page-header .page-title {
        font-size: 1.25rem;
    }

    .scrollable-container {
        height: calc(100vh - 160px);
    }

    .scrollable-list {
        max-height: calc(100vh - 240px);
    }

    .scrollable-table-container {
        max-height: calc(100vh - 240px);
    }
}

@media (max-width: 575.98px) {
    .top-bar {
        height: var(--ias-topbar-height-mobile);
        padding: 0 0.75rem;
    }

    .user-avatar {
        width: 32px;
        height: 32px;
        font-size: 0.875rem;
    }

    .content-area {
        padding: 0.75rem;
        height: calc(100vh - var(--ias-topbar-height-mobile));
        max-height: calc(100vh - var(--ias-topbar-height-mobile));
    }

    .brand-text {
        font-size: 0.9rem;
    }

    .page-header .page-title {
        font-size: 1.125rem;
    }

    .scrollable-container {
        height: auto;
        min-height: auto;
    }

    .scrollable-list {
        max-height: none;
        overflow-y: visible;
    }

    .scrollable-table-container {
        max-height: calc(100vh - 200px);
        min-height: 150px;
    }
}
