/* Layout: tool list on one side, one workspace card on the other; stacks on phones. */
:root {
  --bg: #f2f5f4;
  --surface: #ffffff;
  --surface-2: #e9efee;
  --fg: #132423;
  --muted: #5a6d6b;
  --line: #d2dcdb;
  --accent: #0b6e74;
  --accent-strong: #07555a;
  --accent-soft: #dcefef;
  --accent-fg: #ffffff;
  --danger: #b3261e;
  --ok: #1d7a46;

  --font-display: "Readex Pro", "IBM Plex Sans Arabic", system-ui, sans-serif;
  --font-body: "IBM Plex Sans Arabic", "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, Consolas, monospace;

  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1716;
    --surface: #13201f;
    --surface-2: #1a2b2a;
    --fg: #e3eeec;
    --muted: #93a7a4;
    --line: #263a38;
    --accent: #4fc1c4;
    --accent-strong: #84d8da;
    --accent-soft: #143738;
    --accent-fg: #042120;
    --danger: #f2877f;
    --ok: #6fd39b;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
h1, h2, h3 { font-family: var(--font-display); line-height: 1.25; margin: 0; text-wrap: balance; }
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: not-allowed; }
:focus-visible { outline: 2.5px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--muted); }

/* Header */
.top { border-bottom: 1px solid var(--line); background: var(--surface); }
.top-inner {
  max-width: 1160px; margin: 0 auto;
  padding: 14px max(16px, env(safe-area-inset-right, 0px)) 14px max(16px, env(safe-area-inset-left, 0px));
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark { width: 40px; height: 40px; flex: none; }
.brand h1 { font-size: 22px; font-weight: 700; }
.tagline { margin: 0; color: var(--muted); font-size: 13px; }

.ghost {
  background: transparent; border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 14px; font-size: 13px; font-weight: 500; flex: none;
}
.ghost:hover { border-color: var(--accent); color: var(--accent); }

/* Main layout */
.layout {
  flex: 1;
  width: 100%; max-width: 1160px; margin: 0 auto;
  padding-block: 24px 40px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 24px; align-items: start;
}

/* Tool list */
.tools { display: flex; flex-direction: column; gap: 20px; }
.group h3 {
  font-family: var(--font-body); font-size: 12px; font-weight: 600; letter-spacing: .06em;
  text-transform: uppercase; color: var(--muted); margin-block-end: 8px;
}
.group ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.tool-btn {
  width: 100%; text-align: start; background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; gap: 4px;
}
.tool-btn:hover { border-color: var(--accent); }
.tool-btn[aria-current="true"] { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
[dir="rtl"] .tool-btn[aria-current="true"] { box-shadow: inset -3px 0 0 var(--accent); }
.tool-btn .name { font-weight: 600; font-size: 14.5px; }

/* From → To chips */
.route { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; direction: ltr; justify-content: flex-start; }
[dir="rtl"] .route { justify-content: flex-end; }
.chip {
  font-family: var(--font-mono); font-size: 11px; font-weight: 500; letter-spacing: .02em;
  padding: 1px 7px; border-radius: 5px; background: var(--surface-2); color: var(--fg);
}
.chip.to { background: var(--accent); color: var(--accent-fg); }
.route .arrow { width: 14px; height: 14px; color: var(--muted); flex: none; }

/* Workspace */
.workspace {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 24px; display: flex; flex-direction: column; gap: 16px; min-width: 0;
}
.ws-head { display: flex; flex-direction: column; gap: 6px; }
.ws-head .route { margin-block-end: 2px; }
.ws-head .chip { font-size: 12.5px; padding: 2px 9px; }
.ws-head h2 { font-size: 26px; font-weight: 600; }
.ws-head p { margin: 0; max-width: 65ch; }
.note {
  font-size: 13px; color: var(--muted); background: var(--surface-2);
  border-radius: 8px; padding: 8px 12px;
}

.drop {
  border: 2px dashed var(--line); border-radius: 12px; padding: 32px 16px;
  display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center;
  cursor: pointer; transition: border-color .15s, background-color .15s;
}
.drop svg { width: 34px; height: 34px; color: var(--accent); }
.drop strong { font-size: 16px; font-weight: 600; }
.drop span { font-size: 13px; }
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); }

.link {
  align-self: flex-start; background: none; border: 0; padding: 0;
  color: var(--accent); font-weight: 500; font-size: 14px; text-decoration: underline; text-underline-offset: 3px;
}

/* File list */
.file-list, .result-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.file-list:empty { display: none; }
.file-row, .result-row {
  display: flex; align-items: center; gap: 12px; padding: 8px 10px;
  border: 1px solid var(--line); border-radius: 10px; min-width: 0;
}
.ext {
  flex: none; width: 46px; height: 46px; border-radius: 8px; background: var(--surface-2);
  display: grid; place-items: center; font-family: var(--font-mono); font-size: 11px; font-weight: 500;
  text-transform: uppercase; overflow: hidden;
}
.ext img { width: 100%; height: 100%; object-fit: cover; }
.file-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.file-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; direction: ltr; text-align: start; unicode-bidi: plaintext; }
.file-meta { font-family: var(--font-mono); font-size: 12px; color: var(--muted); }
.tag {
  font-family: var(--font-body); font-size: 11px; font-weight: 600; color: var(--accent);
  background: var(--accent-soft); border-radius: 4px; padding: 0 6px; margin-inline-start: 6px;
}
.row-actions { display: flex; gap: 4px; flex: none; }
.icon-btn {
  width: 32px; height: 32px; border-radius: 8px; border: 1px solid transparent; background: transparent;
  display: grid; place-items: center; color: var(--muted);
}
.icon-btn:hover:not(:disabled) { border-color: var(--line); color: var(--fg); }
.icon-btn:disabled { opacity: .35; }
.icon-btn svg { width: 16px; height: 16px; }

/* Options */
.options { display: flex; flex-wrap: wrap; gap: 12px 20px; }
.options:empty { display: none; }
.opt { display: flex; flex-direction: column; gap: 4px; min-width: 150px; }
.opt label { font-size: 13px; font-weight: 500; color: var(--muted); }
.opt select {
  font: inherit; font-size: 14px; color: var(--fg); background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px;
}
.opt.grow { flex: 1 1 220px; }
.opt input[type="text"] {
  font: inherit; font-family: var(--font-mono); font-size: 14px; color: var(--fg); background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; width: 100%; text-align: left;
}
.opt input[type="text"]::placeholder { color: var(--muted); opacity: .8; }
.opt.check { flex-direction: row; align-items: center; gap: 8px; align-self: flex-end; padding-block-end: 8px; }
.opt.check label { color: var(--fg); }
.opt.check input { width: 17px; height: 17px; accent-color: var(--accent); }

/* Page organizer */
.custom { display: flex; flex-direction: column; gap: 12px; }
.org-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; }
.org-bar .ghost { padding: 6px 14px; }
.org-bar button:disabled { opacity: .45; }
.org-bar .count { margin-inline-start: auto; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.org-grid {
  list-style: none; margin: 0; padding: 0;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px;
}
@media (max-width: 520px) {
  .org-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .pg-acts .icon-btn { width: 26px; height: 26px; }
}
.pg { border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); overflow: hidden; display: flex; flex-direction: column; }
.pg .thumb { position: relative; aspect-ratio: 1; padding: 12px; }
.pg .thumb img {
  /* Square box + contain, so a page stays inside its card at any rotation. */
  width: 100%; height: 100%; object-fit: contain;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .3)); transition: transform .2s ease;
}
.pg-num {
  position: absolute; top: 6px; inset-inline-start: 6px; z-index: 1;
  font-family: var(--font-mono); font-size: 11.5px; font-weight: 500;
  background: var(--surface); border: 1px solid var(--line); border-radius: 5px; padding: 0 6px;
}
.pg-acts { display: flex; justify-content: center; gap: 0; padding: 2px; border-top: 1px solid var(--line); background: var(--surface); }
.pg-acts .icon-btn { width: 28px; height: 28px; }
.pg.del .thumb img { opacity: .3; filter: grayscale(1); }
.pg.del { border-style: dashed; }
[dir="rtl"] .flip { transform: scaleX(-1); }

/* Actions */
.actions { display: flex; align-items: center; flex-wrap: wrap; gap: 12px 16px; }
.primary {
  background: var(--accent); color: var(--accent-fg); border: 0; border-radius: 10px;
  padding: 11px 28px; font-weight: 600; font-size: 15px;
}
.primary:hover:not(:disabled) { background: var(--accent-strong); }
.primary:disabled { opacity: .45; }
.secondary {
  background: var(--surface); color: var(--accent); border: 1px solid var(--accent);
  border-radius: 8px; padding: 6px 14px; font-weight: 600; font-size: 13.5px; text-decoration: none;
}
.secondary:hover { background: var(--accent-soft); }
.status { font-size: 14px; color: var(--muted); min-width: 0; }
.status.error { color: var(--danger); font-weight: 500; }
.status.ok { color: var(--ok); font-weight: 500; }

/* Results */
.results { border-top: 1px solid var(--line); padding-top: 16px; display: flex; flex-direction: column; gap: 12px; }
.results-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.results-head h3 { font-size: 17px; font-weight: 600; }
.result-row .secondary { flex: none; }

.foot {
  text-align: center; font-size: 13px; color: var(--muted);
  padding: 0 max(16px, env(safe-area-inset-right, 0px)) 24px max(16px, env(safe-area-inset-left, 0px));
}
.foot { display: flex; flex-direction: column; gap: 6px; }
.foot p { margin: 0 auto; max-width: 65ch; }
.foot a { color: var(--accent); }

@media (max-width: 820px) {
  .layout { grid-template-columns: minmax(0, 1fr); gap: 16px; padding-block: 16px 32px; }
  .tools { gap: 14px; }
  .group ul { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .workspace { padding: 18px 16px; }
  .ws-head h2 { font-size: 22px; }
  .tagline { display: none; }
}
@media (max-width: 520px) {
  .tool-btn .route { display: none; }
  .tool-btn { padding: 9px 10px; }
  .tool-btn .name { font-size: 14px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* Off-screen paper used to render documents into PDF pages. Always white paper, in both themes. */
.render-host { position: absolute; left: -30000px; top: 0; }
.doc {
  background: #ffffff; color: #111111;
  font-family: "IBM Plex Sans Arabic", "IBM Plex Sans", Arial, sans-serif;
  font-size: 14px; line-height: 1.65; overflow-wrap: anywhere;
}
.doc > * { margin: 0 0 10px; }
.doc * { margin-top: 0; }
.doc h1 { font-family: "Readex Pro", "IBM Plex Sans Arabic", sans-serif; font-size: 26px; line-height: 1.3; }
.doc h2 { font-family: "Readex Pro", "IBM Plex Sans Arabic", sans-serif; font-size: 20px; line-height: 1.35; }
.doc h3, .doc h4 { font-size: 16px; font-weight: 600; }
.doc ul, .doc ol { padding-inline-start: 24px; }
.doc table { border-collapse: collapse; width: 100%; font-size: 12px; }
.doc table.sheet { table-layout: fixed; font-size: 10.5px; }
.doc td, .doc th { border: 1px solid #b9c2c1; padding: 4px 6px; text-align: start; vertical-align: top; }
.doc th, .doc thead td { background: #eaf0ef; font-weight: 600; }
.doc img { max-width: 100%; height: auto; }
.doc pre, .doc code { font-family: "IBM Plex Mono", Consolas, monospace; font-size: 12px; }
.doc pre { white-space: pre-wrap; background: #f3f5f5; padding: 10px; border-radius: 4px; }
.doc blockquote { border-inline-start: 3px solid #b9c2c1; padding-inline-start: 12px; color: #444; }
.doc a { color: #0b6e74; }
.doc hr { border: 0; border-top: 1px solid #ccc; }
