:root {
  /* أداة عمل: شريط أدوات جانبي على اليمين + شبكة صفحات قابلة للسحب */
  --bg: #eef0f3;
  --surface: #ffffff;
  --ink: #1a1e26;
  --muted: #5b6372;
  --line: #d9dde4;
  --accent: #9f2a2f;
  --accent-soft: #f6e4e4;
  --accent-ink: #ffffff;
  --danger: #b42318;
  --ok: #1d7a46;
  --shadow: 0 1px 2px rgba(20,25,35,.06), 0 4px 14px rgba(20,25,35,.06);
  --font-display: "Readex Pro", "IBM Plex Sans Arabic", Tahoma, sans-serif;
  --font-body: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131519; --surface: #1c1f25; --ink: #e7e9ed; --muted: #9aa1ae; --line: #2e333c;
    --accent: #e0686c; --accent-soft: #3a2224; --accent-ink: #1a0c0d; --danger: #f07167; --ok: #5cc98a;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 14px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #131519; --surface: #1c1f25; --ink: #e7e9ed; --muted: #9aa1ae; --line: #2e333c;
  --accent: #e0686c; --accent-soft: #3a2224; --accent-ink: #1a0c0d; --danger: #f07167; --ok: #5cc98a;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 14px rgba(0,0,0,.25);
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font-family: var(--font-body); font-size: 14px; line-height: 1.55; }
button, input, select { font: inherit; color: inherit; }
h1, h2 { font-family: var(--font-display); text-wrap: balance; margin: 0; }

header.top {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px 20px;
  padding: 14px 20px; background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
header.top h1 { font-size: 19px; font-weight: 600; }
header.top .sub { color: var(--muted); font-size: 13px; }
header.top .spacer { flex: 1; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--surface); border-radius: 8px;
  padding: 7px 12px; cursor: pointer; white-space: nowrap; transition: background .12s, border-color .12s;
}
.btn:hover:not(:disabled) { border-color: var(--muted); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover:not(:disabled) { filter: brightness(1.07); border-color: var(--accent); }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; }
.btn svg { width: 16px; height: 16px; flex: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.layout { display: grid; grid-template-columns: 330px minmax(0,1fr); gap: 18px; padding: 18px 20px 40px; align-items: start; }
aside.side { display: flex; flex-direction: column; gap: 12px; position: sticky; top: 76px; max-height: calc(100vh - 92px); overflow-y: auto; padding-inline-end: 2px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.panel > summary { list-style: none; cursor: pointer; padding: 12px 14px; display: flex; align-items: center; gap: 8px; border-radius: 12px; user-select: none; }
.panel > summary::-webkit-details-marker { display: none; }
.panel > summary:hover { background: var(--bg); }
.panel > summary h2 { flex: 1; }
.panel .chev { width: 16px; height: 16px; color: var(--muted); transition: transform .15s; flex: none; }
.panel:not([open]) .chev { transform: rotate(90deg); }
.panel[open] > summary { border-radius: 12px 12px 0 0; }
.panel-body { padding: 2px 14px 14px; display: flex; flex-direction: column; gap: 10px; }
.sum-badge { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.sum-badge:empty { display: none; }
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 0 4px; color: var(--muted); font-size: 12.5px; }
.link-btn { border: 0; background: none; color: var(--accent); cursor: pointer; padding: 2px 4px; font-size: 12.5px; border-radius: 4px; }
.link-btn:hover { text-decoration: underline; }
.layout.side-hidden { grid-template-columns: minmax(0,1fr); }
.layout.side-hidden aside.side { display: none; }
.zoom { display: inline-flex; align-items: center; gap: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 2px 6px; }
.zoom input[type="range"] { width: 120px; accent-color: var(--accent); }
.zval { border: 0; background: none; cursor: pointer; font-size: 12.5px; min-width: 44px; font-variant-numeric: tabular-nums; color: var(--muted); border-radius: 6px; padding: 2px 4px; }
.zval:hover { color: var(--ink); background: var(--bg); }
.panel h2 { font-size: 14px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.panel h2 .step { width: 22px; height: 22px; border-radius: 6px; background: var(--accent-soft); color: var(--accent); display: inline-grid; place-items: center; font-size: 12px; font-variant-numeric: tabular-nums; }
.panel .hint { color: var(--muted); font-size: 12.5px; margin: 0; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1; min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
label.lbl { font-size: 12.5px; color: var(--muted); display: block; margin-bottom: 4px; }
input[type="text"], input[type="number"], select {
  width: 100%; border: 1px solid var(--line); background: var(--bg); border-radius: 8px; padding: 7px 10px;
}
input[type="number"] { font-variant-numeric: tabular-nums; }
input:disabled, select:disabled { opacity: .5; }

.files { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.files li { display: flex; align-items: center; gap: 8px; padding: 7px 8px; border: 1px solid var(--line); border-radius: 8px; }
.files .dot { width: 10px; height: 10px; border-radius: 3px; background: var(--c); flex: none; }
.files .name { flex: 1; min-width: 0; overflow-wrap: anywhere; cursor: pointer; font-size: 13px; }
.files .name:hover { text-decoration: underline; }
.files .cnt { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.icon-btn { border: 0; background: transparent; width: 26px; height: 26px; border-radius: 6px; display: inline-grid; place-items: center; cursor: pointer; color: var(--muted); flex: none; }
.icon-btn:hover:not(:disabled) { background: var(--bg); color: var(--ink); }
.icon-btn:disabled { opacity: .3; cursor: default; }
.icon-btn svg { width: 15px; height: 15px; }
.empty-files { color: var(--muted); font-size: 13px; padding: 4px 0; }

main.work { min-width: 0; display: flex; flex-direction: column; gap: 12px; }
.summary { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.chip { display: inline-flex; gap: 6px; align-items: baseline; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 4px 12px; font-size: 13px; }
.chip b { font-variant-numeric: tabular-nums; font-weight: 600; }
.chip.sel { border-color: var(--accent); color: var(--accent); }
.status { margin-inline-start: auto; color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 8px; }
.spin { width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: sp 0.8s linear infinite; display: none; }
.busy .spin { display: inline-block; }
@keyframes sp { to { transform: rotate(360deg); } }

.banner { background: var(--accent-soft); border: 1px dashed var(--accent); border-radius: 10px; padding: 10px 14px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; font-size: 13px; }
.banner[hidden] { display: none; }
.banner p { margin: 0; flex: 1; min-width: 220px; }

.board { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px; min-height: 360px; position: relative; }
.board.file-over { outline: 2px dashed var(--accent); outline-offset: -6px; }
.pages { --cw: 172px; --th: 196px; display: grid; grid-template-columns: repeat(auto-fill, var(--cw)); gap: 14px; justify-content: start; }
.pages.compact .acts, .pages.compact .meta .src { display: none; }
.pages.compact .card { padding: 5px; }
.card {
  position: relative; border: 1px solid var(--line); border-radius: 10px; background: var(--bg);
  padding: 8px; display: flex; flex-direction: column; gap: 6px; cursor: pointer; user-select: none;
  transition: border-color .12s, box-shadow .12s;
}
.card:hover { border-color: var(--muted); }
.card.sel { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.card.dragging { opacity: .35; }
.card.drop-before::before, .card.drop-after::after {
  content: ""; position: absolute; top: 6px; bottom: 6px; width: 4px; border-radius: 4px; background: var(--accent);
}
.card.drop-before::before { right: -10px; }
.card.drop-after::after { left: -10px; }
.thumb { height: var(--th); display: flex; align-items: center; justify-content: center; overflow: hidden; border-radius: 6px; }
.thumb .pg { background: #fff; box-shadow: var(--shadow); transition: transform .18s; display: block; }
.thumb .pg.blank { display: grid; place-items: center; color: #8a909b; font-size: 12px; border: 1px dashed #c6cad2; }
.thumb .pg.loading { background: repeating-linear-gradient(45deg, #f2f3f5 0 8px, #e9ebee 8px 16px); }
.meta { display: flex; align-items: center; gap: 6px; font-size: 12px; min-width: 0; }
.meta .num { font-family: var(--font-display); font-weight: 600; font-size: 13px; min-width: 26px; height: 22px; padding: 0 6px; border-radius: 6px; background: var(--surface); border: 1px solid var(--line); display: inline-grid; place-items: center; font-variant-numeric: tabular-nums; }
.card.sel .meta .num { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.meta .src { color: var(--muted); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; align-items: center; gap: 5px; }
.meta .src::before { content: ""; width: 8px; height: 8px; border-radius: 2px; background: var(--c); flex: none; }
.acts { display: flex; justify-content: space-between; gap: 2px; }
.acts .icon-btn { width: 30px; height: 28px; }
.rot-badge { position: absolute; top: 12px; left: 12px; background: var(--ink); color: var(--bg); font-size: 11px; border-radius: 5px; padding: 0 5px; font-variant-numeric: tabular-nums; }

.dropzone { border: 2px dashed var(--line); border-radius: 12px; padding: 40px 20px; text-align: center; color: var(--muted); display: flex; flex-direction: column; gap: 12px; align-items: center; }
.dropzone strong { color: var(--ink); font-family: var(--font-display); font-size: 16px; font-weight: 500; }

.toast-wrap { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 50; width: min(92vw, 440px); pointer-events: none; }
.toast { background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow); font-size: 13.5px; pointer-events: auto; }
.toast.err { background: var(--danger); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }

.kbd { font-size: 11.5px; color: var(--muted); }
.grid2 .btn { white-space: normal; min-width: 0; text-align: center; }
.info-btn { width: 20px; height: 20px; border-radius: 50%; border: 1.5px solid var(--muted); background: transparent; color: var(--muted); font: 700 12px/1 var(--font-body); display: inline-grid; place-items: center; cursor: pointer; flex: none; padding: 0; }
.info-btn:hover, .info-btn[aria-expanded="true"] { border-color: var(--accent); color: var(--accent-ink); background: var(--accent); }
.info-box { background: var(--accent-soft); border-radius: 8px; padding: 10px 12px; font-size: 12.5px; color: var(--ink); display: flex; flex-direction: column; gap: 6px; }
.info-box[hidden] { display: none; }
.info-box p { margin: 0; }
.info-box p:empty { display: none; }
.pop-wrap { position: relative; display: inline-flex; }
.pop { position: absolute; top: 28px; inset-inline-start: 0; z-index: 30; width: min(340px, 80vw); background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); padding: 10px 12px; font-size: 12.5px; display: flex; flex-direction: column; gap: 6px; }
.pop p { margin: 0; }
.ver-body { display: flex; flex-direction: column; gap: 10px; border-top: 1px solid var(--line); padding-top: 10px; }
.ver-body[hidden] { display: none; }
.vers { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.vers li { display: flex; align-items: center; gap: 6px; }
.vers .vdot { width: 10px; height: 10px; border-radius: 50%; background: var(--vc); flex: none; }
.vers input { flex: 1; min-width: 0; }
.vers .vcnt { font-size: 12px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.files li { flex-wrap: wrap; }
.ver-sel { flex: 1 0 100%; order: 9; padding: 4px 8px !important; font-size: 12.5px; }
.ver-tag { position: absolute; top: 12px; right: 12px; font-size: 11px; color: #fff; background: var(--vc); border-radius: 5px; padding: 0 6px; max-width: 70%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ver-tag, .rot-badge { z-index: 2; }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.card.part { border-color: var(--accent); border-style: dashed; }
.card.group .pg { margin: 14px 0 0 14px; box-shadow: -6px -6px 0 -1px #fff, -6px -6px 0 0 #c3c8d0, -12px -12px 0 -1px #fff, -12px -12px 0 0 #c3c8d0; }
.thumb { position: relative; }
.stack-badge { position: absolute; bottom: 6px; left: 6px; z-index: 2; background: var(--c, var(--ink)); color: #fff; border-radius: 999px; font-size: 12px; font-weight: 600; padding: 1px 9px; font-variant-numeric: tabular-nums; box-shadow: var(--shadow); }
.pages { row-gap: 22px; padding-top: 6px; }
.run-bar { position: absolute; top: -15px; height: 14px; inset-inline-start: 0; inset-inline-end: -14px; padding: 0; border: 0; background: transparent; cursor: pointer; z-index: 3; }
.run-bar::before { content: ""; position: absolute; inset-inline: 0; top: 5px; height: 3px; background: var(--c); opacity: .3; transition: opacity .12s, height .12s, top .12s; }
.run-bar.first { inset-inline-start: 8px; }
.run-bar.first::before { border-start-start-radius: 3px; border-end-start-radius: 3px; }
.run-bar.last { inset-inline-end: 8px; }
.run-bar.last::before { border-start-end-radius: 3px; border-end-end-radius: 3px; }
.run-bar.solo { inset-inline: 8px; }
.run-bar.solo::before { border-radius: 3px; opacity: .55; }
.card.run-hot .run-bar::before { opacity: 1; height: 5px; top: 4px; }
.run-bar:focus-visible { outline: 2px solid var(--accent); }
.card.is-ver { background: var(--bg); border-style: double; border-width: 3px; }
.chk { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; cursor: pointer; }
.chk input { margin: 3px 0 0; accent-color: var(--accent); width: 15px; height: 15px; flex: none; }
.chk.off { opacity: .45; pointer-events: none; }
.card.is-sep { background: var(--accent-soft); border-style: dashed; }
.toast .act { margin-inline-start: 10px; background: transparent; border: 1px solid currentColor; color: inherit; border-radius: 6px; padding: 1px 8px; cursor: pointer; font-size: 12.5px; }
hr.sep { border: 0; border-top: 1px solid var(--line); margin: 2px 0; width: 100%; }
.watch-chip { gap: 8px; align-items: center; border-color: var(--ok); }
.watch-chip.paused { border-color: var(--line); }
.pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 0 var(--ok); animation: pl 1.6s infinite; flex: none; }
.watch-chip.paused .pulse { background: var(--muted); animation: none; }
@keyframes pl { 0% { box-shadow: 0 0 0 0 rgba(29,122,70,.5); } 70% { box-shadow: 0 0 0 7px rgba(29,122,70,0); } 100% { box-shadow: 0 0 0 0 rgba(29,122,70,0); } }
.unit { font-size: 12.5px; color: var(--muted); }
.btn[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.size-out { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 13px; }
.size-out b { font-variant-numeric: tabular-nums; }
.size-out.warn { border-color: var(--danger); color: var(--danger); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

@media (max-width: 880px) {
  .layout { grid-template-columns: 1fr; padding: 14px 16px 40px; }
  aside.side { position: static; max-height: none; overflow: visible; }
  header.top { position: static; }
}
@media (max-width: 420px) {
  .zoom input[type="range"] { width: 80px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation-duration: 0.01ms !important; }
}
