/* =====================================================================================================================
   WEB W1–W2: браузерный кабинет (только DESK_HOST — файл подключается в base.html и login.html под host_kind == 'desk';
   Mini App его не грузит). Раскладка:
     ≥ 1280 — три колонки: левая 260 px (свернуть — 64 px), центр, правая панель 380 px закреплена (если у экрана она есть);
     1024–1279 — левая колонка, правая панель выезжает поверх («Панель», Esc);
     768–1023 — левая колонка за ☰ (выезжает поверх);
     < 768 — раскладка Mini App: вкладки внизу, сверху полоса «← · 🔍 · ⚙ Настройки · Выйти».
   Центр: списки — до 1100 px, чтение и формы — колонка 780 px (--desk-col), главная кнопка — по колонке.
   ===================================================================================================================== */

body[data-host="desk"] { --desk-side-w: 260px; --desk-panel-w: 380px; --desk-col: 1100px; --desk-bar-h: 52px; }
html[data-side="mini"] body[data-host="desk"] { --desk-side-w: 64px; }
/* чтение и формы — узкая колонка */
body[data-host="desk"]:is(.screen-chapter, .screen-dialog, .screen-dialog-new, .screen-doc, .screen-result, .screen-book,
  .screen-settings, .screen-prompt, .screen-quality-new, .screen-security, .screen-notfound) { --desk-col: 780px; }

/* ---------- верхняя полоса ---------- */
.desk-bar { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 12px; min-height: var(--desk-bar-h);
  padding: 0 16px; background: color-mix(in srgb, var(--page) 88%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  border-bottom: .5px solid var(--sep); }
.desk-bar a { color: var(--accent-text); text-decoration: none; font-size: 16px; }
.desk-brand { font-weight: 600; color: var(--text) !important; }
.desk-bar-space { flex: 1; }
.desk-logout { margin: 0; }
.desk-logout .text-btn, .desk-panel-toggle { font-size: 16px; }
body[data-host="desk"].is-nested .screen { padding-top: 0; }
.desk-icon-btn { display: inline-grid; place-items: center; width: 36px; height: 36px; padding: 0; border: 0; border-radius: 10px;
  background: transparent; color: var(--accent-text); font: 500 20px/1 var(--font-ui); cursor: pointer; }
.desk-icon-btn:hover { background: var(--fill); }
.desk-icon-btn .i { width: 20px; height: 20px; }
.desk-burger { display: none; }

/* ---------- свой диалог подтверждения (W1) ---------- */
.desk-dialog { max-width: min(420px, calc(100vw - 32px)); border: 0; border-radius: 14px; padding: 20px;
  background: var(--surface); color: var(--text); box-shadow: 0 10px 40px rgba(0, 0, 0, .25); }
.desk-dialog::backdrop { background: rgba(0, 0, 0, .35); }
.desk-dialog-text { margin: 0 0 18px; font-size: 16px; line-height: 1.4; }
.desk-dialog-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* ---------- страница входа (W1) ---------- */
.screen-login .login { max-width: 420px; margin: 0 auto; gap: 14px; }
.login-code { margin: 4px 0; font-size: 64px; font-weight: 700; letter-spacing: 6px; text-align: center;
  font-variant-numeric: tabular-nums; }
.login-qr { display: flex; justify-content: center; }
.login-qr svg { width: 200px; height: 200px; background: #fff; border-radius: 12px; }
.login-timer { color: var(--text-2); text-align: center; font-variant-numeric: tabular-nums; }
.screen-login .btn-block, .screen-login form { width: 100%; }

/* ---------- левая колонка ---------- */
.desk-side { display: none; }
.desk-side-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 36px;
  padding: 0 4px 0 8px; }
.desk-logo { display: flex; align-items: center; gap: 8px; min-width: 0; color: var(--text); font: 650 18px/1.2 var(--font-book);
  text-decoration: none; }
.desk-logo-mark { font-size: 22px; line-height: 1; }
.desk-collapse span { font-size: 24px; line-height: 1; }
.desk-search { display: flex; align-items: center; gap: 10px; height: 36px; margin: 14px 0 6px; padding: 0 10px; border: 0;
  border-radius: 10px; background: var(--fill); color: var(--hint); font: 400 15px/1 var(--font-ui); cursor: pointer;
  text-align: left; }
.desk-search span { flex: 1; }
.desk-search kbd { padding: 2px 6px; border-radius: 6px; background: var(--surface); color: var(--text-2);
  font: 500 12px/1.4 var(--font-ui); }
.desk-search .i, .desk-new .i, .desk-nav-link .i { width: 20px; height: 20px; flex: none; }
.desk-new { display: flex; align-items: center; gap: 10px; height: 38px; margin: 2px 0 12px; padding: 0 10px; border-radius: 10px;
  color: var(--accent-text); font-size: 15px; font-weight: 600; text-decoration: none; }
.desk-new:hover, .desk-nav-link:hover { background: var(--fill); }
.desk-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; min-height: 0; overflow-y: auto; margin: 0 -4px; padding: 0 4px; }
.desk-nav > *, .desk-side-head, .desk-search, .desk-new, .desk-side-foot { flex-shrink: 0; }   /* невысокое окно — прокрутка, не сжатие */
.desk-nav-link { display: flex; align-items: center; gap: 12px; width: 100%; height: 38px; padding: 0 10px; border: 0;
  border-radius: 10px; background: transparent; color: var(--text); font: 500 15px/1 var(--font-ui); text-decoration: none;
  text-align: left; cursor: pointer; }
.desk-nav-link.on { background: var(--fill); color: var(--accent-text); }
.desk-topics { margin: 0 0 6px; padding: 0 0 0 32px; list-style: none; }
.desk-topics a { display: block; padding: 5px 10px; border-radius: 8px; color: var(--text-2); font-size: 14px; line-height: 1.3;
  text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.desk-topics a:hover { background: var(--fill); color: var(--text); }
.desk-topics a.on { background: var(--fill); color: var(--accent-text); font-weight: 600; }
.desk-side-foot { display: flex; flex-direction: column; gap: 2px; padding-top: 10px; border-top: .5px solid var(--sep); }
.desk-side-foot form { margin: 0; }
.desk-scrim { position: fixed; z-index: 44; inset: 0; background: rgba(0, 0, 0, .35); }
.desk-scrim[hidden] { display: none; }

/* ---------- правая панель (слот: W2 — образец на «Компонентах», W4 — источники ответа) ---------- */
.desk-panel { position: fixed; z-index: 46; top: 0; right: 0; bottom: 0; display: flex; flex-direction: column;
  width: min(var(--desk-panel-w), 100vw); background: var(--surface); border-left: .5px solid var(--sep);
  box-shadow: -12px 0 32px rgba(0, 0, 0, .18); transform: translateX(100%); visibility: hidden;
  transition: transform var(--dur-2, 200ms) ease, visibility 0s linear var(--dur-2, 200ms); }
body.panel-open .desk-panel { transform: none; visibility: visible; transition-delay: 0s; }
.desk-panel-head { display: flex; align-items: center; justify-content: space-between; min-height: var(--desk-bar-h);
  padding: 0 8px 0 16px; border-bottom: .5px solid var(--sep); }
.desk-panel-title { font-weight: 600; }
.desk-panel-body { flex: 1; overflow-y: auto; padding: 16px; }
.desk-panel-demo { color: var(--text-2); font-size: 15px; line-height: 1.45; }

/* ---------- палитра ⌘K ---------- */
.desk-palette { width: min(640px, calc(100vw - 32px)); max-height: 72vh; margin: 12vh auto auto; padding: 0; border: 0;
  border-radius: 14px; background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0, 0, 0, .3); }
.desk-palette::backdrop { background: rgba(0, 0, 0, .3); }
.desk-palette-box { display: flex; flex-direction: column; max-height: 72vh; }
.desk-palette-field { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: .5px solid var(--sep); }
.desk-palette-field .i { width: 20px; height: 20px; color: var(--hint); flex: none; }
.desk-palette-field input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--text);
  font: 400 17px/1.3 var(--font-ui); }
.desk-palette-field input::-webkit-search-cancel-button { display: none; }
.desk-palette-list { flex: 1; overflow-y: auto; padding: 6px 8px 8px; }
.desk-palette-gtitle { margin: 10px 8px 4px; color: var(--hint); font-size: 12px; font-weight: 600; letter-spacing: .02em;
  text-transform: uppercase; }
.desk-palette-item { display: flex; align-items: center; gap: 12px; padding: 8px 10px; border-radius: 10px; color: var(--text);
  text-decoration: none; }
.desk-palette-item .i { width: 20px; height: 20px; flex: none; color: var(--hint); }
.desk-palette-item.is-active { background: var(--accent); color: var(--on-accent, #fff); }
.desk-palette-item.is-active .i, .desk-palette-item.is-active .desk-palette-sub { color: inherit; opacity: .85; }
.desk-palette-text { display: flex; flex-direction: column; min-width: 0; }
.desk-palette-title, .desk-palette-sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.desk-palette-title { font-size: 15px; }
.desk-palette-sub { color: var(--hint); font-size: 13px; }
.desk-palette-empty { padding: 18px 10px; color: var(--hint); text-align: center; }
.desk-palette-hint { margin: 0; padding: 8px 16px; border-top: .5px solid var(--sep); color: var(--hint); font-size: 12px; }

/* ---------- < 768: раскладка Mini App (вкладки внизу), колонок нет ---------- */
@media (max-width: 767px) {
  .desk-scrim { display: none; }
}

/* ---------- ≥ 768: колонки вместо вкладок ---------- */
@media (min-width: 768px) {
  body[data-host="desk"] { --tabbar-h: 0px; }
  body[data-host="desk"] .tabbar { display: none; }
  body[data-host="desk"].has-tabs .app { padding-left: 0; }
  body[data-host="desk"] .desk-narrow { display: none; }
  body[data-host="desk"] .screen { max-width: var(--desk-col); margin: 0 auto; padding-top: 24px; }
  body[data-host="desk"].is-nested .screen { padding-top: 8px; }
  .desk-burger { display: inline-grid; }
  .desk-side { position: fixed; z-index: 45; top: 0; bottom: 0; left: 0; display: flex; flex-direction: column;
    width: 260px; padding: 16px 12px 14px; background: var(--t-section-bg); border-right: .5px solid var(--sep);
    transform: translateX(-100%); visibility: hidden;
    transition: transform var(--dur-2, 200ms) ease, visibility 0s linear var(--dur-2, 200ms); }
  body.side-open .desk-side { transform: none; visibility: visible; transition-delay: 0s; box-shadow: 12px 0 32px rgba(0, 0, 0, .18); }
  .desk-collapse { display: none; }
  /* главная кнопка — по колонке контента, прилипает к низу окна */
  body[data-host="desk"].outside-tg .mainbutton-preview { position: sticky; z-index: 25; bottom: 0; left: auto; right: auto;
    display: block; width: 100%; max-width: var(--desk-col); margin: 0 auto; padding: 12px 16px 16px;
    background: linear-gradient(to top, var(--page) 72%, transparent); }
  body[data-host="desk"].outside-tg.has-main { --mainbutton-h: 0px; }
  body[data-host="desk"] .toast { bottom: 24px; }
}

/* ---------- ≥ 1024: левая колонка на месте ---------- */
@media (min-width: 1024px) {
  body[data-host="desk"] .app { margin-left: var(--desk-side-w); }
  .desk-side { width: var(--desk-side-w); transform: none; visibility: visible; z-index: 20; transition: width var(--dur-2, 200ms) ease; }
  body.side-open .desk-side { box-shadow: none; }
  .desk-burger, .desk-bar-search, .desk-brand { display: none !important; }
  .desk-bar.is-bare { display: none; }
  .desk-collapse { display: inline-grid; }
  .desk-scrim { display: none; }
  /* свёрнутая колонка — только иконки */
  html[data-side="mini"] .desk-side { padding-left: 10px; padding-right: 10px; }
  html[data-side="mini"] .desk-side .desk-label { display: none; }
  html[data-side="mini"] .desk-side-head { flex-direction: column; padding: 0; gap: 10px; }
  html[data-side="mini"] .desk-collapse span { transform: rotate(180deg); }
  html[data-side="mini"] :is(.desk-search, .desk-new, .desk-nav-link) { justify-content: center; padding: 0; }
}

/* ---------- ≥ 1280: правая панель закреплена ---------- */
@media (min-width: 1280px) {
  body[data-host="desk"][data-panel] .app { margin-right: var(--desk-panel-w); }
  .desk-panel { z-index: 20; transform: none; visibility: visible; box-shadow: none; transition: none; }
  .desk-panel-toggle, .desk-panel-close { display: none !important; }
  body[data-host="desk"][data-panel] .desk-bar.is-bare { display: none; }
  /* центр сужен панелью (≈ 640–800 px): полка — 4 обложки в ряд, а не 6 по ширине окна */
  body[data-host="desk"][data-panel] .shelf { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
  .desk-side, .desk-panel { transition: none; }
}
