:root {
    --green: #166534;
    --green2: #22c55e;
    --ink: #17221b;
    --muted: #66756b;
    --surface: #fff;
    --bg: #f4f7f4;
    --border: #e3ebe5;
    --radius: 18px;
    --shadow: 0 10px 30px rgba(22, 101, 52, .08);
    --control-height: 46px;
    --control-height-sm: 38px;
    --control-height-lg: 50px;
    --control-radius: 12px;
    --card-padding: 1.25rem;
    --section-gap: 1.5rem;
    --tap-target: 44px
}
* {
    box-sizing: border-box
}
body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
    line-height: 1.5;
    overflow-x: hidden
}
.app-shell {
    min-height: 100vh
}
.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 255px;
    background: #0f2f1d;
    color: #fff;
    padding: 24px 16px;
    z-index: 1030
}
.brand {
    display: flex;
    align-items: center;
    gap: 11px;
    text-decoration: none;
    color: #fff;
    font-size: 1.25rem;
    font-weight: 800
}
.brand-icon {
    width: 39px;
    height: 39px;
    display: grid;
    place-items: center;
    border-radius: 12px;
    background: linear-gradient(135deg, #4ade80, #16a34a);
    color: #fff
}
.side-nav {
    margin-top: 28px;
    display: grid;
    gap: 6px
}
.side-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 13px;
    color: #c9d9cf;
    text-decoration: none;
    border-radius: 12px;
    font-weight: 600
}
.side-link:hover,
.side-link.active {
    color: #fff;
    background: rgba(255, 255, 255, .11)
}
.side-link i {
    font-size: 1.1rem
}
.sidebar-user {
    margin-top: auto;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 13px;
    border-top: 1px solid rgba(255, 255, 255, .12)
}
.sidebar-user a {
    font-size: .8rem;
    color: #9fc4ac
}
.avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: #d1fae5;
    color: #166534;
    font-weight: 800
}
.main-area {
    min-width: 0;
    min-height: 100vh
}
.topbar {
    height: 72px;
    background: rgba(255, 255, 255, .92);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 22px;
    position: sticky;
    top: 0;
    z-index: 1020
}
.topbar-title {
    font-weight: 800
}
.topbar-subtitle {
    font-size: .78rem;
    color: var(--muted)
}
.content {
    padding: 24px;
    max-width: 1500px;
    min-width: 0
}
.page-head {
    display: flex;
    justify-content: space-between;
    align-items: end;
    gap: 16px;
    margin-bottom: var(--section-gap)
}
.page-head h1 {
    font-size: clamp(1.45rem, 2vw, 2rem);
    font-weight: 800;
    margin: 0
}
.page-head p {
    color: var(--muted);
    margin: .35rem 0 0
}
.card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: none;
    min-width: 0
}
.card-body {
    min-width: 0;
    padding: var(--card-padding)
}
.card-header,
.card-footer {
    padding: 1rem var(--card-padding);
    border-color: var(--border)
}
.soft-card {
    box-shadow: var(--shadow)
}
.stat-card {
    height: 100%;
    overflow: hidden
}
.stat-icon {
    width: 46px;
    height: 46px;
    border-radius: 14px;
    display: grid;
    place-items: center;
    background: #dcfce7;
    color: var(--green);
    font-size: 1.25rem
}
.stat-value {
    font-size: 1.55rem;
    font-weight: 800
}
.stat-label {
    font-size: .85rem;
    color: var(--muted)
}
.btn,
.form-control,
.form-select,
.input-group-text,
.alert,
.dropdown-menu {
    border-radius: var(--control-radius)
}
.btn {
    min-height: var(--control-height);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .45rem;
    line-height: 1.2;
    white-space: normal
}
.btn-sm {
    min-height: var(--control-height-sm);
    border-radius: 10px
}
.btn-lg {
    min-height: var(--control-height-lg)
}
.btn>i,
.btn>.bi,
.dropdown-item>i,
.dropdown-item>.bi {
    flex: 0 0 auto;
    line-height: 1
}
.btn-success {
    background: var(--green);
    border-color: var(--green)
}
.btn-success:hover {
    background: #14532d;
    border-color: #14532d
}
.form-control,
.form-select {
    min-height: var(--control-height);
    border-color: #dbe5dd;
    line-height: 1.25
}
.form-control-sm,
.form-select-sm {
    min-height: var(--control-height-sm)
}
.form-control-lg,
.form-select-lg {
    min-height: var(--control-height-lg)
}
.form-label {
    margin-bottom: .4rem;
    color: #526057;
    font-size: .82rem;
    font-weight: 700
}
.form-text,
.invalid-feedback,
.valid-feedback {
    overflow-wrap: anywhere
}
.invalid-feedback,
.valid-feedback {
    margin-top: .35rem;
    font-size: .8rem
}
.input-group {
    min-width: 0
}
.input-group>.form-control,
.input-group>.form-select {
    min-width: 0
}
.input-group-text {
    min-height: var(--control-height);
    border-color: #dbe5dd
}
.form-control:focus,
.form-select:focus {
    border-color: #5fbf7c;
    box-shadow: 0 0 0 .2rem rgba(34, 197, 94, .14)
}
.table-card {
    min-width: 0;
    overflow: hidden
}
.table-responsive {
    max-width: 100%;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    -webkit-overflow-scrolling: touch
}
.table {
    margin: 0
}
.table th {
    font-size: .76rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: #637067;
    background: #f8faf8
}
.table td,
.table th {
    padding: 14px 16px;
    vertical-align: middle;
    border-color: #edf1ee;
    overflow-wrap: anywhere
}
.table th {
    white-space: nowrap
}
.table td .badge {
    white-space: normal
}
.action-buttons {
    display: flex;
    gap: 7px;
    flex-wrap: wrap
}
.action-buttons .btn {
    align-self: stretch
}
.table th:last-child,
.table td:last-child {
    width: 1%
}
.table td:last-child .action-buttons {
    min-width: max-content
}
.badge {
    border-radius: 999px;
    padding: .5em .75em;
    line-height: 1.15;
    vertical-align: middle
}
.alert {
    min-width: 0;
    overflow-wrap: anywhere
}
.dropdown-menu {
    max-width: calc(100vw - 1rem);
    padding: .5rem;
    border-color: var(--border);
    box-shadow: var(--shadow)
}
.dropdown-item {
    min-height: var(--tap-target);
    display: flex;
    align-items: center;
    gap: .5rem;
    border-radius: 9px;
    white-space: normal
}
.pagination {
    gap: .35rem;
    margin-bottom: 0
}
.page-link {
    min-width: var(--tap-target);
    min-height: var(--tap-target);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px !important;
    color: var(--green)
}
.page-item.active .page-link {
    background: var(--green);
    border-color: var(--green)
}
.empty-state {
    padding: 45px 20px;
    text-align: center;
    color: var(--muted);
    overflow-wrap: anywhere
}
.empty-state i {
    font-size: 2rem;
    color: #86a88f
}
.empty-state>div {
    margin-top: .5rem
}
.form-card {
    max-width: 850px;
    margin: auto
}
.section-title {
    font-size: 1rem;
    font-weight: 800
}
.invoice-item-row {
    background: #f8fbf8;
    border: 1px solid var(--border);
    border-radius: 15px;
    padding: 14px;
    margin-bottom: 12px
}
.total-box {
    background: #103c24;
    color: #fff;
    border-radius: 16px;
    padding: 18px
}
.report-filter {
    background: #fff;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius)
}
.report-actions {
    position: static;
    z-index: auto
}
.report-nav-card {
    transition: transform .15s ease, border-color .15s ease
}
.report-nav-card:hover {
    transform: translateY(-2px);
    border-color: #86c99b
}
.report-chart {
    position: relative;
    height: 340px;
    min-height: 240px
}
.loading-state,
.workspace-loading {
    min-height: 160px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--muted)
}
.expense-mobile-card {
    padding: var(--card-padding);
    margin-bottom: .75rem;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 4px 16px rgba(16, 60, 36, .06);
    overflow-wrap: anywhere
}
.expense-description {
    max-width: 11.25rem
}
.payment-method-head {
    align-items: center
}
.payment-method-cards {
    display: grid;
    gap: .75rem
}
.payment-method-card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow)
}
.method-usage-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: .5rem;
    margin: 1rem 0
}
.method-usage-grid div {
    min-width: 0;
    padding: .75rem;
    border-radius: var(--control-radius);
    background: #f3faf5;
    text-align: center
}
.method-usage-grid span {
    display: block;
    color: #718077;
    font-size: .75rem;
    overflow-wrap: anywhere
}
.method-usage-grid strong {
    display: block;
    font-size: 1.15rem;
    overflow-wrap: anywhere
}
.payment-method-card .action-buttons .btn {
    flex: 1 1 calc(50% - .5rem)
}
.login-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 1.05fr .95fr;
    background: #eef7f0
}
.login-visual {
    padding: 7vw;
    background: linear-gradient(145deg, rgba(12, 65, 35, .94), rgba(22, 101, 52, .88)),
        url('../images/farm-pattern.svg');
    color: #fff;
    display: flex;
    flex-direction: column;
    justify-content: center
}
.login-visual h1 {
    font-size: clamp(2.4rem, 5vw, 4.5rem);
    font-weight: 900;
    line-height: 1
}
.login-panel {
    display: grid;
    place-items: center;
    padding: 25px
}
.login-card {
    width: min(100%, 440px);
    border: 0;
    box-shadow: 0 24px 70px rgba(15, 47, 29, .16)
}
.icon-btn {
    width: 42px;
    height: 42px
}
.mobile-nav {
    display: grid;
    gap: 7px
}
.mobile-nav a {
    display: flex;
    gap: 12px;
    padding: 12px;
    color: #29362e;
    text-decoration: none;
    border-radius: 12px;
    font-weight: 650
}
.mobile-nav a:hover {
    background: #eef7f0
}
.mobile-nav a.active {
    color: var(--green);
    background: #e7f7ec
}
.modal-header {
    align-items: center;
    border-color: var(--border)
}
.modal-title {
    font-weight: 750
}
.modal-footer {
    gap: .5rem;
    border-color: var(--border)
}
.modal-footer .btn {
    min-width: 7rem
}
.modal-body .mb-3:last-child {
    margin-bottom: 0 !important
}
@media(min-width: 992px) {
    .main-area {
        margin-left: 255px
    }
}
@media(max-width: 767.98px) {
    .content {
        padding: 16px 12px 90px
    }
    .topbar {
        height: 64px;
        padding: 0 12px
    }
    .page-head {
        align-items: stretch;
        flex-direction: column
    }
    .page-head h1,
    .page-head p {
        overflow-wrap: anywhere
    }
    .page-head>.btn, .page-head>.d-flex {
        width: 100%
    }
    .page-head>.btn {
        display: block
    }
    .mobile-stack-table thead {
        display: none
    }
    .mobile-stack-table, .mobile-stack-table tbody, .mobile-stack-table tr, .mobile-stack-table td {
        display: block;
        width: 100%
    }
    .mobile-stack-table tr {
        padding: 12px;
        border-bottom: 8px solid var(--bg)
    }
    .mobile-stack-table td {
        border: 0;
        padding: .4rem .5rem;
        white-space: normal;
        overflow-wrap: anywhere
    }
    .expense-description {
        max-width: none
    }
    .mobile-stack-table td:before {
        content: attr(data-label);
        display: block;
        font-size: .68rem;
        font-weight: 800;
        text-transform: uppercase;
        color: #7b8a80
    }
    .action-buttons .btn, .action-buttons form {
        flex: 1
    }
    .table th:last-child,
    .table td:last-child {
        width: auto
    }
    .table td:last-child .action-buttons {
        min-width: 0
    }
    .action-buttons form .btn {
        width: 100%
    }
    .login-shell {
        grid-template-columns: 1fr
    }
    .login-visual {
        display: none
    }
    .login-panel {
        padding: 15px
    }
    .table-card {
        background: transparent;
        border: 0
    }
    .table-card .table {
        background: #fff
    }
    .invoice-item-row .btn-remove-item {
        width: 100%
    }
    .report-actions,
    .report-actions .btn {
        width: 100%
    }
    .report-actions .btn {
        flex: 1 1 10rem
    }
    .report-filter [class*="col-"] {
        min-width: 0
    }
    .report-chart {
        height: 280px
    }
    .pagination {
        justify-content: center
    }
}
@media(max-width: 575.98px) {
    .expense-page-head .d-flex,
    .expense-page-head .btn {
        width: 100%
    }
    .app-modal .modal-footer {
        position: sticky;
        bottom: 0;
        z-index: 2;
        background: #fff
    }
    .app-modal .modal-footer .btn {
        flex: 1;
        min-height: var(--tap-target)
    }
    .method-usage-grid {
        grid-template-columns: 1fr
    }
    .payment-method-head {
        align-items: stretch
    }
    .payment-method-head>.btn {
        width: 100%
    }
}
.sidebar-user {
    flex-wrap: wrap;
    padding: 14px 5px 2px;
    gap: 7px
}
.sidebar-profile-link {
    min-width: 0;
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    border-radius: 13px;
    color: #fff!important;
    text-decoration: none;
    transition: background .16s ease, transform .16s ease
}
.sidebar-profile-link:hover {
    background: rgba(255, 255, 255, .1);
    transform: translateY(-1px)
}
.sidebar-profile-name {
    min-width: 0;
    flex: 1;
    font-size: .86rem;
    font-weight: 750
}
.sidebar-profile-arrow {
    font-size: .72rem;
    color: #8fbea0;
    transition: transform .16s ease
}
.sidebar-profile-link:hover .sidebar-profile-arrow {
    transform: translateX(2px);
    color: #d7f6e1
}
.sidebar-signout {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 7px 12px 7px 56px;
    border-radius: 10px;
    font-size: .78rem!important;
    color: #9fc4ac!important;
    text-decoration: none
}
.sidebar-signout:hover {
    color: #fff!important;
    background: rgba(255, 255, 255, .07)
}
.sidebar .sidebar-user {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    align-items: stretch;
    gap: 6px;
    padding: 14px 8px 4px;
    border-top: 1px solid rgba(255, 255, 255, .12)
}
.sidebar .sidebar-profile-link {
    width: 100%;
    min-width: 0;
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr) 18px;
    align-items: center;
    gap: 10px;
    padding: 10px;
    border: 1px solid rgba(255, 255, 255, .08);
    border-radius: 14px;
    background: rgba(255, 255, 255, .055);
    color: #fff!important;
    text-decoration: none!important;
    transition: background .16s ease, border-color .16s ease, transform .16s ease
}
.sidebar .sidebar-profile-link:hover {
    background: rgba(255, 255, 255, .11);
    border-color: rgba(134, 239, 172, .3);
    transform: translateY(-1px)
}
.sidebar .sidebar-profile-link .avatar {
    width: 42px;
    height: 42px;
    border: 2px solid rgba(255, 255, 255, .28);
    box-shadow: 0 6px 16px rgba(0, 0, 0, .18)
}
.sidebar .sidebar-profile-name {
    min-width: 0;
    display: block;
    color: #fff;
    font-size: .84rem;
    font-weight: 750;
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-decoration: none
}
.sidebar .sidebar-profile-arrow {
    display: block;
    justify-self: end;
    color: #86d69f;
    font-size: .72rem
}
.sidebar .sidebar-signout {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 9px 12px;
    border-radius: 11px;
    color: #a8cbb4!important;
    font-size: .78rem!important;
    font-weight: 650;
    text-decoration: none!important;
    transition: color .16s ease, background .16s ease
}
.sidebar .sidebar-signout:hover {
    color: #fff!important;
    background: rgba(220, 53, 69, .16)
}

/* Keep numeric validation while hiding browser increment/decrement controls. */
input[type="number"] {
    appearance: textfield;
    -moz-appearance: textfield
}
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
    margin: 0;
    -webkit-appearance: none
}

/* SweetAlert confirmations opened above Bootstrap workspace modals. */
.swal2-container {
    z-index: 20000 !important
}

.swal2-container .swal2-textarea {
    pointer-events: auto;
    touch-action: manipulation
}

/*
 * Application modal contract
 *
 * Header and footer stay in the modal's flex column while only the body scrolls.
 * The form selector supports existing modals whose form wraps all three sections.
 */
.app-modal {
    --app-modal-viewport-gap: 1rem;
    --app-modal-body-safe-space: calc(1.5rem + env(safe-area-inset-bottom, 0px))
}
.app-modal .modal-dialog {
    width: auto;
    max-height: calc(100vh - (var(--app-modal-viewport-gap) * 2));
    max-height: calc(100dvh - (var(--app-modal-viewport-gap) * 2));
    margin-top: var(--app-modal-viewport-gap);
    margin-bottom: var(--app-modal-viewport-gap)
}
.app-modal .modal-content,
.app-modal .modal-content>form {
    min-width: 0;
    min-height: 0;
    max-height: calc(100vh - (var(--app-modal-viewport-gap) * 2));
    max-height: calc(100dvh - (var(--app-modal-viewport-gap) * 2));
    overflow: hidden
}
.app-modal .modal-content>form {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column
}
.app-modal .modal-header,
.app-modal .modal-footer {
    position: static;
    flex: 0 0 auto;
    min-width: 0
}
.app-modal .modal-header {
    padding-top: max(1rem, env(safe-area-inset-top, 0px))
}
.app-modal .modal-title,
.app-modal .modal-body,
.app-modal .modal-body *,
.app-modal .modal-footer {
    min-width: 0;
    overflow-wrap: anywhere
}
.app-modal .modal-body {
    flex: 1 1 auto;
    padding-bottom: var(--app-modal-body-safe-space);
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch
}
.app-modal .modal-body img,
.app-modal .modal-body svg,
.app-modal .modal-body table {
    max-width: 100%
}
.app-modal .modal-footer {
    gap: .5rem;
    flex-wrap: wrap;
    padding-bottom: max(.75rem, env(safe-area-inset-bottom, 0px));
    background: var(--bs-modal-bg, #fff)
}
.app-modal .form-control,
.app-modal .form-select,
.app-modal .btn {
    min-height: 44px
}
@media(max-width: 575.98px) {
    .app-modal {
        --app-modal-viewport-gap: 0px
    }
    .app-modal .modal-dialog:not(.modal-fullscreen-sm-down) {
        margin-right: .5rem;
        margin-left: .5rem
    }
    .app-modal .modal-footer .btn {
        flex: 1 1 9rem
    }
}
