/* ============================================================
   Self-hosted Fonts
   ============================================================ */

/* Heebo — variable, two subsets */
@font-face {
  font-family: 'Heebo';
  src: url('fonts/heebo-hebrew.woff2') format('woff2');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0307-0308, U+0590-05FF, U+200C-2010, U+20AA, U+25CC, U+FB1D-FB4F;
}
@font-face {
  font-family: 'Heebo';
  src: url('fonts/heebo-latin.woff2') format('woff2');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC,
                 U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
                 U+2212, U+2215, U+FEFF, U+FFFD;
}

/* Template fonts (used only inside canvas rendering) */
@font-face {
  font-family: 'Mr Dafoe';
  src: url('fonts/mr-dafoe.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Montserrat';
  src: url('fonts/montserrat-300.woff2') format('woff2');
  font-weight: 300;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Montserrat';
  src: url('fonts/montserrat-400.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Montserrat';
  src: url('fonts/montserrat-700.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Montserrat';
  src: url('fonts/montserrat-900.woff2') format('woff2');
  font-weight: 900;
  font-style: normal;
  font-display: swap;
}

/* ============================================================
   Base & Reset
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Core palette */
  --ink:          #1a1a1a;
  --green:        #4a9c6d;
  --green-disabled:#a8d5bc;
  --bg-warm:      #efeae6;
  --surface:      #ffffff;
  --surface-warm: #faf9f6;
  --border:       #d4d0c8;
  --border-light: #e5e5e5;
  --border-xlight:#eeeeee;
  --text-muted:   #888888;
  --text-label:   #555555;
  --error:        #e53e3e;

  /* Shadows */
  --shadow-sm:    0 2px 8px rgba(0,0,0,.05);
  --shadow-md:    0 4px 20px rgba(0,0,0,.15);
  --shadow-lg:    0 8px 40px rgba(0,0,0,.12);

  /* Radius */
  --radius-input: 8px;
  --radius-btn:   8px;
  --radius-card:  12px;
  --radius-modal: 16px;
  --radius-pill:  30px;

  /* Transitions */
  --transition: all 0.2s ease;
}

html { scroll-behavior: smooth; }

body {
  font-family: 'Heebo', 'Assistant', sans-serif;
  font-size: 16px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--bg-warm);
  direction: rtl;
  min-height: 100vh;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #c5c0b8; border-radius: 3px; }

/* ============================================================
   Header & Progress Bar
   ============================================================ */
.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border-xlight);
  padding: 16px 30px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-logo {
  display: flex;
  align-items: center;
  justify-content: center;
}

.header-logo-img {
  height: 75px;
  width: auto;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
}

@media (max-width: 600px) {
  .header-logo-img { height: 61px; }
}

.progress-bar {
  display: flex;
  align-items: center;
  gap: 0;
  width: 100%;
  max-width: 400px;
  direction: ltr;
}

.progress-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.step-circle {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--border-light);
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .85rem;
  font-weight: 600;
  color: #999;
  transition: all 0.3s ease;
}

.step-label {
  font-size: .7rem;
  color: #999;
  font-weight: 400;
  transition: color 0.3s ease;
  white-space: nowrap;
  font-family: 'Heebo', sans-serif;
}

/* Active step */
.progress-step.active .step-circle {
  background: var(--ink);
  color: #fff;
  font-weight: 600;
}
.progress-step.active .step-label {
  color: var(--ink);
  font-weight: 600;
}

/* Completed step */
.progress-step.done .step-circle {
  background: var(--green);
  color: #fff;
}
.progress-step.done .step-label { color: var(--text-muted); }

/* Connector lines */
.progress-line {
  flex: 1;
  height: 2px;
  background: var(--border-light);
  margin-bottom: 20px;
  transition: background-color 0.3s ease;
}
.progress-line.done { background: var(--green); }

/* ============================================================
   Main Layout
   ============================================================ */
.app-main {
  max-width: 960px;
  margin: 0 auto;
  padding: 32px 20px 64px;
}

/* ============================================================
   Stage Visibility
   ============================================================ */
.stage { display: none; }
.stage.active { display: block; animation: fadeIn .3s ease; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   Cards
   ============================================================ */
.stage-card {
  background: var(--surface);
  border-radius: var(--radius-card);
  padding: 40px 36px;
  box-shadow: var(--shadow-sm);
  max-width: 520px;
  margin: 0 auto;
  border: 1px solid var(--border-light);
}

.stage-card--wide  { max-width: 100%; }
.stage-card--center { text-align: center; }

.stage-icon {
  font-size: 2.5rem;
  margin-bottom: 12px;
  display: block;
}

h1 {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 8px;
  font-family: 'Heebo', sans-serif;
}

.stage-subtitle {
  color: var(--text-muted);
  font-size: .95rem;
  margin-bottom: 28px;
  line-height: 1.6;
}

/* ============================================================
   Forms
   ============================================================ */
.form-group {
  margin-bottom: 20px;
}

/* ── Language switch ── */
.lang-switch {
  display: flex;
  gap: 0;
  width: 100%;
  border-radius: var(--radius-pill);
  border: 2px solid var(--ink);
  overflow: hidden;
}

.lang-btn {
  flex: 1;
  padding: 9px 8px;
  border: none;
  background: var(--surface);
  color: var(--ink);
  font-size: 12px;
  font-weight: 600;
  font-family: 'Heebo', sans-serif;
  cursor: pointer;
  text-align: center;
  line-height: 1.3;
  transition: var(--transition);
}

.lang-btn + .lang-btn {
  border-right: 2px solid var(--ink);
}

.lang-btn.active {
  background: var(--ink);
  color: #fff;
}

.lang-btn:hover:not(.active) {
  background: var(--border-light);
}

.lang-recommended {
  font-size: 10px;
  color: inherit;
  opacity: 0.7;
  font-weight: 400;
}

.lang-btn.active .lang-recommended {
  opacity: 0.8;
}

label {
  display: block;
  font-weight: 500;
  font-size: .875rem;
  margin-bottom: 6px;
  color: var(--text-label);
  font-family: 'Heebo', sans-serif;
}

input[type="text"],
input[type="tel"] {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-input);
  font-family: 'Heebo', sans-serif;
  font-size: 1rem;
  font-weight: 500;
  color: var(--ink);
  background: var(--surface);
  transition: border-color 0.2s ease;
  direction: rtl;
}

input:focus {
  outline: none;
  border-color: var(--ink);
}

@keyframes shake-input {
  0%, 100% { transform: translateX(0); }
  20%       { transform: translateX(-5px); }
  40%       { transform: translateX(5px); }
  60%       { transform: translateX(-3px); }
  80%       { transform: translateX(3px); }
}
.input-shake {
  animation: shake-input 0.35s ease;
  border-color: var(--error) !important;
  box-shadow: 0 0 0 2px rgba(229,62,62,.12) !important;
}

input::placeholder { color: #bbb; font-weight: 400; }

.field-hint {
  display: block;
  font-size: .78rem;
  color: var(--text-muted);
  margin-top: 5px;
  font-family: 'Heebo', sans-serif;
}

.phone-input-wrapper {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-input);
  overflow: hidden;
  transition: border-color 0.2s ease;
  direction: ltr;
}

.phone-input-wrapper:focus-within {
  border-color: var(--ink);
}

.phone-prefix {
  background: var(--surface-warm);
  padding: 10px 14px;
  font-weight: 600;
  color: var(--text-muted);
  font-size: .95rem;
  border-left: 1px solid var(--border);
  white-space: nowrap;
  direction: ltr;
  font-family: 'Heebo', sans-serif;
}

.phone-input-wrapper input {
  border: none;
  border-radius: 0;
  flex: 1;
}
.phone-input-wrapper input:focus { box-shadow: none; }

/* OTP input */
.otp-input {
  text-align: center;
  font-size: 2rem !important;
  font-weight: 700 !important;
  letter-spacing: .5em;
  color: var(--ink) !important;
}

.otp-info-box {
  background: var(--surface-warm);
  border: 1px solid var(--border);
  border-radius: var(--radius-input);
  padding: 12px 16px;
  margin-bottom: 20px;
  font-size: .9rem;
  color: var(--ink);
  font-family: 'Heebo', sans-serif;
}

/* Bypass dev button */
.bypass-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0 4px;
  color: var(--text-muted);
  font-size: .8rem;
  font-family: 'Heebo', sans-serif;
}
.bypass-divider::before,
.bypass-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}
.btn-bypass {
  font-size: .85rem;
  padding: 10px 20px;
  color: var(--text-muted);
  border-color: var(--border);
}
.btn-bypass:hover { color: var(--ink); border-color: var(--ink); }

.resend-hint {
  text-align: center;
  font-size: .85rem;
  color: var(--text-muted);
  margin-top: 12px;
  font-family: 'Heebo', sans-serif;
}

/* ============================================================
   Buttons
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 32px;
  border-radius: var(--radius-btn);
  font-family: 'Heebo', sans-serif;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: var(--transition);
  width: 100%;
  margin-top: 8px;
}

/* Primary — green CTA (main wizard actions) */
.btn-primary {
  background: var(--green);
  color: #fff;
}
.btn-primary:hover:not(:disabled) {
  background: #3d8a5f;
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(74,156,109,.3);
}
.btn-primary:disabled {
  background: var(--green-disabled);
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* Ghost / outline */
.btn-ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--border);
}
.btn-ghost:hover {
  border-color: var(--ink);
  background: var(--surface-warm);
}

/* Download (dashed) */
.btn-download {
  background: transparent;
  border: 1px dashed var(--border);
  color: var(--text-muted);
  font-size: .85rem;
  margin-top: 4px;
}
.btn-download:hover {
  border-color: var(--ink);
  color: var(--ink);
}
.btn-download:disabled {
  opacity: .5;
  cursor: not-allowed;
}

/* Back link */
.btn-back {
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: 'Heebo', sans-serif;
  font-size: .85rem;
  cursor: pointer;
  padding: 8px 4px;
  width: 100%;
  text-align: right;
  margin-top: 4px;
  transition: color var(--transition);
}
.btn-back:hover { color: var(--ink); }

/* Inline text button */
.btn-inline {
  background: none;
  border: none;
  color: var(--green);
  cursor: pointer;
  font-family: 'Heebo', sans-serif;
  font-size: inherit;
  font-weight: 600;
  text-decoration: underline;
  padding: 0;
}

/* Large CTA */
.btn-large { padding: 14px 40px; font-size: 1.05rem; border-radius: 10px; }

/* ============================================================
   Templates Grid
   ============================================================ */
.templates-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 20px;
  margin-top: 8px;
}

.template-card {
  border-radius: var(--radius-card);
  cursor: pointer;
  border: 2px solid var(--border-light);
  background: var(--surface);
  transition: var(--transition);
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}

.template-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
  border-color: #c0bbb3;
}

.template-card.selected {
  border: 3px solid var(--ink);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

/* Selected checkmark badge */
.template-card.selected::after {
  content: '✓ נבחר';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--ink);
  color: #fff;
  text-align: center;
  font-size: .8rem;
  font-weight: 500;
  padding: 6px 0;
  font-family: 'Heebo', sans-serif;
  z-index: 10;
}

.template-preview {
  position: relative;
  width: 100%;
}

.template-preview canvas {
  display: block;
  width: 100%;
  height: auto;
}

/* Loading placeholder */
.template-preview--loading {
  aspect-ratio: 2 / 3;
  background: var(--surface-warm);
  animation: pulse .9s ease-in-out infinite alternate;
}

@keyframes pulse {
  from { opacity: 1; }
  to   { opacity: .5; }
}

.template-bg-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* CSS overlay text on template cards */
.tpl-photo-label {
  position: absolute;
  font-family: 'Montserrat', sans-serif;
  font-size: 5.5cqh;
  font-weight: 400;
  color: #000000;
  white-space: nowrap;
  pointer-events: none;
  direction: rtl;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}

.tpl-text {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  pointer-events: none;
  text-align: center;
  direction: ltr;
  line-height: 1;
}

.tpl-the-wedding {
  font-family: 'Mr Dafoe', cursive;
  font-size: 3.8cqh;
}

.tpl-names {
  font-family: 'Montserrat', sans-serif;
  font-weight: 400;
  font-size: 4cqh;
  letter-spacing: .04em;
}

.tpl-date {
  font-family: 'Montserrat', sans-serif;
  font-weight: 400;
  font-size: 3cqh;
  letter-spacing: .06em;
}

.template-footer {
  padding: 10px 12px;
  background: var(--surface);
  font-size: .8rem;
  font-weight: 500;
  color: var(--text-muted);
  text-align: center;
  font-family: 'Heebo', sans-serif;
}

.stage3-footer {
  margin-top: 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.selected-notice {
  font-size: .9rem;
  color: var(--text-muted);
  font-weight: 500;
  font-family: 'Heebo', sans-serif;
}

/* ============================================================
   Final Template (Stage 4)
   ============================================================ */
.final-template-wrapper {
  width: 100%;
  margin: 0 auto 28px;
  box-shadow: var(--shadow-lg);
  border-radius: var(--radius-card);
  overflow: hidden;
}

.final-template-wrapper .template-preview { width: 100%; }

/* ============================================================
   Confirmation Checkbox
   ============================================================ */
.confirmation-box {
  background: var(--surface-warm);
  border: 1px solid var(--border);
  border-radius: var(--radius-input);
  padding: 18px 20px;
  margin-bottom: 20px;
}

.checkbox-label {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  cursor: pointer;
  user-select: none;
}

.checkbox-label input[type="checkbox"] { display: none; }

.checkbox-custom {
  width: 22px;
  height: 22px;
  border: 1px solid var(--border);
  border-radius: 5px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  margin-top: 1px;
  background: var(--surface);
}

.checkbox-label input:checked + .checkbox-custom {
  background: var(--green);
  border-color: var(--green);
}

.checkbox-label input:checked + .checkbox-custom::after {
  content: '✓';
  color: #fff;
  font-size: .85rem;
  font-weight: 700;
}

.checkbox-text {
  font-size: .95rem;
  font-weight: 500;
  line-height: 1.5;
  font-family: 'Heebo', sans-serif;
  color: var(--ink);
}

/* ============================================================
   Success Screen
   ============================================================ */
.success-animation {
  font-size: 4rem;
  display: block;
  margin-bottom: 16px;
  animation: bounce .6s ease;
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  40%       { transform: translateY(-18px); }
  60%       { transform: translateY(-8px); }
}

.success-details {
  background: rgba(74,156,109,.07);
  border: 1px solid rgba(74,156,109,.2);
  border-radius: var(--radius-input);
  padding: 14px 18px;
  margin: 16px 0;
  font-size: .9rem;
  color: var(--ink);
  line-height: 1.7;
  font-family: 'Heebo', sans-serif;
}

.success-footer {
  color: var(--text-muted);
  font-size: .95rem;
  margin-top: 8px;
  font-family: 'Heebo', sans-serif;
}

/* ============================================================
   Loading Overlay
   ============================================================ */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  backdrop-filter: blur(3px);
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
}

.loading-card {
  background: var(--surface);
  border-radius: var(--radius-modal);
  padding: 36px 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow-lg);
}

.loading-card p {
  font-weight: 600;
  color: var(--ink);
  font-size: 1rem;
  font-family: 'Heebo', sans-serif;
}

.spinner {
  width: 44px;
  height: 44px;
  border: 3px solid var(--border-light);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   Toast
   ============================================================ */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 12px 24px;
  border-radius: 100px;
  font-size: .9rem;
  font-weight: 500;
  z-index: 9999;
  box-shadow: var(--shadow-lg);
  animation: toastIn .3s ease;
  white-space: nowrap;
  font-family: 'Heebo', sans-serif;
}

.toast.error  { background: var(--error); }
.toast.success{ background: var(--green); }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(12px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ============================================================
   Position Tool
   ============================================================ */
#posToolOverlay {
  position: fixed; inset: 0; z-index: 2000;
  background: rgba(0,0,0,0.85);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 16px; overflow-y: auto;
}
#posToolOverlay.hidden { display: none !important; }

.pos-tool-card {
  background: #fff; border-radius: var(--radius-modal);
  width: 100%; max-width: 360px; overflow: hidden; margin: auto;
  box-shadow: var(--shadow-lg);
}
.pos-tool-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; border-bottom: 1px solid var(--border-light); direction: rtl;
}
.pos-tool-header h3 { margin: 0; font-size: 15px; font-weight: 700; font-family: 'Heebo', sans-serif; }
.pos-tool-close {
  background: none; border: none; font-size: 20px;
  cursor: pointer; color: var(--text-muted); line-height: 1; padding: 0;
}

.pos-tool-canvas-wrap { position: relative; width: 100%; }
.pos-tool-canvas-wrap canvas { width: 100%; height: auto; display: block; }

.pos-tool-bars { position: absolute; inset: 0; pointer-events: none; }

.pt-bar {
  position: absolute;
  width: 28%; height: 20px;
  display: flex; align-items: center; justify-content: center;
  font-size: 8px; font-weight: 800; letter-spacing: 0.5px;
  color: #fff; border-radius: 3px; opacity: 0.82;
  cursor: ns-resize; pointer-events: all;
  transform: translateY(-50%);
  user-select: none; touch-action: none;
}
.pt-bar.left  { left: 0;  border-radius: 0 3px 3px 0; }
.pt-bar.right { right: 0; border-radius: 3px 0 0 3px; }
.pt-bar:hover { opacity: 1; }

.pos-tool-panel {
  padding: 10px 12px 14px;
  border-top: 1px solid var(--border-light);
  background: var(--surface-warm);
}
.pt-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 5px 0; border-bottom: 1px solid #f0f0f0; gap: 8px;
}
.pt-row:last-child { border-bottom: none; }
.pt-row-label {
  font-size: 11px; font-weight: 700; color: #374151;
  display: flex; align-items: center; gap: 5px; flex: 1;
  font-family: 'Heebo', sans-serif;
}
.pt-dot-color {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
}
.pt-nudge {
  display: flex; align-items: center; gap: 4px;
}
.pt-nudge button {
  width: 24px; height: 24px; border: 1px solid var(--border);
  background: #fff; border-radius: 5px; cursor: pointer;
  font-size: 14px; line-height: 1; display: flex;
  align-items: center; justify-content: center; padding: 0;
  transition: background 0.15s;
}
.pt-nudge button:hover { background: var(--surface-warm); }
.pt-val-display {
  font-family: monospace; font-size: 12px; font-weight: 700;
  color: var(--ink); min-width: 36px; text-align: center;
}
.pt-section-sep {
  height: 1px; background: var(--border-light); margin: 10px 0 6px;
}
.pt-section-title {
  font-size: 11px; font-weight: 700; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .5px;
  margin-bottom: 6px; padding: 0 2px;
  font-family: 'Heebo', sans-serif;
}
.pt-copy-btn {
  width: 100%; margin-top: 10px;
  padding: 9px; background: var(--ink); color: #fff;
  border: none; border-radius: var(--radius-btn); font-size: 13px;
  font-weight: 700; cursor: pointer; font-family: 'Heebo', sans-serif;
  transition: background 0.2s;
}
.pt-copy-btn:hover { background: #333; }

/* ============================================================
   Utility
   ============================================================ */
.hidden { display: none !important; }

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 600px) {
  .stage-card { padding: 24px 18px; }
  h1 { font-size: 1.4rem; }
  .templates-grid { grid-template-columns: 1fr; gap: 16px; }
  .step-label { display: none; }
  .progress-bar { max-width: 280px; }
  .app-main { padding: 20px 16px 48px; }
}

@media (max-width: 380px) {
  .templates-grid { grid-template-columns: 1fr; gap: 12px; }
}
