/* Page UX – layout, toolbar, compact tables, detail modals
 *
 * Toolbar convention: .page-toolbar wraps the row; put filters/back links in the first flex chunk and group primary/secondary actions in .toolbar-actions.
 *
 * Button hierarchy (list + detail pages):
 * - Primary: .btn-primary (one main action per row, e.g. Add / Save)
 * - Secondary: .btn-outline-primary | .btn-outline-secondary
 * - Destructive: .btn-outline-danger or .btn-danger; keep destructive actions rightmost in toolbars
 * - Dense lists: prefer .btn-sm on toolbar buttons
 */

/* Page toolbar: primary action (Add X) + secondary (Manage types, Export, etc.) */
.page-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}

.toolbar-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
}

/* Card header with toolbar */
.card-header-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

/* Compact data table: essential columns only; extra data in detail modal */
.table-compact thead th {
    white-space: nowrap;
}

.table-compact .col-amount {
    text-align: right;
    white-space: nowrap;
}

.table-compact .col-actions {
    white-space: nowrap;
    width: 1%;
}

/* Table total row: make footer/totals clearly distinct from data rows */
.table tr.table-total-row,
.table tfoot tr {
    border-top: 2px solid var(--color-dark-300) !important;
    background-color: color-mix(in srgb, var(--color-dark-100) 35%, hsl(var(--card))) !important;
    font-weight: 700;
}
.table tfoot td {
    padding: 0.5rem 0.75rem;
    vertical-align: middle;
}

/* Detail modal: key-value pairs, readable */
.detail-modal .detail-grid {
    display: grid;
    gap: 0.75rem 1.5rem;
    grid-template-columns: minmax(140px, auto) 1fr;
    align-items: start;
}

.detail-modal .detail-label {
    font-weight: 600;
    color: var(--color-dark-500);
    font-size: 0.875rem;
}

.detail-modal .detail-value {
    word-break: break-word;
}

.detail-modal .detail-section {
    margin-bottom: 1.25rem;
}

.detail-modal .detail-section-title {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    padding-bottom: 0.25rem;
    border-bottom: 1px solid var(--color-dark-100);
}

/* Action buttons in tables */
.btn-icon {
    width: 32px;
    height: 32px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
}

@media (max-width: 768px) {
    .btn-icon {
        min-width: 2.75rem;
        min-height: 2.75rem;
    }
}

/* Filters: collapsible when used */
.filters-collapse .collapse-toggle {
    cursor: pointer;
    user-select: none;
}

/* Low-level “add” sections: in modals, not always on screen */
.add-form-modal .modal-body .form-floating,
.add-form-modal .modal-body .form-check {
    margin-bottom: 0.75rem;
}

/* Scroll modal body only; keep header + footer (save) visible */
.add-form-modal .modal-dialog {
    max-height: calc(100vh - 1.5rem);
    margin: 0.75rem auto;
}
.add-form-modal .modal-content {
    max-height: calc(100vh - 1.5rem);
    display: flex;
    flex-direction: column;
}
.add-form-modal form {
    display: flex;
    flex-direction: column;
    min-height: 0;
    flex: 1 1 auto;
}
.add-form-modal .modal-body {
    overflow-y: auto;
    flex: 1 1 auto;
    max-height: min(72vh, calc(100vh - 12rem));
    -webkit-overflow-scrolling: touch;
}
.add-form-modal .modal-footer {
    flex-shrink: 0;
}

/* --------------------------------------------------------------------
   Reports: P&L and multi-currency standards
   - KPI cards with currency breakdown pills
   - Original amount vs Base (base currency) columns
   - Section cards, filter bar, distinct totals
--------------------------------------------------------------------*/
.report-container {
    max-width: min(100rem, calc(100% - 2rem));
    margin: 0 auto;
    padding-inline: var(--page-padding-x, 1rem);
    box-sizing: border-box;
}

/* Filter bar above report content */
.report-filter-bar {
    background-color: hsl(var(--muted) / 0.5);
    border-radius: var(--radius);
    padding: 1rem 1.5rem;
    margin-bottom: 1.5rem;
    border: 1px solid hsl(var(--border));
}

/* KPI cards: left border indicates in/out/neutral */
.kpi-card {
    background-color: hsl(var(--card));
    border-radius: var(--radius);
    border: 1px solid hsl(var(--border));
    padding: 1.25rem;
    height: 100%;
    border-left: 4px solid transparent;
}
.kpi-card.positive { border-left-color: hsl(var(--success)); }
.kpi-card.negative { border-left-color: hsl(var(--destructive)); }
.kpi-card.neutral { border-left-color: hsl(var(--primary)); }
.kpi-card .kpi-title {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: hsl(var(--muted-foreground));
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.kpi-card .kpi-value {
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1.2;
    color: hsl(var(--card-foreground));
}
.kpi-currency-breakdown {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.5rem;
    font-size: 0.75rem;
}
.currency-pill {
    background-color: hsl(var(--muted) / 0.6);
    padding: 0.2rem 0.6rem;
    border-radius: 20px;
    border: 1px solid hsl(var(--border));
    color: hsl(var(--foreground));
    white-space: nowrap;
}
.currency-pill strong { font-weight: 600; margin-right: 0.2rem; }

/* Section card: collapsible block with header badges */
.section-card {
    background-color: hsl(var(--card));
    border: 1px solid hsl(var(--border));
    border-radius: var(--radius);
    margin-bottom: 1.25rem;
}
.section-header {
    padding: 1rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    border-bottom: 1px solid transparent;
}
.section-header[aria-expanded="true"] {
    border-bottom-color: hsl(var(--border));
    background-color: hsl(var(--muted) / 0.2);
}
.section-header:hover { background-color: hsl(var(--muted) / 0.3); }
.section-header h6 { margin: 0; font-weight: 600; display: flex; align-items: center; gap: 0.75rem; }
.section-collapse { padding: 1.5rem; }

/* Report tables: original + base columns, badge for currency */
.report-table thead th {
    padding: 0.75rem 1rem;
    font-weight: 500;
    color: hsl(var(--muted-foreground));
    background-color: hsl(var(--muted) / 0.3);
    border-bottom: 1px solid hsl(var(--border));
}
.report-table tbody td { padding: 0.75rem 1rem; vertical-align: middle; }
.report-table tbody tr { border-bottom: 1px solid hsl(var(--border)); }
.report-table tbody tr:hover { background-color: hsl(var(--muted) / 0.3); }
.report-table .btn-expand {
    width: 28px; height: 28px; padding: 0;
    display: inline-flex; align-items: center; justify-content: center;
    border: 1px solid hsl(var(--border));
    background-color: hsl(var(--card));
    border-radius: var(--radius-sm);
}
.report-table .btn-expand:hover { background-color: hsl(var(--accent)); }

/* Amount in original currency: badge + value */
.amount-original { white-space: nowrap; }
.amount-original .badge { font-weight: 400; }

/* Responsive */
@media (max-width: 768px) {
    .page-toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .detail-modal .detail-grid {
        grid-template-columns: 1fr;
    }

    .kpi-card .kpi-value { font-size: 1.4rem; }
    .section-header { flex-wrap: wrap; gap: 0.5rem; }
}

/* Tables: prevent wide grids from forcing page overflow */
.app-shell .table-responsive {
    min-width: 0;
    -webkit-overflow-scrolling: touch;
}

/* Chart wrappers (replace inline max-width / positioning) */
.ui-chart-wrap-doughnut {
    max-width: 280px;
    margin-left: auto;
    margin-right: auto;
    position: relative;
}
.ui-chart-wrap-doughnut--sm {
    max-width: 260px;
}
.ui-chart-wrap-pie-tall {
    height: 240px;
    position: relative;
}
.ui-chart-wrap-pie-short {
    height: 160px;
    position: relative;
}
.ui-pie-center-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    pointer-events: none;
    padding-left: 0.25rem;
    padding-right: 0.25rem;
    width: 100%;
    max-width: 12rem;
    z-index: 2;
}
.ui-pie-center-overlay--narrow {
    max-width: 7.5rem;
}

.ui-alert-warn-soft {
    background: color-mix(in srgb, var(--color-warning) 14%, transparent);
    border-left: 4px solid var(--color-warning) !important;
    color: hsl(var(--foreground));
}

.ui-dropdown-min-w-12 {
    min-width: 12rem;
}

.ui-prose-narrow {
    max-width: 28rem;
    margin-left: auto;
    margin-right: auto;
}

.ui-search-inline-sm {
    width: 14rem;
    min-width: 10rem;
    max-width: 100%;
}

.ui-select-branch-sm {
    max-width: 18rem;
}

.ui-textarea-short {
    min-height: 80px;
}
