/* محرر PDF — Gulf Fashion : الأنماط المشتركة */
@font-face { font-family: "PDF-dejavu"; src: url("fonts/DejaVuSans.ttf") format("truetype"); font-weight: 400; }
@font-face { font-family: "PDF-dejavu"; src: url("fonts/DejaVuSans-Bold.ttf") format("truetype"); font-weight: 700; }
@font-face { font-family: "PDF-freeserif"; src: url("fonts/FreeSerif.ttf") format("truetype"); font-weight: 400; }
@font-face { font-family: "PDF-freeserif"; src: url("fonts/FreeSerifBold.ttf") format("truetype"); font-weight: 700; }
@font-face { font-family: "PDF-carlito"; src: url("fonts/Carlito-Regular.ttf") format("truetype"); font-weight: 400; }
@font-face { font-family: "PDF-carlito"; src: url("fonts/Carlito-Bold.ttf") format("truetype"); font-weight: 700; }
@font-face { font-family: "PDF-liberation-sans"; src: url("fonts/LiberationSans-Regular.ttf") format("truetype"); font-weight: 400; }
@font-face { font-family: "PDF-liberation-sans"; src: url("fonts/LiberationSans-Bold.ttf") format("truetype"); font-weight: 700; }
@font-face { font-family: "PDF-liberation-serif"; src: url("fonts/LiberationSerif-Regular.ttf") format("truetype"); font-weight: 400; }
@font-face { font-family: "PDF-liberation-serif"; src: url("fonts/LiberationSerif-Bold.ttf") format("truetype"); font-weight: 700; }

:root {
  --bg: #f3f5f8;
  --panel: #ffffff;
  --border: #dfe4ea;
  --text: #1f2933;
  --muted: #6b7a8c;
  --accent: #0f6e8c;
  --accent-2: #0b5468;
  --accent-soft: #e3f1f5;
  --danger: #c0392b;
  --warn: #b7791f;
  --ok: #2e8b57;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 14px rgba(16, 24, 40, .06);
  --radius: 10px;
  --font: "Segoe UI", Tahoma, "Noto Naskh Arabic", "Noto Sans Arabic", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 14px;
  direction: rtl; -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; }
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 8px;
  border: 1px solid var(--border); background: #fff; color: var(--text); line-height: 1.2; white-space: nowrap;
  transition: background .12s, border-color .12s, box-shadow .12s;
}
.btn:hover { background: #f7f9fb; border-color: #c9d2dc; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { color: var(--danger); border-color: #efc3bd; }
.btn.danger:hover { background: #fdf1ef; }
.btn.small { padding: 4px 8px; font-size: 12.5px; border-radius: 6px; }
.btn.icon { padding: 6px 8px; }
.btn.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-2); }
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; background: #eef2f6; color: var(--muted);
}
.badge.ok { background: #e6f4ec; color: var(--ok); }
.badge.warn { background: #fbf1dd; color: var(--warn); }
.badge.accent { background: var(--accent-soft); color: var(--accent-2); }
.badge.danger { background: #fbe9e7; color: var(--danger); }
.muted { color: var(--muted); }
.hidden { display: none !important; }
input[type=text], input[type=number], input[type=password], input[type=search], select, textarea {
  padding: 7px 9px; border: 1px solid var(--border); border-radius: 8px; background: #fff; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(15, 110, 140, .15); }
label.f { display: block; font-size: 12.5px; color: var(--muted); margin: 8px 0 4px; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
hr.sep { border: 0; border-top: 1px solid var(--border); margin: 12px 0; }

/* ---- شريط علوي ---- */
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 10px 18px; background: #fff; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
}
.topbar .brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; color: var(--accent-2); }
.topbar .brand .logo {
  width: 32px; height: 32px; border-radius: 8px; background: linear-gradient(135deg, var(--accent), #2aa6c9); color: #fff;
  display: grid; place-items: center; font-size: 15px; font-weight: 800;
}
.topbar .spacer { flex: 1; }

/* ---- تسجيل الدخول ---- */
.login-wrap { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login-card { width: 360px; padding: 28px; }
.login-card h1 { margin: 0 0 4px; font-size: 20px; color: var(--accent-2); }
.login-card .error { background: #fbe9e7; color: var(--danger); padding: 8px 10px; border-radius: 8px; margin-top: 10px; font-size: 13px; }

/* ---- المكتبة ---- */
.lib-main { max-width: 1240px; margin: 0 auto; padding: 18px; }
.dropzone {
  border: 2px dashed #b9c6d3; border-radius: var(--radius); padding: 22px; text-align: center; background: #fff;
  color: var(--muted); transition: border-color .15s, background .15s; cursor: pointer;
}
.dropzone.drag { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-2); }
.dropzone strong { color: var(--text); }
.upload-list { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.upload-item { display: flex; align-items: center; gap: 10px; padding: 8px 12px; font-size: 13px; }
.upload-item .bar { flex: 1; height: 6px; background: #eef2f6; border-radius: 4px; overflow: hidden; }
.upload-item .bar > i { display: block; height: 100%; background: var(--accent); width: 30%; animation: pulse 1s infinite alternate; }
@keyframes pulse { from { opacity: .5; } to { opacity: 1; } }
.lib-toolbar { display: flex; gap: 10px; align-items: center; margin: 18px 0 10px; flex-wrap: wrap; }
.lib-toolbar input[type=search] { max-width: 320px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: #fff; }
.seg button { border: 0; background: transparent; padding: 6px 12px; color: var(--muted); }
.seg button.active { background: var(--accent-soft); color: var(--accent-2); font-weight: 600; }
.doc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.doc-card { display: flex; flex-direction: column; overflow: hidden; transition: transform .12s, box-shadow .12s; }
.doc-card:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(16, 24, 40, .1); }
.doc-card .thumb { height: 190px; background: #eef2f6 center/cover no-repeat; border-bottom: 1px solid var(--border); position: relative; cursor: pointer; }
.doc-card .thumb img { width: 100%; height: 100%; object-fit: cover; object-position: top; display: block; }
.doc-card .thumb .pages { position: absolute; bottom: 6px; left: 6px; background: rgba(0, 0, 0, .55); color: #fff; font-size: 11px; padding: 2px 7px; border-radius: 999px; }
.doc-card .body { padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; }
.doc-card .title { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-card .badges { display: flex; gap: 5px; flex-wrap: wrap; }
.doc-card .meta { font-size: 11.5px; color: var(--muted); }
.doc-card .actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.empty { text-align: center; color: var(--muted); padding: 40px; }
.section-title { font-size: 15px; font-weight: 700; margin: 26px 0 10px; color: var(--accent-2); }
.asset-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.asset-card { padding: 8px; text-align: center; font-size: 12px; }
.asset-card .img { height: 70px; background: repeating-conic-gradient(#eee 0 25%, #fff 0 50%) 0 0/14px 14px; border-radius: 6px; display: grid; place-items: center; overflow: hidden; }
.asset-card .img img { max-width: 100%; max-height: 100%; }
.profile-list { display: flex; flex-direction: column; gap: 8px; }
.profile-item { padding: 10px 12px; display: flex; align-items: center; gap: 10px; }
.kv-list { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }

/* ---- حوارات ---- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: grid; place-items: center; z-index: 200; }
.modal { width: min(560px, 94vw); max-height: 90vh; overflow: auto; padding: 18px 20px; }
.modal h3 { margin: 0 0 10px; font-size: 16px; }
.modal .foot { display: flex; justify-content: flex-start; gap: 8px; margin-top: 14px; }
.toast-wrap { position: fixed; bottom: 18px; right: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 300; }
.toast { background: #1f2933; color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); font-size: 13px; max-width: 360px; }
.toast.ok { background: var(--ok); }
.toast.err { background: var(--danger); }

/* ---- المحرر ---- */
.editor-root { height: 100vh; display: flex; flex-direction: column; }
.editor-top { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: #fff; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.editor-top .title-input { font-weight: 700; font-size: 15px; border: 1px solid transparent; background: transparent; padding: 5px 8px; border-radius: 6px; min-width: 220px; }
.editor-top .title-input:hover, .editor-top .title-input:focus { border-color: var(--border); background: #fff; }
.mode-tabs { display: inline-flex; background: #eef2f6; border-radius: 10px; padding: 3px; gap: 2px; }
.mode-tabs button { border: 0; background: transparent; padding: 6px 12px; border-radius: 8px; color: var(--muted); font-weight: 600; }
.mode-tabs button.active { background: #fff; color: var(--accent-2); box-shadow: 0 1px 3px rgba(0, 0, 0, .08); }
.save-state { font-size: 12px; color: var(--muted); min-width: 70px; text-align: center; }
.save-state.dirty { color: var(--warn); }
.save-state.saved { color: var(--ok); }
.editor-body { flex: 1; display: flex; min-height: 0; }
.side { width: 330px; background: #fff; border-left: 1px solid var(--border); overflow-y: auto; padding: 12px; }
.side h4 { margin: 10px 0 6px; font-size: 13px; color: var(--accent-2); }
.side .tools { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.side .tools .btn { justify-content: center; flex-direction: column; gap: 2px; padding: 8px 4px; font-size: 12px; }
.side .tools .btn .ic { font-size: 18px; line-height: 1; }
.prop-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 8px; }
.prop-grid .full { grid-column: 1 / -1; }
.field-list { display: flex; flex-direction: column; gap: 6px; }
.field-row { padding: 7px 9px; border: 1px solid var(--border); border-radius: 8px; background: #fff; cursor: pointer; }
.field-row:hover { border-color: #c5d0db; }
.field-row.active { border-color: var(--accent); background: var(--accent-soft); }
.field-row .lbl { font-size: 12.5px; color: var(--muted); display: flex; justify-content: space-between; gap: 6px; }
.field-row .lbl b { color: var(--text); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.field-row input, .field-row select, .field-row textarea { margin-top: 4px; padding: 5px 7px; font-size: 13px; }
.viewer { flex: 1; overflow: auto; background: #cfd6de; position: relative; }
.viewer-inner { padding: 20px; display: flex; flex-direction: column; align-items: center; gap: 20px; min-width: min-content; }
.page-wrap { position: relative; background: #fff; box-shadow: 0 2px 12px rgba(0, 0, 0, .25); direction: ltr; }
.page-wrap img.page-img { display: block; user-select: none; -webkit-user-drag: none; }
.page-wrap .overlay { position: absolute; inset: 0; }
.page-wrap .overlay.drawing { cursor: crosshair; }
.page-num { position: absolute; top: -18px; right: 0; font-size: 11px; color: #334; direction: rtl; }
.zoombar { position: sticky; bottom: 10px; display: flex; justify-content: center; pointer-events: none; }
.zoombar .inner { pointer-events: auto; display: inline-flex; gap: 4px; background: #fff; padding: 4px; border-radius: 10px; box-shadow: var(--shadow); border: 1px solid var(--border); align-items: center; }
.zoombar .inner span { min-width: 48px; text-align: center; font-size: 12.5px; }

/* عناصر الطبقة */
.ov-field { position: absolute; border: 1px dashed rgba(15, 110, 140, .55); background: rgba(15, 110, 140, .06); box-sizing: border-box; }
.ov-field.low { border-color: rgba(183, 121, 31, .7); background: rgba(183, 121, 31, .07); }
.ov-field:hover { background: rgba(15, 110, 140, .12); }
.ov-field.selected { border: 1.5px solid var(--accent); background: rgba(15, 110, 140, .12); box-shadow: 0 0 0 2px rgba(15, 110, 140, .18); z-index: 5; }
.ov-field .tag {
  position: absolute; top: -16px; right: -1px; font-size: 10px; background: var(--accent); color: #fff; padding: 1px 6px; border-radius: 4px 4px 0 0;
  white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; direction: rtl; pointer-events: none;
}
.ov-field.low .tag { background: var(--warn); }
.ov-field .tag.left { right: auto; left: -1px; }
.ov-field .type-ic { position: absolute; bottom: 0; left: 0; font-size: 9px; color: var(--accent-2); opacity: .8; pointer-events: none; padding: 0 2px; }
.handle { position: absolute; width: 8px; height: 8px; background: #fff; border: 1.5px solid var(--accent); border-radius: 2px; z-index: 6; }
.handle.nw { left: -5px; top: -5px; cursor: nwse-resize; } .handle.ne { right: -5px; top: -5px; cursor: nesw-resize; }
.handle.sw { left: -5px; bottom: -5px; cursor: nesw-resize; } .handle.se { right: -5px; bottom: -5px; cursor: nwse-resize; }
.handle.n { left: calc(50% - 4px); top: -5px; cursor: ns-resize; } .handle.s { left: calc(50% - 4px); bottom: -5px; cursor: ns-resize; }
.handle.w { left: -5px; top: calc(50% - 4px); cursor: ew-resize; } .handle.e { right: -5px; top: calc(50% - 4px); cursor: ew-resize; }
.ov-field.movable { cursor: move; }

/* وضع التعبئة */
.fill-input {
  position: absolute; border: 1px solid rgba(15, 110, 140, .35); background: rgba(227, 241, 245, .55); padding: 0 3px; margin: 0;
  box-sizing: border-box; outline: none; border-radius: 2px; color: #000; line-height: 1.1; resize: none;
}
.fill-input:focus { border-color: var(--accent); background: rgba(255, 255, 255, .92); box-shadow: 0 0 0 2px rgba(15, 110, 140, .25); z-index: 5; }
.fill-input.filled { background: rgba(255, 255, 255, .0); border-color: rgba(15, 110, 140, .18); }
.fill-check { position: absolute; border: 1px solid rgba(15, 110, 140, .35); background: rgba(227, 241, 245, .5); cursor: pointer; display: grid; place-items: center; color: #000; border-radius: 2px; box-sizing: border-box; }
.fill-check.on { background: rgba(255, 255, 255, 0); border-color: transparent; }
.fill-check svg { width: 100%; height: 100%; display: block; }
.fill-comb { position: absolute; display: flex; cursor: text; }
.fill-comb .cell { position: absolute; display: grid; place-items: center; border: 1px solid rgba(15, 110, 140, .25); background: rgba(227, 241, 245, .45); color: #000; box-sizing: border-box; }
.fill-comb.focused .cell { border-color: var(--accent); }
.fill-comb .cell.caret { box-shadow: inset 0 -2px 0 var(--accent); }
.fill-img { position: absolute; border: 1px dashed rgba(15, 110, 140, .5); background: rgba(227, 241, 245, .4); display: grid; place-items: center; cursor: pointer; font-size: 11px; color: var(--accent-2); overflow: hidden; }
.fill-img img { max-width: 100%; max-height: 100%; }
.fill-input.required-empty, .fill-check.required-empty { border-color: #e67e22; }

/* وضع تعديل النص */
.span-box { position: absolute; border: 1px solid transparent; cursor: text; box-sizing: border-box; }
.span-box:hover { border-color: rgba(192, 57, 43, .6); background: rgba(192, 57, 43, .08); }
.span-box.edited { border-color: rgba(46, 139, 87, .7); }
.text-edit-box { position: absolute; box-sizing: border-box; display: flex; align-items: center; overflow: hidden; white-space: nowrap; }
.text-edit-box.selected { outline: 1.5px solid var(--ok); }

/* عناصر التحرير الحر */
.ov-el { position: absolute; box-sizing: border-box; }
.ov-el.selected { outline: 1.5px solid var(--accent); outline-offset: 1px; z-index: 5; }
.ov-el.movable { cursor: move; }
.ov-el .txt { width: 100%; height: 100%; padding: 2px; white-space: pre-wrap; word-break: break-word; overflow: hidden; }
.ov-el textarea.inline { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: rgba(255, 255, 255, .85); resize: none; padding: 2px; }

/* الصفحات */
.pages-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; padding: 20px; direction: rtl; }
.page-card { padding: 8px; text-align: center; cursor: pointer; position: relative; user-select: none; }
.page-card.selected { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(15, 110, 140, .25); }
.page-card img { max-width: 100%; height: 200px; object-fit: contain; display: block; margin: 0 auto 6px; background: #f6f7f9; }
.page-card .n { font-size: 12px; color: var(--muted); }
.page-card.drag-over { outline: 2px dashed var(--accent); }
.popover { position: absolute; background: #fff; border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 8px 30px rgba(0, 0, 0, .18); padding: 10px; z-index: 40; width: 300px; direction: rtl; }
.popover textarea { min-height: 54px; }
.inline-help { font-size: 12px; color: var(--muted); background: #f6f8fa; border-radius: 8px; padding: 8px 10px; line-height: 1.6; }
.color-row { display: flex; align-items: center; gap: 6px; }
.color-row input[type=color] { width: 36px; height: 30px; padding: 0 2px; border: 1px solid var(--border); border-radius: 6px; background: #fff; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px; border-radius: 999px; background: #eef2f6; font-size: 12px; cursor: pointer; border: 1px solid transparent; }
.chip.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-2); }
.options-editor .opt { display: flex; gap: 4px; margin-bottom: 4px; }
.kbd { font-family: ui-monospace, Consolas, monospace; font-size: 11px; background: #eef2f6; padding: 1px 5px; border-radius: 4px; border: 1px solid var(--border); }
.loading-overlay { position: absolute; inset: 0; background: rgba(255, 255, 255, .6); display: grid; place-items: center; z-index: 30; font-weight: 600; color: var(--accent-2); }
.spinner { width: 28px; height: 28px; border: 3px solid #cfe3ea; border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; vertical-align: middle; margin-left: 8px; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (max-width: 900px) {
  .side { width: 280px; }
}
