/* חתימה ירוקה — RTL first. One stylesheet, no framework. */
:root {
  --green: #16794a;
  --green-dark: #0f5c37;
  --green-soft: #e8f5ee;
  --ink: #10263a;
  --muted: #667c91;
  --line: #e2e8ef;
  --bg: #f4f7f9;
  --card: #ffffff;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --danger: #b91c1c;
  --danger-soft: #fee2e2;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 38, 58, .06), 0 8px 24px rgba(16, 38, 58, .06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", Rubik, Arial, system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  direction: rtl;
  line-height: 1.55;
}

a { color: var(--green-dark); }

/* ---------- chrome ---------- */
.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 18px;
  height: 60px;
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; text-decoration: none; color: var(--ink); }
.brand .mark {
  width: 30px; height: 30px; border-radius: 9px;
  background: linear-gradient(140deg, var(--green), #34a06a);
  display: grid; place-items: center; color: #fff; font-size: 16px;
}
.topbar nav { margin-inline-start: auto; display: flex; gap: 6px; align-items: center; }
.topbar nav a, .topbar nav button {
  padding: 7px 13px; border-radius: 8px; text-decoration: none; color: var(--muted);
  font-size: 14px; border: 0; background: none; cursor: pointer; font-family: inherit;
}
.topbar nav a:hover, .topbar nav button:hover { background: var(--bg); color: var(--ink); }

.wrap { max-width: 1120px; margin: 0 auto; padding: 24px; }
.wrap.narrow { max-width: 620px; }
.wrap.wide { max-width: 1400px; }

h1 { font-size: 24px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 0 0 12px; }
.sub { color: var(--muted); font-size: 14px; margin: 0 0 20px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.card + .card { margin-top: 16px; }
.row { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.row > .grow { flex: 1 1 340px; min-width: 0; }
.head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.head .spacer { margin-inline-start: auto; }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px; justify-content: center;
  background: var(--green); color: #fff; border: 1px solid var(--green);
  padding: 9px 16px; border-radius: 9px; font-size: 14px; font-weight: 600;
  cursor: pointer; text-decoration: none; font-family: inherit; transition: .15s;
}
.btn:hover { background: var(--green-dark); border-color: var(--green-dark); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.ghost { background: #fff; color: var(--ink); border-color: var(--line); }
.btn.ghost:hover { background: var(--bg); }
.btn.danger { background: #fff; color: var(--danger); border-color: #f2c7c7; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.sm { padding: 5px 11px; font-size: 13px; border-radius: 7px; }
.btn.block { width: 100%; }

label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; }
input[type=text], input[type=email], input[type=number], input[type=password], textarea, select, input[type=file] {
  width: 100%; padding: 9px 12px; border: 1px solid var(--line); border-radius: 9px;
  font-family: inherit; font-size: 14px; background: #fff; color: var(--ink);
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--green-soft); border-color: var(--green); }
.field { margin-bottom: 14px; }
.field .err { color: var(--danger); font-size: 12px; margin-top: 4px; }
.hint { color: var(--muted); font-size: 12.5px; }

/* ---------- bits ---------- */
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.draft { background: #eef2f6; color: #5b6b7c; }
.badge.sent { background: var(--warn-soft); color: var(--warn); }
.badge.signed { background: var(--green-soft); color: var(--green-dark); }
.badge.cancelled { background: var(--danger-soft); color: var(--danger); }
.badge.pending { background: #eef2f6; color: #5b6b7c; }
.badge.viewed { background: #e0f2fe; color: #075985; }
.badge.declined { background: var(--danger-soft); color: var(--danger); }

table { width: 100%; border-collapse: collapse; }
th { text-align: right; font-size: 12.5px; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); }
td { padding: 11px 10px; border-bottom: 1px solid var(--line); font-size: 14px; vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tr.clickable:hover { background: var(--bg); }

.msgs { margin-bottom: 16px; display: grid; gap: 8px; }
.msg { padding: 11px 14px; border-radius: 9px; font-size: 14px; border: 1px solid; }
.msg.success { background: var(--green-soft); border-color: #bfe3ce; color: var(--green-dark); }
.msg.error   { background: var(--danger-soft); border-color: #f5c2c2; color: var(--danger); }
.msg.warning { background: var(--warn-soft); border-color: #f5dfa0; color: var(--warn); }
.msg.info    { background: #e0f2fe; border-color: #bae6fd; color: #075985; }

.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty .big { font-size: 40px; margin-bottom: 8px; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.filters a { padding: 6px 13px; border-radius: 999px; background: #fff; border: 1px solid var(--line); text-decoration: none; color: var(--muted); font-size: 13.5px; }
.filters a.on { background: var(--green); border-color: var(--green); color: #fff; }

.linkbox { display: flex; gap: 6px; }
.linkbox input { font-size: 12.5px; direction: ltr; text-align: left; font-family: ui-monospace, monospace; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px dashed var(--line); font-size: 13.5px; }
.timeline li:last-child { border-bottom: 0; }
.timeline .when { color: var(--muted); min-width: 122px; font-variant-numeric: tabular-nums; }

/* ---------- pdf surface (designer + signer share it) ---------- */
.pdf-area { background: #59687a; border-radius: var(--radius); padding: 20px; overflow: auto; max-height: calc(100vh - 210px); }
.page-wrap { position: relative; margin: 0 auto 18px; box-shadow: 0 6px 18px rgba(0,0,0,.28); background: #fff; width: fit-content; }
/* The page is RTL, but a canvas that inherits direction:rtl makes the 2D
   context anchor every glyph on its right edge — pdf.js draws glyph by glyph
   assuming LTR, so Hebrew PDFs come out with the letters scattered. */
.page-wrap canvas { display: block; direction: ltr; }
.overlay { position: absolute; inset: 0; }

.fld {
  position: absolute; border: 2px dashed var(--green); background: rgba(22, 121, 74, .12);
  border-radius: 6px; cursor: move; display: grid; place-items: center;
  font-size: 12px; color: var(--green-dark); font-weight: 600; user-select: none; overflow: hidden;
}
.fld .handle { position: absolute; inset-inline-start: -5px; bottom: -5px; width: 13px; height: 13px; background: var(--green); border: 2px solid #fff; border-radius: 3px; cursor: nesw-resize; }
.fld .kill { position: absolute; inset-inline-end: -8px; top: -8px; width: 19px; height: 19px; border-radius: 50%; background: var(--danger); color: #fff; border: 2px solid #fff; font-size: 12px; line-height: 1; cursor: pointer; display: grid; place-items: center; padding: 0; }
.fld.c1 { border-color: #1d4ed8; background: rgba(29,78,216,.12); color: #1d4ed8; }
.fld.c1 .handle { background: #1d4ed8; }
.fld.c2 { border-color: #b45309; background: rgba(180,83,9,.12); color: #b45309; }
.fld.c2 .handle { background: #b45309; }
.fld.c3 { border-color: #7c3aed; background: rgba(124,58,237,.12); color: #7c3aed; }
.fld.c3 .handle { background: #7c3aed; }

/* signer view: fields are buttons, not draggables */
.fld.todo { cursor: pointer; border-style: solid; background: rgba(22,121,74,.10); animation: pulse 2.4s infinite; }
.fld.done { border-style: solid; border-color: #bfe3ce; background: transparent; animation: none; cursor: pointer; }
.fld.done img { width: 100%; height: 100%; object-fit: contain; }
.fld.done .txt { font-size: inherit; color: var(--ink); font-weight: 500; padding: 0 4px; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(22,121,74,.45); } 50% { box-shadow: 0 0 0 7px rgba(22,121,74,0); } }

.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.chip { padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: #fff; cursor: pointer; font-size: 13.5px; font-family: inherit; display: inline-flex; align-items: center; gap: 6px; }
.chip.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.chip .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--green); }
.chip.c1 .dot { background: #1d4ed8; }
.chip.c2 .dot { background: #b45309; }
.chip.c3 .dot { background: #7c3aed; }

/* ---------- signing page ---------- */
.sign-top { background: var(--card); border-bottom: 1px solid var(--line); padding: 12px 20px; position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.sign-top .progress { color: var(--muted); font-size: 13.5px; }
.sign-bottom { position: sticky; bottom: 0; background: var(--card); border-top: 1px solid var(--line); padding: 12px 20px; display: flex; gap: 10px; align-items: center; z-index: 30; }

dialog { border: 0; border-radius: var(--radius); padding: 0; box-shadow: 0 20px 60px rgba(16,38,58,.3); max-width: 94vw; }
dialog::backdrop { background: rgba(16, 38, 58, .55); }
.modal { padding: 20px; width: 520px; max-width: 94vw; }
.modal h2 { margin-bottom: 6px; }
.pad-box { border: 1px solid var(--line); border-radius: 10px; background: #fff; touch-action: none; display: block; width: 100%; }
.pad-line { text-align: center; color: var(--muted); font-size: 12px; margin-top: 6px; }

.center-card { max-width: 480px; margin: 60px auto; text-align: center; }
.center-card .big { font-size: 46px; margin-bottom: 10px; }

@media (max-width: 720px) {
  .wrap { padding: 16px; }
  .topbar { padding: 0 14px; gap: 10px; }
  .topbar nav a, .topbar nav button { padding: 6px 9px; font-size: 13px; }
  .pdf-area { padding: 10px; max-height: none; }
  th.opt, td.opt { display: none; }
}
