:root {
    color-scheme: light;
    --navy: #0a2a5e;
    --navy-deep: #061a3d;
    --blue: #1468e8;
    --blue-soft: #eaf2ff;
    --cyan: #05a6c7;
    --green: #11875d;
    --green-soft: #e7f7f0;
    --red: #c83d4d;
    --red-soft: #fff0f2;
    --amber: #a85b00;
    --ink: #10213b;
    --muted: #64748b;
    --line: #dce4ef;
    --surface: #ffffff;
    --background: #f4f7fb;
    --shadow: 0 14px 40px rgba(24, 54, 92, 0.08);
    font-family: Inter, "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }

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

body {
    margin: 0;
    min-height: 100vh;
    background: var(--background);
    color: var(--ink);
    font-size: 16px;
    line-height: 1.55;
}

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

.topbar {
    min-height: 68px;
    padding: 12px max(24px, calc((100vw - 1180px) / 2));
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    background: var(--navy-deep);
    color: #fff;
    box-shadow: 0 6px 20px rgba(6, 26, 61, 0.18);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 11px;
    color: #fff;
    text-decoration: none;
    font-weight: 800;
    letter-spacing: .02em;
}

.brand-mark {
    width: 34px;
    height: 34px;
    display: inline-grid;
    place-items: center;
    border-radius: 10px 10px 10px 3px;
    background: linear-gradient(145deg, #2a82ff, #0aa4cc);
    color: #fff;
    font-size: 16px;
    box-shadow: inset 0 1px 0 rgba(255,255,255,.25);
}

.brand-mark-large { width: 48px; height: 48px; font-size: 21px; border-radius: 14px 14px 14px 4px; }

.top-actions { display: flex; align-items: center; gap: 14px; }
.top-actions form { margin: 0; }
.nav-link { text-decoration: none; color: #dbe8ff; font-weight: 700; font-size: 14px; }
.nav-link:hover { color: #fff; }
.user-name { color: #aebfda; font-size: 14px; }

.page-shell { width: min(1180px, calc(100% - 36px)); margin: 0 auto; padding: 36px 0 60px; }
.narrow-page { width: min(920px, calc(100% - 36px)); }

.page-heading {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 24px;
}

.eyebrow {
    margin: 0 0 3px;
    color: var(--blue);
    font-size: 13px;
    font-weight: 800;
    letter-spacing: .12em;
    text-transform: uppercase;
}

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 7px; color: var(--navy-deep); font-size: clamp(28px, 4vw, 42px); line-height: 1.16; letter-spacing: -.035em; }
h2 { margin-bottom: 0; color: var(--navy-deep); font-size: 21px; line-height: 1.3; }

.status-line { display: flex; align-items: center; gap: 12px; margin: 0; color: var(--muted); font-size: 14px; }
.status { display: inline-flex; align-items: center; min-height: 27px; padding: 3px 10px; border-radius: 999px; font-size: 13px; font-weight: 800; }
.status-open { background: var(--green-soft); color: var(--green); }
.status-locked { background: #eef1f5; color: #48576c; }

.month-picker { display: grid; gap: 5px; color: var(--muted); font-size: 13px; font-weight: 700; }
input, select, textarea {
    width: 100%;
    min-height: 46px;
    border: 1px solid #cfd9e7;
    border-radius: 10px;
    padding: 10px 12px;
    background: #fff;
    color: var(--ink);
    outline: none;
    transition: border-color .15s ease, box-shadow .15s ease;
}
textarea { min-height: 92px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(20, 104, 232, .13); }
.month-picker input { min-width: 180px; }

.summary-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.summary-card {
    min-height: 138px;
    padding: 24px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: var(--surface);
    box-shadow: var(--shadow);
    overflow: hidden;
    position: relative;
}
.summary-card::after { content: ""; position: absolute; inset: 0 0 auto; height: 4px; background: var(--blue); }
.summary-spent::after { background: var(--red); }
.summary-remaining { background: linear-gradient(140deg, var(--navy-deep), var(--navy)); border-color: var(--navy); color: #fff; }
.summary-remaining::after { background: #24d7d1; }
.summary-card span { color: var(--muted); font-size: 14px; font-weight: 700; }
.summary-remaining span { color: #b9cae8; }
.summary-card strong { font-size: clamp(27px, 4vw, 39px); line-height: 1; letter-spacing: -.04em; }

.action-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 20px 0 24px; }
.action-row .button-outline { margin-left: auto; }
.read-only-note { color: var(--muted); font-size: 14px; }

.button {
    min-height: 42px;
    padding: 9px 15px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    border: 1px solid transparent;
    border-radius: 10px;
    cursor: pointer;
    text-decoration: none;
    font-weight: 800;
    font-size: 14px;
    transition: transform .12s ease, box-shadow .12s ease, background .12s ease;
}
.button:hover { transform: translateY(-1px); }
.button-primary { background: var(--blue); color: #fff; box-shadow: 0 7px 18px rgba(20,104,232,.2); }
.button-primary:hover { background: #0d5dd6; }
.button-dark { background: var(--navy-deep); color: #fff; }
.button-outline { border-color: #b8c7da; background: #fff; color: var(--navy); }
.button-quiet { border-color: rgba(255,255,255,.18); background: transparent; color: inherit; }
.panel .button-quiet { border-color: var(--line); color: var(--muted); }
.button-full { width: 100%; }

.content-grid { display: grid; grid-template-columns: 1.2fr .8fr; gap: 18px; margin-bottom: 18px; }
.panel { border: 1px solid var(--line); border-radius: 18px; background: var(--surface); box-shadow: var(--shadow); }
.allocation-panel, .equation-panel { padding: 24px; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 22px; }

.allocation-list { display: grid; gap: 17px; }
.allocation-item { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 5px 12px; }
.allocation-label { grid-column: 1 / -1; display: flex; justify-content: space-between; gap: 20px; font-size: 14px; }
.allocation-label strong { color: var(--navy-deep); }
.allocation-item progress { width: 100%; height: 9px; border: 0; border-radius: 20px; overflow: hidden; }
.allocation-item progress::-webkit-progress-bar { background: #edf1f6; border-radius: 20px; }
.allocation-item progress::-webkit-progress-value { background: linear-gradient(90deg, var(--blue), var(--cyan)); border-radius: 20px; }
.allocation-item progress::-moz-progress-bar { background: var(--blue); border-radius: 20px; }
.allocation-item small { color: var(--muted); min-width: 34px; text-align: right; }

.equation-panel { display: flex; flex-direction: column; }
.equation { display: grid; gap: 9px; margin: 19px 0; }
.equation > div { display: flex; justify-content: space-between; gap: 16px; color: var(--muted); font-size: 14px; }
.equation > div strong { color: var(--ink); }
.equation > b { color: #9aa8ba; font-size: 13px; }
.equation-result { margin-top: auto; padding: 17px 18px; display: flex; align-items: center; justify-content: space-between; gap: 18px; border-radius: 13px; background: var(--blue-soft); color: var(--navy); }
.equation-result span { font-size: 14px; font-weight: 700; }
.equation-result strong { font-size: 23px; }

.transactions-panel { overflow: hidden; }
.transactions-panel > .panel-heading { padding: 23px 24px 0; }
.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 14px 15px; border-top: 1px solid #e7ecf3; text-align: left; vertical-align: middle; white-space: nowrap; }
th { color: var(--muted); background: #f9fbfd; font-size: 13px; font-weight: 800; }
td { font-size: 14px; }
.item-cell { min-width: 150px; white-space: normal; font-weight: 700; color: var(--navy-deep); }
.note-cell { min-width: 190px; max-width: 330px; color: var(--muted); white-space: normal; }
.amount-cell { text-align: right; font-variant-numeric: tabular-nums; font-weight: 800; }
.positive { color: var(--green); }
.negative { color: var(--red); }
.badge { display: inline-flex; padding: 4px 9px; border-radius: 999px; background: #eef3f9; color: #526277; font-size: 12px; font-weight: 800; }
.badge-investment { background: var(--green-soft); color: var(--green); }
.text-link { color: var(--blue); font-weight: 800; }
.icon-button { padding: 5px 8px; border: 0; background: transparent; color: var(--red); cursor: pointer; font-size: 13px; font-weight: 800; }

.empty-state { padding: 50px 20px 54px; display: grid; place-items: center; gap: 4px; color: var(--muted); text-align: center; }
.empty-state strong { color: var(--navy); font-size: 18px; }

.modal { width: min(620px, calc(100% - 28px)); padding: 0; border: 0; border-radius: 18px; color: var(--ink); box-shadow: 0 24px 80px rgba(5, 22, 50, .3); }
.modal::backdrop { background: rgba(6, 20, 45, .58); backdrop-filter: blur(3px); }
.modal-card { padding: 24px; }
.modal-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 20px; }
.modal-close { width: 36px; height: 36px; border: 0; border-radius: 50%; background: #eef2f7; color: #526277; cursor: pointer; font-size: 23px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid label, .stack-form label { display: grid; gap: 6px; color: #40516a; font-size: 14px; font-weight: 800; }
.form-wide { grid-column: 1 / -1; }
.form-hint { margin: 10px 0 16px; color: var(--muted); font-size: 13px; }

.login-shell { min-height: 100vh; padding: 30px 18px; display: grid; place-items: center; background: radial-gradient(circle at 20% 15%, #dcecff 0, transparent 30%), linear-gradient(145deg, #f8fbff, #edf3fa); }
.login-card { width: min(430px, 100%); padding: 32px; border: 1px solid #d9e3ef; border-radius: 22px; background: rgba(255,255,255,.96); box-shadow: 0 24px 70px rgba(12, 40, 78, .14); }
.login-heading { display: flex; align-items: center; gap: 14px; margin-bottom: 25px; }
.login-heading h1 { margin: 0; font-size: 28px; }
.login-heading p { margin: 2px 0 0; color: var(--muted); font-size: 14px; }
.stack-form { display: grid; gap: 16px; }
.alert { margin-bottom: 16px; padding: 12px 14px; border-radius: 10px; font-size: 14px; font-weight: 700; }
.alert-error { color: #a02e3c; background: var(--red-soft); }

.toast { width: min(560px, calc(100% - 36px)); margin: 18px auto -8px; padding: 12px 15px; border-radius: 11px; font-size: 14px; font-weight: 800; box-shadow: var(--shadow); }
.toast-success { background: var(--green-soft); color: var(--green); border: 1px solid #bce8d5; }
.toast-error { background: var(--red-soft); color: #a02e3c; border: 1px solid #f1c8ce; }

.report-page { width: min(940px, calc(100% - 40px)); margin: 0 auto; padding: 30px 0 50px; }
.report-toolbar { display: flex; justify-content: space-between; margin-bottom: 24px; }
.report-header { padding-bottom: 22px; display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; border-bottom: 3px solid var(--navy-deep); }
.report-header h1 { margin: 0; font-size: 31px; }
.report-summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin: 22px 0 28px; }
.report-summary > div { padding: 15px; display: grid; gap: 5px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.report-summary span { color: var(--muted); font-size: 13px; }
.report-summary strong { font-size: 19px; }
.report-summary .report-highlight { background: var(--navy-deep); color: #fff; border-color: var(--navy-deep); }
.report-highlight span { color: #bdcce3; }
.report-section { margin-top: 25px; }
.report-section h2 { margin-bottom: 10px; }
.report-section table { border: 1px solid var(--line); background: #fff; }
.report-footer { margin-top: 35px; padding-top: 16px; display: flex; flex-wrap: wrap; justify-content: space-between; gap: 22px; border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (max-width: 800px) {
    .topbar { padding: 11px 16px; }
    .brand > span:last-child, .user-name { display: none; }
    .page-shell { width: min(100% - 24px, 680px); padding-top: 24px; }
    .page-heading { align-items: stretch; flex-direction: column; gap: 15px; }
    .month-picker input { min-width: 0; }
    .summary-grid { grid-template-columns: 1fr; }
    .summary-card { min-height: 112px; padding: 20px; }
    .content-grid { grid-template-columns: 1fr; }
    .action-row .button { flex: 1 1 calc(50% - 10px); }
    .action-row .button-outline { margin-left: 0; }
    .form-grid { grid-template-columns: 1fr; }
    .form-wide { grid-column: auto; }
    .report-summary { grid-template-columns: 1fr 1fr; }
}

@media print {
    @page { size: A4; margin: 14mm; }
    body { background: #fff; color: #111; font-size: 11pt; }
    .no-print { display: none !important; }
    .report-page { width: 100%; padding: 0; }
    .report-header h1 { font-size: 21pt; }
    .report-summary { break-inside: avoid; }
    .report-summary > div { box-shadow: none; }
    .report-section { break-inside: avoid; }
    th, td { padding: 7px 8px; font-size: 9.5pt; }
    a { text-decoration: none; }
}

