:root {
  --bg: #0f1218;
  --surface: #1a1f2a;
  --text: #e8eaef;
  --muted: #8b93a7;
  --accent: #3d8b6e;
  --accent-dim: #2d6b55;
  --danger: #c45c5c;
  --radius: 10px;
  --border: #2a3140;
  --border-input: #3a4255;
  --border-panel: #323a4a;
  --row-hover: #141924;
  --row-hover-alt: #1a2430;
  --row-selected: #243044;
  --row-linked: #1a2e26;
  --row-linked-hover: #1f362c;
  --row-focus: #1b2231;
  --link-accent: #9ec4b0;
  --link-accent-hover: #c9f0dc;
  --linked-accent: #4a8f6f;
  --card-img-bg: #12161e;
  --code-fg: #b8c0d4;
  --stat-heading: #e8ecf4;
  --stat-cat-title: #c8d0e0;
  --nav-pill-bg: #252b38;
  --placeholder-fg: #5c6478;
  --stats-table-block-bg: rgba(0, 0, 0, 0.15);
  --panel-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  --parse-ok-fg: #7dd4b0;
  --parse-err-fg: #e89898;
  --card-hover-border: #3d8b6e66;
  --focus-ring: rgba(106, 165, 255, 0.33);
  --stats-nav-bg: linear-gradient(180deg, rgba(15, 18, 24, 0.97) 0%, rgba(15, 18, 24, 0.92) 100%);
  --stats-nav-shadow: 0 4px 20px rgba(0, 0, 0, 0.45);
  --nav-link-hover-fg: #fff;
  --photo-focus-outline: #6aa5ff55;
  --badge-fg: #c5cad8;
  color-scheme: dark;
  font-family: "Segoe UI", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

.header {
  padding: 1.25rem 1.5rem 0.5rem;
  border-bottom: 1px solid var(--border);
}

h1 {
  margin: 0 0 0.35rem;
  font-size: 1.5rem;
  font-weight: 600;
}

.sub {
  margin: 0 0 1rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.sub code {
  color: var(--code-fg);
  word-break: break-all;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.btn {
  border: none;
  border-radius: var(--radius);
  padding: 0.55rem 1rem;
  font-size: 0.9rem;
  cursor: pointer;
  color: var(--text);
}

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

.btn.secondary {
  background: var(--surface);
  border: 1px solid var(--border-input);
}
.btn.secondary:hover {
  border-color: var(--muted);
}

.status {
  min-height: 1.4rem;
  font-size: 0.9rem;
  color: var(--muted);
}
.status.err {
  color: var(--danger);
}

.parse-banner {
  margin: 0.75rem 1.5rem 0;
  padding: 0.85rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border-input);
  background: var(--surface);
  max-width: 52rem;
}

.parse-banner--running {
  border-color: rgba(61, 139, 110, 0.45);
  background: rgba(61, 139, 110, 0.08);
}

.parse-banner--success {
  border-color: rgba(61, 139, 110, 0.55);
  background: rgba(61, 139, 110, 0.12);
}

.parse-banner--error {
  border-color: rgba(196, 92, 92, 0.5);
  background: rgba(196, 92, 92, 0.1);
}

.parse-banner-inner {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
}

.parse-spinner {
  flex-shrink: 0;
  width: 1.35rem;
  height: 1.35rem;
  margin-top: 0.15rem;
  border: 2px solid var(--border-input);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: parse-spin 0.75s linear infinite;
}

@keyframes parse-spin {
  to {
    transform: rotate(360deg);
  }
}

.parse-banner-copy {
  flex: 1;
  min-width: 0;
}

.parse-banner-title {
  display: block;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.25rem;
}

.parse-banner--success .parse-banner-title {
  color: var(--parse-ok-fg);
}

.parse-banner--error .parse-banner-title {
  color: var(--parse-err-fg);
}

.parse-banner-detail {
  margin: 0;
  font-size: 0.88rem;
  color: var(--muted);
  line-height: 1.45;
}

.filters {
  padding: 0.75rem 1.5rem;
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.filters label {
  cursor: pointer;
  user-select: none;
}

.gallery-bulk {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1rem;
  padding: 0 1.5rem 0.75rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.gallery-bulk__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.gallery-bulk__selectall {
  cursor: pointer;
  user-select: none;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 0.75rem;
  padding: 0.75rem 1.5rem 2rem;
}

.empty {
  grid-column: 1 / -1;
  color: var(--muted);
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  border: 1px solid transparent;
  transition: border-color 0.15s;
}

.card:hover {
  border-color: var(--card-hover-border);
}

.card--selected {
  border-color: var(--card-hover-border);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--card-hover-border) 45%, transparent);
}

.card__img-wrap {
  position: relative;
}

.card__img-wrap img {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  background: var(--card-img-bg);
}

.card__checkbox {
  position: absolute;
  top: 0.4rem;
  left: 0.4rem;
  z-index: 2;
  width: 1.15rem;
  height: 1.15rem;
  cursor: pointer;
}

.cap {
  padding: 0.45rem 0.5rem 0.55rem;
  font-size: 0.75rem;
}

.badge {
  display: inline-block;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  background: var(--border);
  color: var(--badge-fg);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.badge-muted { background: var(--border); color: var(--badge-fg); }
.badge-ok { background: var(--row-linked-hover); color: #bfe6d1; border: 1px solid #4a8f6f55; }
.badge-warn { background: #3a2f1e; color: #f0d6a8; border: 1px solid #b98b2a55; }
.badge-err { background: #3a2020; color: #f0b3b3; border: 1px solid #c45c5c55; }

.fname {
  color: var(--muted);
  word-break: break-all;
}

.lightbox {
  border: none;
  padding: 0;
  max-width: 96vw;
  max-height: 96vh;
  background: #000000ee;
}

.lightbox::backdrop {
  background: rgba(0, 0, 0, 0.75);
}

.lightbox img {
  display: block;
  max-width: 96vw;
  max-height: 92vh;
  width: auto;
  height: auto;
}

.lightbox-close {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 2;
  width: 2.5rem;
  height: 2.5rem;
  border: none;
  border-radius: 50%;
  background: #fff2;
  color: #fff;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}

.lightbox-close:hover {
  background: #fff4;
}

/* Верхняя полоса: вкладки + тема */
.app-topbar {
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: 0.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.app-topbar .tabs {
  flex: 1;
  min-width: 0;
  border-bottom: none;
}

.theme-switch-wrap {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0 1rem 0 0.35rem;
}

.theme-switch-label {
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  max-width: 4.2rem;
  line-height: 1.15;
  text-align: center;
}

.theme-switch-label--strong {
  color: var(--text);
  font-weight: 600;
}

.theme-toggle {
  position: relative;
  width: 2.75rem;
  height: 1.5rem;
  flex-shrink: 0;
  border-radius: 999px;
  border: 1px solid var(--border-input);
  background: var(--row-hover-alt);
  cursor: pointer;
  padding: 0;
  transition: background 0.2s, border-color 0.2s;
}

.theme-toggle:hover {
  border-color: var(--muted);
}

.theme-toggle[aria-checked="true"] {
  background: var(--accent);
  border-color: var(--accent-dim);
}

.theme-toggle-knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: calc(1.5rem - 6px);
  height: calc(1.5rem - 6px);
  border-radius: 50%;
  background: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
  transition: transform 0.2s ease, background 0.2s;
  pointer-events: none;
}

.theme-toggle[aria-checked="true"] .theme-toggle-knob {
  transform: translateX(1.2rem);
  background: #fff;
}

@media (max-width: 520px) {
  .theme-switch-label {
    display: none;
  }
  .theme-switch-wrap {
    padding-right: 0.65rem;
  }
}

/* Вкладки */
.tabs {
  display: flex;
  gap: 0;
  padding: 0 1.5rem;
  background: transparent;
}

.tab {
  display: inline-block;
  padding: 0.75rem 1.25rem;
  color: var(--muted);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

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

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

/* Таблицы замеров — две колонки */
.measurements-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 1rem 1.25rem;
  padding: 0 1.5rem 2rem;
  align-items: start;
}

@media (max-width: 1100px) {
  .measurements-grid {
    grid-template-columns: 1fr;
  }
}

.table-section {
  padding: 0;
  min-width: 0;
}

.table-heading {
  margin: 0 0 0.75rem;
  font-size: 1.1rem;
  font-weight: 600;
}

.table-heading .hint {
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--muted);
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.table-wrap--scroll {
  max-height: min(70vh, 720px);
  overflow-y: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.data-table th,
.data-table td {
  padding: 0.5rem 0.65rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.data-table th {
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}

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

.data-table tbody tr:hover td {
  background: var(--row-hover);
}

.cell-text {
  max-width: 28rem;
  word-break: break-word;
}

.group-row {
  cursor: pointer;
}

.group-row:hover td {
  background: var(--row-hover-alt);
}

.group-row.selected td {
  background: var(--row-selected);
  box-shadow: inset 3px 0 0 var(--accent);
}

tr.photo-row {
  cursor: pointer;
}

tr.photo-row:hover td {
  background: var(--row-hover-alt);
}

tr.photo-row.photo-linked td {
  background: var(--row-linked);
  box-shadow: inset 3px 0 0 var(--linked-accent);
}

tr.photo-row.photo-linked:hover td {
  background: var(--row-linked-hover);
}

tr.photo-row td.cell-photo-path {
  color: var(--link-accent);
}

button.file-link {
  border: none;
  background: transparent;
  padding: 0;
  margin: 0;
  cursor: pointer;
  color: var(--link-accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

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

tr.photo-row.photo-focus td {
  outline: 1px solid var(--photo-focus-outline);
  background: var(--row-focus);
}

.moysklad-block {
  margin-top: 1rem;
  display: grid;
  gap: 0.75rem;
}

.table-wrap--small {
  max-height: min(32vh, 360px);
}

tr.ms-row {
  cursor: pointer;
}

tr.ms-row:hover td {
  background: var(--row-hover-alt);
}

/* Превью фото — компактное окно */
.photo-preview {
  position: relative;
  border: 1px solid var(--border-input);
  border-radius: var(--radius);
  padding: 0;
  width: min(92vw, 980px);
  height: min(90vh, 820px);
  background: var(--surface);
  color: var(--text);
  display: flex;
  flex-direction: column;
  resize: both;
  overflow: hidden;
}

.photo-preview::backdrop {
  background: rgba(0, 0, 0, 0.65);
}

.photo-preview-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--border);
  cursor: grab;
  user-select: none;
}

.photo-preview-bar:active {
  cursor: grabbing;
}

.photo-preview-title {
  font-size: 0.85rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 70vw;
}

.photo-preview-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 0;
  flex: 1;
  min-height: 0;
  height: 100%;
}

@media (max-width: 980px) {
  .photo-preview-body {
    grid-template-columns: 1fr;
  }
}

.photo-preview-viewport {
  position: relative;
  width: 100%;
  flex: 1;
  min-height: 280px;
  overflow: hidden;
  background: var(--card-img-bg);
}

.photo-preview-side {
  border-left: 1px solid var(--border);
  padding: 0.75rem 0.8rem;
  overflow: auto;
}

@media (max-width: 980px) {
  .photo-preview-side {
    border-left: none;
    border-top: 1px solid var(--border);
  }
}

.side-title {
  margin: 0 0 0.4rem;
  font-size: 1rem;
  font-weight: 600;
}

.side-sub {
  margin: 0 0 0.75rem;
  color: var(--muted);
  font-size: 0.85rem;
  min-height: 1.2rem;
}

.side-block {
  margin-bottom: 0.85rem;
}

.side-label {
  color: var(--muted);
  font-size: 0.75rem;
  margin-bottom: 0.3rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.side-value {
  font-size: 1rem;
  font-weight: 600;
}

.side-table-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.side-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.side-table th,
.side-table td {
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.side-table th {
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}

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

.photo-preview img {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(1);
  transform-origin: center center;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
  cursor: grab;
}

.photo-preview-viewport:active img {
  cursor: grabbing;
}

.photo-preview-close {
  position: relative;
  z-index: 2;
  width: 2rem;
  height: 2rem;
  border: none;
  border-radius: 50%;
  background: var(--border);
  color: var(--text);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
}

.photo-preview-close:hover {
  background: var(--border-input);
}

.stats-toolbar {
  align-items: center;
}

.stats-label {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.stats-select {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-input);
  border-radius: var(--radius);
  padding: 0.45rem 0.75rem;
  font-size: 0.9rem;
}

.catalog-toolbar {
  align-items: center;
}

.catalog-search {
  min-width: 280px;
  max-width: min(100%, 420px);
}

.meas-filter-row th {
  padding: 0.35rem 0.45rem;
  vertical-align: middle;
  font-weight: normal;
}

.meas-col-filter {
  width: 100%;
  min-width: 3rem;
  max-width: 100%;
  box-sizing: border-box;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-input);
  border-radius: 6px;
  padding: 0.3rem 0.4rem;
  font-size: 0.78rem;
}

.meas-col-filter::placeholder {
  color: var(--placeholder-fg);
}

.np-cell {
  width: 100%;
  background: transparent;
  color: var(--text);
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0.25rem 0.35rem;
  font-size: 0.85rem;
}

.np-cell:focus {
  outline: none;
  border-color: var(--border-input);
  background: var(--row-hover);
}

.stats-section {
  padding: 0 1.5rem 1.5rem;
}

.stats-hint {
  margin-top: 0;
  margin-bottom: 0.75rem;
}

.stats-cat-title {
  font-size: 1.05rem;
  font-weight: 600;
  margin: 1.25rem 0 0.5rem;
  color: var(--stat-cat-title);
}

.stats-row-rollup td {
  background: rgba(61, 139, 110, 0.12);
  border-top: 1px solid var(--border);
}

.stats-chart-wrap {
  max-width: 100%;
  padding: 0.5rem 0 1rem;
}

.cell-muted {
  color: var(--muted);
  font-size: 0.82rem;
  vertical-align: middle;
}

.stats-section--layout {
  padding-left: 0;
  padding-right: 0;
  max-width: none;
  width: 100%;
}

.stats-layout-with-nav {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.stats-cat-nav {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 0.5rem 1rem;
  padding: 0.65rem 1rem;
  margin: 0;
  background: var(--stats-nav-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--stats-nav-shadow);
  backdrop-filter: blur(8px);
}

.stats-cat-nav[hidden] {
  display: none !important;
}

.stats-cat-nav-label {
  flex-shrink: 0;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding-top: 0.35rem;
}

.stats-cat-nav-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  flex: 1;
  min-width: 0;
}

.stats-cat-nav-link {
  display: inline-block;
  max-width: 100%;
  padding: 0.4rem 0.75rem;
  font-size: 0.78rem;
  line-height: 1.3;
  color: var(--text);
  text-decoration: none;
  background: var(--nav-pill-bg);
  border: 1px solid var(--border-input);
  border-radius: 8px;
  transition: background 0.15s, border-color 0.15s;
}

.stats-cat-nav-link:hover {
  filter: brightness(1.15);
  color: var(--nav-link-hover-fg);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.12);
}

.stats-layout-heading {
  padding: 0 1.25rem;
}

.stats-layout-full {
  width: 100%;
  max-width: none;
  padding: 0 1rem;
  box-sizing: border-box;
}

.stats-pair {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  margin-bottom: 2.5rem;
  padding-bottom: 2rem;
  border-bottom: 1px solid var(--border);
  scroll-margin-top: 5.5rem;
}

.stats-pair:last-child {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

.stats-pair-panel {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--border-panel);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
  box-shadow: var(--panel-shadow);
}

.stats-pair-panel--a,
.stats-pair-panel--b {
  border-left-width: 4px;
  border-left-style: solid;
}

.stats-pair-chart {
  width: 100%;
  box-sizing: border-box;
  padding-top: 0.35rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--panel-shadow);
  overflow: hidden;
}

.stats-pair-chart-summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
}

.stats-pair-chart-summary::-webkit-details-marker {
  display: none;
}

.stats-pair-chart-meta {
  color: var(--muted);
  font-size: 0.85rem;
  flex-shrink: 0;
}

.stats-pair-chart-body {
  padding: 0.75rem 1rem 1rem;
}

.stats-pair-chart-title {
  font-size: 1rem;
  font-weight: 600;
  margin: 0;
  color: var(--stat-heading);
  letter-spacing: 0.02em;
}

.stats-pair-chart .stats-hint {
  margin-bottom: 0.75rem;
}

.stats-pair-panel-head {
  padding: 0.9rem 1.25rem;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--stat-heading);
  letter-spacing: 0.02em;
  border-bottom: 1px solid var(--border);
}

/* Темы пар блоков (цикл 0…5): левая / правая панель разного оттенка */
.stats-pair-theme-0 .stats-pair-panel--a {
  border-left-color: #3d8b6e;
  background: rgba(61, 139, 110, 0.08);
}
.stats-pair-theme-0 .stats-pair-panel--b {
  border-left-color: #5b8fae;
  background: rgba(91, 143, 174, 0.08);
}
.stats-pair-theme-0 .stats-pair-panel--a .stats-pair-panel-head {
  background: linear-gradient(180deg, rgba(61, 139, 110, 0.28) 0%, rgba(26, 31, 42, 0.96) 100%);
}
.stats-pair-theme-0 .stats-pair-panel--b .stats-pair-panel-head {
  background: linear-gradient(180deg, rgba(91, 143, 174, 0.26) 0%, rgba(26, 31, 42, 0.96) 100%);
}
.stats-pair-theme-0 .stats-pair-panel--a .stats-table-block {
  border-color: rgba(61, 139, 110, 0.4);
  background: rgba(61, 139, 110, 0.04);
}
.stats-pair-theme-0 .stats-pair-panel--b .stats-table-block {
  border-color: rgba(91, 143, 174, 0.4);
  background: rgba(91, 143, 174, 0.04);
}
.stats-pair-theme-0 .stats-pair-panel--a .stats-tier-total td {
  background: rgba(61, 139, 110, 0.14);
}
.stats-pair-theme-0 .stats-pair-panel--b .stats-tier-total td {
  background: rgba(91, 143, 174, 0.14);
}
.stats-pair-theme-0 .stats-pair-panel--a .stats-mini-k {
  color: #5cb896;
}
.stats-pair-theme-0 .stats-pair-panel--b .stats-mini-k {
  color: #7eb8d4;
}

.stats-pair-theme-1 .stats-pair-panel--a {
  border-left-color: #c9a227;
  background: rgba(201, 162, 39, 0.1);
}
.stats-pair-theme-1 .stats-pair-panel--b {
  border-left-color: #b87333;
  background: rgba(184, 115, 51, 0.1);
}
.stats-pair-theme-1 .stats-pair-panel--a .stats-pair-panel-head {
  background: linear-gradient(180deg, rgba(201, 162, 39, 0.3) 0%, rgba(26, 31, 42, 0.96) 100%);
}
.stats-pair-theme-1 .stats-pair-panel--b .stats-pair-panel-head {
  background: linear-gradient(180deg, rgba(184, 115, 51, 0.28) 0%, rgba(26, 31, 42, 0.96) 100%);
}
.stats-pair-theme-1 .stats-pair-panel--a .stats-table-block {
  border-color: rgba(201, 162, 39, 0.45);
  background: rgba(201, 162, 39, 0.05);
}
.stats-pair-theme-1 .stats-pair-panel--b .stats-table-block {
  border-color: rgba(184, 115, 51, 0.45);
  background: rgba(184, 115, 51, 0.05);
}
.stats-pair-theme-1 .stats-pair-panel--a .stats-tier-total td {
  background: rgba(201, 162, 39, 0.16);
}
.stats-pair-theme-1 .stats-pair-panel--b .stats-tier-total td {
  background: rgba(184, 115, 51, 0.16);
}
.stats-pair-theme-1 .stats-pair-panel--a .stats-mini-k {
  color: #e4c04a;
}
.stats-pair-theme-1 .stats-pair-panel--b .stats-mini-k {
  color: #d4a574;
}

.stats-pair-theme-2 .stats-pair-panel--a {
  border-left-color: #9b6bb8;
  background: rgba(155, 107, 184, 0.1);
}
.stats-pair-theme-2 .stats-pair-panel--b {
  border-left-color: #6b8cc9;
  background: rgba(107, 140, 201, 0.1);
}
.stats-pair-theme-2 .stats-pair-panel--a .stats-pair-panel-head {
  background: linear-gradient(180deg, rgba(155, 107, 184, 0.3) 0%, rgba(26, 31, 42, 0.96) 100%);
}
.stats-pair-theme-2 .stats-pair-panel--b .stats-pair-panel-head {
  background: linear-gradient(180deg, rgba(107, 140, 201, 0.28) 0%, rgba(26, 31, 42, 0.96) 100%);
}
.stats-pair-theme-2 .stats-pair-panel--a .stats-table-block {
  border-color: rgba(155, 107, 184, 0.45);
  background: rgba(155, 107, 184, 0.05);
}
.stats-pair-theme-2 .stats-pair-panel--b .stats-table-block {
  border-color: rgba(107, 140, 201, 0.45);
  background: rgba(107, 140, 201, 0.05);
}
.stats-pair-theme-2 .stats-pair-panel--a .stats-tier-total td {
  background: rgba(155, 107, 184, 0.16);
}
.stats-pair-theme-2 .stats-pair-panel--b .stats-tier-total td {
  background: rgba(107, 140, 201, 0.16);
}
.stats-pair-theme-2 .stats-pair-panel--a .stats-mini-k {
  color: #c49bdc;
}
.stats-pair-theme-2 .stats-pair-panel--b .stats-mini-k {
  color: #94b8e8;
}

.stats-pair-theme-3 .stats-pair-panel--a {
  border-left-color: #d4705c;
  background: rgba(212, 112, 92, 0.1);
}
.stats-pair-theme-3 .stats-pair-panel--b {
  border-left-color: #c9a227;
  background: rgba(201, 162, 39, 0.08);
}
.stats-pair-theme-3 .stats-pair-panel--a .stats-pair-panel-head {
  background: linear-gradient(180deg, rgba(212, 112, 92, 0.3) 0%, rgba(26, 31, 42, 0.96) 100%);
}
.stats-pair-theme-3 .stats-pair-panel--b .stats-pair-panel-head {
  background: linear-gradient(180deg, rgba(201, 162, 39, 0.3) 0%, rgba(26, 31, 42, 0.96) 100%);
}
.stats-pair-theme-3 .stats-pair-panel--a .stats-table-block {
  border-color: rgba(212, 112, 92, 0.45);
  background: rgba(212, 112, 92, 0.05);
}
.stats-pair-theme-3 .stats-pair-panel--b .stats-table-block {
  border-color: rgba(201, 162, 39, 0.45);
  background: rgba(201, 162, 39, 0.05);
}
.stats-pair-theme-3 .stats-pair-panel--a .stats-tier-total td {
  background: rgba(212, 112, 92, 0.16);
}
.stats-pair-theme-3 .stats-pair-panel--b .stats-tier-total td {
  background: rgba(201, 162, 39, 0.16);
}
.stats-pair-theme-3 .stats-pair-panel--a .stats-mini-k {
  color: #e89888;
}
.stats-pair-theme-3 .stats-pair-panel--b .stats-mini-k {
  color: #e4c04a;
}

.stats-pair-theme-4 .stats-pair-panel--a {
  border-left-color: #3d9e9a;
  background: rgba(61, 158, 154, 0.1);
}
.stats-pair-theme-4 .stats-pair-panel--b {
  border-left-color: #4a8fb8;
  background: rgba(74, 143, 184, 0.1);
}
.stats-pair-theme-4 .stats-pair-panel--a .stats-pair-panel-head {
  background: linear-gradient(180deg, rgba(61, 158, 154, 0.3) 0%, rgba(26, 31, 42, 0.96) 100%);
}
.stats-pair-theme-4 .stats-pair-panel--b .stats-pair-panel-head {
  background: linear-gradient(180deg, rgba(74, 143, 184, 0.28) 0%, rgba(26, 31, 42, 0.96) 100%);
}
.stats-pair-theme-4 .stats-pair-panel--a .stats-table-block {
  border-color: rgba(61, 158, 154, 0.45);
  background: rgba(61, 158, 154, 0.05);
}
.stats-pair-theme-4 .stats-pair-panel--b .stats-table-block {
  border-color: rgba(74, 143, 184, 0.45);
  background: rgba(74, 143, 184, 0.05);
}
.stats-pair-theme-4 .stats-pair-panel--a .stats-tier-total td {
  background: rgba(61, 158, 154, 0.16);
}
.stats-pair-theme-4 .stats-pair-panel--b .stats-tier-total td {
  background: rgba(74, 143, 184, 0.16);
}
.stats-pair-theme-4 .stats-pair-panel--a .stats-mini-k {
  color: #5ed4cf;
}
.stats-pair-theme-4 .stats-pair-panel--b .stats-mini-k {
  color: #7ec4e8;
}

.stats-pair-theme-5 .stats-pair-panel--a {
  border-left-color: #c45c8c;
  background: rgba(196, 92, 140, 0.1);
}
.stats-pair-theme-5 .stats-pair-panel--b {
  border-left-color: #8a6bc9;
  background: rgba(138, 107, 201, 0.1);
}
.stats-pair-theme-5 .stats-pair-panel--a .stats-pair-panel-head {
  background: linear-gradient(180deg, rgba(196, 92, 140, 0.3) 0%, rgba(26, 31, 42, 0.96) 100%);
}
.stats-pair-theme-5 .stats-pair-panel--b .stats-pair-panel-head {
  background: linear-gradient(180deg, rgba(138, 107, 201, 0.28) 0%, rgba(26, 31, 42, 0.96) 100%);
}
.stats-pair-theme-5 .stats-pair-panel--a .stats-table-block {
  border-color: rgba(196, 92, 140, 0.45);
  background: rgba(196, 92, 140, 0.05);
}
.stats-pair-theme-5 .stats-pair-panel--b .stats-table-block {
  border-color: rgba(138, 107, 201, 0.45);
  background: rgba(138, 107, 201, 0.05);
}
.stats-pair-theme-5 .stats-pair-panel--a .stats-tier-total td {
  background: rgba(196, 92, 140, 0.16);
}
.stats-pair-theme-5 .stats-pair-panel--b .stats-tier-total td {
  background: rgba(138, 107, 201, 0.16);
}
.stats-pair-theme-5 .stats-pair-panel--a .stats-mini-k {
  color: #e88ab8;
}
.stats-pair-theme-5 .stats-pair-panel--b .stats-mini-k {
  color: #b8a0f0;
}

/* Кнопки меню категорий в цвет темы */
.stats-cat-nav-link--theme-0 {
  border-color: rgba(61, 139, 110, 0.55);
  background: rgba(61, 139, 110, 0.12);
}
.stats-cat-nav-link--theme-1 {
  border-color: rgba(201, 162, 39, 0.55);
  background: rgba(201, 162, 39, 0.12);
}
.stats-cat-nav-link--theme-2 {
  border-color: rgba(155, 107, 184, 0.55);
  background: rgba(155, 107, 184, 0.12);
}
.stats-cat-nav-link--theme-3 {
  border-color: rgba(212, 112, 92, 0.55);
  background: rgba(212, 112, 92, 0.12);
}
.stats-cat-nav-link--theme-4 {
  border-color: rgba(61, 158, 154, 0.55);
  background: rgba(61, 158, 154, 0.12);
}
.stats-cat-nav-link--theme-5 {
  border-color: rgba(196, 92, 140, 0.55);
  background: rgba(196, 92, 140, 0.12);
}

.stats-pair-panel-body {
  padding: 1rem 1.25rem 1.35rem;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1.15rem;
  min-width: 0;
  overflow-x: auto;
}

.stats-table-block {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem;
  background: var(--stats-table-block-bg);
}

.stats-mini-sep td {
  padding: 0.35rem 0.55rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  background: rgba(42, 49, 64, 0.35);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.stats-pair-total {
  width: 100%;
  padding: 0 1rem;
  box-sizing: border-box;
  display: flex;
  justify-content: center;
}

.stats-pair-total .stats-table-block {
  width: min(980px, 100%);
}

.stats-pair-total--top {
  margin-top: 0.15rem;
}

@media (max-width: 1100px) {
  .stats-pair-panel-body {
    grid-template-columns: 1fr;
  }
}

.stats-sub-block {
  margin-bottom: 0.75rem;
}

.stats-sub-block:last-child {
  margin-bottom: 0;
}

.stats-sub-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

.stats-mini-head {
  font-size: 0.85rem;
  color: var(--code-fg);
  margin-bottom: 0.35rem;
}

.stats-mini-k {
  color: var(--accent);
  font-weight: 600;
}

.stats-mini {
  font-size: 0.78rem;
  min-width: 520px;
}

.stats-mini th,
.stats-mini td {
  white-space: nowrap;
}

.th-gr {
  text-align: center;
  background: rgba(42, 49, 64, 0.6);
}

/* Статистика: колонки подписано / не подписано */
.stats-col-signed,
#tbl-top-summary th.stats-col-signed,
#tbl-global th.stats-col-signed {
  background: rgba(61, 139, 110, 0.14);
  box-shadow: inset 0 0 0 1px rgba(61, 139, 110, 0.22);
}

.stats-col-unsigned,
#tbl-top-summary th.stats-col-unsigned,
#tbl-global th.stats-col-unsigned {
  background: rgba(180, 130, 70, 0.12);
  box-shadow: inset 0 0 0 1px rgba(180, 130, 70, 0.2);
}

.stats-mini th.th-signed-group,
.stats-mini tr.tr-subhead th.stats-col-signed {
  background: rgba(61, 139, 110, 0.16);
  color: #c5e8d8;
  box-shadow: inset 0 0 0 1px rgba(61, 139, 110, 0.25);
}

.stats-mini th.th-unsigned-group,
.stats-mini tr.tr-subhead th.stats-col-unsigned {
  background: rgba(180, 130, 70, 0.14);
  color: #e8d4b8;
  box-shadow: inset 0 0 0 1px rgba(180, 130, 70, 0.22);
}

.stats-mini td.stats-col-signed {
  background: rgba(61, 139, 110, 0.08);
}

.stats-mini td.stats-col-unsigned {
  background: rgba(180, 130, 70, 0.07);
}

.stats-mini tbody tr:hover td.stats-col-signed {
  background: rgba(61, 139, 110, 0.14);
}

.stats-mini tbody tr:hover td.stats-col-unsigned {
  background: rgba(180, 130, 70, 0.11);
}

#tbl-top-summary tbody tr:hover td.stats-col-signed,
#tbl-global tbody tr:hover td.stats-col-signed {
  background: rgba(61, 139, 110, 0.12);
}

#tbl-top-summary tbody tr:hover td.stats-col-unsigned,
#tbl-global tbody tr:hover td.stats-col-unsigned {
  background: rgba(180, 130, 70, 0.1);
}

.stats-pair-panel .stats-mini tbody tr.stats-tier-total td.stats-col-signed {
  background: rgba(61, 139, 110, 0.22);
}

.stats-pair-panel .stats-mini tbody tr.stats-tier-total td.stats-col-unsigned {
  background: rgba(180, 130, 70, 0.17);
}

.tr-subhead th {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
}

.stats-tier-total td {
  font-weight: 600;
}

.stats-click {
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.stats-photos {
  border: 1px solid var(--border-input);
  border-radius: var(--radius);
  padding: 0;
  width: min(96vw, 1180px);
  height: min(90vh, 840px);
  background: var(--surface);
  color: var(--text);
  overflow: hidden;
}

.stats-photos::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

.stats-photos-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

.stats-photos-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
}

.stats-photos-body {
  padding: 0.75rem;
}

.stats-photos-body--split {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 0.75rem;
  height: calc(100% - 0px);
}

@media (max-width: 980px) {
  .stats-photos-body--split {
    grid-template-columns: 1fr;
  }
}

.stats-photos-left {
  min-height: 0;
  overflow: auto;
  padding-right: 0.25rem;
}

.stats-photos-right {
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.photo-preview-body--stats {
  height: 100%;
}

.stats-photos-hint {
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 0.75rem;
}

.stats-photos-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem;
}

@media (max-width: 520px) {
  .stats-photos-list {
    grid-template-columns: 1fr;
  }
}

/* ——— Светлая тема ——— */
html[data-theme="light"] {
  color-scheme: light;
  --bg: #eceff4;
  --surface: #ffffff;
  --text: #161a22;
  --muted: #5a6270;
  --accent: #2d7359;
  --accent-dim: #235a48;
  --danger: #b03d3d;
  --border: #c9d0e0;
  --border-input: #a8b0c4;
  --border-panel: #bcc4d6;
  --row-hover: #f0f2f8;
  --row-hover-alt: #e8ecf4;
  --row-selected: #dbe4f2;
  --row-linked: #e3f4ec;
  --row-linked-hover: #d0ede0;
  --row-focus: #e5ecf8;
  --link-accent: #1d6b4e;
  --link-accent-hover: #145a42;
  --linked-accent: #2a8f62;
  --card-img-bg: #e6e9f0;
  --code-fg: #3d4b60;
  --stat-heading: #1e2430;
  --stat-cat-title: #3d4759;
  --nav-pill-bg: #eef1f7;
  --placeholder-fg: #7a8395;
  --stats-table-block-bg: rgba(0, 0, 0, 0.04);
  --panel-shadow: 0 8px 28px rgba(15, 23, 42, 0.08);
  --parse-ok-fg: #1f7a52;
  --parse-err-fg: #b03030;
  --card-hover-border: rgba(45, 115, 89, 0.45);
  --focus-ring: rgba(37, 99, 235, 0.35);
  --stats-nav-bg: linear-gradient(180deg, rgba(255, 255, 255, 0.98) 0%, rgba(245, 247, 252, 0.96) 100%);
  --stats-nav-shadow: 0 4px 16px rgba(15, 23, 42, 0.07);
  --nav-link-hover-fg: #111318;
  --photo-focus-outline: rgba(37, 99, 235, 0.45);
  --badge-fg: #4a5568;
}

html[data-theme="light"] .stats-cat-nav-link:hover {
  filter: none;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.08);
}

html[data-theme="light"] .badge {
  background: #e2e6ef;
  color: var(--badge-fg);
}

html[data-theme="light"] .badge-muted {
  background: #e2e6ef;
  color: var(--badge-fg);
}

html[data-theme="light"] .badge-ok {
  background: #d8f0e5;
  color: #145a3a;
  border: 1px solid rgba(42, 143, 98, 0.35);
}

html[data-theme="light"] .badge-warn {
  background: #fdf3d9;
  color: #6b5410;
  border: 1px solid rgba(185, 139, 42, 0.35);
}

html[data-theme="light"] .badge-err {
  background: #fde8e8;
  color: #8f2a2a;
  border: 1px solid rgba(196, 92, 92, 0.35);
}

html[data-theme="light"] .th-gr {
  background: rgba(90, 98, 120, 0.12);
}

html[data-theme="light"] .stats-mini th.th-signed-group,
html[data-theme="light"] .stats-mini tr.tr-subhead th.stats-col-signed {
  color: #0d4d32;
}

html[data-theme="light"] .stats-mini th.th-unsigned-group,
html[data-theme="light"] .stats-mini tr.tr-subhead th.stats-col-unsigned {
  color: #6b4818;
}

html[data-theme="light"] .theme-toggle[aria-checked="false"] .theme-toggle-knob {
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

html[data-theme="light"] [class*="stats-pair-theme-"] .stats-pair-panel--a .stats-pair-panel-head,
html[data-theme="light"] [class*="stats-pair-theme-"] .stats-pair-panel--b .stats-pair-panel-head {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.9) 0%, rgba(236, 240, 247, 0.98) 100%) !important;
  color: var(--text);
  border-bottom-color: var(--border);
}
