:root {
  color-scheme: light;
  --paper: #f0f7f0;
  --white: #fff;
  --ink: #18332a;
  --muted: #526b5e;
  --line: #dce9df;
  --accent-soft: #d8eddd;
  --accent: #245a43;
  --accent-strong: #194632;
  --accent-outline: #4d8468;
  --accent-muted: #acd5b8;
  --tint: #e5f3e8;
  --paper-glow: #e1f0e4;
  --field: #f5faf5;
  --divider: #edf3ed;
  --balance-light: #e1f2e5;
  --balance-deep: #c5e2ce;
  --balance-line: #c2decb;
  --balance-mark: #4d886b33;
  --warning-paper: #fff6df;
  --warning-line: #ecd6a5;
  --warning-ink: #6d4b13;
  --danger: #943b42;
  --safe-bottom: max(env(safe-area-inset-bottom, 0px), var(--tg-content-safe-area-inset-bottom, 0px));
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
}

:root[data-theme="silver"] {
  --paper: #f2f4f7;
  --ink: #26323e;
  --muted: #566575;
  --line: #dce2e9;
  --accent-soft: #dfe5ed;
  --accent: #43596d;
  --accent-strong: #304459;
  --accent-outline: #697f95;
  --accent-muted: #b3c0d0;
  --tint: #e8edf4;
  --paper-glow: #e0e5ec;
  --field: #f5f7fa;
  --divider: #eaf0f5;
  --balance-light: #edf1f6;
  --balance-deep: #d6deea;
  --balance-line: #cfd8e4;
  --balance-mark: #60788c33;
}

:root[data-theme="blue"] {
  --paper: #edf6fd;
  --ink: #1e3650;
  --muted: #48647e;
  --line: #d4e5f4;
  --accent-soft: #d5eafb;
  --accent: #285d90;
  --accent-strong: #194777;
  --accent-outline: #5482ad;
  --accent-muted: #a6cae9;
  --tint: #e0f0fc;
  --paper-glow: #dcecf9;
  --field: #f3f9fe;
  --divider: #e8f1f9;
  --balance-light: #e6f3fe;
  --balance-deep: #c6e1f7;
  --balance-line: #bfd8ed;
  --balance-mark: #437cae33;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  min-width: 300px;
  min-height: 100vh;
  color: var(--ink);
  background: radial-gradient(ellipse at 50% -15%, var(--paper-glow) 0, transparent 56%), var(--paper);
}
body:has(.sheet[open]) { overflow: hidden; }
h1, h2, p { margin: 0; }
button, input, select { font: inherit; color: inherit; }
button { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
button:enabled { cursor: pointer; }
button:disabled { opacity: .55; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.symbols { position: absolute; width: 0; height: 0; overflow: hidden; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.icon { width: 22px; height: 22px; flex: 0 0 auto; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.app-shell {
  width: min(100%, 500px);
  margin-inline: auto;
  padding: max(19px, env(safe-area-inset-top, 0px), var(--tg-content-safe-area-inset-top, 0px)) 18px calc(100px + var(--safe-bottom));
}
.app-header, .brand { display: flex; align-items: center; }
.app-header { justify-content: space-between; margin-bottom: 24px; }
.brand { gap: 10px; }
.brand-icon { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 14px; color: var(--accent); background: var(--accent-soft); }
.brand-title { font-size: 16px; font-weight: 740; letter-spacing: -.02em; line-height: 1.15; }
.brand-subtitle { margin-top: 3px; font-size: 12px; color: var(--muted); }
.mode-tag { border: 1px solid var(--line); border-radius: 99px; padding: 6px 10px; color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; }

.screen-heading { margin-bottom: 15px; }
.screen-heading h1 { font-size: clamp(31px, 9vw, 40px); line-height: 1.06; font-weight: 760; letter-spacing: -.052em; }
.screen-heading p { margin-top: 7px; color: var(--muted); font-size: 14px; line-height: 1.45; }
.month-switcher { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
#month-label { font-size: 17px; font-weight: 720; letter-spacing: -.02em; }
.icon-button { display: grid; place-items: center; width: 44px; height: 44px; padding: 0; border: 1px solid var(--line); border-radius: 14px; background: var(--white); color: var(--accent); }
.icon-button:active, .secondary:active { background: var(--accent-soft); }

.card { border: 1px solid var(--line); border-radius: 22px; background: var(--white); box-shadow: 0 3px 13px #12382306; }
.state-card { padding: 22px 16px; color: var(--muted); font-size: 14px; line-height: 1.5; }
.state-card .button { margin-top: 12px; }
.calendar-card { padding: 14px 12px 12px; }
.calendar-weekdays, .calendar-days { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 3px; text-align: center; }
.calendar-weekdays { margin-bottom: 5px; color: var(--muted); font-size: 12px; font-weight: 650; }
.calendar-weekdays span { padding-block: 4px 7px; }
.calendar-day {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  height: 43px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  font-size: 15px;
  font-weight: 570;
  font-variant-numeric: tabular-nums;
}
.calendar-day:active { background: var(--paper); }
.calendar-day.has-entry { background: var(--tint); color: var(--accent-strong); font-weight: 730; }
.calendar-day[aria-current="date"] { border-color: var(--accent-outline); font-weight: 760; }
.calendar-day.has-entry::after { position: absolute; bottom: 4px; width: 4px; height: 4px; border-radius: 50%; background: var(--accent-outline); content: ""; }
.calendar-footer { display: flex; justify-content: space-between; align-items: center; gap: 6px; margin-top: 12px; padding: 11px 3px 0; border-top: 1px solid var(--divider); font-size: 12px; font-weight: 620; color: var(--muted); }
.legend { display: inline-flex; align-items: center; gap: 6px; }
.legend span { width: 9px; height: 9px; border-radius: 3px; background: var(--accent-muted); }

.button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 48px;
  padding: 10px 13px;
  border: 1px solid transparent;
  border-radius: 15px;
  font-size: 14px;
  font-weight: 690;
  line-height: 1.25;
  text-align: center;
}
.button .icon { width: 19px; height: 19px; }
.primary { color: #fff; background: var(--accent); }
.primary:active { background: var(--accent-strong); }
.secondary { background: var(--white); border-color: var(--line); color: var(--accent-strong); }
.today-button { width: 100%; margin-top: 12px; }

.balance-card { position: relative; isolation: isolate; overflow: hidden; padding: 19px 18px 17px; border-radius: 22px; border: 1px solid var(--balance-line); background: linear-gradient(125deg, var(--balance-light) 5%, var(--balance-deep) 100%); color: var(--accent-strong); }
.balance-label { font-size: 14px; font-weight: 700; }
.balance-amount { display: flex; flex-wrap: wrap; align-items: baseline; gap: 7px; margin-block: 4px 10px; font-variant-numeric: tabular-nums; line-height: 1.06; overflow-wrap: anywhere; }
#balance-value { font-size: clamp(32px, 10.4vw, 52px); font-weight: 770; letter-spacing: -.055em; }
.balance-currency { font-size: 17px; font-weight: 700; }
.balance-meta { display: inline-flex; border-radius: 30px; padding: 5px 9px; font-size: 12px; font-weight: 660; background: #ffffffa3; }
.balance-mark { position: absolute; z-index: -1; right: -14px; bottom: -27px; display: grid; place-items: center; width: 143px; height: 143px; border: 1px solid var(--balance-mark); border-radius: 50%; box-shadow: 0 0 0 18px #fff3; color: var(--balance-mark); }
.balance-mark .icon { width: 67px; height: 67px; }
.report-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-block: 10px 15px; }
.report-actions .button { padding-inline: 7px; font-size: 13px; }
.report-actions .icon { width: 17px; height: 17px; }
.breakdown { padding: 15px 15px 4px; }
h2 { font-size: 17px; line-height: 1.2; font-weight: 740; letter-spacing: -.024em; }
.breakdown table { width: 100%; margin-top: 6px; border-collapse: collapse; font-size: 14px; }
.breakdown th, .breakdown td { padding-block: 10px; }
.breakdown th { text-align: left; font-weight: 530; color: var(--muted); padding-right: 9px; }
.breakdown td { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.breakdown tr + tr { border-top: 1px solid var(--divider); }
.positive { color: var(--accent); }
.activity { margin-top: 18px; }
.activity h2 { margin: 0 2px 8px; }
.activity-list { overflow: hidden; }
.empty-activity { padding: 15px; font-size: 13px; color: var(--muted); line-height: 1.45; }
.activity-item { display: flex; align-items: center; width: 100%; gap: 9px; min-height: 60px; padding: 8px 10px; border: 0; background: var(--white); text-align: left; }
.activity-item + .activity-item { border-top: 1px solid var(--divider); }
.activity-item:active { background: var(--paper); }
.activity-item:focus-visible { outline-offset: -3px; }
.activity-icon { display: grid; place-items: center; flex: 0 0 33px; height: 33px; border-radius: 10px; background: var(--tint); color: var(--accent); }
.activity-icon .icon { width: 18px; height: 18px; }
.activity-description { flex: 1; min-width: 0; }
.activity-title { display: block; overflow-wrap: anywhere; font-size: 14px; font-weight: 670; }
.activity-date { display: block; margin-top: 3px; color: var(--muted); font-size: 12px; }
.activity-amount { flex: 0 0 auto; font-size: 13px; font-weight: 720; font-variant-numeric: tabular-nums; }
.activity-chevron { width: 15px; height: 15px; color: var(--muted); }

.tab-bar {
  position: fixed;
  z-index: 2;
  bottom: calc(9px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  width: min(calc(100% - 36px), 464px);
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: #fff;
  box-shadow: 0 9px 25px #20473218;
}
.tab-bar button { display: flex; align-items: center; justify-content: center; gap: 6px; min-height: 46px; border: 0; border-radius: 14px; background: transparent; color: var(--muted); font-size: 14px; font-weight: 670; }
.tab-bar button .icon { width: 19px; height: 19px; }
.tab-bar [aria-current="page"] { color: var(--accent-strong); background: var(--tint); }

.sheet { inset: auto 0 0; width: min(100%, 500px); max-width: none; max-height: 92dvh; overflow-y: auto; margin: 0 auto; padding: 8px 18px calc(15px + var(--safe-bottom)); border: 0; border-radius: 26px 26px 0 0; background: var(--white); color: var(--ink); box-shadow: 0 -10px 50px #10271925; }
.sheet::backdrop { background: #16332664; }
.sheet-grip { width: 33px; height: 4px; margin: 2px auto 14px; border-radius: 10px; background: var(--line); }
.sheet-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 9px; margin-bottom: 15px; }
.sheet-heading h2 { font-size: 22px; }
.sheet-heading p { margin-top: 4px; color: var(--muted); font-size: 13px; line-height: 1.4; }
.close-button { flex: 0 0 44px; }
.fields { display: grid; gap: 12px; }
.field { display: grid; gap: 6px; min-width: 0; font-size: 14px; font-weight: 660; }
.field small { margin-left: 3px; font-size: 12px; font-weight: 500; color: var(--muted); }
.input-wrap { display: flex; align-items: center; min-height: 46px; padding-inline: 11px; border: 1px solid var(--line); border-radius: 13px; background: var(--field); }
.input-wrap:focus-within { border-color: var(--accent-outline); box-shadow: 0 0 0 2px var(--tint); }
.input-wrap > span { font-weight: 550; color: var(--muted); }
.input-wrap input { width: 100%; min-width: 0; height: 44px; padding: 0; border: 0; outline: none; background: transparent; font-size: 16px; font-weight: 560; }
.input-wrap input::placeholder { color: var(--muted); }
.input-wrap input[type="date"] { appearance: none; -webkit-appearance: none; text-align: left; }
.input-wrap input[type="date"]::-webkit-date-and-time-value { text-align: left; }
.payment-kinds { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; min-width: 0; margin: 0; padding: 0; border: 0; }
.payment-kinds legend { margin-bottom: 5px; padding: 0; font-size: 14px; font-weight: 660; }
.payment-kinds label { position: relative; }
.payment-kinds input { position: absolute; opacity: 0; }
.payment-kinds label span { display: grid; place-items: center; min-height: 45px; height: 100%; padding: 6px; border: 1px solid var(--line); border-radius: 12px; font-size: 13px; font-weight: 650; text-align: center; cursor: pointer; }
.payment-kinds input:checked + span { color: var(--accent-strong); background: var(--tint); border-color: var(--accent-muted); }
.payment-kinds input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.save-button { width: 100%; margin-top: 15px; }
.text-button { width: 100%; min-height: 44px; margin-top: 3px; background: transparent; }
.danger { color: var(--danger); }
.danger-button { background: var(--danger); color: var(--white); }
.form-error { margin-top: 9px; color: var(--danger); font-size: 13px; line-height: 1.35; }
.delete-confirmation { margin-top: 10px; padding: 11px; border-radius: 13px; background: #fff2f1; color: var(--danger); font-size: 14px; }
.delete-confirmation div { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin-top: 8px; }
.toast { position: fixed; z-index: 3; bottom: calc(76px + var(--safe-bottom)); left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 6px; width: max-content; max-width: calc(100% - 38px); padding: 9px 13px; border-radius: 13px; background: var(--accent-strong); color: #fff; box-shadow: 0 3px 12px #193c2830; font-size: 13px; font-weight: 650; }
.toast .icon { width: 17px; height: 17px; }


.header-actions { display: flex; align-items: center; gap: 8px; }
.theme-button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 44px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--white);
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 680;
}
.palette-mark { display: inline-flex; padding-left: 3px; }
.palette-mark i { width: 10px; height: 10px; margin-left: -3px; border: 1px solid var(--white); border-radius: 50%; }
.palette-mark i:nth-child(1) { background: #91c9a5; }
.palette-mark i:nth-child(2) { background: #aebacb; }
.palette-mark i:nth-child(3) { background: #9bc6ed; }
.theme-choices { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; }
.theme-choice {
  display: grid;
  align-content: start;
  gap: 8px;
  padding: 6px 6px 10px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: var(--white);
  font-size: 12px;
  font-weight: 680;
  color: var(--ink);
}
.theme-choice[aria-pressed="true"] { border-color: var(--accent-outline); box-shadow: 0 0 0 1px var(--accent-outline); }
.theme-swatch { display: grid; place-items: center; min-height: 45px; border-radius: 10px; }
.theme-swatch::after { width: 35%; height: 8px; border-radius: 5px; background: var(--swatch-ink); content: ""; }
.mint-swatch { background: #d8eddd; --swatch-ink: #245a43; }
.silver-swatch { background: #dfe5ed; --swatch-ink: #43596d; }
.blue-swatch { background: #d5eafb; --swatch-ink: #285d90; }

.notice {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: var(--tint);
  color: var(--accent-strong);
  font-size: 14px;
}
.notice p { margin-top: 3px; font-size: 12px; line-height: 1.4; }
.notice .button { min-height: 44px; }
.storage-warning { border-color: var(--warning-line); background: var(--warning-paper); color: var(--warning-ink); }
.storage-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 12px;
  padding: 12px 14px;
}
.storage-card p { margin-top: 4px; color: var(--muted); font-size: 12px; }
.storage-card .button { min-height: 44px; padding-inline: 10px; font-size: 13px; }
.storage-capacity {
  display: grid;
  gap: 8px;
  padding: 11px 12px;
  border-radius: 14px;
  background: var(--tint);
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 670;
}
.storage-capacity progress { width: 100%; height: 8px; accent-color: var(--accent); }
.storage-actions { gap: 8px; margin-top: 13px; }
.storage-selection { color: var(--muted); font-size: 13px; line-height: 1.4; }
.storage-feedback { margin-top: 9px; color: var(--accent-strong); font-size: 13px; line-height: 1.4; }
.month-select {
  min-height: 44px;
  width: 100%;
  padding-inline: 9px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--field);
  font-size: 16px;
}
.open-copy-button { width: 100%; margin-top: 12px; }
#editor[data-read-only="true"] .field small { display: none; }

@media (min-width: 530px) {
  .app-shell { padding-top: 26px; }
  .calendar-day { height: 48px; }
  .sheet { inset: 0; margin: auto; border-radius: 25px; padding-bottom: 16px; }
}
