:root {
  --green: #174c3c;
  --green-2: #23634f;
  --cream: #f5f4ef;
  --paper: #ffffff;
  --ink: #17211d;
  --muted: #6e7772;
  --line: #dde2de;
  --yellow: #f7c95c;
  --coral: #ef6d4f;
  --shadow: 0 16px 45px rgba(20, 48, 39, .09);
  --radius: 22px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--cream);
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--cream); }
body { margin: 0; min-height: 100vh; background: var(--cream); }
button, input, select { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.auth-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at 20% 10%, #d9eadf 0, transparent 32%), var(--cream); }
.auth-card { width: min(100%, 410px); padding: 34px; background: rgba(255,255,255,.94); border: 1px solid rgba(23,76,60,.1); border-radius: 30px; box-shadow: var(--shadow); }
.brand-mark { width: 62px; height: 62px; display: grid; place-items: center; border-radius: 20px; color: var(--yellow); background: var(--green); font-size: 30px; font-weight: 900; margin-bottom: 24px; }
.auth-card h1 { margin: 5px 0 4px; letter-spacing: -.04em; font-size: 35px; }
.eyebrow { margin: 0; color: var(--green-2); font-size: 11px; font-weight: 800; letter-spacing: .15em; }
.muted { color: var(--muted); line-height: 1.55; }
.demo-hint { margin: 18px 0 0; padding: 12px; border-radius: 14px; background: #fff8df; color: #715c19; font-size: 12px; line-height: 1.5; }
.login-error { margin: 14px 0 0; padding: 12px; border: 1px solid #f0b7aa; border-radius: 13px; color: #8f3525; background: #fff0ec; font-size: 13px; line-height: 1.5; }

.stack { display: grid; gap: 14px; margin-top: 24px; }
label { display: grid; gap: 7px; color: #34413b; font-size: 13px; font-weight: 700; }
input, select { width: 100%; min-height: 46px; border: 1px solid var(--line); border-radius: 13px; padding: 0 13px; color: var(--ink); background: #fff; outline: none; }
input:focus, select:focus { border-color: var(--green-2); box-shadow: 0 0 0 3px rgba(35,99,79,.1); }
.check-row { grid-template-columns: auto 1fr; align-items: center; font-weight: 500; }
.check-row input { width: 18px; min-height: 18px; }
.button { min-height: 48px; padding: 0 18px; border: 0; border-radius: 14px; font-weight: 800; }
.button:disabled { opacity: .55; cursor: wait; }
.primary { background: var(--green); color: white; }
.secondary { background: #e5efe9; color: var(--green); }
.text-button { padding: 8px 0; border: 0; color: var(--green-2); background: transparent; font-weight: 800; }
.icon-button { width: 42px; height: 42px; border: 1px solid var(--line); border-radius: 50%; background: white; color: var(--green); font-size: 20px; }

.app-shell { width: min(100%, 1100px); min-height: 100vh; margin: auto; background: var(--cream); }
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between; padding: max(18px, env(safe-area-inset-top)) 22px 14px; background: rgba(245,244,239,.88); backdrop-filter: blur(16px); }
.topbar h1 { margin: 3px 0 0; font-size: 22px; letter-spacing: -.02em; }
.content { padding: 10px 18px calc(100px + env(safe-area-inset-bottom)); }
.view { display: none; animation: enter .2s ease; }
.view.active { display: block; }
@keyframes enter { from { opacity: .3; transform: translateY(5px); } }
.section-head { display: flex; align-items: end; justify-content: space-between; gap: 15px; margin: 15px 2px 18px; }
.section-head h2 { margin: 3px 0 0; font-size: 29px; letter-spacing: -.04em; }
.month-input { width: 150px; background: transparent; border-color: transparent; font-weight: 800; }

.metric-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.metric { min-width: 0; padding: 18px; border-radius: 20px; background: white; border: 1px solid rgba(23,76,60,.08); box-shadow: 0 6px 25px rgba(20,48,39,.04); }
.metric span { display: block; margin-bottom: 12px; color: var(--muted); font-size: 12px; font-weight: 700; }
.metric strong { display: block; overflow: hidden; text-overflow: ellipsis; font-size: clamp(17px, 2vw, 25px); letter-spacing: -.035em; }
.metric.income { border-top: 4px solid var(--green-2); }
.metric.expense { border-top: 4px solid var(--coral); }
.metric.profit { border-top: 4px solid var(--yellow); }
.metric.funds { color: white; background: var(--green); }
.metric.funds span { color: #cfe2d8; }

.panel { margin-top: 14px; padding: 18px; border: 1px solid rgba(23,76,60,.08); border-radius: var(--radius); background: var(--paper); box-shadow: 0 6px 25px rgba(20,48,39,.035); }
.panel-head { display: flex; align-items: center; justify-content: space-between; }
.panel h3 { margin: 0; font-size: 16px; }
.account-list { display: grid; grid-template-columns: repeat(auto-fit,minmax(135px,1fr)); gap: 10px; margin-top: 14px; }
.account-chip { padding: 13px; border-radius: 15px; background: #f1f5f2; }
.account-chip span { display: block; color: var(--muted); font-size: 11px; }
.account-chip strong { display: block; margin-top: 5px; font-size: 15px; }
.report-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.breakdown-list, .comparison-list { display: grid; gap: 12px; margin-top: 17px; }
.breakdown-row { display: grid; grid-template-columns: minmax(80px,1fr) 2fr auto; align-items: center; gap: 10px; font-size: 12px; }
.breakdown-bar { width: 100%; height: 8px; overflow: hidden; border: 0; border-radius: 99px; background: #edf0ee; appearance: none; }
.breakdown-bar::-webkit-progress-bar { border-radius: 99px; background: #edf0ee; }
.breakdown-bar::-webkit-progress-value { border-radius: 99px; background: var(--coral); }
.breakdown-bar::-moz-progress-bar { border-radius: 99px; background: var(--coral); }
.comparison-row { display: grid; grid-template-columns: 70px 1fr 1fr; gap: 10px; align-items: center; padding-bottom: 10px; border-bottom: 1px solid #edf0ee; font-size: 12px; }
.comparison-row strong:nth-child(2) { color: var(--green-2); }
.comparison-row strong:nth-child(3) { color: var(--coral); text-align: right; }
.transaction-list { display: grid; gap: 0; }
.transaction-row { display: grid; grid-template-columns: 42px minmax(0,1fr) auto auto; gap: 11px; align-items: center; padding: 14px 0; border-bottom: 1px solid #edf0ee; }
.transaction-row:last-child { border-bottom: 0; }
.transaction-icon { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 14px; background: #edf5f0; color: var(--green); font-weight: 900; }
.transaction-icon.expense { color: #a2412c; background: #fff0ec; }
.transaction-icon.transfer { color: #856814; background: #fff7d9; }
.transaction-copy { min-width: 0; }
.transaction-copy strong, .transaction-copy span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.transaction-copy span { margin-top: 3px; color: var(--muted); font-size: 11px; }
.transaction-amount { text-align: right; font-weight: 900; }
.transaction-amount.income { color: var(--green-2); }
.transaction-amount.expense { color: var(--coral); }
.void-button { border: 0; border-radius: 10px; padding: 7px; color: #99503e; background: #fff0ec; font-size: 11px; }
.voided { opacity: .5; text-decoration: line-through; }
.empty { display: grid; gap: 5px; place-items: center; padding: 34px 10px; color: var(--muted); text-align: center; }
.empty span { font-size: 12px; }

.entry-form { max-width: 700px; margin-inline: auto; padding: 22px; }
.segment { display: grid; grid-template-columns: repeat(3,1fr); gap: 5px; padding: 5px; border-radius: 15px; background: #edf1ee; }
.segment-button { min-height: 42px; border: 0; border-radius: 11px; color: var(--muted); background: transparent; font-weight: 800; }
.segment-button.active { color: white; background: var(--green); box-shadow: 0 5px 14px rgba(23,76,60,.18); }
.amount-label { margin: 25px 0; }
.amount-wrap { display: grid; grid-template-columns: auto 1fr; align-items: center; border-bottom: 2px solid var(--green); }
.amount-wrap span { color: var(--green); font-size: 28px; font-weight: 900; }
.amount-wrap input { min-height: 70px; border: 0; box-shadow: none; font-size: 42px; font-weight: 900; letter-spacing: -.04em; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }
.entry-form > label { margin-top: 14px; }
.entry-form > .button { width: 100%; margin-top: 22px; }
.filters { display: grid; grid-template-columns: repeat(5,1fr); gap: 8px; }
.filters input, .filters select { min-width: 0; }

details.panel { padding: 0; overflow: hidden; }
details summary { padding: 18px; list-style: none; cursor: pointer; font-weight: 850; }
details summary::after { content: "+"; float: right; color: var(--green); }
details[open] summary::after { content: "−"; }
.settings-body { margin: 0; padding: 0 18px 18px; border-top: 1px solid #edf0ee; }
.manage-list { display: grid; gap: 8px; padding-top: 15px; }
.manage-item { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 10px; padding: 12px; border-radius: 13px; background: #f3f5f3; }
.manage-item span { color: var(--muted); font-size: 11px; }
.inline-form { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; margin-top: 14px; }

.bottom-nav { position: fixed; left: 50%; bottom: max(10px, env(safe-area-inset-bottom)); z-index: 20; width: min(calc(100% - 24px), 660px); display: grid; grid-template-columns: repeat(4,1fr); transform: translateX(-50%); padding: 7px; border: 1px solid rgba(23,76,60,.1); border-radius: 22px; background: rgba(255,255,255,.94); backdrop-filter: blur(18px); box-shadow: var(--shadow); }
.nav-button { min-height: 54px; display: grid; place-items: center; gap: 1px; border: 0; border-radius: 16px; color: var(--muted); background: transparent; font-size: 11px; font-weight: 800; }
.nav-button span { font-size: 21px; line-height: 1; }
.nav-button.active { color: var(--green); background: #e9f1ec; }
.toast { position: fixed; left: 50%; bottom: 95px; z-index: 100; max-width: calc(100% - 32px); transform: translate(-50%, 20px); padding: 12px 18px; border-radius: 13px; color: white; background: #17211d; opacity: 0; pointer-events: none; transition: .2s; font-size: 13px; box-shadow: var(--shadow); }
.toast.show { opacity: 1; transform: translate(-50%,0); }
.toast.error { background: #9c3c2b; }

@media (max-width: 720px) {
  .metric-grid { grid-template-columns: repeat(2,minmax(0,1fr)); gap: 9px; }
  .metric { padding: 14px; }
  .metric strong { font-size: 17px; }
  .filters { grid-template-columns: 1fr 1fr; }
  .filters > :last-child { grid-column: 1 / -1; }
  .report-grid { grid-template-columns: 1fr; }
  .transaction-row { grid-template-columns: 40px minmax(0,1fr) auto; }
  .transaction-row .void-button { grid-column: 2 / -1; justify-self: end; }
}

@media (max-width: 430px) {
  .auth-card { padding: 27px 22px; }
  .content { padding-inline: 13px; }
  .topbar { padding-inline: 16px; }
  .section-head h2 { font-size: 26px; }
  .month-input { width: 132px; padding-inline: 3px; }
  .form-grid { grid-template-columns: 1fr; }
  .entry-form { padding: 16px; }
  .amount-wrap input { font-size: 36px; }
  .inline-form { grid-template-columns: 1fr; }
}

@media (display-mode: standalone) {
  .topbar { padding-top: max(20px, env(safe-area-inset-top)); }
}
