/* Каталог запчастей — просмотрщик. Чистый, инженерный дизайн, системные шрифты. */

:root {
  --border: #d5d9de;
  --bg: #f5f6f8;
  --panel-bg: #ffffff;
  --text: #1b1f24;
  --text-muted: #667085;
  --accent: #1a5fb4;
  --accent-hover: #164d92;
  --hl-bg: #fff3b0;
  --hl-ring: #e8a900;
  font-size: 15px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ---------- Topbar ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  background: var(--panel-bg);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}

.topbar__title {
  font-weight: 600;
  font-size: 16px;
  white-space: nowrap;
}

.search {
  position: relative;
  flex: 1 1 auto;
  max-width: 520px;
}

.search input {
  width: 100%;
  padding: 8px 12px;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  outline: none;
}

.search input:focus {
  border-color: var(--accent);
}

.search__results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
  max-height: 360px;
  overflow-y: auto;
  z-index: 50;
}

.search__results.hidden { display: none; }

.search__item {
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  line-height: 1.4;
}

.search__item:last-child { border-bottom: none; }

.search__item:hover,
.search__item.is-active {
  background: #eef3fb;
}

.search__item-main {
  font-weight: 600;
}

.search__item-sub {
  color: var(--text-muted);
}

.search__empty {
  padding: 10px 12px;
  color: var(--text-muted);
  font-size: 13px;
}

/* ---------- Mobile tabs (hidden on desktop) ---------- */

.tabs {
  display: none;
  flex: 0 0 auto;
  border-bottom: 1px solid var(--border);
  background: var(--panel-bg);
}

.tabs__btn {
  flex: 1 1 0;
  padding: 10px;
  border: none;
  background: none;
  font-size: 13px;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  cursor: pointer;
}

.tabs__btn.is-active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

/* ---------- Layout ---------- */

.layout {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: 280px 1.4fr 1fr;
  min-height: 0;
}

.panel {
  min-height: 0;
  overflow: auto;
  background: var(--panel-bg);
}

.panel--tree {
  border-right: 1px solid var(--border);
  padding: 8px;
}

.panel--figure {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
}

.panel--table {
  padding: 0;
}

/* ---------- Tree ---------- */

.tree { font-size: 13px; }

.tree__catalog > summary {
  font-weight: 700;
  cursor: pointer;
  padding: 4px 2px;
}

.tree__section { margin: 2px 0 8px 4px; }

.tree__section > summary {
  cursor: pointer;
  padding: 4px 2px;
  font-weight: 600;
  color: var(--text);
}

.tree__figures {
  list-style: none;
  margin: 2px 0 2px 14px;
  padding: 0;
}

.tree__figure {
  padding: 4px 6px;
  border-radius: 4px;
  cursor: pointer;
  color: var(--text-muted);
}

.tree__figure:hover { background: #eef3fb; }

.tree__figure.is-active {
  background: var(--accent);
  color: #fff;
}

.tree__empty, .tree__error {
  color: var(--text-muted);
  padding: 8px 4px;
}

/* ---------- Figure viewport ---------- */

.figure-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}

.figure-toolbar__title {
  font-weight: 600;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.figure-toolbar__zoom {
  display: flex;
  gap: 4px;
  flex: 0 0 auto;
}

.figure-toolbar__zoom button {
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  background: var(--panel-bg);
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
}

.figure-toolbar__zoom button:hover { background: #eef3fb; }

.figure-viewport {
  flex: 1 1 auto;
  position: relative;
  overflow: hidden;
  background:
    repeating-conic-gradient(#eceef1 0% 25%, #f6f7f9 0% 50%) 0 0 / 24px 24px;
  cursor: grab;
}

.figure-viewport.is-panning { cursor: grabbing; }

.figure-canvas {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  display: inline-block;
  line-height: 0;
}

#figure-img {
  display: block;
  max-width: none;
  user-select: none;
  -webkit-user-drag: none;
}

#figure-svg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* «Цифра — это ссылка»: в покое выноска НЕ рисуется (цифра выглядит как в
   оригинале каталога), подсветка появляется только при наведении/фокусе.
   Просьба пользователя: не дорисовывать кружки поверх чертежа. */
.hotspot {
  fill: transparent;
  stroke: transparent;
  stroke-width: 1.5;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
  transition: fill 0.15s ease, stroke 0.15s ease;
}

.hotspot-hit {
  fill: transparent;
  stroke: transparent;
  cursor: pointer;
  pointer-events: all;
}

.hotspot-hit:hover + .hotspot,
.hotspot-hit:focus + .hotspot {
  fill: rgba(26, 95, 180, 0.18);
  stroke: var(--accent);
}

.hotspot.hl {
  fill: rgba(232, 169, 0, 0.45);
  stroke: var(--hl-ring);
  stroke-width: 3;
  vector-effect: non-scaling-stroke;
}

.figure-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  margin: 0;
  pointer-events: none;
}

.figure-empty.hidden { display: none; }

/* ---------- Positions table ---------- */

.positions-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.positions-table thead th {
  position: sticky;
  top: 0;
  background: var(--panel-bg);
  text-align: left;
  padding: 8px 10px;
  border-bottom: 2px solid var(--border);
  z-index: 1;
}

.positions-table td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.positions-table tbody tr:hover {
  background: #f8fafc;
}

.positions-table tbody tr.hl {
  background: var(--hl-bg);
}

.col-pos { width: 48px; }
.col-qty { width: 64px; }

.oem-link {
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
  text-decoration-style: dotted;
}

.oem-link:hover { color: var(--accent-hover); }

.name-en {
  color: var(--text-muted);
  font-style: italic;
}

/* Расшифровка сноски «*N» из-под таблицы PDF, показанная в самой строке. */
.footnote {
  display: block;
  margin-top: 2px;
  color: var(--text-muted);
  font-size: 0.85em;
  line-height: 1.3;
}

.positions-empty {
  color: var(--text-muted);
  padding: 12px;
  display: block;
}

/* ---------- Modal ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 20, 26, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.modal-overlay.hidden { display: none; }

.modal {
  position: relative;
  background: var(--panel-bg);
  border-radius: 8px;
  padding: 24px;
  width: min(480px, 92vw);
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}

.modal__close {
  position: absolute;
  top: 10px;
  right: 12px;
  border: none;
  background: none;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  color: var(--text-muted);
}

.modal__close:hover { color: var(--text); }

.modal__oem {
  margin: 0 24px 4px 0;
  font-size: 18px;
}

.modal__name {
  margin: 0 0 16px 0;
  color: var(--text-muted);
}

.modal__subheading {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin: 16px 0 8px 0;
}

.modal__usages {
  list-style: none;
  margin: 0 0 16px 0;
  padding: 0;
  max-height: 220px;
  overflow-y: auto;
}

.modal__usages li {
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}

.modal__usages a {
  color: var(--accent);
  cursor: pointer;
  text-decoration: none;
}

.modal__usages a:hover { text-decoration: underline; }

.modal__usages-empty {
  color: var(--text-muted);
  padding: 6px 0;
}

.btn {
  display: inline-block;
  padding: 9px 18px;
  border-radius: 6px;
  border: none;
  font-size: 14px;
  cursor: pointer;
}

.btn--primary {
  background: var(--accent);
  color: #fff;
}

.btn--primary:hover { background: var(--accent-hover); }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #1b1f24;
  color: #fff;
  padding: 10px 18px;
  border-radius: 6px;
  font-size: 13px;
  z-index: 300;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  transition: opacity 0.2s ease;
}

.toast.hidden { display: none; }

/* ---------- Mobile (<768px): panels become tabs ---------- */

@media (max-width: 767px) {
  .tabs { display: flex; }

  .layout {
    grid-template-columns: 1fr;
    grid-auto-rows: 1fr;
  }

  .panel {
    border-right: none;
    display: none;
  }

  .panel.is-active-tab {
    display: flex;
    flex-direction: column;
  }

  .panel--tree.is-active-tab { display: block; }

  .panel--table.is-active-tab { display: block; }

  .search { max-width: none; }

  .topbar { flex-wrap: wrap; }
}
