:root {
    --bg: #f5f7f2;
    --panel: #ffffff;
    --ink: #20231f;
    --muted: #697066;
    --line: #dfe5d8;
    --green: #2f7d4f;
    --blue: #2b6f95;
    --gold: #bd8a2b;
    --red: #b6453c;
    --shadow: 0 12px 28px rgba(28, 35, 27, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", Arial, sans-serif;
}

button,
input,
select,
textarea {
    font: inherit;
}

button {
    cursor: pointer;
}

.finance-shell {
    width: min(1280px, 100%);
    margin: 0 auto;
    padding: 18px 14px 84px;
}

.finance-topbar,
.tool-strip,
.pane-head,
.customer-head,
.detail-head,
.form-actions,
.receivable-row,
.payment-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.finance-topbar {
    align-items: flex-start;
    margin-bottom: 16px;
}

.eyebrow,
p,
h1,
h2,
h3 {
    margin-top: 0;
}

.eyebrow {
    margin-bottom: 4px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
}

h1 {
    margin-bottom: 0;
    font-size: 34px;
    line-height: 1.05;
}

h2,
h3 {
    margin-bottom: 0;
}

.quick-links {
    position: relative;
    display: grid;
    grid-template-columns: repeat(4, max-content);
    justify-content: flex-end;
    justify-items: end;
    gap: 8px;
}

.quick-links .more-menu {
    grid-column: 1 / -1;
    justify-self: end;
}

.quick-links a,
.btn {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 14px;
    border: 1px solid var(--green);
    border-radius: 8px;
    background: var(--green);
    color: #ffffff;
    text-decoration: none;
    font-weight: 900;
}

.btn.ghost,
.quick-links a {
    border-color: var(--line);
    background: var(--panel);
    color: var(--green);
}

.btn.danger {
    border-color: #e8c5bf;
    background: #fff4f2;
    color: var(--red);
}

.btn.compact {
    min-height: 36px;
    padding: 7px 10px;
    font-size: 14px;
}

.more-menu {
    position: relative;
}

.more-menu summary {
    width: 48px;
    min-height: 48px;
    height: 48px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--panel);
    color: var(--green);
    font-size: 22px;
    font-weight: 950;
    line-height: 1;
    cursor: pointer;
    list-style: none;
    aspect-ratio: 1 / 1;
}

.more-menu summary::-webkit-details-marker {
    display: none;
}

.more-menu-panel {
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    z-index: 20;
    width: 220px;
    display: grid;
    gap: 4px;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: var(--shadow);
}

.menu-section {
    padding: 8px 10px 4px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 950;
    letter-spacing: 0;
}

.more-menu-panel a,
.more-menu-panel button {
    width: 100%;
    min-height: 40px;
    justify-content: flex-start;
    border: 0;
    background: transparent;
    color: var(--ink);
    display: inline-flex;
    align-items: center;
    padding: 10px;
    border-radius: 8px;
    text-align: left;
    text-decoration: none;
    font-weight: 900;
}

.more-menu-panel a:hover,
.more-menu-panel button:hover {
    background: #f1f6ee;
    color: var(--green);
}

body.modal-open {
    overflow: hidden;
}

.finance-editor-modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    background: var(--bg);
}

.finance-editor-modal.is-hidden {
    display: none;
}

.finance-editor-shell {
    height: 100vh;
    height: 100dvh;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    overflow: hidden;
}

.finance-editor-head {
    min-height: 78px;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 14px;
    padding: 12px 18px;
    border-bottom: 1px solid var(--line);
    background: var(--panel);
}

.modal-close-btn {
    width: 54px;
    height: 54px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfcf8;
    color: var(--ink);
    font-size: 34px;
    font-weight: 900;
    line-height: 1;
}

.finance-editor-body {
    min-height: 0;
    height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px;
    -webkit-overflow-scrolling: touch;
}

.finance-editor-body.no-padding {
    padding: 0;
}

.finance-unit-frame {
    width: 100%;
    height: 100%;
    display: block;
    border: 0;
    background: var(--bg);
}

body.embedded-page .finance-shell {
    width: 100%;
    padding: 14px 14px 48px;
}

.settings-modal-panel {
    width: min(1280px, 100%);
    margin: 0 auto 48px;
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 14px;
}

.summary-grid article,
.tool-strip,
.asset-board,
.month-board,
.customer-pane,
.finance-detail,
.payment-log {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: var(--shadow);
}

.summary-grid article {
    padding: 14px;
}

.month-board {
    margin-bottom: 14px;
    padding: 14px;
}

.asset-board {
    margin-bottom: 14px;
    padding: 14px;
}

.analysis-board {
    margin-bottom: 14px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: var(--shadow);
}

.month-summary-grid,
.asset-summary-grid,
.analysis-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
    margin: 12px 0;
}

.asset-summary-grid-six {
    grid-template-columns: repeat(6, minmax(0, 1fr));
}

.month-summary-grid article,
.asset-summary-grid article,
.analysis-grid article,
.collection-card {
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfcf8;
}

.month-summary-grid span,
.asset-summary-grid span,
.analysis-grid span {
    display: block;
    font-size: 24px;
    font-weight: 950;
}

.month-summary-grid p,
.asset-summary-grid p,
.analysis-grid p {
    margin-bottom: 0;
    color: var(--muted);
    font-weight: 800;
}

.account-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 10px;
}

.account-card {
    display: grid;
    gap: 6px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfcf8;
}

.account-card.is-muted {
    opacity: .62;
}

.account-card span {
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
}

.account-card strong {
    font-size: 17px;
}

.account-card b {
    font-size: 22px;
}

.account-card .btn {
    width: 100%;
    min-height: 36px;
    padding: 7px 10px;
}

.loan-workspace {
    align-items: start;
}

.loan-list {
    display: grid;
    gap: 10px;
}

.loan-card {
    width: 100%;
    display: grid;
    gap: 6px;
    padding: 14px;
    border: 1px solid var(--line);
    border-left: 5px solid var(--green);
    border-radius: 8px;
    background: #fbfcf8;
    color: var(--ink);
    text-align: left;
}

.loan-card.is-active {
    border-color: var(--green);
    box-shadow: 0 0 0 2px rgba(47, 125, 79, 0.13);
}

.loan-card span,
.loan-card small {
    color: var(--muted);
    font-weight: 850;
}

.loan-card strong {
    font-size: 20px;
}

.loan-card b {
    font-size: 28px;
}

.account-form {
    margin-top: 14px;
}

.expense-items-panel {
    display: grid;
    gap: 10px;
    margin-top: 14px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfcf8;
}

.quick-item-line,
.expense-item-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    align-items: center;
}

.expense-items {
    display: grid;
    gap: 8px;
}

.expense-item-row {
    grid-template-columns: minmax(160px, 1.4fr) minmax(76px, .6fr) minmax(70px, .6fr) minmax(96px, .8fr) auto;
}

.settings-list {
    display: grid;
    gap: 8px;
    margin-top: 12px;
}

.check-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-top: 8px;
    max-height: 280px;
    overflow: auto;
    padding-right: 4px;
}

.check-chip {
    min-height: 40px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfcf8;
    font-weight: 850;
    min-width: 0;
}

.check-chip span {
    min-width: 0;
    overflow-wrap: anywhere;
}

.setting-row {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfcf8;
    color: var(--ink);
    text-align: left;
}

.setting-row.is-recently-saved {
    border-color: var(--green);
    background: #edf5ee;
    box-shadow: inset 4px 0 0 var(--green);
}

.setting-row span {
    color: var(--muted);
    font-weight: 800;
    text-align: right;
    overflow-wrap: anywhere;
}

.expense-settings-grid {
    display: grid;
    grid-template-columns: minmax(280px, .8fr) minmax(420px, 1.2fr);
    gap: 14px;
    align-items: start;
}

.vendor-settings-form {
    display: grid;
    gap: 12px;
}

.vendor-settings-form .form-grid {
    grid-template-columns: minmax(0, 1.4fr) minmax(140px, .55fr) minmax(110px, .45fr) minmax(120px, .45fr);
}

.vendor-settings-form .wide {
    grid-column: span 2;
}

.vendor-settings-form .vendor-profile-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.vendor-link-panel {
    display: grid;
    gap: 8px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfcf8;
}

.vendor-link-panel h4 {
    margin: 0;
    font-size: 15px;
}

.vendor-link-panel .check-grid {
    grid-template-columns: 1fr;
}

.vendor-link-panel .check-chip {
    min-height: 44px;
    display: grid;
    grid-template-columns: 28px minmax(0, 1fr);
    align-items: center;
    gap: 10px;
    color: var(--ink);
    font-size: 15px;
    line-height: 1.35;
}

.vendor-link-panel .check-chip input {
    width: 18px;
    min-height: 18px;
    margin: 0;
    padding: 0;
}

.vendor-link-panel .check-chip span {
    display: block;
    min-width: 0;
    white-space: normal;
    word-break: keep-all;
    overflow-wrap: anywhere;
}

.analysis-grid {
    grid-template-columns: repeat(6, minmax(0, 1fr));
}

.analysis-columns {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.bar-list {
    display: grid;
    gap: 10px;
    margin-top: 10px;
}

.bar-row {
    display: grid;
    gap: 7px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfcf8;
}

.bar-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
}

.bar-head span {
    color: var(--muted);
    font-weight: 800;
    text-align: right;
}

.bar-track {
    height: 10px;
    overflow: hidden;
    border-radius: 999px;
    background: #e8eee2;
}

.bar-track i {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: var(--green);
}

.bar-track.secondary i {
    background: var(--gold);
}

.month-board-grid {
    display: grid;
    grid-template-columns: 1.2fr .8fr;
    gap: 12px;
}

.collection-list {
    display: grid;
    gap: 8px;
    margin-top: 10px;
}

.collection-card {
    width: 100%;
    display: grid;
    gap: 6px;
    text-align: left;
    color: var(--ink);
}

button.collection-card {
    cursor: pointer;
}

.collection-card strong {
    font-size: 18px;
}

.collection-card span {
    color: var(--muted);
    font-weight: 800;
}

.collection-money {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.summary-grid span {
    display: block;
    font-size: 28px;
    font-weight: 950;
}

.summary-grid p {
    margin-bottom: 0;
    color: var(--muted);
    font-weight: 800;
}

.tool-strip {
    flex-wrap: wrap;
    margin-bottom: 14px;
    padding: 12px;
}

.filter-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.filter-tabs button {
    min-height: 42px;
    padding: 8px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f8faf6;
    color: var(--ink);
    font-weight: 900;
}

.filter-tabs button.is-active {
    border-color: var(--green);
    background: var(--green);
    color: #ffffff;
}

label {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
}

input,
select,
textarea {
    width: 100%;
    min-height: 44px;
    padding: 10px 11px;
    border: 1px solid #cbd5c3;
    border-radius: 8px;
    background: #ffffff;
    color: var(--ink);
}

textarea {
    min-height: 82px;
    resize: vertical;
}

.search-box {
    min-width: min(420px, 100%);
}

.finance-workspace {
    display: grid;
    grid-template-columns: minmax(310px, .86fr) minmax(0, 1.45fr);
    gap: 14px;
    align-items: start;
}

.customer-pane,
.finance-detail,
.payment-log {
    padding: 14px;
}

.customer-list {
    display: grid;
    gap: 10px;
    margin-top: 12px;
}

.customer-card {
    width: 100%;
    text-align: left;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfcf8;
    color: var(--ink);
}

.customer-card.is-active {
    border-color: var(--green);
    box-shadow: inset 4px 0 0 var(--green);
}

.customer-card h3 {
    font-size: 20px;
}

.customer-card p {
    margin: 8px 0 0;
    color: var(--muted);
    font-weight: 800;
}

.customer-money {
    font-size: 22px;
    font-weight: 950;
}

.status-pill,
.overdue-pill {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    padding: 4px 9px;
    border-radius: 999px;
    background: #edf5ee;
    color: var(--green);
    font-size: 13px;
    font-weight: 900;
}

.overdue-pill {
    background: #fff1ef;
    color: var(--red);
}

.empty-panel,
.empty-state {
    display: grid;
    gap: 8px;
    padding: 24px;
    border: 1px dashed #cbd5c3;
    border-radius: 8px;
    color: var(--muted);
    font-weight: 800;
}

.detail-head {
    align-items: flex-start;
    margin-bottom: 14px;
}

.detail-head h2 {
    font-size: 28px;
}

.facts-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
    margin: 0 0 14px;
}

.facts-grid div,
.receivable-row,
.payment-form,
.payment-card {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f8faf6;
    padding: 12px;
}

.facts-grid dt {
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
}

.facts-grid dd {
    margin: 4px 0 0;
    font-size: 18px;
    font-weight: 950;
}

.receivable-list,
.payment-list {
    display: grid;
    gap: 10px;
    margin-top: 12px;
}

.receivable-row {
    align-items: center;
}

.receivable-row.is-paid {
    opacity: .7;
}

.receivable-main {
    display: grid;
    gap: 4px;
}

.receivable-main strong {
    font-size: 18px;
}

.receivable-main span {
    color: var(--muted);
    font-weight: 800;
}

.receivable-money {
    display: grid;
    gap: 6px;
    min-width: 170px;
}

.receivable-money input {
    text-align: right;
    font-weight: 900;
}

.payment-form {
    margin-top: 16px;
    background: #fffdf7;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.form-grid .wide {
    grid-column: 1 / -1;
}

.form-actions {
    margin-top: 12px;
}

.payment-log {
    margin-top: 14px;
}

.expense-grid {
    display: grid;
    grid-template-columns: minmax(320px, .9fr) minmax(0, 1.1fr);
    gap: 14px;
    align-items: start;
}

.section-gap {
    margin-top: 16px;
}

.payment-card {
    align-items: flex-start;
}

.payment-card-side {
    display: grid;
    justify-items: end;
    gap: 8px;
}

.payment-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
}

.payment-card strong {
    font-size: 18px;
}

.payment-card span {
    color: var(--muted);
    font-weight: 800;
}

.toast {
    position: fixed;
    right: 16px;
    bottom: 16px;
    max-width: min(360px, calc(100% - 32px));
    padding: 12px 14px;
    border-radius: 8px;
    background: #1f2a22;
    color: #ffffff;
    font-weight: 900;
    opacity: 0;
    transform: translateY(8px);
    pointer-events: none;
    transition: opacity .18s ease, transform .18s ease;
}

.toast.is-visible {
    opacity: 1;
    transform: translateY(0);
}

@media (max-width: 860px) {
    .finance-topbar,
    .detail-head,
    .receivable-row,
    .payment-card {
        display: grid;
    }

    .quick-links {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        justify-content: flex-start;
        width: 100%;
    }

    .quick-links a {
        width: 100%;
    }

    .summary-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .finance-workspace,
    .expense-grid,
    .expense-settings-grid,
    .analysis-columns,
    .month-board-grid,
    .facts-grid,
    .form-grid,
    .asset-summary-grid,
    .analysis-grid,
    .month-summary-grid,
    .asset-summary-grid-six {
        grid-template-columns: 1fr;
    }

    .receivable-money {
        min-width: 0;
    }

    .quick-item-line,
    .expense-item-row {
        grid-template-columns: 1fr;
    }

    .setting-row {
        display: grid;
    }

    .vendor-settings-form .form-grid,
    .vendor-settings-form .vendor-profile-grid,
    .check-grid {
        grid-template-columns: 1fr;
    }

    .vendor-settings-form .wide {
        grid-column: auto;
    }

    .check-grid {
        max-height: 340px;
    }
}
