:root {
  --g: #107c41; --g2: #0b5e31; --g-soft: #e7f3ec;
  --bg: #f4f6f5; --card: #fff; --ink: #1d2521; --muted: #6b7a72; --line: #dfe5e1;
  --warn: #b26a00; --err: #c62828; --info: #1565c0;
  --r: 12px;
  --font: "Segoe UI", Tahoma, "Noto Sans Arabic", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--font); color: var(--ink); background: var(--bg); }
body.dash { min-height: 100vh; }
a { color: var(--g); }

/* ---------- أزرار ---------- */
.btn {
  font: inherit; font-size: 14px; border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 8px 14px; border-radius: 9px; cursor: pointer; text-decoration: none; display: inline-flex;
  align-items: center; justify-content: center; gap: 6px; white-space: nowrap; transition: background .15s, border-color .15s;
}
.btn:hover { background: #f0f3f1; border-color: #cfd8d3; }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--g); border-color: var(--g); color: #fff; }
.btn.primary:hover { background: var(--g2); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: rgba(0,0,0,.05); }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 7px; }
.btn.icon { width: 36px; padding: 0; height: 34px; font-size: 18px; }
.btn.sm.icon { width: 30px; height: 28px; }
.btn.block { width: 100%; }
.link-btn { background: none; border: 0; color: var(--muted); font: inherit; font-size: 12px; cursor: pointer; padding: 4px 0; text-decoration: underline; }

.logo { width: 42px; height: 42px; border-radius: 10px; background: var(--g); display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 22px; flex: none; }
.logo.sm { width: 30px; height: 30px; border-radius: 7px; font-size: 16px; }

/* ---------- الدخول ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(160deg, #e7f3ec, #f4f6f5 60%); }
.login-card { width: 100%; max-width: 360px; background: #fff; border-radius: 18px; padding: 32px 26px; box-shadow: 0 12px 40px rgba(16,124,65,.12); text-align: center; }
.login-card .logo { margin: 0 auto 14px; width: 56px; height: 56px; font-size: 28px; }
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card p { margin: 0 0 22px; color: var(--muted); }
.login-card input { width: 100%; font: inherit; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 12px; font-size: 15px; }
.login-card input:focus { outline: 2px solid var(--g-soft); border-color: var(--g); }
.login-card .btn { padding: 12px; font-size: 15px; }
.login-err { color: var(--err); min-height: 20px; margin-top: 10px; font-size: 14px; }

/* ---------- لوحة التحكم ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 10px 20px; background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.brand { display: flex; align-items: center; gap: 10px; font-size: 17px; }
.container { max-width: 980px; margin: 0 auto; padding: 22px 16px 60px; }
.hero { display: flex; gap: 12px; align-items: stretch; margin-bottom: 26px; }
.hero > .btn { flex: none; }
.drop {
  flex: 1; border: 2px dashed #b9cfc2; background: #fff; border-radius: var(--r); padding: 26px 18px; text-align: center;
  cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 6px; transition: .15s;
}
.drop:hover, .drop.hover { border-color: var(--g); background: var(--g-soft); }
.drop-ico { width: 44px; height: 44px; border-radius: 50%; background: var(--g-soft); color: var(--g); display: grid; place-items: center; font-size: 20px; }
.drop small { color: var(--muted); }

.list-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.list-head h2 { font-size: 18px; margin: 0; }
.list-head h2 span { color: var(--muted); font-weight: 400; font-size: 15px; }
.list-head input { font: inherit; padding: 8px 12px; border: 1px solid var(--line); border-radius: 9px; width: 220px; max-width: 50%; background: #fff; }

.books { display: grid; gap: 10px; }
.book { display: flex; align-items: center; gap: 12px; background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; transition: box-shadow .15s; }
.book:hover { box-shadow: 0 4px 16px rgba(0,0,0,.06); }
.book-main { flex: 1; display: flex; align-items: center; gap: 12px; text-decoration: none; color: inherit; min-width: 0; }
.book-ico { width: 40px; height: 40px; border-radius: 9px; background: var(--g-soft); color: var(--g); font-weight: 800; display: grid; place-items: center; flex: none; }
.book-info { min-width: 0; }
.book-info b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.book-info small { color: var(--muted); font-size: 12.5px; }
.badges { display: flex; gap: 5px; margin-top: 4px; }
.badge { font-size: 11px; background: var(--g-soft); color: var(--g2); padding: 2px 7px; border-radius: 20px; }
.badge.warn { background: #fff3e0; color: var(--warn); }
.book-actions { display: flex; gap: 6px; flex: none; }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; background: #fff; border-radius: var(--r); border: 1px solid var(--line); }
.muted { color: var(--muted); font-size: 13.5px; }

/* ---------- نوافذ ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(20,30,25,.45); display: grid; place-items: center; z-index: 100000; padding: 16px; animation: fade .15s; }
.modal { position: relative; background: #fff; border-radius: 16px; width: 100%; max-width: 460px; padding: 22px 20px 18px; max-height: 90vh; overflow: auto; direction: rtl; text-align: right; font-family: var(--font); }
.modal.wide { max-width: 640px; }
.modal h3 { margin: 0 0 14px; font-size: 17px; padding-left: 30px; }
.modal-x { position: absolute; top: 12px; left: 12px; width: 30px; height: 30px; border-radius: 50%; border: 0; background: #f0f3f1; cursor: pointer; font-size: 18px; line-height: 1; }
.menu { display: grid; gap: 4px; }
.menu-item { font: inherit; text-align: right; background: none; border: 0; padding: 11px 12px; border-radius: 9px; cursor: pointer; color: var(--ink); text-decoration: none; font-size: 14.5px; }
.menu-item:hover { background: #f0f3f1; }
.menu-item.danger { color: var(--err); }
.versions { display: grid; gap: 6px; }
.ver { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 9px; }
.ver span { flex: 1; direction: ltr; text-align: right; }
.ver small { color: var(--muted); }

.share-row { border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-bottom: 10px; }
.share-row.off .share-link { opacity: .45; }
.share-head { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 8px; }
.share-head b { display: block; }
.share-head small { color: var(--muted); font-size: 12.5px; }
.share-link { display: flex; gap: 6px; }
.share-link input { flex: 1; min-width: 0; font: inherit; font-size: 12.5px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 7px; background: #f7f9f8; }
.switch { position: relative; width: 40px; height: 22px; flex: none; margin-top: 2px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: #cfd8d3; border-radius: 20px; cursor: pointer; transition: .2s; }
.switch span::after { content: ""; position: absolute; width: 16px; height: 16px; top: 3px; right: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + span { background: var(--g); }
.switch input:checked + span::after { right: 21px; }

/* ---------- إشعارات وتحميل ---------- */
#toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 100001; display: grid; gap: 8px; direction: rtl; font-family: var(--font); }
.toast { background: #24302a; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; box-shadow: 0 6px 20px rgba(0,0,0,.2); animation: up .2s; text-align: center; }
.toast.ok { background: var(--g); }
.toast.err { background: var(--err); }
.toast.out { opacity: 0; transition: .3s; }
.busy { position: fixed; inset: 0; background: rgba(255,255,255,.75); z-index: 100000; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; font-family: var(--font); direction: rtl; }
.spin { width: 34px; height: 34px; border: 3px solid var(--g-soft); border-top-color: var(--g); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(8px); opacity: 0; } }

/* ---------- صفحة الشيت ---------- */
@font-face { font-family: "Noto Sans Arabic"; src: url(fonts/noto-sans-arabic-arabic-400-normal.woff2) format("woff2"); font-weight: 400; font-display: swap; unicode-range: U+0600-06FF, U+0750-077F, U+0870-08FF, U+FB50-FDFF, U+FE70-FEFF; }
@font-face { font-family: "Noto Sans Arabic"; src: url(fonts/noto-sans-arabic-arabic-700-normal.woff2) format("woff2"); font-weight: 700; font-display: swap; unicode-range: U+0600-06FF, U+0750-077F, U+0870-08FF, U+FB50-FDFF, U+FE70-FEFF; }
@font-face { font-family: "Noto Naskh Arabic"; src: url(fonts/noto-naskh-arabic-arabic-400-normal.woff2) format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Noto Naskh Arabic"; src: url(fonts/noto-naskh-arabic-arabic-700-normal.woff2) format("woff2"); font-weight: 700; font-display: swap; }
/* بدائل للخطوط العربية الشائعة لو مش متسطبة على الجهاز */
@font-face { font-family: "Simplified Arabic"; src: local("Simplified Arabic"), url(fonts/noto-naskh-arabic-arabic-400-normal.woff2) format("woff2"); font-weight: 400; }
@font-face { font-family: "Simplified Arabic"; src: local("Simplified Arabic Bold"), url(fonts/noto-naskh-arabic-arabic-700-normal.woff2) format("woff2"); font-weight: 700; }
@font-face { font-family: "Traditional Arabic"; src: local("Traditional Arabic"), url(fonts/noto-naskh-arabic-arabic-400-normal.woff2) format("woff2"); font-weight: 400; }
@font-face { font-family: "Traditional Arabic"; src: local("Traditional Arabic Bold"), url(fonts/noto-naskh-arabic-arabic-700-normal.woff2) format("woff2"); font-weight: 700; }

body.sheet-page { overflow: hidden; height: 100vh; height: 100dvh; display: flex; flex-direction: column; background: #fff; }
.sbar { height: 50px; flex: none; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 0 12px; border-bottom: 1px solid var(--line); background: #fff; font-family: var(--font); }
.sbar-start, .sbar-end { display: flex; align-items: center; gap: 8px; min-width: 0; }
.sbar-start { flex: 1; }
.doc-name { font: inherit; font-size: 15.5px; font-weight: 600; border: 1px solid transparent; border-radius: 7px; padding: 5px 8px; min-width: 80px; max-width: 340px; width: 100%; background: transparent; }
.doc-name:hover { border-color: var(--line); }
.doc-name:focus { outline: none; border-color: var(--g); background: #fff; }
.doc-name-ro { font-size: 15.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status { font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.status.ok { color: var(--g); } .status.warn { color: var(--warn); } .status.busy { color: var(--info); } .status.err { color: var(--err); font-weight: 600; }
.autosave { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); cursor: pointer; white-space: nowrap; user-select: none; }
.autosave .switch { margin-top: 0; }
.pill { font-size: 12px; background: #f0f3f1; color: var(--muted); padding: 4px 10px; border-radius: 20px; }
.banner { flex: none; padding: 8px 14px; font-size: 14px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-family: var(--font); }
.banner.err { background: #fdecea; color: #8a1c1c; } .banner.info { background: #e8f1fc; color: #0d3c78; }
.banner[hidden] { display: none; }
#sheetRoot { flex: 1; min-height: 0; position: relative; }
.loader { position: fixed; inset: 50px 0 0 0; background: #fff; z-index: 2000; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; font-family: var(--font); direction: rtl; color: var(--muted); text-align: center; padding: 20px; }
.loader[hidden] { display: none; }

/* ===== الجدول ===== */
.xg { --xg-cell: #fff; --xg-ink: #000; --xg-grid: #e1e1e1; --xg-hd: #f5f6f7; --xg-hdline: #d4d7da; --xg-sel: #107c41;
  position: absolute; inset: 0; display: flex; flex-direction: column; font-family: var(--font); background: #fff; color: #000; }
.xg-tb { flex: none; display: flex; align-items: center; gap: 3px; padding: 5px 8px; border-bottom: 1px solid var(--line); background: #fafbfa; overflow-x: auto; scrollbar-width: thin; }
.xg-tb .tb { min-width: 30px; height: 30px; border: 1px solid transparent; background: transparent; border-radius: 6px; cursor: pointer; font-size: 15px; color: #333; display: inline-flex; align-items: center; justify-content: center; padding: 0 6px; flex: none; position: relative; }
.xg-tb .tb:hover { background: #eef1ef; }
.xg-tb .tb.on { background: #dfeee5; border-color: #b5d6c2; color: var(--g2); }
.xg-tb .tb:disabled { opacity: .35; cursor: default; }
.xg-tb select { height: 30px; border: 1px solid var(--line); border-radius: 6px; background: #fff; font: inherit; font-size: 13px; padding: 0 4px; flex: none; max-width: 150px; }
.xg-tb .tb-font { width: 130px; } .xg-tb .tb-size { width: 56px; }
.xg-tb .sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; flex: none; }
.tb-color { flex-direction: column; gap: 0; }
.tb-color .ic { font-weight: 700; line-height: 1; padding-top: 2px; }
.tb-color .bar { display: block; width: 18px; height: 4px; border-radius: 2px; }
.tb-color input { position: absolute; inset-inline-end: -2px; bottom: -2px; width: 12px; height: 12px; padding: 0; border: 0; opacity: .01; cursor: pointer; }
.tb-color::after { content: "▾"; position: absolute; inset-inline-end: 0; bottom: 0; font-size: 8px; color: #888; pointer-events: none; }

.xg-fbar { flex: none; display: flex; align-items: center; gap: 6px; padding: 4px 8px; border-bottom: 1px solid var(--line); background: #fff; }
.xg-name { width: 92px; flex: none; border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px; font: inherit; font-size: 13px; text-align: center; direction: ltr; background: #fafbfa; }
.xg-editbtn { flex: none; width: 30px; height: 28px; border: 1px solid var(--line); border-radius: 6px; background: #fff; cursor: pointer; font-size: 15px; color: var(--g2); }
.xg-editbtn:hover { background: var(--g-soft); }
.xg-fx { color: #888; font-style: italic; font-family: Georgia, serif; flex: none; }
.xg-finput { flex: 1; min-width: 0; border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; font: 14px var(--font); }
.xg-finput:focus { outline: none; border-color: var(--g); }

.xg-body { flex: 1; min-height: 0; position: relative; display: grid; overflow: hidden; background: #fff; user-select: none; -webkit-user-select: none; touch-action: manipulation; }
.xg-body .p { position: relative; overflow: hidden; }
.xg-body .lay { position: absolute; top: 0; inset-inline-start: 0; width: 0; height: 0; will-change: transform; }
.p-corner { grid-area: 1 / 1 / 2 / 2; background: var(--xg-hd); border-inline-end: 1px solid var(--xg-hdline); border-bottom: 1px solid var(--xg-hdline); cursor: pointer; }
.p-ch1 { grid-area: 1 / 2 / 2 / 3; } .p-ch2 { grid-area: 1 / 3 / 2 / 4; }
.p-rh1 { grid-area: 2 / 1 / 3 / 2; } .p-rh2 { grid-area: 3 / 1 / 4 / 2; }
.p-tl { grid-area: 2 / 2 / 3 / 3; } .p-tr { grid-area: 2 / 3 / 3 / 4; } .p-bl { grid-area: 3 / 2 / 4 / 3; }
.p-br { grid-area: 3 / 3 / 4 / 4; overflow: auto !important; overscroll-behavior: contain; }
.p-br .spacer { position: absolute; top: 0; inset-inline-start: 0; pointer-events: none; }
.p-ch1, .p-ch2 { background: var(--xg-hd); border-bottom: 1px solid var(--xg-hdline); }
.p-rh1, .p-rh2 { background: var(--xg-hd); border-inline-end: 1px solid var(--xg-hdline); }
.p-tl, .p-tr { border-bottom: 2px solid #b9c2bd; }
.p-tl, .p-bl { border-inline-end: 2px solid #b9c2bd; }
.p-tl:empty, .p-tr:empty { border: 0; }
.xg-body .hd { position: absolute; display: flex; align-items: center; justify-content: center; font-size: 12px; color: #555; box-sizing: border-box; font-family: "Segoe UI", Tahoma, Arial, sans-serif; }
.p-ch1 .hd, .p-ch2 .hd { top: 0; border-inline-end: 1px solid var(--xg-hdline); }
.p-rh1 .hd, .p-rh2 .hd { inset-inline-start: 0; border-bottom: 1px solid var(--xg-hdline); }
.xg-body .hd.on { background: #d6eadd; color: var(--g2); font-weight: 600; }
.p-ch1 .hd.on, .p-ch2 .hd.on { box-shadow: inset 0 -2px 0 var(--xg-sel); }
.p-rh1 .hd.on, .p-rh2 .hd.on { box-shadow: inset -2px 0 0 var(--xg-sel); }
[dir=rtl] .p-rh1 .hd.on, [dir=rtl] .p-rh2 .hd.on { box-shadow: inset 2px 0 0 var(--xg-sel); }
.hd .rz { position: absolute; z-index: 2; }
.p-ch1 .rz, .p-ch2 .rz { top: 0; bottom: 0; inset-inline-end: -4px; width: 8px; cursor: col-resize; }
.p-rh1 .rz, .p-rh2 .rz { inset-inline-start: 0; inset-inline-end: 0; bottom: -4px; height: 8px; cursor: row-resize; }
.ro .hd .rz { display: none; }

.xg .gl { position: absolute; background: var(--xg-grid); pointer-events: none; }
.xg .gl.h { height: 1px; } .xg .gl.v { width: 1px; }
.xg.nogrid .gl { display: none; }
.xg .bg { position: absolute; pointer-events: none; }
.xg .bd { position: absolute; pointer-events: none; box-sizing: border-box; height: 0; width: 0; }
.xg .tx { position: absolute; display: flex; overflow: hidden; padding: 0 3px; box-sizing: border-box; pointer-events: none; line-height: 1.15; }
.xg .tx > span { max-width: 100%; }
.xg .tx:not(.wr) > span { white-space: pre; }
.xg .tx.wr > span { white-space: pre-wrap; overflow-wrap: anywhere; }
.xg .im { position: absolute; pointer-events: none; object-fit: fill; }
.xg .im.chart { background: repeating-linear-gradient(45deg, #f7faf8, #f7faf8 10px, #eef4f0 10px, #eef4f0 20px); border: 1px dashed #9fb8a8; display: flex; align-items: center; justify-content: center; text-align: center; color: #4d6b59; font-size: 13px; }
.xg .sel { position: absolute; background: rgba(16,124,65,.10); border: 1px solid rgba(16,124,65,.6); pointer-events: none; box-sizing: border-box; }
.xg .act { position: absolute; border: 2px solid var(--xg-sel); pointer-events: none; box-sizing: border-box; }
.xg .refhl { position: absolute; border: 2px dashed #1565c0; background: rgba(21,101,192,.08); pointer-events: none; box-sizing: border-box; }
.xg-editor { position: absolute; z-index: 20; opacity: 0; width: 1px; height: 1px; padding: 1px 3px; margin: 0; border: 0; outline: 0; resize: none; overflow: hidden; background: #fff; color: #000; caret-color: #000; white-space: pre; box-sizing: border-box; line-height: 1.15; }
.xg-editor.on { opacity: 1; border: 2px solid var(--xg-sel); box-shadow: 0 2px 10px rgba(0,0,0,.15); }
.xg-guide { position: absolute; z-index: 30; background: var(--xg-sel); pointer-events: none; }
.xg-guide.v { top: 0; bottom: 0; width: 1px; } .xg-guide.h { inset-inline-start: 0; inset-inline-end: 0; height: 1px; }

.xg-foot { flex: none; display: flex; align-items: center; gap: 6px; height: 34px; border-top: 1px solid var(--line); background: #f7f8f7; padding: 0 6px; font-size: 13px; }
.xg-tabs { display: flex; gap: 2px; overflow-x: auto; min-width: 0; flex: 0 1 auto; scrollbar-width: none; height: 100%; align-items: stretch; }
.xg-tabs .tab { border: 0; background: transparent; padding: 0 14px; font: inherit; font-size: 13px; cursor: pointer; white-space: nowrap; border-bottom: 3px solid var(--tabc, transparent); color: #444; }
.xg-tabs .tab:hover { background: #eceeed; }
.xg-tabs .tab.on { background: #fff; color: var(--g2); font-weight: 700; border-bottom-color: var(--g); box-shadow: 0 0 0 1px var(--line); }
.xg-addsheet { border: 0; background: transparent; font-size: 18px; width: 28px; height: 28px; border-radius: 6px; cursor: pointer; color: #555; flex: none; }
.xg-addsheet:hover { background: #e6e9e7; }
.xg-stats { flex: 1; text-align: center; color: #555; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.xg-stats b { color: #222; }
.xg-zoom { display: flex; align-items: center; gap: 4px; flex: none; direction: ltr; }
.xg-zoom button { width: 24px; height: 24px; border: 1px solid var(--line); background: #fff; border-radius: 5px; cursor: pointer; }
.xg-zoom .zv { min-width: 40px; text-align: center; font-size: 12px; color: #555; }
.xg-menu { position: fixed; z-index: 100002; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.15); padding: 5px; min-width: 190px; font-family: var(--font); }
.xg-menu button { display: block; width: 100%; text-align: right; border: 0; background: none; padding: 8px 12px; font: inherit; font-size: 14px; border-radius: 6px; cursor: pointer; color: var(--ink); }
.xg-menu button:hover { background: #f0f3f1; }
.xg-menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }

@media (max-width: 640px) {
  .hero { flex-direction: column; }
  .book { flex-wrap: wrap; }
  .book-actions { width: 100%; justify-content: flex-end; }
  .list-head input { width: 140px; }
  .sbar { padding: 0 8px; gap: 6px; }
  .xg-name { width: 64px; }
  .xg-stats { display: none; }
  .sbar .btn { padding: 6px 9px; font-size: 13px; }
  .status { display: none; }
  .autosave b { display: none; }
  .doc-name { max-width: 140px; }
}

/* زرار الحفظ لما يكون في تعديلات والحفظ التلقائي مقفول */
.btn.pulse { box-shadow: 0 0 0 0 rgba(16,124,65,.6); animation: pulse 1.6s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(16,124,65,.55); } 70% { box-shadow: 0 0 0 8px rgba(16,124,65,0); } 100% { box-shadow: 0 0 0 0 rgba(16,124,65,0); } }

/* ===== الأقسام والفولدرات ===== */
.sections { display: flex; gap: 10px; margin-bottom: 16px; overflow-x: auto; padding-bottom: 2px; }
.sec { flex: 1; min-width: 150px; display: flex; flex-direction: column; align-items: flex-start; gap: 3px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 14px; background: #fff; cursor: pointer; font: inherit; text-align: start; transition: .15s; }
.sec b { font-size: 18px; } .sec small { color: var(--muted); }
.sec:hover { border-color: #b9cfc2; }
.sec.on { border-color: var(--g); box-shadow: 0 0 0 3px var(--g-soft); background: linear-gradient(180deg, #fff, #f6fbf8); }
.bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.crumbs { font-size: 16px; font-weight: 600; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.crumbs a { color: var(--ink); text-decoration: none; padding: 2px 6px; border-radius: 6px; }
.crumbs a:hover { background: #eef1ef; }
.crumbs a:last-child { color: var(--g2); }
.crumbs span { color: var(--muted); }
.bar-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.drop.slim { flex-direction: row; justify-content: center; padding: 12px 16px; margin-bottom: 16px; gap: 10px; }
.drop.slim .drop-ico { width: 32px; height: 32px; font-size: 16px; flex: none; }
.drop.slim small { color: var(--muted); margin-inline-start: 6px; }
.sum-strip { display: flex; gap: 16px; flex-wrap: wrap; align-items: center; font-size: 14px; }
.sum-strip b { font-size: 15px; }
.t-plus { color: #0b7a3b; } .t-minus { color: var(--err); }
.folders { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; margin-bottom: 12px; }
.folders:empty { display: none; }
.folder { display: flex; align-items: center; gap: 6px; background: #fffdf5; border: 1px solid #efe3bf; border-radius: 12px; padding: 10px 10px 10px 6px; }
.folder:hover { box-shadow: 0 4px 16px rgba(0,0,0,.06); }
.folder-main { flex: 1; display: flex; gap: 10px; align-items: center; text-decoration: none; color: inherit; min-width: 0; }
.folder-ico { font-size: 28px; flex: none; }
.folder-info { min-width: 0; display: flex; flex-direction: column; }
.folder-info b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder-info small { color: var(--muted); font-size: 12px; }
.chip { display: inline-block; font-size: 12.5px; font-weight: 600; padding: 3px 9px; border-radius: 20px; white-space: nowrap; direction: rtl; }
.chip.plus { background: #e3f4ea; color: #0b6b34; }
.chip.minus { background: #fdecea; color: #b3261e; }
.chip.zero { background: #f0f3f1; color: #555; }
.chip.muted { background: #f3f4f3; color: #888; font-weight: 400; }
.chip.err { background: #fff3e0; color: var(--warn); }
.book-bal { flex: none; }
.excluded { opacity: .62; }
.excluded .book-ico, .excluded .folder-ico { filter: grayscale(1); }
.picker { max-height: 50vh; overflow: auto; border: 1px solid var(--line); border-radius: 10px; padding: 6px 0; }
.pick { display: flex; align-items: center; gap: 8px; padding: 7px 12px; cursor: pointer; }
.pick:hover { background: #f4f7f5; }
.pick.root { border-top: 1px solid var(--line); margin-top: 4px; padding-top: 10px; }
.pick.root:first-child { border-top: 0; margin-top: 0; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; flex-wrap: wrap; }
.form-row { display: flex; gap: 10px; margin-top: 10px; }
.form-row label { flex: 1; display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.form-row input { font: inherit; font-size: 15px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; color: var(--ink); }
@media (max-width: 640px) {
  .book-bal { order: 3; }
  .bar-actions .btn { padding: 7px 10px; font-size: 13px; }
  .sec { min-width: 120px; padding: 10px 12px; }
}
.xg .mark { position: absolute; border: 2px dashed #d39e00; background: rgba(255, 193, 7, .12); pointer-events: none; box-sizing: border-box; }
.xg .mark i { position: absolute; top: -9px; inset-inline-end: -7px; font-style: normal; font-size: 13px; }
.bal-badge { font-size: 12.5px; padding: 4px 10px; border-radius: 20px; border: 1px dashed #d39e00; background: #fff8e1; color: #6d5200; cursor: pointer; white-space: nowrap; font-family: var(--font); }
.bal-badge b { direction: ltr; unicode-bidi: isolate; }
@media (max-width: 640px) { .bal-badge .lbl { display: none; } }

/* ===== الميزانية العمومية ===== */
.container.wide { max-width: 1100px; }
.bud-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.bud-head h1 { margin: 0; font-size: 22px; }
.bud-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; margin-bottom: 16px; }
.bcard { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; }
.bcard small { color: var(--muted); }
.bcard b { font-size: 24px; }
.bcard.plus b { color: #0b6b34; } .bcard.minus b { color: #b3261e; }
.bcard.net { border-width: 2px; } .bcard.net.plus { border-color: #9fd3b3; background: #f3fbf6; } .bcard.net.minus { border-color: #f1b2ad; background: #fff6f5; }
.bud-filter { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.bud-filter input[type=search] { font: inherit; padding: 8px 12px; border: 1px solid var(--line); border-radius: 9px; width: 260px; max-width: 100%; background: #fff; }
.bud-filter label { display: flex; gap: 6px; align-items: center; font-size: 14px; color: var(--muted); }
.btable { width: 100%; border-collapse: collapse; background: #fff; border-radius: 12px; overflow: hidden; border: 1px solid var(--line); font-size: 14px; }
.btable th, .btable td { padding: 9px 12px; border-bottom: 1px solid #eef1ef; text-align: right; }
.btable th { background: #f4f7f5; font-weight: 700; }
.btable .num { text-align: left; direction: ltr; font-variant-numeric: tabular-nums; white-space: nowrap; font-weight: 600; }
.btable .ref { color: var(--muted); font-size: 12.5px; text-align: right; }
.btable tr.grp td { background: #fffaea; font-weight: 700; border-top: 2px solid #efe3bf; }
.btable tr.sub td { background: #fafbfa; font-weight: 700; font-size: 13px; }
.btable tfoot td { font-weight: 800; font-size: 15px; background: #f4f7f5; border-top: 2px solid #c9d6ce; }
.btable a { color: var(--ink); }
.bud-extra { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; margin-top: 12px; }
.bud-extra summary { cursor: pointer; font-weight: 600; }
.bud-extra ul { margin: 10px 0 0; padding-inline-start: 20px; display: grid; gap: 6px; }
.bud-note { margin-top: 14px; }
@media (max-width: 640px) { .btable .ref, .btable th:nth-child(3) { display: none; } .btable th, .btable td { padding: 7px 8px; } }
@media print {
  .no-print, #toasts { display: none !important; }
  body { background: #fff; }
  .container { padding: 0; max-width: none; }
  .bcard { border-color: #ccc; }
  details.bud-extra { display: none; }
}

.sign-sel select { font: inherit; padding: 5px 8px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); }
.btable .rev { display: inline-block; font-size: 11px; background: #fff3e0; color: var(--warn); border-radius: 10px; padding: 1px 7px; margin-inline-start: 4px; cursor: help; }

/* مفتاح معنى الموجب للقسم كله */
.sec-sign { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; margin-bottom: 14px; font-size: 14px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #f4f6f5; }
.seg button { font: inherit; font-size: 14px; border: 0; background: transparent; padding: 7px 16px; cursor: pointer; color: #555; }
.seg button + button { border-inline-start: 1px solid var(--line); }
.seg button.on[data-sign=mine] { background: #0b7a3b; color: #fff; font-weight: 700; }
.seg button.on[data-sign=theirs] { background: #c62828; color: #fff; font-weight: 700; }

/* قوائم الاختيار */
.xg-ddbtn { position: absolute; z-index: 19; width: 18px; border: 1px solid #b9c2bd; background: #f4f6f5; color: #333; font-size: 11px; line-height: 1; padding: 0; cursor: pointer; box-sizing: border-box; }
.xg-ddbtn:hover { background: #dfeee5; }
.xg-ddbtn[hidden] { display: none; }
.xg-ddmenu { position: fixed; z-index: 100003; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.18); padding: 6px; font-family: var(--font); display: flex; flex-direction: column; gap: 4px; max-height: 280px; }
.xg-ddq { font: inherit; font-size: 14px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 7px; }
.xg-ddlist { overflow: auto; display: flex; flex-direction: column; }
.xg-ddlist button { text-align: right; border: 0; background: none; padding: 7px 10px; font: inherit; font-size: 14px; border-radius: 6px; cursor: pointer; }
.xg-ddlist button:hover { background: #f0f3f1; }
.xg-ddlist button.on { background: var(--g-soft); color: var(--g2); font-weight: 700; }
.xg-ddempty { padding: 8px; color: var(--muted); font-size: 13px; }
.xg-ddnote { color: var(--muted); font-size: 11.5px; padding: 0 4px; }

.share-opt { display: flex; gap: 8px; align-items: center; font-size: 14px; padding: 6px 2px; }
.folder-info .badges { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 4px; }
