/* LGU Budget System - layout and small additions on top of Bootstrap 5.3 */
:root {
    --app-sidebar-width: 270px;
    --app-topbar-height: 56px;
}

body.app {
    background: #f4f6f9;
    min-height: 100vh;
}

.app-topbar {
    height: var(--app-topbar-height);
    position: sticky;
    top: 0;
    z-index: 1030;
}

.app-body {
    display: flex;
    min-height: calc(100vh - var(--app-topbar-height));
}

.app-sidebar {
    width: var(--app-sidebar-width);
    flex-shrink: 0;
}

@media (min-width: 992px) {
    .app-sidebar {
        position: sticky;
        top: var(--app-topbar-height);
        height: calc(100vh - var(--app-topbar-height));
        overflow-y: auto;
        display: flex;
        flex-direction: column;
    }
}

.app-main {
    flex: 1;
    min-width: 0;
    padding: 1.5rem;
}

.app-nav-link {
    display: flex;
    align-items: center;
    gap: .65rem;
    color: #344054;
    border-radius: .5rem;
    padding: .5rem .75rem;
    font-size: .925rem;
}

.app-nav-link:hover {
    background: #f1f4f9;
    color: #0d6efd;
}

.app-nav-link.active {
    background: #e7f0ff;
    color: #0a58ca;
    font-weight: 600;
}

.app-nav-link .badge {
    font-size: .65rem;
    font-weight: 500;
}

.app-nav-link .bi {
    font-size: 1.05rem;
    width: 1.2rem;
    text-align: center;
}

.app-nav-header {
    text-transform: uppercase;
    font-size: .72rem;
    letter-spacing: .06em;
    color: #98a2b3;
    padding: 1rem .75rem .35rem;
}

.page-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .75rem;
    margin-bottom: 1rem;
}

.page-header h1 {
    font-size: 1.4rem;
    margin: 0;
}

.page-header .page-actions {
    margin-left: auto;
    display: flex;
    gap: .5rem;
}

.card-table .table {
    margin-bottom: 0;
}

.card-table .table thead th {
    background: #f8f9fb;
    font-size: .8rem;
    text-transform: uppercase;
    letter-spacing: .03em;
    color: #667085;
    white-space: nowrap;
}

.table td.num, .table th.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.table tr.row-muted td {
    color: #98a2b3;
}

.table-loading {
    opacity: .5;
    pointer-events: none;
}

.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
    padding: .75rem;
    border-bottom: 1px solid var(--bs-border-color);
}

.filter-bar .form-control, .filter-bar .form-select {
    max-width: 240px;
}

.stat-card .stat-value {
    font-size: 1.6rem;
    font-weight: 600;
}

.perm-group {
    border: 1px solid var(--bs-border-color);
    border-radius: .5rem;
    padding: .75rem 1rem;
    margin-bottom: .75rem;
}

.perm-group h6 {
    font-size: .8rem;
    text-transform: uppercase;
    color: #667085;
    letter-spacing: .04em;
}

.code-cell {
    font-family: var(--bs-font-monospace);
    font-size: .85rem;
}

pre.json-view {
    background: #f8f9fb;
    border: 1px solid var(--bs-border-color);
    border-radius: .5rem;
    padding: .75rem;
    font-size: .8rem;
    max-height: 320px;
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-word;
}

body.app-auth {
    background: linear-gradient(160deg, #e9f1ff 0%, #f6f8fb 60%);
}

.app-auth-logo {
    font-size: 2.5rem;
    color: #0d6efd;
}

/* AIP Management */
.aip-table td { font-size: .85rem; }
.aip-table tr.aip-title-row td { background: #fff6e0; }
.plan-card { min-width: 300px; max-width: 440px; flex: 1 1 300px; }
.ref-parts .form-control { padding-left: .4rem; padding-right: .4rem; }

/* Select... pickers and budget screens */
.pick-table tr.pick-row { cursor: pointer; }
.pick-table tr.pick-disabled td { color: #adb5bd; cursor: not-allowed; }
.picker-field { background: var(--bs-secondary-bg); }
.status-ok { color: var(--bs-success-text-emphasis); }
.status-low { color: var(--bs-warning-text-emphasis); }
.status-over { color: var(--bs-danger-text-emphasis); font-weight: 600; }
.money-cell-neg { color: var(--bs-danger-text-emphasis); }
.table tfoot td { font-weight: 600; background: #f8f9fb; }

/* ---------- charts (dashboard) ---------- */
.chart-box { min-height: 220px; }
.chart-svg { display: block; overflow: visible; }
.chart-svg .chart-grid { stroke: #e9ecef; stroke-width: 1; }
.chart-svg .chart-axis { stroke: #adb5bd; stroke-width: 1; }
.chart-svg .chart-tick { font-size: 11px; fill: #6c757d; }
.chart-svg .chart-col { fill: #2a78d6; }
.chart-svg .chart-hit.on { fill: rgba(42, 120, 214, .07); }
.chart-scroll { max-height: 340px; overflow-y: auto; padding-right: 4px; }
.chart-bars { display: flex; flex-direction: column; gap: 12px; }
.chart-bar-row { cursor: default; }
.chart-bar-label { display: flex; gap: 8px; font-size: .875rem; margin-bottom: 3px; }
.chart-bar-value { margin-left: auto; font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
.chart-bar-track { height: 10px; border-radius: 4px; background: #e9ecef; overflow: hidden; }
.chart-bar-fill { height: 100%; border-radius: 4px; background: #2a78d6; }
.chart-bar-fill.over { background: #e34948; }
.chart-bar-sub { font-size: .75rem; color: #6c757d; margin-top: 2px; font-variant-numeric: tabular-nums; }
.chart-empty { color: #6c757d; text-align: center; padding: 40px 0; }
.chart-tip { position: fixed; z-index: 2000; pointer-events: none; background: #fff; border: 1px solid #dee2e6; border-radius: 6px;
    box-shadow: 0 4px 14px rgba(0,0,0,.12); padding: 6px 9px; font-size: .8rem; color: #212529; display: none; max-width: 280px; }

/* ---------- reports ---------- */
.report-table { max-height: 70vh; }
.report-table thead th { position: sticky; top: 0; background: #f8f9fa; z-index: 1; font-size: .75rem; white-space: normal; vertical-align: middle; }
.report-table td { font-size: .8125rem; }
.report-table td.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.report-table tr.rep-group td { font-weight: 600; background: #f1f3f5; }
.report-table tr.rep-sub td { font-weight: 600; }
.report-table tr.rep-total td { font-weight: 700; background: #f1f3f5; border-top: 2px solid #495057; }
#reportList .list-group-item.active .small { color: rgba(255,255,255,.85) !important; }

/* ---------- printing an ordinary page (Ctrl+P): only the content ---------- */
@media print {
    @page { margin: 0; }
    .app-topbar, .app-sidebar, .page-actions, .filter-bar, .card-footer, .dropdown, .btn, .toast-container, .modal { display: none !important; }
    .app-body, .app-main { display: block !important; margin: 0 !important; }
    .app-main { padding: 8mm !important; }
    body { background: #fff !important; }
    .card { box-shadow: none !important; border: 0 !important; }
}

/* ---------- help ---------- */
.help-toc { position: sticky; top: 80px; max-height: calc(100vh - 100px); overflow-y: auto; }
.help-body { max-width: 900px; line-height: 1.6; }
.help-body h2 { font-size: 1.6rem; margin-bottom: 1rem; }
.help-body h3 { font-size: 1.2rem; margin-top: 2rem; padding-top: .5rem; border-top: 1px solid #e9ecef; scroll-margin-top: 80px; }
.help-body h4 { font-size: 1rem; margin-top: 1.2rem; }
.help-body .help-table { font-size: .875rem; }
.help-body .help-table th { background: #f8f9fa; }
@media print { .help-toc { display: none; } .help-body { max-width: none; } }

/* ---------- searchable select (Office choosers) ---------- */
.searchable-select { position: relative; }
.searchable-toggle { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; min-height: calc(1.5em + .75rem + 2px); }
.searchable-toggle.form-select-sm { min-height: calc(1.5em + .5rem + 2px); }
.searchable-toggle::after { display: none; }   /* .form-select already draws the arrow */
.searchable-menu { max-width: min(480px, 92vw); }
.searchable-list { max-height: 280px; overflow-y: auto; }
.searchable-list .dropdown-item { border-radius: 4px; font-size: .9rem; }
.filter-bar .searchable-select { min-width: 200px; }
@media print { .searchable-select { display: none !important; } }

/* ---------- AIP items table: fixed columns, equal amount columns, aligned figures ---------- */
.aip-scroll { max-height: 72vh; overflow: auto; }
.aip-table { table-layout: fixed; width: 100%; min-width: 1000px; border-collapse: separate; border-spacing: 0; }
.aip-table col.c-check { width: 34px; }
.aip-table col.c-ref { width: 126px; }
.aip-table col.c-sched { width: 98px; }
.aip-table td.c-sched-cell { white-space: nowrap; }
.aip-table col.c-amt { width: 90px; }
.aip-table col.c-total { width: 108px; }
.aip-table col.c-status { width: 96px; }
.aip-table col.c-act { width: 48px; }
.aip-table th, .aip-table td { vertical-align: top; }
.aip-table td { font-size: .8125rem; padding-top: .45rem; padding-bottom: .45rem; overflow-wrap: anywhere; }
.aip-table td.num, .aip-table th.num { font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-table .aip-table thead th { white-space: normal; vertical-align: bottom; line-height: 1.2; }
.aip-table thead th.amt-group { border-bottom: 1px solid #d0d5dd; vertical-align: middle; height: 1.95rem; box-sizing: border-box; }
.aip-table .th-sub { font-size: .65rem; text-transform: none; letter-spacing: 0; font-weight: 400; }
/* the four amount columns read as one block */
.aip-table .amt-first { border-left: 1px solid #e4e7ec; }
.aip-table .amt-last { border-right: 1px solid #e4e7ec; }
.aip-table .amt-zero { color: #c0c5ce; }
.aip-table .aip-ref { font-family: SFMono-Regular, Consolas, "Liberation Mono", monospace; font-size: .72rem; line-height: 1.35; }
.aip-table tr.aip-title-row td { background: #fff6e0; }
/* headings stay at the top while scrolling; reference code and description stay in view on narrow screens */
.aip-table thead th { position: sticky; top: 0; z-index: 2; }
.aip-table thead tr:nth-child(2) th { top: 1.95rem; }
.aip-table td.s-check, .aip-table th.s-check { position: sticky; left: 0; z-index: 1; background: #fff; }
.aip-table td.s-ref, .aip-table th.s-ref { position: sticky; left: 0; z-index: 1; background: #fff; }
.aip-table.with-check td.s-ref, .aip-table.with-check th.s-ref { left: 34px; }
.aip-table td.s-desc, .aip-table th.s-desc { position: sticky; left: 126px; z-index: 1; background: #fff; box-shadow: 1px 0 0 #e4e7ec; }
.aip-table.with-check td.s-desc, .aip-table.with-check th.s-desc { left: 160px; }
.aip-table thead th.s-check, .aip-table thead th.s-ref, .aip-table thead th.s-desc { z-index: 3; background: #f8f9fb; }
.aip-table tr.aip-title-row td.s-check, .aip-table tr.aip-title-row td.s-ref, .aip-table tr.aip-title-row td.s-desc { background: #fff6e0; }
@media print { .aip-scroll { max-height: none; overflow: visible; } }
