:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --text: #16213e;
  --muted: #5b6480;
  --line: #e2e6f0;
  --primary: #1f3a93;
  --primary-2: #16307a;
  --accent: #f5b400;
  --ok: #1a8f4e;
  --warn: #b7791f;
  --err: #c0392b;
  --radius: 14px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font-family: "Cairo", "Segoe UI", Tahoma, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}
main { max-width: 1100px; margin: 0 auto; padding: 20px 16px 60px; }
h1, h2, h3 { margin: 0 0 8px; }
h2 { font-size: 1.35rem; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.error { color: var(--err); }
code { background: #eef1f8; padding: 1px 6px; border-radius: 6px; font-size: 0.85em; }

.topbar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  background: var(--card); border-bottom: 1px solid var(--line);
  padding: 10px 16px; position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 800; font-size: 1.15rem; color: var(--primary); }
#nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
#nav button {
  background: transparent; border: 0; padding: 8px 14px; border-radius: 10px;
  font: inherit; font-weight: 600; color: var(--muted); cursor: pointer;
}
#nav button.active { background: #e9edfa; color: var(--primary); }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; margin-bottom: 20px; box-shadow: 0 1px 2px rgba(20, 30, 70, 0.04);
}

button, .button {
  font: inherit; font-weight: 700; border-radius: 10px; padding: 10px 18px;
  border: 1px solid var(--line); background: #fff; color: var(--text); cursor: pointer;
  text-decoration: none; display: inline-block; line-height: 1.3;
}
button:disabled { opacity: 0.55; cursor: default; }
.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.primary:hover:not(:disabled) { background: var(--primary-2); }
.ghost { background: #fff; }
.ghost:hover { background: #f2f4fa; }
.danger { color: var(--err); border-color: #f1c9c4; }
.actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* Fields: caption on one line, control, optional hint below. Rows align at the top so paired
   controls line up whatever the hints below them say. */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 18px; align-items: start; }
.form-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid .span2 { grid-column: 1 / -1; }
label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; min-width: 0; }
.field-label { display: block; line-height: 1.5; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.field-label .muted { font-weight: 400; }
/* A button row placed in a grid cell next to fields: line it up with the controls, not the captions. */
.form-grid .field-actions { padding-top: calc(1.5em + 6px); }
label.inline { flex-direction: row; align-items: center; gap: 6px; font-weight: 500; margin-inline-end: 18px; }
fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px 10px; margin: 0; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
legend { font-weight: 600; padding: 0 6px; }
input[type="text"], input[type="password"], input[type="number"], input[type="search"], input[type="date"], input[type="email"], textarea, select {
  font: inherit; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: #fff; color: var(--text); width: 100%; line-height: 1.4;
}
input[type="text"], input[type="password"], input[type="number"], input[type="search"], input[type="date"], input[type="email"], select { height: 44px; padding-block: 0; }
/* Buttons that sit beside inputs match their height; compact buttons (nav, tables, cards, tabs) opt out. */
button, .button { min-height: 44px; }
#nav button, .balance-pill, .page-card .tools button, .page-card .tools .button, .table button, .table select, .variant-tabs button, .dialog-head button { min-height: 0; }
input[type="file"] { font: inherit; width: 100%; min-width: 0; padding: 6px; border: 1px dashed #c9d0e2; border-radius: 10px; background: #fbfcff; color: var(--muted); }
input[type="file"]::file-selector-button {
  font: inherit; font-weight: 700; color: var(--text); background: #fff; border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 14px; margin-inline-end: 10px; cursor: pointer;
}
textarea { resize: vertical; min-height: 70px; line-height: 1.5; }
input:focus, textarea:focus, select:focus { outline: 2px solid #c9d4f6; border-color: var(--primary); }

.photo-preview img { max-height: 180px; border-radius: 10px; border: 1px solid var(--line); }

.help { background: #fff8e1; border: 1px solid #f3e3a5; border-radius: 10px; padding: 12px 14px; margin-bottom: 16px; line-height: 1.9; font-size: 0.95rem; }

.progress-head { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; align-items: flex-start; margin-bottom: 8px; }
.status-line { margin: 6px 0 12px; font-weight: 600; }
.chip { display: inline-block; padding: 3px 12px; border-radius: 999px; font-size: 0.85rem; font-weight: 600; white-space: nowrap; line-height: 1.5; }
.status-line .chip { margin-inline-end: 8px; }
.chip.running { background: #fff3cd; color: var(--warn); }
.chip.done { background: #e3f6ea; color: var(--ok); }
.chip.partial { background: #fdebd0; color: var(--warn); }
.chip.error { background: #fbe2df; color: var(--err); }
.chip.pending { background: #eef1f8; color: var(--muted); }
details { margin-bottom: 14px; }
details summary { cursor: pointer; font-weight: 600; color: var(--muted); }
details p { margin-top: 8px; background: #f7f8fc; padding: 10px 12px; border-radius: 10px; text-align: left; line-height: 1.6; }

.pages-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; }
.page-card { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: #fbfcff; display: flex; flex-direction: column; }
.page-card .thumb { aspect-ratio: 2 / 3; background: #eef1f8; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 0.9rem; }
.page-card .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.page-card .thumb.running { background: linear-gradient(90deg, #eef1f8, #f8f9fe, #eef1f8); background-size: 200% 100%; animation: shimmer 1.6s infinite; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.page-card .body { padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.page-card .title { font-weight: 700; display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; line-height: 1.5; }
.page-card .page-name { display: flex; gap: 6px; align-items: baseline; min-width: 0; }
.page-card .pnum { color: var(--primary); font-variant-numeric: tabular-nums; }
.page-card .pnum::after { content: "."; }
.page-card .dur { white-space: nowrap; font-weight: 400; }
.page-card .err { color: var(--err); font-size: 0.82rem; line-height: 1.4; word-break: break-word; }
.page-card .retry-note { color: var(--warn); line-height: 1.4; word-break: break-word; }
.page-card .thumb span { text-align: center; line-height: 1.6; padding: 0 8px; }
/* Two even columns of tools, pinned to the bottom so every card in a row lines up. */
.page-card .tools { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; margin-top: auto; }
.page-card .tools button, .page-card .tools .button { padding: 6px 8px; font-size: 0.82rem; width: 100%; text-align: center; }

.books-list { display: flex; flex-direction: column; gap: 10px; }
.book-row { display: flex; align-items: center; gap: 14px; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; flex-wrap: wrap; }
.book-row img { width: 48px; height: 48px; border-radius: 10px; object-fit: cover; background: #eef1f8; }
.book-row .info { flex: 1; min-width: 180px; }
.book-row .info strong { display: block; }

.page-editor { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin-bottom: 12px; background: #fbfcff; }
.page-editor .row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.page-editor .row input { flex: 1; min-width: 160px; }
.page-editor .row .num { font-weight: 800; color: var(--primary); min-width: 32px; }
.page-editor .row button { padding: 6px 10px; font-size: 0.85rem; }
.page-editor textarea { min-height: 160px; font-family: "Segoe UI", Tahoma, sans-serif; font-size: 0.9rem; }

dialog { border: 0; border-radius: var(--radius); padding: 0; max-width: 900px; width: 92vw; }
dialog::backdrop { background: rgba(10, 20, 50, 0.5); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); }
dialog pre { margin: 0; padding: 16px; white-space: pre-wrap; word-break: break-word; max-height: 70vh; overflow: auto; font-size: 0.85rem; line-height: 1.55; text-align: left; }

.overlay { position: fixed; inset: 0; background: var(--bg); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.login-card { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 12px; text-align: center; }

#pdfTray { position: fixed; bottom: 16px; inset-inline-start: 16px; z-index: 59; display: flex; flex-direction: column; gap: 6px; width: min(340px, calc(100vw - 32px)); }
.pdf-row { background: #16213e; color: #fff; border-radius: 10px; padding: 8px 12px; display: flex; flex-direction: column; gap: 2px; font-size: 0.85rem; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2); }
.pdf-row .pdf-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pdf-row .pdf-state { opacity: 0.85; }
.pdf-row.ok { background: #14663a; }
.pdf-row.failed { background: #a12626; }
#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #16213e; color: #fff; padding: 10px 18px; border-radius: 10px; z-index: 60; max-width: 90vw; }

@media (max-width: 900px) {
  .form-grid.cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 700px) {
  .form-grid, .form-grid.cols-3 { grid-template-columns: 1fr; }
  .form-grid .field-actions { padding-top: 0; }
  .pages-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
}

/* story editor: variant tabs */
.variant-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 14px 0 10px; }
.variant-tabs button { padding: 7px 12px; font-size: 0.9rem; }
.variant-tabs button.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.variant-tabs button.missing { border-style: dashed; }
.variant-tabs .badge { font-size: 0.72rem; font-weight: 600; opacity: 0.8; margin-inline-start: 4px; }
.variant-missing { background: #f7f8fc; border: 1px dashed var(--line); border-radius: 12px; padding: 16px; display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.variant-head { margin-bottom: 10px; }

/* back covers in settings */
.backcover { border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.backcover img { max-height: 220px; width: auto; align-self: center; border-radius: 8px; border: 1px solid var(--line); }
.backcover form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
label .hint { font-weight: 400; line-height: 1.5; }

/* users table */
.table-wrap { overflow-x: auto; margin-top: 16px; }
.table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
.table th, .table td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: start; vertical-align: middle; }
.table th { color: var(--muted); font-weight: 600; background: #f7f8fc; }
.table select { width: auto; height: 34px; padding: 0 10px; }
.table .actions button { padding: 5px 10px; font-size: 0.82rem; }
#whoami { margin-inline-start: auto; }
.page-editor .row select { width: auto; max-width: 320px; padding: 0 10px; font-size: 0.85rem; }

/* books list */
.stats-line { margin: 2px 0 10px; font-weight: 600; }
.filter-row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.filter-row input[type="search"] { flex: 1; min-width: 220px; }
.thumb-placeholder { width: 48px; height: 48px; border-radius: 10px; background: #eef1f8; display: flex; align-items: center; justify-content: center; }
.chip.archived { background: #eef1f8; color: var(--muted); }

/* ---------- usage & balance (admin) ---------- */
.balance-pill {
  padding: 6px 14px; border-radius: 999px; font-size: 0.85rem; font-weight: 700;
  background: #e3f6ea; border-color: #bfe6cd; color: var(--ok); font-variant-numeric: tabular-nums;
}
.balance-pill.low { background: #fbe2df; border-color: #f2c2bc; color: var(--err); }
.balance-box {
  display: flex; flex-wrap: wrap; gap: 20px 32px; align-items: stretch;
  padding: 16px; margin: 8px 0 16px; border-radius: 12px; background: #f7f9fe; border: 1px solid var(--line);
}
.balance-box.low { background: #fdf1ef; border-color: #f2c2bc; }
.balance-box p { flex-basis: 100%; margin: 0; }
.balance-main { display: flex; flex-direction: column; justify-content: center; min-width: 0; }
.balance-main strong { font-size: 2.1rem; line-height: 1.2; color: var(--primary); font-variant-numeric: tabular-nums; }
.balance-box.low .balance-main strong { color: var(--err); }
.balance-facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px 24px; flex: 1; min-width: 0; }
.balance-facts > div { display: flex; flex-direction: column; gap: 2px; font-variant-numeric: tabular-nums; }
.threshold-row { display: flex; flex-wrap: wrap; align-items: end; gap: 12px; margin-top: 12px; }
.threshold-row input { width: 110px; }
.balance-history { margin-top: 14px; }
.balance-history summary { cursor: pointer; color: var(--muted); font-weight: 600; }
.range-row { display: flex; flex-wrap: wrap; align-items: end; gap: 12px; margin: 8px 0 16px; }
.range-row input { width: auto; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 20px; }
.kpi { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; }
.kpi strong { font-size: 1.35rem; font-variant-numeric: tabular-nums; }
#view-usage h3 { margin-top: 22px; font-size: 1.05rem; }
.table.num td { font-variant-numeric: tabular-nums; }
.bar-cell { width: 30%; min-width: 80px; }
.bar { display: block; height: 8px; border-radius: 4px; background: var(--primary); opacity: 0.75; min-width: 2px; }
@media (max-width: 560px) {
  .balance-box { flex-direction: column; gap: 14px; }
}

/* spacing for section headings that follow a form */
#view-settings h3 { margin-top: 28px; }
#variantPanel h3 { margin-top: 22px; }
.backcover form input[type="file"] { flex: 1; width: auto; }

/* the photo actually used as the reference for the pages */
.ref-photo { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.ref-photo img { width: 56px; height: 70px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); display: block; }
.ref-photo img.wide { width: 105px; }
.ref-photo .link-btn { background: none; border: 0; padding: 0; color: var(--primary); cursor: pointer; font: inherit; text-decoration: underline; }
.photo-preview { display: flex; flex-wrap: wrap; gap: 8px; }
/* AI prompt assistant */
.prompt-chat { margin-top: 18px; border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; }
.prompt-chat > summary { cursor: pointer; font-weight: 700; }
.chat-log { max-height: 520px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; margin: 10px 0; }
.chat-msg { display: flex; flex-direction: column; gap: 6px; }
.chat-msg .bubble { padding: 8px 12px; border-radius: 12px; max-width: 85%; line-height: 1.6; }
.chat-msg.user .bubble { background: var(--primary); color: #fff; align-self: flex-start; }
.chat-msg.assistant .bubble { background: #f1f3f7; align-self: flex-end; }
.chat-msg.pending .bubble { opacity: 0.6; }
.chat-form textarea { width: 100%; }
.chat-form .actions { display: flex; gap: 8px; margin-top: 6px; }
.proposal { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; background: #fff; }
.proposal.applied { border-color: #7cc49a; }
.proposal.rejected, .proposal.restored, .proposal.stale { opacity: 0.7; }
.proposal-head { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.proposal-diff { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 6px 0; }
.proposal-diff > div { min-width: 0; }
.proposal-diff pre { white-space: pre-wrap; word-break: break-word; max-height: 260px; overflow: auto; font-size: 12px; background: #fafafa; border: 1px solid var(--line); border-radius: 8px; padding: 6px; margin: 2px 0 0; }
.proposal-diff del { background: #fde2e2; color: #a12a2a; }
.proposal-diff ins { background: #dcf5e3; color: #1d6b3a; text-decoration: none; }
.proposal .actions { display: flex; gap: 8px; }
@media (max-width: 760px) { .proposal-diff { grid-template-columns: 1fr; } }
.ref-photo a { color: var(--primary); }
fieldset .span-all { flex-basis: 100%; }

/* dot-letter words to check (ب/ي …) */
.check-note { color: var(--warn); line-height: 1.5; }
.check-summary { color: var(--warn); }
.ok-note { color: var(--ok); }
.chip.text-issue { background: #fff3cd; color: var(--warn); }
.page-card.needs-check { border-color: #f0c36d; box-shadow: 0 0 0 1px #f0c36d inset; }
.page-editor .row .check-note { flex-basis: 100%; }

/* Word import */
.import-box { border: 1px dashed #b9c4e6; border-radius: 12px; padding: 12px 14px; margin: 0 0 16px; background: #f8faff; }
.import-box > summary { font-weight: 700; color: var(--primary); }
.import-form { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 12px 0 6px; }
.import-form input[type="file"] { flex: 1; min-width: 220px; width: auto; }
#importResult { display: flex; flex-direction: column; gap: 14px; margin-top: 12px; }
.findings { margin: 6px 0; padding-inline-start: 18px; display: flex; flex-direction: column; gap: 4px; }
.findings li { line-height: 1.6; }
.findings .sev-error b { color: var(--err); }
.findings .sev-warning b { color: var(--warn); }
.findings .sev-info b { color: var(--muted); }
.findings q { color: var(--muted); font-size: 0.85rem; }
.import-pages { display: flex; flex-direction: column; gap: 8px; }
.import-page { border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; background: #fff; margin: 0; }
.import-page.has-error { border-color: #f1c9c4; }
.import-page.has-warning { border-color: #f3e3a5; }
.import-page > summary { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; color: var(--text); }
.import-page .num { font-weight: 800; color: var(--primary); min-width: 22px; }
.import-page .chip { font-size: 0.78rem; }
.prompt-text { white-space: pre-wrap; word-break: break-word; max-height: 280px; overflow: auto; background: #f7f8fc; border-radius: 8px; padding: 10px 12px; font-size: 0.82rem; line-height: 1.55; margin: 8px 0 0; }

/* 16-page books */
.chip.book16 { background: #e8eefc; color: #2c4a9a; }
.page-card.fixed-card { border-style: dashed; }
.text-dialog { display: grid; gap: 10px; min-width: min(560px, 86vw); }
.text-dialog textarea, #dedicationField textarea { width: 100%; font: inherit; line-height: 1.7; padding: 10px; border: 1px solid var(--line, #d8dce6); border-radius: 8px; resize: vertical; box-sizing: border-box; }
.page-editor textarea.page-text { min-height: 90px; font-family: inherit; font-size: 1rem; line-height: 1.8; margin-top: 4px; }
.prompt-text.page-script { background: #fffaf0; font-size: 1rem; line-height: 1.8; }
.dedication-box { border: 1px solid var(--line, #d8dce6); border-radius: 12px; padding: 12px 14px; margin-bottom: 14px; display: grid; gap: 8px; }
.dedication-row { display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-start; }
.dedication-thumb { width: 150px; min-height: 120px; display: grid; place-items: center; background: #f7f8fc; border-radius: 10px; overflow: hidden; }
.dedication-thumb img { width: 100%; display: block; }
.dedication-actions { flex: 1; min-width: 240px; display: grid; gap: 8px; }
#dedicationPrompt { min-height: 110px; font-family: "Segoe UI", Tahoma, sans-serif; font-size: 0.85rem; }

/* text box designer (16-page Arabic pages) */
dialog.box-dialog { max-width: 1180px; width: 96vw; max-height: 94vh; overflow: auto; }
.box-dialog .dialog-head { gap: 12px; }
.box-editor { display: grid; grid-template-columns: minmax(0, 1fr) minmax(300px, 400px); gap: 16px; padding: 12px 16px 16px; align-items: start; }
.box-stage-wrap { position: sticky; top: 0; }
.box-stage { position: relative; direction: ltr; width: 100%; max-width: 560px; aspect-ratio: 1040 / 1456; margin: 0 auto; background: #eef1f8; border-radius: 8px; overflow: hidden; user-select: none; touch-action: none; }
.box-stage img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: fill; pointer-events: none; }
.box-frame { position: absolute; border: 2px dashed #2563eb; box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.8); cursor: move; box-sizing: border-box; }
.box-frame .h { position: absolute; width: 12px; height: 12px; background: #fff; border: 2px solid #2563eb; border-radius: 3px; box-sizing: border-box; }
.box-frame .h[data-h="n"] { top: -7px; left: calc(50% - 6px); cursor: ns-resize; }
.box-frame .h[data-h="s"] { bottom: -7px; left: calc(50% - 6px); cursor: ns-resize; }
.box-frame .h[data-h="e"] { right: -7px; top: calc(50% - 6px); cursor: ew-resize; }
.box-frame .h[data-h="w"] { left: -7px; top: calc(50% - 6px); cursor: ew-resize; }
/* cover title editor: the title picture inside a movable frame over the cover without its title */
.title-stage #titleRaw { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: fill; }
.title-frame img { position: static; display: block; width: 100%; height: auto; pointer-events: none; }
.title-side { display: grid; gap: 12px; align-content: start; }
.title-side input { width: 100%; }
.box-frame .h[data-h="ne"] { top: -7px; right: -7px; cursor: nesw-resize; }
.box-frame .h[data-h="sw"] { bottom: -7px; left: -7px; cursor: nesw-resize; }
.box-frame .h[data-h="nw"] { top: -7px; left: -7px; cursor: nwse-resize; }
.box-frame .h[data-h="se"] { bottom: -7px; right: -7px; cursor: nwse-resize; }
.box-busy { position: absolute; top: 8px; left: 8px; background: rgba(15, 23, 42, 0.75); color: #fff; font-size: 0.8rem; padding: 4px 10px; border-radius: 999px; }
.box-controls { display: grid; gap: 10px; }
.box-controls fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px 12px; display: grid; gap: 8px; margin: 0; }
.box-controls legend { font-weight: 700; padding: 0 6px; }
.box-controls label { display: grid; gap: 3px; font-size: 0.85rem; min-width: 0; }
.box-controls label.inline { display: flex; gap: 6px; align-items: center; }
.box-controls label.range { grid-template-columns: 1fr auto; align-items: center; column-gap: 8px; }
.box-controls label.range span { grid-column: 1 / -1; }
.box-controls label.range output { font-variant-numeric: tabular-nums; min-width: 2.5em; text-align: center; color: var(--muted); }
.box-controls input[type="number"], .box-controls select, .box-controls textarea { width: 100%; box-sizing: border-box; font: inherit; padding: 5px 6px; border: 1px solid var(--line); border-radius: 6px; }
.box-controls input[type="color"] { width: 100%; height: 32px; padding: 2px; border: 1px solid var(--line); border-radius: 6px; box-sizing: border-box; }
.box-controls textarea { line-height: 1.7; resize: vertical; }
.box-controls .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.box-controls .row4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.box-save .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.font-list { list-style: none; padding: 0; margin: 0 0 8px; display: grid; gap: 4px; }
@media (max-width: 860px) { .box-editor { grid-template-columns: 1fr; } .box-stage-wrap { position: static; } }

.box-image-pick { display: grid; gap: 6px; }
.box-image-pick img { max-width: 100%; max-height: 120px; object-fit: contain; background: repeating-conic-gradient(#e9edf5 0% 25%, #fff 0% 50%) 50% / 16px 16px; border-radius: 6px; justify-self: start; }
.file-button { cursor: pointer; }
.box-image-list { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 8px; }
.box-image-list figure { margin: 0; width: 180px; display: grid; gap: 4px; }
.box-image-list img { width: 100%; height: 110px; object-fit: contain; background: repeating-conic-gradient(#e9edf5 0% 25%, #fff 0% 50%) 50% / 16px 16px; border-radius: 8px; border: 1px solid var(--line); }
.box-image-list figcaption { font-size: 0.85rem; }
.text-frame { position: absolute; border: 2px dashed #16a34a; background: rgba(22, 163, 74, 0.06); cursor: move; box-sizing: border-box; }
.text-frame .h { border-color: #16a34a !important; width: 10px !important; height: 10px !important; }
.text-frame .h[data-t="n"] { top: -6px; left: calc(50% - 5px); cursor: ns-resize; }
.text-frame .h[data-t="s"] { bottom: -6px; left: calc(50% - 5px); cursor: ns-resize; }
.text-frame .h[data-t="e"] { right: -6px; top: calc(50% - 5px); cursor: ew-resize; }
.text-frame .h[data-t="w"] { left: -6px; top: calc(50% - 5px); cursor: ew-resize; }
.text-frame .h[data-t="ne"] { top: -6px; right: -6px; cursor: nesw-resize; }
.text-frame .h[data-t="sw"] { bottom: -6px; left: -6px; cursor: nesw-resize; }
.text-frame .h[data-t="nw"] { top: -6px; left: -6px; cursor: nwse-resize; }
.text-frame .h[data-t="se"] { bottom: -6px; right: -6px; cursor: nwse-resize; }
.size-pair { display: flex; align-items: center; gap: 6px; }
.size-pair input { width: 90px; }
.book-progress { display: grid; gap: 6px; margin: 4px 0 10px; }
.book-progress .bar { height: 10px; background: #e8ecf5; border-radius: 999px; overflow: hidden; }
.book-progress .bar span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--primary), #3b82f6); border-radius: 999px; transition: width 0.6s ease; }
.book-progress.stopped .bar span { background: var(--warn); }
.book-progress .progress-text { color: var(--muted); }
.chip.paused { background: #fff4e0; color: #9a5b00; }
.chip.cancelled { background: #fde8e8; color: #9b1c1c; }
button.danger { color: var(--err); border-color: #f1c4c4; }

/* ---------- story map (gap analysis) ---------- */
:root {
  --st-available: #1a8f4e; --st-available-bg: #e3f6ea;
  --st-progress: #1f6fd1; --st-progress-bg: #e4eefc;
  --st-planned: #b7791f; --st-planned-bg: #fdf3df;
  --st-missing: #c0392b; --st-missing-bg: #fdeceb;
  --st-na: #98a1b6; --st-na-bg: #f2f4f8;
}
.map-head { display: flex; flex-wrap: wrap; gap: 12px 20px; align-items: flex-start; justify-content: space-between; margin-bottom: 14px; }
.map-title { min-width: 0; flex: 1 1 260px; }
.map-title p { margin: 0; }
.map-tools { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #fff; }
.seg button { border: 0; border-radius: 0; padding: 7px 14px; font-size: 0.9rem; background: transparent; color: var(--muted); min-height: 0; }
.seg button + button { border-inline-start: 1px solid var(--line); }
.seg button.on { background: var(--primary); color: #fff; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; flex: none; vertical-align: middle; }
.dot.available { background: var(--st-available); }
.dot.progress { background: var(--st-progress); }
.dot.planned { background: var(--st-planned); }
.dot.missing { background: var(--st-missing); }
.dot.na { background: var(--st-na-bg); box-shadow: inset 0 0 0 2px var(--st-na); }
.map-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 14px; margin-bottom: 18px; }
.map-sum-card { border: 1px solid var(--line); border-radius: 12px; padding: 14px; display: grid; gap: 10px; min-width: 0; background: #fbfcff; }
.map-sum-head { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; align-items: baseline; }
.map-bar { display: flex; height: 14px; border-radius: 999px; overflow: hidden; background: var(--st-na-bg); }
.map-bar span { height: 100%; }
.map-bar .available { background: var(--st-available); }
.map-bar .progress { background: var(--st-progress); }
.map-bar .planned { background: var(--st-planned); }
.map-bar .missing { background: var(--st-missing); }
.map-bar .na { background: repeating-linear-gradient(45deg, #d6dbe6 0 4px, #eef0f5 4px 8px); }
.map-counts { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 0.88rem; }
.map-counts > span { display: inline-flex; align-items: center; gap: 5px; }
.map-counts b { font-variant-numeric: tabular-nums; }
.map-miss { display: grid; gap: 5px; }
.map-miss-row { display: grid; grid-template-columns: minmax(96px, auto) 1fr 2.2em; gap: 8px; align-items: center; font-size: 0.86rem; }
.map-miss-row b { text-align: end; font-variant-numeric: tabular-nums; color: var(--st-missing); }
.map-miss-bar { height: 8px; border-radius: 999px; background: #f0f2f7; overflow: hidden; }
.map-miss-bar span { display: block; height: 100%; background: var(--st-missing); border-radius: 999px; }
.map-section { margin-bottom: 18px; }
.map-section h3 { font-size: 1.05rem; display: flex; gap: 8px; align-items: baseline; }
.map-section h4 { margin: 12px 0 6px; font-size: 0.95rem; }
.map-table { width: 100%; border-collapse: separate; border-spacing: 4px; min-width: 640px; }
.map-table thead th { font-size: 0.82rem; color: var(--muted); font-weight: 700; text-align: center; padding: 4px; }
.map-table thead th:first-child { text-align: start; }
.map-theme { width: 26%; text-align: start; vertical-align: top; padding: 0; }
.theme-btn, .cell-btn { width: 100%; height: 100%; text-align: start; font: inherit; font-weight: 400; color: inherit; background: transparent; border: 0; border-radius: 10px; padding: 8px 10px; min-height: 0; display: flex; gap: 8px; align-items: flex-start; }
.theme-btn { flex-direction: column; gap: 2px; background: #f7f8fc; }
button.theme-btn:hover, button.cell-btn:hover, button.theme-btn:focus-visible, button.cell-btn:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }
.theme-name { font-weight: 700; }
.theme-sub, .theme-note { font-size: 0.8rem; color: var(--muted); }
.theme-note { font-style: italic; }
.planned-chip { background: var(--st-planned-bg); color: var(--st-planned); font-size: 0.72rem; padding: 1px 8px; margin-top: 2px; }
.planned-row .theme-btn { box-shadow: inset 0 0 0 1px var(--st-planned); }
.map-cell { padding: 0; border-radius: 10px; vertical-align: top; }
.map-cell.available { background: var(--st-available-bg); }
.map-cell.progress { background: var(--st-progress-bg); }
.map-cell.planned { background: var(--st-planned-bg); }
.map-cell.missing { background: var(--st-missing-bg); }
.map-cell.na { background: repeating-linear-gradient(45deg, #f2f4f8 0 6px, #e9ecf3 6px 12px); }
.map-cell .dot { margin-top: 5px; }
.cell-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; font-size: 0.82rem; line-height: 1.35; }
.cell-status { font-weight: 700; font-size: 0.86rem; }
.map-cell.available .cell-status { color: var(--st-available); }
.map-cell.progress .cell-status { color: var(--st-progress); }
.map-cell.planned .cell-status { color: var(--st-planned); }
.map-cell.missing .cell-status { color: var(--st-missing); }
.map-cell.na .cell-status { color: var(--muted); }
.cell-story { color: var(--text); overflow-wrap: anywhere; }
.cell-date { color: var(--muted); font-variant-numeric: tabular-nums; }
.cell-note { color: var(--muted); overflow-wrap: anywhere; }
.fix-tag { display: inline-block; font-size: 0.68rem; font-weight: 800; letter-spacing: 0.06em; padding: 0 5px; border-radius: 4px; background: var(--text); color: #fff; vertical-align: 1px; }
.map-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: center; color: var(--muted); border-top: 1px solid var(--line); padding-top: 12px; }
.map-legend > span { display: inline-flex; align-items: center; gap: 6px; }
.map-text ul { margin: 0 0 6px; padding-inline-start: 20px; line-height: 1.8; }
.map-done { display: inline-block; margin: 0 0 6px 6px; padding: 2px 10px; border-radius: 999px; background: var(--st-available-bg); color: var(--st-available); font-size: 0.86rem; }
.map-dialog { display: grid; gap: 0; min-width: min(560px, 90vw); }
.map-dialog-body { padding: 14px 16px; display: grid; gap: 12px; max-height: 70vh; overflow: auto; }
.map-dialog .actions { padding: 0 16px 14px; display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.map-status { border: 1px solid var(--line); border-radius: 10px; display: grid; gap: 8px; padding: 10px 12px; margin: 0; }
.map-status legend { font-weight: 700; color: var(--muted); padding: 0 4px; }
.map-status label { display: flex; align-items: center; gap: 8px; }
.map-story-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.map-story-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; }
.map-story-row select { max-width: 100%; }
.map-versions { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
@media (max-width: 560px) {
  .map-tools { width: 100%; }
  .map-tools .seg { flex: 1 1 auto; }
  .map-tools .seg button { flex: 1; padding: 7px 8px; }
}
/* story map: new uploads and missing information */
.new-chip { background: #e4eefc; color: #1f6fd1; font-size: 0.72rem; padding: 1px 8px; margin-top: 2px; }
.issue-chip { background: #fdf3df; color: #9a5b00; font-size: 0.72rem; padding: 1px 8px; margin-top: 2px; }
.map-notice { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 10px 14px; margin: -6px 0 16px; border-radius: 10px; background: #f4f7fe; border: 1px solid #dfe6f7; font-size: 0.9rem; }
.map-notice .chip { margin: 0; font-weight: 800; }
.map-story-item { display: grid; gap: 6px; padding: 8px 0; border-bottom: 1px solid var(--line); }
/* story map: fixed category tags (OpenAI allowed / not allowed / mixed, superhero-famous / normal) */
.tag-chip { font-size: 0.72rem; padding: 1px 8px; margin: 2px 0 0 4px; font-weight: 600; }
.chip.tag-openai { background: #e3f6ea; color: var(--ok); }
.chip.tag-other { background: #fbe2df; color: var(--err); }
.chip.tag-mixed { background: #fff3cd; color: var(--warn); }
.chip.tag-famous { background: #ece4fb; color: #5b3aa6; }
.chip.tag-normal { background: #eef1f8; color: var(--muted); }
.chip.tag-none { background: #f4f5f8; color: var(--muted); border: 1px dashed #c3c9d6; }
.cell-tags { display: block; line-height: 1.2; }
.cell-tags .tag-chip { font-size: 0.64rem; padding: 0 6px; margin: 2px 0 0 3px; }
.chip.tag-box-app { background: #e4eefc; color: #1f6fd1; }
.chip.tag-box-ai-box { background: #fdf3df; color: #9a5b00; }
.chip.tag-box-ai-text { background: #eef1f8; color: var(--muted); }
.map-story-tags { display: block; }
.map-filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 0 0 14px; }
.map-filters .field-label { margin: 0; }
.map-filters select { width: auto; max-width: 100%; }
.cell-story.tag-dim { opacity: 0.35; }
/* upload type wizard (2026-10-21): type cards, steps, findings */
dialog.wizard-dialog { max-width: 760px; }
.wiz-steps { display: flex; gap: 10px; font-size: 0.8rem; color: var(--muted); }
.wiz-steps .on { color: var(--text); font-weight: 700; }
.wiz-steps .done { color: var(--ok); }
.wiz-types { display: grid; gap: 10px; }
.wiz-type { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; align-items: start; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; }
.wiz-type:has(input:checked) { border-color: var(--accent, #1f6fd1); background: #f4f8ff; }
.wiz-type input { margin-top: 4px; }
.wiz-type .wiz-desc { grid-column: 2; color: var(--muted); font-size: 0.88rem; line-height: 1.6; }
.wiz-type .chip { font-size: 0.72rem; padding: 1px 8px; margin-inline-start: 6px; }
.wiz-warn { padding: 10px 12px; border-radius: 10px; background: #fdf3df; color: #9a5b00; font-size: 0.9rem; }
.wiz-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; max-height: 46vh; overflow: auto; }
.wiz-list li { padding: 8px 10px; border-radius: 8px; font-size: 0.9rem; line-height: 1.6; }
.wiz-list li.sev-block, .wiz-list li.sev-error { background: #fbe2df; color: var(--err); }
.wiz-list li.sev-warning { background: #fff3cd; color: var(--warn); }
.wiz-summary { margin: 0; padding-inline-start: 20px; line-height: 1.9; }
/* the wait while the server reads or reviews a file (waitInDialog) */
.wiz-wait { display: grid; gap: 12px; min-width: min(520px, 80vw); }
.wiz-wait-head { display: flex; align-items: center; gap: 10px; font-size: 1.05rem; }
.wiz-spinner { width: 20px; height: 20px; border: 3px solid #e3e8f6; border-top-color: var(--primary); border-radius: 50%; animation: wiz-spin 0.9s linear infinite; flex: none; }
@keyframes wiz-spin { to { transform: rotate(360deg); } }
.wiz-bar { height: 10px; border-radius: 999px; background: #eef1f8; overflow: hidden; }
.wiz-bar span { display: block; height: 100%; width: 0; border-radius: inherit; background: linear-gradient(90deg, var(--primary), #4a6fd6, var(--primary)); background-size: 200% 100%; animation: shimmer 1.6s infinite; transition: width 0.5s ease; }
.wiz-stages { margin: 0; padding-inline-start: 22px; display: grid; gap: 4px; color: var(--muted); font-size: 0.92rem; line-height: 1.6; }
.wiz-stages li.on { color: var(--text); font-weight: 700; }
.wiz-stages li.done { color: var(--ok); }
.wiz-stages li.done::after { content: " ✓"; }
.type-badge { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; margin: 8px 0; }
.map-story-item:last-child { border-bottom: 0; }
.map-story-tools { display: inline-flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.map-issues { margin: 0; padding-inline-start: 18px; color: #9a5b00; font-size: 0.86rem; line-height: 1.7; }
.map-dl { white-space: nowrap; }
#editorDownload { display: inline-block; margin-top: 6px; }
/* searchable lists (story drop-downs) */
.combo { position: relative; min-width: 0; }
.combo-native { position: absolute !important; inset-inline-start: 0; bottom: 0; width: 1px !important; height: 1px !important; opacity: 0; pointer-events: none; }
.combo-input { width: 100%; }
.combo-list { position: absolute; z-index: 40; inset-inline: 0; top: calc(100% + 4px); max-height: 340px; overflow: auto; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 28px rgba(20, 30, 70, 0.14); padding: 4px; text-align: start; }
.combo-group { padding: 8px 10px 3px; font-size: 0.78rem; color: var(--muted); font-weight: 700; }
.combo-item { padding: 7px 10px; border-radius: 8px; cursor: pointer; line-height: 1.4; }
.combo-item.active { background: #e9edfa; color: var(--primary); }
.combo-item.selected { font-weight: 700; }
.combo-empty { padding: 10px; color: var(--muted); }

/* delete requests: pending count on the nav tab */
.nav-badge { display: inline-block; min-width: 1.3em; padding: 0 0.35em; margin-inline-start: 4px; border-radius: 999px; background: var(--err); color: #fff; font-size: 0.72rem; font-weight: 700; line-height: 1.5; text-align: center; }

/* a deploy happened while the page was open */
.update-banner { position: fixed; inset-inline: 0; bottom: 0; z-index: 50; display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: center; padding: 10px 16px calc(10px + env(safe-area-inset-bottom, 0px)); background: #fff3cd; color: #6b4e00; border-top: 1px solid #f0d58a; font-weight: 600; }

/* colour book import: the parts of the book, then its 7 scenes */
.import-kind { display: inline-flex; flex-wrap: wrap; gap: 12px; }
.color-fields { display: grid; gap: 10px; margin: 10px 0; }
.color-fields textarea, .color-scene textarea { width: 100%; font-family: inherit; }
.color-scene { display: grid; gap: 6px; padding: 8px 10px; border: 1px solid #e3e8f4; border-radius: 10px; margin-bottom: 8px; background: #fff; }
.color-scene-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.color-scene-head input { flex: 1 1 160px; min-width: 0; }
.color-scene .num { font-weight: 700; color: var(--primary); min-width: 1.5em; }
.inline-fields { display: flex; flex-wrap: wrap; gap: 6px; }
.inline-fields input { flex: 1 1 90px; min-width: 0; }

/* the image model of an upload, and a provider whose account stopped working */
.model-pick { border: 2px solid var(--primary); border-radius: 10px; padding: 8px 12px; margin: 10px 0; display: grid; gap: 6px; background: #f5f8ff; }
.model-pick legend { font-weight: 700; color: var(--primary); padding: 0 6px; }
.model-pick p { margin: 0; }
/* look-alike characters of an upload: one question per group, answered before saving */
.cast-questions { border: 2px solid var(--warn); border-radius: 10px; padding: 8px 12px; margin: 10px 0; background: #fff8ec; }
.cast-questions h4 { margin: 0 0 4px; }
.cast-question { border: 1px solid #e6d3ad; border-radius: 8px; padding: 6px 10px; margin: 8px 0; display: grid; gap: 4px; background: #fff; }
.cast-question.answered { border-color: var(--ok); }
.cast-question legend { font-weight: 700; padding: 0 6px; }
.cast-members, .cast-plan { margin: 0; padding-inline-start: 18px; display: grid; gap: 3px; }
.cast-plan { margin-inline-start: 22px; font-size: 0.85rem; }
.cast-en, .cast-plan code, .cast-saved code { display: block; text-align: left; unicode-bidi: isolate; white-space: normal; overflow-wrap: anywhere; }
.cast-saved { display: block; margin-top: 6px; color: var(--text); }
.provider-alert { background: #fbe2df; color: #7a1d12; border-bottom: 2px solid var(--err); padding: 8px 16px; font-weight: 600; }
.provider-alert-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; max-width: 1200px; margin: 0 auto; }

/* the standard portrait could not be made: the uploaded photo is the reference */
.warn-inline { color: var(--warn); font-weight: 700; }

/* auto-save state in the editors */
.save-state { margin-inline-start: 8px; font-weight: 700; font-size: 1rem; }
/* the team's verdict on a generated book (2026-10-18) */
.chip.rejected { background: #fde8e8; color: #b42318; border-color: #f5b5b5; }
.chip.success { background: #e6f6ec; color: #1b7a3d; }
.review-dialog .reasons, .review-dialog .pages { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 6px 0 12px; }
.review-dialog label.inline { font-size: 0.95rem; }
/* the one button every editor ends with (user, 2026-10-14: too many save buttons confused the team) */
.dialog-head .save-close { margin-inline-start: auto; white-space: nowrap; }
.save-state.pending { color: var(--muted); }
.save-state.ok { color: var(--ok); }
.save-state.err { color: var(--err); }

/* pages with two or three text boxes: one tab per box in the box editor */
.box-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.box-tabs .tab { border: 1px solid var(--line, #d6dbe8); background: #fff; border-radius: 999px; padding: 4px 12px; font-weight: 600; }
.box-tabs .tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* production report */
.report-bar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 8px 0; }
.report-bar input[type="date"], .report-bar input[type="month"], .report-bar select { width: auto; min-width: 150px; }
.report-mode { display: inline-flex; gap: 12px; }
#reportBody .kpi strong { font-size: 1.4rem; }
#reportBody .kpi { display: flex; flex-direction: column; gap: 2px; }
#reportBody tr.total td { font-weight: 700; border-top: 2px solid var(--line, #d6dbe8); }

/* draft stories (2026-10-19): just imported, hidden from creators until approved */
.draft-bar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; padding: 10px 14px; border: 1px solid #f3d38a; border-radius: 10px; background: #fff8e6; color: #7a5200; line-height: 1.6; }
.draft-bar button { white-space: nowrap; }
/* colour-book import: the versions side by side before saving */
.cprev-bar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin: 6px 0 10px; }
.cprev-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; }
.cprev-col { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: #fff; min-width: 0; }
.cprev-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-weight: 700; }
.cprev-col .prompt-text { max-height: 340px; }
mark.hl-title { background: #e4eefc; color: #16307a; border-radius: 4px; padding: 0 3px; }
mark.hl-outfit { background: #fde9c8; color: #7a4200; border-radius: 4px; padding: 0 3px; font-weight: 700; }

/* prompt lock (2026-10-19): saved prompts are read-only in the prompt tab */
.prompt-lock-note { background: #fff7e6; border: 1px solid #f0c36d; border-radius: 8px; padding: 8px 12px; margin: 8px 0 12px; line-height: 1.6; }
#variantPanel textarea[readonly] { background: #f6f6f4; color: #444; cursor: default; }

/* employees' performance tracker (admin) */
.perf-strip { position: relative; direction: ltr; height: 16px; background: #eceff4; border-radius: 4px; overflow: hidden; }
.perf-strip i { position: absolute; top: 0; bottom: 0; display: block; }
.perf-ticks { position: relative; direction: ltr; height: 14px; font-size: 10px; color: #888; }
.perf-ticks b { position: absolute; font-weight: 400; transform: translateX(-50%); }
.pf-active { background: #2e9d4a; }
.pf-pause { background: #bfe3c8; }
.pf-idle { background: #e8b4b4; }
.pf-ledger { background: #9db7e8; }
.perf-legend { display: flex; gap: 16px; font-size: 12px; margin: 6px 0; }
.perf-legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -2px; margin-inline-end: 4px; }

/* page editor (src/pageedit.ts) */
.pe-dialog { width: min(980px, 96vw); max-height: 92vh; overflow: auto; }
.pe-dialog textarea { width: 100%; font-family: ui-monospace, Consolas, monospace; font-size: 0.85rem; }
.pe-dialog #peText { font-family: inherit; font-size: 1rem; }
.pe-steps { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.pe-decide { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 10px 12px; margin-bottom: 10px; border-radius: 8px; background: #fff6e0; border: 1px solid #f0d48a; }
.pe-decide .actions { margin: 0; }
.pe-steps span { padding: 3px 10px; border-radius: 12px; background: #eceff4; font-size: 0.8rem; }
.pe-steps span.done { background: #d8f0de; }
.pe-steps span.now { background: #2e6be6; color: #fff; }
.pe-suggest { border: 1px dashed #9db7e8; border-radius: 8px; padding: 8px; margin: 8px 0; }
.pe-suggest pre, .pe-dialog details pre { white-space: pre-wrap; max-height: 220px; overflow: auto; font-size: 0.8rem; background: #f6f7f9; padding: 6px; border-radius: 6px; }
.pe-compare { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pe-compare figure { margin: 0; }
.pe-compare img { width: 100%; border-radius: 6px; border: 1px solid #ddd; }
.pe-compare figcaption { text-align: center; font-size: 0.8rem; color: #666; }
.pe-hist { list-style: none; padding: 0; margin: 4px 0; display: grid; gap: 4px; }
.warn-text { color: var(--warn); }

/* creators' edits (src/creatoredits.ts) */
.ce-list { display: grid; gap: 10px; }
.ce-item { display: grid; grid-template-columns: 110px 1fr; gap: 12px; padding: 10px; border: 1px solid #e3e6ec; border-radius: 10px; }
.ce-thumb img { width: 110px; border-radius: 6px; display: block; }
.ce-info { display: grid; gap: 6px; align-content: start; }
.ce-info button { margin-inline-start: 8px; }
.ce-text { display: grid; gap: 4px; margin: 4px 0; padding: 6px 8px; background: #f6f7f9; border-radius: 6px; }
.box-target { display: flex; gap: 14px; flex-wrap: wrap; margin: 4px 0 8px; }
.dedication-preview { max-width: 160px; border-radius: 6px; border: 1px solid #ddd; }

/* upload auto-improve (src/standardize.ts) */
.wiz-improve { display: grid; gap: 6px; max-height: 52vh; overflow: auto; }
.wiz-imp-row { border: 1px solid #e3e6ec; border-radius: 8px; padding: 6px 8px; }
.wiz-imp-row summary { cursor: pointer; }
.wiz-imp-cmp { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 6px; }
.wiz-imp-cmp pre { white-space: pre-wrap; font-size: 0.75rem; max-height: 260px; overflow: auto; background: #f6f7f9; padding: 6px; border-radius: 6px; }

/* permissions table (Settings, admin) */
.perms-table td, .perms-table th { text-align: center; }
.perms-table td:first-child { text-align: start; }

/* phones (2026-10-27: the admin works from a mobile): a ☰ menu, full-width dialogs, tables that scroll sideways */
.nav-toggle { display: none; }
@media (max-width: 760px) {
  .topbar { gap: 8px; padding: 8px 12px; }
  .brand { font-size: 1rem; flex: 1; }
  .nav-toggle { display: inline-flex; align-items: center; justify-content: center; font-size: 1.3rem; padding: 4px 12px; }
  #nav { display: none; order: 10; flex-basis: 100%; }
  .topbar.nav-open #nav { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; max-height: 70vh; overflow: auto; }
  #nav button { padding: 10px 8px; text-align: center; border: 1px solid var(--line); }
  #whoami { display: none; }
  .balance-pill { font-size: 0.75rem; padding: 3px 8px; }
  .lang-btn, #logoutBtn { padding: 4px 10px; }
  main { padding: 12px 10px 60px; }
  .card { padding: 14px 12px; }
  dialog, dialog.box-dialog, dialog.wizard-dialog, .pe-dialog { width: 100vw; max-width: 100vw; max-height: 100dvh; margin: 0; border-radius: 0; }
  .dialog-head { flex-wrap: wrap; gap: 6px; }
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table { font-size: 0.85rem; }
  .table th, .table td { padding: 6px 8px; }
  .actions { flex-wrap: wrap; }
  .pe-compare, .wiz-imp-cmp { grid-template-columns: 1fr; }
  .ce-item { grid-template-columns: 80px 1fr; }
  .ce-thumb img { width: 80px; }
  .report-bar { flex-wrap: wrap; }
  input, select, textarea { font-size: 16px; }
}

/* page-edit status for the team (2026-10-27) */
.edit-note { display: block; margin-top: 6px; padding: 6px 10px; border-radius: 8px; }
.edit-note.pending { background: #fff3cd; color: #7a5a00; }
.edit-note.applied { background: #e3f4e8; color: #1d6b34; }
.pe-chip { font-size: 0.75rem; padding: 2px 8px; border-radius: 10px; white-space: nowrap; }
.pe-chip.pending { background: #fff3cd; color: #7a5a00; }
.pe-chip.applied { background: #e3f4e8; color: #1d6b34; }
.pe-chip.rejected { background: #fbe2df; color: #a12a1b; }

/* until the user's role and tab are known (refresh, 2026-10-27) */
body.booting #nav, body.booting main { visibility: hidden; }
.ce-more { text-align: center; margin-top: 10px; }
/* 10 rows a page (2026-10-28) */
/* the shop's order: one card per story, the child's photos (2026-11-05) */
/* «تجربة صفحتين» (2026-11-09) */
.dual-form textarea { width: 100%; font-family: monospace; font-size: 0.85rem; }
.dual-row { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; margin-top: 8px; }
.dual-pages { display: flex; flex-wrap: wrap; gap: 12px; }
.dual-pages figure { margin: 0; flex: 1 1 260px; max-width: 420px; }
.dual-pages img { width: 100%; border-radius: 8px; border: 1px solid #e5e8f0; display: block; }
.dual-pages figcaption { text-align: center; font-size: 0.85rem; margin-top: 4px; }
.dual-list { display: flex; flex-direction: column; gap: 4px; }
.dual-list button { text-align: start; background: none; border: 1px solid #e5e8f0; border-radius: 8px; padding: 6px 10px; cursor: pointer; }
.dual-templates { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 8px; }
.dual-template { border: 1px solid #e5e8f0; border-radius: 8px; padding: 8px; }
.dual-prompt { white-space: pre-wrap; font-size: 0.75rem; max-height: 240px; overflow: auto; background: #f8f9fc; padding: 6px; border-radius: 6px; }
.dual-spreads { display: flex; flex-direction: column; gap: 18px; align-items: center; }
.dual-spread { display: flex; direction: rtl; gap: 0; width: min(100%, 720px); box-shadow: 0 6px 18px rgba(0, 0, 0, 0.15); border-radius: 4px; overflow: hidden; background: #fff; }
.dual-spread figure { margin: 0; flex: 1 1 50%; position: relative; }
.dual-spread figure img { width: 100%; display: block; aspect-ratio: 5 / 7; object-fit: cover; }
.dual-spread figure + figure { border-inline-start: 1px solid rgba(0, 0, 0, 0.18); }
.dual-spread figcaption { position: absolute; bottom: 4px; inset-inline-start: 6px; background: rgba(0, 0, 0, 0.55); color: #fff; font-size: 0.72rem; padding: 1px 6px; border-radius: 4px; }
.dual-spread .dual-blank { background: #f3f1ec; aspect-ratio: 5 / 7; }
.dual-spread .dual-wait { border-radius: 0; }
.dual-book { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.dual-book figure { margin: 0; }
.dual-book img { width: 100%; border-radius: 6px; border: 1px solid #e5e8f0; display: block; }
.dual-book figcaption { text-align: center; font-size: 0.8rem; }
.dual-wait { aspect-ratio: 5 / 7; display: flex; align-items: center; justify-content: center; background: #f3f5fa; border-radius: 6px; font-size: 0.75rem; padding: 6px; text-align: center; }
.dual-combined { width: 100%; max-width: 900px; border-radius: 6px; margin-bottom: 10px; }
/* «المساعد» (2026-11-05) */
.chat-wrap { display: grid; grid-template-columns: 240px 1fr; gap: 14px; min-height: 70vh; }
.chat-side { border-inline-end: 1px solid #e5e8f0; padding-inline-end: 12px; display: flex; flex-direction: column; gap: 8px; }
.chat-list { display: flex; flex-direction: column; gap: 4px; overflow-y: auto; max-height: 60vh; }
.chat-list button { text-align: start; background: none; border: 1px solid transparent; border-radius: 8px; padding: 6px 8px; cursor: pointer; }
.chat-list button.active { background: #eef3ff; border-color: #c9d6ff; }
.chat-main { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.chat-messages { flex: 1; overflow-y: auto; max-height: 60vh; display: flex; flex-direction: column; gap: 10px; padding: 4px; }
.chat-msg { max-width: 85%; padding: 10px 12px; border-radius: 12px; white-space: pre-wrap; line-height: 1.6; }
.chat-msg.user { align-self: flex-start; background: #1f3a8a; color: #fff; }
.chat-msg.assistant { align-self: flex-end; background: #f3f5fa; border: 1px solid #e5e8f0; }
.chat-msg img { max-width: 320px; width: 100%; border-radius: 8px; display: block; margin-top: 6px; }
.chat-msg .chat-cost { font-size: 0.75rem; opacity: 0.6; margin-top: 4px; }
.chat-form textarea { width: 100%; }
.chat-tools { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.chat-tools button { margin-inline-start: auto; }
@media (max-width: 760px) { .chat-wrap { grid-template-columns: 1fr; } .chat-side { border: 0; padding: 0; } }
/* «إنشاء من المتجر» (2026-11-11) */
.shop-queue { border: 1px solid #c9d6ff; background: #f5f8ff; border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; }
.shop-queue-head { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; }
.shop-queue select { width: 100%; }
.shop-queue .seg button { border: 1px solid #c9d6ff; background: #fff; padding: 4px 10px; cursor: pointer; }
.shop-queue .seg button.active { background: #1f3a8a; color: #fff; }
.shop-search { display: flex; gap: 6px; }
.shop-search input { flex: 1; }
.manual-entry-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 8px; }
.shop-panel { border: 1px solid var(--line, #d6dbe8); border-radius: 10px; padding: 10px 12px; background: #f8f9fc; }
.shop-story { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; padding: 8px 0; border-top: 1px solid #e5e8f0; }
.shop-story:first-of-type { border-top: 0; }
.shop-story.typed { background: #eef6ff; border-radius: 8px; padding: 8px; }
.shop-story img { width: 64px; height: 64px; object-fit: cover; border-radius: 6px; border: 1px solid #ddd; }
.shop-story .shop-info { min-width: 220px; flex: 1; }
.table-pager { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 10px; }
.table-pager button:disabled { opacity: 0.4; cursor: default; }
tr.pg-off { display: none; }

/* character kinds (2026-10-27) */
.tag-kind { background: #efe7fb; color: #5b2d91; }
.wiz-kind-title { margin: 14px 0 4px; }

/* page tags, reference and check (2026-10-28) */
.checks-bar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 4px 0 8px; }
.page-tags { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; margin-top: 6px; }
.page-tags details { flex-basis: 100%; }
.page-tags .ref-list { margin: 4px 0; padding-inline-start: 18px; }
.check-chip.verified { background: #e3f4e8; color: #1d6b34; }
.check-chip.issues { background: #fff3cd; color: #7a5a00; }
.check-chip.changed { background: #e7eefb; color: #24467a; }
.check-chip.unchecked { background: #eef0f3; color: #555; }
