:root {
  --navy: #1d2840;
  --navy-2: #2c3a5c;
  --gold: #a8844d;
  --gold-soft: #f3ead9;
  --bg: #f4f1ea;
  --card: #ffffff;
  --text: #1f2430;
  --muted: #6b7180;
  --line: #e3ddd0;
  --danger: #b4382f;
  --danger-soft: #fbeceb;
  --ok: #2f7a4f;
  --ok-soft: #e7f4ec;
  --warn: #9a6b12;
  --warn-soft: #fbf2df;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 25, 40, 0.06), 0 6px 20px rgba(20, 25, 40, 0.06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Heebo', 'Arial Hebrew', Arial, sans-serif;
  font-size: 17px;
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
}

body { min-height: 100vh; min-height: 100dvh; }

a { color: var(--navy-2); }

button, input, textarea, select { font: inherit; color: inherit; }

.wrap { max-width: 760px; margin: 0 auto; padding: 0 16px 48px; }

/* ---------- top bar ---------- */
.topbar {
  background: var(--navy);
  color: #fff;
  /* באפליקציה ממסך הבית התוכן מתחיל מתחת לשעון — משאירים לו מקום */
  padding: calc(14px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right)) 14px calc(16px + env(safe-area-inset-left));
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
}
.topbar-inner { max-width: 760px; margin: 0 auto; display: flex; align-items: center; gap: 12px; }
.brand { display: flex; flex-direction: column; line-height: 1.2; flex: 1; min-width: 0; }
.brand b { font-size: 19px; font-weight: 700; letter-spacing: 0.2px; }
.brand small { color: #c9b48d; font-size: 13px; }
.topbar .icon-btn { color: #fff; border-color: rgba(255, 255, 255, 0.25); background: transparent; }

/* ---------- cards & headings ---------- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-top: 16px;
}
h1 { font-size: 24px; margin: 22px 0 4px; color: var(--navy); }
h2 { font-size: 19px; margin: 0 0 12px; color: var(--navy); }
.sub { color: var(--muted); margin: 0; font-size: 15px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: 12px;
  padding: 13px 20px;
  font-weight: 600;
  font-size: 17px;
  cursor: pointer;
  text-decoration: none;
  background: var(--navy);
  color: #fff;
  transition: transform 0.05s ease, background 0.15s ease;
  min-height: 48px;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.gold { background: var(--gold); }
.btn.light { background: var(--gold-soft); color: var(--navy); }
.btn.ghost { background: transparent; color: var(--navy); border: 1.5px solid var(--line); }
.btn.danger { background: transparent; color: var(--danger); border: 1.5px solid #ecc9c5; }
.btn.whatsapp { background: #1f9d55; }
.btn.block { width: 100%; }
.btn.sm { padding: 8px 14px; min-height: 38px; font-size: 15px; border-radius: 10px; }
.btn svg { width: 20px; height: 20px; flex: none; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; }
.btn-row .btn { flex: 1 1 auto; }

.icon-btn {
  border: 1.5px solid var(--line);
  background: #fff;
  border-radius: 10px;
  width: 42px;
  height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex: none;
}
.icon-btn svg { width: 20px; height: 20px; }

/* ---------- forms ---------- */
.field { margin-bottom: 16px; }
.field label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 16px; }
.field .hint { color: var(--muted); font-size: 14px; margin-top: 4px; }
.field .req { color: var(--danger); }
.input, textarea.input {
  width: 100%;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  background: #fff;
  font-size: 17px;
  min-height: 48px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
textarea.input { min-height: 96px; resize: vertical; }
.input:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(168, 132, 77, 0.18); }
.input.ltr { direction: ltr; text-align: right; }
.field.has-error .input, .field.has-error .sig-box { border-color: var(--danger); }
.field .err { color: var(--danger); font-size: 14px; margin-top: 5px; display: none; }
.field.has-error .err { display: block; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
@media (max-width: 560px) { .grid-2 { grid-template-columns: 1fr; } }

.check {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 14px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  cursor: pointer;
  background: #fffdf8;
}
.check input { width: 22px; height: 22px; margin: 2px 0 0; accent-color: var(--navy); flex: none; }

/* ---------- terms (on the signing page) ---------- */
.terms ol { padding: 0 22px 0 0; margin: 0; }
.terms > ol > li { margin-bottom: 10px; }
.terms ol ol { list-style: none; padding-right: 4px; margin-top: 6px; }
.terms ol ol li { margin-bottom: 4px; }
.terms .n { font-weight: 700; margin-left: 6px; color: var(--navy); }
.special {
  background: var(--warn-soft);
  border-right: 4px solid var(--gold);
  padding: 12px 14px;
  border-radius: 8px;
  white-space: pre-wrap;
  margin-top: 12px;
}
.prop-list { margin: 0; padding: 0 20px 0 0; }
.prop-list li { margin-bottom: 4px; }

/* ---------- signature pad ---------- */
.sig-box {
  position: relative;
  border: 2px dashed #cbbf9f;
  border-radius: 12px;
  background: #fffdf8;
  height: 200px;
  touch-action: none;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}
.sig-box canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }
.sig-box .sig-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #b3a888;
  pointer-events: none;
  font-size: 18px;
}
.sig-box .sig-line { position: absolute; left: 24px; right: 24px; bottom: 44px; border-bottom: 1px solid #d9cfb5; pointer-events: none; }
.sig-box.signed .sig-placeholder { display: none; }
.sig-actions { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; color: var(--muted); font-size: 14px; }

/* ---------- alerts / states ---------- */
.alert { padding: 14px 16px; border-radius: 12px; margin-top: 16px; }
.alert.error { background: var(--danger-soft); color: var(--danger); }
.alert.ok { background: var(--ok-soft); color: var(--ok); }
.state { text-align: center; padding: 48px 20px; }
.state .big-icon { width: 72px; height: 72px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; margin-bottom: 12px; }
.state .big-icon svg { width: 38px; height: 38px; }
.state .big-icon.ok { background: var(--ok-soft); color: var(--ok); }
.state .big-icon.err { background: var(--danger-soft); color: var(--danger); }
.spinner { width: 36px; height: 36px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--gold); animation: spin 0.8s linear infinite; margin: 60px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- admin list ---------- */
/* החיפוש והלשוניות נצמדים מתחת לכותרת, עם רקע מלא — כך הם אף פעם לא נחתכים */
.list-head {
  position: sticky;
  top: var(--topbar-h, 0px);
  z-index: 15;
  background: var(--bg);
  margin: 0 -16px;
  padding: 16px 16px 4px;
}
.toolbar { display: flex; gap: 10px; align-items: center; }
.toolbar .input { flex: 1; }
.tabs { display: flex; gap: 6px; margin-top: 14px; background: #ebe5d8; padding: 4px; border-radius: 12px; }
.tabs button {
  flex: 1;
  border: 0;
  background: transparent;
  padding: 9px 8px;
  border-radius: 9px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  font-size: 15px;
}
.tabs button.active { background: #fff; color: var(--navy); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08); }
.tabs .count { font-weight: 500; opacity: 0.8; }

.list { margin-top: 12px; display: flex; flex-direction: column; gap: 10px; }
.row {
  display: flex;
  align-items: center;
  gap: 14px;
  background: #fff;
  border-radius: 12px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
  cursor: pointer;
  text-align: right;
  border: 0;
  width: 100%;
}
.row:active { background: #fbf8f2; }
.row.flash { animation: flash 3s ease-out; }
@keyframes flash {
  0%, 40% { background: #dff0e5; box-shadow: 0 0 0 2px var(--ok); }
  100% { background: #fff; box-shadow: var(--shadow); }
}
.live-note { display: flex; align-items: center; gap: 8px; margin-top: 6px; font-size: 14px; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); animation: pulse 1.6s ease-in-out infinite; flex: none; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }
.avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--gold-soft);
  color: var(--navy);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 18px;
  flex: none;
}
.avatar.pending { background: #eef0f4; color: var(--muted); }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { color: var(--muted); font-size: 14px; line-height: 1.45; }
.row-line { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { font-size: 13px; padding: 3px 10px; border-radius: 99px; font-weight: 600; white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.wait { background: var(--warn-soft); color: var(--warn); }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; }

.fab {
  position: fixed;
  bottom: max(20px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  box-shadow: 0 8px 24px rgba(29, 40, 64, 0.35);
  z-index: 15;
  padding: 14px 28px;
  border-radius: 99px;
}
.fab:active { transform: translateX(-50%) scale(0.98); }

/* ---------- details ---------- */
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 10px 14px; }
.kv dt { color: var(--muted); font-size: 15px; }
.kv dd { margin: 0; font-weight: 500; word-break: break-word; }
.sig-preview { background: #fffdf8; border: 1px solid var(--line); border-radius: 10px; padding: 8px; text-align: center; }
.sig-preview img { max-width: 100%; max-height: 140px; }
.meta { color: var(--muted); font-size: 13px; word-break: break-all; }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--navy); text-decoration: none; font-weight: 600; margin-top: 18px; background: none; border: 0; cursor: pointer; padding: 6px 0; }
.back svg { width: 18px; height: 18px; }

/* ---------- pill buttons (בחירת אחוז) ---------- */
.pills { display: flex; gap: 8px; }
.pill {
  flex: 1;
  min-height: 48px;
  border: 1.5px solid var(--line);
  background: #fff;
  color: var(--navy);
  border-radius: 99px;
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.pill:active { transform: scale(0.97); }
.pill.on { background: var(--navy); border-color: var(--navy); color: #fff; box-shadow: 0 2px 8px rgba(29, 40, 64, 0.25); }

/* ---------- dialog ---------- */
/* הרקע המעומעם תמיד מגיע עד תחתית המסך, כך שדבר מהדף לא מציץ מתחת לחלון */
.dialog-bg {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 20, 35, 0.45);
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-top: calc(env(safe-area-inset-top) + 10px);
  overscroll-behavior: contain;
}
@media (min-width: 640px) { .dialog-bg { align-items: center; padding: 20px; } }
.dialog {
  background: #fff;
  width: 100%;
  max-width: 560px;
  max-height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  border-radius: 18px 18px 0 0;
  /* --kb = גובה המקלדת. החלון הלבן ממשיך עד תחתית המסך (גם מאחורי המקלדת),
     והתוכן עצמו נגמר מעליה. אם המקלדת נעלמת — רואים עוד לבן, לא את הדף */
  padding: 0 20px calc(22px + var(--kb, 0px) + env(safe-area-inset-bottom));
}
@media (min-width: 640px) { .dialog { border-radius: 18px; } }
body.dialog-open .fab { display: none; }
/* הכותרת וכפתור הסגירה נשארים תמיד גלויים בראש החלון */
.dialog-head {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 0 12px;
  margin-bottom: 4px;
}
.dialog-head h2 { margin: 0; }
body.dialog-open { overflow: hidden; }
.link-box {
  direction: ltr;
  text-align: left;
  background: var(--gold-soft);
  border-radius: 10px;
  padding: 12px;
  font-size: 15px;
  word-break: break-all;
  user-select: all;
  margin-bottom: 14px;
}

.toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--navy);
  color: #fff;
  padding: 10px 18px;
  border-radius: 99px;
  z-index: 80;
  font-size: 15px;
  box-shadow: var(--shadow);
}

/* ---------- login ---------- */
.login-card { max-width: 400px; margin: 10vh auto 0; }
.login-card .logo { text-align: center; margin-bottom: 18px; }
.login-card .logo b { display: block; font-size: 22px; color: var(--navy); }
.login-card .logo small { color: var(--gold); }

.hidden { display: none !important; }

/* כפתור "שימוש במיקום הנוכחי" מתחת לשדה הכתובת */
.loc-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  padding: 8px 12px;
  min-height: 40px;
  border: 1.5px solid var(--line);
  border-radius: 99px;
  background: #fff;
  color: var(--navy);
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
}
.loc-btn svg { width: 18px; height: 18px; color: var(--gold); flex: none; }
.loc-btn:disabled { opacity: 0.6; }
.loc-btn:active { background: var(--gold-soft); }
.loc-note { font-size: 14px; margin-top: 6px; color: var(--ok); }
.loc-note.error { color: var(--danger); }

/* כפתור בזמן עבודה: נשאר בצבע מלא, עם עיגול מסתובב */
.btn-spinner {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2.5px solid currentColor;
  border-right-color: transparent;
  display: inline-block;
  flex: none;
  animation: spin 0.7s linear infinite;
}
.btn.is-busy:disabled,
.loc-btn.is-busy:disabled { opacity: 1; cursor: progress; }
.loc-btn.is-busy { background: var(--gold-soft); border-color: var(--gold); }
.loc-btn.is-busy .btn-spinner { color: var(--gold); }
