* { box-sizing: border-box; }
:root {
  font-family: 'Sofia Sans', 'Noto Sans TC', 'Microsoft JhengHei', system-ui, sans-serif;
  color: #141413; background: #f3f0ee; color-scheme: light;
  font-synthesis: none; --ink: #141413; --muted: #655b54; --accent: #141413; --focus: #cf4500;
  --line: #e5ddd7; --white: #fcfbfa; --green: #216147; --red: #973e32; --tint: #f5efea;
}
body { margin: 0; min-width: 310px; }
button, input, select, textarea { font: inherit; color: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
button:disabled { opacity: .5; cursor: wait; }
a { color: var(--accent); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }
h1,h2,h3,p { margin: 0; }
h1 { font-size: clamp(1.75rem,4vw,2.4rem); line-height: 1.25; font-weight: 700; }
h2 { font-size: 1.12rem; }
h3 { font-size: 1rem; }
.muted, .subline, .hint { color: var(--muted); }
.hint, .subline { font-size: .875rem; }
.startup { padding: 3rem; }
.brand { display: flex; align-items: center; gap: .7rem; font-weight: 700; font-size: 1.08rem; white-space: nowrap; }
.brand-mark { display: grid; place-items: center; width: 2.35rem; height: 2.35rem; border-radius: 50%; color: #fcfbfa; background: var(--ink); line-height: 1; }
.app-shell { min-height: 100dvh; }
.app-header { position: sticky; z-index: 3; top: 0; padding: 1rem 1.25rem 0; background: #f3f0ee; }
.topbar { max-width: 77rem; margin: 0 auto; padding: .4rem .65rem .4rem .8rem; display: flex; align-items: center; gap: 1.15rem; justify-content: space-between; border: 1px solid var(--line); border-radius: 999px; background: #fff; box-shadow: 0 4px 20px #3324100b; }
.nav { display: flex; gap: .18rem; overflow-x: auto; padding: .15rem; scrollbar-width: none; }
.nav button { flex: 0 0 auto; background: none; border: 0; border-radius: 999px; padding: .55rem .82rem; min-height: 2.55rem; color: var(--muted); font-weight: 660; white-space: nowrap; }
.nav button:hover { background: var(--tint); }
.nav button[aria-current=page] { background: var(--ink); color: #fff; }
.workspace { width: min(100%, 79.5rem); margin: 0 auto; padding: 2.3rem 1.25rem 3.5rem; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 1.55rem; }
.page-head p { margin-top: .4rem; }
.button { display: inline-flex; gap: .45rem; justify-content: center; align-items: center; border: 1px solid #bdb1a7; border-radius: 999px; padding: .57rem .95rem; min-height: 2.55rem; background: #fff; color: var(--ink); text-decoration: none; white-space: nowrap; font-weight: 650; font-size: .91rem; }
.button:hover { background: var(--tint); }
.button.primary { background: var(--accent); color: white; border-color: var(--accent); }
.button.primary:hover { background: #382b22; }
.button.danger { color: var(--red); }
.button.small { font-size: .85rem; padding: .32rem .6rem; min-height: 2rem; }
.button.icon { min-width: 2.15rem; padding: .3rem; }
.card { background: var(--white); border: 1px solid var(--line); border-radius: 1.75rem; min-width: 0; }
.summary { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: .9rem; margin-bottom: 1.25rem; }
.metric { padding: 1.15rem 1.3rem; min-width: 0; }
.metric:first-child { background: #eee4dc; border-color: #e5d8ce; }
.metric-label { color: var(--muted); font-size: .89rem; font-weight: 600; }
.metric-value { display: block; margin-top: .3rem; font-size: clamp(1.18rem,2.6vw,1.8rem); font-weight: 740; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.income { color: var(--green); }
.expense { color: var(--red); }
.transfer { color: #615749; }
.toolbar { padding: .9rem 1.15rem; border-bottom: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: .6rem; align-items: end; }
.toolbar:last-child { border-bottom: 0; }
.toolbar h2 { margin-right: auto; align-self: center; }
.toolbar label { min-width: 7.3rem; }
.toolbar .search { flex: 1 1 12rem; }
.toolbar .search input { width: 100%; }
.tabbar { display: flex; gap: .25rem; flex-wrap: wrap; padding: .75rem 1.15rem; border-bottom: 1px solid var(--line); }
.tabbar button { background: transparent; border: 0; border-radius: 999px; padding: .5rem .8rem; color: var(--muted); font-weight: 630; font-size: .91rem; }
.tabbar button[aria-pressed=true] { color: #fff; background: var(--ink); }
.panel-header { padding: 1rem 1.2rem; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: .65rem; justify-content: space-between; }
.transaction-filters, .transaction-tabs { margin-bottom: .85rem; }
.transaction-tabs .tabbar { border: 0; }
.desktop-export, .transaction-column:not(.transaction-selected) { display: none; }
.day-label { padding: .55rem 1.2rem; background: var(--tint); color: var(--muted); font-weight: 650; font-size: .86rem; border-bottom: 1px solid var(--line); }
.entry { display: grid; grid-template-columns: minmax(0,1fr) auto; align-items: center; gap: .65rem; padding: .55rem 1.2rem; border-bottom: 1px solid var(--line); min-height: 4.1rem; }
.fee-label { text-align: right; }
.entry:last-child { border-bottom: 0; }
.entry:hover { background: #faf6f1; }
.entry-main { border: 0; background: none; padding: .15rem 0; text-align: left; display: grid; grid-template-columns: minmax(5.75rem, max-content) minmax(0, 1fr); align-items: start; gap: .65rem; min-width: 0; }
.entry-title { display: block; font-weight: 680; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-text { min-width: 0; }
.entry-text .subline { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-text .entry-note { white-space: normal; overflow-wrap: anywhere; }
.entry-text .entry-accounts { display: flex; flex-wrap: wrap; align-items: center; gap: .2rem .4rem; margin-top: .2rem; white-space: normal; overflow-wrap: anywhere; }
.account-badge { padding: .12rem .42rem; border-radius: .45rem; background: #ece8e4; color: #514740; font-size: .82rem; font-weight: 650; min-width: 0; }
.account-badge--cash { background: #e0f1e6; color: #205438; }
.account-badge--deposit { background: #e1edf9; color: #234d78; }
.account-badge--credit { background: #f9e3df; color: #813e32; }
.account-badge--bill { background: #f8ead0; color: #735012; }
.account-badge--stock { background: #eee5fa; color: #593b7c; }
.account-badge--family { background: #f7e2ee; color: #82395c; }
.account-badge--support { background: #ddf1ef; color: #245950; }
.amount { white-space: nowrap; font-weight: 710; font-variant-numeric: tabular-nums; }
.check { background: #fff; min-width: 2.25rem; min-height: 2.25rem; border-radius: 50%; border: 1px solid #d9d0c5; color: #65554a; font-size: .9rem; }
.check[aria-pressed=true] { color: #12614e; background: #eaf7ef; border-color: #a5cdb8; }
.pagination { padding: 1rem 1.2rem; display: flex; align-items: center; justify-content: space-between; gap: .5rem; border-top: 1px solid var(--line); }
.empty { padding: 2.05rem 1.2rem; text-align: center; color: var(--muted); }
.empty h3 { color: var(--ink); margin-bottom: .4rem; }
.empty .button { margin-top: .8rem; }
.report-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 1rem; margin: 1rem 0; }
.report-grid .full { grid-column: 1/-1; }
.period-card { margin-bottom: .85rem; }
.overview-grid { display: grid; grid-template-columns: minmax(0,1.65fr) minmax(17rem,1fr); gap: 1rem; align-items: start; }
.panel-footer { padding: 1rem 1.2rem; }
.account-previous-and-deposits { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: .85rem; align-items: start; }
.stat-lines p { display: flex; justify-content: space-between; gap: .6rem; }
.account-card-grid { display: grid; grid-template-columns: repeat(auto-fit,minmax(min(100%,14rem),1fr)); gap: .7rem; padding: .95rem; }
.account-card { display: grid; align-content: start; justify-items: start; gap: .42rem; padding: .95rem 1rem; border: 1px solid var(--line); border-radius: 1.1rem; background: #fff; min-width: 0; }
.account-card h3 { overflow-wrap: anywhere; }
.account-card .amount { font-size: 1.2rem; }
.report-body { padding: .8rem 1.2rem 1.15rem; display: grid; gap: .6rem; }
.bar-label { display: flex; align-items: baseline; justify-content: space-between; gap: .65rem; }
progress { display: block; width: 100%; height: .54rem; appearance: none; border: 0; background: #eee5dd; border-radius: .45rem; overflow: hidden; }
progress::-webkit-progress-bar { background: #eee5dd; }
progress::-webkit-progress-value { background: #b84a20; border-radius: .45rem; }
progress::-moz-progress-bar { background: #b84a20; }
.setting-row, .balance-row { display: flex; padding: .7rem 1.15rem; gap: .8rem; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.setting-row:last-child, .balance-row:last-child { border-bottom: 0; }
.balance-row .muted { display: block; }
.stack { display: grid; gap: .85rem; }
.wrap { display: flex; flex-wrap: wrap; align-items: center; gap: .55rem; }
.setting-body { padding: 1.05rem 1.2rem; display: grid; gap: .75rem; }
label { display: grid; gap: .3rem; font-size: .875rem; font-weight: 630; }
input,select,textarea { width: 100%; min-width: 0; min-height: 2.65rem; border: 1px solid #cfc3b9; border-radius: .85rem; padding: .55rem .72rem; background: #fff; font-size: 1rem; }
input::placeholder { color: #776b61; }
input[type=checkbox] { width: 1.2rem; height: 1.2rem; min-height: 0; accent-color: var(--accent); }
input[type=file] { min-height: 0; padding: .45rem; }
select { appearance: none; padding-right: 1.65rem; background-image: linear-gradient(45deg,transparent 50%,#655b54 50%),linear-gradient(135deg,#655b54 50%,transparent 50%); background-position: calc(100% - 13px) 52%,calc(100% - 8px) 52%; background-size: 5px 5px; background-repeat: no-repeat; }
textarea { resize: vertical; }
.check-label { display: flex; align-items: center; gap: .45rem; }
.notice { background: #fff4d9; padding: .8rem; border: 1px solid #efd9a2; border-radius: .65rem; color: #604605; }
.form-error { color: var(--red); font-size: .91rem; font-weight: 650; }
.login-shell { display: grid; min-height: 100dvh; place-items: center; padding: 1rem; }
.login-card { width: min(100%,26rem); padding: 1.8rem; display: grid; gap: 1.4rem; }
.login-card .brand { margin-bottom: .3rem; }
.login-card h1 { font-size: 1.85rem; }
dialog { margin: auto; width: min(calc(100% - 1.5rem),46rem); max-height: calc(100dvh - 1.5rem); padding: 0; border: 1px solid var(--line); border-radius: 1.75rem; color: var(--ink); box-shadow: 0 16px 65px #2c180d30; }
dialog::backdrop { background: #271a1375; }
.modal-title { display: flex; align-items: center; justify-content: space-between; background: #fff; padding: .9rem 1.2rem; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 1; }
.modal-body { display: grid; gap: .85rem; padding: 1.05rem 1.2rem; }
.form-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); align-items: end; gap: .7rem; }
.form-grid .full { grid-column: 1/-1; }
.merchant-fields { gap: .45rem; }
.merchant-actions { display: flex; align-items: end; gap: .5rem; }
.merchant-actions label { flex: 1; min-width: 0; }
.merchant-actions button { min-height: 2.55rem; }
.modal-foot { display: flex; justify-content: space-between; align-items: center; gap: .6rem; padding: .8rem 1.2rem; border-top: 1px solid var(--line); position: sticky; bottom: 0; background: #fff; }
.section-head { display: flex; gap: .5rem; align-items: center; justify-content: space-between; }
.detail-card { padding: .8rem; display: grid; gap: .65rem; background: #f9f5f1; border-radius: 1rem; }
.entry-panel { max-width: 57rem; }
.entry-form-toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .25rem .85rem; padding: .6rem 1.2rem; border-bottom: 1px solid var(--line); }
.entry-form-toolbar .tabbar { padding: 0; border: 0; }
.entry-repeat-options { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: .45rem .9rem; margin-left: auto; }
.entry-repeat-options label:has(input:disabled) { color: var(--muted); }
.inline-entry details { padding: .45rem .7rem; border: 1px solid var(--line); border-radius: .75rem; }
#transaction-form summary { cursor: pointer; font-weight: 660; }
#transaction-form details[open] summary { margin-bottom: .5rem; }
.inline-entry .modal-foot { border-radius: 0 0 1.75rem 1.75rem; bottom: 0; z-index: 1; }
.photo { display: block; max-height: 15rem; width: auto; max-width: 100%; border-radius: .55rem; }
#toast { position: fixed; z-index: 4; right: 1rem; bottom: 1rem; border-radius: .8rem; padding: .75rem 1rem; color: white; background: var(--ink); box-shadow: 0 4px 20px #1114; max-width: calc(100% - 2rem); }
.migration-report { max-height: 21rem; overflow: auto; border: 1px solid var(--line); border-radius: .65rem; }
.migration-report p { padding: .65rem .8rem; }

@media (min-width: 1000px) {
  .workspace:has(.transaction-columns) { width: min(100%, 105rem); }
  .desktop-export { display: inline-flex; }
  .mobile-export, .transaction-tabs, .transaction-columns .transaction-all { display: none; }
  .transaction-columns { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: .85rem; align-items: start; }
  .transaction-column:not(.transaction-all) { display: block; }
  .transaction-column .panel-header { padding: .8rem 1rem; }
  .transaction-column .entry, .transaction-column .day-label, .transaction-column .pagination { padding-left: .85rem; padding-right: .85rem; }
  .transaction-column .entry { column-gap: .45rem; row-gap: .25rem; }
}

@media (max-width: 700px) {
  .entry-form-toolbar { padding-inline: .7rem; }
  .app-header { padding: .55rem .65rem 0; }
  .topbar { display: grid; gap: .35rem; padding: .45rem .45rem .35rem; border-radius: 1.35rem; min-width: 0; }
  .topbar .brand { padding-left: .35rem; gap: .45rem; }
  .topbar .brand-mark { width: 1.65rem; height: 1.65rem; font-size: .88rem; }
  .nav { gap: .12rem; }
  .nav button { padding: .42rem .7rem; min-height: 2.15rem; font-size: .87rem; }
  .workspace { padding: 1.15rem .65rem calc(2rem + env(safe-area-inset-bottom)); }
  .page-head { margin-bottom: .95rem; }
  .page-head p { font-size: .87rem; }
  .summary { gap: .45rem; margin-bottom: .85rem; }
  .metric { padding: .7rem .55rem; }
  .metric-label { font-size: .79rem; }
  .metric-value { font-size: .98rem; }
  .entry, .day-label, .toolbar, .tabbar, .panel-header { padding-left: .7rem; padding-right: .7rem; }
  .entry { gap: .38rem; }
  .entry-main { grid-template-columns: minmax(4.6rem, max-content) minmax(0, 1fr); gap: .45rem; }
  .entry .amount { font-size: .88rem; }
  .report-grid,.overview-grid,.account-previous-and-deposits { grid-template-columns: minmax(0,1fr); }
  .fee-label { font-size: .78rem; }
  .inline-entry .modal-foot { padding-bottom: max(.8rem,env(safe-area-inset-bottom)); }
  #toast { bottom: calc(3.6rem + env(safe-area-inset-bottom)); }
}
@media (max-width: 370px) {
  .metric-value { font-size: .85rem; }
  .modal-body,.modal-title,.modal-foot { padding-left: .7rem; padding-right: .7rem; }
}
