:root {
  color-scheme: light;
  /* Shared Library surfaces, with complete offline fallbacks and canonical dark red. */
  --paper: var(--lele-canvas, #ffffff);
  --surface: var(--lele-surface, #ffffff);
  --ink: var(--lele-ink, #1a1a1a);
  --muted: var(--lele-muted, #666666);
  --accent: #B94B45;
  --accent-soft: #faf0ef;
  --line: var(--lele-border, #e0e0e0);
  --card-line: var(--lele-card-border, #eeeeee);
  --input: var(--lele-input, #f8f8f8);
  --alert: #a52d2d;
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--paper);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--paper); --lele-brand-strong: var(--accent); }
button, input, select, textarea { font: inherit; }
button, a, input, select, summary { -webkit-tap-highlight-color: transparent; }
button, input:not([type="checkbox"]), select { min-height: 46px; }
button { padding: .6rem 1rem; color: #fff; background: var(--accent); border: 1px solid var(--accent); border-radius: 20px; cursor: pointer; font-weight: 600; }
button:hover:not(:disabled) { filter: brightness(.94); }
button:disabled, fieldset:disabled button { cursor: not-allowed; opacity: .54; }
input, select, textarea { width: 100%; min-width: 0; padding: .55rem .7rem; border: 1px solid var(--line); border-radius: 14px; background: var(--input); color: var(--ink); }
input:disabled, select:disabled { background: var(--input); color: var(--muted); }
input[type="checkbox"] { width: 22px; height: 22px; flex: 0 0 22px; accent-color: var(--accent); margin: 0; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
a { color: var(--accent); text-underline-offset: 4px; overflow-wrap: anywhere; }
label { display: flex; flex-direction: column; gap: .35rem; font-size: .94rem; font-weight: 500; }
fieldset { min-width: 0; padding: 0; margin: 0; border: 0; }
legend { margin-bottom: .75rem; font-weight: 600; }
h1, h2, p { margin: 0 0 .65rem; }
h1 { font-size: 1.4rem; letter-spacing: .02em; }
h2 { font-size: 1.08rem; }
.small { font-size: .84rem; color: var(--muted); font-weight: 400; }
.quiet { background: var(--surface); color: var(--accent); border-color: var(--line); }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 1rem; max-width: 1060px; margin: auto; padding: 1rem 1.1rem; border-bottom: 1px solid var(--line); }
.topbar > div { display: flex; flex-direction: column; }
.brand { display: inline-flex; align-items: center; min-height: 44px; font-size: 1.25rem; font-weight: 700; text-decoration: none; letter-spacing: .08em; }
main { max-width: 1000px; margin: 0 auto; padding: 1rem 1.1rem 2.5rem; }
.connection { display: flex; align-items: flex-start; justify-content: space-between; gap: .75rem; }
.connection p { margin-bottom: .2rem; }
.connection > button { flex-shrink: 0; }
#connection-message { font-weight: 600; font-size: .94rem; }
#setup-hint { margin: .5rem 0 1rem; }
.tabs { display: grid; grid-template-columns: repeat(2, 1fr); gap: .5rem; margin-top: 1.2rem; }
.tabs button { white-space: nowrap; padding-inline: .3rem; background: var(--surface); border: 1px solid var(--line); border-radius: 20px; color: var(--muted); min-height: 48px; }
.tabs button[aria-selected="true"] { color: #fff; background: var(--accent); border-color: var(--accent); }
.filters { display: flex; flex-wrap: wrap; gap: .7rem; align-items: end; padding: 1rem 0; }
.filters label:first-child { flex: 1 1 145px; max-width: 200px; }
.filters label:nth-child(2) { flex: 0 1 100px; }
.filters .small { flex-basis: 100%; }
.monitor { background: var(--surface); border: 1px solid var(--card-line); border-radius: 14px; padding: 1rem; margin: .25rem 0 1.4rem; }
.operate { background: var(--surface); border: 1px solid var(--card-line); border-radius: 14px; padding: 1rem; }
.monitor h2 { font-size: .9rem; color: var(--muted); font-weight: 500; margin-bottom: .3rem; }
.totals { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: .5rem; margin: .4rem 0 .55rem; }
.totals dt { color: var(--muted); font-size: .82rem; }
.totals dd { margin: .2rem 0 0; font-size: clamp(.85rem,3.4vw,1.3rem); font-weight: 650; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.monitor .small { font-size: .76rem; margin-bottom: .3rem; }
summary { min-height: 44px; padding: .6rem 0; cursor: pointer; color: var(--accent); font-size: .94rem; }
.section-heading { display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: center; justify-content: space-between; margin-bottom: .8rem; }
.section-heading h1, .section-heading h2 { margin: 0; }
.section-heading a { display: inline-flex; align-items: center; min-height: 44px; font-size: .9rem; }
.form-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: .9rem .75rem; }
.form-grid label:nth-child(7), .form-grid label:nth-child(8) { grid-column: 1 / -1; }
.check { display: flex; flex-direction: row; align-items: center; min-height: 48px; gap: .7rem; padding: .6rem 0; font-size: .87rem; }
#entry-fields > button { width: 100%; margin-top: .3rem; }
.help { border-top: 1px solid var(--line); margin-top: 1.5rem; padding-top: .3rem; }
.help p { font-size: .9rem; color: var(--muted); }
.notice { padding: .8rem 1rem; margin: .75rem 0; border-inline-start: 3px solid var(--accent); background: var(--accent-soft); overflow-wrap: anywhere; }
.error { border-color: var(--alert); color: var(--alert); background: var(--surface); }
.search { margin: .8rem 0 1rem; }
.search > div { display: flex; gap: .5rem; margin-top: .4rem; }
.search button { flex-shrink: 0; }
.record-list { margin: 0; padding: 0; list-style: none; border-top: 1px solid var(--line); }
.record-list > li { border-bottom: 1px solid var(--line); }
.record { width: 100%; border: 0; border-radius: 0; padding: 1rem .3rem; text-align: start; display: flex; flex-direction: column; gap: .4rem; font-weight: 400; }
.record-heading { display: flex; gap: .75rem; justify-content: space-between; width: 100%; }
.record-heading > strong:first-child { overflow-wrap: anywhere; min-width: 0; }
.record-heading > strong:last-child { flex-shrink: 0; font-variant-numeric: tabular-nums; }
.record-actions { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.record-actions button { min-width: 44px; min-height: 44px; }
.record-actions .badge { align-self: center; margin-right: auto; }
.badge { align-self: flex-start; font-size: .77rem; padding: .1rem .45rem; border: 1px solid var(--line); border-radius: 4px; color: var(--muted); }
.drop-zone { border: 1px dashed var(--line); background: var(--surface); padding: 1rem; border-radius: 14px; margin-bottom: .8rem; }
.dragging { background: var(--accent-soft); outline: 2px solid var(--accent); }
input[type="file"] { padding: .5rem 0; border: 0; background: transparent; font-size: .85rem; }
input[type="file"]::file-selector-button { min-height: 44px; padding: .5rem .8rem; margin-right: .5rem; border: 1px solid var(--line); color: var(--accent); background: var(--surface); border-radius: 20px; font: inherit; }
#receipt-fields > button { margin: .8rem 0; }
#upload-state { font-size: .9rem; margin-block: .5rem; }
progress { width: 100%; height: 10px; accent-color: var(--accent); }
.receipt-item { padding: 1rem 0; overflow-wrap: anywhere; }
.receipt-item h2 { font-size: 1rem; }
.receipt-item button, #receipt-results > div button { margin: .3rem .5rem .3rem 0; }
.receipt-preview { display: block; max-width: 100%; max-height: 65vh; object-fit: contain; margin-top: .8rem; border: 1px solid var(--line); }
.file-link { display: inline-flex; align-items: center; min-height: 44px; padding: .4rem .5rem; }
.bars { list-style: none; padding: 0; margin: .3rem 0 .8rem; }
.bars li { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1.5fr); gap: .2rem .7rem; margin-bottom: .7rem; font-size: .86rem; }
.bar { grid-column: 1 / -1; background: var(--line); height: 7px; border-radius: 3px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); }
.category-toggle { grid-column: 1 / -1; display: grid; grid-template-columns: minmax(0,1fr) auto; gap: .5rem .7rem; width: 100%; min-width: 0; text-align: start; border-radius: 10px; }
.category-toggle > span:first-child { overflow-wrap: anywhere; }
.category-toggle > strong { text-align: end; font-variant-numeric: tabular-nums; }
.category-toggle[aria-expanded="true"] { background: var(--accent-soft); border-color: var(--accent); }
.category-details { grid-column: 1 / -1; min-width: 0; padding: .5rem .3rem; }
.bars .record-list > li { display: block; margin: 0; }
.category-details .record-heading { flex-wrap: wrap; }
.category-details .record-heading > strong:last-child { margin-left: auto; }
.category-details .record { font-size: .9rem; }
.category-details .small { overflow-wrap: anywhere; }
dialog { width: min(700px,calc(100vw - 1.4rem)); max-height: 90dvh; border: 1px solid var(--line); border-radius: 16px; padding: 1.2rem; background: var(--surface); color: var(--ink); }
dialog::backdrop { background: rgb(26 26 26 / .45); }
dialog details { border-top: 1px solid var(--line); margin: 1rem 0; }
dialog form > fieldset > label { margin-block: .8rem; }
#void-form { border-top: 1px solid var(--line); padding-top: .8rem; }
.danger { color: var(--alert); border-color: var(--alert); }
pre { white-space: pre-wrap; overflow-wrap: anywhere; font-size: .8rem; line-height: 1.6; }
footer { max-width: 1000px; margin: auto; border-top: 1px solid var(--line); padding: 1rem 1.1rem 2rem; font-size: .75rem; color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
.skip { position: absolute; left: 1rem; top: -100px; padding: .6rem 1rem; background: var(--surface); z-index: 5; }
.skip:focus { top: 0; }
@media (min-width: 700px) {
  .tabs { grid-template-columns: repeat(4,minmax(0,1fr)); }
  main { padding: 1.5rem 2rem 3rem; }
  .topbar { padding-inline: 2rem; }
  .topbar > div { flex-direction: row; align-items: baseline; gap: 1rem; }
  .filters .small { flex-basis: auto; margin-left: auto; padding-bottom: .6rem; }
  .form-grid { grid-template-columns: repeat(4,minmax(0,1fr)); gap: 1rem; }
  .form-grid label:nth-child(n+5) { grid-column: span 2; }
  .operate { max-width: 800px; margin-inline: auto; }
  #entry-fields > button { width: auto; min-width: 200px; }
  .totals { gap: 2rem; }
  .totals dd { font-size: 1.35rem; }
}
.chart-selector { max-width: 350px; margin-bottom: .8rem; }
#monthly-focus .totals { grid-template-columns: repeat(2,minmax(0,1fr)); gap: 1rem; }
#bank-accounts .totals { grid-template-columns: repeat(auto-fit,minmax(170px,1fr)); gap: 1rem; }
#bank-accounts .totals > div, #monthly-focus .totals > div { border: 1px solid var(--line); padding: .9rem; border-radius: .5rem; min-width: 0; }
.bars li > span, .bars li > strong { overflow-wrap: anywhere; }
.bars li > strong { text-align: end; }
@media (max-width: 360px) { .form-grid > label:first-child { grid-column: 1 / -1; } }
.login-page { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 1.5rem 1rem; }
.login-page .login-card { width: 100%; max-width: 420px; margin: 0; padding: clamp(1.5rem, 5vw, 2rem); border: 1px solid var(--card-line); border-radius: 14px; background: var(--surface); box-shadow: 0 8px 30px rgb(26 26 26 / .04); }
.login-card h1 { margin-bottom: 1.5rem; color: var(--accent); }
.login-card form { display: grid; gap: 1.25rem; }
.login-card button { width: 100%; }
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }
