:root {
    --ink: #20211f;
    --muted: #686f75;
    --line: #d8ddd6;
    --paper: #fbfaf5;
    --panel: #ffffff;
    --green: #246b4a;
    --green-soft: #e6f1ea;
    --blue: #22577a;
    --amber: #a35d12;
    --amber-soft: #fbecd7;
    --red: #aa3131;
    --shadow: 0 18px 45px rgba(43, 51, 43, 0.12);
    --radius: 8px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    color: var(--ink);
    background:
        linear-gradient(90deg, rgba(34, 87, 122, 0.06) 1px, transparent 1px),
        linear-gradient(0deg, rgba(36, 107, 74, 0.05) 1px, transparent 1px),
        var(--paper);
    background-size: 28px 28px;
    font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", sans-serif;
}

[hidden] {
    display: none !important;
}

a {
    color: var(--blue);
    text-decoration: none;
}

.login-screen {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 20px;
}

.login-panel {
    width: min(420px, 100%);
    display: grid;
    gap: 14px;
    padding: 26px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.install-panel {
    width: min(560px, 100%);
}

.login-panel h1 {
    margin: 0 0 8px;
    font-size: 34px;
    line-height: 1.15;
    letter-spacing: 0;
}

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

.install-form label:nth-of-type(3),
.install-form button {
    grid-column: 1 / -1;
}

.button-link {
    min-height: 42px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 16px;
    border-radius: 7px;
    font-weight: 800;
}

.primary-link {
    color: #fff;
    background: var(--green);
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 18px clamp(16px, 4vw, 44px);
    background: rgba(251, 250, 245, 0.94);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(14px);
}

.top-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.userbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

.userbar span {
    padding-left: 10px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
    white-space: nowrap;
}

.userbar button {
    min-height: 34px;
    padding: 0 12px;
}

.topbar h1,
.section-head h2 {
    margin: 0;
    font-size: 32px;
    line-height: 1.15;
    letter-spacing: 0;
}

.section-head h2 {
    font-size: 26px;
}

.eyebrow {
    margin: 0 0 4px;
    color: var(--green);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
}

.tabs {
    display: flex;
    gap: 8px;
    padding: 4px;
    background: #eef0e9;
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

.tabs a {
    min-height: 38px;
    display: inline-flex;
    align-items: center;
    padding: 0 16px;
    color: var(--muted);
    border-radius: 6px;
    font-weight: 700;
}

.tabs a.active {
    color: #fff;
    background: var(--ink);
}

.shell {
    width: min(1180px, calc(100% - 32px));
    margin: 26px auto 56px;
}

.notice {
    margin-bottom: 16px;
    padding: 12px 14px;
    color: #113f2c;
    background: var(--green-soft);
    border: 1px solid #bdd6c7;
    border-radius: var(--radius);
}

.notice.danger {
    color: #721e1e;
    background: #fbe3e0;
    border-color: #efc2bd;
}

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

.metric {
    min-height: 126px;
    padding: 18px;
    color: #fff;
    background: var(--ink);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.metric span,
.metric small {
    display: block;
    color: rgba(255, 255, 255, 0.76);
}

.metric strong {
    display: block;
    margin: 8px 0 4px;
    font-size: 36px;
    line-height: 1;
}

.metric.approved {
    background: var(--amber);
}

.metric.paid {
    background: var(--green);
}

.panel,
.table-panel {
    margin-bottom: 18px;
    padding: clamp(16px, 3vw, 26px);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.panel.compact {
    box-shadow: none;
}

.section-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

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

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

.inline-form,
.month-form,
.filters {
    display: flex;
    align-items: flex-end;
    gap: 12px;
}

.inline-form label {
    flex: 1;
}

label span {
    display: block;
    margin-bottom: 7px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

input,
select,
textarea,
button {
    width: 100%;
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: 7px;
    font: inherit;
}

input,
select,
textarea {
    padding: 10px 11px;
    color: var(--ink);
    background: #fff;
}

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

input[readonly] {
    color: var(--muted);
    background: #f7f7f1;
}

button {
    width: auto;
    padding: 0 16px;
    color: #fff;
    background: var(--ink);
    border-color: var(--ink);
    cursor: pointer;
    font-weight: 800;
}

button:hover {
    transform: translateY(-1px);
}

.primary {
    grid-column: 1 / -1;
    justify-self: start;
    background: var(--green);
    border-color: var(--green);
}

.ghost {
    color: var(--ink);
    background: #fff;
}

.danger-button {
    color: #fff;
    background: var(--red);
    border-color: var(--red);
}

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

.toolbar {
    display: flex;
    justify-content: flex-end;
    margin: 18px 0 10px;
}

.filters select {
    width: auto;
    min-width: 150px;
}

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

.expense-row,
.row,
.empty {
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

.expense-row {
    display: grid;
    grid-template-columns: 1fr 280px;
    gap: 18px;
    padding: 18px;
}

.expense-title {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

.expense-title h3 {
    margin: 0;
    font-size: 20px;
    line-height: 1.25;
}

.badge {
    flex: 0 0 auto;
    display: inline-flex;
    min-height: 28px;
    align-items: center;
    padding: 0 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 800;
}

.is-pending {
    color: #724009;
    background: var(--amber-soft);
}

.is-approved {
    color: #174665;
    background: #dcecf5;
}

.is-paid {
    color: #145235;
    background: var(--green-soft);
}

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

dt {
    color: var(--muted);
    font-size: 12px;
}

dd {
    margin: 3px 0 0;
    font-weight: 800;
    overflow-wrap: anywhere;
}

.expense-main p {
    margin: 0 0 12px;
    color: #343936;
    line-height: 1.7;
}

.file-links,
.payment-proof {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.file-links a,
.payment-proof a {
    display: inline-flex;
    align-items: center;
    min-height: 30px;
    padding: 0 10px;
    color: var(--blue);
    background: #eff5f7;
    border: 1px solid #cfe0e7;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 700;
}

.payment-proof span,
.project-row small,
.stat-tile small,
.muted-text {
    color: var(--muted);
    font-size: 13px;
}

.actions {
    display: grid;
    gap: 10px;
    align-content: start;
}

.actions form {
    display: grid;
    gap: 8px;
}

.hint-box {
    padding: 12px;
    color: var(--muted);
    background: #f7f7f1;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    font-size: 13px;
    line-height: 1.5;
}

.project-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px;
}

.project-row strong,
.project-row small {
    display: block;
}

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

.account-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px;
    background: #f7f7f1;
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

.account-row strong,
.account-row small {
    display: block;
}

.account-row small {
    margin-top: 4px;
    color: var(--muted);
    font-size: 13px;
}

.chips,
.check-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.chips span {
    display: inline-flex;
    min-height: 28px;
    align-items: center;
    padding: 0 10px;
    color: var(--blue);
    background: #eff5f7;
    border: 1px solid #cfe0e7;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 800;
}

.permission-box {
    grid-column: 1 / -1;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin: 0;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

.permission-box legend {
    padding: 0 6px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
}

.permission-box label,
.check-grid label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 38px;
    padding: 0 12px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 7px;
    font-weight: 800;
}

.permission-box input,
.check-grid input {
    width: 16px;
    min-height: 16px;
}

.approval-form {
    display: grid;
    gap: 14px;
}

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

.empty.soft {
    margin: 0;
    background: #f7f7f1;
}

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

.stat-tile {
    min-height: 126px;
    padding: 16px;
    background: #f7f7f1;
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

.stat-tile span,
.stat-tile small {
    display: block;
}

.stat-tile strong {
    display: block;
    margin: 8px 0;
    font-size: 28px;
}

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

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

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

th {
    color: var(--muted);
    font-size: 13px;
}

@media (max-width: 820px) {
    .topbar {
        align-items: flex-start;
        flex-direction: column;
    }

    .top-actions,
    .userbar {
        width: 100%;
    }

    .top-actions {
        align-items: stretch;
        flex-direction: column;
    }

    .userbar {
        justify-content: space-between;
    }

    .topbar h1 {
        font-size: 26px;
    }

    .section-head h2 {
        font-size: 22px;
    }

    .tabs,
    .tabs a {
        width: 100%;
    }

    .tabs a {
        justify-content: center;
    }

    .shell {
        width: min(100% - 20px, 680px);
        margin-top: 16px;
    }

    .summary,
    .expense-form,
    .account-form,
    .install-form,
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .section-head,
    .inline-form,
    .month-form,
    .filters,
    .account-row,
    .project-row {
        align-items: stretch;
        flex-direction: column;
    }

    .toolbar {
        justify-content: stretch;
    }

    .filters select {
        width: 100%;
    }

    .expense-row {
        grid-template-columns: 1fr;
        padding: 14px;
    }

    .expense-title {
        align-items: flex-start;
        flex-direction: column;
    }

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

    button {
        width: 100%;
    }

    .install-form label:nth-of-type(3),
    .install-form button {
        grid-column: auto;
    }
}

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

    table {
        min-width: 0;
    }

    thead {
        display: none;
    }

    tbody tr {
        display: block;
        padding: 8px 0;
        border-bottom: 1px solid var(--line);
    }

    td {
        display: flex;
        justify-content: space-between;
        gap: 12px;
        padding: 8px 0;
        border-bottom: 0;
        white-space: normal;
    }

    td::before {
        content: attr(data-label);
        flex: 0 0 auto;
        color: var(--muted);
        font-weight: 800;
    }

    td[colspan] {
        display: block;
        text-align: center;
    }

    td[colspan]::before {
        content: "";
    }
}
