/* The platform's page styles, on top of ds.css (the design system: tokens and tp- components, generated by
   docs/design/build.py; never edit ds.css by hand). The classes below are the ones the templates and scripts
   already use (.card, .btn, .pill, tables, .banner, .tabs, the chapter matrix, the review screen), drawn with
   the design system's tokens so every page shares one look. New pages use the tp- components directly. */

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { font-size: 14px; line-height: 24px; }
a { color: var(--ink); text-decoration: underline; text-decoration-color: var(--line-strong); text-underline-offset: 3px; }
a:hover { text-decoration-color: currentColor; }
.tp-app a, .card a.btn, a.btn, .tp-nav a, .tabs a, table a { text-decoration: none; }
table a:hover { text-decoration: underline; }
h1 { font-size: 26px; line-height: 40px; font-weight: 600; margin: 0 0 2px; text-wrap: balance; }
h2 { font-size: 17px; line-height: 28px; font-weight: 600; margin: 28px 0 12px; }
h3 { font-size: 15px; line-height: 24px; font-weight: 600; margin: 18px 0 6px; }
p { margin: 0 0 10px; }
small, .muted { color: var(--ink-muted); }
small { font-size: 12px; line-height: 18px; }
code { font: 12.5px/1.5 var(--font-mono); background: var(--surface-sunken); border: 1px solid var(--line); padding: 1px 5px; border-radius: var(--radius-sm); }

/* Shell: tp-app (sidebar + main) from ds.css; the old .wrap is the content column. */
.wrap { padding: var(--space-6); max-width: var(--content-max); width: 100%; margin: 0; }
.narrow { max-width: 780px; }
.tp-side { position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.tp-side .tp-nav a .tp-icon, .tp-side .tp-navitem .tp-icon { color: inherit; }
.tp-side form { margin: 0; }
.tp-signout { margin-inline-start: auto; }
.tp-topbar .tp-search { max-width: 380px; }
.tp-topbar .tp-search input { height: 100%; }
.jobs-dot { position: relative; }
.jobs-dot[data-n]::after { content: attr(data-n); position: absolute; top: -6px; inset-inline-end: -6px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: var(--accent); color: var(--on-accent); font-size: 11px; line-height: 18px; font-weight: 600; text-align: center; box-shadow: 0 0 0 2px var(--surface); }
.offline { background: var(--warn-soft); color: var(--warn-ink); font-size: 13px; padding: 6px var(--space-6); border-bottom: 1px solid var(--line); }
@media (max-width: 860px) {
  .tp-side { position: static; height: auto; }
  .wrap { padding: var(--space-4) max(16px, env(safe-area-inset-right, 0px)) var(--space-8) max(16px, env(safe-area-inset-left, 0px)); }
  .offline { padding-inline: 16px; }
}

/* Page head */
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--space-4); flex-wrap: wrap; margin-bottom: var(--space-5); }
.sub { color: var(--ink-muted); margin: 0; }

/* Status pills: the old names map onto the design system's six states. */
.pill { display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 8px; border-radius: var(--radius-sm); background: var(--neutral-soft); color: var(--neutral-ink); font-size: 12px; line-height: 16px; font-weight: 500; white-space: nowrap; vertical-align: middle; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 2px; background: currentColor; flex: none; }
.pill.good { background: var(--good-soft); color: var(--good-ink); }
.pill.warn { background: var(--warn-soft); color: var(--warn-ink); }
.pill.bad { background: var(--bad-soft); color: var(--bad-ink); }
.pill.info { background: var(--info-soft); color: var(--info-ink); }
.pill.hold { background: var(--hold-soft); color: var(--hold-ink); }

/* Banners */
.banner { display: block; padding: var(--space-3) var(--space-4); border-radius: var(--radius-md); margin: 0 0 var(--space-4); background: var(--info-soft); color: var(--info-ink); border: 0; font-size: 13px; }
.banner.ok { background: var(--good-soft); color: var(--good-ink); }
.banner.err { background: var(--bad-soft); color: var(--bad-ink); }
.banner.warn { background: var(--warn-soft); color: var(--warn-ink); }
.banner a { color: inherit; }

/* Cards, grids, stats */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: var(--space-5); box-shadow: var(--shadow-card); margin-bottom: var(--space-4); min-width: 0; }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.grid { display: grid; gap: var(--space-4); }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: var(--space-4); margin-bottom: var(--space-5); }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: var(--space-4) var(--space-5); box-shadow: var(--shadow-card); min-width: 0; }
.stat b { display: block; font-size: 26px; line-height: 34px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat span { color: var(--ink-muted); font-size: 13px; }

/* Tables: header band, hairlines, row hover (ds.css draws tp-table the same way). */
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { text-align: start; padding: 10px var(--space-3); border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--ink-muted); font-weight: 500; background: var(--surface-sunken); white-space: nowrap; vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td, table tr:not(:first-child):hover td { background: var(--surface-sunken); }
.card > table, .card.scroll > table, .card > .scroll > table { margin: 0; }
.card.scroll { padding: 0; overflow-x: auto; }
.card.scroll > p, .card.scroll > .help { padding: 0 var(--space-5) var(--space-4); }
.scroll { overflow-x: auto; }
td.clip { max-width: 16rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Book content takes its direction from its own text (dir="auto"); in the Arabic interface it still lines up
   on the right with the rest of the page. The review screen's text columns keep their own alignment. */
[dir="rtl"] :is(td, h3, .tp-card div)[dir="auto"] { text-align: right; }
td.num, th.num { text-align: end; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ar { direction: rtl; text-align: right; font-size: 16px; line-height: 30px; }

/* Buttons and fields */
button, .btn, input, select, textarea { font: inherit; color: inherit; }
.btn, button { display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2); height: var(--control-h); padding: 0 var(--space-4); border-radius: var(--radius-md); border: 1px solid var(--line); background: var(--surface); color: var(--ink); font-size: 13px; font-weight: 500; cursor: pointer; white-space: nowrap; text-decoration: none; }
.btn:hover, button:hover { background: var(--surface-sunken); }
.btn.primary, button.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn.primary:hover, button.primary:hover { background: var(--primary); opacity: .86; }
.btn.danger, button.danger { color: var(--bad-ink); }
.btn.small, button.small { height: var(--control-h-sm); padding: 0 var(--space-3); font-size: 12px; }
button:disabled { opacity: .45; cursor: not-allowed; }
button.link { height: auto; border: 0; background: none; padding: 0; color: var(--ink); text-decoration: underline; text-underline-offset: 3px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=search], input:not([type]), select, textarea {
  width: 100%; min-height: var(--control-h); padding: 6px var(--space-3); border: 1px solid var(--line-strong); border-radius: var(--radius-md); background: var(--surface); color: var(--ink); }
.tp-search input, .tp-search input:not([type]) { border: 0; min-height: 0; padding: 0; background: transparent; }
textarea { min-height: 96px; resize: vertical; line-height: 1.6; }
textarea.mono { font: 12.5px/1.6 var(--font-mono); white-space: pre-wrap; overflow-wrap: anywhere; }
input.term-ar { font-size: 15px; line-height: 1.6; padding: 4px var(--space-3); }
input[type=checkbox], input[type=radio] { accent-color: var(--primary); width: 16px; height: 16px; }
:where(input, select, textarea):focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
label { display: block; font-weight: 500; font-size: 13px; margin: 14px 0 4px; }
label.check { display: flex; align-items: center; gap: var(--space-2); font-weight: 400; font-size: 14px; margin: 4px 0; }
label.check input { width: auto; }
.tp-search { margin: 0; font-weight: 400; }
.help { color: var(--ink-muted); font-size: 12px; line-height: 18px; margin: 4px 0 0; font-weight: 400; }
.row { display: flex; gap: var(--space-3); align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1; min-width: 160px; }
form.inline { display: inline; }

/* Tabs (a book's pages) */
.tabs { display: flex; gap: var(--space-5); border-bottom: 1px solid var(--line); margin: var(--space-2) 0 var(--space-5); overflow-x: auto; }
.tabs a { padding: 10px 2px; color: var(--ink-muted); font-weight: 500; white-space: nowrap; text-decoration: none; }
.tabs a.on { color: var(--ink); box-shadow: inset 0 -2px 0 var(--primary); }
.tabs a:hover { color: var(--ink); }

/* The chapter × pass grid */
.matrix td { min-width: 160px; }
.matrix td:first-child, .matrix th:first-child { min-width: 0; width: 34px; }
.matrix td.title { min-width: 220px; max-width: 320px; font-weight: 500; }
.cell { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.cell .who { font-size: 12px; color: var(--ink-muted); }
.bar { height: 6px; border-radius: var(--radius-full); background: var(--surface-sunken); box-shadow: inset 0 0 0 1px var(--line); overflow: hidden; display: flex; min-width: 120px; }
.bar i { display: block; height: 100%; }
.bar .done { background: var(--primary); } .bar .check { background: var(--warn-ink); } .bar .ai { background: var(--info-ink); }

/* The shared dialog (filled by app.js) */
dialog { border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 0; background: var(--surface); color: var(--ink); max-width: 640px; width: calc(100% - 32px); box-shadow: var(--shadow-pop); }
dialog::backdrop { background: rgba(10, 10, 12, .5); }
dialog .dh { padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--line); font-weight: 600; font-size: 16px; }
dialog .db { padding: var(--space-4) var(--space-5); max-height: 60vh; overflow: auto; }
dialog .df { padding: var(--space-3) var(--space-5); border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: var(--space-2); }

/* The review screen */
.rv-bar { position: sticky; top: var(--topbar-h); z-index: 4; background: var(--canvas); padding: var(--space-3) 0; border-bottom: 1px solid var(--line); margin-bottom: var(--space-3); display: flex; gap: var(--space-3); align-items: center; flex-wrap: wrap; }
.rv-bar .filters { display: inline-flex; gap: 2px; padding: 3px; border-radius: var(--radius-md); background: var(--surface-sunken); flex-wrap: wrap; }
.rv-bar .filters button { height: 28px; border: 0; background: transparent; color: var(--ink-muted); }
.rv-bar .filters button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-card), 0 0 0 1px var(--line); }
.seg { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); margin-bottom: var(--space-3); scroll-margin-top: 140px; overflow: hidden; }
.seg.cur { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
.seg .meta { display: flex; gap: var(--space-2); align-items: center; padding: 6px var(--space-4); border-bottom: 1px solid var(--line); background: var(--surface-sunken); font-size: 12px; color: var(--ink-muted); flex-wrap: wrap; }
.seg .meta .path { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 80px; }
.seg .cols { display: grid; grid-template-columns: 1fr 1fr; }
.seg .cols.one { grid-template-columns: 1fr; }
.seg .col { padding: var(--space-3) var(--space-4); min-width: 0; overflow-wrap: anywhere; font-size: 15px; line-height: 28px; }
.seg .col + .col { border-inline-start: 1px solid var(--line); }
.seg .col h4 { margin: 0 0 4px; font-size: 12px; line-height: 18px; color: var(--ink-muted); font-weight: 500; }
.seg.heading .col .text { font-weight: 600; }
.seg .foot { display: flex; gap: var(--space-2); align-items: center; padding: var(--space-2) var(--space-4); border-top: 1px solid var(--line); flex-wrap: wrap; }
.seg .why { padding: 0 var(--space-4) var(--space-2); font-size: 13px; color: var(--ink-muted); }
.seg .why ul { margin: 4px 0 0; padding-inline-start: 18px; }
.seg .why .flag { color: var(--warn-ink); }
.seg img.fig { max-width: 260px; max-height: 160px; border: 1px solid var(--line); border-radius: var(--radius-md); display: block; margin-top: 8px; }
ins { background: var(--good-soft); color: var(--good-ink); text-decoration: none; border-radius: 3px; padding: 0 1px; }
del { background: var(--bad-soft); color: var(--bad-ink); border-radius: 3px; padding: 0 1px; }
.ref { border-bottom: 1px dotted var(--ink-muted); }
.seg textarea { min-height: 80px; }
.seg .comments { padding: 6px var(--space-4) 10px; font-size: 13px; border-top: 1px solid var(--line); }
.seg .comments div { margin-bottom: 4px; }
.kbd { display: inline-flex; align-items: center; height: 20px; padding: 0 6px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-sunken); font: 11px var(--font-mono); color: var(--ink-muted); }

/* Figures, the guide, login */
.figgrid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }
.figgrid img { max-width: 100%; border: 1px solid var(--line); border-radius: var(--radius-md); background: #fff; }
.guide { max-width: 860px; } .guide h1 { margin-bottom: 12px; } .guide h2 { margin-top: 32px; padding-top: 14px; border-top: 1px solid var(--line); }
.guide table { margin: 10px 0 16px; } .guide td, .guide th { border: 1px solid var(--line); }
.guide ol, .guide ul { padding-inline-start: 22px; } .guide li { margin-bottom: 4px; }
pre { background: var(--surface-sunken); border: 1px solid var(--line); padding: var(--space-3); border-radius: var(--radius-md); overflow-x: auto; font: 12.5px/1.6 var(--font-mono); white-space: pre-wrap; }
.login { max-width: 400px; margin: 10vh auto 0; }
.login .tp-brand { justify-content: center; margin-bottom: var(--space-5); }
@media (max-width: 760px) {
  .seg .cols { grid-template-columns: 1fr; } .seg .col + .col { border-inline-start: 0; border-top: 1px solid var(--line); }
  .figgrid { grid-template-columns: 1fr; } .rv-bar { top: 0; position: static; }
}

/* Arabic interface: one family for both scripts (Readex Pro); a few things stay left to right. */
html[dir=rtl] code, html[dir=rtl] textarea.code, html[dir=rtl] .guide { direction: ltr; unicode-bidi: plaintext; }
html[dir=rtl] input[type=email], html[dir=rtl] input[type=password], html[dir=rtl] input[type=number], html[dir=rtl] input[list] { direction: ltr; text-align: right; }
html[dir=rtl] [translate=no] { unicode-bidi: plaintext; }

/* Dashboard and My work */
.dash-row { display: grid; grid-template-columns: minmax(0, 2fr) minmax(300px, 1fr); gap: var(--space-4); }
.mw-row { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(220px, .8fr) minmax(280px, 1fr); gap: var(--space-4); }
.big { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.big strong { font-size: 26px; line-height: 34px; font-weight: 600; font-variant-numeric: tabular-nums; }
.vsep { border-inline-start: 2px solid var(--line); padding-inline-start: var(--space-3); }
.book-sub { display: flex; align-items: center; gap: 8px; color: var(--ink-muted); font-size: 13px; }
.book-title { margin: 6px 0; font-size: 21px; line-height: 32px; font-weight: 600; }
.book-title a { text-decoration: none; }
.hr { border: 0; border-top: 1px solid var(--line); margin: var(--space-5) 0; }
.stats-stack { display: flex; flex-direction: column; gap: var(--space-3); }
.marker { display: inline-block; width: 10px; height: 10px; flex: none; border-radius: 3px; }
.schedwrap { overflow-x: auto; padding-bottom: 4px; }
.schedwrap .tp-sched { min-width: 680px; }
.tp-chart .hit { fill: transparent; cursor: pointer; }
.tp-chart .hit:focus-visible { outline: none; stroke: var(--focus); stroke-width: 2; }
.tp-tip .tp-delta { margin-inline-start: 6px; vertical-align: 3px; }
.tp-kpis .tp-kpi .tp-display { font-size: 32px; }
.empty-note { color: var(--ink-muted); font-size: 13px; padding: var(--space-6) 0; text-align: center; }
.search-group h2 { margin-top: var(--space-5); }
@media (max-width: 1180px) { .dash-row, .mw-row { grid-template-columns: minmax(0, 1fr); } .stats-stack { flex-direction: row; flex-wrap: wrap; } .stats-stack .tp-stat { flex: 1 1 200px; } }
.tp-darkrow { display: flex; align-items: center; gap: 10px; height: var(--control-h); padding: 0 10px; color: var(--ink-muted); font-weight: 500; flex-wrap: nowrap; }
.tp-usercard b a { color: var(--ink); }
.tp-usercard .tp-signout .tp-btn span { display: none; }
@media (max-width: 860px) {
  .tp-side .tp-usercard { display: flex; margin: 0; padding: 0; border: 0; flex: none; }
  .tp-side .tp-usercard > div { display: none; }
}

/* A book's Profile and prompts page: one block per master prompt with the chapter's own section */
.cp { padding: var(--space-4) 0; border-top: 1px solid var(--line); }
.cp:first-of-type { border-top: 0; }
.cp-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-2) var(--space-4); margin-bottom: var(--space-2); }
.cp-head h3 { margin: 0; }
.cp-meta { display: inline-flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); font-size: 13px; }
.cp textarea { width: 100%; font-family: inherit; }
.cp-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-2); }
.cp-actions input { flex: 1 1 14rem; min-width: 0; }
.cp details { margin-top: var(--space-3); }
.cp summary { cursor: pointer; color: var(--ink-muted); font-size: 13px; }
.cp pre, .cp-full { white-space: pre-wrap; word-break: break-word; max-height: 28rem; overflow: auto; background: var(--surface-sunken); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: var(--space-3); font-size: 12.5px; line-height: 1.6; }
.cp-full mark { background: var(--accent-soft); color: var(--ink); border-radius: 3px; }
.cp-hist { list-style: none; padding: 0; margin: var(--space-2) 0 0; display: flex; flex-direction: column; gap: var(--space-3); font-size: 13px; }

/* Terms: the slider that ticks the most used terms */
.tp-pick { padding-block: var(--space-3); }
.tp-pick label { font-weight: 600; }
.tp-pick-row { display: flex; align-items: center; gap: var(--space-3); margin-top: var(--space-2); }
.tp-pick-row input[type=range] { --pct: 0%; flex: 1; min-width: 0; height: var(--control-h-sm); margin: 0; background: transparent;
  -webkit-appearance: none; appearance: none; cursor: pointer; }
.tp-pick-row input[type=range]:focus-visible { outline: 2px solid var(--focus); outline-offset: 4px; border-radius: var(--radius-sm); }
.tp-pick-row input[type=range]::-webkit-slider-runnable-track { height: 6px; border-radius: var(--radius-full);
  background: linear-gradient(to right, var(--accent) var(--pct), var(--line-strong) var(--pct)); }
html[dir=rtl] .tp-pick-row input[type=range]::-webkit-slider-runnable-track {
  background: linear-gradient(to left, var(--accent) var(--pct), var(--line-strong) var(--pct)); }
.tp-pick-row input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 20px; height: 20px; margin-top: -7px;
  border-radius: var(--radius-full); background: var(--accent); border: 2px solid var(--on-accent); }
.tp-pick-row input[type=range]::-moz-range-track { height: 6px; border-radius: var(--radius-full); background: var(--line-strong); }
.tp-pick-row input[type=range]::-moz-range-progress { height: 6px; border-radius: var(--radius-full); background: var(--accent); }
.tp-pick-row input[type=range]::-moz-range-thumb { width: 16px; height: 16px; border-radius: var(--radius-full); background: var(--accent);
  border: 2px solid var(--on-accent); }
.tp-pick-row input[type=number] { width: 84px; flex: none; }
.tp-pick .help { margin: var(--space-2) 0 0; }

/* Sidebar: the shared term list and the master prompts, under Books */
.tp-nav a.tp-nav-sub { height: 32px; padding-inline-start: 22px; font-size: 0.875rem; }
.tp-nav a.tp-nav-sub .tp-icon { width: 16px; height: 16px; }
@media (max-width: 860px) { .tp-nav a.tp-nav-sub { height: auto; padding-inline-start: 10px; font-size: inherit; } }

/* A book's page: what must be ready before the first AI pass */
.tp-ready ol { margin: var(--space-2) 0 0; padding-inline-start: 20px; display: grid; gap: var(--space-2); }
.tp-ready li { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-3); }
.tp-ready-what { font-weight: 600; min-width: 170px; }
.tp-ready .help { margin: var(--space-3) 0 0; }
.tp-book-cell { min-width: 240px; }

/* Terms: assigning the term check, and the checker's own card */
.tp-assign { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); margin: var(--space-2) 0 0; }
.tp-assign select { width: auto; max-width: 240px; }
.tp-assign input[type=date] { width: auto; }
.tp-termcheck { border-inline-start: 4px solid var(--accent); }
.tp-termcheck p { margin: var(--space-2) 0 0; }
