:root{
  --bar:#123a3a; --bar2:#1b4a4a; --ink:#16302f; --muted:#5d7473; --line:#d5dfde;
  --bg:#e9eeee; --card:#ffffff; --accent:#e88c28; --accent2:#c96f12; --sel:#1e88e5;
  --danger:#c0392b; --safe-top:env(safe-area-inset-top,0px); --safe-bot:env(safe-area-inset-bottom,0px);
}
*{box-sizing:border-box;-webkit-tap-highlight-color:transparent}
html,body{margin:0;height:100%;overflow:hidden;background:var(--bg);color:var(--ink);
  font-family:'Cairo','Tajawal',system-ui,sans-serif;font-size:15px;-webkit-user-select:none;user-select:none}
button{font:inherit;color:inherit;border:0;background:none;cursor:pointer;padding:0}
input,textarea,select{font:inherit;color:inherit}
textarea,input[type=text],input[type=search],input[type=number]{-webkit-user-select:text;user-select:text}
.hidden{display:none!important}
.ic{display:inline-flex;width:24px;height:24px;flex:none}
.ic svg{width:100%;height:100%;fill:none;stroke:currentColor;stroke-width:1.9;stroke-linecap:round;stroke-linejoin:round}
.screen{position:fixed;inset:0;display:flex;flex-direction:column}

/* ---------- Home ---------- */
#home{background:linear-gradient(170deg,#123a3a 0%,#1d5654 46%,var(--bg) 46.2%);overflow-y:auto;padding:calc(var(--safe-top) + 28px) 18px 24px}
.home-head{color:#fff;text-align:center;margin-bottom:22px}
.logo{width:76px;height:76px;margin:0 auto 10px;background:rgba(255,255,255,.12);border-radius:20px;display:grid;place-items:center}
.logo svg{width:56px;height:56px}
.home-head h1{margin:0;font-size:28px;font-weight:700}
.home-head p{margin:4px 0 0;opacity:.85;font-size:14px}
.home-actions{display:grid;grid-template-columns:1fr 1fr;gap:12px;max-width:520px;margin:0 auto}
.big-btn{background:var(--card);border-radius:16px;padding:18px 12px;display:flex;flex-direction:column;align-items:center;gap:4px;
  box-shadow:0 4px 16px rgba(18,58,58,.12);text-align:center}
.big-btn .ic{width:34px;height:34px;color:var(--bar2);margin-bottom:4px}
.big-btn b{font-size:16px}
.big-btn small{color:var(--muted);font-size:12px}
.big-btn.primary{grid-column:1/-1;background:var(--accent);color:#fff;flex-direction:row;justify-content:center;gap:12px;padding:20px}
.big-btn.primary .ic{color:#fff;margin:0}
.big-btn.primary small{color:#fff;opacity:.85}
.big-btn:active{transform:scale(.98)}
.home-foot{text-align:center;color:var(--muted);font-size:12px;margin-top:26px}

/* ---------- Top bar ---------- */
.topbar{background:var(--bar);color:#fff;display:flex;align-items:center;gap:2px;padding:calc(var(--safe-top) + 6px) 6px 6px;flex:none;z-index:5}
.topbar .title{flex:1;min-width:0;font-weight:600;font-size:15px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;padding:0 6px}
.tb{width:40px;height:40px;border-radius:10px;display:grid;place-items:center;flex:none}
.tb:active{background:rgba(255,255,255,.15)}
.tb:disabled{opacity:.35}
.tb.txt{width:auto;padding:0 12px;font-size:14px}
.tb.sm{width:34px;height:34px}

#searchbar{display:flex;align-items:center;gap:4px;background:var(--bar2);color:#fff;padding:6px 8px;flex:none}
#searchbar input{flex:1;min-width:0;border:0;border-radius:10px;padding:8px 12px;background:#fff;color:var(--ink)}
#searchCount{font-size:13px;min-width:46px;text-align:center}

/* ---------- Viewer ---------- */
#viewer{flex:1;overflow:auto;position:relative;touch-action:pan-x pan-y;-webkit-overflow-scrolling:touch}
#pages{padding:10px 8px 120px;display:flex;flex-direction:column;align-items:center;gap:12px;transform-origin:50% 0;width:max-content;min-width:100%}
.page{position:relative;background:#fff;box-shadow:0 2px 10px rgba(0,0,0,.18);flex:none}
.page canvas.pdfc{position:absolute;inset:0;width:100%;height:100%}
.page .overlay{position:absolute;inset:0;touch-action:pan-x pan-y}
#viewer.drawing .overlay{touch-action:none;cursor:crosshair}
#viewer.drawing .obj{pointer-events:none}
.page .pnum{position:absolute;bottom:-1px;left:50%;transform:translate(-50%,100%);font-size:11px;color:var(--muted)}
.obj{position:absolute;touch-action:none}
.obj canvas,.obj img{width:100%;height:100%;display:block;pointer-events:none}
.obj.sel{outline:1.5px dashed var(--sel);outline-offset:2px}
.obj .handle{position:absolute;width:26px;height:26px;left:-15px;bottom:-15px;border-radius:50%;background:var(--sel);border:3px solid #fff;box-shadow:0 1px 4px rgba(0,0,0,.4);touch-action:none}
.live{position:absolute;inset:0;pointer-events:none;width:100%;height:100%}
.flash{position:absolute;background:rgba(255,193,7,.45);border-radius:2px;pointer-events:none;animation:flash 1.6s ease-out}
@keyframes flash{0%{background:rgba(255,120,0,.8)}100%{background:rgba(255,193,7,.35)}}
.dragbox{position:absolute;border:1.5px dashed var(--sel);background:rgba(30,136,229,.08);pointer-events:none}

#pageBadge{position:absolute;bottom:calc(84px + var(--safe-bot));left:50%;transform:translateX(-50%);background:rgba(18,58,58,.85);color:#fff;
  font-size:13px;padding:3px 12px;border-radius:12px;pointer-events:none;transition:opacity .3s}
#zoomBtns{position:absolute;left:10px;bottom:calc(84px + var(--safe-bot));display:flex;flex-direction:column;gap:6px}
#zoomBtns button{width:38px;height:38px;border-radius:50%;background:rgba(255,255,255,.95);box-shadow:0 1px 6px rgba(0,0,0,.25);display:grid;place-items:center;color:var(--bar)}
#zoomBtns .ic{width:20px;height:20px}

/* ---------- Tool bar ---------- */
#toolbar{flex:none;background:var(--card);border-top:1px solid var(--line);display:flex;overflow-x:auto;padding:4px 4px calc(4px + var(--safe-bot));gap:2px;z-index:5;scrollbar-width:none}
#toolbar::-webkit-scrollbar{display:none}
.tool{min-width:62px;height:58px;border-radius:12px;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:2px;color:var(--muted);font-size:11.5px;flex:none}
.tool .ic{width:23px;height:23px}
.tool.on{background:#e3efee;color:var(--bar)}
.tool.on b{font-weight:700}
.tool b{font-weight:500}
#toolopts{flex:none;background:var(--card);border-top:1px solid var(--line);padding:8px 10px;display:flex;align-items:center;gap:10px;overflow-x:auto;z-index:5}
#toolopts .lbl{font-size:12px;color:var(--muted);flex:none}
#toolopts input[type=range]{width:110px;flex:none}

.swatch{width:28px;height:28px;border-radius:50%;border:2px solid #fff;box-shadow:0 0 0 1px var(--line);flex:none;position:relative}
.swatch.on{box-shadow:0 0 0 2.5px var(--sel)}
.swatch.none{background:repeating-linear-gradient(45deg,#fff 0 5px,#f1c6c6 5px 7px)!important}
.swatch.custom{background:conic-gradient(red,yellow,lime,cyan,blue,magenta,red)}
.swatch input{position:absolute;inset:0;opacity:0;width:100%;height:100%}
.chip{border:1px solid var(--line);border-radius:18px;padding:5px 12px;font-size:13px;background:#fff;flex:none;white-space:nowrap}
.chip.on{background:var(--bar);border-color:var(--bar);color:#fff}

/* ---------- selection bar ---------- */
#selbar{position:absolute;top:calc(var(--safe-top) + 58px);left:50%;transform:translateX(-50%);z-index:8;background:#24312f;color:#fff;border-radius:14px;
  display:flex;padding:4px;gap:2px;box-shadow:0 4px 16px rgba(0,0,0,.3);max-width:calc(100% - 16px);overflow-x:auto}
#selbar button{padding:8px 11px;border-radius:10px;font-size:13px;white-space:nowrap;display:flex;align-items:center;gap:4px}
#selbar button:active{background:rgba(255,255,255,.15)}
#selbar .ic{width:18px;height:18px}
#selbar .danger{color:#ff8a80}

/* ---------- Sheets ---------- */
#backdrop{position:fixed;inset:0;background:rgba(0,0,0,.35);z-index:20}
#sheet{position:fixed;left:0;right:0;bottom:0;z-index:21;background:var(--card);border-radius:20px 20px 0 0;max-height:88%;display:flex;flex-direction:column;
  box-shadow:0 -6px 24px rgba(0,0,0,.2);padding-bottom:var(--safe-bot);animation:up .22s ease-out}
@keyframes up{from{transform:translateY(40%);opacity:.4}to{transform:none;opacity:1}}
#sheet .grab{width:42px;height:5px;border-radius:3px;background:#cfd8d8;margin:8px auto 2px;flex:none}
#sheetBody{overflow-y:auto;padding:4px 16px 16px}
.sh-head{display:flex;align-items:center;gap:8px;margin:4px 0 10px}
.sh-head h3{flex:1;margin:0;font-size:17px}
.btn{background:#eef3f3;border-radius:12px;padding:10px 16px;font-weight:600;font-size:14px;display:inline-flex;align-items:center;justify-content:center;gap:6px}
.btn.pri{background:var(--accent);color:#fff}
.btn.dark{background:var(--bar);color:#fff}
.btn.danger{background:#fdecea;color:var(--danger)}
.btn.block{display:flex;width:100%}
.btn .ic{width:20px;height:20px}
.row{display:flex;align-items:center;gap:10px;margin:10px 0;flex-wrap:wrap}
.row>.k{width:72px;color:var(--muted);font-size:13px;flex:none}
.row.scroll{flex-wrap:nowrap;overflow-x:auto;padding-bottom:4px}
.field{width:100%;border:1.5px solid var(--line);border-radius:12px;padding:10px 12px;background:#fbfdfd;outline:none}
.field:focus{border-color:var(--bar2)}
textarea.field{min-height:96px;resize:vertical;font-size:18px;line-height:1.6}
.stepper{display:flex;align-items:center;border:1px solid var(--line);border-radius:12px;overflow:hidden}
.stepper button{width:40px;height:36px;font-size:20px;background:#f3f7f7}
.stepper span{min-width:52px;text-align:center;font-weight:600}
.seg{display:flex;border:1px solid var(--line);border-radius:12px;overflow:hidden}
.seg button{padding:7px 12px;display:grid;place-items:center}
.seg button.on{background:var(--bar);color:#fff}
.seg .ic{width:20px;height:20px}
.menu-list button{display:flex;align-items:center;gap:14px;width:100%;padding:13px 6px;border-bottom:1px solid #eef2f2;font-size:15px;text-align:right}
.menu-list button:last-child{border-bottom:0}
.menu-list .ic{color:var(--bar2)}
.menu-list .danger,.menu-list .danger .ic{color:var(--danger)}
.lib-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(130px,1fr));gap:10px;margin:8px 0}
.lib-item{position:relative;background:#f4f7f7 repeating-conic-gradient(#eef2f2 0 25%,#f8fafa 0 50%) 0 0/16px 16px;border-radius:12px;height:96px;display:grid;place-items:center;border:1px solid var(--line);overflow:hidden}
.lib-item img{max-width:88%;max-height:80px}
.lib-item .x{position:absolute;top:4px;left:4px;width:26px;height:26px;border-radius:50%;background:rgba(0,0,0,.55);color:#fff;font-size:15px;line-height:26px}
.lib-empty{color:var(--muted);font-size:13px;text-align:center;padding:16px 0}
.sigpad{width:100%;height:220px;border:1.5px dashed #b8c8c8;border-radius:14px;background:#fff;touch-action:none;display:block}
.preview-box{background:#f4f7f7 repeating-conic-gradient(#eef2f2 0 25%,#f8fafa 0 50%) 0 0/16px 16px;border-radius:12px;border:1px solid var(--line);display:grid;place-items:center;padding:10px;min-height:120px}
.preview-box canvas,.preview-box img{max-width:100%;max-height:220px}
.fonts{display:flex;gap:8px;overflow-x:auto;padding:2px 0 6px}
.fontchip{flex:none;border:1.5px solid var(--line);border-radius:12px;padding:6px 12px;background:#fff;text-align:center;min-width:86px}
.fontchip.on{border-color:var(--sel);background:#eaf3fd}
.fontchip .s{font-size:20px;line-height:1.5;display:block}
.fontchip .n{font-size:10.5px;color:var(--muted);font-family:'Cairo'}
.sec-title{font-weight:700;font-size:14px;margin:14px 0 4px;color:var(--bar2)}
.info-table{width:100%;border-collapse:collapse;font-size:14px}
.info-table td{padding:8px 4px;border-bottom:1px solid #eef2f2}
.info-table td:first-child{color:var(--muted);width:38%}

/* ---------- Organizer ---------- */
#organizer{background:#dfe6e6}
#orgGrid{flex:1;overflow-y:auto;display:grid;grid-template-columns:repeat(auto-fill,minmax(140px,1fr));gap:14px;padding:14px 12px 20px;align-content:start}
.thumb{background:#fff;border-radius:6px;box-shadow:0 1px 6px rgba(0,0,0,.18);position:relative;display:grid;place-items:center;padding:6px;aspect-ratio:3/4;border:3px solid transparent}
.thumb canvas{max-width:100%;max-height:100%;box-shadow:0 0 0 1px #e3e8e8}
.thumb.on{border-color:var(--sel)}
.thumb .n{position:absolute;bottom:-11px;left:50%;transform:translateX(-50%);background:var(--bar);color:#fff;font-size:12px;border-radius:10px;padding:0 9px}
.thumb .chk{position:absolute;top:6px;left:6px;width:22px;height:22px;border-radius:50%;border:2px solid #9ab;background:#fff}
.thumb.on .chk{background:var(--sel);border-color:var(--sel)}
.thumb.on .chk::after{content:'';position:absolute;left:6px;top:2px;width:5px;height:10px;border:solid #fff;border-width:0 2px 2px 0;transform:rotate(45deg)}
#orgBar{flex:none;background:var(--card);display:flex;overflow-x:auto;padding:4px 4px calc(4px + var(--safe-bot));border-top:1px solid var(--line);gap:2px}
#orgBar .tool:disabled{opacity:.35}

/* ---------- toast / busy ---------- */
#toast{position:fixed;left:50%;bottom:calc(110px + var(--safe-bot));transform:translate(-50%,20px);background:#24312f;color:#fff;padding:10px 18px;border-radius:12px;
  font-size:14px;opacity:0;pointer-events:none;transition:all .25s;z-index:40;max-width:88%;text-align:center}
#toast.show{opacity:1;transform:translate(-50%,0)}
#busy{position:fixed;inset:0;background:rgba(255,255,255,.7);z-index:50;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:12px}
.spinner{width:42px;height:42px;border-radius:50%;border:4px solid #cfdcdc;border-top-color:var(--bar);animation:spin .8s linear infinite}
@keyframes spin{to{transform:rotate(360deg)}}
#busyText{font-weight:600;color:var(--bar)}

#tapmenu{position:fixed;z-index:30;background:#24312f;color:#fff;border-radius:16px;padding:6px;display:grid;grid-template-columns:repeat(4,1fr);gap:2px;
  box-shadow:0 8px 28px rgba(0,0,0,.35);animation:pop .15s ease-out;max-width:calc(100% - 16px)}
#tapmenu button{display:flex;flex-direction:column;align-items:center;gap:3px;padding:9px 8px;border-radius:12px;font-size:12.5px;min-width:64px}
#tapmenu button:active{background:rgba(255,255,255,.15)}
#tapmenu .ic{width:22px;height:22px}
@keyframes pop{from{transform:scale(.85);opacity:0}to{transform:none;opacity:1}}
.tapdot{position:absolute;width:14px;height:14px;margin:-7px 0 0 -7px;border-radius:50%;background:var(--accent);border:2px solid #fff;box-shadow:0 0 0 4px rgba(232,140,40,.3);pointer-events:none}
.fonts{flex-wrap:wrap;overflow:visible}
.fontchip{min-width:0;flex:1 1 30%}

.fsel{flex:1;min-width:0;padding:9px 10px;font-size:15px;background:#fff}
.fprev{flex:none;min-width:84px;height:42px;border:1.5px solid var(--line);border-radius:12px;display:grid;place-items:center;font-size:22px;padding:0 10px;background:#fff;line-height:1}

/* ---------- محرر النص المضغوط ---------- */
#sheet.compact{border-radius:16px 16px 0 0;animation:none}
#sheet.compact .grab{display:none}
#sheet.compact #sheetBody{padding:8px 8px 6px}
.tx-area{min-height:0!important;height:64px;font-size:17px!important;padding:8px 10px!important;margin-bottom:6px}
.tx-bar{display:flex;align-items:center;gap:4px}
.tx-font{flex:1;min-width:0;display:flex;align-items:center;gap:4px;border:1px solid var(--line);border-radius:10px;padding:0 10px;height:36px;background:#fff;color:#1e6fd9}
.tx-font #tFontName{flex:1;min-width:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;text-align:right;font-size:14.5px}
.tx-font .car{font-size:10px;color:var(--muted)}
.tx-size{display:flex;align-items:center;height:36px;border:1px solid var(--line);border-radius:10px;overflow:hidden;flex:none}
.tx-size button{width:28px;height:100%;font-size:18px;color:#1e6fd9;background:#f6f9f9}
.tx-size span{min-width:28px;text-align:center;font-weight:700;font-size:14px;color:#1e6fd9}
.tx-b{width:34px;height:36px;border:1px solid var(--line);border-radius:10px;font-weight:800;font-size:15px;display:grid;place-items:center;flex:none;color:var(--ink)}
.tx-b.on{background:var(--bar);color:#fff;border-color:var(--bar)}
.tx-b .ic{width:18px;height:18px}
.tx-ln{width:40px;display:flex;gap:2px;align-items:center;justify-content:center;font-size:13px}.tx-ln .lnN{font-size:12px}
.tx-col{position:relative;width:44px;height:36px;flex:none}
.tx-col span{position:absolute;top:6px;width:24px;height:24px;border-radius:50%;border:2px solid #fff;box-shadow:0 0 0 1px #c8d2d2}
.tx-col .d1{right:2px;z-index:1}
.tx-col .d2{left:2px;background:#fff}
.tx-col .d2.none{background:repeating-linear-gradient(45deg,#fff 0 4px,#f1c6c6 4px 6px)}
.tx-done{height:36px;padding:0 12px;border-radius:10px;background:var(--accent);color:#fff;font-weight:700;flex:none}
#txPanel{position:fixed;left:8px;right:8px;z-index:25;background:#1f2626;color:#fff;border-radius:14px;box-shadow:0 8px 30px rgba(0,0,0,.35);overflow:hidden;display:flex;flex-direction:column}
.fl-cols{display:grid;grid-template-columns:1fr 1fr;min-height:0;flex:1;overflow:hidden}
.fl-col{overflow-y:auto;min-height:0;max-height:inherit;padding-bottom:6px}
.fl-col+.fl-col{border-right:1px solid rgba(255,255,255,.12)}
.fl-h{position:sticky;top:0;background:#1f2626;font-size:11.5px;color:#9fb5b4;padding:7px 10px 5px;font-weight:700;z-index:1}
#flEn .fl-h{text-align:left;direction:ltr}
.fl-row{display:flex;flex-direction:column;align-items:flex-start;width:100%;padding:5px 10px;border-top:1px solid rgba(255,255,255,.07);text-align:right}
#flEn .fl-row{direction:ltr;text-align:left}
.fl-row .nm{font-size:14px;line-height:1.5;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:100%}
.fl-row .sb{font-size:9.5px;color:#8aa0a0;font-family:Cairo;line-height:1.2}
.fl-row.on{background:#1e6fd9}
.fl-row.on .sb{color:#dbe8ff}
.cp{padding:10px 12px}
.cp-r{display:flex;align-items:center;gap:8px;margin:6px 0;overflow-x:auto}
.cp-r .k{font-size:12px;color:#9fb5b4;width:46px;flex:none}
.cp-r>span:not(.k){display:flex;gap:7px}
.cp-r input[type=range]{flex:1}
.cp .swatch{width:26px;height:26px;border-color:#1f2626}

.tx-font #tFontName{unicode-bidi:plaintext}

.obj .handle.edge-w{left:-13px;top:50%;bottom:auto;margin-top:-11px;width:22px;height:22px;border-radius:6px;background:#fff;border:3px solid var(--sel)}
.obj .handle.edge-h{left:50%;bottom:-13px;margin-left:-11px;width:22px;height:22px;border-radius:6px;background:#fff;border:3px solid var(--sel)}
.txsel{position:absolute;background:rgba(30,136,229,.28);border-radius:2px;pointer-events:none;outline:1.5px solid rgba(30,136,229,.7)}
#tapmenu.txbar{display:flex;grid-template-columns:none;padding:4px}
#tapmenu.txbar button{flex-direction:row;min-width:0;padding:8px 10px;gap:5px;font-size:13px}
#tapmenu.txbar .ic{width:18px;height:18px}

.imgmode{display:grid;grid-template-columns:1fr 1fr;gap:10px;margin:4px 0 8px}
.imgmode button{border:1.5px solid var(--line);border-radius:14px;padding:14px 10px;display:flex;flex-direction:column;align-items:center;gap:4px;background:#fff;text-align:center}
.imgmode button:active{border-color:var(--sel);background:#eaf3fd}
.imgmode b{font-size:15px}
.imgmode small{font-size:11.5px;color:var(--muted);line-height:1.5}
.imgmode .pv{display:grid;place-items:center;margin-bottom:6px}
.imgmode .pv.fit{width:54px;height:72px}
.imgmode .pv.fit i{width:100%;height:100%;border-radius:3px;background:linear-gradient(160deg,#9cc3d9,#d8b48a 60%,#7a8f6a)}
.imgmode .pv.a4{width:54px;height:76px;background:#fff;border:1px solid #c9d3d3;box-shadow:0 1px 4px rgba(0,0,0,.12)}
.imgmode .pv.a4 i{width:40px;height:54px;border-radius:2px;background:linear-gradient(160deg,#9cc3d9,#d8b48a 60%,#7a8f6a)}

#orgGrid{position:relative}
.thumb{touch-action:pan-y;-webkit-touch-callout:none}
.thumb.dragging{opacity:.35}
.drag-ghost{position:fixed;z-index:60;width:96px;transform:translate(-50%,-60%) rotate(-3deg);pointer-events:none;background:#fff;padding:4px;border-radius:6px;box-shadow:0 10px 28px rgba(0,0,0,.35)}
.drag-ghost canvas{width:100%;display:block}
.drag-ghost .cnt{position:absolute;top:-10px;left:-10px;background:var(--sel);color:#fff;font-weight:700;border-radius:12px;min-width:24px;height:24px;display:grid;place-items:center;font-size:13px;padding:0 6px}
.drop-bar{position:absolute;width:5px;border-radius:3px;background:var(--sel);box-shadow:0 0 0 3px rgba(30,136,229,.25);pointer-events:none;z-index:5}
.org-hint{flex:none;text-align:center;font-size:12.5px;color:var(--muted);padding:6px 10px 0}

/* ---------- الشاشات العريضة (لابتوب / تابلت) ---------- */
@media (min-width: 760px) {
  #sheet{left:0;right:0;margin:0 auto;max-width:640px;border-radius:20px 20px 0 0}
  #txPanel{left:0;right:0;margin:0 auto;max-width:640px}
  #toolbar,#orgBar{justify-content:center}
  .tool{min-width:72px}
  #orgGrid{grid-template-columns:repeat(auto-fill,minmax(170px,1fr))}
  .obj .handle{width:20px;height:20px;left:-12px;bottom:-12px}
}
@media (hover: hover) {
  .tool:hover,.tb:hover,#selbar button:hover,#tapmenu button:hover,.menu-list button:hover{filter:brightness(.95)}
  .tool:hover{background:#eef4f4}
  .obj{cursor:move}
  .obj .handle{cursor:nwse-resize}
  .obj .handle.edge-w{cursor:ew-resize}
  .obj .handle.edge-h{cursor:ns-resize}
}

.hfseg{display:flex}
.hfseg button{flex:1;padding:9px 6px;font-size:13.5px}
.lib-grid.wide{grid-template-columns:1fr}
.lib-grid.wide .lib-item{height:74px;background:#fff}
.lib-grid.wide .lib-item img{max-width:96%;max-height:66px}
.hfopt{display:flex;align-items:center;gap:10px;padding:11px 6px;border-bottom:1px solid #eef2f2;font-size:14.5px}
.hdgrid{display:grid;grid-template-columns:1fr 1fr;gap:8px;margin-top:8px}
.hdgrid .field{padding:8px 10px;font-size:14px}

/* ---------- السكان ---------- */
#scanner{background:#1d2424}
#scStage{flex:1;position:relative;display:grid;place-items:center;overflow:hidden;min-height:0}
#scCv{touch-action:none;box-shadow:0 4px 20px rgba(0,0,0,.5)}
.sc-loupe{position:absolute;width:120px;height:120px;border-radius:50%;border:3px solid #fff;box-shadow:0 4px 16px rgba(0,0,0,.5);pointer-events:none}
.sc-res{max-width:calc(100% - 24px);max-height:calc(100% - 24px);box-shadow:0 4px 20px rgba(0,0,0,.5);background:#fff}
#scBar{flex:none;background:var(--card);padding:6px 6px calc(6px + var(--safe-bot));display:flex;flex-wrap:wrap;justify-content:center;gap:4px}
#scBar .tool{flex:1;max-width:120px}
#scBar .sc-go{background:var(--accent);color:#fff}
.sc-filters{display:flex;gap:6px;justify-content:center;width:100%;overflow-x:auto;padding:4px 0}
.sc-row{display:flex;gap:4px;width:100%;justify-content:center}
.sc-grid{width:100%;height:100%;overflow-y:auto;display:grid;grid-template-columns:repeat(auto-fill,minmax(130px,1fr));gap:14px;padding:14px;align-content:start}
.sc-th{position:relative;background:#fff;border-radius:6px;padding:4px;box-shadow:0 2px 8px rgba(0,0,0,.4)}
.sc-th img{width:100%;display:block}
.sc-th .n{position:absolute;bottom:6px;left:50%;transform:translateX(-50%);background:var(--bar);color:#fff;font-size:12px;border-radius:10px;padding:0 9px}
.sc-th .x{position:absolute;top:-8px;left:-8px;width:28px;height:28px;border-radius:50%;background:var(--danger);color:#fff;font-size:17px;line-height:28px}

.home-foot{line-height:1.7}
.home-foot b{color:var(--bar)}
.about{text-align:center;padding:6px 0 10px}
.about .logo{width:72px;height:72px;margin:0 auto 8px;background:var(--bar);border-radius:18px;display:grid;place-items:center}
.about .logo svg{width:52px;height:52px}
.about h2{margin:0;font-size:24px;color:var(--bar)}
.about p{margin:4px 0;color:var(--muted)}
.about .by{margin-top:12px;font-size:15px;color:var(--ink)}

.hf-prev{display:grid;place-items:center;background:#e9eeee;border-radius:12px;padding:10px}
.hf-page{position:relative;background:#fff;box-shadow:0 1px 6px rgba(0,0,0,.2);overflow:hidden}
.hf-page img{position:absolute;display:block}
.zm-wrap{display:flex;gap:12px;align-items:flex-start;flex-wrap:wrap;margin-top:8px}
.zm-col{flex:1 1 150px;min-width:0}
.zm-wrap .zm-col:last-child{flex:2 1 220px}
.zm-page{background:#fff;box-shadow:0 1px 6px rgba(0,0,0,.2);background-size:100% 100%;background-repeat:no-repeat}
.zm-frame{position:absolute;border:2px solid #e53935;background:rgba(229,57,53,.12);pointer-events:none}
.zm-cv{width:100%;height:auto;display:block;background:#fff;border-radius:8px;box-shadow:0 1px 6px rgba(0,0,0,.2)}

.inline-box{position:absolute;z-index:3;border:1.2px dashed var(--sel);box-sizing:border-box;pointer-events:none;border-radius:2px}
.obj.editing .handle,.obj.editing{outline:none!important;box-shadow:none!important}.obj.editing .handle{display:none}
.inline-ta{position:absolute;z-index:4;border:0;border-radius:0;outline:none;resize:none;overflow:hidden;white-space:pre-wrap;overflow-wrap:break-word;margin:0;box-sizing:border-box;
  -webkit-user-select:text;user-select:text;touch-action:auto;caret-color:var(--sel)}

.contact-btn{margin-top:10px;border:1.5px solid var(--bar2);color:var(--bar2);border-radius:20px;padding:7px 16px;font-size:13.5px;background:#fff;direction:rtl}
.contact-btn:active{background:#e3efee}

/* خطوطي */
.uf-row{display:flex;align-items:center;gap:10px;padding:10px 4px;border-bottom:1px solid #eef2f2}
.uf-n{flex:1;min-width:0;display:flex;flex-direction:column}
.uf-n b{font-size:17px;font-weight:400}
.uf-n span{font-size:15px;color:#333;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.uf-n small{font-size:11.5px;color:var(--muted)}
#mfBar{position:fixed;left:10px;right:10px;bottom:calc(150px + env(safe-area-inset-bottom));z-index:60;background:#263238;color:#fff;border-radius:14px;padding:10px 12px;display:flex;align-items:center;gap:8px;font-size:13.5px;box-shadow:0 6px 20px rgba(0,0,0,.3);max-width:520px;margin:0 auto}
#mfBar span{flex:1;line-height:1.5}
#mfBar button{border:0;border-radius:10px;padding:7px 12px;background:#e88c28;color:#fff;font:inherit;font-weight:800;white-space:nowrap}
#mfBar button.x{background:transparent;padding:4px 6px;font-size:16px}

/* رفع خط للمراجعة */
.fup{background:#f4f8f8;border:1.5px solid #dbe6e6;border-radius:14px;padding:10px 12px}
.fup-h{display:flex;align-items:center;gap:8px}
.fup-h b{flex:1;font-size:14.5px}
.fup-i{width:26px;height:26px;border-radius:50%;border:1.5px solid #1a7f8f;color:#1a7f8f;background:#fff;font:italic 800 14px Georgia,serif;display:grid;place-items:center;flex:none}
.fup-pol{margin-top:8px;font-size:13px;line-height:1.8;background:#fff;border-radius:10px;padding:9px 11px;color:#2c3e3e}
.fup-msg{font-size:13px;line-height:1.7;margin-top:6px}
.cbox-w{position:fixed;inset:0;z-index:200;background:rgba(0,0,0,.45);display:grid;place-items:center;padding:20px}
.cbox{background:#fff;border-radius:18px;padding:18px 16px 14px;max-width:360px;width:100%;box-shadow:0 10px 40px rgba(0,0,0,.3)}
.cbox-t{font-size:14.5px;line-height:1.85;text-align:center}
.cbox-b{display:flex;gap:10px;margin-top:14px}
.cbox-b .btn{flex:1}

/* مقابض النص زي الآيفون: دواير صغيرة واضحة + مساحة لمس أكبر من غير ما تبان */
.obj .handle.tc{width:13px;height:13px;margin:0;border-radius:50%;background:var(--sel);border:2px solid #fff;box-shadow:0 0 0 1px rgba(30,136,229,.55),0 1px 3px rgba(0,0,0,.35);bottom:auto;left:auto;top:auto;right:auto}
.obj .handle.tc::after,.obj .handle.tstem::after{content:'';position:absolute;inset:-13px;border-radius:50%}
.obj .handle.tc-tl{left:-8px;top:-8px}.obj .handle.tc-tr{right:-8px;top:-8px}
.obj .handle.tc-bl{left:-8px;bottom:-8px}.obj .handle.tc-br{right:-8px;bottom:-8px}
.obj .handle.tc-tl,.obj .handle.tc-br{cursor:nwse-resize}.obj .handle.tc-tr,.obj .handle.tc-bl{cursor:nesw-resize}
.obj .handle.tstem{width:13px;height:13px;left:50%;bottom:-34px;margin-left:-8px;border-radius:50%;background:#1565c0;border:2px solid #fff;box-shadow:0 1px 3px rgba(0,0,0,.35);cursor:ns-resize}
.obj .handle.tstem::before{content:'';position:absolute;left:50%;bottom:13px;width:1.5px;height:20px;margin-left:-.75px;background:var(--sel)}

.kb-proxy{position:fixed;left:0;top:40%;width:2px;height:2px;opacity:0;border:0;padding:0;font-size:16px;pointer-events:none;z-index:-1}
