@import url('https://fonts.googleapis.com/css2?family=Heebo:wght@400;500;700&display=swap');

:root {
  --bg: #f4f5f8;
  --card: #fff;
  --text: #1c2030;
  --muted: #6b7185;
  --border: #e2e5ec;
  --primary: #3056d3;
  --primary-dark: #2442a8;
  --primary-soft: #e8edfc;
  --success: #1f9d61;
  --success-soft: #e3f6ec;
  --warn: #c27c0e;
  --warn-soft: #fdf3e1;
  --danger: #d33a3a;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(20, 25, 50, .08), 0 4px 16px rgba(20, 25, 50, .05);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: 'Heebo', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  direction: rtl;
  font-size: 15px;
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; }
.hidden { display: none !important; }

/* כפתורים */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: var(--card); color: var(--text);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; text-decoration: none;
  font-size: 14px; font-weight: 500; white-space: nowrap; transition: background .15s, border-color .15s;
}
.btn:hover { background: #f0f2f7; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.success { background: var(--success); border-color: var(--success); color: #fff; }
.btn.danger { color: var(--danger); }
.btn.big { padding: 13px 22px; font-size: 16px; border-radius: 10px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.active { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }

/* פריסה */
.topbar {
  position: sticky; top: 0; z-index: 50; background: var(--card); border-bottom: 1px solid var(--border);
  padding: 10px 16px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.topbar h1 { font-size: 18px; margin: 0; flex: 1; min-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.container { max-width: 960px; margin: 0 auto; padding: 20px 16px 80px; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 18px; }
.card h2 { margin: 0 0 14px; font-size: 17px; }
.muted { color: var(--muted); }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.row > label { flex: 1; min-width: 180px; }
label.field-label { display: block; font-size: 13px; color: var(--muted); }
label.field-label input { margin-top: 4px; }
input[type=text], input[type=password], input[type=date], input[type=email], input[type=tel], textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: #fff; color: var(--text);
}
input:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }

/* מסכי מסמך */
.pages { max-width: 900px; margin: 0 auto; padding: 16px; }
.page {
  position: relative; background: #fff; box-shadow: var(--shadow); width: 100%; user-select: none; touch-action: pan-y;
}
.page canvas { width: 100%; height: 100%; display: block; }
.page-num { text-align: center; color: var(--muted); font-size: 12px; margin: 6px 0 18px; }

/* שדות */
.fld {
  position: absolute; border: 2px solid var(--primary); background: rgba(48, 86, 211, .12); border-radius: 4px;
  display: flex; align-items: center; justify-content: center; font-size: 12px; color: var(--primary);
  overflow: hidden; cursor: pointer; direction: rtl;
}
.fld .fld-label { pointer-events: none; padding: 0 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
/* גודל הכיתוב בתוך השדה נקבע לפי גובה השדה, כך שבטלפון (שדות קטנים) הוא נכנס בשלמותו */
.fld { container-type: size; gap: 1px; }
.fld:not(.filled):not(.prefilled):not(.has-value) { overflow: visible; }
.fld .fld-label { font-size: clamp(7.5px, 75cqh, 13px); line-height: 1; max-width: 100%; }
.fld .req { font-size: clamp(7.5px, 75cqh, 13px); line-height: 1; }
@media (max-width: 640px) {
  .fld { border-width: 1px; border-radius: 3px; }
  .fld .fld-label { padding: 0 2px; }
}
.fld.signature { border-color: #b8860b; background: rgba(255, 196, 0, .16); color: #8a6400; }
.fld.selected { outline: 3px solid rgba(48, 86, 211, .35); }
.fld .handle {
  position: absolute; width: 14px; height: 14px; left: -2px; bottom: -2px; background: var(--primary);
  cursor: nesw-resize; border-radius: 3px 0 3px 0;
}
.fld .req { color: var(--danger); font-weight: 700; flex-shrink: 0; }
.fld .req:empty { display: none; }
/* תיבת סימון קטנה מדי לכיתוב – מספיק הריבוע עצמו */
.fld.checkbox:not(.mine) .fld-label, .fld.checkbox:not(.mine) .req { display: none; }
.fld.filled { background: transparent; border: 1px dashed rgba(31, 157, 97, .6); }
.fld.filled img { width: 100%; height: 100%; object-fit: fill; pointer-events: none; }
.fld.prefilled { background: transparent; border: 0; cursor: default; }
.fld.prefilled img, .fld.mine img { width: 100%; height: 100%; object-fit: fill; pointer-events: none; }
.fld.mine { border-color: var(--success); background: rgba(31, 157, 97, .08); color: var(--success); }
.fld.mine.has-value { background: transparent; border-style: dashed; }
.fld.mine .fld-label { position: absolute; }
.fld.missing { animation: pulse 1.2s ease-in-out 2; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(211, 58, 58, .35); } }

/* סטטוסים */
.badge { display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: 12px; font-weight: 500; }
.badge.draft { background: #eef0f4; color: var(--muted); }
.badge.pending { background: var(--warn-soft); color: var(--warn); }
.badge.signed { background: var(--success-soft); color: var(--success); }

/* מודאל */
.modal-bg {
  position: fixed; inset: 0; background: rgba(15, 20, 35, .5); z-index: 100;
  display: flex; align-items: flex-end; justify-content: center;
}
.modal {
  background: #fff; width: 100%; max-width: 560px; border-radius: 16px 16px 0 0; padding: 20px 18px 24px;
  animation: up .2s ease-out;
}
@media (min-width: 640px) { .modal-bg { align-items: center; } .modal { border-radius: 16px; } }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.modal h3 { margin: 0 0 12px; font-size: 17px; }
.modal .actions { display: flex; gap: 8px; justify-content: flex-start; margin-top: 16px; }
.sig-pad {
  width: 100%; border: 2px dashed var(--border); border-radius: 10px; background: #fcfcfd; touch-action: none; display: block; cursor: crosshair;
}
.sig-hint { font-size: 12px; color: var(--muted); margin-top: 6px; }

.modal { max-height: 92vh; overflow-y: auto; overflow-x: hidden; }
.linkbox { display: flex; gap: 6px; }
.linkbox input { direction: ltr; text-align: left; }
.share-section { border: 1px solid var(--border); border-radius: 12px; padding: 14px; margin-bottom: 12px; }
.share-head { font-weight: 700; margin-bottom: 10px; }
.share-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 480px) { .share-grid { grid-template-columns: 1fr; } }
.share-chk { display: flex; align-items: center; gap: 6px; font-size: 14px; margin-top: 10px; }
.share-note { font-size: 12.5px; color: var(--muted); background: #f6f7fa; border-radius: 8px; padding: 7px 10px; margin-top: 8px; }
.share-result { margin-top: 10px; font-size: 14px; line-height: 1.7; }
.msg-preview {
  white-space: pre-wrap; font-family: inherit; font-size: 14px; line-height: 1.6; margin: 0;
  background: #e7fbe4; border-radius: 10px; padding: 10px 12px; direction: rtl; word-break: break-word;
}
/* ===== חלון שליחה ללקוח (share.js) ===== */
.sh-title { font-size: 20px !important; margin-bottom: 2px !important; }
.sh-sub { color: var(--muted); font-size: 14px; margin-bottom: 14px; }
.sh-sub b { color: var(--text); font-weight: 500; }
.sh-tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; background: var(--bg); padding: 4px; border-radius: 12px; margin-bottom: 16px; }
.sh-tab { border: 0; background: none; border-radius: 9px; padding: 8px 4px; font: inherit; font-size: 14px; font-weight: 500; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer; }
.sh-tab span { font-size: 20px; line-height: 1; }
.sh-tab.on { background: #fff; color: var(--text); box-shadow: 0 1px 4px rgba(20, 25, 50, .12); }
.sh-tab.on.whatsapp { color: #128c4b; }
.sh-tab.on.email { color: var(--primary); }
.sh-field { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.sh-inp { margin-top: 5px; display: flex; align-items: center; border: 1.5px solid var(--border); border-radius: 10px; background: #fff; overflow: hidden; }
.sh-inp input { flex: 1; border: 0 !important; padding: 11px 12px; font-size: 16px; outline: 0 !important; background: none; min-width: 0; }
.sh-inp:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.sh-inp.wa:focus-within { border-color: #25d366; box-shadow: 0 0 0 3px rgba(37, 211, 102, .15); }
.sh-pre { padding: 0 12px; color: var(--muted); border-left: 1px solid var(--border); align-self: stretch; display: flex; align-items: center; direction: ltr; }
.sh-chips { display: flex; gap: 6px; flex-wrap: wrap; margin: -4px 0 14px; }
.sh-chip { font: inherit; font-size: 12.5px; border: 1px solid var(--border); border-radius: 99px; padding: 4px 10px; color: var(--muted); background: #fff; cursor: pointer; }
.sh-chip.label { border: 0; padding-right: 0; cursor: default; }
.sh-chip b { color: var(--text); font-weight: 500; }
.sh-preview { background: #e7f8ee; border-radius: 12px; padding: 34px 12px 10px; font-size: 13.5px; line-height: 1.55; white-space: pre-wrap; word-break: break-word; position: relative; margin-bottom: 6px; }
.sh-preview.mail { background: var(--bg); padding-top: 10px; }
.sh-plabel { position: absolute; right: 12px; top: 9px; font-size: 12px; color: var(--muted); }
.sh-editbtn { position: absolute; left: 8px; top: 7px; font: inherit; font-size: 12px; color: var(--primary); background: #fff; border-radius: 6px; padding: 2px 8px; border: 1px solid var(--border); cursor: pointer; }
.sh-edit { width: 100%; font: inherit; font-size: 14px; line-height: 1.55; border: 1.5px solid var(--primary); border-radius: 12px; padding: 10px 12px; margin-bottom: 6px; resize: vertical; }
.sh-tiny { font-size: 12px; color: var(--muted); margin-bottom: 14px; }
.sh-toggle { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 11px 12px; border: 1px solid var(--border); border-radius: 10px; margin-bottom: 16px; font-size: 14px; cursor: pointer; position: relative; }
.sh-toggle small { display: block; color: var(--muted); font-size: 12px; }
.sh-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.sh-sw { width: 40px; height: 23px; border-radius: 99px; background: #c9ccd6; position: relative; flex-shrink: 0; transition: background .15s; }
.sh-sw::after { content: ''; position: absolute; top: 3px; right: 3px; width: 17px; height: 17px; border-radius: 50%; background: #fff; transition: right .15s; }
.sh-toggle input:checked + .sh-sw { background: var(--success); }
.sh-toggle input:checked + .sh-sw::after { right: 20px; }
.btn.sh-go { width: 100%; border: 0; color: #fff; font-weight: 700; }
.btn.sh-go.wa { background: #25d366; }
.btn.sh-go.wa:hover { background: #1fb959; }
.btn.sh-go.mail { background: var(--primary); }
.btn.sh-copy { background: var(--primary-soft); color: var(--primary); border: 0; font-weight: 700; }
.sh-row { display: flex; gap: 8px; }
.sh-row .btn { flex: 1; }
.sh-off { background: var(--warn-soft); color: var(--warn); border-radius: 12px; padding: 12px 14px; font-size: 14px; line-height: 1.6; }
.sh-off small { color: var(--text); opacity: .8; }
.sh-done { text-align: center; padding: 4px 4px 0; }
.sh-check { width: 64px; height: 64px; border-radius: 50%; background: var(--success-soft); color: var(--success); font-size: 32px; display: flex; align-items: center; justify-content: center; margin: 0 auto 12px; }
.sh-done h3 { margin-bottom: 4px !important; font-size: 19px !important; }
.sh-steps { background: var(--bg); border-radius: 12px; padding: 12px 14px; margin: 4px 0 16px; font-size: 14px; display: grid; gap: 9px; }
.sh-steps > div { display: flex; gap: 8px; align-items: flex-start; }
.sh-steps small { display: block; color: var(--muted); font-size: 12px; }
.sh-steps .d { width: 20px; height: 20px; border-radius: 50%; flex-shrink: 0; font-size: 12px; display: flex; align-items: center; justify-content: center; margin-top: 1px; border: 2px solid #c4c8d2; }
.sh-steps .d.ok { background: var(--success); border-color: var(--success); color: #fff; }
.sh-signer { border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; margin-bottom: 10px; }
.sh-stop { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-weight: 500; }
.sh-signer .sh-mrow { margin-top: 8px; }
.sh-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-left: 6px; }
.sh-mrow { display: flex; gap: 6px; }
.sh-mrow .sh-inp { margin: 0; flex: 1; }
.sh-mrow .sh-inp input { padding: 8px 10px; font-size: 15px; }
.sh-ib { width: 40px; border-radius: 10px; border: 0; color: #fff; font-size: 17px; flex-shrink: 0; cursor: pointer; }
.sh-ib.wa { background: #25d366; }
.sh-ib.mail { background: var(--primary); }
.sh-ib.copy { background: var(--primary-soft); }
.sh-ib:disabled { background: #d5d8e0; cursor: default; }

.badge.opened { background: #e6f4ff; color: #1668b8; }
.badge.not-opened { background: #eef0f4; color: var(--muted); }
.meta.track .late { color: var(--danger); font-weight: 500; }
.signer-rows { margin-top: 4px; display: flex; flex-direction: column; gap: 2px; }
.signer-row { font-size: 13px; color: var(--muted); display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.signer-row b { color: var(--text); font-weight: 500; min-width: 70px; }
.signer-row .ok { color: var(--success); }
.badge.cancelled { background: #fdeaea; color: var(--danger); }

.brand { font-size: 26px; font-weight: 700; color: var(--primary); letter-spacing: .5px; margin-bottom: 2px; direction: ltr; }
.powered { font-size: 13px; color: var(--muted); direction: ltr; white-space: nowrap; }
.powered b { color: var(--primary); }

/* חלון אישור */
.modal.cf-modal { max-width: 440px; padding: 22px 22px 18px; }
.cf-top { display: flex; gap: 14px; align-items: flex-start; }
.cf-ico {
  width: 40px; height: 40px; flex: none; display: grid; place-items: center; border-radius: 11px;
  background: var(--primary-soft); color: var(--primary); font-size: 19px;
}
.cf.danger .cf-ico { background: #fdecec; color: #c8161d; }
.cf-ico svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.cf-body { flex: 1; min-width: 0; padding-top: 2px; }
.cf-body h3 { margin: 0; font-size: 17px; font-weight: 700; line-height: 1.4; letter-spacing: -.01em; }
.cf-subject {
  margin-top: 8px; padding: 7px 10px; border-radius: 8px; background: var(--bg); font-size: 13.5px; font-weight: 500;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cf-body p { margin: 8px 0 0; font-size: 14px; line-height: 1.6; color: var(--muted); }
.cf-acts { display: flex; gap: 8px; justify-content: flex-end; margin-top: 22px; }
.cf-acts .btn { padding: 9px 18px; font-size: 14.5px; min-width: 92px; }
.cf-ok { background: var(--primary); border-color: var(--primary); color: #fff; }
.cf-ok:hover { background: var(--primary-dark); }
.cf.danger .cf-ok { background: #c8161d; border-color: #c8161d; }
.cf.danger .cf-ok:hover { background: #a81218; }
.cf-acts .btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--primary-soft); }
.cf.danger .cf-ok:focus-visible { box-shadow: 0 0 0 3px #f6d0d1; }
@media (max-width: 639px) { .cf-acts .btn { flex: 1; } }
.btn.danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger-solid:hover { background: #b92f2f; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #1c2030; color: #fff;
  padding: 10px 18px; border-radius: 8px; z-index: 200; box-shadow: var(--shadow); font-size: 14px;
}
.toast.error { background: var(--danger); }

.center-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.center-screen .card { max-width: 420px; width: 100%; text-align: center; }
.spinner {
  width: 36px; height: 36px; border: 3px solid var(--primary-soft); border-top-color: var(--primary);
  border-radius: 50%; animation: spin .8s linear infinite; margin: 40px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }
