/* Тема кабинета (B9) — направление A «Родная полка», выбранное пользователем: каркас как у самого Telegram (цвета темы,
   системный шрифт, сгруппированные списки, вкладки внизу), книжность — в обложках и названиях книг (Literata).
   Токены — поверх слоя Telegram --t-* из core.css. Правила и компоненты — docs/B9/design_system.md. */

html { background: var(--t-secondary-bg); }
body {
  --page: var(--t-secondary-bg);
  --header-key: secondary_bg_color;              /* шапка и фон Telegram = фон страницы */
  --surface: var(--t-section-bg);
  --text: var(--t-text);
  --text-2: var(--t-subtitle);
  --hint: var(--t-hint);
  --sep: var(--t-separator);
  --group-head: var(--t-section-header);
  --accent: var(--t-button);
  --accent-text: var(--t-accent-text);
  --on-accent: var(--t-button-text);
  --danger: var(--t-destructive);
  --fill: rgba(118, 118, 128, .12);              /* заливки iOS: поиск, сегменты, чипы */
  --fill-2: rgba(118, 118, 128, .22);
  --seg-on: var(--t-section-bg);
  --pressed: rgba(118, 118, 128, .16);
  --ok: #34c759;
  --warn: #ff9500;
  --font-ui: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-book: "Literata", "Iowan Old Style", Georgia, serif;
  --r-cover: 3px;
  --r-tile: 7px;
  --r-control: 10px;
  --r-group: 12px;
  --r-btn: 12px;
  --r-sheet: 14px;
  --dur-1: 120ms;
  --dur-2: 200ms;
  --dur-3: 320ms;
  --focus: var(--accent);
  font: 400 17px/1.3 var(--font-ui);
  color: var(--text);
  background: var(--page);
}
:root[data-scheme="dark"] body {
  --fill: rgba(118, 118, 128, .24);
  --fill-2: rgba(118, 118, 128, .36);
  --seg-on: #636366;
  --pressed: rgba(255, 255, 255, .08);
  --ok: #30d158;
  --warn: #ff9f0a;
}
.book-font { font-family: var(--font-book); }

/* ---------- заголовки экранов ---------- */
.large-title { padding: 8px 16px 14px; }
.large-title h1 { font: 650 32px/1.12 var(--font-book); letter-spacing: -.012em; text-wrap: balance; }
.large-title-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.lead { padding: 0 16px 16px; color: var(--text-2); font-size: 15px; line-height: 1.4; max-width: 60ch; }
.icon-btn { display: grid; place-items: center; width: 36px; height: 36px; border: 0; border-radius: 50%;
  background: var(--fill); color: var(--accent-text); }
.icon-btn .i { width: 20px; height: 20px; stroke-width: 2; }
.link { color: var(--accent-text); font-size: 15px; }

/* ---------- группы и ячейки (как в настройках Telegram) ---------- */
.group { margin: 0 0 30px; }
.group-header { display: block; padding: 0 32px 7px; font-size: 13px; line-height: 1.3; font-weight: 400;
  color: var(--group-head); }
.group-header-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  padding: 0 16px 8px 32px; }
.group-header-row .group-header { padding: 0; }
.group-footer { padding: 7px 32px 0; font-size: 13px; line-height: 1.35; color: var(--hint); }
.group-note { padding: 0 32px 12px; font-size: 13px; line-height: 1.35; color: var(--hint); }
.section { margin: 0 16px; overflow: hidden; border-radius: var(--r-group); background: var(--surface); }
.section-text { padding: 12px 16px; }

.cell { --sep-inset: 16px; position: relative; display: flex; align-items: center; gap: 12px; min-height: 44px;
  padding: 10px 16px; color: var(--text); background: var(--surface); transition: background var(--dur-1) ease; }
.cell + .cell::before { content: ""; position: absolute; top: 0; right: 0; left: var(--sep-inset); height: 1px;
  background: var(--sep); transform: scaleY(.5); transform-origin: top; }
.cell:has(> .tile) { --sep-inset: 58px; }
.cell:has(> .cell-cover) { --sep-inset: 72px; }
a.cell:active, label.cell:active { background: var(--pressed); }
.cell-body { display: flex; flex: 1; flex-direction: column; gap: 2px; min-width: 0; }
.cell-title { font-size: 17px; line-height: 22px; }
.cell-sub { font-size: 15px; line-height: 20px; color: var(--text-2); }
.cell-help { font-size: 13px; line-height: 18px; color: var(--hint); }
.cell-meta { display: flex; gap: 6px; align-items: center; margin-top: 2px; font-size: 13px; color: var(--hint); }
.cell-value { flex: none; max-width: 48%; font-size: 17px; color: var(--hint); text-align: right; }
.cell-value.is-changed { color: var(--accent-text); }
.cell-value-top { align-self: flex-start; padding-top: 1px; font-size: 15px; }
.cell-tall { align-items: flex-start; padding-top: 12px; padding-bottom: 12px; }
.cell-action { color: var(--accent-text); }
.cell-danger { color: var(--danger); }
.cell-muted .cell-title { color: var(--hint); }
.chevron { width: 18px; height: 18px; margin-right: -4px; color: var(--hint); opacity: .55; stroke-width: 2.4; }
.check { width: 22px; height: 22px; color: var(--accent-text); stroke-width: 2.4; }
.cell-cover { flex: none; width: 44px; }
.cell-book .cell-title { font-size: 16px; font-weight: 600; line-height: 21px; }
.ch-num { flex: none; width: 22px; font-size: 15px; color: var(--hint); text-align: right;
  font-variant-numeric: tabular-nums; }

/* плитки-иконки, как в настройках Telegram */
.tile { display: grid; flex: none; place-items: center; width: 30px; height: 30px; border-radius: var(--r-tile);
  color: #fff; }
.tile .i { width: 19px; height: 19px; stroke-width: 2; }
.tile-blue { background: #007aff; }
.tile-green { background: #34c759; }
.tile-orange { background: #ff9500; }
.tile-violet { background: #af52de; }
.tile-grey { background: #8e8e93; }
.tile-teal { background: #30b0c7; }
.tile-pink { background: #ff2d55; }

/* аватары диалогов — палитра аватаров Telegram */
.avatar { display: grid; flex: none; place-items: center; width: 54px; height: 54px; border-radius: 50%;
  color: #fff; font: 600 22px/1 var(--font-ui); text-transform: uppercase; }
.av-0 { background: linear-gradient(#ff885e, #ff516a); }
.av-1 { background: linear-gradient(#ffcd6a, #ffa85c); }
.av-2 { background: linear-gradient(#82b1ff, #665fff); }
.av-3 { background: linear-gradient(#a0de7e, #54cb68); }
.av-4 { background: linear-gradient(#53edd6, #28c9b7); }
.av-5 { background: linear-gradient(#72d5fd, #2a9ef1); }
.av-6 { background: linear-gradient(#e0a2f3, #d669ed); }

/* ---------- поиск, сегменты, чипы, переключатель ---------- */
.search-wrap { padding: 0 16px 18px; }
.search { display: flex; align-items: center; gap: 6px; height: 36px; padding: 0 8px;
  border-radius: var(--r-control); background: var(--fill); color: var(--hint); }
.search .i { width: 18px; height: 18px; stroke-width: 2.2; }
.search input { flex: 1; min-width: 0; height: 100%; border: 0; outline: none; background: transparent;
  font-size: 17px; color: var(--text); -webkit-appearance: none; appearance: none; }
.search input::placeholder { color: var(--hint); }
.search:focus-within { outline: 2px solid var(--focus); outline-offset: 1px; }

.seg-wrap { padding: 0 16px 18px; }
.seg { display: flex; padding: 2px; border-radius: 9px; background: var(--fill); }
.seg a { display: flex; flex: 1; align-items: center; justify-content: center; gap: 4px; height: 28px;
  border-radius: 7px; font-size: 13px; font-weight: 500; color: var(--text); white-space: nowrap;
  transition: background var(--dur-2) ease; }
.seg a.on { background: var(--seg-on); font-weight: 600;
  box-shadow: 0 3px 8px rgba(0, 0, 0, .12), 0 3px 1px rgba(0, 0, 0, .04); }
.seg-sm { width: 84px; }
.seg-sm a { height: 26px; }
.seg-sm .i { width: 16px; height: 16px; }

.chips { display: flex; gap: 8px; padding: 0 16px 18px; }
.chip { display: inline-flex; align-items: center; height: 32px; padding: 0 14px; border: 0; border-radius: 16px;
  background: var(--fill); color: var(--text); font-size: 15px; white-space: nowrap; }
.chip.on { background: var(--accent); color: var(--on-accent); }

.switch { position: relative; flex: none; width: 51px; height: 31px; margin: 0; border-radius: 16px;
  background: var(--fill-2); cursor: pointer; transition: background var(--dur-2) ease;
  -webkit-appearance: none; appearance: none; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%;
  background: #fff; box-shadow: 0 3px 8px rgba(0, 0, 0, .15), 0 3px 1px rgba(0, 0, 0, .06);
  transition: transform var(--dur-2) cubic-bezier(.3, .7, .4, 1); }
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(20px); }
.switch:disabled { opacity: .45; cursor: default; }

/* ---------- статусы и прогресс ---------- */
.status { display: inline-flex; align-items: center; height: 20px; padding: 0 7px; border-radius: 10px;
  background: #8e8e93; color: #fff; font-size: 12px; font-weight: 600; line-height: 1; white-space: nowrap; }
.status-queued, .status-parsing, .status-indexing { background: #ff9500; }
.status-awaiting_confirm { background: var(--accent); color: var(--on-accent); }
.status-index_stale, .status-index_partial { background: #a2845e; }
.status-failed, .status-index_failed { background: #ff3b30; }
.status-trial { background: #5856d6; }
.status-row { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 16px 18px; }
.progress-demo { padding: 0 16px; }
.progress-label { display: block; margin-bottom: 7px; font-size: 13px; color: var(--hint); }
.progress { height: 4px; overflow: hidden; border-radius: 2px; background: var(--fill-2); }
.progress span { display: block; height: 100%; border-radius: 2px; background: var(--accent); }

/* ---------- кнопки ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 50px; padding: 0 20px;
  border: 0; border-radius: var(--r-btn); background: transparent; color: var(--accent-text); font: 600 17px/1 var(--font-ui);
  transition: opacity var(--dur-1) ease; }
.btn:active { opacity: .65; }
.btn .i { width: 20px; height: 20px; stroke-width: 2; }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-secondary { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.btn-danger { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
.actions-col { display: flex; flex-direction: column; gap: 10px; padding: 0 16px; }
.actions-row { display: flex; gap: 10px; padding: 14px 16px 0; }
.actions-row .btn { height: 44px; }

/* ---------- обложки ---------- */
.cover { border-radius: var(--r-cover); background: var(--cover-color, var(--fill));
  box-shadow: 0 1px 1.5px rgba(0, 0, 0, .14), 0 7px 16px -7px rgba(0, 0, 0, .38); }
.cover::after { content: ""; position: absolute; inset: 0; pointer-events: none; border-radius: inherit;
  /* корешок: тень переплёта и блик у левого края */
  background: linear-gradient(90deg, rgba(0, 0, 0, .16) 0, rgba(255, 255, 255, .18) 1.4%, rgba(255, 255, 255, 0) 3.4%,
                              rgba(0, 0, 0, .07) 4.4%, rgba(0, 0, 0, 0) 7.5%);
  box-shadow: inset 0 0 0 .5px rgba(0, 0, 0, .14); }
/* сгенерированная: цвета аватаров Telegram, название — Literata */
.cover.gen { color: #fff; }
.gen-0 { background: linear-gradient(170deg, #ff885e, #ff516a); }
.gen-1 { background: linear-gradient(170deg, #ffb35c, #f5864a); }
.gen-2 { background: linear-gradient(170deg, #82b1ff, #665fff); }
.gen-3 { background: linear-gradient(170deg, #7fcf6a, #3fae5a); }
.gen-4 { background: linear-gradient(170deg, #45d5c2, #1faf9f); }
.gen-5 { background: linear-gradient(170deg, #5cc6f5, #2a8fe0); }
.gen-face { position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: space-between;
  padding: 12cqw 10cqw 10cqw 14cqw; }
.gen-title { display: -webkit-box; overflow: hidden; -webkit-line-clamp: 5; -webkit-box-orient: vertical;
  font: 650 13cqw/1.12 var(--font-book); letter-spacing: -.01em; overflow-wrap: break-word; -webkit-hyphens: auto;
  hyphens: auto; }
.gen-author { font: 500 8cqw/1.2 var(--font-ui); opacity: .85; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; }

/* ---------- полка ---------- */
.shelf { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 24px 16px; padding: 4px 16px 0; }
.shelf-book { display: flex; flex-direction: column; min-width: 0; }
.shelf-cover { position: relative; display: flex; align-items: flex-end; aspect-ratio: 2 / 3; }
.shelf-cover .cover { width: 100%; transition: transform var(--dur-2) ease; }
.shelf-cover .status { position: absolute; left: 6px; bottom: 6px; }
.shelf-book:active .cover, .strip-book:active .cover { transform: scale(.96); }
.shelf-title { margin-top: 9px; font-size: 14px; font-weight: 600; line-height: 1.25; }
.shelf-author { margin-top: 2px; font-size: 12.5px; color: var(--hint); }
.strip { align-items: flex-end; gap: 14px; padding: 2px 16px 8px; scroll-padding-left: 16px; }
.strip-book { display: flex; flex-direction: column; width: 92px; }
.strip-book .cover { width: 100%; transition: transform var(--dur-2) ease; }
.strip-title { margin-top: 7px; font-size: 12px; color: var(--text-2); }

/* коллекции — плитки с мозаикой обложек */
.tiles { gap: 12px; padding: 0 16px 4px; scroll-padding-left: 16px; }
.tile-col { display: flex; flex-direction: column; width: 128px; }
.mosaic { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; padding: 8px; border-radius: var(--r-group);
  background: var(--surface); }
.mosaic .cover { aspect-ratio: 3 / 4; border-radius: 2px; box-shadow: 0 1px 2px rgba(0, 0, 0, .22); }
.mosaic .cover img { object-position: top; }
.mosaic .cover::after { background: none; }
.mosaic .gen-face { padding: 8cqw; }
.mosaic .gen-author { display: none; }
.mosaic-empty { aspect-ratio: 3 / 4; border-radius: 2px; background: var(--fill); }
.tile-col-name { margin-top: 8px; font-size: 15px; font-weight: 500; }
.tile-col-count { font-size: 13px; color: var(--hint); }
.tile-col:active .mosaic { opacity: .8; }

.col-head { display: flex; flex-direction: column; align-items: center; padding: 10px 24px 26px; text-align: center; }
.mosaic-lg { width: 176px; box-shadow: 0 10px 30px -14px rgba(0, 0, 0, .35); }
.col-title { margin-top: 18px; font: 650 26px/1.2 var(--font-book); text-wrap: balance; }
.col-count { margin-top: 5px; font-size: 15px; color: var(--hint); }

/* ---------- страница книги: поле цвета обложки ---------- */
.screen-book .screen { padding-top: 0; }
.hero { --hero: var(--surface); margin-bottom: 26px; padding: calc(var(--safe-top) + 30px) 24px 28px;
  background: var(--hero); color: #1c1c1e; text-align: center; }
.hero-dark { color: #fff; }
.hero-cover { width: min(52vw, 210px); margin: 0 auto 22px; }
.hero-cover .cover { box-shadow: 0 2px 4px rgba(0, 0, 0, .22), 0 22px 40px -14px rgba(0, 0, 0, .55); }
.hero-title { max-width: 26ch; margin: 0 auto; font-size: 24px; font-weight: 650; line-height: 1.2; text-wrap: balance; }
.hero-author { margin-top: 6px; font-size: 15px; opacity: .72; }
.hero-status { display: inline-flex; align-items: center; gap: 5px; margin-top: 14px; padding: 5px 11px 5px 8px;
  border-radius: 14px; background: rgba(255, 255, 255, .42); font-size: 13px; font-weight: 600; }
.hero-dark .hero-status { background: rgba(0, 0, 0, .22); }
.hero-status .i { width: 15px; height: 15px; stroke-width: 2.6; }
.thesis { font-family: var(--font-book); font-size: 17px; line-height: 1.55; }
.ideas li { position: relative; padding: 10px 0 10px 18px; font-size: 16px; line-height: 1.42; }
.ideas li + li { border-top: .5px solid var(--sep); }
.ideas li::before { content: ""; position: absolute; left: 2px; top: 19px; width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent); }

/* ---------- диалоги: как список чатов ---------- */
.chat { --sep-inset: 82px; align-items: flex-start; gap: 12px; padding: 9px 16px 10px 12px; }
.chat-cover { flex: none; width: 40px; margin: 2px 7px 0; }
.chat-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.chat-top .cell-title { font-size: 16px; font-weight: 600; line-height: 21px; }
.chat-when { flex: none; font-size: 14px; color: var(--hint); }
.chat .cell-sub { font-size: 15px; color: var(--hint); }
.chat-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.tag { padding: 2px 7px; border-radius: 6px; background: color-mix(in srgb, var(--accent) 14%, transparent);
  color: var(--accent-text); font-size: 12px; font-weight: 500; line-height: 16px; }
.tag-plain { background: var(--fill); color: var(--text-2); }
.tag-accent { background: var(--accent); color: var(--on-accent); }

/* ---------- память ---------- */
.cell-memory { align-items: flex-start; padding-top: 12px; padding-bottom: 12px; }
.cell-memory .cell-title { font-size: 16px; line-height: 1.4; }
.is-old { color: var(--hint); text-decoration: line-through; }

/* ---------- пустые состояния, загрузка ---------- */
.empty { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 40px 32px; text-align: center; }
.empty-boxed { margin: 0 16px; border-radius: var(--r-group); background: var(--surface); }
.empty-icon { width: 44px; height: 44px; margin-bottom: 4px; color: var(--hint); stroke-width: 1.4; }
.empty-title { font-size: 17px; font-weight: 600; }
.empty-text { max-width: 32ch; font-size: 15px; line-height: 1.4; color: var(--hint); }
.empty .btn { height: 44px; margin-top: 8px; }
.empty-inline { padding: 24px 32px; color: var(--hint); text-align: center; }
.skeleton { position: relative; display: block; overflow: hidden; border-radius: 4px; background: var(--fill); }
.skeleton::after { content: ""; position: absolute; inset: 0; transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .45), transparent); animation: a-shimmer 1.4s infinite; }
:root[data-scheme="dark"] .skeleton::after { background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .07), transparent); }
@keyframes a-shimmer { to { transform: translateX(100%); } }
.sk-cover { aspect-ratio: 2 / 3; border-radius: var(--r-cover); }
.sk-line { height: 12px; margin-top: 9px; }
.sk-short { width: 60%; margin-top: 6px; }

/* ---------- настройки: свёрнутая группа ---------- */
.group-details > summary { display: flex; align-items: center; gap: 8px; cursor: pointer; list-style: none; }
.group-details > summary::-webkit-details-marker { display: none; }
.group-details > summary::after { content: ""; width: 7px; height: 7px; margin-top: -3px;
  border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; transform: rotate(45deg);
  transition: transform var(--dur-2) ease; }
.group-details[open] > summary::after { margin-top: 2px; transform: rotate(-135deg); }
.group-details[open] > summary { padding-bottom: 7px; }

/* ---------- таб-бар, тост, шторка ---------- */
.tabbar { border-top: .5px solid var(--sep);
  background: color-mix(in srgb, var(--t-bottom-bar-bg) 86%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px); }
.tabbar a { color: var(--hint); font-size: 10px; font-weight: 500; letter-spacing: .01em; }
.tabbar a.on { color: var(--accent-text); }
.tabbar .i { width: 27px; height: 27px; stroke-width: 1.6; }
.tabbar a.on .i { stroke-width: 2; }
.toast { padding: 12px 16px; border-radius: 13px; background: rgba(28, 28, 30, .92); color: #fff; font-size: 15px;
  line-height: 1.35; box-shadow: 0 8px 24px rgba(0, 0, 0, .25); }
.sheet { padding-top: 6px; border-radius: var(--r-sheet) var(--r-sheet) 0 0; background: var(--page); }
.sheet-grabber { width: 36px; height: 5px; margin: 0 auto 10px; border-radius: 3px; background: var(--fill-2); }
.sheet-title { padding: 2px 16px 14px; font-size: 17px; font-weight: 600; text-align: center; }
.sheet-cancel { display: flex; width: calc(100% - 32px); margin: 12px 16px 0; background: var(--surface); }
.sheet-cancel.btn-primary { background: var(--accent); }
.outside-tg .mainbutton-preview { background: var(--page); }

/* ---------- широкий экран: вкладки — колонкой слева, полка шире ---------- */
@media (min-width: 600px) {
  .shelf { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (min-width: 900px) {
  body { --tabbar-h: 0px; }
  .has-tabs .app { padding-left: 232px; }
  .screen { max-width: 860px; margin: 0 auto; padding-top: calc(var(--safe-top) + 28px); }
  .tabbar { top: 0; right: auto; bottom: 0; display: flex; flex-direction: column; gap: 2px; width: 232px;
    padding: calc(var(--safe-top) + 28px) 12px 16px; border-top: 0; border-right: .5px solid var(--sep);
    background: var(--t-section-bg); -webkit-backdrop-filter: none; backdrop-filter: none; }
  .tabbar a { flex-direction: row; justify-content: flex-start; gap: 12px; height: 40px; padding: 0 12px;
    border-radius: 10px; font-size: 15px; font-weight: 500; }
  .tabbar a.on { background: var(--fill); }
  .tabbar .i { width: 22px; height: 22px; }
  .shelf { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 30px 22px; }
  .strip-book { width: 112px; }
  .hero { border-radius: 0 0 var(--r-group) var(--r-group); }
  .toast { bottom: 24px; }
}
@media (min-width: 1200px) {
  .shelf { grid-template-columns: repeat(6, minmax(0, 1fr)); }
}

/* =====================================================================================================================
   Экраны кабинета (часть 2 B9): формы, баннеры, переписка, график, выбор книг, порядок, загрузка
   ===================================================================================================================== */

/* кнопки-ячейки и формы внутри групп */
.cell-form { display: block; margin: 0; }
button.cell, .cell-form > button.cell { width: 100%; border: 0; text-align: left; font: inherit; cursor: pointer; }
.cell-form + .cell-form::before, .cell + .cell-form::before, .cell-form + .cell::before {
  content: ""; position: absolute; top: 0; right: 0; left: 16px; height: 1px; background: var(--sep);
  transform: scaleY(.5); transform-origin: top; }
.cell-form { position: relative; }
.inline-form { margin: 0; flex: none; }
.text-btn { flex: none; padding: 6px 2px; border: 0; background: none; color: var(--accent-text); font: 400 17px/1.2 var(--font-ui); }
.title-tools { display: flex; align-items: center; gap: 14px; }
.icon-btn-sm { width: 30px; height: 30px; }
.icon-btn-sm .i { width: 18px; height: 18px; }
.link-btn { padding: 0; border: 0; background: none; color: var(--accent-text); font: inherit; cursor: pointer; }
.reset-links { display: flex; flex-wrap: wrap; gap: 4px 14px; }
.btn-sm { height: 36px; padding: 0 14px; font-size: 15px; border-radius: 10px; }
.btn-block { display: flex; width: 100%; }
.actions-row { display: flex; flex-wrap: wrap; gap: 10px; padding: 12px 16px 0; margin: 0; }
.actions-wrap { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.actions-wrap form { margin: 0; }
.group-note + .section, .group-header + .section { margin-top: 0; }

/* текст */
.muted { color: var(--hint); }
.meta { font-size: 13px; line-height: 1.4; color: var(--hint); }
.prose { font-size: 16px; line-height: 1.5; }
.prose + .prose, .thesis + .prose { margin-top: 10px; }
.text-h { margin: 14px 0 6px; font-size: 15px; font-weight: 600; }
.text-h:first-child { margin-top: 0; }
.section-text p + p { margin-top: 8px; }
.ok { color: var(--ok); }
.warn-text { color: var(--warn); }
.error-text { color: var(--danger); }
.changed { color: var(--accent-text); }
.banner { margin: 0 16px 18px; padding: 12px 14px; border-radius: var(--r-group); background: var(--surface);
  font-size: 15px; line-height: 1.4; }
.banner ul { margin: 6px 0 0 18px; list-style: disc; }
.banner-warn { background: color-mix(in srgb, var(--warn) 14%, var(--surface)); }
.banner-error { background: color-mix(in srgb, var(--danger) 12%, var(--surface)); color: var(--danger); }
.banner-warn-text { color: var(--warn); }
.page-title { padding: 8px 16px 16px; }
.page-title h1 { font: 650 26px/1.18 var(--font-book); text-wrap: balance; overflow-wrap: anywhere; }
.page-kicker { margin-bottom: 6px; font-size: 15px; }
.page-meta { margin-top: 6px; font-size: 14px; line-height: 1.4; color: var(--hint); }
.page-title .chat-tags { margin-top: 8px; }
.pager { display: flex; justify-content: space-between; gap: 10px; padding: 0 16px 18px; }

/* поля ввода */
input[type=text], input[type=search], input[type=number], textarea, select { font: inherit; color: var(--text); }
.cell-input { padding-top: 6px; padding-bottom: 6px; }
.cell-input input { width: 100%; min-height: 32px; border: 0; outline: none; background: transparent; font-size: 17px; }
.cell-input-row { display: flex; align-items: stretch; }
.cell-input-row .cell-input { flex: 1; }
.cell-input-row > button.cell { width: auto; flex: none; }
.cell-input-row > button.cell::before { display: none; }
.cell-field { flex-direction: column; align-items: stretch; gap: 2px; padding-top: 8px; padding-bottom: 8px; }
.cell-field .field-label { font-size: 13px; color: var(--hint); }
.cell-field input, .cell-field select { border: 0; outline: none; background: transparent; font-size: 17px; padding: 2px 0; }
.cell-field select { width: 100%; -webkit-appearance: none; appearance: none; }
.cell-select { position: relative; }
.cell-select select, .cell-number input { flex: none; max-width: 48%; border: 0; outline: none; background: transparent;
  color: var(--accent-text); font-size: 17px; text-align: right; text-align-last: right; -webkit-appearance: none; appearance: none; }
.cell-number input { width: 96px; }
.cell-select select { padding-right: 2px; cursor: pointer; }
.cell-setting { align-items: center; }
.cell-check { gap: 12px; }
.cell-check input { width: 22px; height: 22px; flex: none; accent-color: var(--accent); }
.cell-file { cursor: pointer; }
.form-stack { display: flex; flex-direction: column; gap: 12px; padding: 0 16px; }
.sheet .form-stack { padding: 0 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 13px; color: var(--hint); }
.field-hint { font-size: 13px; line-height: 1.35; color: var(--hint); }
.field input, .field select, .field textarea, .details-body textarea, .details-body select, .details-body input[type=text] {
  width: 100%; padding: 10px 12px; border: 0; border-radius: var(--r-control); background: var(--fill); font-size: 16px; }
textarea { resize: vertical; line-height: 1.4; }
.filter-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.chip-select select { height: 32px; padding: 0 12px; border: 0; border-radius: 16px; background: var(--fill); font-size: 15px;
  -webkit-appearance: none; appearance: none; }
.sheet-form { margin: 0; }
.sheet-form .section + .group-footer { padding-bottom: 4px; }
.code-editor { display: block; width: 100%; min-height: 320px; padding: 12px 14px; border: 0; outline: none; background: var(--surface);
  font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; tab-size: 2; }
.prompt-text { max-height: 360px; overflow: auto; margin: 0 0 10px; padding: 10px 12px; border-radius: var(--r-control);
  background: var(--fill); font: 12.5px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: pre-wrap; }

/* раскрывающиеся ячейки */
.cell-details { display: block; padding: 0; }
.cell-details > summary { display: flex; align-items: center; gap: 12px; padding: 10px 16px; list-style: none; cursor: pointer; }
.cell-details > summary::-webkit-details-marker { display: none; }
.cell-details > summary::after { content: ""; flex: none; width: 7px; height: 7px; margin-left: auto;
  border-right: 1.6px solid var(--hint); border-bottom: 1.6px solid var(--hint); transform: rotate(45deg); opacity: .7;
  transition: transform var(--dur-2) ease; }
.cell-details[open] > summary::after { transform: rotate(-135deg); }
.details-body { display: flex; flex-direction: column; gap: 10px; padding: 0 16px 14px; font-size: 15px; line-height: 1.45; }
.details-body form { margin: 0; }
.inline-details { margin-top: 8px; }
.inline-details-pad { margin: -6px 16px 14px; }
.inline-details > summary { list-style: none; cursor: pointer; font-size: 15px; }
.inline-details > summary::-webkit-details-marker { display: none; }
.group-details-inline { margin: 8px 0 0; }
.group-details-inline > summary { padding: 0 32px 8px; list-style: none; cursor: pointer; }
.group-details-inline > summary::-webkit-details-marker { display: none; }

/* статистика и график */
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); }
.stat { display: flex; flex-direction: column; gap: 2px; padding: 14px 16px; }
.stat + .stat { border-left: .5px solid var(--sep); }
.stat-value { font: 650 22px/1.1 var(--font-book); font-variant-numeric: tabular-nums; }
.stat-label { font-size: 13px; color: var(--hint); }
.limit-line { margin-bottom: 8px; font-size: 17px; }
.chart { display: block; width: 100%; height: auto; overflow: visible; }
.chart-bar { fill: color-mix(in srgb, var(--accent) 45%, transparent); }
.chart-bar.is-peak { fill: var(--accent); }
.chart-axis { stroke: var(--sep); stroke-width: .5; }
.chart-label { fill: var(--hint); font-size: 8px; }
.table-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th, .tbl td { padding: 9px 12px; border-bottom: .5px solid var(--sep); text-align: left; vertical-align: top; }
.tbl th { color: var(--hint); font-weight: 500; font-size: 13px; white-space: nowrap; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.progress-inline { display: block; height: 3px; margin-top: 7px; }

/* переписка «пузырями» */
.thread { display: flex; flex-direction: column; gap: 8px; padding: 0 12px; }
.bubble { max-width: 88%; padding: 9px 12px 8px; border-radius: 16px; background: var(--surface); }
.bubble-user { align-self: flex-end; border-bottom-right-radius: 5px;
  background: color-mix(in srgb, var(--accent) 16%, var(--surface)); }
.bubble-assistant { align-self: flex-start; border-bottom-left-radius: 5px; }
.bubble-text { font-size: 16px; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 5px; font-size: 12px; color: var(--hint); }
.bubble-more { margin-top: 8px; padding-top: 8px; border-top: .5px solid var(--sep); font-size: 14px; }
.bubble-more > summary { cursor: pointer; color: var(--accent-text); list-style: none; }
.bubble-more > summary::-webkit-details-marker { display: none; }
.sources { margin: 8px 0 0; padding-left: 0; display: flex; flex-direction: column; gap: 8px; }
.sources li { line-height: 1.4; }
.snippet { font-size: 13px; line-height: 1.4; color: var(--hint); }
.rank { flex: none; width: 22px; color: var(--hint); font-size: 15px; text-align: right; font-variant-numeric: tabular-nums; }
.columns { display: grid; grid-template-columns: 1fr; gap: 0; }
@media (min-width: 900px) { .columns { grid-template-columns: 1fr 1fr; } }

/* чтение главы */
.chapter-text { padding: 0 20px; font-family: var(--font-book); font-size: 17px; line-height: 1.65; max-width: 68ch; margin: 0 auto; }
.chapter-text p { margin: 0 0 14px; white-space: pre-line; }
.segment.chunk { margin: 18px 0; padding-left: 12px; border-left: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); }
.segment.focus { border-left-color: var(--accent); background: color-mix(in srgb, var(--accent) 7%, transparent); }
.chunk-label { margin-bottom: 8px; font: 500 12px/1.3 var(--font-ui); color: var(--hint); }
.context { margin: 4px 0 10px; padding: 8px 10px; border-radius: var(--r-control); background: var(--fill);
  font: 13px/1.4 var(--font-ui); color: var(--text-2); }
.note-mark { margin-right: 4px; font: 600 11px/1 var(--font-ui); color: var(--hint); }
.chapter-text p.note { padding: 8px 10px; border-radius: var(--r-control); background: var(--fill); font-size: 15px; }

/* главы книги */
.chapter-cell { padding-left: calc(16px + var(--depth, 0) * 14px); }
.chapter-cell .cell-body { color: var(--text); }
.chapter-cell.is-excluded .cell-title { color: var(--hint); text-decoration: line-through; }
.chapter-cell .chip { height: 28px; padding: 0 10px; font-size: 13px; }
.chapter-cell .chip.on { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent-text); }

/* обложка: прогресс, статусы */
.strip-cover, .cell-cover-wrap { position: relative; display: block; }
.cover-progress { position: absolute; left: 6px; right: 6px; bottom: 6px; height: 4px; overflow: hidden; border-radius: 2px;
  background: rgba(0, 0, 0, .35); }
.cover-progress span { display: block; height: 100%; background: #fff; border-radius: 2px; transition: width var(--dur-3) ease; }
.shelf-cover .status + .cover-progress { bottom: 30px; }
.hero-progress { max-width: 240px; margin: 14px auto 0; background: rgba(255, 255, 255, .35); }
.hero-dark .hero-progress { background: rgba(0, 0, 0, .25); }
.status-dot { display: inline-block; width: 8px; height: 8px; margin-right: 2px; border-radius: 50%; background: #8e8e93; }
.status-dot.status-queued, .status-dot.status-parsing, .status-dot.status-indexing { background: var(--warn); }
.status-dot.status-failed, .status-dot.status-index_failed { background: var(--danger); }
.status-dot.status-awaiting_confirm, .status-dot.status-parsed { background: var(--accent); }

/* коллекции */
.tile-col-new .mosaic-new { display: grid; place-items: center; aspect-ratio: 128 / 164; color: var(--accent-text);
  background: var(--surface); border: 1.5px dashed var(--fill-2); }
.tile-col-new .mosaic-new .i { width: 30px; height: 30px; }
.mosaic-sm { flex: none; width: 52px; padding: 4px; gap: 3px; border-radius: 8px; background: var(--fill); }
.mosaic-sm .cover { border-radius: 1.5px; }
.cell-collection { --sep-inset: 80px; }
.col-tools { display: flex; gap: 18px; margin-top: 12px; }

/* выбор нескольких книг */
.pick-mark { display: none; }
.selecting [data-select-item] .pick-mark { position: absolute; top: 6px; right: 6px; z-index: 2; display: grid; place-items: center;
  width: 24px; height: 24px; border: 1.5px solid #fff; border-radius: 50%; background: rgba(0, 0, 0, .25);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .3); color: transparent; }
.selecting .cell-book .pick-mark { position: static; flex: none; border-color: var(--fill-2); background: transparent; box-shadow: none; }
.selecting [data-select-item].picked .pick-mark { border-color: var(--accent); background: var(--accent); color: var(--on-accent); }
.pick-mark .i { width: 15px; height: 15px; stroke-width: 3; }
.selecting .shelf-book:not(.picked) .cover { opacity: .75; }
.selecting .cell-book .chevron { display: none; }
.select-bar { position: fixed; z-index: 30; left: 0; right: 0; bottom: 0; display: none; flex-direction: column; gap: 8px;
  padding: 10px calc(16px + var(--safe-right)) calc(10px + var(--safe-bottom)) calc(16px + var(--safe-left));
  border-top: .5px solid var(--sep); background: var(--t-bottom-bar-bg); }
.selecting .select-bar { display: flex; }
.selecting .tabbar { display: none; }
.select-count { font-size: 13px; color: var(--hint); }
.select-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.select-actions .btn[disabled] { opacity: .4; }

/* ручной порядок */
.order-row { gap: 10px; }
.drag-handle { flex: none; color: var(--hint); cursor: grab; }
.drag-handle .i { width: 20px; height: 20px; }
.order-row.dragging { opacity: .5; }
@media (pointer: coarse) { .drag-handle { display: none; } }

/* загрузка */
.upload-row .cell-sub { font-size: 14px; }
.upload-row.is-queued .cell-sub { color: var(--ok); }
.upload-row.is-duplicate .cell-sub { color: var(--hint); }
.upload-row.is-error .cell-sub { color: var(--danger); }
.upload-row.is-error .progress span { background: var(--danger); }
.drop-overlay { position: fixed; z-index: 60; inset: 12px; display: none; place-items: center; padding: 24px;
  border: 2px dashed var(--accent); border-radius: 18px; background: color-mix(in srgb, var(--page) 88%, transparent);
  color: var(--accent-text); font-size: 18px; font-weight: 600; text-align: center; pointer-events: none; }
.dropping .drop-overlay { display: grid; }

/* главная кнопка: в Telegram её рисует клиент — дублирующая кнопка формы прячется */
.is-bound.form-fallback, .is-bound .form-fallback { display: none; }
.mainbutton-preview { border: 0; font: inherit; cursor: pointer; width: 100%; }

/* загрузчик и «нет доступа» */
.center-screen { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  min-height: 100vh; min-height: var(--tg-viewport-height, 100dvh); padding: 24px; text-align: center; }
.center-title { font: 650 26px/1.2 var(--font-book); }
.center-text { max-width: 34ch; color: var(--hint); font-size: 16px; line-height: 1.45; }
.loader-mark { display: flex; gap: 6px; }
.loader-mark span { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); opacity: .3;
  animation: loader-dot 1s infinite ease-in-out; }
.loader-mark span:nth-child(2) { animation-delay: .15s; }
.loader-mark span:nth-child(3) { animation-delay: .3s; }
.is-stopped .loader-mark { display: none; }
@keyframes loader-dot { 50% { opacity: 1; transform: translateY(-3px); } }

/* ---------- B10: документы проектов ---------- */
.tile-red { background: #ff3b30; }
/* плитка формата в списке документов: метка формата вместо иконки (PDF, DOCX, XLSX…) */
.tile-fmt { width: 36px; height: 44px; border-radius: 6px; font: 700 10px/1 var(--font-ui); letter-spacing: .02em;
  position: relative; overflow: hidden; }
.tile-fmt::after { content: ""; position: absolute; top: 0; right: 0; width: 10px; height: 10px;
  background: linear-gradient(225deg, var(--page) 50%, rgba(0, 0, 0, .18) 50%); }
/* переключатель «Книги · Проекты» во всю ширину под заголовком «Библиотеки» */
.seg-block { margin: 0 16px 18px; }
.seg-block a { height: 32px; font-size: 14px; }
/* страница документа: «мини-страница» формата вместо обложки */
.screen-doc .screen { padding-top: 0; }
.hero-doc { --hero: var(--surface); }
.doc-page { position: relative; display: grid; place-items: end start; width: 112px; height: 144px; margin: 0 auto 22px;
  padding: 14px; border-radius: 10px; color: #fff; box-shadow: 0 2px 4px rgba(0, 0, 0, .18), 0 18px 34px -14px rgba(0, 0, 0, .45); }
.doc-page-label { font: 800 20px/1 var(--font-ui); letter-spacing: .03em; }
.doc-page-fold { position: absolute; top: 0; right: 0; width: 26px; height: 26px; border-bottom-left-radius: 8px;
  background: linear-gradient(225deg, var(--hero) 50%, rgba(0, 0, 0, .22) 50%); }
.doc-red { background: linear-gradient(160deg, #ff5a4f, #e0271b); }
.doc-blue { background: linear-gradient(160deg, #3d9bff, #0a64d6); }
.doc-green { background: linear-gradient(160deg, #3fd06a, #1f9c47); }
.doc-orange { background: linear-gradient(160deg, #ffab2e, #e07b00); }
.doc-grey { background: linear-gradient(160deg, #a3a3aa, #6d6d73); }
.hero-doc .hero-title { font-family: var(--font-ui); font-size: 21px; word-break: break-word; }
.hero-doc .link { color: inherit; text-decoration: underline; text-underline-offset: 3px; }
.cell.is-this .cell-title { font-weight: 600; }
.i-ok { width: 14px; height: 14px; stroke-width: 2.6; vertical-align: -2px; color: var(--ok, #34c759); }
.chunk-place { display: inline-block; margin-left: 6px; color: var(--accent-text); }
.mode-cell .cell-sub { white-space: normal; }
/* выбор одного варианта списком — галочка справа, как в настройках Telegram */
.cell-radio { position: relative; cursor: pointer; }
.cell-radio input { position: absolute; opacity: 0; pointer-events: none; }
.cell-radio .check { visibility: hidden; }
.cell-radio input:checked ~ .check { visibility: visible; }
.cell-radio input:focus-visible ~ .cell-body { outline: 2px solid var(--focus); outline-offset: 2px; }
.upload-choice { display: flex; gap: 8px; margin-top: 8px; }
.upload-row.is-conflict .cell-sub { color: var(--text); }
/* раздел документа: интерфейсный шрифт и переносы строк (строки таблиц, пункты, строки слайдов) */
.doc-text p { font-family: var(--font-ui); font-size: 15px; line-height: 1.5; white-space: pre-wrap; }
/* B11: рабочие результаты — список и страница результата */
.tile-emoji { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; flex: none;
  background: color-mix(in srgb, var(--accent) 12%, var(--surface)); font-size: 17px; line-height: 1; }
.cell:has(> .tile-emoji) { --sep-inset: 58px; }
.hero-result .result-icon { font-size: 44px; line-height: 1; margin-bottom: 14px; }
.table-wrap { overflow-x: auto; }
.result-table { width: 100%; border-collapse: collapse; font-size: 15px; line-height: 1.4; }
.result-table th { text-align: left; font-weight: 600; font-size: 13px; color: var(--hint); padding: 6px 8px 6px 0; }
.result-table td { vertical-align: top; padding: 8px 8px 8px 0; border-top: .5px solid var(--sep); }
.task-cell { align-items: flex-start; padding-top: 10px; padding-bottom: 10px; }
.task-box { display: grid; place-items: center; width: 24px; height: 24px; margin-top: 1px; padding: 0; flex: none;
  border: 1.5px solid var(--accent); border-radius: 7px; background: transparent; color: var(--accent); cursor: pointer; }
.task-box .i { width: 16px; height: 16px; stroke-width: 3; }
.task-cell.is-done .cell-title { text-decoration: line-through; color: var(--hint); }
.task-cell.is-overdue .task-box { border-color: var(--danger); }
.task-cell .cell-sub { white-space: normal; }
.due-form input[type="date"] { max-width: 136px; font-size: 13px; }
.phrase + .phrase, .variant + .variant { margin-top: 14px; padding-top: 12px; border-top: .5px solid var(--sep); }
.phrase-situation { font-weight: 600; font-size: 15px; }
.doc-text-p { white-space: pre-wrap; font-size: 16px; line-height: 1.5; margin-top: 6px; }
.section-tools { display: flex; flex-direction: column; gap: 6px; padding: 8px 16px 0; }
.section-tools textarea { width: 100%; font: inherit; font-size: 15px; }
.diff { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; line-height: 1.45; white-space: pre-wrap; }
.diff-add { background: color-mix(in srgb, #34c759 16%, transparent); }
.diff-del { background: color-mix(in srgb, var(--danger) 14%, transparent); text-decoration: line-through; }
.diff-hunk { color: var(--hint); }

/* ---------- навигация, этап 2 ---------- */
.cell-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.cell-actions form { margin: 0; }
.chip-accent { background: var(--accent); color: var(--on-accent); }
.seg-block + .seg-block { margin-top: 0; }
.date-group-header { padding-top: 18px; }
.download-row { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 16px 12px; }
.group-subheader { padding: 18px 32px 7px; font-size: 13px; font-weight: 600; letter-spacing: .02em; text-transform: uppercase;
  color: var(--hint); }
.hero { position: relative; }
.hero-more { position: absolute; top: 8px; right: 12px; background: color-mix(in srgb, var(--surface) 70%, transparent); }
/* Настройки на телефоне (N16): название и пояснение — на всю ширину, значение — строкой ниже, пояснение в 2 строки
   (полностью — при выборе поля) */
@media (max-width: 560px) {
  .cell-setting.cell-select, .cell-setting.cell-number { flex-wrap: wrap; align-items: flex-start; }
  .cell-setting.cell-select .cell-body, .cell-setting.cell-number .cell-body { flex: 1 0 100%; }
  .cell-setting.cell-select select { max-width: 100%; width: 100%; margin-top: 6px; text-align: left; padding: 8px 12px;
    border-radius: 10px; background: var(--fill); }
  .cell-setting.cell-number input { margin-top: 6px; }
}
.cell-setting .cell-help { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.cell-setting:focus-within .cell-help, .cell-setting:hover .cell-help { -webkit-line-clamp: unset; overflow: visible; }
/* четыре вкладки на ширине телефона (Память: «Активные · Предложения · Прошедшие · История») */
.seg-4 a { flex: 1 1 auto; padding: 0 4px; font-size: 13px; letter-spacing: -.01em; white-space: nowrap; }

/* темы (02.10): выбор области темы — «Выбрано» карточками, поиск, разделы */
.pick-summary { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 16px 10px; }
.pick-count { color: var(--text-2); font-size: 15px; }
.pick-chips { flex-wrap: wrap; padding-bottom: 14px; }
.pick-chips .chip { white-space: normal; height: auto; min-height: 32px; padding: 6px 12px; text-align: left; }
.picker .search-wrap { padding-bottom: 12px; }
.picker [hidden] { display: none !important; }
