/* Waraq PDF Tools
   Layout concept: a desk of paper sheets. Each tool is one wide "sheet" with a folded corner;
   files sit on it as small A4-proportioned cards. Logical CSS properties throughout so RTL just works. */
:root {
  --paper: #f3f5f3;
  --surface: #ffffff;
  --ink: #14232a;
  --muted: #5a6a6f;
  --line: #d6ddd9;
  --accent: #0f6e66;
  --accent-ink: #ffffff;
  --accent-soft: #e2efec;
  --marker: #f2c14e;
  --danger: #b23a2a;
  --ok: #2c7a3f;

  --f-display: "Readex Pro", "IBM Plex Sans Arabic", system-ui, sans-serif;
  --f-body: "IBM Plex Sans Arabic", "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif;
  --f-mono: "IBM Plex Mono", ui-monospace, Consolas, monospace;

  --r: 10px;
  --step--1: 0.8125rem;
  --step-0: 1rem;
  --step-1: 1.25rem;
  --step-2: 1.75rem;
  --step-3: clamp(2rem, 1.4rem + 2.6vw, 3rem);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0e1618; --surface: #152125; --ink: #e5ecea; --muted: #94a5a7; --line: #27373b;
    --accent: #3fb5a8; --accent-ink: #062320; --accent-soft: #173533; --marker: #e0b13e;
    --danger: #ef7d6b; --ok: #6cc583; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #0e1618; --surface: #152125; --ink: #e5ecea; --muted: #94a5a7; --line: #27373b;
  --accent: #3fb5a8; --accent-ink: #062320; --accent-soft: #173533; --marker: #e0b13e;
  --danger: #ef7d6b; --ok: #6cc583; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--f-body);
  font-size: var(--step-0);
  line-height: 1.6;
}
:lang(ar) body, body:lang(ar) { line-height: 1.75; }
img { max-width: 100%; }
[hidden] { display: none !important; }
a { color: var(--accent); }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--marker); outline-offset: 2px; }

.wrap {
  max-width: 1080px;
  margin-inline: auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}

/* Header */
.site-head { border-block-end: 1px solid var(--line); background: var(--surface); }
.site-head .wrap { display: flex; align-items: center; gap: 16px; padding-block: 12px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); margin-inline-end: auto; }
.brand-mark {
  width: 30px; height: 38px; position: relative; flex: none;
  background: var(--accent); border-radius: 3px;
  clip-path: polygon(0 0, 68% 0, 100% 26%, 100% 100%, 0 100%);
}
.brand-mark::after {
  content: ""; position: absolute; inset-block-start: 0; inset-inline-end: 0;
  width: 32%; height: 26%; background: var(--marker);
  clip-path: polygon(0 0, 0 100%, 100% 100%);
}
[dir="rtl"] .brand-mark { clip-path: polygon(32% 0, 100% 0, 100% 100%, 0 100%, 0 26%); }
[dir="rtl"] .brand-mark::after { clip-path: polygon(100% 0, 100% 100%, 0 100%); }
.brand-name { font-family: var(--f-display); font-weight: 600; font-size: 1.35rem; letter-spacing: -0.01em; }
.brand-name small { display: block; font-family: var(--f-body); font-weight: 400; font-size: var(--step--1); color: var(--muted); letter-spacing: 0; margin-block-start: -4px; }

.lang-toggle {
  display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; background: var(--paper);
}
.lang-toggle button {
  border: 0; background: transparent; padding: 5px 14px; cursor: pointer; font-size: var(--step--1); font-weight: 600; color: var(--muted);
}
.lang-toggle button[aria-pressed="true"] { background: var(--ink); color: var(--surface); }

.tool-nav { border-block-end: 1px solid var(--line); background: var(--surface); }
.tool-nav .wrap { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.tool-nav a {
  white-space: nowrap; text-decoration: none; color: var(--muted); padding: 10px 12px; font-size: 0.9375rem; font-weight: 500;
  border-block-end: 3px solid transparent;
}
.tool-nav a:hover { color: var(--ink); }
.tool-nav a[aria-current="page"] { color: var(--ink); border-block-end-color: var(--accent); }

/* Page heading */
.page-head { padding-block: 36px 20px; }
.page-head h1 {
  font-family: var(--f-display); font-weight: 600; font-size: var(--step-3); line-height: 1.15; margin: 0 0 8px;
  letter-spacing: -0.02em; text-wrap: balance;
}
.page-head p { margin: 0; color: var(--muted); max-width: 62ch; font-size: 1.0625rem; }
.privacy-note { display: inline-flex; align-items: center; gap: 8px; margin-block-start: 14px; font-size: var(--step--1); color: var(--ok); font-weight: 600; }
.privacy-note svg { width: 16px; height: 16px; flex: none; }

/* The sheet */
.sheet {
  position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  padding: clamp(16px, 3vw, 28px); margin-block-end: 28px;
}
.sheet::before {
  content: ""; position: absolute; inset-block-start: -1px; inset-inline-end: -1px; width: 28px; height: 28px;
  background: linear-gradient(225deg, var(--paper) 50%, var(--line) 50%, var(--accent-soft) 54%);
  border-start-end-radius: var(--r);
}
[dir="rtl"] .sheet::before { background: linear-gradient(135deg, var(--paper) 50%, var(--line) 50%, var(--accent-soft) 54%); }

.drop {
  display: grid; place-items: center; text-align: center; gap: 10px;
  border: 2px dashed var(--line); border-radius: var(--r); padding: 36px 16px; cursor: pointer;
  transition: border-color .15s, background .15s;
}
.drop:hover, .drop.is-over { border-color: var(--accent); background: var(--accent-soft); }
.drop strong { font-family: var(--f-display); font-weight: 500; font-size: var(--step-1); }
.drop .hint { color: var(--muted); font-size: var(--step--1); }
.drop-icon { width: 44px; height: 44px; color: var(--accent); }
.drop.compact { padding: 14px 16px; grid-auto-flow: column; justify-content: center; }
.drop.compact .drop-icon { width: 24px; height: 24px; }
.drop.compact strong { font-size: var(--step-0); }
.drop.compact .hint, .drop.compact .btn { display: none; }

.sample-link { margin-block-start: 10px; text-align: center; font-size: var(--step--1); color: var(--muted); }
.sample-link button { background: none; border: 0; color: var(--accent); text-decoration: underline; cursor: pointer; padding: 0; font-weight: 600; }

/* File cards */
.files { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; margin-block: 20px 4px; }
.fcard { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.fthumb {
  position: relative; aspect-ratio: 210 / 297; max-width: 100%; background: var(--paper); border: 1px solid var(--line);
  border-radius: 6px; display: grid; place-items: center; overflow: hidden;
}
.fthumb img, .fthumb canvas { max-width: 92%; max-height: 92%; object-fit: contain; box-shadow: 0 1px 3px rgb(0 0 0 / .15); transition: transform .2s; }
.fbadge {
  position: absolute; inset-block-start: 6px; inset-inline-start: 6px; background: var(--ink); color: var(--surface);
  font-family: var(--f-mono); font-size: 11px; padding: 1px 6px; border-radius: 4px;
}
.fname { font-size: var(--step--1); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fmeta { font-family: var(--f-mono); font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.factions { display: flex; gap: 4px; }
.icon-btn {
  display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--surface); cursor: pointer; color: var(--ink); padding: 0;
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }
.icon-btn.danger:hover { border-color: var(--danger); color: var(--danger); }
.icon-btn svg { width: 16px; height: 16px; }
.icon-btn:disabled { opacity: .35; cursor: default; }
[dir="rtl"] .flip-rtl svg { transform: scaleX(-1); }

/* Options */
.options { display: flex; flex-wrap: wrap; gap: 18px 28px; padding-block: 18px; border-block-start: 1px solid var(--line); margin-block-start: 18px; }
.opt { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.opt-label { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
:lang(ar) .opt-label { text-transform: none; letter-spacing: 0; font-size: var(--step--1); }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg label { position: relative; cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; padding: 7px 14px; font-size: 0.9rem; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.seg label:hover span { border-color: var(--accent); }
.seg input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.seg input:focus-visible + span { outline: 3px solid var(--marker); outline-offset: 2px; }
.seg small { font-size: 12px; opacity: .8; }
.note { font-size: var(--step--1); color: var(--muted); max-width: 62ch; margin: 0; }

/* Action row */
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid transparent; border-radius: 8px; padding: 11px 22px; cursor: pointer;
  font-weight: 600; font-size: 1rem; text-decoration: none;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:disabled { opacity: .45; cursor: default; filter: none; }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn-ghost:hover { border-color: var(--accent); }
.btn svg { width: 18px; height: 18px; }

.status { font-size: 0.9375rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.status.error { color: var(--danger); font-weight: 500; }
.progress { height: 6px; background: var(--paper); border-radius: 99px; overflow: hidden; flex: 1 1 160px; max-width: 280px; }
.progress i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }

/* Result */
.result {
  margin-block-start: 20px; padding: 18px; border-radius: var(--r); background: var(--accent-soft);
  display: flex; flex-wrap: wrap; gap: 14px 24px; align-items: center;
}
.result-text { flex: 1 1 240px; min-width: 0; }
.result-text strong { display: block; font-family: var(--f-display); font-weight: 500; font-size: var(--step-1); }
.result-text span { font-family: var(--f-mono); font-size: var(--step--1); color: var(--muted); }
.size-bar { display: flex; flex-direction: column; gap: 4px; margin-block-start: 8px; max-width: 360px; }
.size-bar div { height: 8px; border-radius: 99px; background: var(--muted); opacity: .35; }
.size-bar div.after { background: var(--accent); opacity: 1; }

.pages-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 12px; margin-block-start: 16px; width: 100%; }
.pages-grid figure { margin: 0; display: flex; flex-direction: column; gap: 6px; }
.pages-grid img { width: 100%; aspect-ratio: 210/297; object-fit: contain; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; }
.pages-grid figcaption { display: flex; justify-content: space-between; align-items: center; font-family: var(--f-mono); font-size: 12px; color: var(--muted); }

/* Ad slots: reserved space, switched on in production (see README). */
.ad-slot { display: none; }
.ads-on .ad-slot {
  display: grid; place-items: center; min-height: 100px; margin-block: 0 28px; border: 1px dashed var(--line);
  border-radius: var(--r); color: var(--muted); font-size: 12px;
}

/* Home */
.tool-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 16px; margin-block-end: 36px; }
.tool-card {
  display: flex; gap: 16px; align-items: flex-start; padding: 20px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r); text-decoration: none; color: var(--ink); transition: border-color .15s, transform .15s;
}
.tool-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.tool-card h2 { font-family: var(--f-display); font-weight: 500; font-size: var(--step-1); margin: 0 0 4px; line-height: 1.3; }
.tool-card p { margin: 0; color: var(--muted); font-size: 0.9375rem; }
.mini-sheet {
  flex: none; width: 46px; height: 60px; border-radius: 4px; background: var(--accent-soft); border: 1px solid var(--line);
  display: grid; place-items: center; color: var(--accent);
}
.mini-sheet svg { width: 24px; height: 24px; }

.points { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 24px; padding-block: 8px 40px; }
.points h3 { font-family: var(--f-display); font-weight: 500; margin: 0 0 4px; font-size: 1.0625rem; }
.points p { margin: 0; color: var(--muted); font-size: 0.9375rem; }

.site-foot { border-block-start: 1px solid var(--line); padding-block: 22px; color: var(--muted); font-size: var(--step--1); }
.site-foot .wrap { display: flex; flex-wrap: wrap; gap: 8px 20px; justify-content: space-between; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
@media (max-width: 520px) {
  .files { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .btn { width: 100%; }
}

/* PDF to Word preview */
.result-sub { display: block; margin-block-start: 2px; }
.text-preview {
  width: 100%; max-height: 320px; overflow: auto; background: var(--surface); border: 1px solid var(--line);
  border-radius: 8px; padding: 14px 18px; display: flex; flex-direction: column; gap: 8px;
}
.text-preview p, .text-preview h4 { margin: 0; max-width: 75ch; font-size: 0.9375rem; overflow-wrap: anywhere; }
.text-preview h4 { font-family: var(--f-display); font-weight: 600; font-size: 1.05rem; }
.text-preview [dir="rtl"] { text-align: right; }
.text-preview [dir="ltr"] { text-align: left; }

/* Image to Text */
.ocr-box { width: 100%; display: flex; flex-direction: column; gap: 6px; }
.ocr-text {
  width: 100%; min-height: 220px; resize: vertical; padding: 14px 16px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--ink); font-family: var(--f-body); font-size: 1rem; line-height: 1.8;
  unicode-bidi: plaintext; text-align: start; /* each line takes its own direction: Arabic right, English left */
}
.ocr-text:focus-visible { outline: 3px solid var(--marker); outline-offset: 1px; }

/* Home groups */
.tool-group { margin-block-end: 28px; }
.group-title { font-family: var(--f-display); font-weight: 500; font-size: var(--step-1); margin: 0 0 12px; color: var(--muted); }
.tool-group .tool-grid { margin-block-end: 0; }
.tool-card h3 { font-family: var(--f-display); font-weight: 500; font-size: var(--step-1); margin: 0 0 4px; line-height: 1.3; }

/* Shared form fields */
.text-input {
  font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  padding: 9px 12px; min-width: 0; max-width: 100%;
}
.text-input:focus-visible { outline: 3px solid var(--marker); outline-offset: 1px; border-color: var(--accent); }
.text-input.narrow { width: 9em; }
.link-btn { background: none; border: 0; padding: 4px 2px; color: var(--accent); font-weight: 600; cursor: pointer; text-decoration: underline; font-size: 0.9rem; }
.opt-wide { flex: 1 1 100%; }
.opt.grow { flex: 1 1 220px; }
.btn-small { padding: 6px 12px; font-size: 0.875rem; }
.btn-small svg { width: 15px; height: 15px; }

/* Split PDF page picker */
.range-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; }
.range-row .text-input { flex: 1 1 220px; max-width: 360px; font-family: var(--f-mono); }
.sel-count { font-size: 0.875rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.page-picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 10px; max-height: 460px; overflow-y: auto; padding: 4px; }
.pp-tile {
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 6px; border: 2px solid var(--line);
  border-radius: 8px; background: var(--paper); cursor: pointer; color: var(--muted);
}
.pp-tile:hover { border-color: var(--accent); }
.pp-tile.on { border-color: var(--accent); background: var(--accent-soft); color: var(--ink); }
.pp-img { width: 100%; aspect-ratio: 210 / 297; display: grid; place-items: center; background: var(--surface); border-radius: 3px; overflow: hidden; }
.pp-img img { max-width: 100%; max-height: 100%; }
.pp-num { font-family: var(--f-mono); font-size: 12px; font-weight: 500; }
.pp-tile.on .pp-num { color: var(--accent); }

/* Image compressor results */
.img-meta { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.img-meta .ok { color: var(--ok); font-family: var(--f-body); }
.img-meta .warn { color: var(--danger); font-family: var(--f-body); }
.pages-grid figcaption { align-items: flex-start; gap: 6px; }

/* Tafqeet */
.tafqeet-inputs { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 16px 24px; margin-block-end: 14px; }
.amount-input { font-family: var(--f-mono); font-size: 1.25rem; width: 100%; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; padding-block: 10px; font-size: 0.9375rem; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.amount-figure { font-family: var(--f-mono); font-size: 1.05rem; color: var(--muted); margin: 0 0 12px; font-variant-numeric: tabular-nums; text-align: start; }
.words-card { border: 1px solid var(--line); border-radius: var(--r); padding: 14px 18px 18px; margin-block-end: 14px; background: var(--paper); }
.words-card.is-empty { opacity: .45; }
.words-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-block-end: 8px; }
.words { margin: 0; font-size: 1.3rem; line-height: 1.9; min-height: 1.9em; overflow-wrap: anywhere; }
.words-ar { font-family: var(--f-body); font-weight: 500; text-align: right; }
.words-en { font-family: var(--f-body); text-align: left; font-size: 1.1rem; }

.tool-group .tool-grid { grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); }
.group-pair { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); gap: 0 16px; }
.group-pair .tool-grid { grid-template-columns: 1fr; }

/* Organize PDF */
.org-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
.org-tile { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); cursor: grab; }
.org-tile.dragging { opacity: .4; }
.org-tile.drop-target { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.org-tile.is-del .org-img { opacity: .25; }
.org-tile.is-del .pp-num { color: var(--danger); }
.org-img img { transition: transform .2s; }
.org-tile .factions { flex-wrap: wrap; justify-content: center; }

/* Date converter & calculators */
.spacer { height: 14px; }
.date-big { margin: 0 0 4px; font-family: var(--f-display); font-weight: 500; font-size: clamp(1.35rem, 1rem + 1.6vw, 1.9rem); line-height: 1.5; }
.date-alt { margin: 0 0 10px; color: var(--muted); font-size: 1.05rem; }
.calc-rows { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px 20px; margin: 14px 0 0; padding-block-start: 14px; border-block-start: 1px solid var(--line); }
.calc-rows dt { color: var(--muted); font-size: 0.9375rem; }
.calc-rows dd { margin: 0; font-family: var(--f-mono); font-size: 0.9rem; font-variant-numeric: tabular-nums; text-align: end; }
input[type="date"].text-input { min-width: 11em; }

/* Content below each tool (how-to, FAQ, related) */
.seo { padding-block: 8px 40px; }
.seo h2 { font-family: var(--f-display); font-weight: 500; font-size: 1.2rem; margin: 0 0 10px; }
.seo p { margin: 0 0 18px; color: var(--muted); max-width: 65ch; }
.seo-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); gap: 12px 40px; }
.steps { margin: 0 0 18px; padding-inline-start: 1.4em; color: var(--muted); display: grid; gap: 6px; }
.steps li::marker { color: var(--accent); font-weight: 600; }
.faq { display: grid; gap: 8px; }
.faq details { border: 1px solid var(--line); border-radius: 8px; background: var(--surface); padding: 10px 14px; }
.faq summary { cursor: pointer; font-weight: 600; list-style-position: inside; }
.faq details p { margin: 8px 0 2px; }
.related { margin-block-start: 22px; }
.related ul { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 10px; }
.related a, .chip {
  display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); color: var(--ink); text-decoration: none; font-weight: 500; font-size: 0.9375rem;
}
.related a:hover, .chip:hover { border-color: var(--accent); color: var(--accent); }
.chip svg { width: 18px; height: 18px; color: var(--accent); }
.embed-box { margin-block-start: 26px; padding: 18px; border: 1px dashed var(--line); border-radius: var(--r); display: grid; gap: 10px; justify-items: start; }
.embed-box p { margin: 0; }
.embed-code { width: 100%; font-family: var(--f-mono); font-size: 0.8rem; resize: vertical; }

/* "Continue with" after a result */
.continue { margin-block-start: 14px; display: flex; flex-direction: column; gap: 8px; }
.continue-links { display: flex; flex-wrap: wrap; gap: 8px; }

/* Footer links */
.foot-links { display: flex; flex-wrap: wrap; gap: 6px 16px; }
.foot-links a { color: var(--muted); text-decoration: none; }
.foot-links a:hover, .foot-links a[aria-current="page"] { color: var(--accent); text-decoration: underline; }

/* Info pages (about, privacy, terms, contact) */
.prose { max-width: 760px; padding-block: 36px 48px; }
.prose h1 { font-family: var(--f-display); font-weight: 600; font-size: var(--step-3); line-height: 1.15; margin: 0 0 12px; text-wrap: balance; }
.prose h2 { font-family: var(--f-display); font-weight: 500; font-size: 1.25rem; margin: 28px 0 8px; }
.prose p { margin: 0 0 12px; max-width: 68ch; }
.prose .updated { color: var(--muted); font-size: var(--step--1); }

/* Embedded calculators */
main.embed { padding: 12px max(12px, env(safe-area-inset-left, 0px)) 8px max(12px, env(safe-area-inset-right, 0px)); }
main.embed .sheet { margin-block-end: 8px; }
main.embed .sheet::before { display: none; }
.embed-credit { margin: 0; font-size: 0.8125rem; text-align: center; }
.embed-credit a { color: var(--muted); }

/* Light / dark switch */
.theme-toggle {
  display: inline-grid; place-items: center; width: 36px; height: 36px; padding: 0; cursor: pointer;
  border: 1px solid var(--line); border-radius: 999px; background: var(--paper); color: var(--ink);
}
.theme-toggle:hover { border-color: var(--accent); color: var(--accent); }
.theme-toggle svg { width: 18px; height: 18px; }

/* Barcode generator */
.bc-value { width: 100%; font-family: var(--f-mono); font-size: 1.1rem; resize: vertical; }
.bc-row { margin-block-end: 18px; }
.bc-value.is-text, .bc-list.is-text { font-family: inherit; }
.bc-list { width: 100%; font-family: var(--f-mono); font-size: 0.95rem; resize: vertical; line-height: 1.6; }
.bc-preview { display: grid; place-items: center; min-height: 120px; padding: 20px; margin-block: 4px 16px; background: #ffffff;
  border: 1px solid var(--line); border-radius: var(--r); }
.bc-preview:empty { display: none; }
.bc-preview img { max-width: 100%; max-height: 360px; height: auto; image-rendering: pixelated; }
.bc-bad { margin-block-start: 12px; font-size: var(--step--1); color: var(--danger); }
.bc-bad p { margin: 0 0 6px; font-weight: 600; }
.bc-bad ul { margin: 0; padding-inline-start: 20px; display: flex; flex-direction: column; gap: 4px; }
.bc-bad bdi { font-family: var(--f-mono); color: var(--ink); }
#bc-hint { margin-block-start: 4px; }

/* ---------- ZATCA invoice QR ---------- */
.zq-grid { display: grid; grid-template-columns: minmax(150px, 220px) minmax(0, 1fr); gap: 18px; align-items: start; }
.zq-preview { background: #fff; border-radius: 8px; padding: 6px; border: 1px solid var(--line); aspect-ratio: 1; }
.zq-preview svg { display: block; width: 100%; height: auto; }
.zq-side { min-width: 0; display: grid; gap: 10px; }
.zq-b64 { font-family: var(--f-mono); font-size: 0.8rem; word-break: break-all; margin: 0; padding: 8px 10px; background: var(--paper); border: 1px solid var(--line); border-radius: 8px; color: var(--muted); text-align: left; }
#zq-in { width: 100%; font-family: var(--f-mono); font-size: 0.85rem; resize: vertical; }
@media (max-width: 560px) { .zq-grid { grid-template-columns: 1fr; } .zq-preview { max-width: 240px; } }

/* ---------- Fill & sign ---------- */
.sg-file { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 14px; margin-block-end: 14px; }
.sg-file .fname { font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.sg-bar { display: grid; gap: 8px; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5; }
.sg-tools { display: flex; flex-wrap: wrap; gap: 6px; }
.sg-tool span[aria-hidden] { font-weight: 700; color: var(--accent); min-width: 1em; display: inline-block; text-align: center; }
.sg-panel { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 16px; margin-block-start: 10px; padding: 12px 14px; border: 1px solid var(--accent); border-radius: var(--r); background: var(--accent-soft); }
.sg-panel .opt.grow { flex: 1 1 260px; min-width: 0; }
.sg-panel textarea { width: 100%; resize: vertical; font-size: 1rem; }
.sg-panel-actions { display: flex; gap: 6px; margin-inline-start: auto; }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.sg-swatch { display: inline-block; width: 0.8em; height: 0.8em; border-radius: 50%; vertical-align: -1px; }
.sg-help { margin-block: 10px; }
.sg-sigbox { display: grid; gap: 8px; margin-block-start: 10px; padding: 14px; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); }
.sg-pad { width: 100%; max-width: 640px; aspect-ratio: 3 / 1; background: #fff; border: 1px dashed var(--muted); border-radius: 8px; touch-action: none; cursor: crosshair; }
.sg-pages { display: grid; gap: 22px; justify-items: center; margin-block: 14px; }
.sg-fig { margin: 0; width: 100%; max-width: 820px; }
.sg-fig figcaption { text-align: center; font-size: 0.85rem; color: var(--muted); margin-block-start: 6px; font-variant-numeric: tabular-nums; }
.sg-page { position: relative; width: 100%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.12), 0 6px 20px rgba(0,0,0,.08); border-radius: 2px; overflow: hidden; }
.sg-page > img { position: absolute; inset: 0; width: 100%; height: 100%; user-select: none; -webkit-user-drag: none; }
.sg-layer { position: absolute; inset: 0; direction: ltr; }
.sg-item { position: absolute; cursor: move; touch-action: none; outline: 1px dashed transparent; outline-offset: 1px; }
.sg-item img { display: block; width: 100%; height: 100%; pointer-events: none; user-select: none; }
.sg-item:hover { outline-color: var(--accent); }
.sg-item.is-sel, .sg-item:focus-visible { outline: 2px solid var(--accent); }
.sg-handle { position: absolute; right: -7px; bottom: -7px; width: 14px; height: 14px; border-radius: 50%; background: var(--accent); border: 2px solid #fff; cursor: nwse-resize; display: none; }
.sg-item.is-sel .sg-handle { display: block; }
.sg-actions { position: sticky; bottom: env(safe-area-inset-bottom, 0px); background: var(--paper); padding-block: 10px; z-index: 5; }
.sg-count { margin: 0; }
.sg-tools .btn { width: auto; flex: 0 1 auto; }
@media (max-width: 560px) { .sg-tools { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); } .sg-tools .btn { padding-inline: 6px; } }

/* ---------- Watermark / page numbers ---------- */
.pm-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(220px, 320px); gap: 20px; align-items: start; }
.pm-options { display: flex; flex-wrap: wrap; gap: 14px 22px; align-content: start; min-width: 0; }
.pm-options .opt { min-width: 0; }
.pm-options .opt.grow { flex: 1 1 100%; }
.pm-options input[type="range"] { width: min(240px, 100%); accent-color: var(--accent); }
.pm-fig { margin: 0; position: sticky; top: 12px; }
.pm-preview { display: block; width: 100%; height: auto; max-width: 100%; background: #fff; border-radius: 2px; box-shadow: 0 1px 3px rgba(0,0,0,.12), 0 6px 20px rgba(0,0,0,.08); }
.pm-fig figcaption { text-align: center; font-size: 0.85rem; color: var(--muted); margin-block-start: 6px; }
.pm-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; }
@media (max-width: 720px) { .pm-grid { grid-template-columns: 1fr; } .pm-fig { position: static; max-width: 340px; justify-self: center; width: 100%; } }

/* ---------- Release 3 tools ---------- */
.at-box { width: 100%; resize: vertical; font-size: 1.05rem; line-height: 1.7; }
#at-out { background: var(--paper); }
.at-options { display: grid; gap: 10px; }
.at-checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 6px 18px; }
.table-scroll { overflow-x: auto; margin-block-start: 10px; border: 1px solid var(--line); border-radius: var(--r); }
.ib-table { border-collapse: collapse; width: 100%; font-size: 0.9rem; }
.ib-table th, .ib-table td { padding: 8px 12px; border-bottom: 1px solid var(--line); text-align: start; vertical-align: top; }
.ib-table tr:last-child td { border-bottom: 0; }
.ib-table th { font-size: 0.8rem; color: var(--muted); font-weight: 600; }
.ib-table .mono { font-family: var(--f-mono); white-space: nowrap; }
.ib-table tr.is-bad td:last-child, .ib-result.is-bad { color: var(--danger); }
.ib-table tr.is-ok td:last-child, .ib-result.is-ok { color: var(--accent); }
.wd-hols { display: grid; gap: 6px; margin-block: 6px 14px; }
.sl-rates { margin-block: 10px; padding: 10px 14px; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); }
.sl-rates summary { cursor: pointer; font-weight: 600; font-size: 0.92rem; }
.sl-rates[open] summary { margin-block-end: 10px; }
.op-preview { white-space: pre-wrap; max-height: 9em; overflow: auto; margin: 6px 0 0; font-size: 0.95rem; }
@media (max-width: 560px) {
  .ib-table thead { display: none; }
  .ib-table tr { display: block; border-bottom: 1px solid var(--line); padding-block: 6px; }
  .ib-table tr:last-child { border-bottom: 0; }
  .ib-table td { display: block; border: 0; padding: 2px 12px; }
  .ib-table .mono { white-space: normal; overflow-wrap: anywhere; }
}

/* ---------- Scan to PDF ---------- */
.sc-capture { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; margin-block-end: 14px; }
.sc-capture .hint { flex: 1 1 260px; }
.sc-editor { display: grid; gap: 12px; margin-block: 8px 18px; padding: 14px; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); }
.sc-stage { position: relative; width: 100%; max-width: 560px; max-height: 70vh; margin-inline: auto; touch-action: none; user-select: none; direction: ltr; }
.sc-stage > img { position: absolute; inset: 0; width: 100%; height: 100%; border-radius: 4px; }
.sc-svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.sc-poly { fill: rgba(15, 110, 102, .16); stroke: var(--accent); stroke-width: 4; vector-effect: non-scaling-stroke; }
.sc-handle { position: absolute; width: 30px; height: 30px; margin: -15px 0 0 -15px; border-radius: 50%; border: 3px solid #fff; background: var(--accent); box-shadow: 0 1px 4px rgba(0,0,0,.4); cursor: grab; touch-action: none; padding: 0; }
.sc-handle:focus-visible { outline: 3px solid var(--marker); outline-offset: 2px; }
@media (pointer: coarse) { .sc-handle { width: 40px; height: 40px; margin: -20px 0 0 -20px; } }

/* ---------- Batch & workflows ---------- */
.bt-files { list-style: none; margin: 10px 0; padding: 0; display: grid; gap: 4px; }
.bt-files li { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.bt-files .fname { flex: 1 1 200px; min-width: 0; overflow-wrap: anywhere; font-weight: 500; }
.bt-err { color: var(--danger); font-size: 0.85rem; }
.bt-options { display: grid; gap: 10px; }
.bt-steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.bt-step { border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); padding: 10px 12px; display: grid; gap: 8px; }
.bt-step-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.bt-step-actions { display: flex; gap: 4px; }
.bt-step-opts { display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: flex-end; }
.bt-step-opts .opt.grow { flex: 1 1 220px; }
.bt-saved { display: grid; gap: 10px; margin-block-start: 18px; padding: 12px 14px; border: 1px dashed var(--line); border-radius: var(--r); }
.bt-saved-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.bt-saved-list li { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline; }
.bt-saved .text-input { flex: 1 1 200px; }
.link-btn.danger { color: var(--danger); }

/* ---------- Switched-off tool notice ---------- */
.tool-off h2 { font-family: var(--f-display); font-weight: 500; margin: 0 0 6px; }
.tool-off > p { color: var(--muted); margin: 0 0 16px; max-width: 62ch; }

/* ---------- Control panel (admin.html) ---------- */
.admin-page main { padding-block: 8px 48px; }
.admin-signin { max-width: 420px; display: grid; gap: 12px; }
.admin-signin h2 { margin: 0; font-family: var(--f-display); font-weight: 500; }
.admin-summary { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 16px; margin-block-end: 10px; }
.admin-count { font-family: var(--f-display); font-size: 1.6rem; font-variant-numeric: tabular-nums; }
.admin-summary .link-btn { margin-inline-start: auto; }
.admin-actions { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5; background: var(--paper); padding-block: 10px; margin-block-end: 6px; }
.admin-group { margin-block: 18px; }
.admin-list, .admin-log { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 6px; }
.admin-item { display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; align-items: center; gap: 8px 14px; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); }
.admin-item.is-off { background: var(--paper); }
.admin-item.is-off .admin-name label { color: var(--muted); text-decoration: line-through; }
.admin-item.is-dirty { border-color: var(--marker); }
.admin-name { display: grid; min-width: 0; }
.admin-name label { font-weight: 600; cursor: pointer; overflow-wrap: anywhere; }
.admin-name span { color: var(--muted); font-size: 0.9rem; text-align: left; unicode-bidi: plaintext; }
.admin-switch { position: relative; display: inline-block; width: 46px; height: 26px; cursor: pointer; }
.admin-switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.admin-switch .track { position: absolute; inset: 0; border-radius: 999px; background: var(--line); transition: background .15s; }
.admin-switch .track::after { content: ""; position: absolute; top: 3px; inset-inline-start: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.3); transition: transform .15s; }
.admin-switch input:checked + .track { background: var(--accent); }
.admin-switch input:checked + .track::after { transform: translateX(20px); }
[dir="rtl"] .admin-switch input:checked + .track::after { transform: translateX(-20px); }
.admin-switch input:focus-visible + .track { outline: 3px solid var(--marker); outline-offset: 2px; }
.pill { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 10px; border-radius: 999px; white-space: nowrap; }
.pill-on { background: var(--accent-soft); color: var(--accent); }
.pill-off { background: var(--paper); color: var(--danger); border: 1px solid var(--line); }
.admin-log li { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 0.9rem; }
.admin-log .mono { font-family: var(--f-mono); color: var(--muted); }
@media (max-width: 560px) { .admin-item { grid-template-columns: auto minmax(0, 1fr) auto; } .admin-item .link-btn { grid-column: 2; } }
@media (prefers-reduced-motion: reduce) { .admin-switch .track, .admin-switch .track::after { transition: none; } }
