:root {
  --bg: #f4f1ea;
  --card: #ffffff;
  --text: #1d2422;
  --muted: #6b7471;
  --line: #e4dfd4;
  --accent: #1f6f5c;
  --accent-soft: #dcebe5;
  --accent-text: #ffffff;
  --danger: #b3412e;
  --chip: #efebe2;
  --shadow: 0 1px 2px rgba(30, 40, 35, .06), 0 4px 16px rgba(30, 40, 35, .06);
  --radius: 18px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121615;
    --card: #1c2220;
    --text: #eef2f0;
    --muted: #9aa5a1;
    --line: #2c3431;
    --accent: #4fb397;
    --accent-soft: #1f3a32;
    --accent-text: #0d1513;
    --danger: #e0715c;
    --chip: #262d2b;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", "Heebo", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { margin: 0; }
.muted { color: var(--muted); }

.screen { min-height: 100dvh; }
.center { display: grid; place-items: center; padding: 24px 16px; }
main {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(96px + env(safe-area-inset-bottom));
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.narrow { width: 100%; max-width: 380px; text-align: center; display: grid; gap: 12px; }
.logo {
  width: 64px; height: 64px; margin: 0 auto; border-radius: 20px;
  display: grid; place-items: center;
  background: var(--accent); color: var(--accent-text); font-size: 34px; font-weight: 700;
}
#login-form { display: grid; gap: 12px; }
#login-form input {
  padding: 14px; border-radius: 14px; border: 1px solid var(--line); background: var(--bg); text-align: center; font-size: 18px;
}
.error { color: var(--danger); margin: 0; }
.who-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 8px; }

.btn {
  border: 0; border-radius: 14px; padding: 12px 16px; background: var(--chip); font-weight: 600;
}
.btn.big { padding: 16px; font-size: 18px; width: 100%; }
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.primary:disabled { opacity: .6; }
.btn.danger { background: transparent; color: var(--danger); }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.who { background: var(--accent-soft); font-size: 22px; padding: 24px 12px; }

.view-title { font-size: 22px; margin: 4px 4px 12px; }
.section-title { font-size: 15px; color: var(--muted); font-weight: 600; margin: 24px 4px 8px; }
.section-title.flush { margin: 0 0 12px; }

/* טופס */
.expense-form { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
.amount-field {
  display: flex; align-items: center; gap: 8px;
  border-bottom: 2px solid var(--line); padding: 4px 4px 8px;
}
.amount-field:focus-within { border-color: var(--accent); }
.currency { font-size: 28px; color: var(--muted); }
.amount-field input {
  flex: 1; width: 100%; min-width: 0; border: 0; background: transparent; outline: none;
  font-size: 40px; font-weight: 700; direction: ltr; text-align: right;
}
.note {
  padding: 14px; border-radius: 14px; border: 1px solid var(--line); background: var(--bg); font-size: 17px; outline: none;
}
.note:focus { border-color: var(--accent); }
.cat-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.cat-chip {
  border: 0; border-radius: 999px; padding: 8px 14px; background: var(--accent-soft); font-weight: 600;
}
.chev { font-size: 12px; opacity: .7; }
.cat-hint { font-size: 13px; }
.cat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.cat-option {
  display: grid; justify-items: center; gap: 2px; padding: 10px 4px; border-radius: 14px;
  border: 1px solid var(--line); background: var(--card); font-size: 13px;
}
.cat-option span { font-size: 22px; }
.cat-option.on { border-color: var(--accent); background: var(--accent-soft); }

.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--chip); border-radius: 14px; padding: 4px; gap: 4px; }
.seg button { border: 0; background: transparent; border-radius: 11px; padding: 10px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--text); box-shadow: var(--shadow); }

.date-row { display: flex; gap: 8px; align-items: center; }
.chip { border: 0; border-radius: 999px; padding: 8px 14px; background: var(--chip); font-weight: 600; color: var(--muted); }
.chip.on { background: var(--accent-soft); color: var(--text); }
.date-row input {
  flex: 1; min-width: 0; padding: 8px 10px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg);
}
.form-actions { display: flex; justify-content: space-between; }

/* רשימות */
.expense-list { list-style: none; margin: 0; padding: 0; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.expense {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-top: 1px solid var(--line); cursor: pointer;
}
.expense:first-child { border-top: 0; }
.expense:active { background: var(--chip); }
.exp-icon { font-size: 22px; width: 32px; text-align: center; }
.exp-main { flex: 1; min-width: 0; display: grid; }
.exp-note { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.exp-meta { font-size: 13px; color: var(--muted); }
.exp-amount { font-weight: 700; white-space: nowrap; }
.empty { text-align: center; color: var(--muted); padding: 20px; list-style: none; }
.list-total { padding: 12px 14px; border-top: 1px solid var(--line); text-align: left; color: var(--muted); }
.list-total b { color: var(--text); }

.month-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.month-label { font-size: 20px; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--card); box-shadow: var(--shadow); font-size: 24px; line-height: 1;
}
.month-total { text-align: center; color: var(--muted); margin: 0 0 8px; }
.month-total b { color: var(--text); }
.day-title { display: flex; justify-content: space-between; font-size: 14px; color: var(--muted); font-weight: 600; margin: 18px 6px 6px; }

/* סיכום */
#summary { display: grid; gap: 12px; }
.total-card { display: grid; justify-items: center; gap: 2px; padding: 22px 16px; }
.total { font-size: 38px; font-weight: 800; color: var(--accent); }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.mini { display: grid; gap: 2px; }
.mini b { font-size: 20px; }
.bar-row { margin-bottom: 12px; }
.bar-row:last-child { margin-bottom: 0; }
.bar-head { display: flex; justify-content: space-between; gap: 8px; font-size: 15px; margin-bottom: 4px; }
.bar { height: 8px; background: var(--chip); border-radius: 99px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 99px; }

/* תפריט תחתון */
.tabbar {
  position: fixed; inset: auto 0 0 0; display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--card); border-top: 1px solid var(--line);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
}
.tab { border: 0; background: transparent; display: grid; justify-items: center; gap: 0; padding: 6px; font-size: 13px; color: var(--muted); font-weight: 600; }
.tab-icon { font-size: 22px; line-height: 1.2; }
.tab.active { color: var(--accent); }

/* עריכה */
dialog {
  border: 0; border-radius: var(--radius); padding: 16px; width: min(520px, calc(100% - 24px));
  background: var(--card); color: var(--text); box-shadow: 0 10px 40px rgba(0, 0, 0, .25);
}
dialog::backdrop { background: rgba(10, 15, 13, .45); }

#toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: .25s; max-width: calc(100% - 32px); text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
