/* ===== أختامي × Arcadia — ثيم هندسي فاتح ===== */

/* شارة الاستضافة المحقونة تغطي أزرار التطبيق على الموبايل — إخفاؤها ضرورة وظيفية */
iframe#nl-badge-frame { display: none !important; }

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
  --paper: #f4f3ef;
  --surface: #ffffff;
  --ink: #16181d;
  --ink2: #4a4f5a;
  --muted: #8a8f9c;
  --line: #e3e1da;
  --line2: #cfccc2;
  --red: #c8283c;
  --red-soft: #fdeef0;
  --green: #1e9e6a;
  --desk: #d8d6cf;
  --radius: 16px;
  --shadow: 0 1px 3px rgba(22,24,29,.06), 0 6px 24px rgba(22,24,29,.07);
  --shadow-lg: 0 4px 12px rgba(22,24,29,.1), 0 16px 48px rgba(22,24,29,.14);
}

html, body {
  height: 100%;
  font-family: "Cairo", "Segoe UI", Tahoma, sans-serif;
  background: var(--paper);
  color: var(--ink);
  overscroll-behavior: none;
}

.view { display: none; height: 100%; flex-direction: column; }
.view.active { display: flex; }
.hidden { display: none !important; }

/* ===== أيقونات ===== */
.ic {
  width: 20px; height: 20px;
  fill: none; stroke: currentColor; stroke-width: 1.9;
  stroke-linecap: round; stroke-linejoin: round;
  flex: 0 0 auto; vertical-align: middle;
}
.ic.big { width: 44px; height: 44px; stroke-width: 1.4; }
.ic.dim { color: var(--muted); width: 18px; height: 18px; }
.flip { transform: scaleX(-1); }

/* ===== أزرار ===== */
.btn {
  border: none; border-radius: 12px;
  padding: 11px 18px; font-size: 15px; font-weight: 700;
  cursor: pointer; font-family: inherit;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform .12s, box-shadow .15s, background .15s;
  touch-action: manipulation; user-select: none;
  line-height: 1;
}
.btn .ic { width: 18px; height: 18px; }
.btn:active { transform: scale(.965); }
.btn-dark { background: var(--ink); color: #fff; box-shadow: 0 2px 8px rgba(22,24,29,.25); }
.btn-dark:active { background: #000; }
.btn-red { background: var(--red); color: #fff; box-shadow: 0 2px 8px rgba(200,40,60,.3); }
.btn-light { background: var(--surface); color: var(--ink); border: 1.5px solid var(--line2); }
.btn-ghost { background: transparent; color: var(--ink2); border: 1.5px solid var(--line); }
.btn-sm { padding: 8px 13px; font-size: 13.5px; border-radius: 10px; }
.btn-sm .ic { width: 16px; height: 16px; }
.btn-block { width: 100%; padding: 14px; font-size: 16px; }

/* أزرار أيقونية */
.tbtn, .cbtn {
  border: none; background: transparent; cursor: pointer;
  width: 38px; height: 38px; border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--ink2); font-family: inherit;
  transition: background .15s, transform .1s;
  touch-action: manipulation;
}
.tbtn:active, .cbtn:active { transform: scale(.9); background: rgba(0,0,0,.07); }
.cbtn { width: 34px; height: 34px; border: 1.5px solid var(--line); background: var(--surface); }
.cbtn .ic { width: 16px; height: 16px; }
.cbtn.danger { color: var(--red); border-color: #f0c8cd; background: var(--red-soft); }

/* ===== الشاشة الرئيسية ===== */
#view-home { overflow-y: auto; }

.brand-bar {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.brand-logo { height: 34px; width: auto; }
.brand-sep { width: 1px; height: 30px; background: var(--line2); }
.brand-app h1 { font-size: 19px; font-weight: 800; line-height: 1.1; }
.brand-app span { font-size: 11px; color: var(--muted); font-weight: 600; }
.privacy-badge {
  margin-inline-start: auto;
  display: flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 700; color: var(--green);
  background: #e8f7f0; padding: 6px 10px; border-radius: 99px;
}
.privacy-badge .ic { width: 14px; height: 14px; }

.home-main { padding: 16px; max-width: 640px; margin: 0 auto; width: 100%; }

/* بطاقة المتابعة */
.resume-card {
  width: 100%; border: 1.5px solid var(--ink); background: var(--surface);
  border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px;
  display: flex; align-items: center; gap: 12px; cursor: pointer;
  font-family: inherit; text-align: start; box-shadow: var(--shadow);
  transition: transform .12s;
}
.resume-card:active { transform: scale(.98); }
.resume-icon {
  width: 42px; height: 42px; border-radius: 12px; background: var(--ink); color: #fff;
  display: flex; align-items: center; justify-content: center;
}
.resume-text { flex: 1; display: flex; flex-direction: column; }
.resume-text b { font-size: 15px; }
.resume-text span { font-size: 12px; color: var(--muted); }

/* منطقة الإسقاط */
.dropzone {
  background: var(--surface); border: 2px dashed var(--line2); border-radius: 20px;
  padding: 30px 20px; text-align: center;
  transition: border-color .2s, background .2s;
}
.dropzone.dragover { border-color: var(--ink); background: #fafaf7; }
.dz-icon {
  width: 64px; height: 64px; margin: 0 auto 12px;
  border-radius: 18px; background: var(--ink); color: #fff;
  display: flex; align-items: center; justify-content: center;
}
.dz-icon .ic { width: 28px; height: 28px; }
.dropzone h2 { font-size: 19px; font-weight: 800; margin-bottom: 4px; }
.dropzone p { font-size: 13px; color: var(--muted); margin-bottom: 18px; }
.dz-buttons { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* المكتبة */
.library-section { margin-top: 24px; }
.section-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.section-head h2 { font-size: 16px; font-weight: 800; display: flex; align-items: center; gap: 7px; }
.section-head h2 .ic { width: 19px; height: 19px; color: var(--red); }

.library-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(108px, 1fr));
  gap: 10px;
}
.lib-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  padding: 10px; text-align: center; position: relative;
  box-shadow: 0 1px 2px rgba(22,24,29,.04);
}
.lib-thumb {
  width: 100%; height: 72px; border-radius: 9px;
  background: repeating-conic-gradient(#eceae4 0% 25%, #f7f6f2 0% 50%) 0 0 / 14px 14px;
  border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.lib-thumb img { max-width: 90%; max-height: 90%; object-fit: contain; }
.lib-name { font-size: 12px; font-weight: 700; margin-top: 7px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lib-type { font-size: 10.5px; color: var(--muted); font-weight: 600; }
.lib-del {
  position: absolute; top: 6px; left: 6px;
  width: 24px; height: 24px; border-radius: 8px; border: none;
  background: rgba(255,255,255,.9); color: var(--red); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 1px 4px rgba(0,0,0,.12);
}
.lib-del .ic { width: 13px; height: 13px; }

.empty-state {
  text-align: center; padding: 26px 20px; color: var(--muted);
  border: 1.5px dashed var(--line2); border-radius: var(--radius);
  font-size: 13px; line-height: 1.9;
}
.empty-state .ic { color: var(--line2); margin-bottom: 8px; }
.empty-state b { color: var(--ink2); font-size: 14.5px; }

.home-footer { margin-top: 26px; display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* ===== المحرر ===== */
#view-editor { overflow: hidden; background: var(--desk); position: relative; }

.editor-topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 6px; padding: 8px 10px;
  background: var(--surface); border-bottom: 1px solid var(--line);
  z-index: 20;
}
.page-nav {
  display: flex; align-items: center; gap: 2px;
  background: var(--paper); border-radius: 12px; padding: 2px;
}
#page-indicator { font-size: 13.5px; min-width: 50px; text-align: center; font-weight: 800; }
.topbar-actions { display: flex; gap: 5px; align-items: center; }

/* شريط وضع الإسقاط */
.place-hint {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--ink); color: #fff; padding: 9px 14px;
  font-size: 13.5px; font-weight: 700; z-index: 19;
  animation: pulseHint 1.6s ease-in-out infinite;
}
@keyframes pulseHint { 50% { background: #2a2e38; } }
.place-hint .btn { color: #fff; border-color: rgba(255,255,255,.3); padding: 3px 8px; }
.place-hint .ic { width: 17px; height: 17px; }

/* أزرار زوم عائمة */
.zoom-fab {
  position: absolute; bottom: 130px; left: 12px; z-index: 25;
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
.fabbtn {
  pointer-events: auto;
  width: 42px; height: 42px; border-radius: 50%;
  border: 1px solid var(--line); background: rgba(255,255,255,.92);
  backdrop-filter: blur(6px);
  box-shadow: var(--shadow);
  cursor: pointer; color: var(--ink);
  display: flex; align-items: center; justify-content: center;
  transition: transform .12s;
  touch-action: manipulation;
}
.fabbtn:active { transform: scale(.88); }
.fabbtn .ic { width: 19px; height: 19px; }

#editor-scroll {
  flex: 1; overflow: auto; position: relative;
  display: flex; align-items: flex-start; justify-content: center;
  padding: 20px 14px 30px;
}
#zoom-wrap { transform-origin: top center; }
#page-wrap {
  position: relative; background: #fff;
  box-shadow: 0 2px 6px rgba(22,24,29,.12), 0 12px 40px rgba(22,24,29,.18);
  touch-action: pan-x pan-y;
  border-radius: 2px;
}
#page-wrap.place-mode { cursor: crosshair; }
#page-wrap.place-mode::after {
  content: ""; position: absolute; inset: 0;
  border: 2px solid var(--red); border-radius: 2px;
  pointer-events: none; opacity: .55;
}
#page-canvas { display: block; }
#placements-layer { position: absolute; inset: 0; }

.placement { position: absolute; cursor: grab; touch-action: none; }
.placement img {
  width: 100%; height: 100%; display: block;
  pointer-events: none; user-select: none; -webkit-user-drag: none;
  mix-blend-mode: multiply;
}
.placement.selected { outline: 1.5px dashed var(--ink); outline-offset: 3px; }
.placement .handle {
  position: absolute; width: 28px; height: 28px; border-radius: 50%;
  background: var(--ink); border: 2.5px solid #fff;
  display: none; align-items: center; justify-content: center;
  color: #fff; z-index: 5;
  box-shadow: 0 2px 8px rgba(0,0,0,.35);
  touch-action: none; font-size: 0;
}
.placement.selected .handle { display: flex; }
.handle svg { width: 14px; height: 14px; }
.h-scale { bottom: -14px; left: -14px; cursor: nwse-resize; }
.h-rotate { top: -40px; right: 50%; margin-right: -14px; cursor: grab; }
.h-rotate::after {
  content: ""; position: absolute; top: 100%; right: 50%;
  width: 2px; height: 26px; background: var(--ink); opacity: .5;
}

/* الشريط السفلي */
.editor-bottom {
  background: var(--surface); border-top: 1px solid var(--line);
  padding: 8px 12px calc(10px + env(safe-area-inset-bottom));
  z-index: 20;
}
.tray-head { font-size: 12px; color: var(--muted); font-weight: 700; margin-bottom: 7px; }
#tray {
  display: flex; gap: 9px; overflow-x: auto; padding-bottom: 3px;
  -webkit-overflow-scrolling: touch;
}
.tray-item {
  flex: 0 0 auto; width: 68px; text-align: center; cursor: pointer;
  border: 2px solid var(--line); border-radius: 12px; padding: 6px 4px;
  background: var(--surface);
  transition: border-color .15s, transform .1s;
}
.tray-item:active { transform: scale(.95); }
.tray-item.armed { border-color: var(--red); background: var(--red-soft); }
.tray-thumb {
  height: 42px; border-radius: 7px;
  background: repeating-conic-gradient(#eceae4 0% 25%, #f7f6f2 0% 50%) 0 0 / 12px 12px;
  display: flex; align-items: center; justify-content: center;
}
.tray-thumb img { max-width: 88%; max-height: 88%; }
.tray-name { font-size: 10.5px; font-weight: 700; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tray-empty { color: var(--muted); font-size: 13px; padding: 10px; }

#selection-controls { margin-bottom: 9px; padding-bottom: 9px; border-bottom: 1px solid var(--line); }
.ctrl-row { display: flex; align-items: center; gap: 9px; }
.ctrl-row input[type=range] { flex: 1; min-width: 70px; accent-color: var(--ink); height: 26px; }
.ctrl-btns { display: flex; gap: 4px; flex-wrap: wrap; }

/* ===== مودالات ===== */
.modal {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(22,24,29,.5); backdrop-filter: blur(4px);
  display: flex; align-items: flex-end; justify-content: center;
}
@media (min-width: 560px) { .modal { align-items: center; padding: 20px; } }
.modal-card {
  background: var(--surface); border-radius: 22px 22px 0 0;
  padding: 20px 20px calc(20px + env(safe-area-inset-bottom));
  width: 100%; max-width: 460px; max-height: 90vh; overflow-y: auto;
  animation: sheetUp .28s cubic-bezier(.2,.9,.3,1);
}
@media (min-width: 560px) { .modal-card { border-radius: 22px; } }
@keyframes sheetUp { from { transform: translateY(40px); opacity: 0; } }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.modal-head h3 { font-size: 17px; font-weight: 800; display: flex; align-items: center; gap: 8px; }

.form-row { margin-bottom: 15px; }
.form-row label { display: flex; align-items: center; gap: 7px; font-size: 13px; font-weight: 700; margin-bottom: 7px; color: var(--ink2); }
.form-row input[type=text] {
  width: 100%; padding: 12px 14px; border-radius: 12px;
  border: 1.5px solid var(--line2); background: var(--paper); color: var(--ink);
  font-size: 15px; font-family: inherit; font-weight: 600;
}
.form-row input[type=text]:focus { outline: none; border-color: var(--ink); }
.form-row input[type=range] { width: 100%; accent-color: var(--ink); }
.form-row small { color: var(--muted); font-size: 11.5px; display: block; margin-top: 4px; }
.val-chip { background: var(--ink); color: #fff; font-size: 11px; padding: 2px 9px; border-radius: 99px; }
.auto-badge {
  display: inline-flex; align-items: center; gap: 4px;
  background: #e8f7f0; color: var(--green); font-size: 10.5px; font-weight: 800;
  padding: 3px 9px; border-radius: 99px;
}
.auto-badge .ic { width: 12px; height: 12px; }

.type-picker { display: flex; gap: 10px; }
.type-opt { flex: 1; cursor: pointer; }
.type-opt input { display: none; }
.type-card {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px; border-radius: 12px; font-weight: 700; font-size: 14.5px;
  border: 2px solid var(--line); color: var(--ink2);
  transition: all .15s;
}
.type-opt input:checked + .type-card { border-color: var(--ink); background: var(--ink); color: #fff; }

.preview-wrap {
  border-radius: 14px; overflow: hidden; margin-bottom: 16px;
  background: #fbfaf7;
  border: 1.5px solid var(--line);
  text-align: center; padding: 14px;
  position: relative;
}
.preview-wrap::before {
  content: "معاينة فوق ورقة"; position: absolute; top: 7px; right: 10px;
  font-size: 10px; color: var(--muted); font-weight: 700;
}
#item-preview { max-width: 100%; max-height: 200px; mix-blend-mode: multiply; }
.modal-actions { display: flex; gap: 10px; }

.help-list { padding-right: 18px; line-height: 2.1; font-size: 14px; }
.help-list b { font-weight: 800; }
.help-list code { background: var(--paper); padding: 2px 7px; border-radius: 6px; font-size: 12px; }
.url-template {
  background: var(--ink); color: #7ee2ae; padding: 10px 12px; border-radius: 10px;
  font-size: 11.5px; direction: ltr; display: block; margin-top: 6px;
  word-break: break-all; user-select: all; font-family: monospace;
}
.help-note {
  font-size: 13px; color: var(--green); margin-top: 12px; line-height: 1.9;
  background: #e8f7f0; padding: 10px 12px; border-radius: 12px; font-weight: 600;
}
.help-note .ic { width: 15px; height: 15px; }

/* تصدير */
.export-card { text-align: center; padding-top: 28px; }
.export-spinner {
  width: 46px; height: 46px; margin: 0 auto 14px;
  border: 4px solid var(--line); border-top-color: var(--ink);
  border-radius: 50%; animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.progress-wrap { height: 8px; background: var(--paper); border-radius: 6px; overflow: hidden; margin: 14px 0 8px; }
#export-progress { height: 100%; width: 0; background: var(--ink); transition: width .3s; border-radius: 6px; }
#export-status { font-size: 12.5px; color: var(--muted); font-weight: 600; }

/* ===== توست ===== */
#toast {
  position: fixed; bottom: 100px; right: 50%; transform: translateX(50%) translateY(16px);
  background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 14px;
  font-size: 14px; font-weight: 700; opacity: 0; pointer-events: none;
  transition: opacity .25s, transform .25s; z-index: 200;
  max-width: 88vw; text-align: center;
  box-shadow: var(--shadow-lg);
}
#toast.show { opacity: 1; transform: translateX(50%) translateY(0); }
#toast.error { background: var(--red); }

/* مؤشر الربط */
.cbtn.active-link { border-color: var(--ink); background: var(--ink); color: #fff; }
.placement.linked-member::before {
  content: ""; position: absolute; top: -6px; right: -6px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--ink); opacity: 0; transition: opacity .2s;
}
