@font-face { font-family: "Naskh"; src: url(../fonts/naskh-r.ttf); font-weight: 400; font-display: swap; }
@font-face { font-family: "Naskh"; src: url(../fonts/naskh-b.ttf); font-weight: 700; font-display: swap; }

:root {
  --bg: #e9ecf2; --bar: #1f2a44; --bar2: #2b3858; --ink: #1d2330;
  --accent: #2f7cf6; --danger: #d64545; --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Naskh", system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif;
  background: var(--bg); color: var(--ink);
  display: flex; flex-direction: column; overflow: hidden;
}
button, select, input { font: inherit; }

.topbar, .toolbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 6px 10px; color: #fff;
}
.topbar { background: var(--bar); padding-top: max(6px, env(safe-area-inset-top)); }
.toolbar { background: var(--bar2); justify-content: space-between; }
.brand { font-weight: 700; font-size: 18px; margin-inline-end: auto; }
.group { display: flex; align-items: center; gap: 4px; }
.pageinfo { font-variant-numeric: tabular-nums; min-width: 60px; justify-content: center; }

.btn, .tool {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
  border: 1px solid rgba(255,255,255,.18); background: rgba(255,255,255,.08); color: #fff;
  padding: 6px 12px; border-radius: var(--radius); min-height: 38px; line-height: 1;
}
.btn:hover, .tool:hover { background: rgba(255,255,255,.16); }
.btn:disabled { opacity: .4; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); }
.btn.danger { background: var(--danger); border-color: var(--danger); }
.btn.icon { width: 38px; justify-content: center; padding: 0; font-size: 18px; }
.btn.ghost { background: transparent; min-width: 64px; justify-content: center; }
.tools { display: flex; gap: 4px; }
.tool.active { background: #fff; color: var(--bar); border-color: #fff; }
.props { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.prop { display: none; }
.prop.show { display: inline-flex; }
.prop select { border-radius: 8px; border: 0; padding: 6px 8px; min-height: 34px; }
.swatches { gap: 6px; }
.swatch { width: 26px; height: 26px; border-radius: 50%; border: 2px solid rgba(255,255,255,.5); cursor: pointer; padding: 0; }
.swatch.sel { border-color: #fff; box-shadow: 0 0 0 2px var(--accent); }

.viewer { flex: 1; overflow: auto; position: relative; -webkit-overflow-scrolling: touch; }
.pages { display: flex; flex-direction: column; align-items: center; gap: 16px; padding: 16px 8px 80px; }
.page {
  position: relative; background: #fff; box-shadow: 0 2px 10px rgba(0,0,0,.15);
  flex: none;
}
.page canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.page .overlay { touch-action: pan-x pan-y pinch-zoom; }
.page .overlay.capture { touch-action: none; }
.page .num { position: absolute; bottom: -14px; left: 50%; transform: translateX(-50%); font-size: 11px; color: #667; direction: ltr; }
body[data-tool="text"] .overlay { cursor: text; }
body[data-tool="highlight"] .overlay, body[data-tool="pen"] .overlay { cursor: crosshair; }

.editor {
  position: absolute; z-index: 5; resize: none; overflow: hidden; white-space: pre;
  border: 1px dashed var(--accent); background: rgba(255,255,255,.85); outline: none;
  padding: 0; margin: 0; line-height: 1.5; min-width: 2em;
  unicode-bidi: plaintext;
}

.empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 20px; }
.empty.hidden { display: none; }
.drop {
  border: 2px dashed #9aa6bf; border-radius: 16px; padding: 40px 30px; text-align: center;
  background: #fff; max-width: 420px; width: 100%;
}
.drop.over { border-color: var(--accent); background: #eef4ff; }
.drop .big { font-size: 56px; }
.drop .en { color: #778; direction: ltr; margin-top: -8px; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: #1d2330; color: #fff; padding: 10px 18px; border-radius: 10px; z-index: 50;
  max-width: 90vw; box-shadow: 0 4px 16px rgba(0,0,0,.3);
}

@media (max-width: 640px) {
  .lbl { display: none; }
  .brand { font-size: 16px; }
  .topbar, .toolbar { gap: 6px; padding-inline: 6px; }
  .tool { padding: 6px 10px; }
}

[hidden] { display: none !important; }
.pageinfo { direction: ltr; }

.searchbar {
  display: flex; align-items: center; gap: 6px; padding: 6px 10px;
  background: #fff; border-bottom: 1px solid #d5dae4; box-shadow: 0 2px 6px rgba(0,0,0,.06);
}
.searchbar input {
  flex: 1; min-width: 0; border: 1px solid #c5ccda; border-radius: 8px; padding: 7px 10px; min-height: 38px;
}
.searchbar input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.searchbar .count { color: #556; font-size: 13px; white-space: nowrap; direction: ltr; min-width: 48px; text-align: center; }
.searchbar .btn { color: var(--ink); background: #f1f3f8; border-color: #d5dae4; }
.searchbar .btn:hover { background: #e4e8f1; }

.btn.bold { font-weight: 700; width: 38px; justify-content: center; padding: 0; font-family: Georgia, serif; font-size: 18px; }
.btn.bold.on { background: #fff; color: var(--bar); }
#fontSel { max-width: 210px; }
.editor.block { border: 1px solid var(--accent); background: transparent; white-space: pre-wrap; overflow: hidden; box-shadow: 0 0 0 3px rgba(47,124,246,.18); }
body[data-tool="edit"] .overlay { cursor: text; }

.workspace { flex: 1; display: flex; min-height: 0; position: relative; }
.sidebar {
  width: 168px; flex: none; background: #d9dfea; border-inline-end: 1px solid #c3cbdb;
  display: flex; flex-direction: column; min-height: 0;
}
.side-head { padding: 8px 10px; font-weight: 700; font-size: 14px; color: #2b3858; }
.side-head .en { font-weight: 400; color: #778; font-size: 12px; }
.thumbs { overflow-y: auto; flex: 1; padding: 4px 14px 30px; }
.thumbset { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.thumb { cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 4px; width: 100%; }
.thumb .tc { background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.18); outline: 3px solid transparent; outline-offset: 2px; border-radius: 2px; }
.thumb canvas { display: block; width: 100%; height: 100%; }
.thumb .tn { font-size: 12px; color: #445; direction: ltr; }
.thumb:hover .tc { outline-color: rgba(47,124,246,.35); }
.thumb.cur .tc { outline-color: var(--accent); }
.thumb.cur .tn { color: var(--accent); font-weight: 700; }
@media (max-width: 760px) {
  .sidebar { position: absolute; inset-block: 0; inset-inline-start: 0; z-index: 20; box-shadow: 0 0 24px rgba(0,0,0,.3); width: 150px; }
}

.dlg { border: 0; border-radius: 14px; padding: 18px 20px; width: min(560px, 94vw); box-shadow: 0 12px 40px rgba(0,0,0,.35); color: var(--ink); }
.dlg::backdrop { background: rgba(20,26,40,.45); }
.dlg h3 { margin: 0 0 4px; }
.dlg h3 .en, .dlg .en { color: #778; font-weight: 400; font-size: 14px; }
.dlg .hint { color: #667; font-size: 13px; margin: 4px 0 12px; }
.dlg .row { display: flex; align-items: center; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.dlg .grow { flex: 1; }
.dlg .btn { color: var(--ink); background: #f1f3f8; border-color: #d5dae4; }
.dlg .btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.mlist { list-style: none; padding: 0; margin: 0; max-height: 46vh; overflow: auto; border: 1px solid #e1e5ee; border-radius: 10px; }
.mlist:empty::before { content: "لا توجد ملفات بعد — No files yet"; display: block; padding: 18px; text-align: center; color: #99a; }
.mlist li { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-bottom: 1px solid #eef0f5; }
.mlist li:last-child { border-bottom: 0; }
.mlist .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; direction: ltr; text-align: right; }
.mlist .meta { color: #889; font-size: 12px; white-space: nowrap; }
.mlist button { border: 1px solid #d5dae4; background: #f6f7fb; border-radius: 8px; width: 32px; height: 32px; cursor: pointer; }
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.choice { text-align: start; border: 1px solid #d5dae4; background: #f8f9fc; border-radius: 12px; padding: 12px; cursor: pointer; display: flex; flex-direction: column; gap: 4px; font: inherit; color: var(--ink); }
.choice:hover { border-color: var(--accent); background: #eef4ff; }
.choice span { font-size: 12.5px; color: #667; }
.choice:disabled { opacity: .5; cursor: wait; }
@media (max-width: 520px) { .choices { grid-template-columns: 1fr; } }

.viewer { min-width: 0; }

.tabbar { display: flex; align-items: flex-end; gap: 6px; background: var(--bar); padding: 4px 8px 0; }
.tabs { display: flex; gap: 3px; overflow-x: auto; scrollbar-width: thin; min-width: 0; }
.tab {
  display: flex; align-items: center; gap: 6px; flex: none; max-width: 220px; min-width: 90px;
  padding: 6px 10px; border-radius: 9px 9px 0 0; cursor: pointer; user-select: none;
  background: rgba(255,255,255,.10); color: #cfd6e6; font-size: 13.5px;
}
.tab:hover { background: rgba(255,255,255,.18); }
.tab.active { background: var(--bar2); color: #fff; }
.tname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; direction: ltr; text-align: right; }
.tdot { width: 8px; height: 8px; border-radius: 50%; background: #ffb74d; flex: none; }
.tclose { border: 0; background: transparent; color: inherit; cursor: pointer; border-radius: 5px; width: 22px; height: 22px; flex: none; font-size: 12px; opacity: .75; }
.tclose:hover { background: rgba(255,255,255,.2); opacity: 1; }
.tabadd { border: 0; background: transparent; color: #cfd6e6; font-size: 20px; cursor: pointer; width: 32px; height: 30px; border-radius: 8px; flex: none; }
.tabadd:hover { background: rgba(255,255,255,.15); color: #fff; }
