/*
 * catalog.css — единые стили каталога UnitService
 * Подключается в base.html ПОСЛЕ {{ theme_style | safe }}
 * Заменяет {% block extra_styles %} в:
 *   rottne_scheme.html, kf_scheme.html, rottne_part.html, kf_part.html
 *   rottne_section.html, kf_section.html, kf_subsection.html и др.
 */

/* ══════════════════════════════════════════════
   LAYOUT — страница схемы / детали
══════════════════════════════════════════════ */

.page {
  padding: 16px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
  margin-bottom: 16px;
}

.title-block h1 {
  margin: 0 0 6px 0;
  font-size: 22px;
  font-weight: 700;
  line-height: 1.2;
}

.title-block .subtitle {
  font-size: 13px;
  color: var(--text-muted);
}

.actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.actions a {
  height: 36px;
  padding: 0 14px;
  border: 1px solid var(--border);
  background: var(--white);
  cursor: pointer;
  text-decoration: none;
  color: var(--graphite);
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  font-family: var(--font-ui, 'IBM Plex Sans'), sans-serif;
  transition: border-color .15s, color .15s;
}

.actions a:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.layout {
  display: flex;
  gap: 20px;
  align-items: flex-start;
}

.layout .left {
  flex: 1 1 auto;
  min-width: 0;
}

.layout .right {
  flex: 0 0 520px;
  width: 520px;
  background: var(--card-bg, #fff);
  border: 1px solid #d8d8d8;
  max-height: calc(100vh - 170px);
  overflow: auto;
  overflow-x: hidden;
  position: sticky;
  top: 16px;
}

/* ══════════════════════════════════════════════
   VIEWER — общие стили вьювера (Rottne SVG + KF PNG)
══════════════════════════════════════════════ */

.viewer-shell {
  background: var(--card-bg, #fff);
  border: 1px solid #d8d8d8;
  position: relative;
}

.viewer-box {
  height: calc(100vh - 260px);
  min-height: 400px;
  overflow: auto;
  position: relative;
  background: var(--card-bg, #fff);
  cursor: grab;
}

.viewer-box.dragging {
  cursor: grabbing;
  user-select: none;
}

.viewer-canvas {
  transform-origin: top left;
  width: fit-content;
  padding: 16px;
  display: inline-block;
}

.viewer-canvas svg {
  display: block;
  width: auto;
  height: auto;
  max-width: none;
  user-select: none;
}

/* Zoom controls — оверлей поверх вьювера */
.viewer-controls {
  display: flex;
  gap: 4px;
  padding: 6px;
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 10;
}

.viewer-controls button {
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.9);
  color: var(--text-secondary, #555);
  cursor: pointer;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  touch-action: manipulation;
  transition: background .15s, color .15s;
}

.viewer-controls button:hover {
  background: var(--card-bg, #fff);
  color: var(--graphite);
  border-color: var(--graphite);
}

/* ══════════════════════════════════════════════
   KF PNG VIEWER — hotspot overlay
══════════════════════════════════════════════ */

.scheme-wrap {
  position: relative;
  display: block;
  width: 100%;
  overflow: hidden;
  background: var(--card-hover, #fafafa);
}

.scheme-wrap img {
  width: 100%;
  display: block;
  user-select: none;
}

#hotspotsLayer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.hotspot-dot {
  position: absolute;
  transform: translate(-50%, -50%);
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: transparent;
  border: 2px solid transparent;
  cursor: pointer;
  pointer-events: all;
  transition: all .15s;
}

.hotspot-dot:hover {
  background: rgba(76, 140, 43, 0.15);
  border-color: var(--accent);
  transform: translate(-50%, -50%) scale(1.2);
}

.hotspot-dot.active {
  background: rgba(200, 80, 0, 0.15);
  border: 2px solid rgba(200, 80, 0, 0.9);
  transform: translate(-50%, -50%) scale(1.2);
}

.hotspot-dot span {
  display: none;
}

/* ══════════════════════════════════════════════
   PARTS TABLE (правая панель схемы)
══════════════════════════════════════════════ */

.right-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border, #ddd);
  background: var(--card-bg, #fff);
}

.right-header h2 {
  margin: 0 0 8px 0;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.1;
}

.filters {
  display: flex;
  gap: 8px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border, #ddd);
  background: var(--card-hover, #fafafa);
}

.filters input {
  flex: 1;
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--border);
  font-size: 14px;
  font-family: var(--font-ui, 'IBM Plex Sans'), sans-serif;
  outline: none;
  transition: border-color .15s;
}

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

.filters button {
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--border);
  background: var(--card-bg, #fff);
  cursor: pointer;
  font-family: var(--font-ui, 'IBM Plex Sans'), sans-serif;
  font-size: 12px;
  transition: border-color .15s;
}

.filters button:hover {
  border-color: var(--accent);
}

.parts-table {
  table-layout: fixed;
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  background: var(--card-bg, #fff);
}

.parts-table th {
  font-size: 12px;
  font-weight: 600;
  color: var(--graphite, #333);
  padding: 8px 10px;
  border-bottom: 1px solid var(--border, #eee);
  background: var(--card-bg, #fff);
  position: sticky;
  top: 0;
  text-align: left;
}

.parts-table tr {
  border-bottom: 1px solid var(--border, #eee);
}

.parts-table td {
  padding: 8px 10px;
  vertical-align: middle;
  text-align: left;
  color: var(--graphite, #333);
}

.parts-table tbody tr:hover td {
  background: #f9fdf5;
  cursor: pointer;
}

.parts-table tbody tr.active-row td {
  background: #fff8e1;
}

.parts-table a {
  text-decoration: none;
  color: var(--accent) !important;
  font-family: var(--font-mono, 'IBM Plex Mono'), monospace;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  word-break: keep-all;
  overflow-wrap: normal;
}

.parts-table a:visited {
  color: var(--accent) !important;
}

.parts-table a:hover {
  text-decoration: underline;
}

/* Кнопка «В корзину» в строке таблицы */
.cart-add-btn {
  background: none;
  border: 1px solid #e0e0e0;
  cursor: pointer;
  padding: 3px 6px;
  opacity: 0;
  border-radius: 2px;
  transition: all .15s;
}

.parts-table tbody tr:hover .cart-add-btn {
  opacity: 1;
}

.cart-add-btn:hover {
  border-color: var(--accent);
}

@media (max-width: 900px) {
  .cart-add-btn {
    opacity: 1 !important;
  }
}

/* Inline-корзина в ячейке (Rottne схема) */
.cart-inline {
  justify-content: center;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  vertical-align: middle;
}

.cart-inline button {
  width: 22px;
  height: 22px;
  border: 1px solid #ddd;
  background: #fff;
  cursor: pointer;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 2px;
}

.cart-inline .qty-val {
  min-width: 18px;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
}

/* ══════════════════════════════════════════════
   SCHEME BANNER — «Запросить у менеджера»
══════════════════════════════════════════════ */

.scheme-banner {
  margin-top: 12px;
  padding: 14px 16px;
  background: #f0f7eb;
  border: 1px solid #c8e6b0;
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.scheme-banner-text {
  font-size: 13px;
  color: var(--graphite);
}

.scheme-banner-btn {
  flex-shrink: 0;
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 8px 18px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border-radius: 2px;
  white-space: nowrap;
  font-family: var(--font-ui, 'IBM Plex Sans'), sans-serif;
  transition: background .15s;
}

.scheme-banner-btn:hover {
  background: var(--accent-light, #5ba332);
}

/* ══════════════════════════════════════════════
   PART PAGE — заголовок детали
══════════════════════════════════════════════ */

.part-header {
  background: var(--white);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  padding: 20px 24px;
  margin-bottom: 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.part-article {
  font-family: var(--font-mono, 'IBM Plex Mono'), monospace;
  font-size: 22px;
  font-weight: 600;
  margin-bottom: 4px;
}

.part-name {
  font-size: 15px;
  color: var(--text-secondary);
}

/* Кнопка «В корзину» на странице детали */
.part-cart-btn {
  background: none;
  border: 1px solid var(--border);
  padding: 8px 16px;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-ui, 'IBM Plex Sans'), sans-serif;
  transition: border-color .15s, color .15s;
}

.part-cart-btn.in-cart {
  border-color: var(--accent);
  color: var(--accent);
}

.part-qty-controls {
  display: none;
  align-items: center;
  gap: 4px;
}

.part-qty-controls.visible {
  display: flex;
}

.part-qty-btn {
  width: 30px;
  height: 34px;
  background: none;
  border: 1px solid var(--border);
  cursor: pointer;
  font-size: 16px;
  color: var(--graphite);
  transition: border-color .15s;
}

.part-qty-btn:hover {
  border-color: var(--accent);
}

.part-qty-num {
  min-width: 28px;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--graphite);
  cursor: pointer;
}

/* ══════════════════════════════════════════════
   USAGE TABLE — «Где используется» на странице детали
══════════════════════════════════════════════ */

.section-label {
  font-family: var(--font-mono, 'IBM Plex Mono'), monospace;
  font-size: 10px;
  color: var(--accent);
  letter-spacing: 3px;
  text-transform: uppercase;
  margin-bottom: 10px;
}

.usage-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--white);
  border: 1px solid var(--border);
}

.usage-table th {
  background: var(--card-hover, #f8f8f8);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  padding: 10px 14px;
  border-bottom: 2px solid var(--border);
  text-align: left;
}

.usage-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  vertical-align: top;
}

.usage-table tr:last-child td {
  border-bottom: none;
}

.usage-table tr:hover td {
  background: var(--card-hover, #fafafa);
}

.usage-table tbody tr[data-href] {
  cursor: pointer;
}

.usage-table tbody tr[data-href]:hover td {
  background: #f0f7eb;
}

.usage-table a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
}

.usage-table a:hover {
  text-decoration: underline;
}

/* ══════════════════════════════════════════════
   SCHEMES LIST — страница секции
══════════════════════════════════════════════ */

.schemes-list {
  list-style: none;
  padding: 0;
  margin: 0;
  background: var(--white);
  border: 1px solid var(--border);
}

.schemes-list li {
  border-bottom: 1px solid var(--border);
}

.schemes-list li:last-child {
  border-bottom: none;
}

.schemes-list a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  text-decoration: none;
  color: var(--graphite);
  transition: background .15s;
  border-left: 3px solid transparent;
}

.schemes-list a:hover {
  background: #f8f8f8;
  border-left-color: var(--accent);
}

.scheme-name {
  font-size: 14px;
  font-weight: 500;
}

.scheme-code {
  font-family: var(--font-mono, 'IBM Plex Mono'), monospace;
  font-size: 11px;
  color: var(--text-muted);
}

.scheme-nosvg {
  font-size: 11px;
  color: #ccc;
}

/* ══════════════════════════════════════════════
   SVG LOADING / EMPTY STATE
══════════════════════════════════════════════ */

.empty-scheme {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.svg-loading {
  padding: 30px 20px;
  color: #999;
  font-size: 16px;
}

/* ══════════════════════════════════════════════
   RESPONSIVE
══════════════════════════════════════════════ */

@media (max-width: 900px) {
  .layout {
    flex-direction: column;
  }

  .layout .left {
    width: 100%;
  }

  .layout .right {
    flex: none;
    width: 100%;
    max-height: none;
    position: static;
  }

  .viewer-box {
    height: 60vw;
    min-height: 300px;
  }

  .page {
    padding: 8px;
  }
}

@media (max-width: 600px) {
  .viewer-box {
    height: 80vw;
    min-height: 260px;
  }

  .right-header h2 {
    font-size: 15px;
  }

  .parts-table th,
  .parts-table td {
    padding: 6px 6px;
    font-size: 12px;
  }
}
