/* ===================================================================
   Danny Khreet — ATS CV Builder (أداة إنشاء السيرة الذاتية)
   RTL, Arabic-first. Builds on the site theme tokens (navy + gold).
   The on-screen ".cv-paper" IS the ATS document: what you see is what
   you print. Print rules show only the paper at A4, single column,
   real selectable text — readable by Applicant Tracking Systems.
   =================================================================== */

.cv-page { font-family: "Tajawal", "Cairo", system-ui, -apple-system, sans-serif; }
.cv-page h1, .cv-page h2, .cv-page h3 { font-family: "Cairo", "Tajawal", system-ui, sans-serif; }

/* ---------- Intro ---------- */
.cv-intro {
  background:
    radial-gradient(900px 460px at 88% -20%, rgba(200,164,92,.18), transparent 60%),
    linear-gradient(155deg, var(--navy-900) 0%, var(--navy-800) 60%, var(--navy-700) 100%);
  color: #eaf0f7;
  padding: clamp(40px, 6vw, 72px) 0 clamp(34px, 5vw, 56px);
}
.cv-intro .eyebrow { color: var(--gold-soft); }
.cv-intro h1 { color: #fff; font-size: clamp(28px, 5.2vw, 46px); line-height: 1.18; margin-bottom: 16px; }
.cv-intro-lead { color: #c3d0e0; font-size: clamp(15.5px, 2.2vw, 18px); line-height: 1.75; max-width: 70ch; }
.cv-intro-lead strong { color: #fff; }

.cv-steps {
  display: flex; flex-wrap: wrap; gap: 12px; margin: 26px 0 18px;
}
.cv-steps li {
  display: flex; align-items: center; gap: 10px;
  background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.12);
  border-radius: 999px; padding: 8px 18px 8px 8px; font-weight: 500; color: #eaf0f7; font-size: 15px;
}
.cv-step-no {
  display: grid; place-items: center; width: 28px; height: 28px; flex: none;
  background: var(--gold); color: var(--navy-900); border-radius: 50%;
  font-family: var(--font-head); font-weight: 800; font-size: 14px;
}
.cv-autosave-note {
  display: inline-flex; align-items: center; gap: 9px;
  color: #aebccd; font-size: 14.5px; margin-top: 6px;
}
.cv-autosave-note svg { width: 18px; height: 18px; flex: none; color: var(--gold); }

/* ---------- App shell ---------- */
.cv-app { padding-top: 24px; padding-bottom: 80px; }

/* ---------- Toolbar ---------- */
.cv-toolbar {
  position: sticky; top: 72px; z-index: 60;
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  background: rgba(255,255,255,.92);
  -webkit-backdrop-filter: saturate(160%) blur(10px); backdrop-filter: saturate(160%) blur(10px);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; margin-bottom: 20px; box-shadow: var(--shadow-sm);
}
.cv-act { padding: 11px 18px; font-size: 15px; }
.cv-act svg { width: 19px; height: 19px; flex: none; }
.cv-act-soft {
  background: #fff; color: var(--navy-800); border-color: var(--line);
  box-shadow: var(--shadow-sm);
}
.cv-act-soft:hover { border-color: var(--gold-soft); transform: translateY(-2px); }
.cv-act-danger { background: #fff; color: #a23b3b; border-color: #f0d4d4; }
.cv-act-danger:hover { background: #fdf3f3; border-color: #e6b9b9; }
.cv-save-state {
  margin-inline-start: auto; font-size: 13.5px; color: var(--slate);
  display: inline-flex; align-items: center; gap: 7px; min-height: 22px;
}
.cv-save-state.is-saved { color: #2e7d52; }
.cv-save-state::before {
  content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; opacity: .55;
}
.cv-save-state:empty::before { display: none; }

/* ---------- Mobile pane switch (hidden on desktop) ---------- */
.cv-panes-switch { display: none; gap: 8px; margin-bottom: 16px; }
.cv-pane-btn {
  flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px; border: 1px solid var(--line); background: #fff; color: var(--slate);
  border-radius: var(--radius-sm); font-family: var(--font-head); font-weight: 700; font-size: 15px; cursor: pointer;
}
.cv-pane-btn svg { width: 19px; height: 19px; }
.cv-pane-btn.is-active { background: var(--navy-800); color: #fff; border-color: var(--navy-800); }

/* ---------- Layout ---------- */
.cv-layout {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 794px);
  gap: 28px; align-items: start;
}

/* ---------- Form ---------- */
.cv-form { display: grid; gap: 18px; min-width: 0; }
.cv-fsec {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  padding: clamp(18px, 2.5vw, 26px); box-shadow: var(--shadow-sm);
}
.cv-fsec-head {
  display: flex; align-items: center; gap: 11px;
  font-size: 19px; color: var(--navy-800); margin-bottom: 6px;
}
.cv-fsec-no {
  display: grid; place-items: center; width: 30px; height: 30px; flex: none;
  background: var(--navy-800); color: var(--gold); border-radius: 9px;
  font-family: var(--font-head); font-weight: 800; font-size: 15px;
}
.cv-opt { font-size: 13.5px; font-weight: 500; color: var(--slate); }
.cv-fsec-sub { color: var(--slate); font-size: 14.5px; margin: 2px 0 14px; line-height: 1.6; }

.cv-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 12px; }
.cv-col-2 { grid-column: 1 / -1; }

.cv-field { display: grid; gap: 6px; min-width: 0; }
.cv-label { font-weight: 600; color: var(--navy-800); font-size: 14.5px; }
.cv-label em { color: #c0392b; font-style: normal; }
.cv-hint { font-size: 12.5px; color: var(--slate); line-height: 1.5; }

.cv-form input[type="text"],
.cv-form input[type="tel"],
.cv-form input[type="email"],
.cv-form textarea,
.cv-form select {
  width: 100%; font-family: inherit; font-size: 15.5px; color: var(--ink);
  background: #fdfdfe; border: 1.5px solid var(--line); border-radius: 10px;
  padding: 11px 13px; transition: border-color .2s var(--ease), box-shadow .2s var(--ease), background .2s var(--ease);
}
.cv-form textarea { resize: vertical; line-height: 1.7; min-height: 84px; }
.cv-form input::placeholder, .cv-form textarea::placeholder { color: #97a4b3; }
.cv-form input:focus, .cv-form textarea:focus, .cv-form select:focus {
  outline: none; border-color: var(--gold); background: #fff;
  box-shadow: 0 0 0 4px rgba(200,164,92,.18);
}
.cv-form select { cursor: pointer; }
.cv-form input:disabled,
.cv-form input:read-only { background: #f0f2f5; color: #9aa3ad; cursor: not-allowed; }
.cv-field.is-disabled .cv-label { color: #9aa3ad; }
.cv-field-note { font-size: 12px; color: var(--slate); }

.cv-check { display: inline-flex; align-items: center; gap: 9px; font-size: 14.5px; color: var(--navy-800); cursor: pointer; user-select: none; }
.cv-check input { width: 19px; height: 19px; accent-color: var(--navy-700); cursor: pointer; }
.cv-current-wrap { align-self: end; padding-bottom: 9px; }

/* ---------- Repeatable items ---------- */
.cv-items { display: grid; gap: 14px; }
.cv-item {
  border: 1.5px solid var(--line); border-radius: var(--radius-sm);
  padding: 16px; background: #fbfcfe; position: relative;
}
.cv-item-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 4px; }
.cv-item-title { font-family: var(--font-head); font-weight: 700; color: var(--navy-700); font-size: 14px; }
.cv-item-tools { display: flex; gap: 6px; }
.cv-move, .cv-del {
  border: 1px solid var(--line); background: #fff; color: var(--slate);
  border-radius: 8px; cursor: pointer; font-family: inherit; font-size: 13px; padding: 5px 9px;
  transition: background .2s, color .2s, border-color .2s;
}
.cv-move { font-size: 15px; line-height: 1; min-width: 32px; }
.cv-move:hover { background: var(--navy-800); color: #fff; border-color: var(--navy-800); }
.cv-del { color: #a23b3b; font-weight: 600; }
.cv-del:hover { background: #fdecec; border-color: #e6b9b9; }
.cv-del-inline { position: absolute; top: 10px; left: 12px; }
.cv-item-inline { padding-top: 40px; }

.cv-add {
  display: inline-flex; align-items: center; gap: 8px; margin-top: 14px;
  background: rgba(200,164,92,.10); border: 1.5px dashed var(--gold); color: var(--navy-800);
  border-radius: 10px; padding: 11px 18px; cursor: pointer;
  font-family: var(--font-head); font-weight: 700; font-size: 15px;
  transition: background .2s var(--ease), transform .2s var(--ease);
}
.cv-add span { font-size: 18px; line-height: 1; }
.cv-add:hover { background: rgba(200,164,92,.18); transform: translateY(-1px); }

/* ---------- Preview ---------- */
.cv-preview-wrap { position: sticky; top: 140px; min-width: 0; }
.cv-preview-bar {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px;
  margin-bottom: 12px;
}
.cv-preview-title {
  display: inline-flex; align-items: center; gap: 8px;
  font-family: var(--font-head); font-weight: 700; color: var(--navy-800); font-size: 15.5px;
}
.cv-preview-title svg { width: 18px; height: 18px; color: var(--gold); }
.cv-dir-switch { display: inline-flex; align-items: center; gap: 6px; }
.cv-dir-label { font-size: 13px; color: var(--slate); }
.cv-dir-btn {
  border: 1px solid var(--line); background: #fff; color: var(--slate);
  border-radius: 8px; padding: 6px 14px; cursor: pointer; font-family: inherit; font-weight: 600; font-size: 13.5px;
}
.cv-dir-btn.is-active { background: var(--navy-800); color: #fff; border-color: var(--navy-800); }

.cv-paper-scroll {
  background: #e7ecf3; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; overflow: auto;
  max-height: calc(100vh - 180px); max-height: calc(100dvh - 180px);
}

/* ===== The ATS document itself ===== */
.cv-paper {
  width: 100%; max-width: 794px; margin: 0 auto;
  background: #fff; color: #1a1a1a;
  font-family: "Tajawal", "Cairo", system-ui, sans-serif;
  font-size: 14px; line-height: 1.65;
  padding: 16mm; box-shadow: 0 2px 6px rgba(8,24,46,.10), 0 14px 40px rgba(8,24,46,.14);
  box-sizing: border-box; border-radius: 2px;
}
.cv-paper * { box-sizing: border-box; }

.cv-doc-empty { color: #8a93a0; text-align: center; padding: 40px 10px; font-size: 15px; line-height: 1.8; }

.cv-doc-header { padding-bottom: 12px; margin-bottom: 14px; border-bottom: 2px solid #0a2342; }
.cv-doc-name { font-size: 26px; font-weight: 800; color: #0a2342; line-height: 1.2; margin: 0 0 2px; }
.cv-doc-title { font-size: 15.5px; font-weight: 600; color: #b8860b; margin: 0 0 9px; }
.cv-doc-contact { display: flex; flex-wrap: wrap; gap: 4px 0; font-size: 12.7px; color: #333; }
.cv-doc-contact .ci { display: inline-flex; align-items: center; overflow-wrap: anywhere; unicode-bidi: isolate; }
.cv-doc-contact .ci + .ci::before { content: "•"; margin: 0 9px; color: #b0b8c2; }

.cv-doc-section { margin-top: 15px; }
.cv-doc-section:first-of-type { margin-top: 4px; }
.cv-doc-h2 {
  font-size: 14.5px; font-weight: 800; color: #0a2342; letter-spacing: .02em;
  margin: 0 0 8px; padding-bottom: 4px; border-bottom: 1px solid #c9d2de;
}
.cv-doc-p { font-size: 13.6px; color: #2a2a2a; margin: 0; line-height: 1.7; white-space: pre-wrap; }

.cv-doc-item { margin-bottom: 11px; }
.cv-doc-item:last-child { margin-bottom: 0; }
.cv-doc-item-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
}
.cv-doc-role { font-size: 14px; font-weight: 700; color: #1a1a1a; }
.cv-doc-org { font-size: 13.5px; color: #444; font-weight: 500; }
.cv-doc-dates { font-size: 12.3px; color: #666; white-space: nowrap; flex: none; unicode-bidi: isolate; }
.cv-doc-details { font-size: 12.8px; color: #555; margin-top: 2px; }
/* Bullets are real DOM glyph spans (see renderPreview) so they render reliably
   on screen, in the html2canvas export image, and in print — and never depend
   on the "background graphics" print setting. */
.cv-doc-bullets { margin: 5px 0 0; padding: 0; list-style: none; }
.cv-doc-bullets li { font-size: 13.3px; color: #2a2a2a; line-height: 1.6; margin-bottom: 2px; }
.cv-doc-bullet { color: #b8860b; font-weight: 700; }
.cv-doc-skills { font-size: 13.3px; color: #2a2a2a; line-height: 1.9; }
.cv-doc-langs { font-size: 13.4px; color: #2a2a2a; }
.cv-doc-langs .lg + .lg::before { content: "•"; margin: 0 8px; color: #b0b8c2; }

/* LTR variant for English résumés */
.cv-paper[dir="ltr"] { font-family: "Inter", "Tajawal", system-ui, sans-serif; }

/* ---------- ATS tips ---------- */
.cv-tips {
  margin-top: 26px; background: #fff; border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow-sm); overflow: hidden;
}
.cv-tips summary {
  display: flex; align-items: center; gap: 10px; cursor: pointer; list-style: none;
  padding: 18px 22px; font-family: var(--font-head); font-weight: 700; color: var(--navy-800); font-size: 16px;
}
.cv-tips summary::-webkit-details-marker { display: none; }
.cv-tips summary svg { width: 20px; height: 20px; color: var(--gold); flex: none; }
.cv-tips summary::after { content: "▾"; margin-inline-start: auto; color: var(--slate); transition: transform .25s var(--ease); }
.cv-tips[open] summary::after { transform: rotate(180deg); }
.cv-tips-body { padding: 0 22px 22px; color: var(--slate); line-height: 1.8; font-size: 15px; }
.cv-tips-body ul { margin: 10px 0; display: grid; gap: 7px; }
.cv-tips-body li { position: relative; padding-inline-start: 20px; }
.cv-tips-body li::before { content: "✓"; position: absolute; inset-inline-start: 0; color: var(--gold); font-weight: 700; }
.cv-tips-tip { background: var(--bg-soft); border-radius: 10px; padding: 12px 16px; margin-top: 12px; color: var(--navy-800); }

/* ---------- Modal ---------- */
.cv-modal {
  position: fixed; inset: 0; z-index: 2000; display: grid; place-items: center;
  background: rgba(8,24,46,.55); padding: 20px; animation: cvFade .2s var(--ease);
}
.cv-modal[hidden] { display: none; }
@keyframes cvFade { from { opacity: 0; } to { opacity: 1; } }
.cv-modal-box {
  position: relative; background: #fff; border-radius: var(--radius); max-width: 480px; width: 100%;
  padding: 30px 28px; box-shadow: var(--shadow-lg); animation: cvPop .25s var(--ease);
}
@keyframes cvPop { from { opacity: 0; transform: scale(.96) translateY(8px); } to { opacity: 1; transform: none; } }
.cv-modal-x {
  position: absolute; top: 12px; left: 14px; background: none; border: 0; cursor: pointer;
  font-size: 18px; color: var(--slate); line-height: 1; padding: 6px;
}
.cv-modal-box h3 { color: var(--navy-800); font-size: 21px; margin-bottom: 12px; }
.cv-modal-box p { color: var(--slate); font-size: 15px; line-height: 1.7; }
.cv-modal-steps { display: grid; gap: 10px; margin: 16px 0; counter-reset: step; }
.cv-modal-steps li {
  position: relative; padding-inline-start: 40px; color: var(--ink); font-size: 15px; line-height: 1.6; counter-increment: step;
}
.cv-modal-steps li::before {
  content: counter(step); position: absolute; inset-inline-start: 0; top: 0;
  width: 28px; height: 28px; display: grid; place-items: center;
  background: var(--navy-800); color: var(--gold); border-radius: 50%; font-weight: 800; font-size: 14px;
}
.cv-modal-note { background: var(--bg-soft); border-radius: 10px; padding: 11px 15px; font-size: 13.5px; margin-top: 4px; }
.cv-modal-inapp { background: #fff7e8; border: 1px solid var(--gold-soft); border-radius: 10px; padding: 12px 15px; font-size: 13.8px; line-height: 1.7; margin-top: 12px; color: var(--ink); }
.cv-modal-inapp[hidden] { display: none; }
.cv-modal-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 22px; }
.cv-modal-actions .btn { flex: 1; min-width: 160px; }

/* ---------- Toast ---------- */
.cv-toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%) translateY(20px);
  z-index: 2200; background: var(--navy-800); color: #fff; padding: 13px 22px; border-radius: 999px;
  font-weight: 600; font-size: 15px; box-shadow: var(--shadow-lg); opacity: 0; transition: opacity .25s var(--ease), transform .25s var(--ease);
  max-width: 90vw; text-align: center;
}
.cv-toast[hidden] { display: none; }
.cv-toast.is-show { opacity: 1; transform: translateX(-50%) translateY(0); }
.cv-toast.is-error { background: #a23b3b; }

/* ---------- Mobile primary CTA (thumb zone) — hidden on desktop ---------- */
.cv-mobile-cta {
  display: none; position: fixed; left: 0; right: 0; bottom: 0; z-index: 80;
  padding: 11px 16px calc(11px + env(safe-area-inset-bottom, 0px));
  background: rgba(255,255,255,.97);
  -webkit-backdrop-filter: saturate(160%) blur(12px); backdrop-filter: saturate(160%) blur(12px);
  border-top: 1px solid var(--line); box-shadow: 0 -6px 22px rgba(8,24,46,.12);
}
.cv-mobile-cta .btn { width: 100%; padding: 15px; font-size: 16.5px; }
.cv-mobile-cta .btn svg { width: 20px; height: 20px; }

/* ===================================================================
   Responsive
   =================================================================== */
@media (max-width: 980px) {
  .cv-layout { grid-template-columns: 1fr; }
  .cv-preview-wrap { position: static; }
  .cv-paper-scroll { max-height: none; padding: 12px; }
  .cv-app.view-fill .cv-preview-wrap { display: none; }
  .cv-app.view-preview .cv-form { display: none; }

  /* free vertical space: the site header scrolls away on this focused tool */
  .cv-page .site-header { position: static; }

  /* touch-friendly, zoom-proof inputs (iOS zooms in when font-size < 16px) */
  .cv-form input[type="text"],
  .cv-form input[type="tel"],
  .cv-form input[type="email"],
  .cv-form textarea,
  .cv-form select { font-size: 16px; padding: 13px 14px; }
  .cv-check input { width: 22px; height: 22px; }

  /* sticky segmented view switch — always lets the user flip form/preview */
  .cv-panes-switch {
    display: flex; position: sticky; top: 0; z-index: 70;
    gap: 6px; padding: 6px; margin: 0 0 16px;
    background: rgba(255,255,255,.96);
    -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
    border: 1px solid var(--line); border-radius: 999px; box-shadow: var(--shadow-sm);
  }
  .cv-pane-btn { border: 0; border-radius: 999px; padding: 11px; }
  .cv-pane-btn.is-active { box-shadow: var(--shadow-sm); }

  /* compact, non-sticky toolbar (primary action moves to the fixed bottom bar) */
  .cv-toolbar { position: static; gap: 8px; padding: 10px; }
  #btnPdf { display: none; }
  .cv-act { flex: 1 1 calc(50% - 5px); justify-content: center; padding: 13px 10px; font-size: 14.5px; }
  .cv-save-state { order: 9; width: 100%; margin-inline-start: 0; justify-content: center; }

  /* surface the fixed bottom CTA + keep content & WhatsApp clear of it */
  .cv-mobile-cta { display: flex; }
  .cv-app { padding-bottom: 92px; }
  .cv-page .wa-float { bottom: calc(86px + env(safe-area-inset-bottom, 0px)); }

  /* condense the intro so the tool is reachable sooner */
  .cv-intro { padding: 26px 0 22px; }
  .cv-intro-lead { font-size: 15px; }
  .cv-autosave-note { font-size: 13px; }
}

@media (max-width: 560px) {
  .cv-grid-2 { grid-template-columns: 1fr; }
  .cv-current-wrap { padding-bottom: 0; align-self: start; }
  .cv-paper { padding: 12mm 9mm; font-size: 13px; }
  .cv-fsec { padding: 18px 15px; }
  .cv-fsec-head { font-size: 17.5px; }
  .cv-steps { gap: 8px; }
  .cv-steps li { font-size: 13.5px; padding: 7px 13px 7px 7px; }

  /* larger touch targets for per-item controls */
  .cv-move, .cv-del { min-height: 38px; padding: 8px 12px; }
  .cv-move { min-width: 40px; }
  .cv-item-tools { gap: 8px; }
  .cv-add { width: 100%; justify-content: center; padding: 14px; }
}

/* ===================================================================
   PRINT — show ONLY the résumé paper, at A4, single column.
   Real text + standard structure = readable by ATS.
   =================================================================== */
@media print {
  /* Vertical margins live on @page so EVERY page gets the same top/bottom
     breathing room — page 2+ no longer starts flush against the paper edge.
     Horizontal margins stay on .cv-paper padding below. Keeping the left/right
     @page margins at 0 still avoids the browser's default header/footer there. */
  @page { size: A4; margin: 14mm 0; }

  /* hide everything except the document */
  .site-header, .site-footer, .wa-float, .skip-link,
  .cv-intro, .cv-toolbar, .cv-panes-switch, .cv-form,
  .cv-preview-bar, .cv-tips, .cv-modal, .cv-toast, .cv-mobile-cta {
    display: none !important;
  }

  html, body { background: #fff !important; margin: 0 !important; padding: 0 !important; }
  main, .cv-app, .cv-layout, .cv-preview-wrap, .cv-paper-scroll {
    display: block !important; position: static !important;
    margin: 0 !important; padding: 0 !important; border: 0 !important;
    background: #fff !important; box-shadow: none !important;
    max-width: none !important; width: auto !important; max-height: none !important; overflow: visible !important;
  }

  .cv-paper {
    display: block !important; box-shadow: none !important; border-radius: 0 !important;
    margin: 0 !important; width: 100% !important; max-width: none !important;
    padding: 0 16mm !important; font-size: 11pt; color: #000 !important;
  }
  .cv-paper, .cv-paper * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }

  /* Keep individual entries together, but NOT whole sections (a tall section
     must be allowed to split, or it leaves the prior page half-blank). */
  .cv-doc-item { break-inside: avoid; page-break-inside: avoid; }

  /* A section heading must never strand at the foot of a page, separated from
     its body. break-after:avoid alone is unreliable across browsers, so we
     also pin the element right after the heading with break-before:avoid —
     the two travel to the next page together. The body itself (a list or a
     stack of entries) can still split internally, so a tall section never
     leaves the previous page half-blank. */
  .cv-doc-h2 { break-after: avoid; page-break-after: avoid; }
  .cv-doc-h2 + * { break-before: avoid; page-break-before: avoid; }
}
