/* ============================================================
   واجهة التطبيق
   ============================================================ */

.app { min-height: 100vh; display: flex; flex-direction: column; }
.app-view { flex: 1; }

/* ---------- الترويسة ---------- */
.app-header {
  background: #fff; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 90;
}
.app-header-inner {
  max-width: 1280px; margin: 0 auto; padding: 0 20px;
  display: flex; align-items: center; gap: 24px; height: 62px;
}
.app-nav { display: flex; gap: 4px; flex: 1; }
.app-nav a {
  color: var(--muted); font-weight: 700; font-size: 14px;
  padding: 8px 14px; border-radius: 10px; transition: all .15s;
}
.app-nav a:hover { color: var(--p1); background: var(--g-50); }
.app-nav a.active { color: var(--p1); background: var(--g-50); }
.app-user { display: flex; align-items: center; gap: 10px; }
.user-chip {
  display: flex; align-items: center; gap: 8px; font-size: 13.5px; font-weight: 700;
  background: var(--bg); border: 1px solid var(--line); border-radius: 99px; padding: 5px 13px 5px 6px;
}
html[dir="ltr"] .user-chip { padding: 5px 6px 5px 13px; }
.user-avatar {
  width: 28px; height: 28px; border-radius: 50%; background: var(--grad); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 800;
}

.page-wrap { max-width: 1280px; margin: 0 auto; padding: 28px 20px 60px; }
.page-title { font-size: 26px; font-weight: 900; margin: 0 0 6px; }
.page-sub { color: var(--muted); margin: 0 0 26px; }

/* ---------- المصادقة ---------- */
.auth-wrap {
  min-height: calc(100vh - 62px); display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(600px 300px at 85% 10%, #dcefe5 0%, transparent 60%),
    radial-gradient(500px 300px at 10% 90%, #e9f3ec 0%, transparent 60%),
    var(--bg);
  padding: 30px 16px;
}
.auth-card { width: 100%; max-width: 420px; padding: 34px 30px; }
.auth-logo { display: flex; justify-content: center; margin-bottom: 18px; }
.auth-tabs { display: flex; background: var(--bg); border-radius: 12px; padding: 4px; margin-bottom: 22px; }
.auth-tabs button {
  flex: 1; border: none; background: transparent; border-radius: 9px;
  padding: 9px; font-size: 14px; font-weight: 700; color: var(--muted); transition: all .15s;
}
.auth-tabs button.active { background: #fff; color: var(--p1); box-shadow: var(--shadow-sm); }
.auth-card .btn { width: 100%; margin-top: 6px; }
.auth-foot { text-align: center; margin-top: 16px; font-size: 13.5px; color: var(--muted); }
.auth-foot a { font-weight: 700; cursor: pointer; }

/* ---------- لوحة التحكم ---------- */
.dash-grid { display: grid; grid-template-columns: 1.2fr .8fr; gap: 20px; margin-bottom: 20px; }
.dash-hero { padding: 28px; background: var(--grad); color: #fff; border: none; position: relative; overflow: hidden; }
.dash-hero::after { content: ''; position: absolute; width: 220px; height: 220px; border-radius: 50%; background: rgba(255,255,255,.1); top: -90px; inset-inline-end: -50px; }
.dash-hero h2 { margin: 0 0 8px; font-size: 23px; }
.dash-hero p { margin: 0 0 20px; opacity: .9; font-size: 14.5px; max-width: 420px; }
.dash-progress-card { padding: 24px; }
.dash-progress-card h3 { margin: 0 0 14px; font-size: 16px; }
.progress-track { height: 10px; background: var(--bg); border-radius: 99px; overflow: hidden; margin-bottom: 8px; }
.progress-fill { height: 100%; background: var(--grad); border-radius: 99px; transition: width .6s ease; }
.progress-label { font-size: 13px; color: var(--muted); }
.dash-checklist { list-style: none; margin: 14px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.dash-checklist li { display: flex; align-items: center; gap: 9px; font-size: 13.5px; color: var(--muted); }
.dash-checklist li.done { color: var(--ink); }
.dash-checklist .ck { width: 19px; height: 19px; border-radius: 6px; border: 1.5px solid var(--line); display: flex; align-items: center; justify-content: center; font-size: 11px; color: #fff; flex: 0 0 auto; }
.dash-checklist li.done .ck { background: var(--ok); border-color: var(--ok); }

.dash-sec-title { font-size: 18px; font-weight: 800; margin: 26px 0 14px; display: flex; align-items: center; justify-content: space-between; }
.owned-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.owned-empty { padding: 36px; text-align: center; color: var(--muted); }

/* ---------- محرر البيانات ---------- */
.editor-layout { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 24px; align-items: start; }
.wizard-card { padding: 0; overflow: hidden; }

.wizard-steps {
  display: flex; overflow-x: auto; gap: 4px; padding: 14px 16px;
  background: #fff; border-bottom: 1px solid var(--line);
}
.wizard-steps button {
  display: flex; align-items: center; gap: 7px; white-space: nowrap;
  border: none; background: transparent; color: var(--muted);
  font-size: 13px; font-weight: 700; padding: 8px 13px; border-radius: 9px; transition: all .15s;
}
.wizard-steps button.active { background: var(--g-50); color: var(--p1); }
.wizard-steps button.filled .st-num { background: var(--ok); color: #fff; border-color: var(--ok); }
.st-num {
  width: 21px; height: 21px; border-radius: 50%; border: 1.5px solid var(--line);
  display: flex; align-items: center; justify-content: center; font-size: 11px; flex: 0 0 auto;
}
.wizard-steps button.active .st-num { background: var(--p1); color: #fff; border-color: var(--p1); }

.wizard-body { padding: 24px; }
.wizard-foot { display: flex; justify-content: space-between; padding: 16px 24px; border-top: 1px solid var(--line); background: #fafbfc; }

.bi-field { margin-bottom: 16px; }
.bi-field > label { display: block; font-size: 13px; font-weight: 700; color: var(--ink-2); margin-bottom: 6px; }
.bi-inputs { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.bi-input { position: relative; }
.bi-input input, .bi-input textarea {
  width: 100%; border: 1.5px solid var(--line); border-radius: 10px;
  padding: 10px 13px; font-size: 14.5px; outline: none; transition: border-color .15s, box-shadow .15s;
}
.bi-input input:focus, .bi-input textarea:focus { border-color: var(--p1); box-shadow: 0 0 0 3px rgba(5,150,105,.14); }
.bi-input .bi-tag {
  position: absolute; top: -8px; inset-inline-end: 10px; background: #fff;
  font-size: 10.5px; font-weight: 800; color: var(--muted); padding: 0 6px; border-radius: 4px;
}
.bi-input[data-l="en"] input, .bi-input[data-l="en"] textarea { direction: ltr; }
.bi-input textarea { min-height: 92px; resize: vertical; line-height: 1.6; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }

.item-card { border: 1.5px solid var(--line); border-radius: 14px; padding: 18px; margin-bottom: 14px; position: relative; background: #fff; }
.item-card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.item-card-head b { font-size: 14px; color: var(--p1); }
.item-del { border: none; background: #fef2f2; color: var(--danger); border-radius: 8px; padding: 6px 11px; font-size: 12.5px; font-weight: 700; }
.add-item-btn {
  width: 100%; border: 2px dashed var(--line); background: transparent; border-radius: 12px;
  padding: 13px; color: var(--p1); font-size: 14.5px; font-weight: 700; transition: all .15s;
}
.add-item-btn:hover { border-color: var(--p1); background: var(--g-50); }

.level-input { display: flex; align-items: center; gap: 10px; }
.level-input input[type="range"] { flex: 1; accent-color: var(--p1); }
.level-val { font-size: 12.5px; font-weight: 700; color: var(--p1); min-width: 56px; text-align: center; background: var(--g-50); border-radius: 7px; padding: 4px 8px; }

.photo-row { display: flex; align-items: center; gap: 16px; margin-bottom: 18px; }
.photo-preview {
  width: 76px; height: 76px; border-radius: 50%; background: var(--bg);
  border: 2px dashed var(--line); overflow: hidden; display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 24px; flex: 0 0 auto;
}
.photo-preview img { width: 100%; height: 100%; object-fit: cover; }

.save-state { font-size: 12.5px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.save-state.ok { color: var(--ok); }

/* معاينة حية */
.live-preview { position: sticky; top: 86px; }
.live-preview-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.live-preview-head h4 { margin: 0; font-size: 14px; color: var(--muted); }
.live-preview-box {
  border-radius: 14px; overflow: hidden; border: 1px solid var(--line);
  box-shadow: var(--shadow-sm); background: #f1f5f9; direction: ltr; height: 480px;
}
.live-preview-box .scale-host { transform-origin: top left; }

/* ---------- معرض القوالب ---------- */
.gallery-filters { display: flex; gap: 8px; margin-bottom: 22px; flex-wrap: wrap; }
.gallery-filters button {
  border: 1.5px solid var(--line); background: #fff; color: var(--ink-2);
  border-radius: 99px; padding: 7px 18px; font-size: 13.5px; font-weight: 700;
}
.gallery-filters button.active { background: var(--grad); color: #fff; border-color: transparent; }
.gallery-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; }
.g-card { background: #fff; border: 1px solid var(--line); border-radius: 16px; overflow: hidden; transition: transform .2s, box-shadow .2s; cursor: pointer; position: relative; }
.g-card:hover { transform: translateY(-5px); box-shadow: var(--shadow); }
.g-thumb { height: 280px; overflow: hidden; position: relative; background: #f1f5f9; direction: ltr; }
.g-thumb .cv-page { transform: scale(.345); transform-origin: top left; pointer-events: none; }
.g-thumb::after { content: ''; position: absolute; inset: 0; background: linear-gradient(180deg, transparent 72%, rgba(255,255,255,.96)); }
.g-info { padding: 12px 15px 15px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.g-info h4 { margin: 0; font-size: 15.5px; }
.g-info small { display: block; color: var(--muted); font-size: 11.5px; margin-top: 2px; }
.g-corner { position: absolute; top: 10px; inset-inline-start: 10px; z-index: 2; display: flex; gap: 6px; }
.data-src-note { margin: 0 0 18px; font-size: 13px; color: var(--muted); background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 9px 14px; display: inline-block; }

/* ---------- صفحة المعاينة ---------- */
.preview-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 26px; align-items: start; }
.preview-stage {
  background:
    radial-gradient(400px 200px at 80% 0%, #dcefe5 0%, transparent 55%),
    #eef1f6;
  border: 1px solid var(--line); border-radius: 18px; padding: 30px; display: flex; justify-content: center;
  min-height: 70vh; overflow: auto;
}
.preview-scale-wrap { direction: ltr; }
.preview-scale-host { transform-origin: top left; }
.preview-scale-host .cv-page { box-shadow: 0 18px 50px -18px rgba(15,23,42,.35); margin-bottom: 24px; }
.preview-side { position: sticky; top: 86px; display: flex; flex-direction: column; gap: 14px; }
.preview-side .card { padding: 20px; }
.preview-side h3 { margin: 0 0 4px; font-size: 19px; }
.preview-side .tpl-desc { color: var(--muted); font-size: 13.5px; margin: 0 0 14px; }
.lang-pick { display: flex; background: var(--bg); border-radius: 11px; padding: 4px; margin-bottom: 14px; }
.lang-pick button { flex: 1; border: none; background: transparent; border-radius: 8px; padding: 9px; font-size: 13.5px; font-weight: 700; color: var(--muted); }
.lang-pick button.active { background: #fff; color: var(--p1); box-shadow: var(--shadow-sm); }
.preview-side .btn { width: 100%; }
.preview-badges { display: flex; gap: 7px; flex-wrap: wrap; margin-top: 12px; }
.lock-note { background: #fffbeb; border: 1px solid #fde68a; color: #92400e; border-radius: 11px; padding: 11px 14px; font-size: 13px; }

/* ---------- الدفع ---------- */
.checkout-tpl { display: flex; align-items: center; gap: 14px; background: var(--bg); border-radius: 14px; padding: 14px; margin-bottom: 18px; }
.checkout-tpl .ct-swatch { width: 46px; height: 60px; border-radius: 7px; flex: 0 0 auto; box-shadow: var(--shadow-sm); }
.checkout-tpl b { display: block; }
.checkout-tpl small { color: var(--muted); }
.checkout-price { margin-inline-start: auto; font-size: 21px; font-weight: 900; color: var(--p1); white-space: nowrap; }
.demo-note { background: #fffbeb; border: 1px solid #fde68a; color: #92400e; border-radius: 11px; padding: 10px 14px; font-size: 12.5px; margin-bottom: 16px; }
.card-visual {
  background: linear-gradient(120deg, #1e293b, #334155); border-radius: 16px; color: #fff;
  padding: 18px 20px; margin-bottom: 18px; font-family: monospace; position: relative; overflow: hidden;
}
.card-visual::after { content: ''; position: absolute; width: 130px; height: 130px; border-radius: 50%; background: rgba(255,255,255,.07); top: -50px; inset-inline-end: -30px; }
.card-visual .cv-num { font-size: 17px; letter-spacing: 2px; direction: ltr; text-align: left; margin: 14px 0 10px; }
.card-visual .cv-meta { display: flex; justify-content: space-between; font-size: 12px; opacity: .85; direction: ltr; }
.pay-success { text-align: center; padding: 20px 0; }
.pay-success .ps-ic {
  width: 74px; height: 74px; margin: 0 auto 16px; border-radius: 50%;
  background: #ecfdf5; color: var(--ok); font-size: 34px;
  display: flex; align-items: center; justify-content: center;
  animation: popIn .4s cubic-bezier(.2,1.4,.4,1);
}

/* قصاصات احتفال */
.confetti { position: fixed; top: -12px; z-index: 3000; width: 9px; height: 15px; border-radius: 2px; animation: confettiFall linear forwards; pointer-events: none; }
@keyframes confettiFall { to { transform: translateY(105vh) rotate(660deg); opacity: .9; } }

/* ---------- الاستوديو ---------- */
.builder-page { max-width: 1500px; margin: 0 auto; padding: 18px 16px 40px; }
.builder-topbar { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 16px; flex-wrap: wrap; }
.builder-topbar h2 { margin: 0; font-size: 20px; }
.builder-grid { display: grid; grid-template-columns: 250px minmax(0, 1fr) 250px; gap: 16px; align-items: start; }
.builder-panel { background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 16px; position: sticky; top: 80px; max-height: calc(100vh - 100px); overflow: auto; }
.builder-panel h4 { margin: 0 0 12px; font-size: 13.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.builder-panel h4:not(:first-child) { margin-top: 20px; }
.palette-list { display: flex; flex-direction: column; gap: 7px; }
.palette-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  border: 1.5px solid var(--line); background: #fff; border-radius: 11px;
  padding: 9px 12px; font-size: 13.5px; font-weight: 700; color: var(--ink-2);
  cursor: grab; transition: all .15s; text-align: start;
}
.palette-item:hover { border-color: var(--p1); color: var(--p1); background: var(--g-50); transform: translateX(-2px); }
html[dir="ltr"] .palette-item:hover { transform: translateX(2px); }
.palette-item:active { cursor: grabbing; }

.b-set { margin-bottom: 14px; }
.b-set > label { display: block; font-size: 12.5px; font-weight: 700; color: var(--ink-2); margin-bottom: 7px; }
.seg { display: flex; background: var(--bg); border-radius: 10px; padding: 3px; }
.seg button { flex: 1; border: none; background: transparent; border-radius: 8px; padding: 7px 6px; font-size: 12px; font-weight: 700; color: var(--muted); }
.seg button.active { background: #fff; color: var(--p1); box-shadow: var(--shadow-sm); }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatches button { width: 28px; height: 28px; border-radius: 50%; border: 2.5px solid transparent; outline: 2px solid transparent; transition: all .15s; }
.swatches button.active { border-color: #fff; outline-color: var(--ink); }
.variant-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.v-btn { border: 1.5px solid var(--line); background: #fff; border-radius: 9px; padding: 8px 6px; font-size: 12px; font-weight: 700; color: var(--ink-2); }
.v-btn.active { border-color: var(--p1); background: var(--g-50); color: var(--p1); }
.b-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 18px; }
.b-actions .btn { width: 100%; }

.builder-canvas {
  background: #eef1f6; border: 1px solid var(--line); border-radius: 16px;
  padding: 20px; overflow: auto; max-height: calc(100vh - 100px); direction: ltr;
}
.canvas-scale { transform-origin: top left; margin: 0 auto; }
.canvas-scale .cv-page { box-shadow: 0 14px 40px -16px rgba(15,23,42,.3); }

/* الويدجت داخل الكانفس */
.bw { position: relative; cursor: grab; border-radius: 4px; transition: outline-color .12s; outline: 2px dashed transparent; outline-offset: 3px; }
.bw:hover { outline-color: #bfe0d2; }
.bw.selected { outline: 2px solid var(--p1); }
.bw.dragging { opacity: .4; }
.bw.drop-before::before, .bw.drop-after::after {
  content: ''; position: absolute; left: 0; right: 0; height: 3px; background: var(--p1); border-radius: 3px; z-index: 5;
}
.bw.drop-before::before { top: -5px; }
.bw.drop-after::after { bottom: -5px; }
.bw-empty { padding: 14px; text-align: center; color: var(--muted); background: #f8fafc; border-radius: 8px; font-size: 12px; }

.builder-locked { text-align: center; padding: 70px 24px; }
.builder-locked .bl-ic { font-size: 52px; margin-bottom: 14px; }

/* ---------- استجابة ---------- */
@media (max-width: 1150px) {
  .gallery-grid { grid-template-columns: repeat(3, 1fr); }
  .owned-grid { grid-template-columns: repeat(3, 1fr); }
  .builder-grid { grid-template-columns: 210px minmax(0, 1fr) 220px; }
}
@media (max-width: 960px) {
  .editor-layout { grid-template-columns: 1fr; }
  .live-preview { display: none; }
  .preview-layout { grid-template-columns: 1fr; }
  .preview-side { position: static; }
  .dash-grid { grid-template-columns: 1fr; }
  .gallery-grid { grid-template-columns: repeat(2, 1fr); }
  .owned-grid { grid-template-columns: repeat(2, 1fr); }
  .builder-grid { grid-template-columns: 1fr; }
  .builder-panel { position: static; max-height: none; }
}
@media (max-width: 600px) {
  .gallery-grid { grid-template-columns: 1fr; }
  .owned-grid { grid-template-columns: 1fr; }
  .bi-inputs { grid-template-columns: 1fr; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .app-nav { overflow-x: auto; }
}
