/* ============ Base & variables ============ */
:root {
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --bg: #f4f5fb;
  --surface: #ffffff;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
  --shadow: 0 4px 20px rgba(15, 23, 42, .08);
  --radius: 14px;
}
body.dark {
  --bg: #0f172a;
  --surface: #1e293b;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --border: #334155;
  --shadow: 0 4px 20px rgba(0, 0, 0, .4);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: 'Tajawal', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  transition: background .3s, color .3s;
}
.container { max-width: 1100px; margin: 0 auto; padding: 0 20px; }
a { text-decoration: none; color: inherit; }

/* ============ Buttons ============ */
.btn {
  display: inline-block; padding: 10px 20px; border-radius: 10px;
  border: 1px solid transparent; cursor: pointer; font-family: inherit;
  font-size: 15px; font-weight: 700; transition: all .2s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); transform: translateY(-1px); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { border-color: var(--primary); color: var(--primary); }
.btn-lg { padding: 14px 30px; font-size: 17px; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-icon { background: transparent; border-color: var(--border); color: var(--text); padding: 8px 12px; }
.btn-add { width: 100%; background: transparent; border: 2px dashed var(--border); color: var(--muted); }
.btn-add:hover { border-color: var(--primary); color: var(--primary); }

/* ============ Landing page ============ */
.lp-header { position: sticky; top: 0; background: var(--surface); box-shadow: var(--shadow); z-index: 50; }
.lp-nav { display: flex; align-items: center; justify-content: space-between; height: 64px; gap: 16px; }
.logo { font-size: 22px; font-weight: 800; }
.logo span { color: var(--primary); }
.lp-nav nav { display: flex; gap: 24px; }
.lp-nav nav a:hover { color: var(--primary); }
.hero { text-align: center; padding: 90px 0 70px; }
.hero h1 { font-size: clamp(28px, 5vw, 52px); font-weight: 800; line-height: 1.3; }
.grad { background: linear-gradient(90deg, #4f46e5, #9333ea); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero p { margin: 20px auto; max-width: 600px; color: var(--muted); font-size: 18px; }
.hero-actions { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; margin-top: 26px; }
.hero-badges { margin-top: 30px; display: flex; gap: 20px; justify-content: center; flex-wrap: wrap; color: var(--muted); font-weight: 500; }
.section { padding: 70px 0; }
.section.alt { background: var(--surface); }
.section h2 { text-align: center; font-size: 32px; margin-bottom: 40px; font-weight: 800; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 22px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 26px; box-shadow: var(--shadow); }
.section.alt .card { background: var(--bg); }
.card .icon { font-size: 34px; margin-bottom: 12px; }
.card h3 { margin-bottom: 8px; }
.card p { color: var(--muted); }
.step { width: 44px; height: 44px; border-radius: 50%; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 20px; margin-bottom: 12px; }
.center { text-align: center; margin-top: 40px; }
.tpl-thumb { height: 160px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 26px; font-weight: 800; color: #fff; margin-bottom: 14px; }
.tpl-modern { background: linear-gradient(135deg, #4f46e5, #9333ea); }
.tpl-classic { background: linear-gradient(135deg, #334155, #64748b); }
.tpl-dev { background: linear-gradient(135deg, #0f172a, #16a34a); font-family: 'Roboto Mono', monospace; }
.lp-footer { padding: 30px 0; text-align: center; color: var(--muted); border-top: 1px solid var(--border); }

/* ============ Builder app ============ */
.builder-page { height: 100vh; display: flex; flex-direction: column; overflow: hidden; }
.app-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 18px; background: var(--surface); border-bottom: 1px solid var(--border);
  gap: 12px; flex-wrap: wrap; z-index: 20;
}
.header-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
#templateSelect {
  padding: 9px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-family: inherit; font-weight: 700;
}
.app-main { flex: 1; display: grid; grid-template-columns: minmax(340px, 480px) 1fr; overflow: hidden; }
.form-panel { overflow-y: auto; padding: 18px; border-inline-end: 1px solid var(--border); }
.hint { color: var(--muted); font-size: 13px; margin-bottom: 14px; }
.section-block {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); margin-bottom: 12px; overflow: hidden;
}
.section-block summary {
  padding: 13px 16px; font-weight: 700; cursor: pointer; user-select: none;
  display: flex; align-items: center; gap: 8px; list-style: none;
}
.section-block summary::-webkit-details-marker { display: none; }
.drag-handle { cursor: grab; color: var(--muted); font-size: 18px; }
.section-block.dragging { opacity: .4; }
.section-block.drag-over { outline: 2px dashed var(--primary); }
.fields { padding: 0 16px 16px; display: flex; flex-direction: column; gap: 10px; }
.fields label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 700; color: var(--muted); }
.fields input, .fields textarea, .item-card input, .item-card textarea {
  padding: 10px 12px; border-radius: 9px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font-family: inherit; font-size: 14px;
}
.fields input:focus, .fields textarea:focus { outline: 2px solid var(--primary); border-color: transparent; }
.item-card {
  border: 1px solid var(--border); border-radius: 10px; padding: 12px;
  display: flex; flex-direction: column; gap: 8px; background: var(--bg);
}
.item-card .row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.item-card .item-head { display: flex; justify-content: space-between; align-items: center; }
.item-card .item-head span { font-size: 12px; font-weight: 700; color: var(--muted); }
.btn-del { background: transparent; border: none; color: #ef4444; cursor: pointer; font-size: 15px; }
.items { display: flex; flex-direction: column; gap: 10px; }

/* Preview panel */
.preview-panel { overflow: hidden; display: flex; flex-direction: column; background: #8b8fa3; }
body.dark .preview-panel { background: #0b1120; }
.preview-scroll { overflow: auto; flex: 1; padding: 28px; display: flex; justify-content: center; }
.cv-page {
  width: 210mm; min-height: 297mm; background: #fff; color: #111;
  box-shadow: 0 8px 30px rgba(0,0,0,.3); flex-shrink: 0;
  transform-origin: top center;
}
body.fullscreen-preview .form-panel { display: none; }
body.fullscreen-preview .app-main { grid-template-columns: 1fr; }

/* Toast */
.toast {
  position: fixed; bottom: 24px; inset-inline-start: 50%; transform: translateX(50%);
  background: var(--text); color: var(--bg); padding: 12px 22px; border-radius: 30px;
  font-weight: 700; opacity: 0; pointer-events: none; transition: opacity .3s, bottom .3s; z-index: 100;
}
html[dir="ltr"] .toast { transform: translateX(-50%); }
.toast.show { opacity: 1; bottom: 34px; }

/* ============ Responsive ============ */
@media (max-width: 900px) {
  .builder-page { height: auto; overflow: auto; }
  .app-main { grid-template-columns: 1fr; overflow: visible; }
  .form-panel { border-inline-end: none; border-bottom: 1px solid var(--border); overflow: visible; }
  .preview-scroll { padding: 14px; }
  .cv-page { transform: scale(.45); transform-origin: top right; margin-bottom: calc(-297mm * .55); }
  html[dir="ltr"] .cv-page { transform-origin: top left; }
  .lp-nav nav { display: none; }
}

/* ============ Print ============ */
@media print {
  .app-header, .form-panel, .toast, .hint { display: none !important; }
  .preview-scroll { padding: 0; }
  .cv-page { box-shadow: none; }
}
