/* DigitalSign — שפת עיצוב בהשראת iOS/macOS: רקע אפור-בהיר, כרטיסים לבנים מעוגלים, כחול מערכת, Heebo */
:root {
  --bg: #f2f2f7;
  --surface: #ffffff;
  --surface-2: #f7f7fa;
  --fill: #eeeef3;
  --line: rgba(60, 60, 67, 0.14);
  --text: #1c1c1e;
  --text-2: #3a3a3c;
  --muted: #6e6e73;
  --muted-2: #aeaeb2;
  --primary: #0071e3;
  --primary-press: #0060c0;
  --primary-ink: #ffffff;
  --primary-soft: rgba(10, 132, 255, 0.12);
  --wa: #25d366;
  --wa-ink: #0b3d20;
  --danger: #ff3b30;
  --danger-soft: rgba(255, 59, 48, 0.12);
  --ok: #34c759;
  --ok-soft: rgba(52, 199, 89, 0.14);
  --warn: #ff9f0a;
  --warn-soft: rgba(255, 159, 10, 0.16);
  --purple: #5e5ce6;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 10px 30px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 24px 70px rgba(0, 0, 0, 0.22);
  --font: 'Heebo', -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, system-ui, sans-serif;
  --glass: rgba(255, 255, 255, 0.72);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #1c1c1e;
    --surface-2: #2c2c2e;
    --fill: #2c2c2e;
    --line: rgba(84, 84, 88, 0.6);
    --text: #f2f2f7;
    --text-2: #e5e5ea;
    --muted: #98989d;
    --muted-2: #636366;
    --primary: #0a84ff;
    --primary-press: #409cff;
    --primary-soft: rgba(10, 132, 255, 0.22);
    --danger: #ff453a;
    --danger-soft: rgba(255, 69, 58, 0.2);
    --ok: #30d158;
    --ok-soft: rgba(48, 209, 88, 0.2);
    --warn: #ffd60a;
    --warn-soft: rgba(255, 214, 10, 0.18);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.5), 0 10px 30px rgba(0, 0, 0, 0.35);
    --glass: rgba(28, 28, 30, 0.72);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  direction: rtl;
  line-height: 1.5;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: var(--primary); text-decoration: none; }
h1, h2, h3 { margin: 0 0 8px; font-weight: 700; letter-spacing: -0.01em; }
h1 { font-size: 28px; letter-spacing: -0.02em; }
h2 { font-size: 18px; }
h3 { font-size: 13px; color: var(--muted); font-weight: 600; text-transform: none; letter-spacing: 0.02em; }
p { margin: 0 0 8px; }
code { font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace; font-size: 0.92em; background: var(--fill); padding: 1px 6px; border-radius: 6px; direction: ltr; unicode-bidi: embed; }
.muted { color: var(--muted); font-size: 13px; }
.small { font-size: 12px; }
::selection { background: var(--primary-soft); }

/* ---------- סרגל עליון (זכוכית) ---------- */
.topbar {
  background: var(--glass);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--line);
  padding: 0 20px;
  padding-top: env(safe-area-inset-top);
  height: calc(56px + env(safe-area-inset-top));
  display: flex;
  align-items: center;
  gap: 18px;
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar .brand { font-weight: 800; font-size: 18px; color: var(--text); display: flex; align-items: center; gap: 10px; letter-spacing: -0.02em; }
.topbar .brand .logo { width: 30px; height: 30px; border-radius: 9px; box-shadow: 0 2px 6px rgba(10, 132, 255, 0.35); }
.topbar nav { display: flex; gap: 4px; margin-inline-start: auto; }
.topbar nav a { color: var(--muted); font-weight: 600; font-size: 14px; padding: 6px 12px; border-radius: 10px; transition: background 0.15s, color 0.15s; }
.topbar nav a:hover { background: var(--fill); color: var(--text); }
.topbar nav a.active { color: var(--primary); background: var(--primary-soft); }
@media (max-width: 480px) { .topbar { padding: 0 12px; gap: 8px; } .topbar nav a { padding: 6px 9px; font-size: 13px; } .topbar .brand span { display: none; } }

.container { max-width: 1100px; margin: 0 auto; padding: 22px 16px 60px; }
.page-title { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 4px 4px 14px; }
.card {
  background: var(--surface);
  border: 1px solid transparent;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}
@media (prefers-color-scheme: dark) { .card { border-color: var(--line); } }
@media (max-width: 480px) { .card { padding: 16px; border-radius: 16px; } }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 720px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---------- כפתורים ---------- */
.btn {
  appearance: none;
  border: 1px solid transparent;
  background: var(--fill);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  font-size: 14px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background 0.15s, transform 0.08s, box-shadow 0.15s, opacity 0.15s;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  min-height: 40px;
}
.btn:hover { background: color-mix(in srgb, var(--fill) 85%, var(--text) 15%); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.btn.primary { background: var(--primary); color: var(--primary-ink); box-shadow: 0 4px 14px rgba(10, 132, 255, 0.28); }
.btn.primary:hover { background: var(--primary-press); }
.btn.wa { background: var(--wa); color: var(--wa-ink); box-shadow: 0 4px 14px rgba(37, 211, 102, 0.3); }
.btn.wa:hover { background: #1fc95c; }
.btn.danger { color: var(--danger); background: var(--danger-soft); }
.btn.danger:hover { background: color-mix(in srgb, var(--danger-soft) 70%, var(--danger) 30%); color: #fff; }
.btn.ghost { background: transparent; color: var(--primary); }
.btn.ghost:hover { background: var(--primary-soft); }
.btn.sm { padding: 6px 12px; font-size: 13px; border-radius: 10px; min-height: 32px; }
.btn.lg { padding: 14px 22px; font-size: 16px; border-radius: 14px; min-height: 52px; }
.btn.block { width: 100%; }
.btn.tool.active { background: var(--primary); color: #fff; }
.btn.tool { background: var(--fill); }

/* ---------- שדות ---------- */
.input, select, textarea {
  font: inherit;
  width: 100%;
  padding: 11px 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--fill);
  color: var(--text);
  transition: box-shadow 0.15s, background 0.15s;
  min-height: 44px;
}
.input::placeholder, textarea::placeholder { color: var(--muted-2); }
.input:focus, select:focus, textarea:focus { outline: none; box-shadow: 0 0 0 3px var(--primary-soft); background: var(--surface); border-color: var(--primary); }
.input:disabled { opacity: 0.6; }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(14px) 50%, calc(14px + 5px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-left: 32px; }
textarea { min-height: 110px; resize: vertical; }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 13px; color: var(--muted); margin: 0 4px 6px; font-weight: 600; }
.checkbox { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; }
.checkbox input { width: 20px; height: 20px; margin-top: 2px; accent-color: var(--primary); flex: none; }

/* ---------- טבלה ---------- */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { text-align: right; padding: 12px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { color: var(--muted); font-weight: 600; font-size: 12px; }
.table tr:last-child td { border-bottom: 0; }
.table tr:hover td { background: var(--surface-2); }
.table a.title { font-weight: 700; color: var(--text); }
@media (max-width: 640px) { .table th:nth-child(2), .table td:nth-child(2) { display: none; } }

/* ---------- תגיות סטטוס ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 700; background: var(--fill); color: var(--muted); white-space: nowrap;
}
.pill::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.draft { background: var(--fill); color: var(--muted); }
.pill.sent, .pill.viewed { background: var(--warn-soft); color: #9a5c05; }
.pill.pending { background: var(--fill); color: var(--muted); }
.pill.completed, .pill.signed { background: var(--ok-soft); color: #1f8f3f; }
.pill.declined, .pill.cancelled { background: var(--danger-soft); color: var(--danger); }
@media (prefers-color-scheme: dark) { .pill.sent, .pill.viewed { color: var(--warn); } .pill.completed, .pill.signed { color: var(--ok); } }

/* ---------- הודעות ---------- */
.toast {
  position: fixed; bottom: calc(24px + env(safe-area-inset-bottom)); left: 50%; transform: translate(-50%, 10px);
  background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 14px; font-size: 14px; font-weight: 600;
  z-index: 100; box-shadow: var(--shadow-lg); opacity: 0; transition: opacity 0.2s, transform 0.2s; pointer-events: none; max-width: 90vw;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); color: #fff; }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.4);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  display: none; align-items: center; justify-content: center; z-index: 50; padding: 12px;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--surface); border-radius: 22px; width: 100%; max-width: 560px;
  box-shadow: var(--shadow-lg); padding: 22px; max-height: 92vh; overflow: auto;
  animation: pop 0.18s ease-out;
}
@keyframes pop { from { transform: scale(0.96); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal h2 { margin-bottom: 14px; font-size: 20px; }
.modal .actions { display: flex; gap: 8px; justify-content: flex-start; margin-top: 16px; flex-wrap: wrap; }
@media (max-width: 480px) {
  .modal-backdrop { align-items: flex-end; padding: 0; }
  .modal { border-radius: 22px 22px 0 0; max-height: 94vh; padding-bottom: calc(22px + env(safe-area-inset-bottom)); }
}

.empty { text-align: center; color: var(--muted); padding: 36px 10px; }
.empty .big { font-size: 42px; margin-bottom: 8px; }

/* ---------- כניסה ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; background: radial-gradient(1200px 600px at 50% -10%, var(--primary-soft), transparent 60%), var(--bg); }
.login-wrap .card { width: 100%; max-width: 380px; padding: 28px 24px; text-align: center; }
.login-wrap .logo-big { width: 76px; height: 76px; border-radius: 20px; margin: 0 auto 14px; display: block; box-shadow: 0 10px 30px rgba(10, 132, 255, 0.35); }
.login-wrap h1 { font-size: 24px; }
.login-wrap .input { text-align: center; font-size: 17px; letter-spacing: 0.2em; }
.login-wrap .input::placeholder { letter-spacing: 0; }

.drop {
  border: 1.5px dashed var(--line); border-radius: var(--radius); padding: 26px; text-align: center;
  color: var(--muted); cursor: pointer; transition: border-color 0.15s, background 0.15s; background: var(--surface-2);
}
.drop.over, .drop:hover { border-color: var(--primary); background: var(--primary-soft); }
.drop input { display: none; }
.drop .big { font-size: 36px; margin-bottom: 4px; }

/* ---------- סינון (segmented) ---------- */
#filters { background: var(--fill); padding: 3px; border-radius: 12px; gap: 2px; }
#filters .btn.tool { background: transparent; color: var(--muted); border-radius: 9px; min-height: 30px; padding: 5px 10px; }
#filters .btn.tool.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }
@media (max-width: 640px) { #filters { width: 100%; overflow-x: auto; flex-wrap: nowrap; } }

/* ---------- עורך מסמך ---------- */
.editor { display: grid; grid-template-columns: 340px 1fr; gap: 16px; align-items: start; }
@media (max-width: 900px) { .editor { grid-template-columns: 1fr; } .side { position: static; max-height: none; } }
.side { position: sticky; top: 72px; display: flex; flex-direction: column; gap: 12px; max-height: calc(100vh - 90px); overflow: auto; padding: 2px; }
.side .card { margin: 0; }
.signer-item {
  display: flex; align-items: center; gap: 10px; padding: 10px; border: 1px solid transparent;
  border-radius: 14px; margin-bottom: 8px; background: var(--surface-2); cursor: pointer; transition: background 0.15s, border-color 0.15s;
}
.signer-item:hover { background: var(--fill); }
.signer-item.active { border-color: var(--primary); background: var(--primary-soft); }
.signer-item .dot { width: 12px; height: 12px; border-radius: 50%; flex: none; box-shadow: 0 0 0 3px color-mix(in srgb, currentColor 20%, transparent); }
.signer-item .info { flex: 1; min-width: 0; }
.signer-item .name { font-weight: 700; font-size: 14px; }
.signer-item .phone { font-size: 12px; color: var(--muted); direction: ltr; text-align: right; }
.tools { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.pages { display: flex; flex-direction: column; gap: 18px; align-items: center; }
.page-wrap { position: relative; background: #fff; box-shadow: 0 2px 20px rgba(0, 0, 0, 0.18); line-height: 0; border-radius: 4px; overflow: hidden; }
.page-wrap canvas { display: block; width: 100%; height: auto; }
.page-wrap .overlay { position: absolute; inset: 0; }
.page-wrap.placing .overlay { cursor: crosshair; }
.page-num { font-size: 12px; color: var(--muted); margin-top: -8px; }
.fld {
  position: absolute; border: 2px solid var(--c, var(--primary)); background: color-mix(in srgb, var(--c, var(--primary)) 14%, transparent);
  border-radius: 6px; font-size: 11px; line-height: 1.2; color: var(--c, var(--primary)); font-weight: 700;
  display: flex; align-items: center; justify-content: center; text-align: center; overflow: hidden; user-select: none;
  touch-action: none;
}
.fld.editable { cursor: move; }
.fld .del {
  position: absolute; top: -9px; left: -9px; width: 20px; height: 20px; border-radius: 50%; background: var(--danger);
  color: #fff; font-size: 12px; display: none; align-items: center; justify-content: center; cursor: pointer; line-height: 1; box-shadow: 0 1px 4px rgba(0,0,0,.3);
}
.fld .rs {
  position: absolute; bottom: -6px; right: -6px; width: 14px; height: 14px; background: var(--c, var(--primary));
  border-radius: 4px; cursor: nwse-resize; display: none; border: 2px solid #fff;
}
.fld.editable:hover .del, .fld.editable:hover .rs { display: flex; }
@media (hover: none) { .fld.editable .del, .fld.editable .rs { display: flex; } .fld .del { width: 26px; height: 26px; top: -12px; left: -12px; font-size: 14px; } .fld .rs { width: 20px; height: 20px; bottom: -9px; right: -9px; } }
.fld img { max-width: 100%; max-height: 100%; object-fit: contain; }
.fld.filled { background: transparent; border-style: solid; border-color: rgba(52, 199, 89, 0.7); color: #1c1c1e; font-size: 12px; font-weight: 500; }
.fld.filled.text { justify-content: flex-start; padding: 0 4px; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.legend span::before { content: ''; display: inline-block; width: 10px; height: 10px; border-radius: 3px; background: var(--c); margin-inline-end: 5px; vertical-align: middle; }
.events { font-size: 12px; color: var(--muted); max-height: 240px; overflow: auto; }
.events div { padding: 6px 0; border-bottom: 1px solid var(--line); }
.events div:last-child { border-bottom: 0; }
.events b { color: var(--text-2); font-weight: 600; }
.link-box { display: flex; gap: 6px; align-items: center; }
.link-box input { direction: ltr; font-size: 12px; }
.save-state { font-size: 12px; color: var(--muted); }
.warn-card { border: 1px solid color-mix(in srgb, var(--warn) 50%, transparent) !important; background: var(--warn-soft) !important; }

/* ---------- עמוד חותם ---------- */
.sign-head {
  background: var(--glass); -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--line); padding: 12px 16px; padding-top: calc(12px + env(safe-area-inset-top)); position: sticky; top: 0; z-index: 20;
}
.sign-head .title { font-weight: 800; font-size: 17px; letter-spacing: -0.01em; }
.sign-head .progress { height: 6px; background: var(--fill); border-radius: 3px; overflow: hidden; margin-top: 10px; }
.sign-head .progress > div { height: 100%; background: linear-gradient(90deg, var(--ok), #30b0c7); width: 0; transition: width 0.3s; border-radius: 3px; }
.sign-main { padding: 12px 8px calc(var(--foot-h, 180px) + 24px); max-width: 900px; margin: 0 auto; }
.sign-main .pages { gap: 12px; }
.fld.mine { cursor: pointer; --c: var(--primary); animation: pulse 2s infinite; }
.fld.mine::after { content: ''; position: absolute; inset: -14px; }
.fld.mine:not(.filled) { min-width: 28px; min-height: 24px; }
.fld.mine.filled { animation: none; }
.fld.other { --c: #8e8e93; border-style: dashed; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(10, 132, 255, 0.4); } 50% { box-shadow: 0 0 0 7px rgba(10, 132, 255, 0); } }
.sign-foot {
  position: fixed; bottom: 0; left: 0; right: 0; background: var(--glass); -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--line); padding: 10px 14px calc(12px + env(safe-area-inset-bottom)); z-index: 20;
}
.sign-foot .inner { max-width: 900px; margin: 0 auto; display: flex; flex-direction: column; gap: 10px; }
.sign-foot .consent { font-size: 12px; color: var(--text-2); }
.sigpad { border: 1.5px solid var(--line); border-radius: 14px; background: #fff; touch-action: none; width: 100%; height: 200px; display: block; }
.sigpad-wrap { position: relative; }
.sigpad-wrap .baseline { position: absolute; left: 24px; right: 24px; bottom: 48px; border-bottom: 1.5px dashed #c7c7cc; pointer-events: none; }
.tabs { display: flex; gap: 2px; background: var(--fill); padding: 3px; border-radius: 12px; margin-bottom: 12px; }
.tabs button { flex: 1; border: 0; background: transparent; padding: 8px; border-radius: 9px; font: inherit; font-weight: 600; cursor: pointer; color: var(--muted); transition: background 0.15s; }
.tabs button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,0.12); }
.typed-preview { height: 120px; border: 1.5px solid var(--line); border-radius: 14px; display: flex; align-items: center; justify-content: center; font-family: 'Segoe Script', 'Brush Script MT', 'Snell Roundhand', cursive; font-size: 40px; overflow: hidden; background: #fff; color: #102a6b; }
.status-page { max-width: 520px; margin: 40px 16px; text-align: center; padding: 28px 20px; }
@media (min-width: 560px) { .status-page { margin: 40px auto; } }
.status-page .big { font-size: 60px; margin-bottom: 6px; }
.signers-strip { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.verify-box { max-width: 420px; margin: 40px 16px; }
@media (min-width: 460px) { .verify-box { margin: 40px auto; } }
.verify-box .input { text-align: center; font-size: 26px; letter-spacing: 0.4em; direction: ltr; }

/* ---------- מגע: יעדי לחיצה של 44px ---------- */
@media (pointer: coarse) {
  .btn.sm { min-height: 44px; padding: 8px 14px; }
  #filters .btn.tool { min-height: 40px; }
  .tabs button { min-height: 44px; }
  .topbar nav a { padding: 11px 12px; }
  .checkbox input { width: 22px; height: 22px; }
}
/* רשימת מסמכים בטלפון: כרטיסים במקום טבלה */
@media (max-width: 640px) {
  .table thead { display: none; }
  .table tr { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
  .table td { border: 0; padding: 2px 0; }
  .table td:first-child { grid-column: 1 / -1; }
  .table td:last-child { grid-column: 2; grid-row: 2 / span 2; align-self: center; }
  .table tr:hover td { background: transparent; }
}

/* ---------- אייקונים ---------- */
.ic { vertical-align: -0.22em; flex: none; }
.ic.mirror, [dir="rtl"] .ic-send, [dir="rtl"] .ic-logout, [dir="rtl"] .ic-external { transform: scaleX(-1); }
.btn .ic { margin-inline-end: 2px; }
.btn.sm .ic { width: 16px; height: 16px; }
.drop .big .ic { color: var(--primary); }
.empty .big .ic { color: var(--muted-2); }
.status-ic { display: block; margin: 0 auto 12px; }
.status-ic.ok { color: var(--ok); }
.status-ic.bad { color: var(--danger); }
.status-ic.wait { color: var(--muted); }
.warn-card .ic { color: var(--warn); }

/* ---------- כותרת תחתונה ---------- */
.footer { text-align: center; color: var(--muted); font-size: 12px; padding: 20px 0 0; }
