:root {
    font: 16px/1.45 "Instrument Sans", "Segoe UI", sans-serif;
    color: #172d27;
    background: #f4f7f5;
    --green: #17664c;
    --edge: #dbe6df;
    --muted: #526960;
    --sidebar: #142f28;
    --shadow: 0 3px 12px #142f2808;
    --control-height: 42px;
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; }
a { color: var(--green); text-underline-offset: 3px; }
button, input, select { font: inherit; }
:focus-visible { outline: 3px solid #389a72; outline-offset: 3px; }
h1, h2, p { overflow-wrap: anywhere; }
h1 { margin: .15rem 0 .4rem; font-size: clamp(1.85rem, 3.6vw, 2.85rem); line-height: 1.1; letter-spacing: -.045em; }
h2 { font-size: 1.16rem; margin: 0 0 .85rem; letter-spacing: -.018em; }

.app-shell { display: grid; grid-template-columns: 224px minmax(0, 1fr); min-height: 100vh; }
.app-shell.sidebar-collapsed { grid-template-columns: minmax(0, 1fr); }
.sidebar { background: var(--sidebar); color: white; height: 100vh; position: sticky; top: 0; overflow: auto; padding: 23px 15px; }
.brand { display: flex; align-items: center; gap: 11px; color: white; text-decoration: none; font-weight: 700; line-height: 1.3; }
.sidebar .brand { margin: 0 5px 25px; }
.brand small { display: block; color: #b6d0c4; font-weight: 500; margin-top: 4px; }
.brand-logo { flex: 0 0 auto; display: block; width: 45px; height: 50px; padding: 4px; object-fit: contain; border-radius: 10px; background: white; }
.login-brand .brand-logo { width: 53px; height: 58px; }
.sidebar nav { display: grid; gap: 5px; }
.sidebar nav a, .report-menu summary { display: flex; align-items: center; gap: 9px; padding: .58rem .72rem; border-radius: 9px; color: #dae7e0; text-decoration: none; font-weight: 600; }
.sidebar nav a:hover, .report-menu summary:hover { background: #21483b; }
.sidebar nav .active { background: #2c5849; color: white; }
.report-menu summary { cursor: pointer; list-style: none; }
.report-menu summary::-webkit-details-marker { display: none; }
.report-menu ul { display: grid; gap: 4px; margin: 4px 0 0; padding: 0 0 0 1.35rem; list-style: none; }
.report-menu-divider { margin-block-start: .5rem; margin-inline-start: -1.35rem; padding: .5rem 0 0 1.35rem; border-top: 1px solid #53756a; }
.nav-chevron { width: .48em; height: .48em; margin-inline-start: auto; border: solid currentColor; border-width: 0 1px 1px 0; transform: translateY(-.12em) rotate(45deg); }
.report-menu[open] .nav-chevron { transform: translateY(.12em) rotate(225deg); }
.nav-icon { width: 19px; flex: 0 0 auto; color: #b5d9c7; text-align: center; font-size: 1.15rem; }
.app-content { min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; min-height: 60px; gap: 10px; padding: .5rem clamp(16px, 3vw, 36px); background: white; border-bottom: 1px solid var(--edge); }
.topbar-heading { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; min-width: 0; }
#sidebar-toggle[hidden] { display: none; }
.topbar-title { font-weight: 700; color: var(--muted); }
.account-menu { display: flex; align-items: center; justify-content: flex-end; gap: 9px; min-width: 0; }
.account-avatar { display: grid; place-items: center; flex: 0 0 33px; height: 33px; background: #e6f2eb; color: #205740; border-radius: 50%; font-weight: 750; }
.account-name { font-size: .9rem; font-weight: 650; max-width: 26ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wrap { max-width: 1640px; margin: auto; padding: 0 clamp(16px, 2.5vw, 34px) 40px; }
.spread, .actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.heading { margin: 22px 0 16px; }
.app-content .heading h1, .dashboard-hero h1 { font-size: clamp(1.4rem, 2.1vw, 1.85rem); letter-spacing: -.025em; line-height: 1.18; }
.heading p { margin: 4px 0; }
.context { color: var(--green); font-weight: 700; font-size: .87rem; }

.settings { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.card, .table-wrap, .report { min-width: 0; background: white; border: 1px solid var(--edge); border-radius: 16px; box-shadow: var(--shadow); }
.card, .report { padding: clamp(14px, 1.8vw, 22px); }
.entry-page { max-width: 1040px; }
.entry-page .heading > a { font-size: .9rem; }
.fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; margin-bottom: 14px; }
.full { grid-column: 1 / -1; }
label { display: block; min-width: 0; font-weight: 650; font-size: .91rem; }
label input, label select { display: block; margin-top: 6px; width: 100%; }
input, select { min-width: 0; min-height: var(--control-height); padding: .45rem .65rem; background: #fdfefd; color: inherit; border: 1px solid #becfc5; border-radius: 8px; font-weight: 500; }
input[readonly], select:disabled { background: #eff4f1; }
fieldset { min-width: 0; border: 0; padding: 0; margin: 0 0 16px; }
legend { font-size: 1.1rem; font-weight: 750; margin-bottom: 10px; padding: 0; }
.button { display: inline-flex; justify-content: center; align-items: center; gap: .45rem; text-decoration: none; cursor: pointer; min-height: var(--control-height); padding: .42rem .75rem; border: 1px solid transparent; border-radius: 9px; background: var(--green); color: white; font-size: .94rem; font-weight: 700; }
.secondary { background: white; color: var(--green); border-color: #b8cabf; }
.compact { min-height: 36px; padding: .36rem .65rem; font-size: .86rem; }
.button:hover { filter: brightness(.94); }
.year-list { list-style: none; padding: 0; margin: 0 0 1rem; }
.year-list .year-links { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; border-bottom: 1px solid var(--edge); padding: .65rem 0; }
.year-links a { text-decoration: none; font-weight: 700; font-size: .86rem; }
.year-links strong { margin-right: auto; }
.settings form > .button { margin-top: 12px; }
.profile-logo-upload { display: flex; align-items: center; flex-wrap: wrap; gap: 14px; padding: 14px; border: 1px solid var(--edge); border-radius: 10px; }
.profile-logo-upload label { flex: 1 1 240px; }
.profile-logo-upload input { max-width: 100%; }
.profile-logo-upload .muted { display: block; margin-top: 5px; font-weight: 500; }
.profile-logo-preview { width: 65px; height: 75px; object-fit: contain; }
.notice { padding: 12px 16px; border: 1px solid #a7c7b4; background: #edf7f0; border-radius: 10px; margin: 14px 0; overflow-wrap: anywhere; }
.notice ul { margin: 0; padding-left: 1.2rem; }
.notice code { font-size: .83rem; }
.danger { border-color: #dca6a1; background: #fff0ee; color: #802a23; }
.link { background: none; border: 0; padding: 0; color: var(--green); text-decoration: underline; cursor: pointer; }
.danger-text { color: #8c2d24; }
.table-wrap { overflow: auto; }
.account-table { container-type: inline-size; }
.account-table .table-wrap { max-width: 100%; }
.table-scroll-hint { display: none; margin: 0 0 .4rem; font-size: .8rem; color: var(--muted); }
@container (max-width: 670px) {
    .table-scroll-hint { display: block; }
}
table { border-collapse: collapse; width: 100%; min-width: 670px; font-size: .88rem; }
th, td { text-align: left; padding: .52rem .65rem; border-bottom: 1px solid var(--edge); vertical-align: top; }
thead, tfoot, .level-1 { background: #e6f1ea; color: #214b39; }
tfoot th, tfoot td { border-bottom: 0; font-weight: 750; }
.subtotal { font-weight: 700; background-color: #f4f8f5; }
.subtotal.level-1 { background-color: #e6f1ea; }
.level-3 th { padding-left: 1.15rem; }
.level-4 th { padding-left: 1.5rem; }
.detail { padding-left: 1.8rem; min-width: 175px; font-weight: 500; overflow-wrap: anywhere; }
.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.budget-comparison thead .num { white-space: normal; }
.code { white-space: nowrap; }
.empty { padding: 1.65rem; text-align: center; color: var(--muted); }
.toolbar { margin: 16px 0 12px; }
.filter-controls { display: flex; align-items: flex-end; flex-wrap: wrap; gap: 10px; min-width: 0; }
.filter-controls > label { flex: 0 1 auto; min-width: min(100%, 160px); max-width: 100%; }
.filter-controls select, .filter-controls .button { height: var(--control-height); min-height: var(--control-height); }
.budget-report-controls { display: grid; grid-template-columns: minmax(0, 150px) auto auto; justify-content: start; gap: 8px; }
.budget-report-controls > label { min-width: 0; }
.budget-report-controls select, .budget-report-controls > .button { padding-inline: .55rem; }
.budget-report-controls > .button { white-space: nowrap; }
.report-controls-with-stage { grid-template-columns: minmax(0, 150px) minmax(0, 195px) auto auto; }
.report-activity-filters { margin-top: 12px; }
.stage-filter { flex-wrap: nowrap; }
.stage-filter > label { flex: 0 1 195px; min-width: 0; }
.stage-filter > .button, .dashboard-filters > .button { flex-shrink: 0; padding-inline: .72rem; }
.report .heading { margin-top: 0; text-align: center; }
.report-logo { display: block; width: 55px; height: 65px; object-fit: contain; margin: 0 auto 8px; }
.muted { color: var(--muted); font-size: .9rem; }
.filter-form .filter-controls:not(.budget-report-controls) > label { flex: 1 1 150px; }
.filter-submit { display: flex; align-items: flex-end; gap: 10px; flex: 1 1 255px; min-width: 0; }
.filter-submit > label { flex: 1; }
.filter-submit > .button { flex-shrink: 0; }
.filter-form .actions { margin-top: 12px; }
.activity-group { margin: 1.35rem 0; }
.activity-group .context { margin: 0 0 .25rem; }
.activity-group h2 { margin-bottom: .65rem; }
.detail-meta { display: block; color: var(--muted); font-weight: 400; margin-top: .2rem; }
.expenditure-total { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin: 1rem 0; padding: .74rem 1rem; background: #e6f1ea; color: #214b39; border-radius: 9px; }
.optional-fields { margin: 0 0 1rem; padding: .68rem .82rem; border: 1px solid var(--edge); border-radius: 10px; }
.optional-fields summary { cursor: pointer; font-weight: 700; }
.optional-fields .fields { margin: .8rem 0 0; }

.dashboard-hero { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px; margin: 20px 0 16px; padding: clamp(16px, 2.2vw, 26px); border-radius: 16px; color: #f7fff9; background: radial-gradient(ellipse at top right, #408969 0, transparent 62%), #1a513e; }
.dashboard-hero p { margin: 0; }
.dashboard-hero .context { color: #ceeade; margin-bottom: 6px; }
.dashboard-hero h1 + p { color: #e0eee7; }
.dashboard-filters { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr) auto; width: min(100%, 460px); }
.dashboard-filters > label { min-width: 0; }
.dashboard-filters input, .dashboard-filters select { color: #173d30; }
.dashboard-filters .button { background: #d6efdf; color: #184a36; }
.metrics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.dashboard-totals { grid-template-columns: repeat(auto-fit, minmax(min(100%, 215px), 1fr)); }
.metric.remaining { background: #eaf5ee; border-color: #cfe4d6; }
.metric h2 { margin: .7rem 0 .12rem; font-size: .91rem; font-weight: 700; color: var(--muted); }
.metric-mark, .quick-icon { display: grid; place-items: center; line-height: 1; width: 39px; height: 39px; border-radius: 11px; font-size: 1.35rem; font-weight: 750; color: #22674c; background: #e4f3e9; }
.expense .metric-mark { color: #80511b; background: #f9efdb; }
.balance .metric-mark { color: #425c85; background: #eaf0f8; }
.metric, .financing-summary .metrics > div { container-type: inline-size; min-width: 0; }
.metric-amount { margin: 0; font-size: clamp(.93rem, 8.5cqi, 1.48rem); font-weight: 760; line-height: 1.25; letter-spacing: -.025em; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.metric-foot { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 6px; font-size: .87rem; color: var(--muted); margin: .65rem 0 0; }
.metric-foot a { font-weight: 700; text-decoration: none; }
.financing-summary { margin-top: 16px; }
.financing-summary h2 { margin: 0; }
.financing-summary .metrics { grid-template-columns: repeat(auto-fit, minmax(min(100%, 190px), 1fr)); margin: 1rem 0 0; }
.financing-summary dt { color: var(--muted); font-weight: 650; font-size: .91rem; }
.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(0, 1fr); align-items: start; gap: 16px; margin-top: 16px; }
.budget-groups { display: grid; gap: 16px; }
.budget-groups .button { margin-top: .9rem; }
.dashboard-reports { margin-top: 16px; }
.dashboard-report-links { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 205px), 1fr)); gap: 8px 20px; }
.dashboard-report-links a { padding: .45rem .65rem; border: 1px solid var(--edge); border-radius: 9px; }
.comparison h2 { margin-bottom: .1rem; }
.comparison > p { margin: 0 0 1rem; }
.plot-row + .plot-row { margin-top: 1.12rem; }
.plot-label { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: .35rem; font-size: .91rem; margin-bottom: .4rem; }
.plot-label h3 { font-size: 1rem; margin: 0; }
.plot-difference { color: #32576e; }
.plot-change { display: flex; align-items: baseline; flex-wrap: wrap; gap: .25rem .45rem; font-size: .8rem; }
.plot-percentage { padding: .12rem .4rem; border-radius: 5px; background: #eef2f0; color: #415a50; font-weight: 700; }
.plot-increase { background: #e4f3e9; color: #18573d; }
.plot-decrease { background: #faeee4; color: #793a22; }
.plot-series + .plot-series { margin-top: .45rem; }
.plot-series .plot-label { color: var(--muted); margin-bottom: .2rem; }
.plot-track { position: relative; height: .65rem; border-radius: 5px; background: #edf3ef; overflow: hidden; }
.plot-track::after { content: ""; position: absolute; inset-block: 0; inset-inline-start: var(--plot-zero); border-inline-start: 1px solid #768c82; }
.plot-track span { position: absolute; height: 100%; border-radius: inherit; background: #607e9b; }
.plot-series-change .plot-track span { background: #267459; }
.shortlinks a { display: grid; align-items: center; grid-template-columns: 26px minmax(0, 1fr) auto; gap: 9px; min-height: 34px; margin-top: 3px; text-decoration: none; font-size: .9rem; font-weight: 650; }
.shortlinks a:hover { text-decoration: underline; }
.quick-icon { width: 25px; height: 25px; border-radius: 6px; font-size: 1rem; }
.group-row { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .3rem 1rem; padding: .62rem 0; border-bottom: 1px solid var(--edge); font-size: .91rem; }
.group-row:last-child { border: 0; }

.guest-page { background: #eef4f0; }
.login-shell { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, .9fr); width: min(1050px, calc(100% - 44px)); min-height: 590px; margin: max(22px, calc((100vh - 590px) / 2)) auto; background: white; border: 1px solid #d7e4dc; border-radius: 25px; box-shadow: 0 24px 64px #173e3220; overflow: hidden; }
.login-brand { isolation: isolate; position: relative; display: flex; flex-direction: column; justify-content: space-between; gap: 25px; min-width: 0; padding: clamp(24px, 4.5vw, 54px); background: radial-gradient(ellipse at 100% 95%, #3a8968, transparent 62%), linear-gradient(140deg, #162f29, #205740); color: white; overflow: hidden; }
.login-brand::after { position: absolute; inset: auto -9rem -13rem auto; z-index: -1; content: ""; width: 29rem; height: 29rem; border: 1px solid #e3f5e64d; border-radius: 50%; box-shadow: 0 0 0 2rem #e3f5e619, 0 0 0 4rem #e3f5e617, 0 0 0 6rem #e3f5e615; }
.login-copy h1 { font-size: clamp(1.85rem, 4vw, 3.25rem); }
.login-copy p { max-width: 28ch; color: #dcefe4; font-size: 1.06rem; }
.login-code { font-size: .85rem; color: #d6ebe0; }
.login-panel { display: grid; place-items: center; padding: clamp(20px, 5vw, 54px); min-width: 0; }
.login-box { width: min(100%, 355px); }
.login-box h2 { font-size: clamp(1.5rem, 3vw, 2rem); margin-bottom: 1.25rem; }
.login-form > label:first-of-type { margin-bottom: 15px; }
.password-field { position: relative; margin-top: 6px; }
.password-field input { width: 100%; padding-right: 7rem; }
.password-field .link { position: absolute; right: .75rem; top: 50%; transform: translateY(-50%); font-size: .83rem; font-weight: 650; }
.login-form > .button { width: 100%; min-height: 46px; justify-content: space-between; margin-top: 20px; }

@media (max-width: 1090px) {
    .app-shell { grid-template-columns: 188px minmax(0, 1fr); }
    .sidebar { padding-inline: 10px; }
    .sidebar nav a, .report-menu summary { padding-inline: .55rem; font-size: .89rem; }
}
@media (max-width: 820px) {
    .dashboard-grid { grid-template-columns: minmax(0, 1fr); }
    .app-shell { display: block; }
    .sidebar { position: static; height: auto; overflow: visible; padding: 13px 16px; }
    .sidebar .brand { margin: 0 0 11px; }
    .sidebar nav { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 4px; }
    .sidebar nav a, .report-menu summary { padding: .39rem .53rem; min-height: 36px; }
    .topbar { min-height: 52px; }
}
@media (max-width: 600px) {
    .filter-submit { flex-basis: 100%; }
    .settings, .fields, .metrics { grid-template-columns: minmax(0, 1fr); }
    .metric h2 { margin-top: .55rem; }
    .login-shell { grid-template-columns: minmax(0, 1fr); width: calc(100% - 24px); margin: 12px auto; min-height: 0; border-radius: 17px; }
    .login-brand { gap: 12px; }
    .login-copy p { margin: .4rem 0; }
    .login-panel { padding-bottom: 25px; }
    .account-name { max-width: 12ch; }
}
@media (max-width: 480px) {
    .budget-report-controls { grid-template-columns: minmax(0, 1fr) auto auto; }
    .budget-report-controls > .button { font-size: .84rem; }
    .report-controls-with-stage { grid-template-columns: minmax(0, 1fr) minmax(0, 1.6fr) auto; }
    .report-controls-with-stage > .report-print { grid-column: 1 / -1; justify-self: start; }
    .dashboard-filters { grid-template-columns: minmax(0, 1fr) auto; }
    .dashboard-filters > label:first-child { grid-column: 1 / -1; }
    .topbar { flex-wrap: wrap; }
}
@media (max-width: 360px) {
    .report-controls-with-stage { grid-template-columns: minmax(0, 1fr) auto; }
    .report-controls-with-stage > label:first-child { grid-column: 1 / -1; }
}
@media print {
    @page { size: A4 landscape; margin: 12mm; }
    .screen-only { display: none !important; }
    body { background: white; color: black; }
    .app-shell { display: block; }
    .wrap, .report { max-width: none; padding: 0; border: 0; box-shadow: none; }
    .report .heading { margin-bottom: 14px; }
    .report-logo { width: 43px; height: 50px; margin-bottom: 5px; }
    .table-wrap { overflow: visible; border-radius: 0; box-shadow: none; }
    th, td { padding: 4px 6px; }
    table { font-size: 10pt; min-width: 0; }
    .budget-summary-report .account-table { container-type: normal; }
    .budget-summary-report table { table-layout: fixed; width: 100%; }
    .budget-summary-report thead th:first-child { width: 64%; }
    .budget-summary-report .budget-comparison thead th:first-child { width: 30%; }
    .budget-summary-report .budget-comparison thead th:last-child { width: 13%; }
    .budget-summary-report th, .budget-summary-report td { white-space: normal; overflow-wrap: anywhere; }
    tr { break-inside: avoid; }
    thead { display: table-header-group; }
    tfoot { display: table-row-group; }
}
