:root {
  --bg: #fbf1e5;
  --surface: #ffffff;
  --primary: #e8563f;
  --primary-dark: #cf4630;
  --accent: #f6a324;
  --accent-dark: #e0801a;
  --gold: #f6a623;
  --ink: #35271d;
  --muted: #8a7a6d;
  --line: #f0e2d2;
  --danger: #cf3d3d;
  --ok: #1f9d57;
  --radius: 16px;
  --shadow: 0 18px 45px rgba(200, 90, 50, .16);
  --shadow-sm: 0 6px 18px rgba(200, 90, 50, .10);
}

* { box-sizing: border-box; }

/* The hidden attribute must always win over display rules like .field { display:flex } */
[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }

body {
  font-family: "Segoe UI", "Assistant", "Rubik", Arial, "Noto Sans Hebrew", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 100% 0, rgba(246, 163, 36, .18), transparent 30rem),
    radial-gradient(circle at 0 6%, rgba(232, 86, 63, .12), transparent 26rem),
    linear-gradient(180deg, #fdf8f1 0, var(--bg) 40rem);
  min-height: 100vh;
  line-height: 1.5;
}

/* ---------- Header ---------- */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px clamp(16px, 4vw, 48px);
  background: rgba(255, 255, 255, .8);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 46px; height: 46px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: #fff;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.logo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.brand-text { display: flex; flex-direction: column; }
.brand-text strong { font-size: 1.02rem; }
.brand-text span { font-size: .82rem; color: var(--muted); }
.header-meta {
  font-size: .82rem; color: var(--primary);
  background: rgba(232, 86, 63, .08);
  padding: 8px 14px; border-radius: 999px; font-weight: 600;
}

/* ---------- Layout ---------- */
.container {
  max-width: 900px;
  margin: 0 auto;
  padding: clamp(20px, 4vw, 40px) clamp(16px, 4vw, 32px) 64px;
}

.intro { text-align: center; margin-bottom: 26px; }
.eyebrow {
  display: inline-block; margin: 0 0 8px;
  color: var(--accent-dark); font-weight: 700; font-size: .82rem;
  text-transform: uppercase; letter-spacing: 1.5px;
}
.intro h1 { margin: 0 0 10px; font-size: clamp(1.6rem, 4vw, 2.3rem); line-height: 1.2; }
.lead { margin: 0 auto; max-width: 40rem; color: var(--muted); font-size: 1.02rem; }

/* ---------- Progress ---------- */
.progress-wrap { margin: 0 0 22px; }
.progress-head {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: 8px; font-size: .9rem; font-weight: 600; color: var(--primary);
}
.progress-bar {
  height: 10px; border-radius: 999px; background: #f2e4d3; overflow: hidden;
}
.progress-bar span {
  display: block; height: 100%; width: 17%;
  background: linear-gradient(90deg, var(--accent), var(--primary));
  border-radius: 999px; transition: width .35s ease;
}

/* ---------- Cards / steps ---------- */
.step-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(20px, 3.5vw, 34px);
  animation: rise .35s ease;
}
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.step-card[hidden] { display: none; }
.step-head { margin-bottom: 18px; padding-bottom: 16px; border-bottom: 1px solid var(--line); }
.step-head h2 { margin: 0 0 4px; font-size: 1.4rem; color: var(--primary); }
.step-head p { margin: 0; color: var(--muted); }

/* ---------- Fields ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field.wide { grid-column: 1 / -1; }
.field > span { font-size: .9rem; font-weight: 600; color: #5c4a3d; }
.req { color: var(--danger); }
.field input,
.field select,
.field textarea {
  font: inherit;
  padding: 12px 14px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: #fffdf9;
  color: var(--ink);
  transition: border-color .15s, box-shadow .15s;
  width: 100%;
}
.field textarea { resize: vertical; min-height: 76px; }
.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(246, 163, 36, .16);
  background: #fff;
}
.field input.invalid { border-color: var(--danger); box-shadow: 0 0 0 4px rgba(214, 69, 69, .12); }

/* ---------- Section sub-heading ---------- */
.subhead {
  margin: 24px 0 12px;
  font-size: 1.08rem;
  color: var(--primary);
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
}
.step-card > .subhead:first-of-type { margin-top: 4px; }

/* ---------- Checkboxes ---------- */
.checks { display: flex; flex-direction: column; gap: 10px; margin-bottom: 18px; }
.check {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 14px 16px; border: 1.5px solid var(--line); border-radius: 12px;
  background: #fffdf9; cursor: pointer; transition: border-color .15s, background .15s;
}
.check:hover { border-color: #ecd8c2; }
.check input { margin-top: 3px; width: 18px; height: 18px; accent-color: var(--accent); flex: 0 0 auto; }
.check span { font-size: .95rem; color: #5c4a3d; }
.check:has(input:checked) { border-color: var(--accent); background: rgba(246, 163, 36, .07); }
.check.invalid { border-color: var(--danger); background: rgba(214, 69, 69, .06); }
.field-sub { display: block; margin: -2px 0 2px; color: var(--muted); font-size: .82rem; line-height: 1.3; }
.role-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 14px; }

/* ---------- Buttons / nav ---------- */
.wizard-nav {
  display: flex; justify-content: space-between; gap: 12px; margin-top: 20px;
}
.final-actions {
  display: flex; flex-direction: column; gap: 14px; margin-top: 20px;
  padding-top: 20px; border-top: 1px dashed var(--line);
}
.final-actions[hidden], #btnBack[hidden], #btnNext[hidden] { display: none; }
.submit-main {
  width: 100%; font-size: 1.14rem; padding: 18px; border-radius: 14px;
  box-shadow: 0 10px 24px rgba(200, 90, 50, .20);
}
.submit-main:hover:not(:disabled) { box-shadow: 0 14px 30px rgba(200, 90, 50, .28); }
.final-secondary { display: flex; flex-wrap: wrap; gap: 12px; }
.final-secondary .btn { flex: 1 1 auto; }
.btn {
  font: inherit; font-weight: 700;
  padding: 13px 26px; border-radius: 12px; border: 1.5px solid transparent;
  cursor: pointer; transition: transform .06s, box-shadow .15s, background .15s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .6; cursor: default; }
.btn.primary {
  background: linear-gradient(135deg, var(--primary), var(--accent-dark));
  color: #fff; box-shadow: var(--shadow-sm);
}
.btn.primary:hover:not(:disabled) { box-shadow: 0 10px 24px rgba(200, 90, 50, .22); }
.btn.ghost { background: #fff; border-color: var(--line); color: var(--primary); }
.btn.ghost:hover { border-color: var(--accent); color: var(--accent-dark); }
.btn.danger { background: #fff; border-color: #f0c9c9; color: var(--danger); }
.btn.danger:hover { background: #fdeeee; }

/* ---------- Footer ---------- */
.site-footer {
  text-align: center; color: var(--muted); font-size: .85rem;
  padding: 24px 16px 40px;
}

/* ---------- Contract preview (also used for PDF) ---------- */
.contract-preview { margin: 4px 0; }
.contract-paper {
  background: #fff; color: #111827;
  border: 1px solid #cbd5e1; border-radius: 12px; overflow: hidden;
}
.contract-paper header {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff; padding: 22px 26px; text-align: center;
}
.contract-paper header p, .contract-paper header h3, .contract-paper header small { margin: 0; }
.contract-paper header p { font-weight: 800; letter-spacing: .3px; }
.contract-paper header h3 { font-size: 1.7rem; margin: 6px 0 3px; }
.contract-paper header small { opacity: .9; }
.contract-meta {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px 22px;
  padding: 20px 26px; border-bottom: 1px solid #e5e9f0;
}
.contract-meta > div { display: flex; flex-direction: column; gap: 2px; font-size: .9rem; }
.contract-meta strong { color: var(--muted); font-weight: 600; font-size: .78rem; }
.contract-meta span { color: #111827; border-bottom: 1px dotted #cbd5e1; min-height: 1.2em; }
.contract-body { padding: 8px 26px 20px; }
.contract-body section { margin-top: 16px; }
.contract-body h4 { margin: 0 0 4px; color: var(--primary); font-size: 1rem; }
.contract-body p { margin: 0; color: #26324a; font-size: .92rem; line-height: 1.6; }
.contract-checks { display: flex; flex-direction: column; gap: 4px; font-size: .9rem; }
.contract-signatures {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px;
  padding: 18px 26px 26px; border-top: 1px solid #e5e9f0;
}
.contract-signatures > div { text-align: center; font-size: .85rem; }
.contract-signatures span { display: block; min-height: 1.4em; border-bottom: 1px solid #94a3b8; margin-bottom: 6px; }
.contract-signatures strong { color: var(--muted); font-weight: 600; }

/* ---------- Off-screen PDF stage ---------- */
.pdf-clip { position: fixed; left: 0; top: 0; width: 0; height: 0; overflow: hidden; z-index: -1; }
.pdf-stage { width: 794px; background: #fff; direction: rtl; }
.pdf-stage .contract-paper { border: none; }

/* ---------- Upload field ---------- */
.upload-field {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px dashed var(--line);
}
.upload-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.btn-upload { padding: 10px 18px; }
.upload-hint { color: var(--muted); font-size: .92rem; }
.upload-name {
  margin-top: 10px;
  display: flex; align-items: center; gap: 10px;
  background: rgba(246, 163, 36, .08);
  border: 1px solid rgba(246, 163, 36, .3);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: .9rem; color: var(--primary);
}
.upload-name button {
  margin-inline-start: auto;
  border: none; background: transparent; cursor: pointer;
  color: var(--danger); font-weight: 700; font-size: 1.1rem; line-height: 1;
}

/* ---------- Yes/No toggle ---------- */
.toggle-btns { display: flex; gap: 10px; }
.toggle { flex: 1; position: relative; margin: 0; }
.toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle span {
  display: block; text-align: center; padding: 11px 14px;
  border: 1.5px solid var(--line); border-radius: 12px;
  background: #fffdf9; cursor: pointer; font-weight: 700; color: var(--ink);
  transition: border-color .15s, background .15s, color .15s;
}
.toggle input:checked + span {
  border-color: var(--accent); background: rgba(246, 163, 36, .12); color: var(--accent-dark);
}
.toggle input:focus-visible + span { box-shadow: 0 0 0 4px rgba(246, 163, 36, .16); }

/* ---------- Read-only auto fields + terms note ---------- */
.field input[readonly] {
  background: #f6efe4;
  color: var(--ink);
  cursor: default;
  border-style: dashed;
}
.field input[readonly]::placeholder { color: var(--muted); }
/* Native date inputs render their value LTR/left-aligned even under dir=rtl;
   align it to the right so it matches the other fields (notably on mobile). */
.field input[type="date"] { text-align: right; }
.field input[type="date"]::-webkit-date-and-time-value { text-align: right; }
.terms-note {
  margin: 16px 0 0;
  padding: 12px 16px;
  background: rgba(246, 163, 36, .07);
  border: 1px solid rgba(246, 163, 36, .25);
  border-radius: 12px;
  color: var(--primary);
  font-size: .92rem;
}

/* ---------- Contract terms accordion ---------- */
.contract-terms { margin: 22px 0; }
.contract-terms > h3 { margin: 0 0 4px; font-size: 1.15rem; color: var(--primary); }
.terms-intro { margin: 0 0 14px; color: var(--muted); font-size: .92rem; }
.clause {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fffdf9;
  margin-bottom: 10px;
  overflow: hidden;
}
.clause > summary {
  cursor: pointer;
  list-style: none;
  padding: 14px 44px 14px 16px;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 3px;
  transition: background .15s;
}
.clause > summary:hover,
.clause[open] > summary { background: rgba(246, 163, 36, .06); }
.clause > summary::-webkit-details-marker { display: none; }
.clause > summary::after {
  content: "＋";
  position: absolute;
  inset-inline-end: 16px;
  top: 13px;
  color: var(--accent-dark);
  font-weight: 800;
  font-size: 1.2rem;
}
.clause[open] > summary::after { content: "－"; }
.clause-title { font-weight: 700; color: var(--primary); }
.clause-summary { color: var(--muted); font-size: .9rem; line-height: 1.5; }
.clause-body {
  padding: 4px 16px 16px;
  border-top: 1px solid var(--line);
  color: #5c4a3d;
  font-size: .92rem;
  line-height: 1.7;
}
.clause-body p { margin: 10px 0 0; }

/* ---------- Submit overlay ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(18, 41, 77, .55);
  backdrop-filter: blur(4px);
  animation: overlayFade .2s ease;
}
@keyframes overlayFade { from { opacity: 0; } to { opacity: 1; } }
.overlay-card {
  background: #fff;
  border-radius: 18px;
  padding: 34px 30px;
  max-width: 360px;
  text-align: center;
  box-shadow: var(--shadow);
  animation: rise .3s ease;
}
.overlay-card h3 { margin: 18px 0 8px; color: var(--primary); font-size: 1.2rem; }
.overlay-card .btn { margin-top: 18px; }
.overlay-card p { margin: 0; color: var(--muted); font-size: .95rem; line-height: 1.55; }
.spinner {
  width: 58px;
  height: 58px;
  margin: 0 auto;
  border: 5px solid rgba(246, 163, 36, .2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.overlay-card.success[hidden] { display: none; }
.success-check {
  width: 64px; height: 64px; margin: 0 auto;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%; background: #2ba676; color: #fff;
  font-size: 34px; font-weight: 800; line-height: 1;
  box-shadow: 0 8px 20px rgba(43, 166, 118, .35);
  animation: pop .35s ease;
}
@keyframes pop { 0% { transform: scale(.4); opacity: 0; } 60% { transform: scale(1.1); } to { transform: scale(1); opacity: 1; } }

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .grid { grid-template-columns: 1fr; }
  .contract-meta { grid-template-columns: 1fr; }
  .contract-signatures { grid-template-columns: 1fr; gap: 24px; }
  .wizard-nav { flex-direction: row; }
  .final-secondary .btn { flex: 1 1 46%; }
  .header-meta { display: none; }
}

/* ---------- Print ---------- */
@media print {
  .site-header, .site-footer, .intro, .progress-wrap, .wizard-nav,
  .final-actions, .step-card:not([data-print]) { display: none !important; }
  body { background: #fff; }
  .container { max-width: none; padding: 0; }
  .contract-paper { border: none; }
}
