:root {
  font-family: "Segoe UI", "Microsoft JhengHei", "PingFang TC", sans-serif;
  font-size: 100%;
  color: #192924;
  background: #f3f6f4;
  --ink: #192924;
  --muted: #52635b;
  --line: #dbe4dd;
  --surface: #fff;
  --green: #175944;
  --green-light: #e6f2eb;
  --rail: #152b23;
  --radius: 1rem;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 16rem; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .54; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid #638f70; outline-offset: 3px; }

.app {
  display: grid;
  grid-template-columns: 14.5rem minmax(0, 1fr);
  min-height: 100vh;
}

.rail {
  align-self: start;
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding: 1.75rem 1rem 1.125rem;
  color: #edf6ef;
  background: var(--rail);
}

.brand {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin: 0 .375rem 2.75rem;
  font-weight: 700;
  font-size: 1.125rem;
  letter-spacing: .06em;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 2.35rem;
  height: 2.35rem;
  border-radius: .7rem;
  background: #bce3c9;
  color: #153527;
  font-family: "Noto Serif TC", "PMingLiU", serif;
  font-size: 1.2rem;
}

.navigation { display: grid; gap: .375rem; }
.nav-item {
  display: flex;
  align-items: center;
  gap: .75rem;
  width: 100%;
  min-height: 2.85rem;
  padding: .55rem .75rem;
  text-align: left;
  border: 1px solid transparent;
  border-radius: .65rem;
  background: transparent;
  color: #d4e5db;
  font-size: .9375rem;
  font-weight: 600;
}
.nav-item:hover { background: #203d31; }
.nav-item[aria-current="page"] { background: #294b3c; border-color: #446454; color: #f2fbf4; }
.nav-icon { flex: 0 0 1.125rem; text-align: center; color: #bce3c9; line-height: 1; font-size: 1.15rem; }
.nav-count { display: block; color: #bed6c8; font-size: .875rem; font-weight: 400; }
.nav-count:empty { display: none; }

.rail-footer { margin-top: auto; padding: 1rem .375rem 0; border-top: 1px solid #395348; }
.folder-status { display: flex; align-items: baseline; gap: .5rem; min-width: 0; font-size: .875rem; }
#folder-indicator { width: .5rem; height: .5rem; flex: 0 0 .5rem; border-radius: 50%; background: #a5b2a9; }
#folder-indicator.is-connected { background: #9dd9ae; }
#folder-name { overflow-wrap: anywhere; }
.rail-action { margin-top: .375rem; padding: .375rem 0; color: #d4e5db; background: transparent; border: 0; font-size: .875rem; }
.rail-action:not(:disabled):hover { text-decoration: underline; text-underline-offset: .2em; }
.rail-account { display: flex; flex-wrap: wrap; align-items: center; gap: 0 .75rem; }

.workspace { min-width: 0; }
.toolbar {
  min-height: 4.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: .75rem clamp(1rem, 3vw, 2.75rem);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.search-tools { display: flex; align-items: center; gap: .625rem; min-width: 0; }
.search-field { position: relative; flex: 1 1 16rem; min-width: 0; }
.search-field input {
  width: 100%;
  min-height: 2.65rem;
  padding: .5rem .75rem .5rem 2.375rem;
  border: 1px solid var(--line);
  border-radius: .6rem;
  background: #f6f8f6;
  color: var(--ink);
}
.search-field input::placeholder { color: var(--muted); }
.search-icon {
  position: absolute;
  top: .82rem;
  left: .85rem;
  width: .8rem;
  height: .8rem;
  border: 1.5px solid #61776a;
  border-radius: 50%;
  pointer-events: none;
}
.search-icon::after {
  content: "";
  position: absolute;
  top: .56rem;
  left: .55rem;
  width: .36rem;
  height: 1.5px;
  transform: rotate(45deg);
  transform-origin: left center;
  background: #61776a;
}

.button {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: .375rem;
  min-height: 2.65rem;
  padding: .45rem .8rem;
  border: 1px solid transparent;
  border-radius: .6rem;
  white-space: nowrap;
  font-size: .9rem;
  font-weight: 650;
}
.button-outline { background: var(--surface); border-color: var(--line); color: var(--ink); }
.button-outline:not(:disabled):hover { background: #eff5f0; border-color: #aac2b2; }
.button-primary { background: var(--green); color: white; padding-inline: 1rem; }
.button-primary:not(:disabled):hover { background: #104b39; }
.button-quiet { background: transparent; color: var(--green); }
.button-quiet:not(:disabled):hover { background: var(--green-light); }
.filter-button[aria-pressed="true"] { background: var(--green-light); color: #154d38; border-color: #a1c7ae; }

.content { max-width: 78rem; margin-inline: auto; padding: 2.75rem clamp(1rem, 3vw, 2.75rem) 3rem; }
.masthead { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; margin-bottom: 1.75rem; }
.view-date { margin: 0 0 .45rem; color: var(--muted); font-size: .9375rem; font-weight: 600; }
.view-date:empty { display: none; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(1.85rem, 3.7vw, 2.75rem); line-height: 1.2; letter-spacing: -.035em; }
h2 { margin-bottom: 0; font-size: 1.0625rem; line-height: 1.4; }
.content-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(14rem, 17.75rem); align-items: start; gap: 1.25rem; }
.content-layout.is-wide { grid-template-columns: minmax(0, 1fr); }
.panel { min-width: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 2px 4px #152b2307; }
.panel-heading { min-height: 3.75rem; display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .75rem 1.25rem; border-bottom: 1px solid var(--line); }
.finance-view { display: grid; gap: 1.25rem; }
.finance-heading { flex-wrap: wrap; }
.balance-caption { margin: .2rem 0 0; color: var(--muted); font-size: .875rem; }
.finance-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: .625rem;
  margin: 0;
  padding: 1rem 1.2rem;
  border-bottom: 1px solid var(--line);
}
.finance-summary div, .day-spending { min-width: 0; padding: .75rem .875rem; border-radius: .7rem; background: #f3f6f4; }
.finance-summary .net-total, .day-spending { background: var(--green-light); }
.finance-summary dt, .day-spending dt { color: var(--muted); font-size: .875rem; }
.finance-summary dd, .day-spending dd {
  margin: .25rem 0 0;
  color: var(--ink);
  font-size: clamp(1.05rem, 2.4vw, 1.5rem);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
.transaction-overview {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  padding: 1rem 1.2rem;
  border-bottom: 1px solid var(--line);
}
.transaction-tools { padding: 0; }
.transaction-tools label { color: var(--muted); font-size: .875rem; white-space: nowrap; }
.transaction-tools input { width: auto; flex: 1 1 auto; }
.day-spending { margin: 0; }
.finance-empty { margin: 0; padding: 1rem 1.2rem; color: var(--muted); }
.count { color: var(--muted); font-size: .875rem; white-space: nowrap; }
.history-tools { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .875rem .875rem .5rem; }
.history-tools input { min-width: 0; width: 100%; min-height: 2.65rem; padding: .375rem .5rem; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: .6rem; }
.history-list { display: grid; gap: .2rem; max-height: 24rem; overflow: auto; padding: .25rem .875rem .875rem; }
.history-button { display: flex; min-height: 2.45rem; align-items: center; padding: .4rem .65rem; text-align: left; border: 1px solid transparent; border-radius: .6rem; background: transparent; color: var(--ink); }
.history-button:hover, .history-button[aria-current="date"] { background: var(--green-light); color: #174e37; }
.history-button[aria-current="date"] { font-weight: 700; }
.history-empty { margin: .35rem 0 0; color: var(--muted); font-size: .875rem; line-height: 1.5; }

.empty {
  display: grid;
  justify-items: center;
  align-content: center;
  min-height: 15rem;
  padding: 1.5rem;
  text-align: center;
}
.empty-mark {
  display: grid;
  place-items: center;
  width: 2.8rem;
  height: 2.8rem;
  margin-bottom: .875rem;
  border-radius: .8rem;
  font-size: 1.4rem;
  line-height: 1;
  background: var(--green-light);
  color: var(--green);
}
.empty p { margin: .4rem 0 .6rem; color: var(--muted); line-height: 1.5; }
.empty p:last-child { margin-bottom: 0; }
.empty .button { margin-top: .35rem; }
.entry { display: grid; grid-template-columns: 1.4rem minmax(0, 1fr) auto; gap: .75rem; align-items: start; padding: 1rem 1.2rem; }
.entry + .entry { border-top: 1px solid var(--line); }
.entry-marker { padding-top: .25rem; display: grid; justify-items: center; }
.entry-marker input { width: 1.1rem; height: 1.1rem; margin: 0; accent-color: var(--green); cursor: pointer; }
.entry-symbol { color: var(--green); line-height: 1.15; font-size: 1.1rem; }
.entry-meta, .entry-actions { display: flex; align-items: center; flex-wrap: wrap; gap: .325rem; }
.entry-meta { margin-bottom: .3rem; }
.entry-type { padding: .1rem .45rem; background: #eaf3ed; color: #235641; border-radius: .4rem; font-size: .875rem; font-weight: 650; }
.entry-context, .entry-detail { color: var(--muted); font-size: .9rem; }
.entry-context { padding: .1rem .3rem; border: 0; background: transparent; text-decoration: underline; text-underline-offset: .15em; }
.entry-title { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.55; }
.entry.is-done .entry-title { text-decoration: line-through; color: var(--muted); }
.entry-detail { margin: .375rem 0 0; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.5; }
.entry-detail strong { margin-right: .4em; font-weight: 650; }
.entry-actions .button { min-height: 2.1rem; padding: .25rem .375rem; }

.notice { margin: 0 0 1rem; padding: .6rem .8rem; color: #215840; background: #e7f1ea; border: 1px solid #c6decf; border-radius: .6rem; font-size: .9rem; overflow-wrap: anywhere; }
.notice-error { color: #842e24; background: #fff1ec; border-color: #efc7bb; }
.no-script { padding: 1rem; }

dialog { width: min(100% - 2rem, 32rem); max-height: min(90vh, 46rem); padding: 0; border: 1px solid var(--line); border-radius: var(--radius); color: var(--ink); box-shadow: 0 16px 52px #142d2633; }
dialog::backdrop { background: #17292085; }
.editor-form { display: grid; gap: .875rem; padding: 1.25rem; }
.editor-header, .editor-actions { display: flex; justify-content: space-between; align-items: center; gap: .625rem; }
.editor-header h2 { font-size: 1.35rem; }
.editor-form label { display: grid; gap: .35rem; font-size: .9375rem; font-weight: 650; }
.editor-form input, .editor-form select, .editor-form textarea { width: 100%; min-height: 2.65rem; padding: .45rem .625rem; border: 1px solid #ccdacf; border-radius: .55rem; background-color: white; color: var(--ink); font-weight: 400; }
.editor-form select { appearance: none; padding-right: 2rem; background-image: linear-gradient(45deg, transparent 48%, #435b4e 48% 59%, transparent 59%), linear-gradient(135deg, transparent 48%, #435b4e 48% 59%, transparent 59%); background-size: .4rem .4rem; background-position: right 1.15rem center, right .8rem center; background-repeat: no-repeat; }
.editor-form textarea { resize: vertical; }
.editor-actions { justify-content: flex-end; }
.editor-form .notice { margin: 0; }
.session-shell { display: grid; place-items: center; min-height: 100vh; padding: 1rem; }
.session-card { width: min(100%, 26rem); padding: clamp(1.25rem, 5vw, 2.25rem); }
.session-card .brand { margin: 0 0 1.5rem; }
.session-card h1 { font-size: clamp(1.55rem, 5vw, 2rem); }
.session-help, .form-help { margin: .5rem 0 0; color: var(--muted); line-height: 1.55; }
.session-card .editor-form { padding: 0; margin-top: 1.25rem; }
.account-editor > form { padding: 0; }
.account-editor .password-editor { padding-top: 1rem; border-top: 1px solid var(--line); }
.visually-hidden { 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: 57rem) {
  .app { grid-template-columns: 12rem minmax(0, 1fr); }
  .content-layout { grid-template-columns: minmax(0, 1fr); }
  .history { grid-row: 1; }
  .history-list { display: flex; flex-wrap: wrap; max-height: 8rem; }
}

@media (max-width: 40rem) {
  .app { display: block; }
  .rail { position: static; min-height: 0; padding: .875rem .75rem .5rem; }
  .brand { margin: 0 .375rem .75rem; }
  .navigation { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .nav-item { justify-content: center; gap: .3rem; padding-inline: .3rem; font-size: .875rem; }
  .nav-icon { display: none; }
  .rail-footer { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .25rem .75rem; border-top: 0; padding-top: .375rem; }
  .rail-action { margin-top: 0; }
  .toolbar { flex-wrap: wrap; gap: .5rem; }
  .search-tools { flex-basis: 100%; }
  .content { padding-top: 1.5rem; }
  .masthead { align-items: center; margin-bottom: 1rem; }
  .content-layout { gap: .75rem; }
  .finance-view { gap: .75rem; }
  .finance-summary { gap: .375rem; padding-inline: .75rem; }
  .finance-summary div { padding-inline: .5rem; }
  .transaction-overview { padding-inline: .875rem; }
  .entry { grid-template-columns: 1.25rem minmax(0, 1fr); padding-inline: .875rem; }
  .entry-actions { grid-column: 2; }
}
