:root {
  color-scheme: light;
  font-family: Inter, system-ui, -apple-system, 'Segoe UI', sans-serif;
  color: #202a24;
  background: #f6f5ee;
  --green: #215640;
  --dark-green: #194432;
  --pale-green: #e9f2e8;
  --rust: #994835;
  --line: #e1e3d9;
  --muted: #5e685e;
  --paper: #fffefa;
  --radius: 22px;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 300px; }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
button, label, input, select { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid #509677; outline-offset: 3px; }
h1, h2, p { margin: 0; }
h1 { font-size: clamp(2rem, 5vw, 2.8rem); letter-spacing: -.055em; line-height: 1.1; }
h2 { font-size: 1.12rem; letter-spacing: -.024em; line-height: 1.3; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
.muted, .hint, .empty { color: var(--muted); }
.hint { font-size: .85rem; line-height: 1.4; }
.empty { padding: 23px 0 7px; font-size: .95rem; line-height: 1.55; }

.topbar { background: var(--paper); border-bottom: 1px solid var(--line); }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 20px; min-height: 70px; width: min(100% - 40px, 1000px); margin: auto; }
.brand, .brand-mark { display: inline-flex; align-items: center; }
.brand { gap: 10px; white-space: nowrap; font-size: 1.09rem; font-weight: 750; letter-spacing: -.035em; }
.brand-mark { justify-content: center; width: 35px; height: 35px; border-radius: 11px; color: #eaf5db; background: var(--green); font-size: 1.45rem; line-height: 1; }
.top-date { color: var(--muted); font-size: .84rem; font-weight: 600; white-space: nowrap; }
nav { display: flex; gap: 3px; padding: 4px; border-radius: 14px; background: #f1f2e9; }
nav button { display: flex; align-items: center; justify-content: center; gap: 7px; padding: 8px 13px; min-height: 41px; border: 1px solid transparent; border-radius: 10px; color: var(--muted); background: transparent; font-size: .88rem; font-weight: 700; }
nav button[aria-current] { color: var(--dark-green); border-color: var(--line); background: var(--paper); }
.icon { display: inline-block; width: 16px; height: 16px; position: relative; flex: none; }
.icon-entry { border: 1.5px solid currentColor; border-radius: 4px; }
.icon-entry::before, .icon-entry::after { position: absolute; content: ''; background: currentColor; border-radius: 1px; inset: 6px 3px; }
.icon-entry::after { transform: rotate(90deg); }
.icon-report { border-left: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; border-radius: 1px; }
.icon-report::after { position: absolute; bottom: 2px; left: 3px; content: ''; width: 3px; height: 4px; background: currentColor; border-radius: 1px; box-shadow: 4px -3px currentColor, 8px -6px currentColor; }
.icon-settings { border: 1.5px solid currentColor; border-radius: 50%; }
.icon-settings::after { position: absolute; content: ''; inset: 3px; border: 1.5px solid currentColor; border-radius: 50%; }

main { width: min(100% - 40px, 1000px); margin: 36px auto 65px; }
.boot { text-align: center; color: var(--muted); margin: 70px 0; }
.page-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px 14px; flex-wrap: wrap; margin-bottom: 21px; }
.date-pill { padding: 6px 11px; border: 1px solid #dbe2d5; border-radius: 99px; color: var(--dark-green); background: #edf1e6; font-size: .8rem; font-weight: 650; white-space: nowrap; }
.entry-layout, .report-layout, .settings-layout { display: grid; gap: 18px; align-items: start; }
.entry-layout { grid-template-columns: 1.15fr 1fr; }
.report-layout { grid-template-columns: 1fr 1.15fr; }
.settings-layout { grid-template-columns: 1.5fr 1fr; }
.panel { min-width: 0; padding: 23px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper); box-shadow: 0 2px 5px #202a2406; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 7px 12px; min-height: 30px; }
.panel-heading .muted { font-size: .85rem; }
.entry-panel, .login-panel { display: grid; gap: 15px; }
.login-view { max-width: 390px; margin: clamp(27px, 11vh, 105px) auto; }
.login-panel { padding: clamp(22px, 6vw, 32px); }
.login-panel h1 { margin-bottom: 8px; }
.login-mark { width: 49px; height: 49px; border-radius: 15px; font-size: 2rem; }

.field { display: grid; gap: 6px; min-width: 0; color: #27352c; font-size: .875rem; font-weight: 700; }
.field-heading { display: flex; align-items: center; justify-content: space-between; gap: 5px; }
.field small { margin-left: 4px; font-size: .77rem; color: var(--muted); font-weight: 500; }
.field input:not([type='radio']), .field select { width: 100%; min-width: 0; min-height: 45px; padding: 9px 12px; border: 1px solid #cfd5ca; border-radius: 11px; background: #fff; color: #202a24; font-size: 1rem; font-weight: 500; }
.field input[type='date'] { display: block; -webkit-appearance: none; appearance: none; }
.field input::placeholder { color: #6d756d; }
.field input:focus, .field select:focus { border-color: #4a8967; }
fieldset { min-inline-size: 0; margin: 0; padding: 0; border: none; }
legend { padding: 0; }
.segmented, .payment-options { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.segmented { padding: 4px; border-radius: 13px; background: #efefe7; }
.segmented label, .payment-options label { position: relative; min-width: 0; cursor: pointer; }
.segmented input, .payment-options input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.segmented label > span, .payment-options label > span { display: flex; align-items: center; justify-content: center; gap: 6px; min-height: 43px; border: 1px solid transparent; border-radius: 10px; font-size: .9rem; font-weight: 700; }
.segmented input:checked + span { background: var(--paper); border-color: var(--line); color: var(--green); }
.segmented label:first-of-type input:checked + span { color: var(--rust); }
.segmented input:focus-visible + span, .payment-options input:focus-visible + span { outline: 3px solid #509677; outline-offset: 2px; }
.segmented b { font-size: 1.1rem; }
.amount-input { display: flex; align-items: center; gap: 8px; min-width: 0; padding-right: 12px; border: 1px solid #cfd5ca; border-radius: 11px; background: #f8faf4; }
.amount-input:focus-within { outline: 2px solid #509677; outline-offset: 2px; }
.amount-field .amount-input input { min-height: 53px; padding: 8px 12px; border: 0; background: transparent; font-size: clamp(1.4rem, 6vw, 1.8rem); font-weight: 750; font-variant-numeric: tabular-nums; letter-spacing: -.045em; outline: none; }
.amount-input > span { color: var(--green); font-size: 1.14rem; }
#expense-fields { display: grid; gap: 14px; }
.payment-options label > span { min-height: 47px; padding: 6px; border-color: #cfd5ca; background: #fff; }
.payment-options input:checked + span { border-color: #5b9574; background: var(--pale-green); color: var(--dark-green); }
.payment-options b { font-size: .72rem; color: var(--green); background: #ecf0e7; padding: 4px 5px; border-radius: 5px; }

.primary, .secondary, .danger { min-height: 44px; padding: 9px 16px; border: 1px solid transparent; border-radius: 11px; font-weight: 750; white-space: nowrap; }
.primary { color: white; background: var(--green); }
.primary:hover:not(:disabled) { background: var(--dark-green); }
.primary:disabled { color: #566057; background: #e1e5dc; }
.secondary { color: var(--dark-green); border-color: #cfd5ca; background: var(--paper); }
.secondary:hover:not(:disabled) { background: #eff4ec; }
.danger { color: #842f20; background: #faece6; }
.text-button { min-height: 34px; border: 0; border-radius: 7px; padding: 3px 4px; color: var(--dark-green); background: transparent; font-weight: 700; font-size: .81rem; text-decoration: underline; text-underline-offset: 3px; }
.full { width: 100%; }
.feedback { padding: 10px 12px; border-radius: 9px; background: var(--pale-green); color: var(--dark-green); font-size: .88rem; line-height: 1.4; font-weight: 600; }
.feedback[data-error] { color: #842f20; background: #faece6; }

.transaction { display: grid; grid-template-columns: 36px minmax(0, 1fr) auto; align-items: center; gap: 9px; min-height: 61px; width: 100%; padding: 8px 0; color: inherit; text-align: left; background: transparent; border: 0; border-bottom: 1px solid var(--line); }
.transaction:last-child { border-bottom: 0; }
.transaction:hover { background: #f8faf4; }
.transaction-icon { display: grid; place-items: center; width: 33px; height: 33px; border-radius: 10px; background: #faece6; color: var(--rust); font-weight: 750; }
.transaction-icon.income { color: var(--green); background: var(--pale-green); }
.transaction-info { display: grid; gap: 3px; min-width: 0; }
.transaction-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .91rem; font-weight: 720; }
.transaction-meta { color: var(--muted); font-size: .75rem; line-height: 1.3; }
.transaction-amount { color: var(--rust); font-size: .85rem; font-weight: 750; font-variant-numeric: tabular-nums; white-space: nowrap; }
.transaction-amount.income { color: var(--green); }

.filter-panel { display: flex; flex-wrap: wrap; align-items: end; gap: 12px; margin-bottom: 15px; }
.filter-panel > .field { flex: 0 1 215px; }
.custom-period { display: grid; grid-template-columns: 1fr 1fr auto; align-items: end; gap: 10px; }
.metrics { display: grid; grid-template-columns: 1fr 1fr 1.05fr; gap: 12px; margin: 15px 0; }
.metric { display: grid; align-content: start; gap: 9px; min-width: 0; padding: 17px; border: 1px solid var(--line); border-radius: 16px; background: var(--paper); }
.metric span { color: var(--muted); font-size: .83rem; font-weight: 700; }
.metric strong { font-size: clamp(1.05rem, 3.2vw, 1.7rem); letter-spacing: -.035em; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.metric-income strong { color: var(--green); }
.metric-expense strong { color: var(--rust); }
.metric-net { color: #f4f8ee; border-color: var(--green); background: var(--green); }
.metric-net span { color: #e0ebdc; }
.breakdown { display: grid; gap: 15px; margin-top: 12px; }
.group-line { display: flex; justify-content: space-between; align-items: start; gap: 10px; font-size: .875rem; }
.group-line span { min-width: 0; overflow-wrap: anywhere; }
.group-line strong { white-space: nowrap; }
progress { display: block; width: 100%; height: 8px; margin-top: 7px; overflow: hidden; border: none; border-radius: 99px; color: #4f825f; background: #e8eee4; }
progress::-webkit-progress-bar { background: #e8eee4; }
progress::-webkit-progress-value { border-radius: 99px; background: #4f825f; }
progress::-moz-progress-bar { border-radius: 99px; background: #4f825f; }
.payments-summary { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding-top: 16px; margin-top: 20px; border-top: 1px solid var(--line); }
.payments-summary div { display: grid; gap: 5px; font-size: .85rem; overflow-wrap: anywhere; }
.payments-summary span { color: var(--muted); }
#load-more, #logout { margin-top: 10px; }

.category-form { display: grid; grid-template-columns: 1fr auto; align-items: end; gap: 10px; margin: 10px 0; }
.category-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 49px; padding: 5px 0; border-bottom: 1px solid var(--line); }
.category-row:last-child { border-bottom: 0; }
.category-name { min-width: 0; overflow-wrap: anywhere; font-weight: 650; }
.category-actions { display: flex; gap: 10px; flex: none; }
.category-actions button { min-height: 43px; }
dialog { width: min(100% - 32px, 410px); padding: 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper); color: inherit; }
dialog::backdrop { background: #152a21a6; }
.dialog-form { display: grid; gap: 15px; padding: 22px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.transaction-details { color: var(--muted); line-height: 1.55; overflow-wrap: anywhere; }

@media (max-width: 700px) {
  .topbar-inner { width: calc(100% - 32px); min-height: 58px; }
  main { width: calc(100% - 32px); margin: 22px auto calc(86px + env(safe-area-inset-bottom)); }
  nav { position: fixed; z-index: 2; left: 0; right: 0; bottom: 0; justify-content: center; gap: 6px; padding: 6px 12px calc(6px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); border-radius: 0; background: var(--paper); }
  nav button { flex: 1 1 0; max-width: 175px; min-height: 53px; flex-direction: column; gap: 5px; padding: 5px; font-size: .76rem; }
  nav button[aria-current] { border-color: transparent; background: var(--pale-green); }
  .entry-layout, .report-layout, .settings-layout { grid-template-columns: 1fr; gap: 13px; }
  .panel { padding: 16px; border-radius: 17px; }
  .page-heading { margin-bottom: 14px; }
  .filter-panel > .field { flex: 1 1 100%; }
  .custom-period { width: 100%; grid-template-columns: 1fr 1fr; }
  .custom-period button { grid-column: 1 / -1; }
  .metrics { grid-template-columns: 1fr 1fr; gap: 8px; }
  .metric { padding: 12px; }
  .metric-net { grid-column: 1 / -1; grid-template-columns: auto 1fr; align-items: center; }
  .metric-net strong { justify-self: end; }
}

@media (max-width: 365px) {
  .topbar-inner, main { width: calc(100% - 22px); }
  .panel { padding: 13px; }
  .payment-options label > span { font-size: .79rem; }
  .category-form { grid-template-columns: 1fr; }
  .transaction { grid-template-columns: 29px minmax(0, 1fr) auto; gap: 6px; }
  .transaction-icon { width: 26px; height: 29px; }
  .transaction-amount { font-size: .78rem; }
}
