:root {
    --bg: #eef2ee;
    --surface: #ffffff;
    --surface-soft: #f8faf7;
    --ink: #16201c;
    --muted: #66736b;
    --line: #dbe4dc;
    --line-strong: #c8d4ca;
    --teal: #0f766e;
    --teal-dark: #115e59;
    --teal-soft: #e4f4f1;
    --amber: #b7791f;
    --amber-soft: #fff7e6;
    --red: #b91c1c;
    --red-soft: #fff1f1;
    --green: #15803d;
    --green-soft: #edf8ef;
    --shadow: 0 18px 42px rgba(22, 32, 28, .08);
    --shadow-soft: 0 8px 22px rgba(22, 32, 28, .06);
    --font: Calibri, Arial, Helvetica, sans-serif;
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    background: var(--bg);
}

body {
    margin: 0;
    min-height: 100%;
    background:
        linear-gradient(180deg, rgba(15, 118, 110, .08), transparent 260px),
        var(--bg);
    color: var(--ink);
    font-family: var(--font);
}

button,
input,
select,
textarea {
    font-family: var(--font);
}

button,
input,
select {
    font-size: 14px;
    line-height: 1.3;
}

.txn-type-mobile {
    display: none;
}

.txn-note {
    display: block;
    margin-top: 2px;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.25;
}

strong,
h1,
h2,
.metric strong,
.loan-balance strong,
.loan-facts strong,
.compact-item strong,
.rows strong,
.badge {
    font-family: var(--font);
    letter-spacing: 0;
}

button,
select {
    -webkit-tap-highlight-color: transparent;
}

.app-shell {
    width: min(1120px, 100%);
    margin: 0 auto;
    padding: 18px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 16px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.brand img {
    width: 58px;
    height: 58px;
    flex: 0 0 auto;
    border: 3px solid #121212;
    border-radius: 50%;
    background: #fff;
    object-fit: cover;
    box-shadow: var(--shadow-soft);
}

.eyebrow {
    margin: 0 0 4px;
    color: var(--teal-dark);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0;
    text-transform: uppercase;
}

h1,
h2 {
    margin: 0;
}

h1 {
    color: var(--ink);
    font-size: 30px;
    line-height: 1.12;
    text-transform: uppercase;
}

h2 {
    font-size: 17px;
    line-height: 1.25;
    margin-bottom: 12px;
    text-transform: uppercase;
}

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

.metric {
    min-height: 104px;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow-soft);
}

.metric span {
    display: block;
    min-height: 18px;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.3;
    text-transform: uppercase;
}

.metric strong {
    display: block;
    margin-top: 11px;
    color: var(--ink);
    font-size: 25px;
    line-height: 1.1;
}

.metric.primary {
    border-color: var(--teal);
    background: linear-gradient(135deg, var(--teal), #178f80);
    color: #fff;
    box-shadow: 0 18px 40px rgba(15, 118, 110, .24);
}

.metric.primary span,
.metric.primary strong {
    color: #fff;
}

.tabs {
    position: sticky;
    top: 0;
    z-index: 5;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin: 0 0 14px;
    padding: 8px 0;
    background: rgba(238, 242, 238, .94);
    backdrop-filter: blur(10px);
}

.tab,
.ghost-button,
.primary-button,
.small-button,
.danger-button,
.settle-button {
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: 8px;
    cursor: pointer;
    transition: transform .12s ease, border-color .12s ease, background .12s ease, color .12s ease;
}

.tab:active,
.ghost-button:active,
.primary-button:active,
.small-button:active,
.danger-button:active,
.settle-button:active {
    transform: translateY(1px);
}

.tab {
    background: rgba(255, 255, 255, .86);
    color: var(--muted);
    font-weight: 800;
    text-transform: uppercase;
}

.tab.active {
    border-color: var(--teal);
    background: var(--teal);
    color: #fff;
}

.ghost-button {
    background: rgba(255, 255, 255, .9);
    color: var(--ink);
    padding: 0 14px;
    box-shadow: var(--shadow-soft);
}

.primary-button {
    border-color: var(--teal);
    background: var(--teal);
    color: #fff;
    padding: 0 16px;
    font-weight: 800;
}

.small-button {
    border-color: var(--teal-dark);
    background: var(--teal-dark);
    color: #fff;
    padding: 0 12px;
}

.danger-button {
    border-color: #f3b9b9;
    background: var(--red-soft);
    color: var(--red);
    padding: 0 10px;
}

.settle-button {
    width: 100%;
    margin-top: 12px;
    border-color: var(--green);
    background: var(--green);
    color: #fff;
    font-weight: 800;
}

.panel {
    display: none;
}

.panel.active {
    display: block;
}

.split {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

.split > div,
.form-grid,
.table-wrap,
.loan-card,
.member-card,
.dialog-card {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, .94);
    box-shadow: var(--shadow-soft);
}

.split > div {
    padding: 15px;
}

.rows,
.notice-list {
    display: grid;
    gap: 9px;
}

.rows div,
.compact-item,
.notice-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 46px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-soft);
    padding: 10px 12px;
}

.rows span,
label {
    color: var(--muted);
    text-transform: uppercase;
}

.rows strong,
.compact-item strong,
.notice-item strong {
    text-align: right;
}

.notice-item {
    border-left: 4px solid var(--teal);
}

.notice-item.danger {
    border-left-color: var(--red);
    background: var(--red-soft);
}

.notice-item.warning {
    border-left-color: var(--amber);
    background: var(--amber-soft);
}

.notice-item.success {
    border-left-color: var(--green);
    background: var(--green-soft);
}

.notice-item.info,
.notice-item.calm {
    border-left-color: var(--teal);
    background: var(--teal-soft);
}

.notice-item span {
    color: var(--ink);
    font-weight: 800;
}

.notice-item strong {
    white-space: nowrap;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 14px;
    padding: 14px;
}

.loan-filters {
    display: grid;
    grid-template-columns: minmax(0, 1.6fr) minmax(140px, .7fr) minmax(140px, .7fr) auto;
    align-items: end;
    gap: 10px;
    margin-bottom: 10px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, .94);
    box-shadow: var(--shadow-soft);
}

.loan-member-filter,
.loan-type-filter {
    min-width: 0;
}

.filter-label {
    display: block;
    margin-bottom: 7px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
}

.filter-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
}

.filter-chip {
    min-height: 34px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-soft);
    color: var(--ink);
    padding: 0 11px;
    font-weight: 800;
    cursor: pointer;
}

.filter-chip.active {
    border-color: var(--teal);
    background: var(--teal);
    color: #fff;
    box-shadow: 0 8px 18px rgba(15, 118, 110, .18);
}

.loan-filter-summary {
    margin: 0 0 10px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.member-filters {
    display: grid;
    grid-template-columns: 1fr;
    margin-bottom: 12px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, .94);
    box-shadow: var(--shadow-soft);
}

.date-pair {
    display: grid;
    gap: 8px;
}

.lunar-row {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
}

.lunar-row label {
    font-size: 12px;
}

label {
    display: grid;
    gap: 6px;
    font-size: 13px;
    font-weight: 800;
}

input,
select {
    width: 100%;
    min-height: 42px;
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    background: #fff;
    color: var(--ink);
    padding: 0 11px;
    outline: none;
}

input:focus,
select:focus {
    border-color: var(--teal);
    box-shadow: 0 0 0 3px rgba(15, 118, 110, .14);
}

.lunar-end-display {
    background: var(--surface-soft);
    color: var(--muted);
    font-weight: 800;
}

.due-date-pair .solar-date {
    display: none;
}

.due-date-pair > label:first-child {
    display: none;
}

.due-date-pair {
    align-self: end;
}

.due-date-pair .lunar-row {
    grid-template-columns: 1.2fr 1fr 1fr;
}

.wide,
.checkline {
    grid-column: span 2;
}

.checkline {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 42px;
}

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

.toolbar {
    margin: 0 0 10px;
}

.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    min-width: 760px;
    border-collapse: collapse;
}

th,
td {
    border-bottom: 1px solid var(--line);
    padding: 12px 10px;
    text-align: left;
    vertical-align: top;
}

th {
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

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

.amount-income {
    color: var(--green);
    font-weight: 800;
}

.amount-expense {
    color: var(--red);
    font-weight: 800;
}

.loan-list,
.member-grid {
    display: grid;
    gap: 12px;
}

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

.loan-card,
.member-card {
    padding: 14px;
}

.loan-card-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(140px, 160px);
    gap: 14px;
    align-items: stretch;
}

.loan-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
}

.loan-head h2,
.member-card h2 {
    margin-bottom: 8px;
    text-transform: uppercase;
}

.member-card h2 {
    color: var(--teal-dark);
    font-size: 18px;
    font-weight: 900;
    letter-spacing: 0;
    text-transform: uppercase;
}

.badge-row,
.loan-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
}

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    border-radius: 999px;
    padding: 0 10px;
    background: var(--teal-soft);
    color: var(--teal-dark);
    font-size: 12px;
    font-weight: 800;
}

.status-active {
    background: var(--amber-soft);
    color: var(--amber);
}

.status-paid {
    background: var(--green-soft);
    color: var(--green);
}

.status-overdue {
    background: var(--red-soft);
    color: var(--red);
}

.loan-balance {
    display: grid;
    align-content: center;
    justify-items: end;
    gap: 14px;
    min-height: 68px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-soft);
    padding: 10px;
}

.loan-balance span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
}

.loan-balance strong {
    font-size: 18px;
}

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

.loan-facts div {
    display: grid;
    gap: 4px;
    min-width: 0;
}

.loan-facts span,
.loan-dates {
    display: block;
    color: var(--muted);
    font-size: 12px;
}

.loan-facts strong {
    font-size: 13px;
    white-space: nowrap;
}

.loan-dates {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-top: 8px;
    border-top: 1px solid var(--line);
    padding-top: 8px;
    white-space: nowrap;
}

.loan-dates span:last-child {
    text-align: right;
}

.loan-meta {
    margin-top: 10px;
}

.payment-form {
    display: grid;
    grid-template-columns: 150px 1fr 1fr auto;
    gap: 8px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--line);
}

.settled-note {
    margin-top: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--green-soft);
    color: var(--green);
    padding: 11px 12px;
    font-weight: 800;
    text-align: center;
}

.hidden,
.admin-only {
    display: none !important;
}

body.admin .admin-only {
    display: grid !important;
}

body.admin th.admin-only,
body.admin td.admin-only {
    display: table-cell !important;
}

dialog {
    border: 0;
    background: transparent;
    padding: 0;
}

dialog::backdrop {
    background: rgba(22, 32, 28, .44);
}

.dialog-card {
    width: min(420px, calc(100vw - 32px));
    padding: 18px;
}

.dialog-card p {
    color: var(--muted);
}

.form-error {
    display: none;
    margin: 10px 0;
    border: 1px solid #fecaca;
    border-radius: 8px;
    background: var(--red-soft);
    color: var(--red) !important;
    padding: 10px;
    font-weight: 800;
}

.form-error.active {
    display: block;
}

.dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 14px;
}

.empty {
    color: var(--muted);
    padding: 22px 16px;
    text-align: center;
}

.readonly-note {
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
    text-transform: uppercase;
}

@media (max-width: 920px) {
    .summary-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .split,
    .member-grid,
    .loan-filters {
        grid-template-columns: 1fr;
    }

    .loan-filters {
        gap: 8px;
        padding: 10px;
    }

    .loan-member-filter,
    .loan-type-filter {
        order: 1;
    }

    .loan-filters > label {
        order: 2;
    }

    #clearLoanFilters {
        order: 3;
    }

    .filter-chips {
        gap: 6px;
    }

    .filter-chip {
        min-height: 32px;
        padding: 0 9px;
        font-size: 13px;
    }

    .member-filters {
        grid-template-columns: 1fr;
        padding: 10px;
    }

    .loan-status-filter {
        display: none;
    }
}

@media (min-width: 980px) {
    .loan-list {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    #transactionForm,
    #loanForm {
        grid-template-columns: repeat(12, minmax(0, 1fr));
        align-items: start;
        gap: 12px;
        padding: 16px;
    }

    #transactionForm {
        grid-template-areas: none;
    }

    #transactionForm > label:nth-of-type(1) {
        grid-column: span 3;
    }

    #transactionForm .date-pair {
        grid-column: span 5;
    }

    #transactionForm > label:nth-of-type(2) {
        grid-column: span 4;
    }

    #transactionForm > label:nth-of-type(3) {
        grid-column: span 3;
    }

    #transactionForm .wide {
        grid-column: span 6;
    }

    #transactionForm .primary-button {
        grid-column: span 3;
        width: 100%;
        justify-self: end;
        align-self: end;
    }

    #loanForm {
        grid-auto-flow: dense;
    }

    #loanForm > label:nth-of-type(1),
    #loanForm > label:nth-of-type(2) {
        grid-column: span 3;
    }

    #loanForm .date-pair {
        grid-column: span 6;
    }

    #loanForm .hot-field:not(.checkline),
    #loanForm .share-field,
    #loanForm .other-field {
        grid-column: span 3;
    }

    #loanForm .due-date-pair {
        grid-column: span 6;
    }

    #loanForm .wide {
        grid-column: span 6;
    }

    #loanForm .checkline {
        grid-column: span 6;
        align-self: center;
    }

    #loanForm .primary-button {
        grid-column: span 3;
        width: 100%;
        justify-self: end;
        align-self: end;
    }

    #loanForm .share-field,
    #loanForm .other-field,
    #loanForm .hot-field {
        min-width: 0;
    }

    .date-pair {
        grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
        align-items: end;
    }

    .due-date-pair {
        grid-template-columns: 1fr;
    }

    .lunar-row {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .due-date-pair .lunar-row {
        grid-template-columns: 1.2fr 1fr 1fr;
    }
}

@media (max-width: 760px) {
    .app-shell {
        padding: 12px;
        padding-bottom: 20px;
    }

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

    .brand {
        gap: 10px;
    }

    .brand img {
        width: 48px;
        height: 48px;
        border-width: 2px;
    }

    h1 {
        font-size: 24px;
    }

    .ghost-button {
        min-height: 38px;
        padding: 0 12px;
    }

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

    .metric {
        min-height: 92px;
        padding: 13px;
    }

    .metric.primary {
        grid-column: 1 / -1;
    }

    .metric span {
        font-size: 13px;
    }

    .metric strong {
        font-size: 22px;
    }

    .tabs {
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 6px;
        margin-bottom: 10px;
        padding: 7px 0;
    }

    .tab {
        min-height: 40px;
        font-size: 13px;
    }

    .form-grid,
    .payment-form {
        grid-template-columns: 1fr;
    }

    .wide,
    .checkline {
        grid-column: auto;
    }

    .lunar-row {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .table-wrap {
        overflow: visible;
        border: 0;
        background: transparent;
        box-shadow: none;
    }

    table,
    tbody,
    tr,
    td {
        display: block;
        width: 100%;
        min-width: 0;
    }

    table {
        border-collapse: separate;
        border-spacing: 0 10px;
    }

    thead {
        display: none;
    }

    tr {
        border: 1px solid var(--line);
        border-radius: 8px;
        background: var(--surface);
        box-shadow: 0 4px 12px rgba(22, 32, 28, .04);
        overflow: hidden;
        padding: 11px 12px;
    }

    td {
        display: block;
        border-bottom: 0;
        padding: 0;
    }

    td::before {
        content: none;
    }

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

    td[data-label="Ngày"] {
        display: flex;
        align-items: center;
        justify-content: flex-start;
        gap: 7px;
        min-height: 22px;
        color: var(--muted);
        font-size: 12px;
        font-weight: 800;
    }

    td[data-label="Loại"] {
        display: none;
    }

    .txn-type-mobile {
        display: inline-flex;
        align-items: center;
        min-height: 20px;
        border-radius: 999px;
        padding: 0 8px;
        font-size: 11px;
        font-weight: 900;
        text-transform: uppercase;
    }

    .txn-type-mobile.income {
        background: var(--green-soft);
        color: var(--green);
    }

    .txn-type-mobile.expense {
        background: var(--red-soft);
        color: var(--red);
    }

    td[data-label="Nội dung"] {
        display: block;
        width: 100%;
        margin-top: 8px;
        padding-right: 116px;
        color: var(--ink);
        line-height: 1.35;
    }

    td[data-label="Nội dung"] strong {
        font-size: 13px;
    }

    td[data-label="Người"] {
        display: block;
        width: 100%;
        margin-top: 4px;
        padding-right: 116px;
        color: var(--muted);
        font-size: 12px;
    }

    .txn-person {
        display: block;
    }

    .txn-note {
        margin-top: 3px;
        color: #7a857e;
    }

    td[data-label="Số tiền"] {
        float: right;
        width: 110px;
        margin-top: -42px;
        text-align: right;
        font-size: 13px;
        font-weight: 900;
        white-space: nowrap;
    }

    td[data-label="Thao tác"] {
        clear: both;
        display: flex;
        justify-content: flex-end;
        gap: 8px;
        margin-top: 9px;
        padding-top: 8px;
        border-top: 1px solid var(--line);
    }

    td[data-label="Thao tác"] .small-button,
    td[data-label="Thao tác"] .danger-button {
        min-height: 32px;
    }

    body.admin td.admin-only {
        display: flex !important;
    }

    td.admin-only {
        grid-template-columns: none;
    }

    .loan-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
    }

    .loan-card-grid {
        grid-template-columns: minmax(0, 1fr) minmax(128px, 148px);
        gap: 10px;
    }
}

@media (max-width: 420px) {
    .summary-grid {
        grid-template-columns: 1fr;
    }

    .metric.primary {
        grid-column: auto;
    }

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

    .loan-facts {
        grid-template-columns: 1fr;
    }
}

/* v55: ghi chú quy tắc, lịch sử trả nợ, chi tiết lãi */
.rule-note {
    grid-column: 1 / -1;
    margin: 0;
    color: var(--muted);
    font-size: 13px;
}

.metric small {
    display: block;
    margin-top: 4px;
    color: var(--muted);
    font-size: 11px;
}

.payment-history {
    display: grid;
    gap: 6px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--line);
}

.payment-history-title {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.payment-history-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
}

.payment-history-item span {
    flex: 1;
    min-width: 0;
    overflow-wrap: anywhere;
}

.payment-history-item strong {
    white-space: nowrap;
}

body.admin .payment-history-item .admin-only {
    display: inline-block !important;
    padding: 4px 8px;
}

/* v55: hàng nút Tất toán / Trả 1 phần */
.loan-pay-actions {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 12px;
}

.loan-pay-actions .settle-button {
    width: 100%;
    margin-top: 0;
}

.partial-button {
    min-height: 42px;
    border: 1px solid var(--teal-dark);
    border-radius: 8px;
    background: #fff;
    color: var(--teal-dark);
    font-weight: 800;
    cursor: pointer;
    transition: background .12s ease, color .12s ease;
}

.partial-button:hover,
.partial-button.active {
    background: var(--teal-dark);
    color: #fff;
}

.partial-wrap .payment-form {
    margin-top: 8px;
    padding-top: 0;
    border-top: 0;
}

/* =========================================================
   v58 – Giao diện gọn: dải quỹ, danh sách theo tháng,
   thẻ vay có tiến độ, danh sách thành viên đang nợ.
   Các selector bắt đầu bằng .app-shell để thắng quy tắc cũ.
   ========================================================= */
:root {
    --font: 'Be Vietnam Pro', 'Segoe UI', Arial, sans-serif;
    --bg: #eef2ef;
    --ink: #15211d;
    --muted: #5d6b64;
    --line: #dde5df;
    --radius: 12px;
}

body {
    background: var(--bg);
    font-size: 15px;
    line-height: 1.45;
}

.amount,
.fund-hero strong,
.fund-hero dd,
.loan-left-amount strong,
.loan-facts dd,
.member-total,
.member-parts b,
.notice-value,
.txn-month-head b {
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.app-shell {
    padding: 18px 18px 40px;
}

.app-shell h1 {
    font-size: 26px;
    font-weight: 700;
}

.app-shell .eyebrow {
    font-size: 12px;
    font-weight: 600;
}

.app-shell h2 {
    font-size: 16px;
    font-weight: 600;
    text-transform: none;
    margin-bottom: 10px;
}

.app-shell label,
.app-shell .filter-label,
.app-shell .tab,
.app-shell .filter-chip {
    text-transform: none;
}

.app-shell label {
    font-weight: 500;
}

/* ---------- Dải quỹ ---------- */
.fund-hero {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(300px, 400px);
    gap: 18px 48px;
    align-items: center;
    margin-bottom: 16px;
    padding: 22px 26px;
    border-radius: 16px;
    background: #0f6f67;
    color: #fff;
}

.dot {
    display: inline-block;
    width: 9px;
    height: 9px;
    margin-right: 8px;
    border-radius: 50%;
    vertical-align: 1px;
}

.dot-cash { background: #fff; }
.dot-loan { background: #7fd4c8; }

.fund-label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    opacity: .92;
}

.fund-main strong {
    display: block;
    margin: 2px 0 12px;
    font-size: clamp(36px, 6vw, 48px);
    font-weight: 700;
    line-height: 1.05;
    letter-spacing: -.01em;
}

.fund-main strong.negative { color: #ffd2cc; }

.fund-bar {
    height: 8px;
    border-radius: 999px;
    background: #7fd4c8;
    overflow: hidden;
}

.fund-bar span {
    display: block;
    height: 100%;
    border-radius: 999px 0 0 999px;
    background: #fff;
}

.fund-main small {
    display: block;
    margin-top: 8px;
    font-size: 12.5px;
    opacity: .8;
}

.fund-rows {
    display: grid;
    margin: 0;
}

.fund-rows div {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    padding: 7px 0;
}

.fund-rows dt {
    font-size: 14px;
    opacity: .92;
}

.fund-rows dd {
    margin: 0;
    font-size: 17px;
    font-weight: 600;
}

.fund-rows .fund-sub {
    padding-top: 0;
}

.fund-rows .fund-sub dt,
.fund-rows .fund-sub dd {
    padding-left: 17px;
    font-size: 12.5px;
    font-weight: 400;
    opacity: .75;
}

.fund-rows .fund-total {
    margin-top: 4px;
    padding-top: 10px;
    border-top: 1px solid rgba(255, 255, 255, .25);
}

.fund-rows .fund-total dt {
    font-weight: 600;
    opacity: 1;
}

.fund-rows .fund-total dd { font-size: 19px; }

.fund-rows dd { font-variant-numeric: tabular-nums; white-space: nowrap; }

.overdue-strip {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 44px;
    border: 0;
    border-radius: 10px;
    padding: 0 14px;
    background: #fff;
    color: var(--red);
    font: inherit;
    font-size: 14px;
    text-align: left;
    cursor: pointer;
}

.overdue-strip::before {
    content: '';
    flex: 0 0 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--red);
}

.overdue-strip span:first-of-type {
    flex: 1;
}

.strip-link {
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 3px;
}

/* ---------- Tab ---------- */
.app-shell .tabs {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 4px;
    margin-bottom: 16px;
    padding: 4px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fff;
}

.app-shell .tab {
    min-height: 40px;
    border: 0;
    border-radius: 9px;
    background: transparent;
    color: var(--muted);
    font-size: 14px;
    font-weight: 600;
    box-shadow: none;
}

.app-shell .tab.active {
    background: var(--teal);
    color: #fff;
}

/* ---------- Khối chung ---------- */
.app-shell .split > div,
.app-shell .form-grid,
.app-shell .loan-card,
.app-shell .loan-filters,
.txn-month,
.member-row {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
    box-shadow: none;
}

.app-shell .split > div {
    padding: 16px;
}

.app-shell .empty {
    margin: 0;
    padding: 18px 8px;
    font-size: 14px;
}

.amount-income { color: var(--green); }
.amount-expense { color: var(--red); }
.amount { font-weight: 600; }

.text-button {
    min-height: 32px;
    border: 0;
    border-radius: 6px;
    padding: 0 8px;
    background: transparent;
    color: var(--teal-dark);
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

.text-button:hover { background: var(--teal-soft); }
.text-button.danger { color: var(--red); }
.text-button.danger:hover { background: var(--red-soft); }

:focus-visible {
    outline: 2px solid #0f766e;
    outline-offset: 2px;
}

/* ---------- Tổng quan ---------- */
.notice-list {
    display: grid;
    gap: 6px;
}

.notice-row {
    display: grid;
    grid-template-columns: 8px minmax(0, 1fr) auto;
    align-items: center;
    gap: 12px;
    width: 100%;
    border: 0;
    border-radius: 10px;
    padding: 10px 12px;
    background: var(--surface-soft);
    color: var(--ink);
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.notice-row:hover { background: #eef4f0; }

.notice-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--muted);
}

.notice-row.danger .notice-dot { background: var(--red); }
.notice-row.warning .notice-dot { background: var(--amber); }
.notice-row.success .notice-dot { background: var(--green); }
.notice-row.danger { background: var(--red-soft); }

.notice-text strong {
    display: block;
    font-size: 14px;
    font-weight: 600;
}

.notice-text small,
.more-note {
    color: var(--muted);
    font-size: 12.5px;
}

.notice-value { font-weight: 600; }
.more-note { margin: 6px 2px 0; }

.mini-row {
    display: grid;
    grid-template-columns: 46px minmax(0, 1fr) auto;
    gap: 10px;
    align-items: baseline;
    padding: 9px 2px;
    border-bottom: 1px solid var(--line);
    font-size: 14px;
}

.mini-row:last-child { border-bottom: 0; }
.mini-date { color: var(--muted); font-size: 13px; }

/* ---------- Thu chi ---------- */
.list-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    margin: 0 0 12px;
}

.list-toolbar input[type="search"] {
    flex: 1 1 220px;
    min-height: 40px;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 0 12px;
    background: #fff;
}

.txn-list {
    display: grid;
    gap: 12px;
}

.txn-month { overflow: hidden; }

.txn-month-head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 4px 16px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--line);
    background: var(--surface-soft);
    color: var(--muted);
    font-size: 13px;
}

.txn-month-head h3 {
    flex: 1;
    margin: 0;
    color: var(--ink);
    font-size: 15px;
    font-weight: 600;
}

.txn-row {
    display: grid;
    grid-template-columns: 48px minmax(0, 1fr) auto auto;
    gap: 12px;
    align-items: center;
    padding: 11px 16px;
    border-bottom: 1px solid var(--line);
}

.txn-row:last-child { border-bottom: 0; }
.txn-day { color: var(--muted); font-size: 13px; }

.txn-main strong {
    display: block;
    font-size: 14.5px;
    font-weight: 500;
}

.txn-main span {
    display: block;
    color: var(--muted);
    font-size: 12.5px;
}

.txn-row .amount { font-size: 15px; }
.txn-row.is-auto .txn-main strong { color: #33413b; }

body.admin .app-shell .row-actions.admin-only {
    display: flex !important;
    gap: 2px;
}

/* ---------- Vay nợ ---------- */
.app-shell .loan-filters {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    margin-bottom: 10px;
    padding: 12px 14px;
}

.app-shell .loan-filters > div {
    display: grid;
    grid-template-columns: 82px minmax(0, 1fr);
    align-items: center;
    gap: 10px;
}

.app-shell .loan-status-filter { display: grid; }

.app-shell .filter-label {
    margin: 0;
    font-size: 13px;
    font-weight: 500;
}

.app-shell .filter-chips { gap: 6px; }

.app-shell .filter-chip {
    min-height: 32px;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 0 12px;
    background: #fff;
    color: var(--ink);
    font-size: 13px;
    font-weight: 500;
    box-shadow: none;
}

.app-shell .filter-chip.active {
    border-color: var(--teal);
    background: var(--teal);
    color: #fff;
}

.app-shell #clearLoanFilters {
    justify-self: start;
    min-height: 32px;
    font-size: 13px;
}

.app-shell .loan-filter-summary {
    margin: 0 2px 10px;
    font-weight: 400;
    font-size: 14px;
}

.app-shell .loan-list {
    display: grid;
    gap: 12px;
}

.app-shell .loan-card {
    display: grid;
    gap: 10px;
    padding: 16px;
    border-left: 4px solid var(--line);
}

.app-shell .loan-card.overdue { border-left-color: var(--red); }
.app-shell .loan-card.active { border-left-color: var(--teal); }
.app-shell .loan-card.paid { opacity: .78; }

.loan-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
}

.loan-who h3 {
    margin: 0 0 6px;
    font-size: 17px;
    font-weight: 600;
}

.app-shell .badge-row { display: flex; flex-wrap: wrap; gap: 6px; }

.app-shell .badge {
    min-height: 24px;
    padding: 0 9px;
    font-size: 12px;
    font-weight: 600;
}

.loan-left-amount { text-align: right; }

.loan-left-amount strong {
    display: block;
    font-size: 21px;
    font-weight: 700;
}

.loan-card.overdue .loan-left-amount strong { color: var(--red); }

.loan-left-amount span {
    color: var(--muted);
    font-size: 12.5px;
}

.progress {
    height: 6px;
    border-radius: 999px;
    background: #e7ede9;
    overflow: hidden;
}

.progress span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: var(--green);
}

.app-shell .loan-facts {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 22px;
    margin: 0;
}

.app-shell .loan-facts div { display: block; }

.app-shell .loan-facts dt {
    color: var(--muted);
    font-size: 12px;
}

.app-shell .loan-facts dd {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
}

.loan-due {
    margin: 0;
    color: var(--muted);
    font-size: 13px;
}

.loan-due.danger { color: var(--red); font-weight: 600; }
.loan-due.warning { color: var(--amber); font-weight: 600; }

.loan-note,
.loan-hint {
    margin: 0;
    font-size: 13px;
}

.loan-note { color: #3b4943; }

.loan-hint {
    color: var(--muted);
    font-style: italic;
}

.app-shell .payment-history {
    margin: 0;
    padding: 0;
    border: 0;
}

.app-shell .payment-history summary {
    cursor: pointer;
    color: var(--teal-dark);
    font-size: 13px;
    font-weight: 600;
}

.app-shell .payment-history-item {
    padding: 6px 0;
    border-bottom: 1px dashed var(--line);
}

.app-shell .loan-pay-actions { margin-top: 2px; }

.app-shell .settle-button,
.app-shell .partial-button {
    min-height: 40px;
    font-size: 14px;
    font-weight: 600;
}

.app-shell .partial-wrap .payment-form { margin-top: 0; }

body.admin .app-shell .loan-admin.admin-only {
    display: flex !important;
    justify-content: flex-end;
    gap: 4px;
    margin-top: -4px;
}

/* ---------- Thành viên ---------- */
.member-summary {
    margin: 0 2px 12px;
    font-size: 14px;
}

.member-list {
    display: grid;
    gap: 8px;
}

.member-row {
    overflow: hidden;
}

.member-row summary {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto 14px;
    gap: 12px;
    align-items: center;
    padding: 14px 16px;
    cursor: pointer;
    list-style: none;
}

.member-row summary::-webkit-details-marker { display: none; }

.member-row summary::after {
    content: '';
    justify-self: center;
    width: 8px;
    height: 8px;
    border-right: 2px solid var(--muted);
    border-bottom: 2px solid var(--muted);
    transform: translateY(-2px) rotate(45deg);
}

.member-row[open] summary::after { transform: translateY(2px) rotate(225deg); }
.member-row.has-overdue { border-left: 4px solid var(--red); }

.member-head {
    display: grid;
    gap: 2px;
    min-width: 0;
}

.member-name {
    font-size: 16px;
    font-weight: 600;
}

.member-meta {
    color: var(--muted);
    font-size: 13px;
}

.tone-danger { color: var(--red); font-weight: 600; }

.member-total {
    font-size: 18px;
    font-weight: 700;
    text-align: right;
}

.member-row.has-overdue .member-total { color: var(--red); }

.member-loans {
    display: grid;
    gap: 8px;
    padding: 10px 12px 12px;
    border-top: 1px solid var(--line);
    background: var(--surface-soft);
}

.member-loan {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 3px 12px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-left: 3px solid var(--teal);
    border-radius: 8px;
    background: #fff;
}

.member-loan.overdue { border-left-color: var(--red); }

.ml-type {
    font-size: 14px;
    font-weight: 600;
}

.ml-amount {
    font-size: 15px;
    font-weight: 600;
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.ml-dates,
.ml-state,
.ml-extra {
    color: var(--muted);
    font-size: 12.5px;
}

.ml-state {
    text-align: right;
    white-space: nowrap;
}

.ml-state.danger { color: var(--red); font-weight: 600; }
.ml-state.warning { color: var(--amber); font-weight: 600; }

.ml-extra {
    grid-column: 1 / -1;
    padding-top: 4px;
    border-top: 1px dashed var(--line);
    margin-top: 3px;
}

.member-clear {
    margin: 4px 2px 0;
    color: var(--muted);
    font-size: 14px;
}

@media (min-width: 761px) {
    .member-loans {
        grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
        padding: 12px 16px 16px;
    }
}

/* ---------- Máy tính bảng / điện thoại ---------- */
@media (max-width: 760px) {
    .app-shell { padding: 12px 12px 32px; }
    .app-shell h1 { font-size: 21px; }

    .fund-hero {
        grid-template-columns: 1fr;
        gap: 14px;
        padding: 18px 16px;
    }

    .fund-rows div { padding: 6px 0; }
    .fund-rows dd { font-size: 16px; }
    .fund-rows .fund-total dd { font-size: 17px; }

    .app-shell .tab { font-size: 13px; min-height: 38px; padding: 0 2px; }

    .txn-row {
        grid-template-columns: 42px minmax(0, 1fr) auto;
        padding: 10px 12px;
        gap: 10px;
    }

    .txn-row .row-actions { grid-column: 2 / -1; }
    body.admin .app-shell .txn-row .row-actions.admin-only { margin-top: -6px; }
    .txn-month-head { padding: 10px 12px; }

    .app-shell .loan-filters > div { grid-template-columns: 1fr; gap: 6px; }

    .app-shell .loan-filters .filter-chips {
        flex-wrap: nowrap;
        overflow-x: auto;
        margin: 0 -14px;
        padding: 0 14px 2px;
        scrollbar-width: none;
    }

    .app-shell .filter-chip { flex: 0 0 auto; }
    .app-shell .loan-card { padding: 14px; }
    .loan-left-amount strong { font-size: 19px; }

}

@media (prefers-reduced-motion: reduce) {
    * { scroll-behavior: auto !important; transition: none !important; }
}

.app-shell .loan-filters > div { order: 0; }

.app-shell .lunar-end-display,
.app-shell .lunar-row input {
    padding-left: 8px;
    padding-right: 4px;
    font-size: 13px;
}

/* ---------- v60: thanh menu dưới đáy trên điện thoại ---------- */
.app-shell .tab {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
}

.tab-icon {
    width: 18px;
    height: 18px;
    flex: 0 0 auto;
}

.tab-badge {
    min-width: 18px;
    height: 18px;
    border-radius: 999px;
    padding: 0 5px;
    background: var(--red);
    color: #fff;
    font-size: 11px;
    font-style: normal;
    font-weight: 700;
    line-height: 18px;
    text-align: center;
}

.app-shell .tab.active .tab-badge { background: #fff; color: var(--red); }

@media (max-width: 760px) {
    .app-shell {
        padding-bottom: calc(86px + env(safe-area-inset-bottom));
    }

    .app-shell .tabs {
        position: fixed;
        top: auto;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 50;
        margin: 0;
        padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
        gap: 0;
        border: 0;
        border-top: 1px solid var(--line);
        border-radius: 0;
        background: rgba(255, 255, 255, .97);
        box-shadow: 0 -6px 20px rgba(21, 33, 29, .06);
        backdrop-filter: blur(8px);
    }

    .app-shell .tab {
        flex-direction: column;
        gap: 3px;
        min-height: 54px;
        border-radius: 10px;
        padding: 4px 2px;
        color: var(--muted);
        font-size: 11.5px;
        font-weight: 500;
    }

    .app-shell .tab.active {
        background: transparent;
        color: var(--teal);
        font-weight: 600;
    }

    .app-shell .tab.active .tab-icon {
        stroke-width: 2.3;
    }

    .app-shell .tab::before {
        content: '';
        position: absolute;
        top: 0;
        left: 50%;
        width: 0;
        height: 3px;
        border-radius: 0 0 3px 3px;
        background: var(--teal);
        transform: translateX(-50%);
        transition: width .15s ease;
    }

    .app-shell .tab.active::before { width: 28px; }

    .tab-icon {
        width: 23px;
        height: 23px;
    }

    .tab-badge {
        position: absolute;
        top: 3px;
        left: calc(50% + 6px);
        min-width: 17px;
        height: 17px;
        font-size: 10.5px;
        line-height: 17px;
        border: 2px solid #fff;
        box-sizing: content-box;
    }

    .app-shell .tab.active .tab-badge { background: var(--red); color: #fff; }

    .app-shell #overview,
    .app-shell .panel { margin-top: 0; }
    .fund-hero { margin-bottom: 14px; }
}

/* ---------- v61: bộ lọc vay nợ gọn ---------- */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

.app-shell .loan-filters {
    display: grid;
    grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
    gap: 10px;
    align-items: center;
    padding: 10px;
}

.status-tabs {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 3px;
    padding: 3px;
    border-radius: 10px;
    background: #edf2ef;
}

.status-tab {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 36px;
    border: 0;
    border-radius: 8px;
    padding: 0 4px;
    background: transparent;
    color: var(--muted);
    font: inherit;
    font-size: 13.5px;
    font-weight: 500;
    white-space: nowrap;
    cursor: pointer;
}

.status-tab b {
    min-width: 20px;
    border-radius: 999px;
    padding: 1px 6px;
    background: rgba(21, 33, 29, .07);
    color: var(--ink);
    font-size: 11.5px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.status-tab.has-alert b {
    background: var(--red);
    color: #fff;
}

.status-tab.active {
    background: #fff;
    color: var(--ink);
    font-weight: 600;
    box-shadow: 0 1px 3px rgba(21, 33, 29, .12);
}

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

.app-shell .filter-select {
    display: block;
    margin: 0;
}

.app-shell .filter-select select {
    width: 100%;
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 0 30px 0 12px;
    background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5 6 6.5l5-5' fill='none' stroke='%235d6b64' stroke-width='1.8' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 11px center;
    color: var(--ink);
    font: inherit;
    font-size: 14px;
    appearance: none;
    -webkit-appearance: none;
    text-overflow: ellipsis;
}

.app-shell .filter-select select.is-set {
    border-color: var(--teal);
    background-color: var(--teal-soft);
    color: var(--teal-dark);
    font-weight: 600;
}

.app-shell .loan-filter-summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-height: 32px;
    margin: 0 2px 8px;
    color: var(--muted);
}

.app-shell .loan-filter-summary b { color: var(--ink); }
.app-shell #clearLoanFilters { min-height: 30px; }

@media (max-width: 860px) {
    .app-shell .loan-filters {
        grid-template-columns: 1fr;
        gap: 8px;
    }
}

@media (max-width: 380px) {
    .status-tab { font-size: 12.5px; gap: 4px; }
    .status-tab b { padding: 1px 5px; }
}

.app-shell .loan-filters > .status-tabs {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 3px;
}

.app-shell .loan-filters > .filter-selects {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.app-shell #clearLoanFilters { white-space: nowrap; flex: 0 0 auto; }

@media (max-width: 520px) {
    .status-tab {
        flex-direction: column;
        gap: 1px;
        min-height: 50px;
        padding: 4px 2px;
        font-size: 12.5px;
    }

    .status-tab b {
        min-width: 0;
        padding: 0;
        background: transparent;
        font-size: 16px;
        font-weight: 700;
        line-height: 1.2;
    }

    .status-tab.has-alert b {
        background: transparent;
        color: var(--red);
    }

    .app-shell .loan-filter-summary { font-size: 13.5px; }
}

/* ---------- v62: tìm kiếm + kiểu vay, danh sách tự chia nhóm ---------- */
.app-shell .loan-filters {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px 12px;
    align-items: center;
    margin-bottom: 14px;
    padding: 10px;
}

.loan-search input {
    width: 100%;
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 0 12px 0 38px;
    background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%235d6b64' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E") no-repeat 12px center;
    font: inherit;
    font-size: 14.5px;
}

.app-shell .loan-filters > .filter-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 0;
    padding: 0;
    overflow: visible;
}

.app-shell .loan-filters .filter-chip b {
    margin-left: 3px;
    font-weight: 600;
    opacity: .7;
}

.app-shell .loan-filters .filter-chip.active b { opacity: 1; }

.app-shell .loan-filters > .loan-filter-summary {
    grid-column: 1 / -1;
    display: flex;
    margin: 0;
    min-height: 0;
}

.app-shell .loan-filters > .loan-filter-summary.hidden { display: none !important; }

.loan-group {
    margin-bottom: 18px;
}

.group-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    margin: 0 2px 10px;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--line);
}

.group-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 16px;
    font-weight: 700;
}

.group-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--teal);
}

.group-count {
    color: var(--muted);
    font-size: 13px;
    font-weight: 500;
}

.group-sum {
    color: var(--muted);
    font-size: 13.5px;
    white-space: nowrap;
}

.group-sum b {
    color: var(--ink);
    font-size: 15px;
    font-variant-numeric: tabular-nums;
}

.loan-group.overdue .group-head { border-bottom-color: #f2c4c4; }
.loan-group.overdue .group-dot { background: var(--red); }
.loan-group.overdue .group-title,
.loan-group.overdue .group-sum b { color: var(--red); }
.loan-group.paid .group-dot { background: var(--green); }

details.loan-group > summary {
    cursor: pointer;
    list-style: none;
}

details.loan-group > summary::-webkit-details-marker { display: none; }

details.loan-group > summary .group-sum::after {
    content: '';
    display: inline-block;
    width: 7px;
    height: 7px;
    margin: 0 4px 3px 12px;
    border-right: 2px solid var(--muted);
    border-bottom: 2px solid var(--muted);
    transform: rotate(45deg);
}

details.loan-group[open] > summary .group-sum::after { transform: rotate(225deg); margin-bottom: -1px; }

@media (max-width: 760px) {
    .app-shell .loan-filters { grid-template-columns: 1fr; }
    .app-shell .loan-filters > .filter-chips { flex-wrap: nowrap; gap: 5px; }
    .app-shell .loan-filters .filter-chip { flex: 1 1 auto; padding: 0 7px; font-size: 12.5px; white-space: nowrap; }
    .app-shell .loan-filters .filter-chip b { margin-left: 2px; }
    .group-title { font-size: 15px; white-space: nowrap; }
}

.app-shell .loan-filters > label { order: 0; }
.app-shell .loan-filters > .filter-chips { order: 1; }
.app-shell .loan-filters > .loan-filter-summary { order: 2; }

/* ---------- v63: 3 ô lọc Người vay / Kiểu vay / Trạng thái ---------- */
.app-shell .loan-filters {
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 12px;
}

.app-shell .loan-filters > .filter-selects {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
}

.app-shell .filter-select {
    display: grid;
    gap: 4px;
    min-width: 0;
}

.filter-select-label {
    color: var(--muted);
    font-size: 12.5px;
    font-weight: 500;
    padding-left: 2px;
}

.app-shell .filter-select select {
    min-height: 42px;
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
}

.app-shell .loan-filters > .loan-filter-summary {
    align-items: center;
    padding-top: 2px;
    color: var(--muted);
    font-size: 13.5px;
}

@media (max-width: 420px) {
    .app-shell .loan-filters { padding: 10px; }
    .app-shell .loan-filters > .filter-selects { gap: 6px; }
    .app-shell .filter-select select {
        padding: 0 24px 0 9px;
        background-position: right 8px center;
        font-size: 13px;
    }
}

/* ---------- v64: chế độ sửa rõ ràng, chọn Thu/Chi bắt buộc ---------- */
.app-shell .form-grid > .edit-banner {
    grid-column: 1 / -1;
    margin: 0;
    padding: 10px 12px;
    border-radius: 10px;
    background: var(--amber-soft);
    color: #7a4b0c;
    font-size: 14px;
    font-weight: 600;
}

.app-shell .form-grid.is-editing {
    border-color: var(--amber);
    box-shadow: 0 0 0 3px var(--amber-soft);
}

.app-shell .type-toggle {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin: 0;
    padding: 0;
    border: 0;
    min-width: 0;
}

.type-toggle legend {
    margin-bottom: 6px;
    padding: 0;
    color: var(--muted);
    font-size: 13px;
    font-weight: 500;
}

.app-shell .type-option {
    position: relative;
    display: block;
    margin: 0;
    cursor: pointer;
}

.type-option input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.type-option span {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 46px;
    border: 1.5px solid var(--line);
    border-radius: 10px;
    background: #fff;
    color: var(--muted);
    font-size: 15px;
    font-weight: 600;
}

.type-option.income input:checked + span {
    border-color: var(--green);
    background: var(--green-soft);
    color: var(--green);
}

.type-option.expense input:checked + span {
    border-color: var(--red);
    background: var(--red-soft);
    color: var(--red);
}

.type-option input:focus-visible + span {
    outline: 2px solid var(--teal);
    outline-offset: 2px;
}

.app-shell .form-actions {
    display: flex;
    gap: 8px;
    align-items: end;
}

.app-shell .form-actions .primary-button { flex: 1; min-height: 44px; }
.app-shell .form-actions .ghost-button { min-height: 44px; }

@media (min-width: 980px) {
    #transactionForm .form-actions,
    #loanForm .form-actions { grid-column: span 3; }
}

@media (min-width: 980px) {
    .app-shell #transactionForm > .wide { grid-column: span 9; }
}
