/* ============================================================
   محرّر المستندات — app.css
   واجهة داكنة + ورقة بيضاء + قواعد طباعة مطابقة
   ============================================================ */

:root{
  --bg:#0d1219;
  --bg2:#131a26;
  --bg3:#1a2333;
  --bg4:#212c3f;
  --line:#26324a;
  --line2:#33415c;
  --text:#e7eefb;
  --muted:#8a9ab5;
  --accent:#4f8cff;
  --accent-d:#2f6fe0;
  --danger:#ef4d5c;
  --ok:#22c55e;
  --paper:#ffffff;
  --ink:#111827;
  --radius:10px;
  --sb-w:290px;
  --top-h:58px;
  --doc-font: "Cairo", "Segoe UI", Tahoma, Arial, sans-serif;
}

*{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0; background:var(--bg); color:var(--text);
  font-family:"Segoe UI", Tahoma, Arial, sans-serif;
  font-size:14px; overflow:hidden;
  -webkit-font-smoothing:antialiased;
}
button{font-family:inherit; cursor:pointer}
input,select{font-family:inherit}
::-webkit-scrollbar{width:11px;height:11px}
::-webkit-scrollbar-track{background:transparent}
::-webkit-scrollbar-thumb{background:#2b3852;border-radius:6px;border:2px solid transparent;background-clip:padding-box}
::-webkit-scrollbar-thumb:hover{background:#3c4d6d;background-clip:padding-box}

.ic{width:18px;height:18px;fill:none;stroke:currentColor;stroke-width:1.7;stroke-linecap:round;stroke-linejoin:round;flex:none}

/* ==================== الهيكل ==================== */
.app{
  display:grid;
  grid-template-columns:var(--sb-w) 1fr;
  grid-template-rows:var(--top-h) 1fr;
  height:100vh;
}
.app.sb-closed{grid-template-columns:0 1fr}
.app.sb-closed .sidebar{transform:translateX(100%);opacity:0;pointer-events:none}

/* ==================== الشريط العلوي ==================== */
.topbar{
  grid-column:1/-1; grid-row:1;
  display:flex; align-items:center; gap:12px;
  padding:0 14px;
  background:linear-gradient(180deg,#151d2b,#111823);
  border-bottom:1px solid var(--line);
  z-index:40;
}
.brand{display:flex;align-items:center;gap:9px;flex:none}
.brand-logo{
  width:34px;height:34px;border-radius:9px;display:grid;place-items:center;
  background:linear-gradient(135deg,#2f6fe0,#5b9bff);
  color:#fff;box-shadow:0 4px 14px rgba(79,140,255,.35);
}
.brand-logo .ic{width:19px;height:19px;stroke-width:1.8}
.brand-txt{display:flex;flex-direction:column;line-height:1.15}
.brand-txt strong{font-size:13.5px;letter-spacing:.2px}
.brand-txt small{font-size:10.5px;color:var(--muted);letter-spacing:.3px}

.doc-title{
  flex:1; min-width:80px; max-width:520px;
  background:var(--bg3); border:1px solid transparent; color:var(--text);
  border-radius:8px; padding:8px 12px; font-size:14px; font-weight:600;
  transition:.15s;
}
.doc-title:hover{background:var(--bg4)}
.doc-title:focus{outline:none;background:var(--bg2);border-color:var(--accent)}

.topbar-actions{display:flex;align-items:center;gap:8px;margin-inline-start:auto;flex:none}
.save-state{
  display:inline-flex;align-items:center;gap:6px;
  font-size:11.5px;color:var(--muted);padding:4px 10px;border-radius:20px;
  background:#16202e;border:1px solid #202c40;white-space:nowrap;
}
.save-state i{width:6px;height:6px;border-radius:50%;background:var(--ok);display:block}
.save-state.dirty i{background:#f59e0b}
.save-state.saving i{background:var(--accent);animation:pulse .9s infinite}
@keyframes pulse{50%{opacity:.25}}

.btn{
  display:inline-flex;align-items:center;gap:7px;
  border:1px solid var(--line2); background:var(--bg3); color:var(--text);
  padding:8px 13px; border-radius:8px; font-size:13px; font-weight:600;
  transition:.15s; white-space:nowrap;
}
.btn:hover{background:var(--bg4);border-color:#42557a}
.btn:active{transform:translateY(1px)}
.btn.primary{background:linear-gradient(180deg,#4f8cff,#2f6fe0);border-color:#3b7bf0;color:#fff;box-shadow:0 4px 14px rgba(47,111,224,.35)}
.btn.primary:hover{background:linear-gradient(180deg,#5c96ff,#3a7af0)}
.btn.ghost{background:transparent}
.btn.ghost:hover{background:var(--bg3)}
.btn.danger{background:linear-gradient(180deg,#ef4d5c,#d32f3f);border-color:#e04150;color:#fff}
.btn.sm{padding:6px 10px;font-size:12px}
.btn.big{padding:11px 20px;font-size:14px}
.btn .ic{width:16px;height:16px}

.icon-btn{
  width:34px;height:34px;display:grid;place-items:center;flex:none;
  background:transparent;border:1px solid transparent;color:var(--muted);
  border-radius:8px;transition:.15s;
}
.icon-btn:hover{background:var(--bg3);color:var(--text)}
.only-mobile{display:none}

/* ==================== الشريط الجانبي ==================== */
.sidebar{
  grid-column:1; grid-row:2;
  display:flex;flex-direction:column;min-height:0;
  background:var(--bg2); border-inline-end:1px solid var(--line);
  transition:.22s ease;
}
.sb-head{display:flex;align-items:center;justify-content:space-between;padding:14px 12px 10px;gap:8px}
.sb-head h2{margin:0;font-size:13px;font-weight:700;letter-spacing:.3px;display:flex;align-items:center;gap:7px;white-space:nowrap}
.sb-actions{display:flex;gap:5px;flex:none}
.sb-actions .btn{padding:6px 9px}
.sb-actions .btn span{font-size:11.5px}
.sb-head .count{
  font-size:10.5px;background:var(--bg4);color:var(--muted);
  padding:1px 7px;border-radius:20px;font-weight:600;
}
.sb-search{
  margin:0 12px 10px; position:relative; display:flex; align-items:center;
  background:var(--bg3); border:1px solid var(--line); border-radius:8px; padding:0 9px;
}
.sb-search .ic{width:15px;height:15px;color:var(--muted)}
.sb-search input{
  flex:1;background:transparent;border:0;color:var(--text);
  padding:8px 7px;font-size:12.5px;outline:none;min-width:0;
}
.sb-search:focus-within{border-color:var(--accent)}

.doc-list{flex:1;overflow-y:auto;padding:2px 8px 12px;display:flex;flex-direction:column;gap:3px}
.doc-item{
  display:flex;align-items:center;gap:9px;padding:9px 9px;border-radius:9px;
  cursor:pointer;border:1px solid transparent;transition:.13s;position:relative;
}
.doc-item:hover{background:var(--bg3)}
.doc-item.active{background:#1c2c47;border-color:#2d4b7a}
.doc-item.active .di-icon{background:#27456f;color:#9cc4ff}
.di-icon{
  width:30px;height:30px;border-radius:7px;background:var(--bg4);
  display:grid;place-items:center;color:var(--muted);flex:none;
}
.di-icon .ic{width:15px;height:15px}
.di-main{flex:1;min-width:0}
.di-title{
  font-size:12.8px;font-weight:600;white-space:nowrap;overflow:hidden;
  text-overflow:ellipsis;margin-bottom:2px;
}
.di-title input{
  width:100%;background:var(--bg);border:1px solid var(--accent);border-radius:5px;
  color:var(--text);font-size:12.5px;padding:2px 5px;outline:none;font-weight:600;
}
.di-meta{font-size:10.5px;color:var(--muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.di-actions{display:flex;gap:1px;opacity:0;transition:.13s;flex:none}
.doc-item:hover .di-actions,.doc-item.active .di-actions{opacity:1}
.mini{
  width:24px;height:24px;display:grid;place-items:center;border:0;border-radius:6px;
  background:transparent;color:var(--muted);
}
.mini:hover{background:var(--bg4);color:var(--text)}
.mini .ic{width:14px;height:14px}
.mini:hover[data-act="del"]{color:#ff8a95;background:#3a1f26}

.empty{padding:26px 12px;text-align:center;color:var(--muted);font-size:12px}
.sb-foot{border-top:1px solid var(--line);padding:10px}
.account{
  display:flex;align-items:center;gap:9px;width:100%;padding:8px 9px;
  border-radius:9px;background:var(--bg3);border:1px solid var(--line);
  color:var(--text);text-align:start;transition:.14s;
}
.account:hover{background:var(--bg4);border-color:var(--line2)}
.acc-avatar{
  width:28px;height:28px;border-radius:8px;display:grid;place-items:center;flex:none;
  font-size:12px;font-weight:800;color:#fff;
  background:linear-gradient(135deg,#2f6fe0,#5b9bff);
}
.acc-avatar.local{background:linear-gradient(135deg,#475569,#64748b)}
.acc-main{flex:1;min-width:0;display:flex;flex-direction:column;line-height:1.35}
.acc-main b{font-size:11.5px;font-weight:700;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.acc-main small{font-size:10px;color:var(--muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.account .ic{width:14px;height:14px;color:var(--muted);flex:none}
.key-row{display:flex;gap:6px;align-items:center;width:100%}
.key-row input{flex:1 1 auto;min-width:0;font-family:ui-monospace,Consolas,"Courier New",monospace;font-size:11.5px;letter-spacing:.2px}
.key-row .btn{flex:0 0 auto}
.key-display{
  font-family:ui-monospace,Consolas,"Courier New",monospace;
  font-size:11.5px;line-height:1.75;letter-spacing:.3px;
  color:#d3e2ff;background:var(--bg);border:1px solid var(--line2);
  border-radius:8px;padding:9px 11px;
  word-break:break-all;direction:ltr;text-align:left;
  user-select:all;cursor:text;
}
.key-actions{display:flex;gap:9px;align-items:center;flex-wrap:wrap}
.hint-inline{font-size:10.5px;color:var(--muted)}
.acc-mode{
  font-size:12px;line-height:1.75;color:#a9b8d1;
  background:#101825;border:1px dashed #2a3852;border-radius:9px;
  padding:10px 12px;margin:0 0 14px;
}

/* ==================== مساحة العمل ==================== */
.workspace{
  grid-column:2; grid-row:2;
  display:flex;flex-direction:column;min-width:0;min-height:0;
  background:var(--bg);position:relative;
}
.workspace.drop-hover::after{
  content:'أفلت الملف هنا لفتحه';
  position:absolute;inset:10px;z-index:8;
  border:2px dashed #4f8cff;border-radius:16px;
  background:rgba(47,111,224,.12);
  display:flex;align-items:center;justify-content:center;
  font-size:16px;font-weight:800;color:#bcd6ff;
  pointer-events:none;backdrop-filter:blur(2px);
}

/* ---------- شريط الأدوات ---------- */
.toolbar{
  display:flex;flex-direction:column;gap:3px;
  padding:6px 10px 7px;background:var(--bg2);
  border-bottom:1px solid var(--line);
  position:relative;z-index:20;
}
.tb-row{
  display:flex;align-items:center;gap:5px;flex-wrap:nowrap;
  overflow-x:auto;overflow-y:hidden;
}
.tb-row::-webkit-scrollbar{height:4px}
.tb-row::-webkit-scrollbar-thumb{background:#2b3852;border-radius:3px;border:0}
.tb-group{display:flex;align-items:center;gap:2px;flex:none}
.tb-div{width:1px;height:22px;background:var(--line);margin:0 5px}
.tb{
  height:30px;min-width:30px;padding:0 5px;display:inline-flex;align-items:center;justify-content:center;gap:5px;
  background:transparent;border:1px solid transparent;border-radius:7px;
  color:#c3cfe4;font-size:12.5px;transition:.12s;
}
.tb:hover{background:var(--bg4);color:#fff}
.tb.on{background:#24406b;color:#9fc5ff;border-color:#2f5588}
.tb .ic{width:17px;height:17px}
.tb.txt{font-size:15px;font-weight:600;font-family:Georgia,serif;min-width:28px}
.tb.txt.bold{font-weight:800}
.tb.txt.ital{font-style:italic;font-family:Georgia,serif}
.tb.txt.und{text-decoration:underline}
.tb.txt.strk{text-decoration:line-through}
.tb.wide{padding:0 9px;font-size:12px}
.tb.wide span{font-size:12px}

.tb.color{position:relative;overflow:hidden;flex-direction:column;gap:0;padding:2px 4px 1px}
.tb.color .cl-a{font-size:13px;font-weight:700;line-height:1.05;border-bottom:3px solid #cfdaee;padding:0 1px;color:#dfe7f5}
.tb.color .cl-a.hl{border-bottom-color:#fde68a}
.tb.color input[type=color]{
  position:absolute;inset:0;opacity:0;cursor:pointer;width:100%;height:100%;border:0;padding:0;
}
.tb-select{
  height:30px;background:var(--bg3);border:1px solid var(--line);color:#cfdaee;
  border-radius:7px;font-size:12px;padding:0 7px;outline:none;cursor:pointer;
}
.tb-select:hover{border-color:var(--line2)}
.tb-select:focus{border-color:var(--accent)}
.w-font{width:132px}
.w-size{width:66px}
.w-block{width:112px}
.w-lh{width:80px}

/* ---------- الكانفاس ---------- */
.canvas{
  flex:1;overflow:auto;padding:28px 20px 60px;
  display:flex;justify-content:center;align-items:flex-start;
  background:
    radial-gradient(1100px 500px at 50% -10%,rgba(79,140,255,.07),transparent 70%),
    #0a0e15;
}
.sheet-wrap{display:flex;justify-content:center;width:100%}
.sheet{
  background:var(--paper);color:var(--ink);
  width:210mm;min-height:297mm;
  padding:20mm 15mm;
  box-shadow:0 18px 50px rgba(0,0,0,.55),0 0 0 1px rgba(255,255,255,.05);
  border-radius:2px;
  flex:none;
}
.editor{
  outline:none;min-height:100%;
  font-family:var(--doc-font);
  font-size:16px;line-height:1.9;color:var(--ink);
  direction:rtl;text-align:right;
  word-wrap:break-word;overflow-wrap:break-word;
}
.editor:empty::before{
  content:attr(data-placeholder);color:#9aa3b2;pointer-events:none;
}

/* ---------- تنسيق محتوى المستند ---------- */
.editor p{margin:0 0 10px}
.editor h1{font-size:30px;line-height:1.35;margin:18px 0 10px;font-weight:800;color:#0b1220}
.editor h2{font-size:23px;line-height:1.4;margin:16px 0 8px;font-weight:700;color:#111c33}
.editor h3{font-size:19px;line-height:1.45;margin:14px 0 6px;font-weight:700;color:#1a2740}
.editor ul,.editor ol{margin:0 0 10px;padding-inline-start:26px}
.editor li{margin:3px 0}
.editor blockquote{
  margin:12px 0;padding:10px 16px;border-inline-start:4px solid #4f8cff;
  background:#f2f6ff;color:#2b3a55;border-radius:0 8px 8px 0;font-style:normal;
}
.editor pre{
  background:#0f172a;color:#dbe7ff;padding:12px 14px;border-radius:8px;
  font-family:"Courier New",monospace;font-size:13px;line-height:1.7;
  overflow-x:auto;direction:ltr;text-align:left;
}
.editor a{color:#1d5fd8;text-decoration:underline}
.editor hr.doc-hr{border:0;border-top:2px solid #e2e8f0;margin:16px 0}
.editor img.doc-img{max-width:100%;height:auto;border-radius:6px;display:inline-block;cursor:pointer}
.editor img.doc-img:hover{outline:2px solid rgba(79,140,255,.55);outline-offset:2px}
.editor p.img-block{text-align:center;margin:12px 0}

.doc-table{
  width:100%;border-collapse:collapse;margin:12px 0;font-size:14px;
}
.doc-table th,.doc-table td{
  border:1px solid #cbd5e1;padding:8px 10px;text-align:start;vertical-align:top;
}
.doc-table thead th{background:#eef3fb;font-weight:700;color:#132038}
.doc-table tbody tr:nth-child(even){background:#f8fafc}

/* ---------- البانرات ---------- */
.doc-banner{
  padding:22px 26px;border-radius:12px;margin:14px 0;color:#fff;
  position:relative;overflow:hidden;break-inside:avoid;
}
.doc-banner .bn-title{font-size:26px;font-weight:800;line-height:1.35}
.doc-banner .bn-sub{font-size:14px;opacity:.92;margin-top:6px;line-height:1.6}
.banner-blue{background:linear-gradient(120deg,#1e3a8a,#2563eb 55%,#0ea5e9)}
.banner-violet{background:linear-gradient(120deg,#4c1d95,#7c3aed 55%,#db2777)}
.banner-sunset{background:linear-gradient(120deg,#7c2d12,#ea580c 50%,#f59e0b)}
.banner-emerald{background:linear-gradient(120deg,#064e3b,#059669 55%,#84cc16)}
.banner-dark{background:linear-gradient(120deg,#0f172a,#1e293b 60%,#334155)}
.banner-gold{background:linear-gradient(120deg,#78350f,#b45309 50%,#fbbf24)}
.banner-light{background:linear-gradient(120deg,#e0f2fe,#f1f5f9);color:#0f172a;border:1px solid #cbd5e1}

/* ---------- فاصل الصفحة ---------- */
.page-break{
  position:relative;height:34px;margin:14px 0;
  border-top:2px dashed #b9c4d6;
  display:flex;align-items:flex-start;justify-content:center;
  user-select:none;
}
.page-break span{
  position:absolute;top:-11px;background:#fff;padding:0 10px;
  font-size:11px;color:#8d99ad;font-family:"Segoe UI",sans-serif;
  letter-spacing:.5px;
}

/* ---------- شريط الحالة ---------- */
.statusbar{
  height:34px;display:flex;align-items:center;justify-content:space-between;
  padding:0 14px;background:var(--bg2);border-top:1px solid var(--line);
  font-size:11.5px;color:var(--muted);
}
.st-left{display:flex;align-items:center;gap:9px}
.dot{width:3px;height:3px;border-radius:50%;background:#3d4c66}
.st-right{display:flex;align-items:center;gap:2px}
.mini-z{
  width:24px;height:22px;border:0;background:transparent;color:var(--muted);
  border-radius:5px;font-size:15px;line-height:1;
}
.mini-z:hover{background:var(--bg4);color:var(--text)}
.zoom-val{
  background:transparent;border:0;color:#b6c4db;font-size:11.5px;
  min-width:44px;height:22px;border-radius:5px;font-weight:600;
}
.zoom-val:hover{background:var(--bg4)}

/* ==================== أدوات الصورة ==================== */
.img-tools{
  position:fixed;display:none;align-items:center;gap:2px;z-index:120;
  background:#182233;border:1px solid #2c3b57;border-radius:9px;
  padding:4px;box-shadow:0 10px 26px rgba(0,0,0,.5);
}
.img-tools button{
  border:0;background:transparent;color:#c9d6ea;font-size:11.5px;
  padding:5px 8px;border-radius:6px;font-weight:600;
}
.img-tools button:hover{background:#27354d;color:#fff}
.img-tools button.danger:hover{background:#3d1f26;color:#ff97a1}
.it-div{width:1px;height:16px;background:#2c3b57;margin:0 3px}

/* ==================== النوافذ ==================== */
.modal-overlay{
  position:fixed;inset:0;background:rgba(6,10,16,.72);
  backdrop-filter:blur(3px);
  display:none;align-items:center;justify-content:center;z-index:200;padding:20px;
}
.modal-overlay.show{display:flex}
.modal{
  width:min(560px,100%);max-height:90vh;overflow:auto;
  background:var(--bg2);border:1px solid var(--line2);border-radius:14px;
  box-shadow:0 30px 80px rgba(0,0,0,.65);
  animation:pop .16s ease-out;
}
.modal.narrow{width:min(400px,100%)}
@keyframes pop{from{opacity:0;transform:translateY(10px) scale(.985)}}
.modal-head{
  display:flex;align-items:center;justify-content:space-between;
  padding:14px 16px;border-bottom:1px solid var(--line);
}
.modal-head h3{margin:0;font-size:14.5px;font-weight:700}
.modal-body{padding:16px}
.modal-foot{
  display:flex;justify-content:flex-end;gap:8px;padding:13px 16px;
  border-top:1px solid var(--line);background:#111927;
  border-radius:0 0 14px 14px;
}
.field-row{display:flex;align-items:center;gap:12px;margin-bottom:12px}
.field-row.col{flex-direction:column;align-items:stretch;gap:8px}
.field-row label{font-size:12.5px;color:#a9b8d1;font-weight:600;min-width:96px}
.field-row.col label{min-width:0}
.field-row input[type=text],.field-row input[type=number],.field-row select{
  flex:1;background:var(--bg);border:1px solid var(--line2);color:#f1f6ff;
  border-radius:8px;padding:9px 11px;font-size:13px;outline:none;min-width:0;
  font-weight:500;
}
.field-row input::placeholder{color:#61708a}
.field-row input:focus,.field-row select:focus{border-color:var(--accent)}
.seg{display:flex;background:var(--bg);border:1px solid var(--line2);border-radius:8px;padding:2px;flex:1}
.seg button{
  flex:1;border:0;background:transparent;color:var(--muted);
  padding:7px;border-radius:6px;font-size:12.5px;font-weight:600;
}
.seg button.on{background:var(--accent);color:#fff}
.margins-grid{display:grid;grid-template-columns:1fr 1fr;gap:8px}
.margins-grid > div{display:flex;align-items:center;gap:8px;background:var(--bg);border:1px solid var(--line2);border-radius:8px;padding:5px 9px}
.margins-grid span{font-size:11.5px;color:var(--muted);min-width:32px}
.margins-grid input{flex:1;background:transparent;border:0;color:var(--text);font-size:13px;outline:none;width:100%;text-align:center}
.presets{display:flex;gap:6px;flex-wrap:wrap}
.presets button{
  background:var(--bg3);border:1px solid var(--line2);color:#b9c7de;
  border-radius:20px;padding:5px 12px;font-size:11.5px;
}
.presets button:hover{background:var(--bg4);color:#fff}
.hint{margin:4px 0 0;font-size:11.5px;color:var(--muted);line-height:1.6}

.swatches{display:flex;gap:8px;flex-wrap:wrap}
.sw{width:44px;height:30px;border-radius:7px;border:2px solid transparent;padding:0}
.sw.on{border-color:#fff;box-shadow:0 0 0 2px var(--accent)}
.bn-preview{background:#fff;border-radius:10px;padding:10px;margin-top:4px}
.bn-preview .doc-banner{margin:0}
.bn-preview .bn-title{font-size:19px}
.bn-preview .bn-sub{font-size:12px}

.switch{position:relative;width:42px;height:23px;flex:none;display:inline-block;cursor:pointer}
.switch input{position:absolute;opacity:0;width:100%;height:100%;margin:0;cursor:pointer}
.switch i{position:absolute;inset:0;background:var(--bg4);border-radius:20px;transition:.18s}
.switch i::after{content:"";position:absolute;width:17px;height:17px;background:#8fa1bd;border-radius:50%;top:3px;left:3px;transition:.18s}
.switch input:checked + i{background:#2f6fe0}
.switch input:checked + i::after{transform:translateX(19px);background:#fff}

.export-hero{display:flex;gap:13px;align-items:flex-start;background:linear-gradient(120deg,#1b2a44,#16233a);border:1px solid #2a3f61;border-radius:11px;padding:14px;margin-bottom:14px}
.eh-icon{width:40px;height:40px;border-radius:10px;background:linear-gradient(135deg,#2f6fe0,#5b9bff);display:grid;place-items:center;color:#fff;flex:none}
.export-hero h4{margin:0 0 5px;font-size:14px}
.export-hero p{margin:0;font-size:12.3px;line-height:1.75;color:#a9bad4}
.export-hero b{color:#dbe7fb}
.export-steps{display:flex;flex-direction:column;gap:7px;margin-bottom:14px}
.export-steps > div{display:flex;align-items:center;gap:9px;font-size:12.3px;color:#b7c5dc}
.export-steps b{
  width:19px;height:19px;border-radius:50%;background:var(--bg4);color:#9fc5ff;
  font-size:11px;display:grid;place-items:center;flex:none;
}
.export-steps span{color:#e7eefb;background:#1d2941;padding:1px 6px;border-radius:5px;font-size:11.5px}
.export-info{font-size:11.8px;color:var(--muted);background:#101825;border:1px dashed #2a3852;border-radius:9px;padding:10px 12px;line-height:1.7;margin-bottom:14px}
.export-alt{display:flex;gap:8px;flex-wrap:wrap}
.export-alt .btn{flex:1;justify-content:center}
.confirm-msg{margin:0;font-size:13px;line-height:1.8;color:#c6d3e8}

/* ==================== Toast ==================== */
.toast-wrap{position:fixed;bottom:22px;left:50%;transform:translateX(-50%);z-index:300;display:flex;flex-direction:column;gap:8px;align-items:center;pointer-events:none}
.toast{
  background:#1c2839;border:1px solid #2f4160;color:#e7eefb;
  padding:9px 16px;border-radius:22px;font-size:12.5px;font-weight:600;
  box-shadow:0 10px 30px rgba(0,0,0,.5);
  animation:tin .2s ease-out;display:flex;align-items:center;gap:8px;
}
.toast.ok{border-color:#1f6b46;background:#12291f;color:#a9f0c4}
.toast.warn{border-color:#6b521f;background:#2a2312;color:#f7dda1}
@keyframes tin{from{opacity:0;transform:translateY(8px)}}

/* ==================== استجابة ==================== */
@media (max-width:900px){
  .app,.app.sb-closed{grid-template-columns:1fr}
  .sidebar{position:fixed;top:var(--top-h);bottom:0;inset-inline-start:0;width:270px;z-index:60;box-shadow:-20px 0 50px rgba(0,0,0,.5)}
  .app.sb-closed .sidebar{transform:translateX(100%)}
  .workspace{grid-column:1}
  .only-mobile{display:grid}
  .hide-sm{display:none}
  .brand-txt{display:none}
  .canvas{padding:14px 8px 50px}
  .sheet{width:100%!important;min-height:auto!important;padding:16px!important;border-radius:8px}
  .doc-title{max-width:none}

  /* شريط أدوات مضغوط: سطران قابلان للتمرير أفقياً */
  .toolbar{padding:5px 8px 6px;gap:2px}
  .tb.wide span{display:none}
  .tb.wide{padding:0 6px}
  .tb-div{margin:0 3px}
  .w-font{width:112px}
  .w-block{width:96px}
}
@media (max-width:560px){
  .save-state{display:none}
  .btn.primary span{display:none}
  .btn.primary{padding:9px 11px}
}

/* ============================================================
   الطباعة / PDF
   ============================================================ */
@media print{
  @page{ } /* تُحقن ديناميكياً في <style id="pageStyle"> */
  html,body{
    height:auto!important;overflow:visible!important;
    background:#fff!important;color:#000!important;
  }
  .topbar,.sidebar,.toolbar,.statusbar,.modal-overlay,.toast-wrap,.img-tools,
  .page-break span,.only-mobile{display:none!important}

  .app{display:block!important;height:auto!important}
  .workspace{display:block!important;overflow:visible!important;height:auto!important;min-height:0!important;background:#fff!important}
  .canvas{
    display:block!important;overflow:visible!important;
    padding:0!important;height:auto!important;background:#fff!important;
  }
  .sheet-wrap{display:block!important;width:auto!important;margin:0!important;padding:0!important}
  .sheet{
    width:auto!important;min-height:0!important;
    padding:0!important;margin:0!important;
    box-shadow:none!important;border:0!important;border-radius:0!important;
    background:#fff!important;zoom:1!important;
  }
  .editor{min-height:0!important;outline:none!important;color:#111!important}

  .page-break{
    height:0!important;margin:0!important;border:0!important;
    break-after:page!important;page-break-after:always!important;
  }
  .doc-banner,blockquote,pre{break-inside:avoid;page-break-inside:avoid}
  .editor h1,.editor h2,.editor h3{break-after:avoid;page-break-after:avoid}
  .doc-table{break-inside:auto}
  .doc-table tr,.doc-table td,.doc-table th{break-inside:avoid}
  img.doc-img{max-width:100%!important}
  *{
    -webkit-print-color-adjust:exact!important;
    print-color-adjust:exact!important;
  }
}
