/* Kafedrum 2.8 — information hierarchy, density and navigation.
   Loaded last. Keeps the Quiet Cinema palette and editorial headline, but moves functional
   content up: one Knowledge base → Subject → Overview / Lecture model, compact headers,
   list rows instead of sparse cards, a modal mobile drawer and anchored menus.
   Spacing follows a 4 px scale; 64 px is reserved for rare editorial moments. */

:root {
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --space-8: 64px;
  --gutter: clamp(32px, 3.2vw, 48px);
  --sidebar-w: 280px;
  --rail-w: 72px;
  --topbar-h: 56px;
  --touch: 44px;
}
@media (max-width: 850px) { :root { --gutter: 24px; } }
@media (max-width: 359px) { :root { --gutter: 16px; } }

.ui-icon { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- top bar ---------- */
.topbar { height: var(--topbar-h); gap: var(--space-4); padding: 0 var(--space-5); }
.product-tabs { height: var(--topbar-h); }
.nav-btn { min-width: 0; padding: 0 var(--space-4); }
.menu-btn { display: none; }
.topbar-context { display: none; }
.profile { position: relative; }
.profile-button { min-height: 40px; display: inline-flex; align-items: center; gap: var(--space-2); padding: 4px 8px 4px 4px; border: 1px solid transparent; border-radius: 6px; background: transparent; color: var(--text); cursor: pointer; font: 500 14px var(--display); }
.profile-button:hover, .profile-button[aria-expanded="true"] { border-color: var(--line); background: rgba(255, 255, 255, .04); }
.profile-button .avatar { width: 28px; height: 28px; font-size: 13px; }
.profile-name { max-width: 14ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile-button .ui-icon { width: 14px; height: 14px; color: var(--muted); }
.menu-header { display: grid; gap: 2px; padding: var(--space-2) 10px var(--space-3); border-bottom: 1px solid var(--line); margin-bottom: var(--space-1); }
.menu-header strong { overflow: hidden; color: var(--text); font: 600 15px var(--display); text-overflow: ellipsis; white-space: nowrap; }
.menu-header span { color: var(--muted); font-size: 13px; line-height: 1.4; }

/* ---------- anchored menus and tooltips ---------- */
.popover-menu { position: fixed; z-index: 260; min-width: 220px; max-width: min(320px, calc(100vw - 16px)); max-height: min(440px, calc(100dvh - 16px)); overflow: auto; padding: 6px; border: 1px solid var(--line-2); border-radius: 8px; background: #121613; box-shadow: 0 24px 64px rgba(0, 0, 0, .55); overscroll-behavior: contain; }
.popover-menu[hidden] { display: none !important; }
.menu-item { width: 100%; min-height: 40px; display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 0; border-radius: 5px; background: transparent; color: var(--text); cursor: pointer; font: 500 15px/1.3 var(--display); text-align: left; }
.menu-item .ui-icon { width: 16px; height: 16px; color: var(--muted); }
.menu-item:hover:not(:disabled), .menu-item:focus-visible { background: rgba(255, 255, 255, .07); }
.menu-item:disabled { color: var(--subtle); cursor: not-allowed; }
.menu-item[aria-checked="true"] { color: var(--accent-2); }
.menu-item[aria-checked="true"]::after { content: "Сейчас здесь"; margin-left: auto; color: var(--muted); font-size: 12px; }
.menu-item.is-danger, .menu-item.is-danger .ui-icon { color: var(--bad-ink); }
.menu-item.is-danger:hover:not(:disabled), .menu-item.is-danger:focus-visible { background: rgba(195, 87, 69, .18); }
.menu-item.is-danger:disabled { color: var(--subtle); }
.menu-item.is-danger:disabled .ui-icon { color: var(--subtle); }
.menu-item-copy { min-width: 0; display: grid; gap: 2px; }
.menu-item-copy small { color: var(--muted); font-size: 13px; line-height: 1.4; }
.menu-item:disabled .menu-item-copy small { color: var(--subtle); }
.menu-label { margin: 0; padding: 8px 10px 4px; color: var(--muted); font: 500 13px var(--display); }
.menu-separator { height: 1px; margin: 6px 4px; background: var(--line); }
.menu-item-mobile { display: none; }
@media (pointer: coarse) { .menu-item { min-height: var(--touch); } }

.tooltip { position: fixed; z-index: 300; max-width: 260px; padding: 6px 10px; border: 1px solid var(--line-2); border-radius: 6px; background: #1b201c; color: var(--text); box-shadow: 0 10px 28px rgba(0, 0, 0, .45); font: 500 13px/1.35 var(--display); pointer-events: none; }
.tooltip[hidden] { display: none; }
@media (min-width: 851px) { .drawer-backdrop { display: none; } }

/* ---------- sidebar (desktop) ---------- */
.unified-layout { grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
.library-panel { display: flex; flex-direction: column; }
.knowledge-head { min-height: var(--topbar-h) !important; gap: var(--space-2); padding: 0 var(--space-2) 0 var(--space-4); }
.knowledge-title { min-width: 0; display: flex; align-items: center; gap: var(--space-2); margin: 0; color: var(--text); font: 600 15px var(--display) !important; letter-spacing: 0 !important; text-transform: none !important; }
.knowledge-title::before, .knowledge-title::after { content: none !important; }
.knowledge-title .ui-icon { color: var(--accent); }
.knowledge-actions { display: flex; align-items: center; gap: var(--space-1); }
.knowledge-actions .icon-btn { width: 36px; height: 36px; }
#toggle-sidebar .icon-close, #toggle-sidebar .icon-expand { display: none; }
.knowledge-base-list { flex: 1; min-height: 0; display: grid; align-content: start; gap: 2px; overflow: auto; padding: var(--space-2); }
.kb-group-label { margin: var(--space-3) 0 var(--space-1); padding: 0 var(--space-2); color: var(--muted); font: 500 13px var(--display); }
.knowledge-base-item { width: 100%; min-height: var(--touch); grid-template-columns: 32px minmax(0, 1fr) auto; align-items: center; gap: var(--space-3); padding: 6px var(--space-2); }
.knowledge-base-item:hover { transform: none; }
.kb-icon { width: 32px; height: 32px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 6px; background: rgba(255, 255, 255, .02); color: var(--muted); font: 600 12px/1 var(--display); letter-spacing: .02em; }
.knowledge-base-item.is-active .kb-icon { border-color: rgba(196, 206, 181, .45); background: rgba(196, 206, 181, .12); color: var(--accent-2); }
.knowledge-base-item .kb-label { color: inherit; }
.knowledge-base-item.is-active .kb-label { color: var(--text); font-weight: 600; }
.kb-count { min-width: 20px; color: var(--muted); font: 500 13px var(--display); text-align: right; font-variant-numeric: tabular-nums; }
.sidebar-queue { padding: var(--space-2) var(--space-4); border-top: 1px solid var(--line); }
.queue-summary, .queue-summary span { display: block; border: 0; background: transparent; padding: 0; }
.queue-summary { color: var(--muted); font: 14px/1.4 var(--display); }
.queue-summary b { color: var(--text); font-weight: 600; }
.library-footer { display: grid; gap: 2px; padding: var(--space-2); background: rgba(0, 0, 0, .16); }
.nav-utility { width: 100%; min-height: 40px; display: flex; align-items: center; gap: var(--space-3); padding: 6px var(--space-2); border: 0; border-radius: 6px; background: transparent; color: var(--muted); cursor: pointer; font: 500 14px var(--display); text-align: left; }
.nav-utility .ui-icon { width: 32px; }
.nav-utility:hover { background: rgba(255, 255, 255, .04); color: var(--text); }
.refresh-btn.is-refreshing .ui-icon { animation: refresh-spin .7s linear infinite; }
.rail-record { min-height: var(--touch); justify-content: center; margin: var(--space-2) 0 0; }
.rail-record .ui-icon { width: 16px; height: 16px; }

/* collapsed rail: icons stay, labels move into tooltips */
@media (min-width: 851px) {
  .sidebar-collapsed .unified-layout { grid-template-columns: var(--rail-w) minmax(0, 1fr); }
  .sidebar-collapsed .library-panel { width: 100%; }
  .sidebar-collapsed .knowledge-head { flex-direction: column; justify-content: center; gap: var(--space-1); padding: var(--space-2) 0; }
  .sidebar-collapsed .knowledge-title { display: none; }
  .sidebar-collapsed .knowledge-actions { position: static !important; flex-direction: column-reverse; display: flex !important; }
  .sidebar-collapsed #add-knowledge-base { display: inline-grid !important; }
  .sidebar-collapsed #toggle-sidebar { transform: none; }
  #toggle-sidebar .icon-collapse { display: block; }
  .sidebar-collapsed #toggle-sidebar .icon-collapse { display: none; }
  .sidebar-collapsed #toggle-sidebar .icon-expand { display: block; }
  .sidebar-collapsed .knowledge-base-list { display: grid !important; justify-items: center; padding: var(--space-2) 0; }
  .sidebar-collapsed .kb-group-label { width: 32px; height: 1px; margin: var(--space-2) 0; padding: 0; overflow: hidden; background: var(--line); color: transparent; }
  .sidebar-collapsed .knowledge-base-item { width: 48px; grid-template-columns: 1fr; justify-items: center; padding: 6px 0; }
  .sidebar-collapsed .kb-label, .sidebar-collapsed .kb-count, .sidebar-collapsed .sidebar-queue, .sidebar-collapsed .nav-utility span { display: none !important; }
  .sidebar-collapsed .library-footer { width: 100%; justify-items: center; margin-top: 0; padding: var(--space-2) 0; }
  .sidebar-collapsed .nav-utility { width: 48px; justify-content: center; padding: 6px 0; }
  .sidebar-collapsed .rail-record { width: var(--touch); min-width: var(--touch); height: var(--touch); margin: var(--space-2) auto 0; padding: 0; border-radius: 50%; }
  .sidebar-collapsed .rail-record span { display: none; }
  .sidebar-collapsed .rail-record .ui-icon { width: 18px; height: 18px; }
}

/* ---------- workspace canvas ---------- */
.study-workbench { padding: var(--space-5) var(--gutter) var(--space-7); }
@media (min-width: 851px) {
  /* Collapsing the rail hands its width back to the canvas: the content reflows into the
     freed space instead of holding its old position. */
  .sidebar-collapsed .study-workbench { padding-left: var(--gutter); }
  .sidebar-collapsed .workspace-shell { width: 100%; }
}
.workspace-shell { width: min(1120px, 100%); }
.processing-notice { margin-bottom: var(--space-4); }

.breadcrumb { margin: 0 0 var(--space-3); }
.breadcrumb ol { display: flex; flex-wrap: wrap; align-items: center; margin: 0; padding: 0; list-style: none; color: var(--muted); font: 500 14px/1.4 var(--display); }
.breadcrumb li { min-width: 0; display: flex; align-items: center; }
.breadcrumb li + li::before { content: "/"; margin: 0 var(--space-2); color: var(--subtle); }
.breadcrumb button { min-height: 32px; padding: 4px 6px; margin: 0 -6px; border: 0; border-radius: 4px; background: transparent; color: var(--muted); cursor: pointer; font: inherit; text-decoration: underline; text-decoration-color: transparent; text-underline-offset: 3px; }
.breadcrumb button:hover { color: var(--text); text-decoration-color: currentColor; }
.breadcrumb [aria-current="page"] { overflow: hidden; color: var(--text); text-overflow: ellipsis; white-space: nowrap; }

/* ---------- page headers ---------- */
.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--space-4) var(--space-6); padding: 0 0 var(--space-5); border-bottom: 1px solid var(--line); }
.page-header-copy { min-width: 0; max-width: 760px; }
.editorial-title { margin: 0; color: var(--text); font: 650 clamp(32px, 3.4vw, 46px)/1.04 var(--display); letter-spacing: -.045em; text-wrap: balance; overflow-wrap: anywhere; }
.editorial-title em { color: #a3ae99; font-family: Georgia, "Times New Roman", serif; font-style: italic; font-weight: 400; letter-spacing: -.03em; }
.page-lede { max-width: 64ch; margin: var(--space-2) 0 0; color: var(--muted); font-size: 16px; line-height: 1.5; }
.page-lede:empty { display: none; }
.page-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); flex: none; }
.page-actions .btn { min-height: var(--touch); justify-content: center; padding-inline: 18px; }
.page-actions .hero-secondary { border-color: var(--line-2); }

.section-bar { display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); margin: var(--space-5) 0 var(--space-3); }
.section-bar h2 { display: flex; align-items: baseline; gap: var(--space-2); margin: 0; color: var(--text); font: 600 20px/1.2 var(--display); letter-spacing: -.02em; }
.section-count { color: var(--muted); font: 500 15px var(--display); font-variant-numeric: tabular-nums; }
.section-count:empty { display: none; }
.section-note { margin: 0; color: var(--muted); font-size: 14px; }
.section-note:empty { display: none; }

/* ---------- knowledge-base home ---------- */
.subjects-section { padding: 0; border-top: 0; }
.subject-grid { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: var(--space-3); }
.subject-card { height: auto; min-height: 88px; grid-template-columns: 40px minmax(0, 1fr) 18px; align-items: center; gap: var(--space-3); padding: var(--space-4); cursor: pointer; }
.subject-card:hover { transform: translateY(-2px); box-shadow: 0 16px 40px rgba(0, 0, 0, .26); }
.subject-card::before { inset: -80% -30% 40% 45%; }
.subject-monogram { width: 40px; height: 40px; font-size: 14px; }
.subject-card-copy { gap: 2px; }
.subject-card-copy strong { font: 600 17px/1.25 var(--display); letter-spacing: -.015em; }
.subject-card-copy em { font-size: 14px; }
.subject-card-copy small { margin-top: 2px; }
.subject-card > .ui-icon { color: var(--muted); transition: transform .3s var(--ease), color .3s; }
.subject-card:hover > .ui-icon { color: var(--accent-2); transform: translateX(3px); }
.subjects-empty { min-height: 0; gap: var(--space-3); padding: var(--space-6) var(--space-5); border-radius: 8px; text-align: center; }
.subjects-empty strong { color: var(--text); font: 600 18px var(--display); }
.subjects-empty p { max-width: 52ch; margin: 0; color: var(--muted); }

.how-it-works { margin-top: var(--space-6); padding-top: var(--space-5); border-top: 1px solid var(--line); }
.section-kicker { margin: 0 0 var(--space-3); color: var(--muted); font: 500 14px var(--display); }
.how-steps { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-3); margin: 0; padding: 0; list-style: none; counter-reset: step; }
.how-steps li { display: grid; grid-template-columns: 24px minmax(0, 1fr); gap: 2px var(--space-2); padding: var(--space-4); border: 1px solid var(--line); border-radius: 7px; background: rgba(255, 255, 255, .015); counter-increment: step; }
.how-steps li::before { content: counter(step, decimal-leading-zero); grid-row: span 2; padding-top: 3px; color: var(--subtle); font: 12px var(--mono); }
.how-steps strong { color: var(--text); font: 600 15px/1.35 var(--display); }
.how-steps span { color: var(--muted); font-size: 14px; line-height: 1.45; }

/* ---------- subject overview ---------- */
.subject-status { display: flex; flex-wrap: wrap; gap: 6px; margin: var(--space-3) 0 0; padding: 0; list-style: none; }
.subject-status:empty { display: none; }
.status-chip { min-height: 28px; display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border: 1px solid var(--line-2); border-radius: 999px; color: var(--muted); font: 500 14px var(--display); }
.status-chip b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.status-chip i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); }
.status-chip.is-ready i { background: var(--good); }
.status-chip.is-processing i { background: var(--warn); }
.status-chip.is-failed i { background: var(--bad); }

.subject-empty { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: var(--space-4) var(--space-6); margin-top: var(--space-5); padding: var(--space-5); border: 1px dashed var(--line-2); border-radius: 8px; background: rgba(255, 255, 255, .015); }
.subject-empty h2 { margin: 0; color: var(--text); font: 600 20px/1.25 var(--display); letter-spacing: -.015em; }
.subject-empty p { max-width: 62ch; margin: var(--space-2) 0 0; color: var(--muted); font-size: 15px; line-height: 1.5; }
.subject-empty ol { display: flex; flex-wrap: wrap; gap: var(--space-1) var(--space-4); margin: var(--space-3) 0 0; padding: 0; list-style: none; counter-reset: step; color: var(--muted); font-size: 14px; }
.subject-empty li { counter-increment: step; }
.subject-empty li::before { content: counter(step) ". "; color: var(--subtle); }
.subject-empty .btn { min-height: var(--touch); justify-content: center; padding-inline: 20px; }

/* ---------- lecture rows ---------- */
.lecture-rows { display: grid; border: 1px solid var(--line); border-radius: 8px; background: rgba(255, 255, 255, .012); }
.lecture-row { position: relative; display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: var(--space-1); padding-right: var(--space-2); transition: background-color .2s; }
.lecture-row + .lecture-row { border-top: 1px solid var(--line); }
.lecture-row:first-child { border-radius: 7px 7px 0 0; }
.lecture-row:last-child { border-radius: 0 0 7px 7px; }
.lecture-row:only-child { border-radius: 7px; }
.lecture-row:hover { background: rgba(255, 255, 255, .03); }
.lecture-row-main { min-width: 0; min-height: 68px; display: grid; grid-template-columns: 36px minmax(0, 1fr) auto auto; align-items: center; gap: var(--space-2) var(--space-4); padding: var(--space-3) var(--space-2) var(--space-3) var(--space-4); border: 0; border-radius: 7px; background: transparent; color: inherit; cursor: pointer; font: inherit; text-align: left; }
.lecture-row-main:focus-visible { outline-offset: -3px !important; box-shadow: none !important; }
.lecture-row-main[aria-disabled="true"] { cursor: default; }
.lecture-row-icon { width: 36px; height: 36px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 6px; color: var(--muted); }
.status-completed .lecture-row-icon { border-color: rgba(145, 173, 121, .32); color: var(--good-ink); }
.status-failed .lecture-row-icon { border-color: rgba(217, 119, 106, .35); color: var(--bad-ink); }
.status-leased .lecture-row-icon, .status-queued .lecture-row-icon { border-color: rgba(192, 165, 110, .32); color: var(--warn-ink); }
.lecture-row-copy { min-width: 0; display: grid; gap: 2px; }
.lecture-row-title { overflow: hidden; color: var(--text); font: 600 16px/1.35 var(--display); text-overflow: ellipsis; white-space: nowrap; }
.lecture-row-meta { display: flex; flex-wrap: wrap; color: var(--muted); font: 14px/1.4 var(--display); }
.lecture-row-meta > span:not(.job-status) + span:not(.job-status)::before { content: "·"; margin: 0 var(--space-2); color: var(--subtle); }
.lecture-row-meta-status { display: none; }
.lecture-row-detail { color: var(--muted); font: 14px/1.4 var(--display); }
.lecture-row-detail.is-error { color: var(--bad-ink); }
.lecture-row-progress { height: 3px; margin-top: 6px; overflow: hidden; border-radius: 3px; background: var(--line); }
.lecture-row-progress span { display: block; height: 100%; background: var(--warn); }
.lecture-row-state .job-status { white-space: nowrap; }
.lecture-row-action { min-width: 96px; display: flex; justify-content: flex-end; }
.lecture-row-open { min-height: 36px; display: inline-flex; align-items: center; gap: 6px; padding: 0 12px; border: 1px solid var(--line-2); border-radius: 6px; color: var(--accent-2); font: 600 14px var(--display); white-space: nowrap; transition: border-color .2s, background-color .2s; }
.lecture-row-open .ui-icon { width: 14px; height: 14px; }
.lecture-row-main:hover .lecture-row-open { border-color: rgba(207, 218, 195, .45); background: rgba(255, 255, 255, .05); }
.lecture-row-pending { color: var(--muted); font: 500 14px var(--display); font-variant-numeric: tabular-nums; white-space: nowrap; }
.lecture-row-retry { min-height: 36px; }
.lecture-row-menu { width: 40px; height: 40px; }
.lecture-row-menu[aria-expanded="true"] { background: rgba(255, 255, 255, .08); color: var(--text); }
.load-more { margin: var(--space-4) auto 0; }

/* ---------- lecture reader ---------- */
.reader-breadcrumb { min-width: 0; overflow: hidden; color: var(--muted); font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.reader-breadcrumb span + span::before { content: "/"; margin: 0 6px; color: var(--subtle); }
.result-dialog .dialog-actions.reader-actions { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); padding: 10px 22px calc(10px + env(safe-area-inset-bottom)); }
.reader-actions-end { position: relative; display: flex; align-items: center; gap: var(--space-2); }
.result-dialog .reader-actions .button { width: auto; min-height: var(--touch); }
.export-button .ui-icon { width: 16px; height: 16px; }
.export-button .export-chevron { width: 14px; height: 14px; }
.export-menu { width: 340px; }

/* ---------- delete confirmation ---------- */
.delete-lecture-title { margin: var(--space-3) 0 0; padding: var(--space-3) var(--space-4); border-left: 3px solid var(--bad); border-radius: 4px; background: rgba(195, 87, 69, .1); color: var(--text) !important; font: 600 16px/1.4 var(--display); overflow-wrap: anywhere; }
#delete-dialog .confirm-actions { margin-top: var(--space-5); }
#delete-dialog .button { min-height: var(--touch); }

/* ---------- tablet and phone ---------- */
@media (max-width: 1080px) {
  .how-steps { grid-template-columns: 1fr; }
}

@media (max-width: 850px) {
  .topbar { position: sticky; top: 0; height: var(--topbar-h); grid-template-columns: minmax(0, 1fr) auto; gap: var(--space-2); padding: 0 var(--space-2) 0 var(--space-1); padding-top: env(safe-area-inset-top); }
  .topbar .brand, .topbar .release-stamp { display: none; }
  .topbar-start { gap: var(--space-1); }
  .menu-btn { width: var(--touch); height: var(--touch); display: inline-grid; place-items: center; border-radius: 6px; color: var(--text); }
  .menu-btn .ui-icon { width: 22px; height: 22px; }
  .topbar-context { min-width: 0; display: flex; flex-direction: column; justify-content: center; line-height: 1.2; }
  .topbar-context-parent { width: fit-content; max-width: 100%; min-height: 0; overflow: hidden; padding: 0; border: 0; background: transparent; color: var(--muted); cursor: pointer; font: 13px var(--display); text-align: left; text-overflow: ellipsis; white-space: nowrap; }
  .topbar-context-parent[hidden] { display: none; }
  /* The crumb is visually small; its hit area extends into the header's empty top edge. */
  .topbar-context-parent { position: relative; overflow: visible; }
  .topbar-context-parent::after { content: ""; position: absolute; inset: -14px -12px -6px; }
  .topbar-context-title { overflow: hidden; color: var(--text); font: 600 16px var(--display); text-overflow: ellipsis; white-space: nowrap; }
  .topbar .service-state { display: inline-grid !important; width: 24px; height: var(--touch); min-height: 0; place-items: center; padding: 0; border: 0; background: transparent; }
  .topbar .service-state > span { display: none; }
  .profile-button { width: var(--touch); height: var(--touch); justify-content: center; padding: 0; }
  .profile-button .avatar { width: 32px; height: 32px; }
  .profile-name, .profile-button > .ui-icon { display: none !important; }

  .breadcrumb { display: none; }
  .study-workbench, .sidebar-collapsed .study-workbench { padding: var(--space-5) var(--gutter) var(--space-7); }

  /* the drawer is a real modal: full height, above the header, strong backdrop */
  .library-panel, .sidebar-collapsed .library-panel { position: fixed; z-index: 90; top: 0; bottom: 0; left: 0; width: min(88vw, 340px); height: 100dvh; min-height: 0; display: flex; padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom); border-right: 1px solid var(--line-2); box-shadow: none; visibility: hidden; transform: translateX(-100%); transition: transform .3s var(--ease), visibility 0s linear .3s; touch-action: pan-y; }
  .drawer-open .library-panel { visibility: visible; transform: none; box-shadow: 24px 0 64px rgba(0, 0, 0, .6); transition: transform .3s var(--ease); }
  .library-panel.is-dragging { transition: none !important; }
  .drawer-backdrop { position: fixed; z-index: 85; inset: 0; background: rgba(2, 3, 3, .74); backdrop-filter: blur(3px); opacity: 0; visibility: hidden; transition: opacity .25s, visibility 0s linear .25s; }
  .drawer-open .drawer-backdrop { opacity: 1; visibility: visible; transition: opacity .25s; }
  html.drawer-lock, html.drawer-lock body { overflow: hidden; overscroll-behavior: none; }
  .knowledge-head { min-height: 64px !important; padding: 0 var(--space-2) 0 var(--space-5); }
  .knowledge-actions .icon-btn { width: var(--touch); height: var(--touch); }
  #toggle-sidebar .icon-collapse, #toggle-sidebar .icon-expand { display: none !important; }
  #toggle-sidebar .icon-close { display: block; width: 22px; height: 22px; }
  .knowledge-base-list { padding: var(--space-2) var(--space-3); }
  .knowledge-base-item { min-height: 48px; }
  .sidebar-queue { padding: var(--space-3) var(--space-5); }
  .library-footer { padding: var(--space-2) var(--space-3) var(--space-3); }
  .nav-utility { min-height: var(--touch); }

  .page-header { flex-direction: column; align-items: stretch; gap: var(--space-4); padding-bottom: var(--space-5); }
  .editorial-title { font-size: clamp(30px, 8.4vw, 38px); }
  .page-actions .btn { flex: 1 1 auto; }
  .subject-grid { grid-template-columns: 1fr; }
  .subject-empty { grid-template-columns: 1fr; padding: var(--space-5) var(--space-4); }
  .subject-empty .btn { width: 100%; }
}

@media (max-width: 600px) {
  .page-actions { display: grid; grid-template-columns: 1fr; }
  .subject-view .page-actions { display: flex; }
  .lecture-row { grid-template-columns: minmax(0, 1fr) auto; padding-right: 0; }
  /* The whole row opens a ready lecture; the status chip flows at the end of the metadata line. */
  .lecture-row-main { min-height: 64px; grid-template-columns: minmax(0, 1fr); gap: 4px; padding: var(--space-3) var(--space-1) var(--space-3) var(--space-4); }
  .lecture-row-icon, .lecture-row-state, .lecture-row-action { display: none; }
  .lecture-row-copy { gap: 4px; }
  .lecture-row-title { display: -webkit-box; white-space: normal; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
  .lecture-row-meta { align-items: center; row-gap: 4px; }
  .lecture-row-meta-status { display: inline-flex; margin-left: var(--space-2); }
  .section-bar .refresh-btn { width: var(--touch); height: var(--touch); }
  .lecture-row-open { width: 32px; padding: 0; justify-content: center; border: 0; }
  .lecture-row-open-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .lecture-row-open .ui-icon { width: 18px; height: 18px; }
  .lecture-row-retry { grid-column: 1 / -1; grid-row: 2; justify-self: start; min-height: var(--touch); margin: 0 0 var(--space-3) var(--space-4); }
  .lecture-row-menu { grid-column: 2; grid-row: 1; width: var(--touch); height: var(--touch); }

  .result-dialog .dialog-actions.reader-actions { padding: var(--space-2) var(--space-3) calc(var(--space-2) + env(safe-area-inset-bottom)); }
  .result-dialog #copy-summary { display: none; }
  .menu-item-mobile { display: flex; }
  .export-button { padding-inline: 16px; }
  .reader-controls .icon-btn { min-width: var(--touch); min-height: var(--touch); }
  .toast { left: var(--space-4); right: var(--space-4); max-width: none; }
}

@media (prefers-reduced-motion: reduce) {
  .library-panel, .drawer-backdrop { transition: none !important; }
  .subject-card:hover > .ui-icon { transform: none; }
}

/* ---------- support contact, change-password (B-16 / B-06) ---------- */
.menu-support[hidden] { display: none; }
.menu-support-item { text-decoration: none; }
.menu-support-item > span { display: grid; gap: 1px; min-width: 0; }
.menu-support-item .menu-hint { overflow: hidden; color: var(--muted); font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
div.menu-support-item { cursor: default; }
.support-line { margin-top: var(--space-2); }
.support-link, .support-text { overflow-wrap: anywhere; }
.support-link { display: inline-flex; align-items: center; min-height: var(--touch); color: var(--accent-2); text-decoration: underline; text-underline-offset: 3px; }
.support-hint { display: flex; flex-wrap: wrap; align-items: center; gap: 0 .35em; }
.password-dialog .hint { margin: 12px 0; }
.password-dialog .field + .field { margin-top: 12px; }
.password-dialog input { font-size: 16px; }

/* ---------- B-15: touch targets >= 44 px (tablet/phone and any coarse pointer) ----------
   Small visuals keep their size and get an invisible ::before hit area; full-size buttons and fields are simply taller. */
@media (max-width: 1024px), (pointer: coarse) {
  .topbar-context-parent { z-index: 2; }
  .topbar-context-parent::after { inset: -14px -12px -20px; }
  .notice-more summary { min-height: var(--touch); }
  .ts, .ts-link, .text-action { position: relative; }
  .ts::before, .ts-link::before { content: ""; position: absolute; inset: -5px; }
  .text-action::before { content: ""; position: absolute; inset: -5px 0; }
  .study-action, #copy-summary { min-height: var(--touch); }
  .icon-btn, .knowledge-actions .icon-btn, .reader-controls .icon-btn, .result-dialog .dialog-close { min-width: var(--touch); min-height: var(--touch); }
  input:not([type="checkbox"]):not([type="radio"]):not([type="file"]), select, textarea { min-height: var(--touch); }
}
/* Touch laptops / landscape tablets wider than 1024 px: the desktop-density controls also reach 44 px. */
@media (pointer: coarse) {
  .breadcrumb button, .profile-button, .nav-utility, .refresh-btn, .rail-record, .product-tabs .nav-btn { min-height: var(--touch); }
}
