:root {
  --bg: #0d0f12;
  --surface: #17191e;
  --surface-2: #1f2229;
  --border: #2a2e37;
  --text: #e6e8ec;
  --text-dim: #9aa1ad;
  --accent: #4a9eff;
  --accent-2: #2b7fe0;
  --active: #c49a6c;
  --accent-light: #e0b070;
  --success: #00e676;
  --radius: 8px;
  --radius-sm: 5px;
  /* Боковая панель уже на 30 % (было 220px) */
  --sidebar-w: 154px;
  --font: 'Segoe UI', Inter, system-ui, -apple-system, sans-serif;
  --mono: ui-monospace, 'SF Mono', 'Cascadia Code', Consolas, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  width: 100vw;
}
@supports not (height: 100dvh) { #app { height: 100vh; } }

/* ───────── Верхняя панель ───────── */
#topbar {
  display: flex;
  flex-direction: column;   /* два фиксированных ряда: row1 сверху, row2 под ним */
  gap: 6px;
  padding: 6px 10px;
  padding-top: calc(6px + env(safe-area-inset-top, 0px));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  /* Разрешаем выпадающему меню инструментов выходить за нижнюю границу топбара */
  overflow: visible;
}

/* ─────────── Ряд 1: [☰ логотип] · тулбар(центр) · [действия справа] ───────────
   Тулбар центрируется свободным местом; действия ВСЕГДА прижаты вправо. */
.topbar-row1 {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  width: 100%;
}
/* Левая группа (☰ + логотип) и правая (действия) получают равную базовую
   ширину → тулбар между ними оказывается ровно по центру ВСЕГО окна.
   Левая группа прижата влево, действия — вправо; обе могут сжиматься. */
.topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-row1 > .topbar-left { flex: 1 1 0; justify-content: flex-start; }
.topbar-row1 > .top-actions { flex: 1 1 0; min-width: 0; justify-content: flex-end; }

/* ─────────── Ряд 2: ВСЕГДА под тулбаром (Окно + 3D для КТ) ─────────── */
.topbar-row2 {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  width: 100%;
}
/* Если внутри ряда 2 нет видимых панелей — не занимаем вертикальное место */
.topbar-row2:not(:has(.wwwc-row:not(.hidden))) {
  display: none;
}

.brand { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.logo { width: 30px; height: 30px; object-fit: contain; border-radius: 4px; }
.brand-text {
  font-size: 0.8rem;
  font-weight: 700;
  line-height: 1.15;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .04em;
  white-space: nowrap;
}

.btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 600;
  font-size: .82rem;
  font-family: inherit;
  transition: background .15s, border-color .15s;
  white-space: nowrap;
}
.btn:hover { background: #262a33; }
.btn.primary { background: var(--accent-2); border-color: var(--accent); }
.btn.primary:hover { background: var(--accent); }

.icon-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  width: 34px; height: 34px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 1rem;
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background .15s;
}
.icon-btn:hover { background: #262a33; }

/* ─────────────────────────────────────────────────────────────────────────
   Плавное мигание кнопок-подсказок (sidebarToggle, loadBtn) для первых
   трёх посещений страницы (счётчик визитов — в localStorage, класс
   навешивается из app.js). Пульсация раз в 3 сек: свечение accent-цветом
   плавно нарастает и затухает. prefers-reduced-motion уважается.
   ───────────────────────────────────────────────────────────────────────── */
@keyframes hint-blink {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(74, 158, 255, 0.0);
    border-color: var(--border);
  }
  50% {
    box-shadow: 0 0 0 4px rgba(74, 158, 255, 0.45),
                0 0 14px 3px rgba(74, 158, 255, 0.55);
    border-color: var(--accent);
  }
}

.hint-blink {
  animation: hint-blink 3s ease-in-out infinite;
  /* по центру пульсации — акцентная обводка не должна «дёргать» верстку */
  position: relative;
}

@media (prefers-reduced-motion: reduce) {
  .hint-blink { animation: none; }
}


.top-actions {
  display: flex; gap: 6px; align-items: center;
  margin-left: auto;   /* ВСЕГДА прижата к правому верхнему углу */
  flex-shrink: 0;
}

/* Инструменты в топе — дизайн кнопок сохранён из новой версии */
/* Центрирование: у .toolbar слева auto-отступ, у .top-actions — тоже auto.
   Flexbox делит всё свободное место между двумя auto-отступами поровну,
   поэтому панель инструментов «висит» по центру свободной зоны между
   логотипом и правым блоком действий и не прижимается к логотипу. */
.toolbar {
  order: 0;
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: nowrap;      /* тулбар НИКОГДА не переносится на новый ряд */
  flex: 0 1 auto;         /* может сжиматься (→ скролл), но не растягивается */
  min-width: 0;           /* позволяет overflow-скроллу работать */
  /* Центрирование: симметричные auto-отступы съедают всё свободное место,
     поэтому при широком окне (>1200x) тулбар висит по центру между логотипом
     и блоком действий. Если места не хватает — auto-отступы схлопываются,
     тулбар сжимается и скроллится по горизонтали (не переносясь). */
  /* боковые колонки .brand/.top-actions имеют равный flex-basis, поэтому
     тулбар (flex:0 1 auto) центрируется по середине окна автоматически */
  padding-left: 12px;  /* гарантированный зазор от логотипа */
  padding-right: 12px; /* гарантированный зазор от блока действий */
  overflow-x: auto;    /* если не вмещается по ширине — горизонтальный скролл */
  overflow-y: visible;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.toolbar::-webkit-scrollbar { height: 5px; }
.toolbar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }




.tbtn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  width: 36px; height: 32px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 1.05rem;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background .15s, border-color .15s;
  flex-shrink: 0;
}
.tbtn:hover { background: #262a33; }
.tbtn.active { background: var(--active); border-color: var(--active); color: #000; }
.tbtn:disabled { opacity: .35; cursor: not-allowed; }
.sep { width: 1px; height: 24px; background: var(--border); margin: 0 3px; flex-shrink: 0; }
#sidebarToggle {width: 36px; height: 36px;}

/* ───────────── Стили для PNG иконок в кнопках ───────────── */
.icon-img {
  width: 28px;
  height: 28px;
  object-fit: contain;
  filter: brightness(1);
}

.icon-img-sm {
  width: 28px;
  height: 28px;
  object-fit: contain;
  margin-right: 4px;
}

/* В активных кнопках иконки могут получать фильтр для контраста */
.tbtn.active .icon-img,
.more-item.active .icon-img-sm {
  filter: brightness(0.95);
}

/* На мобильных устройствах (максимум 768px) увеличиваем на 5% */
@media (max-width: 768px) {
  .tbtn {
    width: 42px;
    height: 38px;
  }
  
  .icon-btn {
    width: 42px;
    height: 38px;
  }
  
  .icon-img {
    width: 30px;
    height: 30px;
  }
  
  .icon-img-sm {
    width: 30px;
    height: 30px;
  }
}




/* Выпадающее меню «прочие инструменты».
   position: fixed — чтобы меню НЕ обрезалось overflow-скроллом тулбара
   (актуально на узких экранах / смартфоне). Координаты задаются в JS. */
.tool-more { position: relative; display: inline-flex; }
.tool-more-menu {
  position: fixed;
  top: 0;
  left: 0;
  min-width: 210px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 12px 30px rgba(0,0,0,.55);
  padding: 5px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 70vh;
  overflow-y: auto;
}
.tool-more-menu.hidden { display: none; }
.more-item {
  display: flex;
  align-items: center;
  gap: 8px;
  text-align: left;
  background: transparent;
  border: none;
  color: var(--text);
  font-family: inherit;
  font-size: .82rem;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
}
.more-item:hover { background: var(--surface-2); }
.more-item.active { background: var(--active); color: #000; }
#toolMoreBtn.has-active { background: var(--active); border-color: var(--active); color: #000; }

/* ─────────────────────────────────────────────────────────────────────────────
   ИКОНКА АКТИВНОГО ИНСТРУМЕНТА ПОД ФОНОМ КНОПКИ «ПРОЧИЕ ИНСТРУМЕНТЫ»

   Иконка more.png почти полностью прозрачная, поэтому под ней хорошо видно
   подложку. Когда пользователь выбирает инструмент из выпадающего списка,
   в кнопку подставляется иконка этого инструмента — она рисуется ПОД
   more.png (z-index ниже) и приглушена, чтобы сам значок «прочие» оставался
   читаемым. Так по кнопке сразу видно, какой именно инструмент активен.
   ───────────────────────────────────────────────────────────────────────────── */
#toolMoreBtn { position: relative; overflow: hidden; }

/* Базовая иконка «прочие» — всегда поверх подложки. */
#toolMoreBtn .more-btn-base { position: relative; z-index: 2; }

/* Иконка активного инструмента — подложка. */
#toolMoreBtn .more-active-icon {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 26px;
  height: 26px;
  object-fit: contain;
  z-index: 1;
  opacity: .85;
  pointer-events: none;
}
#toolMoreBtn .more-active-icon.hidden { display: none; }

/* На активной (подсвеченной) кнопке подложку слегка затемняем,
   чтобы она читалась на светлом фоне --active. */
#toolMoreBtn.has-active .more-active-icon { opacity: 1; filter: brightness(0.9); }

@media (max-width: 768px) {
  #toolMoreBtn .more-active-icon { width: 28px; height: 28px; }
}



/* Выбор окна — только для КТ */
.wwwc-row { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
/* Ряды разнесены в .topbar-row1 / .topbar-row2, поэтому order-хаки не нужны:
   «Окно» и «3D» всегда во втором ряду, блок действий — в правом верхнем углу. */
.row-label { font-size: .75rem; color: var(--text-dim); }
#wwwcSelect, #presetSelect {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  font-size: .8rem;
  font-family: inherit;
  max-width: 100%;
}

/* ───────── Тело ───────── */
#body { display: flex; flex: 1; min-height: 0; position: relative; }

#sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
  transition: margin-left .2s ease;
}
#sidebar::-webkit-scrollbar { width: 6px; }
#sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* Свёрнутое состояние (десктоп) */
#app.sidebar-collapsed #sidebar { margin-left: calc(-1 * var(--sidebar-w)); }

.sidebar-section { border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.sidebar-section.grow { flex: 1 1 auto; min-height: 120px; display: flex; flex-direction: column; }
.sidebar-title {
  padding: 8px 10px 6px;
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
}
.slice-counter {
  color: var(--accent-light);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-transform: none;
  letter-spacing: 0;
}

.series-list { padding: 0 6px; display: flex; flex-direction: column; gap: 4px; max-height: 26vh; overflow-y: auto; }
.series-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  text-align: left;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 7px;
  cursor: pointer;
  color: var(--text);
  font-family: inherit;
  transition: border-color .15s, background .15s;
}
.series-item:hover { background: #262a33; }
.series-item.active { border-color: var(--accent); background: #1a2330; }
.series-mod {
  font-weight: 700;
  font-size: .64rem;
  background: var(--accent-2);
  color: #fff;
  padding: 1px 5px;
  border-radius: 3px;
  align-self: flex-start;
}
.series-desc { font-size: .72rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; width: 100%; }
.series-count { font-size: .66rem; color: var(--text-dim); }

/* Мини-превью срезов */
.thumb-list {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 4px 6px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 5px;
  align-content: start;
}
.thumb {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 5px;
  overflow: hidden;
  cursor: pointer;
  background: #000;
  aspect-ratio: 1 / 1;
  padding: 0;
  transition: border-color .15s;
}
.thumb:hover { border-color: var(--accent); }
.thumb.active { border-color: var(--accent-light); box-shadow: 0 0 0 1px var(--accent-light); }
.thumb canvas { width: 100%; height: 100%; display: block; object-fit: contain; image-rendering: auto; }
/* Одиночное превью тома (КТ/МРТ) — крупнее и по центру */
.thumb-list.single { grid-template-columns: 1fr; }
.thumb-list.single .thumb { max-width: 220px; margin: 0 auto; }
.thumb-idx {
  position: absolute;
  bottom: 1px; right: 3px;
  font-size: .6rem;
  color: #fff;
  background: rgba(0,0,0,.62);
  padding: 0 3px;
  border-radius: 3px;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

/* Гистограмма и слайдеры */
.histogram-container { padding: 0 6px; }
#histogramCanvas {
  display: block;
  width: 100%;
  height: 58px;
  background: #101318;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  touch-action: none;
}
.slider-group { display: flex; align-items: center; gap: 6px; padding: 5px 8px 0; }
.slider-group label { color: var(--text-dim); font-size: 1.1rem; width: 16px; text-align: center; flex-shrink: 0; cursor: pointer; }
.slider-group input[type="range"] {
  flex: 1 1 auto;
  min-width: 0;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: var(--border);
  border-radius: 3px;
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent-light); cursor: pointer; border: none;
}
input[type="range"]::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent-light); cursor: pointer; border: none;
}

/* ───────── Сцена ───────── */
#stage { flex: 1; min-width: 0; display: flex; flex-direction: column; }
#viewportArea { flex: 1; position: relative; min-height: 0; background: #000; }
.cs-viewport { 
  width: 100%; 
  height: 100%; 
  position: relative; 
  cursor: crosshair !important;
  touch-action: none;
}

.stack-wrap { position: absolute; inset: 0; }
.measure-canvas {
  position: absolute;
  inset: 0;
  z-index: 10;
  touch-action: none;
  pointer-events: none;
}

.volume-wrap {
  position: absolute; inset: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 2px;
  background: var(--border);
}
.mpr-cell { position: relative; background: #000; overflow: hidden; }
.mpr-cell.cell-active { outline: 2px solid var(--accent); outline-offset: -2px; }

/* Переключатель MPR-проекций — на десктопе скрыт, виден только на мобильных */
.mpr-switch { display: none; }
.cell-label {
  position: absolute; top: 6px; left: 8px;
  font-size: .72rem; color: var(--accent);
  background: rgba(0,0,0,.5); padding: 2px 6px; border-radius: 4px;
  pointer-events: none; z-index: 15;
}

/* Кнопка «развернуть на всё окно» в каждой MPR-ячейке */
.cell-fs {
  position: absolute; top: 4px; right: 4px;
  z-index: 16;
  width: 26px; height: 26px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.5);
  color: #cfe4ff;
  border: 1px solid rgba(111,184,255,.28);
  border-radius: 5px;
  font-size: .95rem; line-height: 1;
  cursor: pointer;
  opacity: .55;
  transition: opacity .15s, background .15s, border-color .15s;
}
.cell-fs:hover { opacity: 1; background: rgba(20,32,46,.85); border-color: var(--accent); }

/* Развёрнутая ячейка занимает всю сетку 2x2 */
.volume-wrap.has-fs .mpr-cell { display: none; }
.volume-wrap.has-fs .mpr-cell.fs {
  display: block;
  grid-column: 1 / 3;
  grid-row: 1 / 3;
}

#toolHint {
  position: absolute;
  top: 10px; right: 10px;
  max-width: min(320px, calc(100% - 20px));
  background: rgba(0,0,0,.8);
  color: #6fb8ff;
  padding: 9px 11px;
  font-family: var(--mono);
  font-size: .73rem;
  line-height: 1.45;
  border: 1px solid rgba(111,184,255,.28);
  border-radius: var(--radius);
  white-space: pre-line;
  z-index: 25;
  pointer-events: none;
}

/* Оверлеи рабочей области (инфо о срезах / пациенте) */
.vp-overlay {
  position: absolute;
  top: 8px;
  z-index: 20;
  pointer-events: none;
  font-family: var(--mono);
  font-size: .74rem;
  line-height: 1.4;
  color: #cfe4ff;
  text-shadow: 0 1px 3px rgba(0,0,0,.9), 0 0 2px rgba(0,0,0,.9);
  white-space: pre-line;
}
.vp-overlay-tl { left: 10px; text-align: left; }
.vp-overlay-tr { right: 30px; text-align: right; }
/* Правый оверлей — три отдельных ряда (файл / пациент / исследование) */
.vp-overlay-tr .vp-overlay-row { display: block; white-space: nowrap; }
.vp-overlay-tr .vp-overlay-row:first-child { color: #eaf3ff; font-weight: 600; }
.vp-overlay b { color: var(--accent-light); font-weight: 700; }
.drop-zone {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  z-index: 30;
  background: radial-gradient(circle at 50% 40%, #14171d, #0a0c0f);
}
.drop-zone.drag .drop-inner { border-color: var(--accent); background: #16202e; }
.drop-inner {
  text-align: center;
  border: 2px dashed var(--border);
  border-radius: 14px;
  padding: 40px 52px;
  transition: border-color .2s, background .2s;
}
.drop-icon { font-size: 3rem; margin-bottom: 12px; }
.drop-title { font-size: 1.02rem; font-weight: 600; margin-bottom: 6px; }
.drop-sub { color: var(--text-dim); font-size: .84rem; margin-bottom: 16px; }

/* ───────── Статус / тост ───────── */
#statusbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 12px;
  padding-bottom: calc(4px + env(safe-area-inset-bottom, 0px));
  background: var(--surface);
  border-top: 1px solid var(--border);
  font-size: .74rem;
  color: var(--text-dim);
  /* \u041f\u043e\u0432\u0435\u0440\u0445 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u2014 \u043d\u0435 \u0441\u0434\u0432\u0438\u0433\u0430\u0435\u0442 \u043c\u0430\u043a\u0435\u0442 \u043f\u0440\u0438 \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u0438/\u0438\u0441\u0447\u0435\u0437\u043d\u043e\u0432\u0435\u043d\u0438\u0438 */
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 210;
  overflow: hidden;
  transition: opacity 0.3s ease, transform 0.3s ease;
}
#statusbar.hidden {
  display: flex !important;
  opacity: 0;
  transform: translateY(100%);
  pointer-events: none;
}
.status-progress {
  position: absolute;
  left: 0;
  top: 0;
  height: 2px;
  background: var(--accent);
  width: 0%;
  transition: width 0.3s ease;
  z-index: 1;
}

/* Прогресс-бар статусной строки (полоска у нижнего края) */
.status-progress-track {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 6px;
  background: transparent;
  z-index: 1;
  pointer-events: none;
  opacity: 0;
  transition: opacity .2s ease;
}
/* Дорожка видна только когда идёт процесс с известным прогрессом */
.status-progress-track.is-active {
  opacity: 1;
  background: rgba(255, 255, 255, .10);
}
.status-progress-bar {
  display: block;
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 0 2px 2px 0;
  transition: width .18s linear;
}
.series-badge { margin-left: auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 50vw; }

.toast {
  position: fixed;
  bottom: 44px; left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #1f2733;
  border: 1px solid #3c4a5e;
  color: #dce7f5;
  padding: 11px 17px;
  border-radius: 8px;
  font-size: .84rem;
  max-width: 90vw;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s, transform .25s;
  z-index: 200;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: #2a1e1e; border-color: #6b3a3a; color: #ffd9d9; }
.toast.success { background: #16261c; border-color: #2f6b45; color: #d3f5e0; }

.hidden { display: none !important; }

/* ───────── Настройки (модальное окно) ───────── */
.modal { position: fixed; inset: 0; z-index: 300; display: flex; align-items: center; justify-content: center; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.66); backdrop-filter: blur(2px); }
.modal-body {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: min(560px, calc(100vw - 24px));
  max-height: min(84vh, 760px);
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,.6);
}
/* ───────── Видео-заставка в окне настроек ───────── */
.settings-video-wrap {
  padding: 14px 16px 0;
  display: flex;
  justify-content: center;
}
.settings-video {
  width: 100%;
  max-height: 200px;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: #000;
  box-shadow: 0 6px 20px rgba(0,0,0,.45);
  display: block;
}
@media (max-width: 520px) {
  .settings-video { max-height: 150px; }
}

.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-head h2 { font-size: 1rem; font-weight: 700; }
.modal-content { padding: 14px 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 18px; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

.settings-block h3 {
  font-size: .74rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-dim);
  margin-bottom: 8px;
}
.radio-row, .check-row {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 0;
  font-size: .86rem;
  cursor: pointer;
}
.radio-row input, .check-row input { accent-color: var(--accent); width: 16px; height: 16px; cursor: pointer; }
.hint-text { font-size: .76rem; color: var(--text-dim); margin-bottom: 8px; }

.key-grid { display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; align-items: center; }
.key-label { font-size: .82rem; display: flex; align-items: center; gap: 8px; }
.key-label-icon { width: 22px; height: 22px; object-fit: contain; flex-shrink: 0; }
.key-input {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--accent-light);
  font-family: var(--mono);
  font-size: .78rem;
  font-weight: 700;
  padding: 5px 10px;
  min-width: 74px;
  text-align: center;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.key-input.listening { border-color: var(--accent); color: var(--accent); background: #16202e; }
.key-group-title {
  grid-column: 1 / -1;
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-dim);
  margin-top: 8px;
}

/* ═════════ Вкладки окна настроек: «Настройки» | «Инструкция» ═════════
   Заголовок и переключатель вкладок стоят в ОДНОМ ряду шапки модалки,
   поэтому длинную инструкцию больше не нужно пролистывать каждый раз. */
.modal-head .modal-title {
  font-size: 1rem;
  font-weight: 700;
  margin-right: auto;
  white-space: nowrap;
}
.settings-tabs {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  margin: 0 10px;
}
.settings-tab {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-dim);
  font: inherit;
  font-size: .8rem;
  font-weight: 600;
  padding: 5px 14px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s ease, color .15s ease;
}
.settings-tab:hover { color: var(--text); }
.settings-tab.active {
  background: var(--accent);
  color: #06121e;
}
.settings-tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Панель вкладки: внутренняя раскладка та же, что у .modal-content */
.tab-content { display: flex; flex-direction: column; gap: 18px; }
.tab-content.hidden { display: none !important; }

@media (max-width: 520px) {
  .modal-head { flex-wrap: wrap; gap: 8px; }
  .modal-head .modal-title { font-size: .92rem; }
  .settings-tabs { margin: 0; order: 3; width: 100%; justify-content: center; }
  .settings-tab { flex: 1; text-align: center; padding: 6px 8px; }
}

/* ═════════ Инструкция ═════════ */
.instruction-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.instruction-list li {
  position: relative;
  padding-left: 16px;
  font-size: .83rem;
  line-height: 1.45;
  color: var(--text);
}
.instruction-list li::before {
  content: '';
  position: absolute;
  left: 2px;
  top: .55em;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
}
.instruction-list b, .instruction-list strong { color: var(--accent-light); font-weight: 700; }

/* ===== Вкладка «Отзыв» ===== */
.feedback-mail {
  margin: 10px 0 14px;
  text-align: center;
}
.feedback-mail a {
  display: inline-block;
  padding: 10px 22px;
  border-radius: 10px;
  border: 1px solid var(--accent);
  background: rgba(74, 158, 255, .10);
  color: var(--accent-light);
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: .3px;
  text-decoration: none;
  transition: background .15s ease, transform .15s ease;
}
.feedback-mail a:hover {
  background: rgba(74, 158, 255, .20);
  transform: translateY(-1px);
}
.feedback-mail a:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.ann-style-note { margin-top: 6px; margin-bottom: 0; line-height: 1.4; }

/* ═════════ Блокировка инструментов при «Стандартной разметке» ═════════ */
.tbtn.tool-disabled,
.more-item.tool-disabled,
button[data-tool].tool-disabled {
  opacity: .34;
  cursor: not-allowed;
  filter: grayscale(1);
  pointer-events: auto;          /* нужен, чтобы работал title-тултип */
}
.tbtn.tool-disabled:hover,
.more-item.tool-disabled:hover { background: transparent; }
.more-item.tool-disabled { position: relative; }
.more-item.tool-disabled::after {
  content: '🔒';
  margin-left: auto;
  padding-left: 8px;
  font-size: .78rem;
  filter: none;
}

.key-label.key-row-disabled,
.key-input.key-row-disabled {
  opacity: .4;
  cursor: not-allowed;
}
.key-label-lock {
  font-size: .66rem;
  color: var(--text-dim);
  white-space: nowrap;
  margin-left: 6px;
}








/* ───────── Мобильная адаптация ───────── */
.sidebar-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 45; }

@media (max-width: 900px) {
  /* Меньше свободного места — уменьшаем зазоры вокруг тулбара */
  .toolbar { padding-left: 6px; padding-right: 6px; }
  /* brand-text остаётся видимым и на мобильном */
  .btn .t { display: none; }
  .tbtn { width: 34px; height: 32px; font-size: .98rem; }
  #topbar { gap: 6px; }
}

@media (max-width: 760px) {
  /* На мобильных боковая панель по умолчанию скрыта, разворачивается кнопкой */
  #sidebar {
    position: absolute;
    left: 0; top: 0; bottom: 0;
    z-index: 50;
    width: 190px;
    margin-left: -190px;
    box-shadow: 4px 0 22px rgba(0,0,0,.6);
    transition: margin-left .22s ease;
  }
  #app.sidebar-open #sidebar { margin-left: 0; }
  /* На мобильных класс sidebar-collapsed не влияет — управляет sidebar-open */
  #app.sidebar-collapsed #sidebar { margin-left: -190px; }
  #app.sidebar-open.sidebar-collapsed #sidebar { margin-left: 0; }

  .series-list { max-height: 22vh; }

  /* ── МОБИЛЬНЫЙ MPR: одновременно показываем только ОДНУ проекцию ──
     Переключение — вкладками #mprSwitch. Сетка 2×2 не используется. */
  .volume-wrap {
    display: flex;
    flex-direction: column;
    grid-template-columns: none;
    grid-template-rows: none;
    overflow: hidden;
    gap: 0;
  }
  /* По умолчанию скрываем все ячейки; видима только активная (.mpr-current) */
  .volume-wrap .mpr-cell { display: none; flex: 1 1 auto; height: auto; width: 100%; }
  .volume-wrap .mpr-cell.mpr-current { display: block; }
  /* Панель переключения проекций видна только на мобильных */
  #mprSwitch { display: flex; }

  /* На мобильном в объёмном режиме панель выбора проекции (Аксиал./Корон./3D…)
     находится сверху рабочей области. Оверлеи и подсказки по измерениям
     смещаем ниже неё, чтобы они не наслаивались на кнопки выбора проекции.
     В полноэкранном режиме одной ячейки (.has-fs) панель скрыта — смещение не нужно. */
  #viewportArea:has(#volumeWrap:not(.hidden)):not(:has(.volume-wrap.has-fs)) .vp-overlay,
  #viewportArea:has(#volumeWrap:not(.hidden)):not(:has(.volume-wrap.has-fs)) #toolHint {
    top: 62px;
  }

  /* Кнопка «развернуть на всё окно» на мобильном не нужна */
  .volume-wrap .cell-fs { display: none; }
  /* Полноэкранный режим на мобильном также показывает 1 окно */
  .volume-wrap.has-fs .mpr-cell { display: none; }
  .volume-wrap.has-fs .mpr-cell.mpr-current { display: block; }
  .drop-inner { padding: 28px 22px; }
  .toolbar { gap: 3px; }
  #wwwcSelect { max-width: 120px; }
}

/* ═══════════ Раскладка верхней панели при нехватке ширины ═══════════
   Структура ВСЕГДА такая (за счёт .topbar-row1 / .topbar-row2):
     Ряд 1: [☰ логотип] · тулбар(центр) · [Загрузить · инфо · настройки — справа]
     Ряд 2: [Окно: …] [3D: …]   (всегда под тулбаром, только для КТ)

   Тулбар центрируется, когда есть свободное место (окна шире 1200px).
   Если тулбар не вмещается — он НЕ переносится, а скроллится по горизонтали.

   При ширине ≤1200px свободного места в первом ряду обычно нет, поэтому
   разрешаем ПЕРВОМУ ряду переноситься: логотип и блок действий остаются на
   верхней визуальной линии, а тулбар опускается на отдельную линию под ними
   (во всю ширину, с горизонтальным скроллом). Ряд 2 (Окно+3D) по-прежнему
   располагается НИЖЕ тулбара. */
@media (max-width: 1200px) {
  .topbar-row1 { flex-wrap: wrap; }
  /* сбрасываем равные боковые колонки: слева ☰+логотип, справа действия */
  .topbar-row1 > .topbar-left { flex: 0 1 auto; }
  .topbar-row1 > .top-actions { flex: 0 1 auto; }
  .topbar-left  { order: 0; }
  .top-actions  { order: 1; }
  /* тулбар — отдельная линия во всю ширину, без auto-центрирования 
  .toolbar {
    order: 2;
    width: 100%;
    margin-left: 0;
    margin-right: 0;
    padding-left: 0;
    padding-right: 0;
    padding-bottom: 2px;
  }
  */
  .toolbar {
    order: 2;
    flex: 0 1 auto;   /* не заполняет весь доступный размер */
    margin-left: auto;   /* центрирование */
    margin-right: auto;  /* центрирование */
    
    min-width: 0;
      overflow-x: auto;   /*  если не вмещается по ширине — горизонтальный скролл */
  overflow-y: visible;
  /*scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;*/
    
  }
  
  .wwwc-row { flex: 0 1 auto; }
}

@media (max-width: 520px) {
  #topbar { padding: 5px 7px; gap: 5px; }
  .tbtn { width: 32px; height: 30px; font-size: .92rem; }
  .sep { margin: 0 1px; }
  .logo { width: 26px; height: 26px; }
  .series-badge { max-width: 40vw; }

  .toolbar { scrollbar-width: none; }
  .toolbar::-webkit-scrollbar { display: none; }
/*
   На узком смартфоне ограничиваем ширину селектов, чтобы «Окно» и «3D»
     помещались бок о бок */
  #wwwcSelect { max-width: 44vw; }
  #presetSelect { max-width: 44vw; }
}

/* ═══════════ Панель переключения MPR-проекций (мобильные) ═══════════ */
.mpr-switch {
  flex: 0 0 auto;
  gap: 4px;
  padding: 6px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}
.mpr-switch::-webkit-scrollbar { display: none; }
.mpr-tab {
  flex: 1 1 0;
  min-width: 64px;
  padding: 8px 6px;
  font-size: .82rem;
  font-weight: 600;
  color: var(--text-dim);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 7px;
  cursor: pointer;
  white-space: nowrap;
  transition: color .12s, background .12s, border-color .12s;
}
.mpr-tab.active {
  color: #fff;
  background: var(--accent-2);
  border-color: var(--accent);
}

/* ═══════════ DICOM-информация: таблица тегов ═══════════ */
#infoModal .modal-body { width: min(680px, calc(100vw - 24px)); max-height: min(88vh, 820px); }
#infoModal .modal-content { padding: 0; gap: 0; }
.info-toolbar {
  display: flex; gap: 8px; align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.info-search {
  flex: 1 1 auto;
  padding: 8px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  font-size: .88rem;
}
.info-search:focus { outline: none; border-color: var(--accent); }
.info-table-wrap { overflow-y: auto; padding: 4px 0 10px; }
.info-empty { padding: 40px 16px; text-align: center; color: var(--text-dim); font-size: .9rem; }
.info-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .84rem;
}
.info-table thead th {
  position: sticky; top: 0; z-index: 2;
  text-align: left;
  padding: 8px 16px;
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-dim);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.info-group-row td {
  padding: 10px 16px 4px;
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--accent-light);
  background: transparent;
}
.info-table tbody tr.info-row { border-bottom: 1px solid rgba(42,46,55,.5); }
.info-table tbody tr.info-row:hover { background: rgba(74,158,255,.06); }
.info-table td { padding: 7px 16px; vertical-align: top; }
.info-table td.col-code { color: var(--text-dim); font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: .78rem; white-space: nowrap; }
.info-table td.col-name { color: var(--text); }
.info-table td.col-val { color: var(--text); word-break: break-word; }
.info-table td.col-val.empty { color: var(--text-dim); font-style: italic; }
.info-row.required td.col-name { color: var(--accent); font-weight: 600; }
.info-row.required td.col-val { color: #fff; font-weight: 600; }
.info-row.required { background: rgba(74,158,255,.05); }

@media (max-width: 760px) {
  .info-table td, .info-table thead th { padding-left: 12px; padding-right: 12px; }
  .info-table td.col-code { font-size: .72rem; }
}


/* Стили для превью в списке серий */
.series-item {
  display: flex;
  flex-direction: row !important;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px;
}
.series-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex-grow: 1;
  overflow: hidden;
}
.series-preview-box {
  position: relative;
  width: 48px;
  height: 48px;
  flex-shrink: 0;
  background: #000;
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.series-preview-box canvas {
  width: 100%;
  height: 100%;
  display: block;
}
.series-preview-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  text-shadow: 0 1px 3px rgba(0,0,0,0.8);
  pointer-events: none;
}
