:root {
    --surface: #ffffff;
    --surface-soft: #f4f8f6;
    --focus: #1b7b59;
    --shadow-soft: 0 10px 30px rgba(11, 60, 44, .07);
    --shadow-hover: 0 16px 38px rgba(11, 60, 44, .12);
}

html {
    overflow-x: hidden;
    scroll-behavior: smooth;
}

body {
    min-width: 320px;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

.main-content,
.page-heading,
.content,
.panel,
.split > *,
.two-cols > * {
    min-width: 0;
}

:where(a, button, input, select, textarea):focus-visible {
    outline: 3px solid rgba(27, 123, 89, .2);
    outline-offset: 2px;
}

.topbar {
    position: sticky;
    z-index: 15;
    top: 0;
    min-height: 86px;
    box-shadow: 0 1px 0 rgba(8, 47, 36, .03);
}

.page-heading {
    flex: 1;
}

.content {
    width: min(100%, 1600px);
}

.panel,
.metrics article,
.mini-metrics span,
.filters {
    border-color: #d8e5de;
    box-shadow: var(--shadow-soft);
}

.panel {
    transition: border-color .18s ease, box-shadow .18s ease;
}

.btn,
button,
input,
select,
textarea {
    transition: border-color .16s ease, box-shadow .16s ease, background-color .16s ease, transform .16s ease;
}

.btn {
    gap: 7px;
    font-weight: 650;
}

.btn:hover:not(:disabled) {
    border-color: #b9cec2;
    box-shadow: 0 7px 18px rgba(13, 69, 50, .09);
    transform: translateY(-1px);
}

.btn.primary:hover:not(:disabled) {
    background: #105e43;
    border-color: #105e43;
}

button:disabled,
.btn:disabled {
    cursor: not-allowed;
    opacity: .52;
}

input:hover,
select:hover,
textarea:hover {
    border-color: #adc5b8;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--focus);
    outline: 0;
    box-shadow: 0 0 0 3px rgba(27, 123, 89, .12);
}

input[readonly] {
    background: var(--surface-soft);
    color: #587068;
}

.alert,
.notice {
    border: 1px solid rgba(23, 107, 77, .09);
}

.table-wrap {
    max-width: 100%;
    border-radius: 10px;
    overscroll-behavior-inline: contain;
    -webkit-overflow-scrolling: touch;
}

tbody tr {
    transition: background-color .14s ease;
}

tbody tr:hover {
    background: #f7faf8;
}

.actions {
    flex-wrap: wrap;
}

.role-grid,
.permission-list {
    display: grid;
    gap: 12px;
}

.role-grid {
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.permission-list label {
    display: flex;
    grid-template-columns: none;
    align-items: center;
    gap: 9px;
    padding: 9px 10px;
    border-radius: 8px;
    background: var(--surface-soft);
}

.permission-list input {
    width: 18px;
    min-height: 18px;
}

.user-account-actions,
.user-editor-buttons {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 7px;
}

.user-account-actions form {
    margin: 0;
}

.user-account-actions {
    flex-wrap: nowrap;
}

.user-action {
    display: inline-flex;
    min-height: 34px;
    padding: 6px 10px;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: 1px solid transparent;
    border-radius: 9px;
    background: #fff;
    box-shadow: 0 2px 6px rgba(14, 62, 47, .035);
    font-size: 12px;
    font-weight: 700;
    line-height: 1;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color .16s ease, border-color .16s ease, box-shadow .16s ease, color .16s ease, transform .16s ease;
}

.user-action > span {
    display: inline-grid;
    width: 15px;
    height: 15px;
    place-items: center;
    font-size: 14px;
    font-weight: 800;
    line-height: 1;
}

.user-action:hover {
    box-shadow: 0 6px 14px rgba(14, 62, 47, .1);
    transform: translateY(-1px);
}

.user-action-edit {
    border-color: #c8e1d5;
    background: #edf7f2;
    color: #176b4d;
}

.user-action-edit:hover {
    border-color: #a8d0bd;
    background: #e2f2ea;
    color: #105d42;
}

.user-action-deactivate {
    border-color: #ecd9aa;
    background: #fff8e7;
    color: #8a5d08;
}

.user-action-deactivate:hover {
    border-color: #ddc477;
    background: #fff2cf;
    color: #744c00;
}

.user-action-activate {
    border-color: #bfe1cf;
    background: #e7f6ee;
    color: #176b4d;
}

.user-action-activate:hover {
    border-color: #9ed0b5;
    background: #daf0e4;
}

.user-action-remove {
    border-color: #edcdd0;
    background: #fff1f2;
    color: #ad3d46;
}

.user-action-remove:hover {
    border-color: #dfaeb3;
    background: #fde5e7;
    color: #922f38;
}

.user-actions-column {
    position: sticky;
    z-index: 2;
    right: 0;
    min-width: 268px;
    background: #fff;
    box-shadow: -10px 0 18px -16px rgba(10, 52, 38, .55);
}

tbody tr:hover .user-actions-column {
    background: #f7faf8;
}

.user-editor-buttons .btn {
    flex: 1 1 130px;
}

@media (max-width: 1400px) {
    .user-management-layout {
        grid-template-columns: minmax(0, 1fr);
    }

    .user-management-layout .form-panel {
        width: min(560px, 100%);
    }
}

.sidebar-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sidebar-close,
.sidebar-backdrop {
    display: none;
}

.login-column {
    width: min(430px, 100%);
}

.login-column .login-card {
    width: 100%;
}

.mobile-login-brand {
    display: none;
}

@media (max-width: 1100px) {
    .content {
        padding: 24px;
    }

    .split {
        grid-template-columns: minmax(0, 1fr) 320px;
    }
}

@media (max-width: 900px) {
    .shell {
        display: block;
    }

    .sidebar {
        position: fixed;
        z-index: 50;
        inset: 0 auto 0 0;
        left: 0;
        display: flex;
        width: min(340px, calc(100vw - 28px));
        height: 100vh;
        height: 100dvh;
        padding: max(18px, env(safe-area-inset-top)) 14px max(18px, env(safe-area-inset-bottom));
        flex-direction: column;
        overflow: hidden;
        border-radius: 0 20px 20px 0;
        background: linear-gradient(180deg, #082f24 0%, #0b3b2d 100%);
        box-shadow: 22px 0 60px rgba(2, 22, 16, .28);
        transform: translateX(-105%);
        visibility: hidden;
        transition: transform .24s ease, visibility 0s linear .24s;
        will-change: transform;
        overscroll-behavior: contain;
    }

    .sidebar.open,
    .sidebar-open .sidebar {
        left: 0;
        transform: translateX(0);
        visibility: visible;
        transition-delay: 0s;
    }

    .sidebar .logo {
        margin: 0;
    }

    .sidebar-close {
        display: grid;
        width: 42px;
        height: 42px;
        flex: 0 0 42px;
        padding: 0;
        place-items: center;
        border: 1px solid rgba(255, 255, 255, .12);
        border-radius: 10px;
        background: rgba(255, 255, 255, .06);
        color: #d8ebe3;
        font-size: 25px;
        cursor: pointer;
    }

    .sidebar nav {
        display: grid;
        margin: 22px -3px 0;
        padding: 0 3px 12px;
        flex: 1;
        align-content: start;
        overflow-y: auto;
        scrollbar-width: thin;
        -webkit-overflow-scrolling: touch;
    }

    .sidebar nav a {
        min-height: 47px;
        padding: 12px 13px;
        border: 1px solid transparent;
        font-size: 15px;
    }

    .sidebar nav a.active {
        border-color: rgba(255, 255, 255, .08);
        background: rgba(38, 122, 91, .55);
        box-shadow: inset 3px 0 #9ce0ba;
    }

    .sidebar form {
        flex: 0 0 auto;
    }

    .sidebar .logout {
        min-height: 46px;
        margin-top: 10px;
        border: 1px solid rgba(255, 255, 255, .09);
        background: rgba(255, 255, 255, .045);
    }

    .sidebar-backdrop {
        position: fixed;
        z-index: 45;
        inset: 0;
        display: block;
        border: 0;
        background: rgba(3, 24, 18, .52);
        opacity: 0;
        pointer-events: none;
        transition: opacity .22s ease;
        backdrop-filter: blur(2px);
        -webkit-backdrop-filter: blur(2px);
        touch-action: none;
    }

    .sidebar-open {
        overflow: hidden;
    }

    .sidebar-open .sidebar-backdrop {
        opacity: 1;
        pointer-events: auto;
    }

    .menu {
        display: grid;
        width: 42px;
        height: 42px;
        flex: 0 0 42px;
        padding: 0;
        place-items: center;
        border: 1px solid var(--line);
        border-radius: 11px;
        background: var(--surface-soft);
        color: var(--deep);
        cursor: pointer;
        touch-action: manipulation;
    }

    .menu-bars {
        display: grid;
        gap: 4px;
    }

    .menu-bars i {
        display: block;
        width: 19px;
        height: 2px;
        border-radius: 2px;
        background: currentColor;
        transition: transform .18s ease, opacity .18s ease;
    }

    .menu[aria-expanded="true"] .menu-bars i:first-child {
        transform: translateY(6px) rotate(45deg);
    }

    .menu[aria-expanded="true"] .menu-bars i:nth-child(2) {
        opacity: 0;
    }

    .menu[aria-expanded="true"] .menu-bars i:last-child {
        transform: translateY(-6px) rotate(-45deg);
    }

    .topbar {
        min-height: 74px;
        padding: 14px 20px;
        gap: 13px;
    }

    .content {
        padding: 22px 20px 36px;
    }

    .split,
    .two-cols {
        grid-template-columns: 1fr;
    }

    .form-panel {
        width: 100%;
    }

    .filters {
        flex-wrap: wrap;
    }

    .filters input,
    .filters select {
        flex: 1 1 180px;
    }
}

@media (max-width: 780px) {
    .guest {
        display: block;
        min-height: 100svh;
        background:
            radial-gradient(circle at 100% 0, rgba(72, 168, 126, .11), transparent 32%),
            #f8fbf9;
    }

    .login-panel {
        min-height: 100svh;
        padding: 28px 22px;
        place-items: center;
    }

    .mobile-login-brand {
        display: flex;
        align-items: center;
        gap: 11px;
        margin-bottom: clamp(42px, 10vh, 76px);
        color: var(--deep);
    }

    .mobile-login-brand .mark {
        width: 42px;
        height: 42px;
        border-radius: 12px;
    }

    .mobile-login-brand strong,
    .mobile-login-brand small {
        display: block;
    }

    .mobile-login-brand small {
        color: var(--muted);
        font-size: 10px;
        letter-spacing: .12em;
        text-transform: uppercase;
    }

    .login-card h2 {
        font-size: clamp(36px, 11vw, 46px);
    }

    .login-card .stack {
        margin-top: 26px;
    }
}

@media (max-width: 640px) {
    .topbar {
        padding: 12px 14px;
    }

    .topbar p {
        font-size: 10px;
    }

    .topbar h1 {
        overflow: hidden;
        font-size: 18px;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .user > span {
        width: 36px;
        height: 36px;
    }

    .user > div {
        display: none;
    }

    .content {
        padding: 16px 13px 30px;
    }

    .panel {
        padding: 16px;
        border-radius: 13px;
    }

    .page-actions,
    .section-head {
        align-items: stretch;
        flex-wrap: wrap;
    }

    .page-actions {
        justify-content: flex-start;
    }

    .page-actions .inline {
        flex: 1 0 100%;
    }

    .page-actions .inline select,
    .page-actions > .btn {
        min-height: 44px;
    }

    .page-actions > .btn {
        flex: 1 1 145px;
    }

    .section-head > * {
        min-width: 0;
    }

    .section-head h2,
    .panel h2 {
        font-size: 19px;
    }

    .filters {
        display: grid;
        grid-template-columns: 1fr;
        padding: 12px;
    }

    .filters > *,
    .filters input,
    .filters select {
        width: 100%;
    }

    .form-grid,
    .metrics,
    .mini-metrics,
    .fund-grid {
        grid-template-columns: 1fr;
    }

    .span-2 {
        grid-column: auto;
    }

    input,
    select,
    textarea {
        min-height: 46px;
        font-size: 16px;
    }

    .btn {
        min-height: 44px;
    }

    .table-wrap {
        margin-right: -4px;
        margin-left: -4px;
    }

    .table-wrap table {
        min-width: 640px;
    }

    th,
    td {
        padding: 11px 9px;
    }

    .fund-numbers {
        gap: 8px;
    }

    .fund-numbers p {
        min-width: 0;
    }

    .pagination {
        flex-wrap: wrap;
        gap: 10px;
    }

    .empty {
        padding: 48px 16px;
    }
}

@media (max-width: 420px) {
    .page-actions > .btn {
        flex-basis: 100%;
    }

    .login-panel {
        padding: 22px 17px;
    }

    .mobile-login-brand {
        margin-bottom: 42px;
    }

    .fund-numbers {
        font-size: 12px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        transition-duration: .01ms !important;
        animation-duration: .01ms !important;
    }
}

/* Shared interface polish */
:root {
    --canvas: #f5f8f6;
    --canvas-deep: #edf3ef;
    --border-soft: #dbe7e0;
    --text-soft: #708079;
}

body {
    background:
        radial-gradient(circle at 96% 4%, rgba(33, 129, 91, .055), transparent 26rem),
        linear-gradient(180deg, #f9fbfa 0, var(--canvas) 280px);
}

.topbar {
    border-bottom-color: rgba(205, 221, 212, .82);
    background: rgba(255, 255, 255, .92);
    box-shadow: 0 8px 28px rgba(13, 61, 45, .035);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.page-heading p {
    color: #7c8d86;
    font-weight: 600;
    letter-spacing: .018em;
}

.page-heading h1 {
    color: #13372b;
    font-size: clamp(22px, 2vw, 28px);
    letter-spacing: -.025em;
}

.user > span {
    border: 1px solid #dceae3;
    background: linear-gradient(145deg, #edf7f2, #e5f1eb);
    box-shadow: inset 0 1px #fff;
}

.panel {
    border-color: rgba(211, 226, 218, .9);
    border-radius: 16px;
    box-shadow: 0 14px 34px rgba(14, 66, 48, .065);
}

.panel h2,
.section-head h2 {
    color: #183b30;
    letter-spacing: -.018em;
}

.page-actions {
    margin-bottom: 22px;
}

.report-page-actions {
    align-items: flex-end;
    justify-content: space-between;
}

.page-action-buttons {
    display: flex;
    margin-left: auto;
    align-items: center;
    gap: 10px;
}

.period-toolbar {
    display: flex;
    flex-wrap: wrap;
    min-width: 0;
    max-width: 860px;
    padding: 11px 12px;
    flex: 1 1 580px;
    align-items: flex-end;
    gap: 10px;
    border: 1px solid var(--border-soft);
    border-radius: 14px;
    background: rgba(255, 255, 255, .88);
    box-shadow: 0 9px 25px rgba(13, 64, 46, .055);
}

.period-control,
.filter-control {
    display: grid;
    min-width: 0;
    gap: 5px;
}

.period-control {
    flex: 1 1 145px;
}

.period-control-wide {
    flex-basis: 220px;
}

.period-control > span,
.filter-control > span {
    padding-left: 2px;
    color: #75867f;
    font-size: 10px;
    font-weight: 750;
    letter-spacing: .075em;
    line-height: 1;
    text-transform: uppercase;
}

.period-control select,
.filter-control input,
.filter-control select {
    min-height: 40px;
    border-color: #d5e3db;
    background-color: #fbfdfc;
    box-shadow: inset 0 1px 1px rgba(10, 45, 33, .025);
}

.period-apply,
.filter-submit {
    min-height: 40px;
    border-color: #cfe0d7;
    background: #edf6f1;
    color: #145f44;
    white-space: nowrap;
}

.report-period-summary {
    position: relative;
    display: flex;
    min-height: 52px;
    margin: 0 0 24px;
    padding: 12px 16px 12px 48px;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    overflow: hidden;
    border: 1px solid #d7e7de;
    border-radius: 13px;
    background: linear-gradient(100deg, #edf7f2, #f9fcfa 64%);
    box-shadow: inset 3px 0 #348766;
}

.report-period-summary::before {
    content: "◷";
    position: absolute;
    left: 17px;
    display: grid;
    width: 23px;
    height: 23px;
    place-items: center;
    border-radius: 7px;
    background: #dcefe5;
    color: #176b4d;
    font-size: 13px;
}

.report-period-summary b {
    color: #21463a;
    font-size: 13px;
}

.report-period-summary span {
    color: #71837b;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .025em;
}

.record-filters {
    display: grid;
    grid-template-columns: repeat(2, minmax(130px, .65fr)) minmax(220px, 1.35fr) minmax(150px, .8fr) minmax(130px, .65fr) auto;
    align-items: end;
    gap: 12px;
    padding: 16px;
    border-radius: 16px;
    background: rgba(255, 255, 255, .9);
}

.record-filters .period-control,
.record-filters .filter-control {
    width: 100%;
}

.record-filters .filter-search {
    min-width: 220px;
}

.record-filters .filter-submit {
    padding-inline: 17px;
}

.report-metrics {
    grid-template-columns: repeat(3, minmax(160px, 1fr));
}

.report-metrics article {
    position: relative;
    overflow: hidden;
    min-height: 112px;
    padding-top: 22px;
}

.report-metrics article::before {
    content: "";
    position: absolute;
    inset: 0 0 auto;
    height: 3px;
    background: #38906c;
}

.report-metrics article:nth-child(2)::before { background: #b5636b; }
.report-metrics article:nth-child(3)::before { background: #5c7798; }
.report-metrics article:nth-child(4)::before { background: #b48655; }

table thead th {
    padding-top: 11px;
    padding-bottom: 11px;
    border-bottom-color: #dce8e1;
    background: #f5f9f7;
    color: #71827b;
}

table thead th:first-child { border-radius: 9px 0 0 9px; }
table thead th:last-child { border-radius: 0 9px 9px 0; }

tbody td {
    border-bottom-color: #e9f0ec;
}

tbody tr:last-child td {
    border-bottom: 0;
}

.badge {
    border: 1px solid rgba(85, 116, 102, .08);
    font-weight: 700;
    letter-spacing: .015em;
}

.pagination span,
.pagination a {
    display: inline-flex;
    min-height: 36px;
    padding: 7px 12px;
    align-items: center;
    border: 1px solid var(--border-soft);
    border-radius: 9px;
    background: #fff;
}

.pagination span {
    color: var(--text-soft);
}

@media (max-width: 1220px) {
    .record-filters {
        grid-template-columns: repeat(3, minmax(150px, 1fr));
    }

    .record-filters .filter-search {
        min-width: 0;
    }
}

@media (max-width: 780px) {
    .report-page-actions {
        align-items: stretch;
    }

    .period-toolbar {
        max-width: none;
        flex-basis: 100%;
        flex-wrap: wrap;
    }

    .period-control,
    .period-control-wide {
        flex: 1 1 calc(50% - 6px);
    }

    .period-apply {
        flex: 1 1 100%;
    }

    .page-action-buttons {
        margin-left: 0;
    }

    .record-filters,
    .report-metrics {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 560px) {
    .page-action-buttons {
        width: 100%;
        flex-wrap: wrap;
    }

    .page-action-buttons > .btn {
        min-height: 44px;
        flex: 1 1 145px;
    }

    .period-control,
    .period-control-wide,
    .record-filters > * {
        flex-basis: 100%;
        grid-column: 1 / -1;
    }

    .record-filters,
    .report-metrics {
        grid-template-columns: 1fr;
    }

    .report-period-summary {
        padding-left: 46px;
        align-items: flex-start;
        flex-direction: column;
        gap: 2px;
    }

    .report-period-summary::before {
        top: 14px;
    }
}

/* Align field content with its language while keeping the surrounding form stable. */
input[dir],
textarea[dir],
select[dir],
option[dir] {
    text-align: start;
    letter-spacing: normal;
}

textarea[dir="auto"] {
    line-height: 1.65;
    unicode-bidi: plaintext;
}

.expense-availability-panel {
    display: grid;
    gap: 5px;
    align-content: start;
    margin: 0;
    min-height: 128px;
    grid-column: 2;
    grid-row: 2 / span 3;
}

.expense-availability-panel [data-expense-parent-use] {
    color: #176b4d;
    font-weight: 700;
}

.expense-availability-panel [data-expense-parent-use].danger {
    color: #b43a3a;
}

@media (max-width: 780px) {
    .expense-availability-panel {
        grid-column: auto;
        grid-row: auto;
    }
}

tr[data-transaction-row]{cursor:pointer}
tr[data-transaction-row]:hover,tr[data-transaction-row]:focus-within{background:#eff6f2}
a[data-transaction-link]{text-decoration:underline;text-underline-offset:3px}

.sidebar-dropdown summary{display:flex;align-items:center;gap:12px;padding:11px 13px;border-radius:9px;color:#bcd1c9;cursor:pointer;list-style:none}
.sidebar-dropdown summary::-webkit-details-marker{display:none}
.sidebar-dropdown summary:hover,.sidebar-dropdown[open]>summary{background:#174c3a;color:#fff}
.sidebar-dropdown-arrow{margin-left:auto;transition:transform .15s;font-size:22px;line-height:1}
.sidebar-dropdown[open] .sidebar-dropdown-arrow{transform:rotate(90deg)}
.sidebar nav .sidebar-dropdown a{margin:4px 0 0 24px;padding-left:21px;font-size:13px}
.sidebar-dropdown summary:focus-visible{outline:2px solid #bce7cc;outline-offset:2px}
.orphan-record-details{min-width:120px;max-width:320px}.orphan-record-details summary{cursor:pointer;color:var(--green)}
.orphan-record-details dl{white-space:normal;min-width:230px}.orphan-record-details dt{font-size:12px;color:var(--muted);margin-top:10px}.orphan-record-details dd{margin:3px 0;white-space:pre-wrap;overflow-wrap:anywhere}
