:root {
  --bg: #0f1419;
  --bg-panel: #161b22;
  --bg-elevated: #1c2330;
  --border: #2d3640;
  --text: #e8ecf1;
  --text-muted: #8b9aab;
  --accent: #e8a838;
  --accent-dim: rgba(232, 168, 56, 0.15);
  --tier-a: #3dd68c;
  --tier-b: #5b9cf5;
  --verified: #7c6cf0;
  --danger: #f07178;
  --radius: 10px;
  --font: "DM Sans", system-ui, sans-serif;
  --mono: "JetBrains Mono", monospace;
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

.app {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
}

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 100; transform: translateX(-100%); transition: transform 0.2s; }
  .sidebar.open { transform: translateX(0); }
}

/* Sidebar */
.sidebar {
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1.25rem;
  gap: 1rem;
  overflow: hidden;
  max-height: 100vh;
  position: sticky;
  top: 0;
}

.niche-list-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.brand {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
}

.brand-mark {
  background: linear-gradient(135deg, var(--accent), #c47f20);
  color: #0f1419;
  font-weight: 700;
  font-size: 0.7rem;
  padding: 0.35rem 0.5rem;
  border-radius: 6px;
  letter-spacing: 0.02em;
}

.brand h1 {
  font-size: 1.1rem;
  font-weight: 600;
  line-height: 1.2;
}

.brand-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.stat-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.6rem 0.75rem;
}

.stat-card strong {
  display: block;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--accent);
}

.stat-card span {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.region-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.region-btn {
  flex: 1 1 calc(50% - 0.2rem);
  min-width: 0;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.region-btn:hover {
  border-color: var(--text-muted);
  color: var(--text);
}

.region-btn.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}

.region-btn .count {
  display: block;
  font-size: 0.65rem;
  opacity: 0.8;
  margin-top: 0.1rem;
}

.sidebar-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

.niche-list {
  list-style: none;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding-right: 0.15rem;
}

.sidebar-scroll-hint {
  font-size: 0.68rem;
  color: var(--text-muted);
  margin-top: 0.35rem;
  line-height: 1.3;
}

.niche-list li button {
  width: 100%;
  text-align: left;
  padding: 0.45rem 0.6rem;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.8rem;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
}

.niche-list li button:hover { background: var(--bg-elevated); color: var(--text); }
.niche-list li button.active { background: var(--bg-elevated); color: var(--accent); }

.niche-list .niche-count {
  font-size: 0.7rem;
  opacity: 0.7;
  font-variant-numeric: tabular-nums;
}

.cat-parent {
  margin-bottom: 0.35rem;
}

.cat-parent-btn {
  font-weight: 600;
}

.cat-parent-btn .cat-chevron {
  display: inline-block;
  width: 0.65rem;
  margin-right: 0.25rem;
  opacity: 0.6;
  transition: transform 0.15s;
}

.cat-parent.is-expanded .cat-chevron {
  transform: rotate(90deg);
}

.cat-children {
  list-style: none;
  margin: 0.2rem 0 0.45rem 0.5rem;
  padding: 0 0 0 0.5rem;
  border-left: 1px solid var(--border);
}

.cat-parent:not(.is-expanded) .cat-children {
  display: none;
}

.cat-leaf-btn.is-placeholder,
.cat-leaf-btn.is-placeholder .niche-count {
  opacity: 0.45;
  font-style: italic;
}

.catalog-table.has-product-col .col-check,
.catalog-table.has-product-col .col-product-th {
  min-width: 200px;
}

.col-product {
  max-width: 220px;
  font-size: 0.78rem;
  line-height: 1.35;
  color: var(--text-muted);
}

body:not(.mode-opt) .col-product {
  max-width: 280px;
}

.col-product strong {
  display: block;
  color: var(--text);
  font-weight: 500;
  margin-bottom: 0.15rem;
}

.cat-leaf-btn {
  font-size: 0.78rem !important;
  padding: 0.32rem 0.5rem !important;
}

/* Один лист в разделе — как обычный пункт меню, без вложенности */
.niche-list li button.cat-flat {
  font-size: 0.8rem !important;
  padding: 0.45rem 0.6rem !important;
  font-weight: 600;
}

.sidebar-foot {
  margin-top: auto;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.link-muted {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-decoration: none;
}

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

.badge-verify {
  font-size: 0.65rem;
  background: rgba(61, 214, 140, 0.12);
  color: var(--tier-a);
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  width: fit-content;
}

/* Main */
.main {
  padding: 1.25rem 1.5rem 2rem;
  overflow-x: auto;
  position: relative;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
}

.toolbar-left {
  flex: 1 1 200px;
  min-width: 0;
}

.toolbar h2 {
  font-size: 1.35rem;
  font-weight: 600;
}

.subtitle {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
}

.toolbar-right {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin-left: auto;
}

.catalog-switch {
  display: flex;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
  gap: 3px;
}

.catalog-switch-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 88px;
  padding: 0.4rem 0.75rem;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
}

.catalog-switch-btn:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
}

.catalog-switch-btn.active {
  background: var(--accent-dim);
  color: var(--accent);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
}

.catalog-switch-btn[data-mode="opt"].active {
  background: rgba(91, 156, 245, 0.18);
  color: var(--tier-b);
}

.switch-label {
  font-weight: 700;
  font-size: 0.85rem;
  line-height: 1.2;
}

.switch-hint {
  font-size: 0.62rem;
  opacity: 0.85;
  margin-top: 0.1rem;
}

body.mode-opt .brand-mark {
  background: linear-gradient(135deg, var(--tier-b), #3d7dd8);
}

body.mode-opt .niche-list li button.active {
  color: var(--tier-b);
}

.search-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.45rem 0.75rem;
  min-width: 220px;
}

.search-wrap svg { color: var(--text-muted); flex-shrink: 0; }

.search-wrap input {
  border: none;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 0.85rem;
  width: 100%;
  outline: none;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

.toggle input { accent-color: var(--accent); }

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.75rem;
  min-height: 0;
}

.filter-chip {
  font-size: 0.75rem;
  padding: 0.2rem 0.55rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-muted);
}

/* Table */
.table-wrap {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

.catalog-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.catalog-table thead {
  background: var(--bg-elevated);
  position: sticky;
  top: 0;
  z-index: 2;
}

.catalog-table th {
  text-align: left;
  padding: 0.65rem 0.75rem;
  font-weight: 600;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.catalog-table td {
  padding: 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.catalog-table tbody tr {
  cursor: pointer;
  transition: background 0.1s;
}

.catalog-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.03);
}
.col-name { min-width: 200px; }
.col-contact { min-width: 180px; }
.col-check { min-width: 140px; }
.col-markets { width: 100px; }
.col-site { width: 44px; }

.factory-name {
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.15rem;
}

.factory-meta {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.tier-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  font-weight: 700;
  font-size: 0.75rem;
}

.tier-badge.a { background: rgba(61, 214, 140, 0.2); color: var(--tier-a); }
.tier-badge.b { background: rgba(91, 156, 245, 0.2); color: var(--tier-b); }

.status-badge {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 600;
  padding: 0.2rem 0.45rem;
  border-radius: 6px;
  white-space: nowrap;
}

.status-badge.status-top {
  background: rgba(232, 168, 56, 0.2);
  color: var(--accent);
}

.status-badge.status-verified {
  background: rgba(124, 108, 240, 0.2);
  color: var(--verified);
}

.status-badge.status-base {
  background: rgba(139, 154, 171, 0.15);
  color: var(--text-muted);
}

.catalog-table:not(.has-status-col) .col-status-cell {
  display: none;
}

.verify-pill {
  display: block;
  font-size: 0.65rem;
  color: var(--verified);
  margin-top: 0.2rem;
  font-family: var(--mono);
}

.contact-line {
  display: block;
  margin-bottom: 0.2rem;
  word-break: break-all;
}

.contact-line a {
  color: var(--tier-b);
  text-decoration: none;
}

.contact-line a:hover { text-decoration: underline; }

.contact-muted {
  color: var(--text-muted);
  font-size: 0.75rem;
}

.market-dots {
  display: flex;
  gap: 0.25rem;
  flex-wrap: wrap;
}

.market-dot {
  font-size: 0.65rem;
  font-weight: 600;
  padding: 0.15rem 0.35rem;
  border-radius: 4px;
  background: var(--bg-elevated);
  color: var(--text-muted);
}

.market-dot.ready { background: rgba(61, 214, 140, 0.15); color: var(--tier-a); }
.market-dot.dealer { background: rgba(232, 168, 56, 0.12); color: var(--accent); }

.btn-site {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--accent);
  text-decoration: none;
  transition: all 0.15s;
}

.btn-site:hover {
  background: var(--accent-dim);
  border-color: var(--accent);
}

.empty-state {
  padding: 3rem;
  text-align: center;
  color: var(--text-muted);
}

.empty-state.hidden,
.hidden { display: none !important; }

.loading-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

.loading-box {
  text-align: center;
  color: var(--text-muted);
}

.loading-box .brand-mark {
  display: inline-block;
  margin-bottom: 1rem;
}

.loading-error {
  max-width: 420px;
  padding: 1.5rem;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.loading-error .hint {
  margin-top: 1rem;
  font-size: 0.8rem;
}

.loading-error code {
  font-family: var(--mono);
  color: var(--accent);
}

.btn-ghost {
  margin-top: 1rem;
  padding: 0.5rem 1rem;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  font-family: inherit;
  cursor: pointer;
}

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

/* Drawer */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 50;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: min(480px, 100vw);
  height: 100vh;
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  z-index: 51;
  overflow-y: auto;
  padding: 1.5rem;
  box-shadow: -8px 0 32px rgba(0, 0, 0, 0.4);
}

.drawer-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  width: 36px;
  height: 36px;
  border: none;
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 1.5rem;
  border-radius: 8px;
  cursor: pointer;
  line-height: 1;
}

.drawer h3 { font-size: 1.15rem; margin-bottom: 0.35rem; padding-right: 2rem; }

.drawer-cat {
  font-size: 0.85rem;
  color: var(--accent);
  margin-bottom: 0.75rem;
}

.drawer-en {
  margin-top: 0.5rem;
  font-style: italic;
  font-size: 0.85rem;
}

.drawer-section {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.drawer-section h4 {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.drawer p, .drawer dl {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.drawer dl dt { color: var(--text); font-weight: 500; margin-top: 0.5rem; }
.drawer dl dd { margin-left: 0; margin-top: 0.15rem; }

.score-bar {
  display: inline-block;
  background: var(--accent-dim);
  color: var(--accent);
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  font-weight: 600;
  font-size: 0.8rem;
}

/* L4 — team contact */
.badge-team-contact {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 0.22rem 0.5rem;
  border-radius: 6px;
  white-space: nowrap;
  background: rgba(232, 168, 56, 0.22);
  color: #e8a838;
  border: 1px solid rgba(232, 168, 56, 0.35);
}

.team-empty {
  color: var(--text-muted);
  font-size: 0.75rem;
}

.col-team-cell {
  white-space: nowrap;
  width: 6.5rem;
}

.catalog-table:not(.has-team-col) .col-team-cell,
.catalog-table:not(.has-team-col) .col-team {
  display: none;
}

.team-legend {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.35rem;
  max-width: 42rem;
  line-height: 1.45;
}

.toolbar-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.filter-chip {
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  border: 1px dashed var(--border);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.filter-chip:hover,
.filter-chip.active {
  border-color: rgba(232, 168, 56, 0.55);
  color: var(--accent);
  background: rgba(232, 168, 56, 0.08);
}

.link-team-mode.active {
  color: var(--accent);
}

.drawer-team {
  border-left: 3px solid rgba(232, 168, 56, 0.45);
  padding-left: 0.75rem;
}

.btn-team-mark {
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.55rem 1rem;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  color: #0f1419;
  background: linear-gradient(135deg, var(--accent), #c47f20);
  width: 100%;
}

.team-modal {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

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

.team-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
}

.team-modal-panel {
  position: relative;
  width: 100%;
  max-width: 400px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.team-modal-close {
  position: absolute;
  top: 0.5rem;
  right: 0.65rem;
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 1.4rem;
  cursor: pointer;
}

.team-modal-label {
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  margin: 0.75rem 0 0.35rem;
}

.team-modal-input,
.team-modal-textarea {
  width: 100%;
  font-family: inherit;
  font-size: 0.85rem;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-elevated);
  color: var(--text);
}

.team-modal-factory {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.team-modal-error {
  color: #e85d5d;
  font-size: 0.78rem;
  margin-top: 0.65rem;
}

.team-modal-hint {
  font-size: 0.75rem;
  color: var(--tier-b);
  margin-top: 0.5rem;
  line-height: 1.4;
}

.team-modal-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 1rem;
}

.btn-team-primary {
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  padding: 0.6rem 1rem;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  color: #0f1419;
  background: linear-gradient(135deg, var(--accent), #c47f20);
}

.btn-team-ghost {
  font-family: inherit;
  font-size: 0.82rem;
  padding: 0.5rem;
  border: 1px dashed var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}
