:root {
  color-scheme: light;
  --ink: #172420;
  --muted: #64716d;
  --paper: #f4f1e9;
  --card: #fffefa;
  --line: #dcd8cc;
  --brand: #153c34;
  --brand-2: #26725f;
  --accent: #d4a52c;
  --danger: #a23a34;
  --good: #28724d;
  --shadow: 0 10px 30px rgba(21, 60, 52, .09);
  font-family: Arial, "Noto Sans Hebrew", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--paper); color: var(--ink); }
body { min-height: 100dvh; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: .55; }
a { color: var(--brand-2); }

.app-shell { min-height: 100dvh; padding-bottom: calc(78px + env(safe-area-inset-bottom)); }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  color: white; background: var(--brand); box-shadow: 0 2px 12px rgba(0,0,0,.12);
}
.brand-title { font-weight: 800; font-size: 1.1rem; }
.brand-subtitle { font-size: .75rem; opacity: .75; margin-top: 2px; }
.sync-pill { border: 1px solid rgba(255,255,255,.3); color: white; background: rgba(255,255,255,.08); border-radius: 999px; padding: 7px 10px; font-size: .78rem; }
.sync-pill.error { background: rgba(162,58,52,.75); }

main { width: min(920px, 100%); margin: 0 auto; padding: 16px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.page-head h1 { font-size: 1.35rem; margin: 0; }
.page-head p { margin: 4px 0 0; color: var(--muted); font-size: .86rem; }

.bottom-nav {
  position: fixed; z-index: 30; inset-inline: 0; bottom: 0;
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  background: rgba(255,254,250,.97); border-top: 1px solid var(--line); backdrop-filter: blur(16px);
}
.nav-btn { border: 0; background: transparent; color: var(--muted); border-radius: 12px; padding: 7px 3px; font-size: .72rem; min-width: 0; }
.nav-btn strong { display: block; font-size: 1.25rem; line-height: 1.1; margin-bottom: 3px; }
.nav-btn.active { color: var(--brand); background: #e6eee9; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 16px; box-shadow: var(--shadow); }
.card + .card { margin-top: 14px; }
.grid { display: grid; gap: 12px; }
.stats { grid-template-columns: repeat(3, 1fr); }
.stat { min-width: 0; }
.stat-label { color: var(--muted); font-size: .76rem; }
.stat-value { font-size: 1.15rem; font-weight: 800; margin-top: 5px; overflow-wrap: anywhere; }
.stat-value.expense { color: var(--danger); }
.stat-value.income { color: var(--good); }

.segmented { display: flex; gap: 4px; background: #e8e5dc; border-radius: 12px; padding: 4px; }
.segmented button { flex: 1; border: 0; background: transparent; border-radius: 9px; padding: 8px; color: var(--muted); }
.segmented button.active { background: white; color: var(--ink); box-shadow: 0 2px 8px rgba(0,0,0,.08); }

.primary, .secondary, .danger, .ghost {
  border-radius: 12px; min-height: 44px; padding: 10px 14px; font-weight: 700;
}
.primary { border: 0; color: white; background: var(--brand-2); }
.secondary { border: 1px solid var(--brand-2); color: var(--brand-2); background: transparent; }
.danger { border: 1px solid #dbb4b0; color: var(--danger); background: #fff7f6; }
.ghost { border: 0; color: var(--brand); background: #e6eee9; }
.icon-btn { border: 0; background: transparent; padding: 8px; border-radius: 10px; color: var(--brand); }
.full { width: 100%; }
.actions { display: flex; flex-wrap: wrap; gap: 9px; }
.actions > * { flex: 1 1 130px; }

label { display: grid; gap: 6px; font-size: .84rem; color: var(--muted); }
input, select, textarea {
  width: 100%; border: 1px solid #cfcabd; border-radius: 12px; background: white; color: var(--ink);
  padding: 11px 12px; min-height: 44px;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(38,114,95,.16); border-color: var(--brand-2); }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.form-grid .wide { grid-column: 1 / -1; }

.gate { min-height: 100dvh; display: grid; place-items: center; padding: 22px; background: radial-gradient(circle at 20% 10%, #dbe7dd, transparent 35%), var(--paper); }
.gate-card { width: min(480px, 100%); }
.logo { width: 78px; height: 78px; display: grid; place-items: center; border-radius: 24px; background: var(--brand); color: white; font-size: 2.1rem; font-weight: 900; box-shadow: var(--shadow); margin-bottom: 16px; }
.gate h1 { margin: 0; font-size: 1.75rem; }
.gate .intro { color: var(--muted); line-height: 1.55; }
.gate form { margin-top: 18px; display: grid; gap: 12px; }
.small-note { color: var(--muted); font-size: .78rem; line-height: 1.5; }
.error-box { border: 1px solid #e5b9b5; background: #fff5f4; color: var(--danger); border-radius: 12px; padding: 10px; margin-top: 10px; }

.list { display: grid; gap: 9px; }
.list-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid #ebe7dc; }
.list-row:last-child { border-bottom: 0; }
.list-main { flex: 1; min-width: 0; }
.list-title { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-meta { color: var(--muted); font-size: .77rem; margin-top: 4px; }
.amount { direction: ltr; font-weight: 800; white-space: nowrap; }
.amount.expense { color: var(--danger); }
.amount.income { color: var(--good); }
.badge { display: inline-flex; align-items: center; border-radius: 999px; padding: 4px 8px; font-size: .72rem; background: #ede9de; color: var(--muted); }
.badge.business { background: #f0e5c7; color: #755b16; }
.empty { text-align: center; color: var(--muted); padding: 26px 10px; }

.progress-row { margin-top: 14px; }
.progress-head { display: flex; justify-content: space-between; gap: 12px; font-size: .82rem; margin-bottom: 6px; }
.budget-progress { width: 100%; height: 10px; border: 0; border-radius: 999px; overflow: hidden; background: #e5e2d9; }
.budget-progress::-webkit-progress-bar { background: #e5e2d9; border-radius: 999px; }
.budget-progress::-webkit-progress-value { background: var(--brand-2); border-radius: 999px; }
.budget-progress::-moz-progress-bar { background: var(--brand-2); border-radius: 999px; }
.budget-progress.over::-webkit-progress-value { background: var(--danger); }
.budget-progress.over::-moz-progress-bar { background: var(--danger); }

.fab {
  position: fixed; z-index: 25; inset-inline-end: 18px; bottom: calc(84px + env(safe-area-inset-bottom));
  width: 56px; height: 56px; border-radius: 50%; border: 0; background: var(--accent); color: #2b240e;
  box-shadow: 0 8px 24px rgba(0,0,0,.22); font-size: 1.8rem; font-weight: 500;
}

dialog { width: min(590px, calc(100% - 20px)); max-height: 90dvh; border: 0; border-radius: 20px; padding: 0; box-shadow: 0 20px 70px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(10,24,20,.55); backdrop-filter: blur(3px); }
.dialog-body { padding: 18px; overflow: auto; max-height: 90dvh; }
.dialog-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }
.dialog-head h2 { margin: 0; font-size: 1.25rem; }

.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 12px; }
table { width: 100%; border-collapse: collapse; font-size: .78rem; }
th, td { padding: 9px; border-bottom: 1px solid var(--line); text-align: start; white-space: nowrap; }
th { background: #eeece5; position: sticky; top: 0; }

.code-box { direction: ltr; text-align: left; overflow-wrap: anywhere; font-family: monospace; background: #efede6; border-radius: 10px; padding: 10px; font-size: .76rem; }
.toast { position: fixed; z-index: 100; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); background: #172420; color: white; padding: 11px 15px; border-radius: 12px; opacity: 0; pointer-events: none; transition: .2s; max-width: calc(100% - 30px); text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.warning { color: #7c5a0b; background: #fff8e5; border: 1px solid #ead7a5; border-radius: 12px; padding: 10px; }

@media (max-width: 620px) {
  main { padding: 12px; }
  .stats { grid-template-columns: 1fr; }
  .stats .stat { display: flex; align-items: baseline; justify-content: space-between; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .wide { grid-column: auto; }
  .card { padding: 14px; border-radius: 16px; }
}
.success-box { border: 1px solid #a9d8c8; background: #f1fbf7; color: #17644f; border-radius: 12px; padding: 10px; margin: 0 0 14px; }
.import-rules { margin: 14px 0; padding: 12px; border: 1px solid var(--line); border-radius: 14px; background: #faf9f4; }
.import-rules h3 { margin: 0 0 4px; }
.import-rules label { margin-top: 10px; }
