:root {
  --bg: #f5f7fb;
  --card: #ffffff;
  --text: #1c2333;
  --muted: #6b7489;
  --line: #e3e7ef;
  --primary: #2f6fed;
  --primary-soft: #e6eeff;
  --ok: #1f9d55;
  --ok-soft: #e3f6ea;
  --warn: #c77700;
  --warn-soft: #fff3dc;
  --danger: #d33a3a;
  --danger-soft: #fde8e8;
  /* Why someone can't walk (weekly grid) and "rather not". */
  --study: #2f6fed; --study-soft: #dfe9ff;
  --social: #9b3fd6; --social-soft: #f1e3fb;
  --work: #c25b00; --work-soft: #ffe7d1;
  --avoid: #7a6a1f; --avoid-soft: #f4efcf;
  /* Task topics: one hue each, so a list scans by color (chips in rows, the picker in the form). */
  --topic-chore: #0f8f8a; --topic-chore-soft: #dcf5f3;
  --topic-shopping: #d9480f; --topic-shopping-soft: #ffe3d3;
  --topic-reading: #7c3aed; --topic-reading-soft: #ede4ff;
  --topic-learning: #2f6fed; --topic-learning-soft: #dfe9ff;
  --topic-call: #1f9d55; --topic-call-soft: #e3f6ea;
  --topic-build: #8a5a1b; --topic-build-soft: #f5e9d6;
  --topic-develop: #3b4d8f; --topic-develop-soft: #e3e7f8;
  --topic-plan: #b8287a; --topic-plan-soft: #fbe3f0;
  --topic-other: #5b6478; --topic-other-soft: #e9ecf2;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 30, 60, .06), 0 2px 8px rgba(20, 30, 60, .05);
  --nav-h: 64px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11151d; --card: #1a202b; --text: #e8ecf4; --muted: #98a2b8; --line: #2a3242;
    --primary: #6e9bff; --primary-soft: #1f2b45; --ok: #4cc983; --ok-soft: #173326;
    --warn: #f0b04a; --warn-soft: #3a2e17; --danger: #ff7272; --danger-soft: #3d1e22;
    --study: #8fb2ff; --study-soft: #1e2b4a; --social: #d29bff; --social-soft: #33204a;
    --work: #ffa45c; --work-soft: #3d2614; --avoid: #e2d07a; --avoid-soft: #35301a;
    --topic-chore: #4fd1c5; --topic-chore-soft: #13332f; --topic-shopping: #ff9b6a; --topic-shopping-soft: #3d2214;
    --topic-reading: #c4a6ff; --topic-reading-soft: #2c1f4a; --topic-learning: #8fb2ff; --topic-learning-soft: #1e2b4a;
    --topic-call: #4cc983; --topic-call-soft: #173326; --topic-build: #e0b074; --topic-build-soft: #3a2b17;
    --topic-develop: #a9b6f0; --topic-develop-soft: #242b47; --topic-plan: #f295c9; --topic-plan-soft: #3e1c30;
    --topic-other: #b0b8c8; --topic-other-soft: #2a3242;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", "Rubik", "Assistant", Arial, sans-serif;
  background: var(--bg); color: var(--text); font-size: 16px; line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.2; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: .25rem 0 .75rem; }
a { color: var(--primary); }

.splash { display: grid; place-items: center; min-height: 100vh; font-size: 4rem; }

.wrap { max-width: 640px; margin: 0 auto; padding: 16px 16px calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)); }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.topbar .sub { color: var(--muted); font-size: .9rem; }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; margin-bottom: 12px; border: 1px solid var(--line); }
.card.hero { background: linear-gradient(135deg, var(--primary), #6f4cff); color: #fff; border: 0; }
.card.hero .muted { color: rgba(255,255,255,.8); }
.card.warn { background: var(--warn-soft); border-color: transparent; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap-row { flex-wrap: wrap; }
.spacer { flex: 1; }
.stack > * + * { margin-top: 8px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.btn {
  border: 0; border-radius: 12px; padding: 10px 14px; background: var(--primary); color: #fff; font-weight: 600;
  cursor: pointer; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn:disabled { opacity: .5; cursor: default; }
.btn.secondary { background: var(--primary-soft); color: var(--primary); }
.btn.ok { background: var(--ok); }
.btn.danger { background: var(--danger-soft); color: var(--danger); }
.btn.ghost { background: transparent; color: var(--primary); padding: 8px; min-height: 36px; }
.btn.small { min-height: 34px; padding: 6px 10px; font-size: .9rem; border-radius: 10px; }
.btn.block { width: 100%; }
.hero .btn.secondary { background: rgba(255,255,255,.2); color: #fff; }

label.field { display: block; margin-bottom: 10px; }
label.field > span { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=time], input[type=tel], select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); min-height: 44px;
}
textarea { min-height: 70px; resize: vertical; }
.check { display: flex; align-items: center; gap: 8px; margin: 8px 0; }
.check input { width: 20px; height: 20px; }

.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px 3px 8px; border-radius: 999px;
  font-size: .9rem; font-weight: 600; background: var(--primary-soft); white-space: nowrap;
}
.chip .dot, .dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }
.badge { display: inline-block; font-size: .75rem; padding: 2px 8px; border-radius: 999px; background: var(--line); color: var(--muted); font-weight: 600; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.info { background: var(--primary-soft); color: var(--primary); }

/* Walk rows */
.walk { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); cursor: pointer; }
.walk:first-of-type { border-top: 0; }
.walk .time { width: 64px; flex: none; }
.walk .time b { display: block; }
.walk .time small { color: var(--muted); }
.walk .who { flex: 1; display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.walk.mine { background: linear-gradient(to left, var(--primary-soft), transparent 70%); margin: 0 -14px; padding-inline: 14px; }
.walk.done .who .chip { opacity: .7; }
.day-head { display: flex; align-items: baseline; justify-content: space-between; }
.day-head.today h3::after { content: " · היום"; color: var(--primary); }
.weeknav { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }

/* Bottom navigation */
nav.tabs {
  position: fixed; bottom: 0; inset-inline: 0; height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom); background: var(--card); border-top: 1px solid var(--line);
  display: flex; z-index: 10;
}
nav.tabs button {
  flex: 1; border: 0; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; font-size: .75rem; color: var(--muted); cursor: pointer; position: relative;
  padding: 0 2px; min-width: 0; white-space: nowrap; /* six tabs for parents: ~65px each at 390px */
}
nav.tabs button .ico { font-size: 1.35rem; line-height: 1; }
nav.tabs button.active { color: var(--primary); font-weight: 700; }
nav.tabs .count { position: absolute; top: 6px; inset-inline-start: calc(50% + 6px); background: var(--danger); color: #fff; border-radius: 999px; font-size: .7rem; padding: 0 6px; }

/* Bottom sheet */
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  background: var(--card); width: 100%; max-width: 640px; border-radius: 18px 18px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  max-height: 90vh; overflow: auto; animation: up .18s ease-out;
}
.sheet .grab { width: 40px; height: 4px; border-radius: 4px; background: var(--line); margin: -6px auto 12px; }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }

#toast {
  position: fixed; bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom)); inset-inline: 16px; margin: 0 auto; max-width: 480px;
  background: #1c2333; color: #fff; padding: 12px 14px; border-radius: 12px; z-index: 30; opacity: 0; transform: translateY(10px);
  transition: .2s; pointer-events: none; text-align: center;
}
#toast.show { opacity: 1; transform: none; }
#toast.error { background: var(--danger); }

/* Login */
.people { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; }
.person { border: 1px solid var(--line); background: var(--card); border-radius: var(--radius); padding: 14px 8px; cursor: pointer; text-align: center; font-weight: 600; }
.avatar { width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 1.2rem; margin: 0 auto 6px; }
.pinpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; max-width: 280px; margin: 12px auto; direction: ltr; }
.pinpad button { min-height: 56px; font-size: 1.3rem; border-radius: 14px; border: 1px solid var(--line); background: var(--card); cursor: pointer; }
.pindots { display: flex; justify-content: center; gap: 10px; direction: ltr; margin: 10px 0; }
.pindots span { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--primary); }
.pindots span.on { background: var(--primary); }

/* WhatsApp login code and phone status */
input.otp {
  display: block; max-width: 260px; margin: 12px auto 6px; direction: ltr; text-align: center;
  font-size: 1.8rem; font-weight: 600; letter-spacing: .4em; padding-inline-start: calc(12px + .4em); font-variant-numeric: tabular-nums;
}
input.otp::placeholder { color: var(--line); letter-spacing: .25em; }
.otp-error { min-height: 1.3em; text-align: center; color: var(--danger); font-size: .9rem; margin-bottom: 8px; }
.wa-status { font-size: .85rem; margin-top: 4px; }
.wa-status.ok { color: var(--ok); }
.wa-status.warn { color: var(--warn); }

/* Availability grid */
.avail { width: 100%; border-collapse: collapse; font-size: .85rem; table-layout: fixed; }
.avail th:first-child { width: 64px; }
.avail th, .avail td { padding: 4px 2px; text-align: center; }
.avail td button { width: 100%; min-height: 36px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); cursor: pointer; font-size: 1rem; }
.avail td button.unavailable { background: var(--danger-soft); border-color: transparent; }
.avail td button.preferred { background: var(--ok-soft); border-color: transparent; }
.avail td button.study { background: var(--study-soft); color: var(--study); border-color: transparent; }
.avail td button.social { background: var(--social-soft); color: var(--social); border-color: transparent; }
.avail td button.work { background: var(--work-soft); color: var(--work); border-color: transparent; }
.avail td button.avoid { background: var(--avoid-soft); border-color: transparent; }
/* The mark picker doubles as the color key. */
.segmented.marks { margin-bottom: 6px; }
.segmented.marks button { border: 2px solid transparent; font-size: .85rem; padding: 6px 4px; }
.segmented.marks button.mark-study { background: var(--study-soft); color: var(--study); }
.segmented.marks button.mark-social { background: var(--social-soft); color: var(--social); }
.segmented.marks button.mark-work { background: var(--work-soft); color: var(--work); }
.segmented.marks button.mark-avoid { background: var(--avoid-soft); color: var(--avoid); }
.segmented.marks button.mark-preferred { background: var(--ok-soft); color: var(--ok); }
.segmented.marks button.active { border-color: currentColor; box-shadow: var(--shadow); }

table.stats { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.stats th, table.stats td { padding: 6px 4px; border-bottom: 1px solid var(--line); text-align: start; }
table.stats td.n, table.stats th.n { text-align: center; }

.bar { height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--primary); }

.list-item { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-top: 1px solid var(--line); }
.list-item:first-child { border-top: 0; }

.segmented { display: flex; background: var(--line); border-radius: 12px; padding: 3px; gap: 3px; margin-bottom: 10px; }
.segmented button { flex: 1; border: 0; border-radius: 10px; padding: 8px; background: none; cursor: pointer; font-weight: 600; color: var(--muted); }
.segmented button.active { background: var(--card); color: var(--text); box-shadow: var(--shadow); }

.empty { text-align: center; color: var(--muted); padding: 18px 8px; }
.daypick { display: flex; gap: 4px; flex-wrap: wrap; }
.daypick label { display: inline-flex; align-items: center; gap: 2px; border: 1px solid var(--line); border-radius: 8px; padding: 4px 8px; }

/* Gaps between walks */
.walk .gap { flex-basis: 100%; }
.walk.gap-alert { background: var(--danger-soft); box-shadow: inset 4px 0 0 var(--danger); margin: 0 -14px; padding-inline: 14px; }
.walk .exec { font-size: .8rem; color: var(--muted); flex-basis: 100%; }
.late { color: var(--warn); }

/* Balance & favors */
.pos { color: var(--ok); font-weight: 600; }
.neg { color: var(--danger); font-weight: 600; }

/* Waiting for a parent */
.avail td button.pending { border: 2px dashed var(--warn); }
.avail td button.has-request { box-shadow: inset 0 0 0 2px var(--warn); }
table.stats tr.flag td { background: var(--warn-soft); }
.danger-text { color: var(--danger); }
.warn-text { color: var(--warn); }
.review-grid { border-top: 1px solid var(--line); padding-top: 10px; margin-top: 10px; }
.review-grid h3 { display: flex; align-items: center; gap: 6px; margin: 0 0 8px; }
.date-input { position: relative; }
.date-shown { padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); min-height: 44px; direction: ltr; text-align: right; }
.date-input input[type=date] { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }
@media (pointer: fine) { .date-input input[type=date]:focus { opacity: 1; } }
.date-clear { position: absolute; inset-inline-end: 6px; top: 50%; transform: translateY(-50%); z-index: 1; border: 0; background: none; color: var(--muted); font-size: 1rem; padding: 6px; cursor: pointer; }

/* Tasks */
.chip.topic-chore { background: var(--topic-chore-soft); color: var(--topic-chore); }
.chip.topic-shopping { background: var(--topic-shopping-soft); color: var(--topic-shopping); }
.chip.topic-reading { background: var(--topic-reading-soft); color: var(--topic-reading); }
.chip.topic-learning { background: var(--topic-learning-soft); color: var(--topic-learning); }
.chip.topic-call { background: var(--topic-call-soft); color: var(--topic-call); }
.chip.topic-build { background: var(--topic-build-soft); color: var(--topic-build); }
.chip.topic-develop { background: var(--topic-develop-soft); color: var(--topic-develop); }
.chip.topic-plan { background: var(--topic-plan-soft); color: var(--topic-plan); }
.chip.topic-other { background: var(--topic-other-soft); color: var(--topic-other); }
/* The topic picker in the form: chips as buttons; the chosen one gets a border in its own color (like .segmented.marks). */
.topics { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.topics .chip { border: 2px solid transparent; cursor: pointer; min-height: 34px; }
.topics .chip.active { border-color: currentColor; box-shadow: var(--shadow); }
.task-title { font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.task-title.done { text-decoration: line-through; color: var(--muted); font-weight: 500; }
.list-item.task.closed { opacity: .75; }
.btn.ghost.danger-text { color: var(--danger); }
.list-item.task .bar { margin-top: 2px; }

/* Staging marker (server APP_ENV=staging). */
.envtag { position: fixed; top: env(safe-area-inset-top, 0); inset-inline-end: 0; z-index: 20; background: var(--warn); color: #fff; font: 700 .7rem system-ui, sans-serif; padding: 2px 8px; border-end-start-radius: 8px; pointer-events: none; }
