/* Архив кейсов и WSI-viewer. Только новые классы с префиксом cases-. */

.cases-page {
  background: var(--paper);
}

.cases-main {
  padding: 40px 0 96px;
}

.cases-topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
  margin-bottom: 26px;
}

.cases-title-block {
  max-width: 640px;
}

.cases-eyebrow {
  margin: 0 0 10px;
  color: #4387a1;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1.1px;
  text-transform: uppercase;
}

.cases-title {
  margin: 0;
  color: var(--ink);
  font: 600 clamp(28px, 4vw, 42px) / 1.1 var(--font-display);
  letter-spacing: -1.8px;
}

.cases-subtitle {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.75;
}

.cases-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.cases-actions .button {
  gap: 10px;
  white-space: nowrap;
}

.cases-layout {
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.cases-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Filters ---------- */

.cases-filters {
  margin-bottom: 20px;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--white);
  box-shadow: 0 18px 45px #1732480f;
}

.cases-filters-toggle {
  display: none;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #f4f7f2;
  color: var(--ink);
  font: 600 12px var(--font-body);
  cursor: pointer;
}

.cases-filters-toggle::after {
  content: "+";
  font-size: 16px;
  color: #4387a1;
}

.cases-filters.is-open .cases-filters-toggle::after {
  content: "−";
}

.cases-filters-hint {
  margin-left: auto;
  color: #4387a1;
  font-size: 10px;
  font-weight: 700;
}

.cases-filters-panel {
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  align-items: end;
  gap: 12px 14px;
}

.cases-segment {
  display: grid;
  grid-column: span 2;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border-radius: 7px;
  background: #f2f4f0;
}

.cases-segment-btn {
  min-height: 32px;
  padding: 0 8px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: #748077;
  font: 600 10.5px var(--font-body);
  cursor: pointer;
  transition: background 0.2s, color 0.2s, box-shadow 0.2s;
}

.cases-segment-btn:hover {
  color: var(--ink);
}

.cases-segment-btn.is-active {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 1px 4px #203b2217;
  box-shadow: inset 0 0 0 1px #bfe3f2, 0 1px 4px #203b2217;
}

.cases-segment-btn:focus-visible,
.cases-filters-toggle:focus-visible,
.cases-tool-btn:focus-visible,
.cases-reset:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.cases-filter-group {
  display: flex;
  flex-direction: column;
  grid-column: span 2;
  gap: 6px;
  min-width: 0;
}

.cases-filter-search {
  grid-column: span 3;
}

.cases-label {
  color: #879189;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.9px;
  text-transform: uppercase;
}

.cases-input,
.cases-select {
  width: 100%;
  height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fafbf9;
  color: #263c30;
  font: 400 12px var(--font-body);
}

.cases-input::placeholder {
  color: #a7b0a7;
}

.cases-input:focus,
.cases-select:focus {
  outline: none;
  border-color: #5aa4c0;
  box-shadow: 0 0 0 3px #87ceeb30;
}

.cases-search {
  position: relative;
  display: block;
}

.cases-search .cases-input {
  padding-left: 32px;
}

.cases-search-icon {
  position: absolute;
  top: 50%;
  left: 10px;
  width: 14px;
  height: 14px;
  color: #879189;
  transform: translateY(-50%);
  pointer-events: none;
}

.cases-date-row {
  display: flex;
  grid-column: span 3;
  gap: 10px;
  min-width: 0;
}

.cases-date-row .cases-filter-group {
  min-width: 0;
}

.cases-reset {
  grid-column: span 2;
  width: 100%;
  min-height: 36px;
  font-size: 10.5px;
}

.cases-count {
  grid-column: span 2;
  margin: 0;
  align-self: center;
  color: #526159;
  font-size: 10.5px;
  font-weight: 600;
}

/* ---------- Case list ---------- */

.cases-list {
  min-width: 0;
}

.cases-loading {
  margin: 0;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--white);
  color: var(--muted);
  font-size: 12px;
}

.cases-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}

.cases-card {
  position: relative;
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--white);
  text-align: left;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
}

.cases-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 30px #1732481a;
}

.cases-card.is-selected {
  border-color: var(--brand);
  box-shadow: 0 0 0 2px #87ceeb66, 0 16px 34px #1732481f;
}

.cases-card:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.cases-card-preview {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  background: #f3edf1;
}

.cases-card-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.cases-caption {
  position: absolute;
  right: 6px;
  bottom: 6px;
  padding: 3px 6px;
  border-radius: 4px;
  background: #ffffffd9;
  color: #4a3a48;
  font-size: 8px;
  font-weight: 600;
  letter-spacing: 0.3px;
  white-space: nowrap;
  backdrop-filter: blur(4px);
}

.cases-card-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 11px 12px;
}

.cases-card-code {
  margin: 0;
  color: var(--ink);
  font: 600 12px var(--font-display);
  letter-spacing: -0.2px;
}

.cases-card-meta {
  margin: 0;
  color: var(--muted);
  font-size: 9.5px;
  line-height: 1.5;
}

.cases-card-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 2px;
}

.cases-card-date {
  color: #879189;
  font-size: 9px;
  white-space: nowrap;
}

/* ---------- Status badges ---------- */

.cases-badge {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding: 0 8px;
  border-radius: 999px;
  background: #f0f2ee;
  color: #6f7a71;
  font-size: 8.5px;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  white-space: nowrap;
}

.cases-badge--draft {
  background: #eef0ec;
  color: #7e877e;
}

.cases-badge--progress {
  background: #e7f5fb;
  color: #2f6f88;
}

.cases-badge--completed {
  background: #e9f2e6;
  color: #5d7f56;
}

/* ---------- Empty state ---------- */

.cases-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 42px 20px;
  border: 1px dashed #d8e0d6;
  border-radius: 12px;
  background: #fbfcfa;
  text-align: center;
}

.cases-empty h2 {
  margin: 6px 0 0;
  color: var(--ink);
  font: 600 17px var(--font-display);
  letter-spacing: -0.4px;
}

.cases-empty p {
  max-width: 320px;
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.7;
}

.cases-empty .button {
  min-height: 38px;
  font-size: 10.5px;
}

.cases-empty-art {
  width: 96px;
  height: auto;
  opacity: 0.9;
}

/* ---------- Viewer ---------- */

.cases-viewer {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--white);
  box-shadow: 0 18px 45px #17324812;
}

.cases-viewer-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.cases-viewer-head .cases-eyebrow {
  margin-bottom: 6px;
}

.cases-viewer-title {
  margin: 0;
  color: var(--ink);
  font: 600 20px var(--font-display);
  letter-spacing: -0.6px;
}

.cases-viewer-sub {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 10.5px;
}

.cases-viewer-head-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.cases-viewer-body {
  display: flex;
  gap: 12px;
  min-height: 0;
}

.cases-toolbar {
  display: flex;
  flex: 0 0 54px;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  max-height: 100%;
  padding: 8px 6px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #f8faf7;
  scrollbar-width: none;
}

.cases-tool-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 100%;
  padding: 0 0 8px;
  border-bottom: 1px solid #e4e9e1;
}

.cases-tool-group:last-of-type {
  border-bottom: 0;
  padding-bottom: 0;
}

.cases-tool-btn {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid #e0e6dc;
  border-radius: 6px;
  background: #fff;
  color: #526159;
  font: 600 14px var(--font-body);
  cursor: pointer;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}

.cases-tool-btn svg {
  width: 15px;
  height: 15px;
}

.cases-tool-btn:hover {
  color: var(--ink);
  border-color: #bfe3f2;
  background: #f2fafd;
}

.cases-tool-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.cases-tool-btn.is-active {
  border-color: #bfe3f2;
  background: #e7f5fb;
  color: #2f6f88;
}

.cases-zoom-label {
  min-width: 40px;
  color: #526159;
  font-size: 10px;
  font-weight: 700;
  text-align: center;
}

.cases-range-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  color: #7d897e;
  font-size: 8px;
  font-weight: 600;
  letter-spacing: 0.3px;
}

.cases-range {
  width: 20px;
  height: 88px;
  accent-color: #5aa4c0;
  cursor: pointer;
  direction: rtl;
  writing-mode: vertical-lr;
}

.cases-viewer-stage {
  position: relative;
  display: grid;
  flex: 1 1 auto;
  place-items: center;
  min-width: 0;
  height: clamp(420px, 56vh, 720px);
  padding: 16px;
  overflow: hidden;
  border-radius: 10px;
  background: radial-gradient(circle at 50% 42%, #21405b 0%, #173248 62%, #102536 100%);
}

.cases-viewer-frame {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.cases-viewer-slide {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  transform-origin: center;
  transition: transform 0.18s ease, filter 0.12s linear;
  will-change: transform, filter;
  user-select: none;
  -webkit-user-drag: none;
}

.cases-viewer-slide.is-fill {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.cases-viewer-stage .cases-caption {
  right: 12px;
  bottom: 12px;
  padding: 4px 8px;
  font-size: 9px;
}

.cases-annotation {
  position: absolute;
  top: 26%;
  left: 34%;
  width: 30%;
  height: 26%;
  border: 1.5px dashed #87ceeb;
  border-radius: 3px;
  box-shadow: 0 0 0 9999px #0d1c2a1a;
  pointer-events: none;
}

.cases-annotation::after {
  content: "ROI";
  position: absolute;
  top: -19px;
  left: -1px;
  padding: 2px 6px;
  border-radius: 3px;
  background: #87ceeb;
  color: #173248;
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.6px;
}

.cases-viewer-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  color: #b9cbd8;
  font-size: 11.5px;
  text-align: center;
}

.cases-viewer:fullscreen,
.cases-viewer.is-expanded {
  position: fixed;
  inset: 0;
  z-index: 90;
  width: 100vw;
  height: 100vh;
  padding: 18px;
  overflow: hidden;
  border-radius: 0;
  background: var(--white);
}

.cases-viewer:fullscreen .cases-viewer-body,
.cases-viewer.is-expanded .cases-viewer-body {
  flex: 1;
  min-height: 0;
}

.cases-viewer:fullscreen .cases-viewer-stage,
.cases-viewer.is-expanded .cases-viewer-stage {
  flex: 1;
  height: auto;
  min-height: 0;
}

.cases-viewer:fullscreen .cases-meta-grid,
.cases-viewer:fullscreen .cases-strip,
.cases-viewer.is-expanded .cases-meta-grid,
.cases-viewer.is-expanded .cases-strip {
  display: none;
}

/* ---------- Metadata ---------- */

.cases-meta-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px 16px;
  margin: 0;
}

.cases-meta-item {
  min-width: 0;
}

.cases-meta-label {
  display: block;
  margin: 0 0 3px;
  color: #879189;
  font-size: 8.5px;
  font-weight: 700;
  letter-spacing: 0.8px;
  text-transform: uppercase;
}

.cases-meta-value {
  margin: 0;
  overflow-wrap: anywhere;
  color: var(--ink);
  font-size: 11.5px;
  line-height: 1.5;
}

/* ---------- Thumbnail strip ---------- */

.cases-strip {
  padding-top: 12px;
  border-top: 1px solid var(--line);
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: thin;
}

.cases-strip-track {
  display: flex;
  gap: 8px;
  min-height: 64px;
}

.cases-thumb {
  position: relative;
  flex: 0 0 auto;
  width: 84px;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.cases-thumb img {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
}

.cases-thumb.is-active {
  border-color: var(--brand);
  box-shadow: 0 0 0 2px #87ceeb66;
}

.cases-thumb:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

/* ---------- Header user ---------- */

.cases-header-user {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.cases-header-avatar {
  width: 32px;
  height: 32px;
  font-size: 11px;
}

.cases-header-email {
  max-width: 170px;
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cases-back-short {
  display: none;
}

/* ---------- Responsive ---------- */

@media (max-width: 1199px) {
  .cases-layout {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 991px) {
  .cases-filters-panel {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .cases-segment,
  .cases-filter-search,
  .cases-date-row {
    grid-column: span 2;
  }

  .cases-filter-group,
  .cases-reset,
  .cases-count {
    grid-column: auto;
  }
}

@media (max-width: 767px) {
  .cases-main {
    padding: 26px 0 72px;
  }

  .cases-topbar {
    align-items: stretch;
    gap: 16px;
  }

  .cases-actions {
    justify-content: flex-start;
  }

  .cases-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .cases-filters {
    padding: 14px;
  }

  .cases-filters-toggle {
    display: flex;
  }

  .cases-filters-panel {
    display: none;
    margin-top: 14px;
  }

  .cases-filters.is-open .cases-filters-panel {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    align-items: stretch;
  }

  .cases-segment,
  .cases-filter-group,
  .cases-filter-search,
  .cases-date-row {
    grid-column: auto;
  }

  .cases-reset {
    grid-column: auto;
    width: 100%;
  }

  .cases-count {
    grid-column: auto;
    margin-left: 0;
    align-self: flex-start;
  }

  .cases-toolbar {
    flex-basis: 48px;
  }

  .cases-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .cases-viewer {
    padding: 14px;
  }

  .cases-viewer-stage {
    height: clamp(260px, 52vh, 380px);
    padding: 10px;
  }

  .cases-meta-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .cases-header-email {
    display: none;
  }

  .cases-header-user {
    display: none;
  }

  .cases-header-actions .account-header-link {
    display: inline-flex;
    font-size: 11px;
    white-space: nowrap;
  }

  .cases-back-full {
    display: none;
  }

  .cases-back-short {
    display: inline;
  }

  .cases-thumb {
    width: 72px;
  }
}

@media (max-width: 420px) {
  .cases-meta-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .cases-toolbar {
    gap: 8px;
  }

  .cases-range {
    width: 20px;
    height: 64px;
  }

  .cases-zoom-label {
    min-width: 34px;
  }
}

/* ---------- Pagination ---------- */

.cases-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 16px;
}

.cases-pagination .cases-count {
  margin: 0;
}

/* ---------- Case files ---------- */

.cases-files {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 14px;
}

/* ---------- OpenSeadragon viewer (Part 3b-1) ---------- */

/* OSD-контейнер лежит поверх SVG-сцены: stage сохраняет свою высоту, а
   переключение режимов делается классом is-osd на #cases-stage. */
.cases-osd {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  min-height: 400px;
  background: #0b0f14;
}

.cases-osd[hidden] {
  display: none;
}

/* Chromium рисует focus-ring на контейнере после клика мышью; для OSD это
   визуальный шум. Клавиатурный фокус (:focus-visible) оставляем видимым. */
.cases-osd:focus:not(:focus-visible) {
  outline: none;
}

/* Режим переключается классом на stage: у .cases-viewer-frame display:grid,
   и прятать его через [hidden] пришлось бы с !important. */
.cases-viewer-stage.is-osd .cases-viewer-frame,
.cases-viewer-stage.is-osd .cases-viewer-empty {
  display: none;
}

/* Тулбар общий для обоих режимов (Part 3b-2): кнопки ветвятся внутри
   обработчиков (OSD API или CSS-трансформы превью). Правило остаётся
   страховкой на случай программного скрытия. */
.cases-toolbar[hidden] {
  display: none;
}

.cases-osd-status {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #0b0f14cc;
  color: #b9cbd8;
  font-size: 11.5px;
  text-align: center;
}

.cases-osd-status[hidden] {
  display: none;
}

/* На мобиле сцена ниже 400px, иначе OSD обрежется overflow:hidden. */
@media (max-width: 760px) {
  .cases-osd {
    min-height: 0;
  }
}

/* ---------- Тулбар и аннотации при OSD (Part 3b-2) ---------- */

/* ROI в OSD-режиме: OpenSeadragon сам ставит inline left/top/width/height
   из imageToViewportRectangle, поэтому проценты и «прожектор» SVG-варианта
   (.cases-annotation) здесь не нужны. Рамка и метка «ROI» наследуются. */
.cases-annotation--osd {
  top: auto;
  left: auto;
  width: auto;
  height: auto;
  box-sizing: border-box;
  box-shadow: none;
}

/* ---------- Part D: viewer above the archive list ---------- */

.cases-layout {
  grid-template-columns: minmax(0, 1fr);
}

.cases-layout > .cases-filters {
  margin-bottom: 0;
}

.cases-viewer-stage {
  height: clamp(500px, 65vh, 800px);
}

@media (max-width: 767px) {
  .cases-viewer-stage {
    height: clamp(300px, 45vh, 500px);
  }
}
