@font-face { font-family: "Nastaliq"; src: url(fonts/NotoNastaliqUrdu.ttf) format("truetype"); font-display: swap; }

:root {
  --bg: #f6f1e7; --surface: #fffdf8; --ink: #1d1b16; --muted: #6f685b; --line: #e3dccd;
  --accent: #1f3a34; --accent-ink: #fff; --gold: #b0893a; --danger: #a23b2a; --ok: #2f6b4f;
  --radius: 14px; --shadow: 0 1px 2px rgba(0,0,0,.06), 0 6px 20px rgba(0,0,0,.06);
  --ui: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --ur: "Nastaliq", "Noto Nastaliq Urdu", "Jameel Noori Nastaleeq", serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12110f; --surface: #1c1a17; --ink: #ece6da; --muted: #a39b8c; --line: #2e2b26;
    --accent: #7fb8a4; --accent-ink: #0f1a17; --gold: #d0ad62; --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #12110f; --surface: #1c1a17; --ink: #ece6da; --muted: #a39b8c; --line: #2e2b26;
  --accent: #7fb8a4; --accent-ink: #0f1a17; --gold: #d0ad62; --shadow: none;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 15px/1.5 var(--ui); }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
.ur { font-family: var(--ur); direction: rtl; }

/* ---------- shell ---------- */
.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: var(--bg); border-bottom: 1px solid var(--line); }
.top h1 { font-size: 18px; margin: 0; flex: 1; letter-spacing: .2px; }
.top h1 small { color: var(--muted); font-weight: 400; font-size: 13px; margin-inline-start: 6px; }
.iconbtn { border: 0; background: transparent; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; cursor: pointer; }
.iconbtn:active { background: var(--line); }
.iconbtn svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
main { padding: 16px; padding-bottom: calc(90px + env(safe-area-inset-bottom)); max-width: 960px; margin: 0 auto; }
.tabs { position: fixed; bottom: 0; left: 0; right: 0; z-index: 6; display: flex; justify-content: space-around;
  background: var(--surface); border-top: 1px solid var(--line); padding: 6px 0 calc(6px + env(safe-area-inset-bottom)); }
.tabs a { text-decoration: none; display: flex; flex-direction: column; align-items: center; font-size: 11px; color: var(--muted); padding: 4px 14px; }
.tabs a.on { color: var(--accent); font-weight: 600; }
.tabs svg { width: 24px; height: 24px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.btn { border: 0; background: var(--accent); color: var(--accent-ink); padding: 12px 18px; border-radius: 12px; font-weight: 600; cursor: pointer; }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn:disabled { opacity: .5; }
.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input, .field select, .field textarea { width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); }
.field input.ur, .field textarea.ur { font-size: 18px; line-height: 2; }
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; border: 1px solid var(--line); }
.muted { color: var(--muted); }
#toast { position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--ink); color: var(--bg);
  padding: 10px 16px; border-radius: 10px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 50; max-width: calc(100% - 32px); }
#toast.show { opacity: 1; }

/* ---------- login ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login .card { width: 100%; max-width: 360px; }
.brand { text-align: center; margin-bottom: 20px; }
.brand .ur { font-size: 30px; line-height: 2; color: var(--accent); }

/* ---------- library ---------- */
.search { width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); margin-bottom: 12px; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 10px; scrollbar-width: none; }
.chip { flex: none; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 4px 14px; font-family: var(--ur); font-size: 15px; line-height: 2; cursor: pointer; }
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.shelf-title { font-family: var(--ur); font-size: 20px; line-height: 2.2; margin: 18px 0 6px; direction: rtl; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 16px 14px; direction: rtl; }
.book { text-decoration: none; display: block; cursor: pointer; }
.cover { aspect-ratio: 2/3; border-radius: 6px 12px 12px 6px; position: relative; overflow: hidden; padding: 14px 12px;
  display: flex; flex-direction: column; justify-content: space-between; color: #f4ecd8; box-shadow: var(--shadow), inset 6px 0 0 rgba(0,0,0,.18); }
.cover::after { content: ""; position: absolute; inset: 10px; border: 1px solid rgba(240,220,170,.35); border-radius: 4px; pointer-events: none; }
.cover .t { font-family: var(--ur); font-size: 17px; line-height: 2.1; text-align: center; direction: rtl; margin-top: 8px; }
.cover .a { font-family: var(--ur); font-size: 12px; line-height: 2; text-align: center; opacity: .85; direction: rtl; }
.cover .badge { position: absolute; top: 8px; left: 8px; font: 600 11px var(--ui); background: rgba(0,0,0,.45); padding: 2px 8px; border-radius: 999px; }
.meta { margin-top: 6px; font-size: 12px; color: var(--muted); direction: ltr; text-align: right; }
.bar { height: 4px; background: var(--line); border-radius: 4px; overflow: hidden; margin-top: 6px; }
.bar > i { display: block; height: 100%; background: var(--gold); width: 0; transition: width .3s; }
.empty { text-align: center; padding: 48px 16px; color: var(--muted); }

/* ---------- upload / job ---------- */
.drop { border: 2px dashed var(--line); border-radius: var(--radius); padding: 28px 16px; text-align: center; cursor: pointer; margin-bottom: 16px; background: var(--surface); }
.drop.has { border-style: solid; border-color: var(--accent); }
.steps { list-style: none; padding: 0; margin: 0 0 18px; }
.steps li { display: flex; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); color: var(--muted); }
.steps li .dot { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line); flex: none; display: grid; place-items: center; font-size: 12px; }
.steps li.on { color: var(--ink); font-weight: 600; }
.steps li.on .dot { border-color: var(--accent); border-top-color: transparent; animation: spin 1s linear infinite; }
.steps li.ok { color: var(--ink); }
.steps li.ok .dot { background: var(--ok); border-color: var(--ok); color: #fff; }
@keyframes spin { to { transform: rotate(360deg); } }
.big { font-size: 34px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 14px 0; }
.stats div { background: var(--bg); border-radius: 10px; padding: 10px; text-align: center; }
.stats b { display: block; font-size: 18px; font-variant-numeric: tabular-nums; }
.stats span { font-size: 12px; color: var(--muted); }
.bar.lg { height: 10px; }

/* ---------- reader ---------- */
.reader { position: fixed; inset: 0; background: var(--rbg, var(--bg)); color: var(--rink, var(--ink)); overflow: hidden; }
.reader[data-rt="sepia"] { --rbg: #f3e7cf; --rink: #3b2f1e; --line: #dccbaa; --surface: #f8eedb; }
.reader[data-rt="night"] { --rbg: #0e0e0d; --rink: #cfc8b8; --line: #2a2824; --surface: #1a1917; }
.reader[data-rt="day"] { --rbg: #fffdf8; --rink: #1d1b16; }
.pages { position: absolute; top: calc(14px + env(safe-area-inset-top)); bottom: calc(34px + env(safe-area-inset-bottom)); left: 0; right: 0;
  overflow: hidden; direction: rtl; }
.flow { height: 100%; column-gap: 0; column-fill: auto; font-family: var(--ur); text-align: justify; transition: transform .28s ease; }
.flow p { margin: 0 22px .5em; }
.flow .ln { border-radius: 4px; }
.flow .ln.fixed { background: rgba(47,107,79,.12); }
.flow .ln.low { text-decoration: underline dotted rgba(176,137,58,.7); text-underline-offset: 6px; }
.flow .pm { display: block; text-align: center; font: 12px var(--ui); color: var(--muted); margin: 1.2em 22px .6em; letter-spacing: 1px; break-after: avoid; }
.flow .pm::before, .flow .pm::after { content: " — "; }
.rfoot { position: absolute; left: 0; right: 0; bottom: 0; padding: 6px 18px calc(8px + env(safe-area-inset-bottom)); font-size: 12px; color: var(--muted);
  display: flex; justify-content: space-between; direction: ltr; font-variant-numeric: tabular-nums; }
.rbar { position: absolute; top: 0; left: 0; right: 0; z-index: 3; display: flex; align-items: center; gap: 4px;
  padding: calc(6px + env(safe-area-inset-top)) 8px 6px; background: var(--surface); border-bottom: 1px solid var(--line); transform: translateY(-100%); transition: transform .2s; }
.rbar .ttl { flex: 1; font-family: var(--ur); font-size: 15px; line-height: 2; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; direction: rtl; }
.rpanel { position: absolute; left: 0; right: 0; bottom: 0; z-index: 3; background: var(--surface); border-top: 1px solid var(--line);
  padding: 12px 16px calc(14px + env(safe-area-inset-bottom)); transform: translateY(100%); transition: transform .2s; }
.reader.chrome .rbar, .reader.chrome .rpanel { transform: none; }
.rpanel input[type=range] { width: 100%; accent-color: var(--gold); }
.row { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.row .grow { flex: 1; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; background: transparent; padding: 8px 9px; cursor: pointer; white-space: nowrap; }
.seg button.on { background: var(--accent); color: var(--accent-ink); }
.sheet { position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center; }
.sheet > div { background: var(--surface); color: var(--ink); width: 100%; max-width: 640px; max-height: 88vh; overflow: auto; border-radius: 18px 18px 0 0;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); }
.sheet .grab { width: 40px; height: 4px; background: var(--line); border-radius: 4px; margin: 0 auto 12px; }
.sheet img { width: 100%; background: #fff; border-radius: 8px; border: 1px solid var(--line); image-rendering: auto; }
.scan { position: fixed; inset: 0; z-index: 15; background: #fff; overflow: auto; }
.scan img { width: 100%; display: block; }
.scan .close { position: fixed; top: calc(8px + env(safe-area-inset-top)); right: 8px; background: rgba(0,0,0,.6); color: #fff; }
.toc a { display: flex; justify-content: space-between; padding: 10px 4px; border-bottom: 1px solid var(--line); text-decoration: none; font-variant-numeric: tabular-nums; }

/* ---------- agent ---------- */
.task { border-bottom: 1px solid var(--line); padding: 12px 0; }
.task .st { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--line); }
.task .st.running { background: var(--gold); color: #fff; }
.task .st.done { background: var(--ok); color: #fff; }
.task .st.failed { background: var(--danger); color: #fff; }
.task pre, .log { white-space: pre-wrap; word-break: break-word; font: 12px/1.5 ui-monospace, Menlo, monospace; background: var(--bg); padding: 10px; border-radius: 10px; max-height: 300px; overflow: auto; }

/* ---------------- v2: covers, book page, checklist, fleet ---------------- */
.coverwrap { position: relative; }
.coverwrap .badge { position: absolute; top: 8px; left: 8px; font: 600 11px var(--ui); background: rgba(0,0,0,.55); color: #fff; padding: 2px 8px; border-radius: 999px; }
.coverwrap .badge.ok { background: var(--ok); }
img.cover.img { width: 100%; aspect-ratio: 1600/2560; object-fit: cover; padding: 0; display: block; }
img.cover.img::after { display: none; }
.meta.ur { font-family: var(--ur); font-size: 14px; line-height: 2; color: var(--ink); direction: rtl; text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.small { font-size: 12px; }
.bookhead { text-align: center; padding: 6px 0 18px; }
.bigcover { width: min(62%, 280px); aspect-ratio: 1600/2560; border-radius: 6px 12px 12px 6px; box-shadow: 0 10px 30px rgba(0,0,0,.25); display: block; margin: 0 auto 14px; }
.btitle { font-size: 26px; line-height: 2.1; }
.bsub { font-size: 17px; line-height: 2; color: var(--muted); }
.bauthor { font-size: 18px; line-height: 2.2; color: var(--muted); margin-bottom: 12px; }
section.card { margin-bottom: 14px; }
section.card h3 { margin: 0 0 10px; font-size: 16px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.desc { font-size: 17px; line-height: 2.2; margin: 0 0 8px; text-align: justify; }
.chips.wrap { flex-wrap: wrap; overflow: visible; }
.chips.wrap .chip { cursor: default; font-size: 14px; }
.pill { font: 600 12px var(--ui); padding: 2px 10px; border-radius: 999px; background: var(--line); color: var(--ink); }
.pill.ready, .pill.approve { background: var(--ok); color: #fff; }
.pill.needs_review, .pill.reject { background: var(--gold); color: #fff; }
.checks { list-style: none; padding: 0; margin: 0 0 12px; }
.checks li { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.checks .ic { flex: none; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 13px; font-weight: 700; color: #fff; }
.checks .pass .ic { background: var(--ok); }
.checks .warn .ic { background: var(--gold); }
.checks .fail .ic { background: var(--danger); }
.row.dl { flex-wrap: wrap; }
.row.dl .btn { padding: 8px 14px; text-decoration: none; }
.qa { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.qa img { width: 84px; border: 1px solid var(--line); border-radius: 4px; background: #fff; }
.qa ul { margin: 6px 0 0; padding-inline-start: 18px; }
.toc a.lv1 { font-size: 18px; padding: 8px 4px; }
.toc a.lv2 { font-size: 15px; padding: 4px 22px 4px 4px; color: var(--muted); }
.toc a { display: block; text-decoration: none; border-bottom: 1px solid var(--line); line-height: 2; }
.fleet { margin: 10px 0 0; }
.fl { display: grid; grid-template-columns: 56px 1fr 34px; gap: 8px; align-items: center; font-size: 12px; color: var(--muted); }
.fl .bar { margin: 0; }
.fl b { text-align: left; font-variant-numeric: tabular-nums; color: var(--ink); }

/* reader: recreated book */
.flow h1, .flow h2, .flow h3 { font-weight: normal; margin: 0 22px; break-after: avoid; }
.flow h1 { font-size: 1.8em; text-align: center; margin: .8em 22px .6em; }
.flow h2 { font-size: 1.3em; margin: 1em 22px .3em; }
.flow h3 { font-size: 1.1em; margin: .8em 22px .2em; }
.flow p { text-indent: 1.1em; }
.flow p.c { text-align: center; text-indent: 0; }
.flow blockquote.ar { margin: .4em 34px; text-align: center; font-size: 1.04em; }
.flow blockquote.ar p { margin: 0; text-indent: 0; }
.flow .fpage { break-before: column; break-after: column; height: 100%; box-sizing: border-box; padding: 0 22px; }
.flow .fcover { display: flex; align-items: center; justify-content: center; padding: 0; }
.flow .fcover img { max-height: 100%; max-width: 100%; box-shadow: 0 6px 24px rgba(0,0,0,.25); }
.flow .ftitle { text-align: center; padding-top: 18%; }
.flow .ftitle .t { font-size: 1.8em; line-height: 2; }
.flow .ftitle .s { font-size: 1.05em; opacity: .8; }
.flow .ftitle .a { font-size: 1.2em; margin-top: 2em; }
.flow .ftitle .p { font-size: .85em; margin-top: 3em; opacity: .75; }
.flow .fcopy { font-size: .8em; padding-top: 30%; }
.flow .fcopy p { text-indent: 0; margin-bottom: .6em; }
.flow aside.note { font-size: .8em; margin: .4em 22px .8em; padding-top: .3em; border-top: 1px solid var(--line); opacity: .9; }
.flow aside.note p { text-indent: 0; margin: 0; }
