/*
 * Paginated table of contents of the book page (TOC track): views/book/_toc.php, the #toc block of
 * views/book/index.php, www/js/modules/toc.js. The chapter rows themselves are styled in nb.css (.nb-toc #Chapters).
 * Tokens only (nb.css), sharp radii.
 */

/* ---------- head: read count, latest chapter, chapter search ---------- */
.nb-toc-head { gap: 12px; font-size: 13px; }
.nb-toc-readcount { display: inline-flex; align-items: center; gap: 5px; color: var(--success); font-weight: 550; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nb-toc-readcount[hidden] { display: none; }
.nb-toc-find { position: relative; margin: 0; }
.nb-toc-find input[type="search"] { margin: 0; }
.nb-toc-results {
	position: absolute; z-index: 40; top: calc(100% + 4px); right: 0; width: min(380px, calc(100vw - 32px));
	max-height: 340px; overflow: auto; margin: 0; padding: 4px; list-style: none;
	background: var(--popover); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--elev-3);
}
.nb-toc-results[hidden] { display: none; }
.nb-toc-results li { display: flex; align-items: baseline; gap: 10px; padding: 7px 9px; border-radius: var(--radius); font-size: 13px; line-height: 1.35; color: var(--foreground); cursor: pointer; }
.nb-toc-results li .n { flex: none; min-width: 34px; color: var(--muted-foreground); font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }
.nb-toc-results li .t { min-width: 0; overflow-wrap: anywhere; }
.nb-toc-results li .v { flex: none; margin-left: auto; color: var(--muted-foreground); font-size: 11.5px; white-space: nowrap; }	/* VOLUMES: том найденной главы */
.nb-toc-results li:hover, .nb-toc-results li[aria-selected="true"] { background: var(--muted); }
.nb-toc-results li.empty { color: var(--muted-foreground); cursor: default; }
.nb-toc-results li.empty:hover { background: transparent; }

/* ---------- toolbar: All / Free / Premium · page ranges · oldest / newest ---------- */
.nb-toc-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; margin: 0 0 2px; }
.nb-toc-bar .nb-coins-filter { margin: 0; }
.nb-toc-bar .nb-seg a {
	display: inline-flex; align-items: center; gap: 5px; width: auto; height: 30px; padding: 0 11px;
	color: var(--muted-foreground); font-size: 12.5px; font-weight: 550; white-space: nowrap;
}
.nb-toc-bar .nb-seg a + a { border-left: 1px solid var(--border); }
.nb-toc-bar .nb-seg a:hover { background: var(--muted); color: var(--foreground); text-decoration: none; }
.nb-toc-bar .nb-seg a.on { background: var(--primary); color: var(--primary-foreground); border-color: transparent; }
.nb-toc-bar .nb-seg a small { font-size: 11px; opacity: .75; font-variant-numeric: tabular-nums; }
.nb-toc-bar > .nb-toc-status { order: 1; font-size: 12.5px; }
.nb-toc-jump { order: 2; }
.nb-toc-sort { order: 3; margin-left: auto; }
.nb-toc-ranges { order: 4; flex: 1 1 100%; }

/* equal chips that fill the row; --toc-chip = the longest label in ch (set by _toc.php) */
.nb-toc-ranges { display: grid; grid-template-columns: repeat(auto-fill, minmax(calc(var(--toc-chip, 7ch) + 14px), 1fr)); gap: 4px; font-size: 12px; }
.nb-toc-ranges a {
	display: inline-flex; align-items: center; justify-content: center; height: 28px; padding: 0 6px; box-sizing: border-box;
	border: 1px solid var(--border); border-radius: var(--radius); background: var(--card-solid);
	color: var(--muted-foreground); font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap;
}
.nb-toc-ranges a:hover { color: var(--foreground); border-color: var(--input); text-decoration: none; }
.nb-toc-ranges a.on { background: var(--primary); color: var(--primary-foreground); border-color: transparent; }

.nb-toc-jump { display: inline-flex; align-items: center; gap: 6px; margin: 0; }
.nb-toc-jump select { width: auto; max-width: 100%; height: 30px; margin: 0; padding: 0 8px; font-size: 13px; font-variant-numeric: tabular-nums; }
.nb-toc-bar.has-chips .nb-toc-jump { display: none; }
.nb-toc-section.is-js [data-toc-nojs] { display: none; }

/* the #Chapters anchor leaves the toolbar above it in view (sticky header ≈ 126px + toolbar) */
.nb-toc-section #Chapters { scroll-margin-top: 176px; }
/* no-JS search / found links land on #c_<id>: keep the row clear of the sticky header, with rows above it for context */
.nb-toc-section #Chapters tr:target { scroll-margin-top: 30vh; }

/* ---------- rows: read checkmarks, found chapter ---------- */
.nb-toc #Chapters tr.is-read td.t .ttl > a { color: var(--muted-foreground); font-weight: 500; }
.nb-toc #Chapters tr.is-read td.t .ttl > a:hover { color: var(--link); }
.nb-toc #Chapters tr.is-read td.t .num { background: color-mix(in oklab, var(--success) 14%, transparent); color: var(--success); }
.nb-toc #Chapters tr.is-found td { background: color-mix(in oklab, var(--warning) 13%, var(--card)); border-color: color-mix(in oklab, var(--warning) 50%, transparent); }
.nb-toc #Chapters tr.is-found.is-flash td { animation: nb-toc-flash 1.6s ease-out; }
@keyframes nb-toc-flash { 0%, 30% { background: color-mix(in oklab, var(--warning) 32%, var(--card)); } }

/* a long title wraps under itself, not under the number chip (phones get the same from nb.css) */
.nb-toc #Chapters td.t .num { float: left; }
.nb-toc #Chapters td.t .ttl { display: flow-root; padding-top: 3px; line-height: 1.35; }

.nb-toc-tick {
	display: inline-grid; place-items: center; width: 28px; height: 28px; margin: 0 0 0 6px; padding: 0; vertical-align: middle;
	border: 1px solid var(--border); border-radius: var(--radius); background: transparent; color: var(--muted-foreground); cursor: pointer;
}
.nb-toc-tick:hover { color: var(--foreground); border-color: var(--input); }
.nb-toc-tick.on { color: var(--success); background: color-mix(in oklab, var(--success) 10%, transparent); border-color: color-mix(in oklab, var(--success) 45%, transparent); }
.nb-toc-tick[disabled] { opacity: .5; cursor: progress; }

.nb-toc-none { margin: 4px 0 0; font-size: 13.5px; }

/* ---------- no-JS search results (?toc_find=) ---------- */
.nb-toc-found { margin: 6px 0 4px; padding: 10px 14px; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--card); font-size: 13.5px; }
.nb-toc-found p { margin: 0; }
.nb-toc-found ol { display: grid; gap: 2px; margin: 8px 0 0; padding: 0; list-style: none; }
.nb-toc-found ol a { display: flex; gap: 10px; padding: 4px 0; color: var(--foreground); }
.nb-toc-found ol .n { min-width: 34px; color: var(--muted-foreground); font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }

/* ---------- pager ---------- */
.nb-toc-pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 4px 0 0; }
.nb-toc-pager .nb-btn { gap: 4px; }
.nb-toc-pager .is-disabled { opacity: .45; pointer-events: none; }
.nb-toc-status { color: var(--muted-foreground); font-size: 13px; font-variant-numeric: tabular-nums; text-align: center; }

/* ---------- AJAX loading ---------- */
.nb-toc-body { position: relative; outline: none; scroll-margin-top: 136px; }
.nb-toc-body.is-loading { cursor: progress; }
.nb-toc-body.is-loading .nb-toc, .nb-toc-body.is-loading .nb-toc-pager { opacity: .5; transition: opacity .15s; }
.nb-toc-body.is-loading::before {
	content: ""; position: absolute; left: 0; right: 0; top: -6px; height: 2px;
	background: linear-gradient(90deg, transparent, var(--primary), transparent); background-size: 40% 100%; background-repeat: no-repeat;
	animation: nb-toc-load 1s linear infinite;
}
@keyframes nb-toc-load { from { background-position: -40% 0; } to { background-position: 140% 0; } }
/* while CE.js reorders the chapters of a page, leaving the page would drop the new order */
.nb-toc-section.is-reordering .nb-toc-bar, .nb-toc-section.is-reordering .nb-toc-pager, .nb-toc-section.is-reordering .nb-toc-find { display: none; }

/* ---------- phones: a select instead of range chips ---------- */
@media (max-width: 760px) {
	.nb-toc-section .nb-section-head { flex-wrap: wrap; }
	.nb-toc-head { flex: 1 1 100%; }
	.nb-toc-find { flex: 1 1 100%; }
	.nb-toc-results { left: 0; right: 0; width: auto; }
	.nb-toc-bar { gap: 8px; }
	.nb-toc-bar.has-chips .nb-toc-ranges { display: none; }
	.nb-toc-bar.has-chips .nb-toc-jump { display: flex; }
	.nb-toc-jump { flex: 1 1 100%; order: -1; }
	.nb-toc-bar.has-pages > .nb-toc-status { display: none; }
	.nb-toc-jump select { flex: 1 1 auto; min-width: 0; height: 38px; }
	.nb-toc-bar .nb-seg { flex: 1 1 100%; margin-left: 0; }
	.nb-toc-bar .nb-seg a { flex: 1 1 0; justify-content: center; height: 36px; }
	.nb-toc-section #Chapters { scroll-margin-top: 200px; }
	.nb-toc-body { scroll-margin-top: 112px; }
	.nb-toc-tick { width: 34px; height: 34px; }
	.nb-toc-pager .nb-btn { height: 36px; }
	.nb-toc-status .pg { display: none; }
}
@media (prefers-reduced-motion: reduce) {
	.nb-toc #Chapters tr.is-found.is-flash td, .nb-toc-body.is-loading::before { animation: none; }
}

/* ---------- touch screens: 36-40 px targets in the chapter list and around it ---------- */
@media (max-width: 760px), (pointer: coarse) {
	.nb-toc-head > a { display: inline-flex; align-items: center; min-height: 36px; }
	.nb-toc-results li { min-height: 40px; align-items: center; box-sizing: border-box; }
	.nb-toc #Chapters td.act-cell .nb-btn-sm { height: 36px; }
	.nb-toc-tick { width: 36px; height: 36px; }
	.nb-toc-pager .nb-btn { height: 40px; }
	.nb-toc-bar .nb-seg a { min-height: 36px; }
	.nb-toc-ranges a { height: 36px; }
}

/* ======================================================================================================================
 * Строки в одну строку (просьба владельца: окна глав и томов ниже, в одну строку) — views/book/_toc_rows.php.
 * Широкое оглавление (контейнер nb-toc от 560 px): [галочка] номер · название «…» · сводка · дата · статус · читать · ✎,
 * высота строки ≈ 40 px. Узкое (телефон): не больше двух строк — номер и название, под ними сводка с датой и статусом.
 * Прогресса по фрагментам нет: у главы один фрагмент, готовность — это статус перевода (колонка «Статус», команде).
 * Префикс .nb-novel .nb-toc-section — сильнее старых правил nb.css / book-page.css для тех же ячеек.
 * ==================================================================================================================== */
.nb-novel .nb-toc-section .nb-toc #Chapters { border-spacing: 0 4px; }
.nb-novel .nb-toc-section .nb-toc #Chapters thead th { padding: 0 8px 1px; font-size: 10.5px; white-space: nowrap; }
.nb-novel .nb-toc-section .nb-toc #Chapters tbody td { height: 40px; box-sizing: border-box; padding: 4px 8px; vertical-align: middle; }
.nb-novel .nb-toc-section .nb-toc #Chapters tbody td:first-child { padding-left: 10px; }
.nb-novel .nb-toc-section .nb-toc #Chapters tbody td:last-child { padding-right: 10px; }
.nb-novel .nb-toc-section .nb-toc #Chapters td.t .tl { display: flex; align-items: center; gap: 8px; min-width: 0; }
.nb-novel .nb-toc-section .nb-toc #Chapters td.t .num { float: none; flex: none; min-width: 24px; height: 22px; margin: 0; padding: 0 3px; box-sizing: border-box; font-size: 11.5px; }
.nb-novel .nb-toc-section .nb-toc #Chapters td.t .ttl { display: block; flex: 1 1 0; min-width: 5em; padding: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; line-height: 1.35; }
.nb-novel .nb-toc-section .nb-toc #Chapters td.t .ttl a { overflow-wrap: normal; font-size: 13.5px; }
.nb-novel .nb-toc-section .nb-toc #Chapters .nb-toc-sub { flex: 0 0 auto; flex-wrap: nowrap; gap: 4px; max-width: 55%; margin: 0; min-width: 0; overflow: hidden; }
.nb-novel .nb-toc-section .nb-toc #Chapters .nb-toc-sub > * { flex: none; }
.nb-novel .nb-toc-section .nb-toc #Chapters .nb-toc-sub .nb-cchip { height: 20px; padding: 0 6px; font-size: 11.5px; }
.nb-novel .nb-toc-section .nb-toc #Chapters .nb-toc-sub .nb-chip { font-size: 11px; padding: 0 6px; line-height: 18px; }
.nb-novel .nb-toc-section .nb-toc #Chapters .nb-toc-m { display: none; }
.nb-novel .nb-toc-section .nb-toc #Chapters td.dat { width: 50px; text-align: right; font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nb-novel .nb-toc-section .nb-toc #Chapters td.dat.is-plan { color: var(--link); }
.nb-novel .nb-toc-section .nb-toc #Chapters td.st { width: 68px; white-space: nowrap; }
.nb-novel .nb-toc-section .nb-toc #Chapters td.act-cell { width: 88px; text-align: right; white-space: nowrap; }
.nb-novel .nb-toc-section .nb-toc #Chapters td.act-cell .nb-btn-sm { height: 28px; padding: 0 8px; font-size: 12.5px; }
.nb-novel .nb-toc-section .nb-toc #Chapters td.act-cell.empty .nb-btn-sm { padding: 0 8px; }
.nb-novel .nb-toc-section .nb-toc #Chapters .nb-toc-tick { width: 28px; height: 28px; margin-left: 4px; }
.nb-novel .nb-toc-section .nb-toc #Chapters td.e { width: 14px; text-align: center; }
.nb-novel .nb-toc-section .nb-toc #Chapters td.pk, .nb-novel .nb-toc-section .nb-toc #Chapters th.pk { width: 18px; padding-right: 0; text-align: center; }
.nb-novel .nb-toc-section .nb-toc #Chapters td.pk input, .nb-novel .nb-toc-section .nb-toc #Chapters th.pk input { width: 16px; height: 16px; margin: 0; vertical-align: middle; cursor: pointer; accent-color: var(--primary); }
.nb-novel .nb-toc-section .nb-toc #Chapters tr.is-picked td { background: color-mix(in oklab, var(--link) 9%, var(--card)); border-color: color-mix(in oklab, var(--link) 35%, transparent); }
/* плоский список: ширины колонок по шапке (у блоков томов — colgroup, volumes.css) */
.nb-novel .nb-toc-section .nb-toc table#Chapters.nb-toc-table { table-layout: fixed; }
.nb-novel .nb-toc-section .nb-toc table#Chapters.nb-toc-table th.dat { width: 50px; text-align: right; }
.nb-novel .nb-toc-section .nb-toc table#Chapters.nb-toc-table th.st { width: 68px; }
.nb-novel .nb-toc-section .nb-toc table#Chapters.nb-toc-table th.act { width: 88px; }
.nb-novel .nb-toc-section .nb-toc table#Chapters.nb-toc-table th.e { width: 14px; }
.nb-novel .nb-toc-section .nb-toc table#Chapters.nb-toc-table th.pk { width: 18px; }

/* узкое оглавление (телефон, узкая колонка): две строки — номер и название, под ними сводка + дата и статус */
@container nb-toc (max-width: 559px) {
	.nb-novel .nb-toc-section .nb-toc #Chapters thead { display: none; }
	.nb-novel .nb-toc-section .nb-toc #Chapters tbody td { height: auto; padding: 6px 5px; }
	.nb-novel .nb-toc-section .nb-toc #Chapters tbody td:first-child { padding-left: 8px; }
	.nb-novel .nb-toc-section .nb-toc #Chapters tbody td:last-child { padding-right: 8px; }
	.nb-novel .nb-toc-section .nb-toc #Chapters td.t .tl { flex-wrap: wrap; row-gap: 3px; column-gap: 7px; }
	.nb-novel .nb-toc-section .nb-toc #Chapters td.t .ttl { flex: 1 1 0; min-width: 0; }
	.nb-novel .nb-toc-section .nb-toc #Chapters .nb-toc-sub { flex: 1 1 100%; flex-wrap: nowrap; padding-left: 31px; overflow: hidden; }
	.nb-novel .nb-toc-section .nb-toc #Chapters .nb-toc-m { display: inline-flex; align-items: center; gap: 8px; order: -1; font-size: 11.5px; color: var(--muted-foreground); font-variant-numeric: tabular-nums; }
	.nb-novel .nb-toc-section .nb-toc #Chapters .nb-toc-m:empty { display: none; }
	.nb-novel .nb-toc-section .nb-toc #Chapters .nb-toc-m .nb-tstatus { font-size: 11.5px; }
	/* колонки даты и статуса — нулевой ширины, а не display: none: иначе ячейки сдвинулись бы в чужие колонки (colgroup томов) */
	.nb-novel .nb-toc-section .nb-toc #Chapters td.dat,
	.nb-novel .nb-toc-section .nb-toc #Chapters td.st { display: table-cell; width: 0; max-width: 0; padding: 0 !important; overflow: hidden; font-size: 0; }
	.nb-novel .nb-toc-section .nb-toc #Chapters td.dat > *, .nb-novel .nb-toc-section .nb-toc #Chapters td.st > * { display: none; }
	/* ширины первой строки задают колонки плоского списка (шапка скрыта); у ячеек tbody — border-box */
	.nb-novel .nb-toc-section .nb-toc #Chapters td.act-cell { width: 106px; }
	.nb-novel .nb-toc-section .nb-toc #Chapters td.pk { width: 26px; vertical-align: top; padding-top: 10px; }
	.nb-novel .nb-toc-section .nb-toc #Chapters td.e { width: 28px; }
	.nb-novel .nb-toc-section .nb-toc #Chapters .nb-toc-sub { flex: 1 1 100%; max-width: none; }
	.nb-novel .nb-toc-section .nb-toc #Chapters td.act-cell .nb-btn-sm { padding: 0 9px; }
}

/* ---------- панель массовых действий (views/book/_toc_bulk.php, www/js/modules/toc-bulk.js) ---------- */
.nb-bulk {
	position: sticky; bottom: 8px; z-index: 30; display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; margin: 8px 0 0; padding: 8px 10px; box-sizing: border-box;
	border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--popover); box-shadow: var(--elev-3);
}
.nb-bulk.is-js:not(.is-on) { display: none; }
.nb-bulk-head { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; min-width: 0; }
.nb-bulk-head .n { min-width: 0; font-size: 13px; font-weight: 650; font-variant-numeric: tabular-nums; }
.nb-bulk:not(.is-on) .nb-bulk-head .n { font-weight: 500; color: var(--muted-foreground); }
.nb-bulk-head .sp { flex: 1; }
.nb-bulk-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; }
.nb-bulk select, .nb-bulk input[type=number], .nb-bulk input[type=datetime-local] { width: auto; min-width: 0; max-width: 100%; height: 32px; margin: 0; padding: 0 8px; font-size: 13px; box-sizing: border-box; }
.nb-bulk select[data-bulk-op] { max-width: 260px; }
.nb-bulk select[name=volume_id] { max-width: 240px; }
.nb-bulk input[type=number] { width: 84px; }
.nb-bulk-f { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 6px; min-width: 0; max-width: 100%; font-size: 13px; }
.nb-bulk-f .tz { color: var(--muted-foreground); font-size: 12px; font-weight: 600; }
.nb-bulk-f .loc { flex: 1 1 100%; color: var(--muted-foreground); font-size: 12px; }
.nb-bulk-f .loc:empty { display: none; }
.nb-bulk-note { color: var(--muted-foreground); font-size: 12.5px; }
.nb-bulk-del { color: var(--destructive); font-weight: 550; cursor: pointer; }
.nb-bulk-del input { margin: 0; }
.nb-bulk [data-bulk-go] { margin-left: auto; }
/* поля выбранного действия (без JS тоже — :has); браузер без :has показывает все поля */
@supports selector(:has(*)) {
	.nb-bulk [data-when] { display: none; }
	.nb-bulk:has(select[data-bulk-op] option[value="at"]:checked) [data-when="at"],
	.nb-bulk:has(select[data-bulk-op] option[value="queue"]:checked) [data-when="queue"],
	.nb-bulk:has(select[data-bulk-op] option[value="price"]:checked) [data-when="price"],
	.nb-bulk:has(select[data-bulk-op] option[value="volume"]:checked) [data-when="volume"],
	.nb-bulk:has(select[data-bulk-op] option[value="status"]:checked) [data-when="status"],
	.nb-bulk:has(select[data-bulk-op] option[value="delete"]:checked) [data-when="delete"] { display: inline-flex; }
	.nb-bulk .nb-bulk-freeat { display: none; }
	.nb-bulk:has(select[name=free_mode] option[value="date"]:checked) .nb-bulk-freeat { display: inline-flex; align-items: center; gap: 6px; }
	.nb-bulk:has(select[data-bulk-op] option[value="delete"]:checked) [data-bulk-go] { background: var(--destructive); border-color: var(--destructive); color: var(--primary-foreground); }
}
@media (max-width: 860px) {
	.nb-bulk.is-js {
		position: fixed; left: 0; right: 0; bottom: calc(56px + env(safe-area-inset-bottom)); margin: 0; border-radius: 0; border-width: 1px 0 0;
		padding: 8px 12px; max-height: 60vh; overflow: auto;
	}
	.nb-bulk select, .nb-bulk input[type=number], .nb-bulk input[type=datetime-local] { height: 40px; }
	.nb-bulk select[data-bulk-op] { flex: 1 1 100%; max-width: none; }
	.nb-bulk [data-bulk-go] { min-height: 40px; flex: 1 1 auto; }
	body.nb-has-bulk #nb-toasts { bottom: 170px !important; }
}
body.nb-has-bulk #nb-toasts { bottom: 150px !important; }
