/* מצב יום הוא ברירת המחדל תמיד, בלי קשר להגדרת המערכת.
   מצב לילה נדלק רק כשהמשתמש בוחר בו, וזה נשמר במכשיר. */
:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-text: #ffffff;
  --primary-soft: #dbeafe;
  --shared: #7c3aed;
  --mine: #0891b2;
  --theirs: #ea580c;
  --good: #16a34a;
  --bad: #dc2626;
  --warn: #d97706;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 8px 24px rgba(15, 23, 42, .06);
  --tabbar-h: 62px;
}

html[data-theme="dark"] {
  --bg: #0b1120;
  --surface: #111827;
  --surface-2: #0f172a;
  --border: #1f2937;
  --text: #e5e7eb;
  --muted: #94a3b8;
  --primary: #3b82f6;
  --primary-soft: #1e3a8a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Noto Sans Hebrew", Rubik, Arial, sans-serif;
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

.hidden { display: none !important; }

.screen { min-height: 100dvh; }
.center { display: flex; align-items: center; justify-content: center; padding: 20px; }

.spinner {
  width: 34px; height: 34px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ----------------------------- כרטיסים ----------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin: 0 0 14px;
}
.card h2 { font-size: 16px; margin: 0 0 10px; }
.auth-card { width: 100%; max-width: 380px; }
.auth-card h1 { font-size: 22px; margin: 0 0 6px; }

hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.hint { font-size: 13px; color: var(--muted); background: var(--surface-2); padding: 8px 10px; border-radius: 8px; }
.error { color: var(--bad); font-size: 14px; min-height: 18px; margin: 4px 0; }

/* ----------------------------- טפסים ----------------------------- */
label { display: block; font-size: 13px; color: var(--muted); margin: 0 0 12px; }
input, select, textarea {
  width: 100%;
  margin-top: 5px;
  padding: 11px 12px;
  font: inherit;
  font-size: 15px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  outline: none;
}
input:focus, select:focus { border-color: var(--primary); }
.checkbox { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.checkbox input { width: auto; margin: 0; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 11px 16px;
  font: inherit; font-size: 15px; font-weight: 600;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); width: 100%; }
.btn.ghost { background: transparent; }
.btn.wide { width: 100%; }
.btn.tiny { padding: 7px 12px; font-size: 13px; }
.btn.danger { color: var(--bad); border-color: var(--bad); background: transparent; }
.btn.shared { background: var(--shared); border-color: var(--shared); color: #fff; }
.btn.mine { background: var(--mine); border-color: var(--mine); color: #fff; }
.btn.theirs { background: var(--theirs); border-color: var(--theirs); color: #fff; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* בחירת מי נכנס, במסך ההתחברות.
   הצבעים כאן מפורשים ולא מחושבים, כדי שגם WebView ישן יראה בבירור מה נבחר. */
.who-pick { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 0 0 14px; }
.who {
  display: flex; align-items: center; justify-content: center; gap: 7px;
  min-height: 58px;
  padding: 14px 10px;
  font: inherit; font-size: 17px; font-weight: 600;
  color: var(--text);
  background: var(--surface-2);
  border: 2px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.who .mark {
  flex: 0 0 auto;
  width: 20px; height: 20px;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; line-height: 1;
  color: transparent;
  border: 2px solid var(--border);
  border-radius: 50%;
}
.who.active {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-text);
  box-shadow: 0 4px 14px rgba(37, 99, 235, .3);
}
.who.active .mark { color: var(--primary); background: #fff; border-color: #fff; }
.who:active { transform: scale(.98); }

.row-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
.row-form input, .row-form select { width: auto; flex: 1 1 120px; margin-top: 0; }
.row-form .arrow { color: var(--muted); }

/* ----------------------------- מבנה ----------------------------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px calc(12px);
  padding-top: max(12px, env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-title { font-size: 17px; font-weight: 700; }
.topbar-actions { display: flex; gap: 6px; }
.icon-btn {
  width: 38px; height: 38px;
  font-size: 18px; line-height: 1;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
}
.icon-btn.spinning { animation: spin 1s linear infinite; }

/* מתג יום/לילה על מסכי הכניסה - פינה שמאלית עליונה, כמו באפליקציה עצמה */
.theme-fab {
  position: fixed; z-index: 40;
  left: 14px; top: max(14px, env(safe-area-inset-top));
  width: 40px; height: 40px;
  font-size: 19px; line-height: 1;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 50%;
  box-shadow: var(--shadow);
  cursor: pointer;
}

#main { padding: 14px 14px calc(var(--tabbar-h) + 20px); max-width: 760px; margin: 0 auto; }

.tabbar {
  position: fixed; bottom: 0; inset-inline: 0; z-index: 30;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  position: relative;
  padding: 9px 0;
  font: inherit; font-size: 11px;
  color: var(--muted);
  background: none; border: none;
  cursor: pointer;
}
.tab span { font-size: 19px; line-height: 1.1; }
.tab.active { color: var(--primary); }
.tab .dot {
  position: absolute; top: 6px; inset-inline-end: 24%;
  width: 8px; height: 8px;
  background: var(--bad);
  border-radius: 50%;
}

/* ----------------------------- מאזן ----------------------------- */
.balance-card { text-align: center; padding: 22px 18px; }
.balance-label { font-size: 14px; color: var(--muted); }
.balance-amount { font-size: 34px; font-weight: 800; margin: 6px 0; letter-spacing: -.5px; }
.balance-amount.owed-to-me { color: var(--good); }
.balance-amount.i-owe { color: var(--bad); }
.balance-amount.even { color: var(--muted); }
.balance-sub { font-size: 13px; color: var(--muted); }
.balance-breakdown {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
  margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border);
}
.breakdown-item { text-align: center; }
.breakdown-item b { display: block; font-size: 14px; }
.breakdown-item small { color: var(--muted); font-size: 11px; }

.alert {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 13px 15px; margin-bottom: 14px;
  background: color-mix(in srgb, var(--warn) 14%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--warn) 40%, var(--border));
  border-radius: var(--radius);
  font-size: 14px;
}

/* ----------------------------- הכנסות ----------------------------- */
.filters { margin-bottom: 12px; }
.chips { display: flex; gap: 7px; overflow-x: auto; padding-bottom: 8px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 7px 13px;
  font: inherit; font-size: 13px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  white-space: nowrap;
  cursor: pointer;
}
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.chip .badge {
  min-width: 19px; padding: 1px 5px;
  font-size: 11px; font-weight: 700; text-align: center;
  background: var(--bad); color: #fff;
  border-radius: 999px;
}
.chip.active .badge { background: rgba(255, 255, 255, .3); }
.filter-row { display: flex; gap: 8px; }
.filter-row input { flex: 2; margin-top: 0; }
.filter-row select { flex: 1; margin-top: 0; }

.income {
  display: flex; gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-inline-start: 4px solid var(--border);
  border-radius: 12px;
  padding: 13px 14px;
  margin-bottom: 9px;
}
.income.selected { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 8%, var(--surface)); }
.income.split-shared  { border-inline-start-color: var(--shared); }
.income.split-me      { border-inline-start-color: var(--mine); }
.income.split-partner { border-inline-start-color: var(--theirs); }
.income.unclassified  { border-inline-start-color: var(--warn); }
.income-main { flex: 1; min-width: 0; }
.income-top { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.income-amount { font-size: 18px; font-weight: 700; }
.income-date { font-size: 12px; color: var(--muted); white-space: nowrap; }
.income-who { font-size: 14px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.income-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 7px; font-size: 11px; color: var(--muted); }
.pill { padding: 2px 8px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; }
.pill.shared  { color: var(--shared); border-color: color-mix(in srgb, var(--shared) 40%, var(--border)); }
.pill.me      { color: var(--mine);   border-color: color-mix(in srgb, var(--mine) 40%, var(--border)); }
.pill.partner { color: var(--theirs); border-color: color-mix(in srgb, var(--theirs) 40%, var(--border)); }
.pill.pending { color: var(--warn);   border-color: color-mix(in srgb, var(--warn) 40%, var(--border)); }
.income-actions { display: flex; gap: 6px; margin-top: 10px; }
.income-actions .btn { flex: 1; }
.income-note { margin-top: 8px; font-size: 13px; }
.income-note input { margin-top: 0; padding: 8px 10px; font-size: 13px; }
.select-box {
  flex: 0 0 auto; width: 22px; height: 22px; margin-top: 3px;
  border: 2px solid var(--border); border-radius: 6px;
  background: var(--surface-2);
  cursor: pointer;
}
.income.selected .select-box { background: var(--primary); border-color: var(--primary); }

.bulk-bar {
  position: sticky; top: 62px; z-index: 15;
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  padding: 10px 13px; margin-bottom: 10px;
  background: var(--surface);
  border: 1px solid var(--primary);
  border-radius: 12px;
  font-size: 14px;
  box-shadow: var(--shadow);
}
.bulk-actions { display: flex; gap: 6px; }

/* ----------------------------- חשבונות ----------------------------- */
.account-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.account-title { font-size: 16px; font-weight: 700; }
.webhook-url {
  display: flex; gap: 6px; align-items: center;
  margin-top: 8px; padding: 9px 11px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px;
  font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 11px;
  word-break: break-all;
}
.webhook-url button { flex: 0 0 auto; }
.status-line { font-size: 12px; color: var(--muted); margin-top: 8px; }
.status-line.bad { color: var(--bad); }

/* ----------------------------- טבלאות ----------------------------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 8px 6px; text-align: start; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: 12px; }

.list-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 0; border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.list-row:last-child { border-bottom: none; }

.empty { padding: 26px 12px; text-align: center; color: var(--muted); font-size: 14px; }

/* ----------------------------- טוסט ----------------------------- */
.toast {
  position: fixed; bottom: calc(var(--tabbar-h) + 16px); inset-inline: 16px; z-index: 60;
  max-width: 420px; margin: 0 auto;
  padding: 13px 16px;
  background: var(--text); color: var(--bg);
  border-radius: 11px;
  font-size: 14px; text-align: center;
  box-shadow: var(--shadow);
}
.toast.bad { background: var(--bad); color: #fff; }

@media (min-width: 700px) {
  .two-col { grid-template-columns: 1fr 1fr; }
}
