/* Layout
   Page shell: sidebar container, content area, header, footer, page-specific height rules */

/* ======= LAYOUT STYLES ======= */

.page {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Main layout container */
.main-container {
    display: flex;
    flex: 1;
}

/* Sidebar - Updated with new color palette */
.sidebar {
    background-color: var(--primary-color);
    background-image: linear-gradient(to bottom, var(--primary-color), var(--primary-dark));
    color: #fff;
    width: 260px;
    transition: all var(--transition-normal);
    z-index: 100;
    position: fixed;
    height: 100vh;
    top: 0;
    left: 0;
    box-shadow: var(--shadow-lg);
}

html[dir="rtl"] .sidebar {
    left: auto;
    right: 0;
}

.sidebar.collapsed {
    width: 70px;
}

/* Content area - fixed height; allow vertical scroll when content overflows (e.g. dashboard) */
.content-wrapper {
    width: 100%;
    max-width: 100%;
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 0;
}

.content-body,
.content-body > * {
    width: 100%;
    max-width: 100%;
    min-width: 0;
}

.content-body {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

/* Don't apply to modal backdrops – they use their own dimmed overlay and must not get a white background */
.content-body > *:not(.row):not(.d-flex):not(.modal-backdrop-formal):not(.content-no-fill) {
    background: white;
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

/* Customer Statement page: allow customer search dropdown to overflow the card and content boundaries */
.content-body:has(.customer-statement-page),
.content-body > .customer-statement-page {
    overflow: visible !important;
}

/* Customer Detail page: allow the full customer account view to scroll instead of clipping above the footer. */
.content-body:has(.customer-detail-page),
.content-body > .customer-detail-page {
    flex: 0 0 auto !important;
    min-height: auto !important;
    overflow: visible !important;
}

.content-body:has(.customer-detail-page) > *,
.content-body > .customer-detail-page {
    flex: none !important;
    overflow: visible !important;
}

/* Recurring Expenses page: avoid flex-stretching to viewport height
   (otherwise it leaves large blank white space below the table). */
.content-body:has(.recurring-expenses-page),
.content-body > .recurring-expenses-page {
    overflow: hidden !important;
}

.content-body > .recurring-expenses-page {
    display: flex !important;
    flex: 1 1 auto !important;
    min-height: 0 !important;
    height: 100% !important;
}

/* Debts page: fill viewport; table panel grows to bottom */
.content-body:has(.depts-page),
.content-body > .depts-page {
    overflow: hidden !important;
}

.content-body > .depts-page {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    height: 100% !important;
}

/* Permissions page: fill viewport; table scrolls inside panel */
.content-body:has(.permission-manager),
.content-body > .permission-manager {
    overflow: hidden !important;
}

.content-body > .permission-manager {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    height: 100% !important;
    padding-block: 0.25rem 0 !important;
}

.customer-statement-card,
.customer-statement-card > .card-body {
    overflow: visible !important;
}

/* Payment new page: allow customer search dropdown to extend outside the card */
.content-body:has(.payment-new-page),
.content-body > .payment-new-page {
    overflow: visible !important;
}

.payment-new-card,
.payment-new-card > .card-body,
.payment-new-card .card-body {
    overflow: visible !important;
}

.content-body > .row {
    flex-shrink: 0;
}

/* Page header must not stretch (avoids huge empty top space on Settings and similar pages) */
.content-body > .page-header {
    flex: 0 0 auto !important;
    min-height: 0 !important;
}

/* Product detail (and similar content pages): fill height and scroll when content overflows */
.content-body > .product-detail-page {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}

/* Tasks page: allow vertical scrolling inside content body */
.content-body > .task-management-container {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}

/* Main dashboard: let content grow so .content-wrapper can scroll */
.content-body:has(.dashboard-container) {
    flex: 0 0 auto;
    min-height: 0;
    overflow: visible;
}

/* Tasks page: let content grow so .content-wrapper can scroll */
.content-body:has(.task-management-container) {
    flex: 0 0 auto;
    min-height: 0;
    overflow: visible;
}

.content-body .dashboard-container {
    min-height: 0;
}

.invoice-dashboard,
.dashboard-container,
.container-fluid {
    width: 100%;
    max-width: 100%;
}

/* Invoice dashboard only: flex column so documents-section can grow and fill bottom.
   Do not apply to .dashboard-container so the main Dashboard page can scroll. */
.content-body .invoice-dashboard {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

/* Only documents-section grows; actions and stats stay at natural height */
.content-body .invoice-dashboard .dashboard-actions,
.content-body .invoice-dashboard .stats-overview {
    flex-shrink: 0;
    flex-grow: 0;
}

.content-body .invoice-dashboard .documents-section,
.content-body .invoice-dashboard .documents-section .card {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.content-body .invoice-dashboard .documents-section .card .card-body {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

/* Tab body: fill card; table scrolls inside .table-responsive */
.content-body .invoice-dashboard .documents-section .card .card-body .invoices-tab-body {
    flex: 1 1 0;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    position: relative;
}

.content-body .invoice-dashboard .documents-section .card .card-body .invoices-tab-body .tab-content {
    flex: 1 1 0;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* Inactive tab panes: hidden so only one tab content shows (removes white space between tab and list) */
.content-body .invoice-dashboard .documents-section .card .card-body .invoices-tab-body .tab-content .tab-pane:not(.show.active) {
    display: none !important;
}

.content-body .invoice-dashboard .documents-section .card .card-body .invoices-tab-body .tab-content .tab-pane.show.active {
    flex: 1 1 0;
    min-height: 0;
    width: 100%;
    display: flex !important;
    flex-direction: column;
    overflow: hidden;
}

.content-body .invoice-dashboard .documents-section .card .card-body .invoices-tab-body .tab-content .tab-pane .table-responsive {
    flex: 1 1 0;
    min-height: 0;
    overflow: auto;
}

.content-body .invoice-dashboard .documents-section .card .card-body .invoices-tab-body .tab-content .tab-pane .empty-state {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

/* Main content area - full width */
.main-content {
    flex: 1;
    width: calc(100% - 260px);
    min-width: 0;
    margin-left: 260px;
    transition: all var(--transition-normal);
    background-color: var(--background-color);
    padding: 0;
    min-height: 100vh;
}

html[dir="rtl"] .main-content {
    margin-left: 0;
    margin-right: 260px;
}

.main-content.expanded {
    margin-left: 70px;
}

html[dir="rtl"] .main-content.expanded {
    margin-left: 0;
    margin-right: 70px;
}

/* Header - Compact POS/ERP Style */
.top-header,
.header {
    background: #ffffff;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid #e5e7eb;
    flex-shrink: 0;
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.header-title {
    font-weight: 600;
    color: #1f2937;
    font-size: 0.95rem;
    margin: 0;
    white-space: nowrap;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.375rem;
}

/* All elements same height: 32px - compact */
.hdr-btn,
.hdr-badge {
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    padding: 0 0.625rem;
    font-size: 0.8rem;
    font-weight: 500;
    border-radius: 6px;
    border: 1px solid #d1d5db;
    background: #ffffff;
    color: #374151;
    white-space: nowrap;
}

.hdr-btn {
    cursor: pointer;
}

.hdr-btn-outline {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.hdr-btn-outline:hover:not(:disabled) {
    background: var(--primary-color);
    color: #fff;
}

.hdr-btn-primary {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: #fff;
}

.hdr-badge {
    background: #f3f4f6;
    border: 1px solid #e5e7eb;
    color: #4b5563;
    cursor: default;
}

.hdr-badge i {
    color: var(--primary-color);
}

.hdr-divider {
    width: 1px;
    height: 20px;
    background: #e5e7eb;
}

/* RTL Support */
[dir="rtl"] .header-content {
    flex-direction: row-reverse;
}

/* Footer */
.footer {
    background-color: var(--card-bg-color);
    border-top: 1px solid var(--border-color);
    padding: var(--spacing-md);
    text-align: center;
    color: var(--text-light);
    font-size: var(--font-size-sm);
}
