/* Стили рабочего интерфейса графа: тёмная синяя тема без декоративных блоков. */

.review-controls { margin-bottom: 16px; }
.review-controls label { display: inline-flex; align-items: center; gap: 8px; }
.map-wrap.review-map { height: min(65vh, 650px); min-height: 360px; }
#community-plot { display: block; width: 100%; height: 100%; cursor: grab; }
#community-members td:nth-child(2) { white-space: pre-wrap; overflow-wrap: anywhere; }
#community-members tr { cursor: pointer; }
#community-search { flex: 1; }
.review-evidence { white-space: pre-wrap; overflow-wrap: anywhere; }

/* Цветовая схема и базовые правила страницы. */
:root {
  --bg: #071321;
  --side: #081827;
  --panel: #0c2034;
  --panel2: #0a1b2c;
  --line: #183a58;
  --text: #e9f3fb;
  --muted: #86a3ba;
  --blue: #1683e8;
  --blue2: #3ebcff;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 Segoe UI, Arial, sans-serif;
}

/* Боковая навигация. */
aside {
  position: fixed;
  inset: 0 auto 0 0;
  width: 210px;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  background: var(--side);
  border-right: 1px solid var(--line);
}

.brand {
  padding: 4px 10px 28px;
  font-size: 19px;
  font-weight: 750;
}

.brand::before {
  content: "KG";
  width: 31px;
  height: 31px;
  margin-right: 10px;
  display: inline-grid;
  place-items: center;
  background: var(--blue);
  border-radius: 7px;
}

.engine-switch {
  display: grid;
  gap: 6px;
  margin: 0 0 22px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #06111d;
}

.engine {
  padding: 9px 10px;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  font-size: 12px;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
}

.engine:hover,
.engine.active {
  color: white;
  background: #133553;
}




.answer-text {
  color: var(--text);
  line-height: 1.65;
  white-space: pre-wrap;
}

.result-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.result-heading h3 { margin: 0; }

.query-metrics {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.query-metric {
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: var(--panel2);
  font-size: 12px;
  white-space: nowrap;
}

@media (max-width: 760px) {
  .result-heading { flex-direction: column; }
  .query-metrics { justify-content: flex-start; }
}

.engine:disabled {
  opacity: .45;
  cursor: not-allowed;
}

nav {
  display: grid;
  gap: 4px;
}

.nav {
  padding: 11px 13px;
  color: #91aabe;
  background: transparent;
  border: 0;
  border-radius: 7px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}

.nav:hover,
.nav.active {
  color: white;
  background: #102e49;
}

.nav.active {
  box-shadow: inset 3px 0 var(--blue2);
}

.server {
  margin-top: auto;
  padding: 15px 8px;
  color: var(--muted);
  border-top: 1px solid var(--line);
  font-size: 12px;
}

.server i {
  width: 7px;
  height: 7px;
  margin-right: 8px;
  display: inline-block;
  background: #32d99a;
  border-radius: 50%;
}

/* Основная рабочая область и её верхняя панель. */
main {
  margin-left: 210px;
  padding: 0 28px 40px;
}

header {
  height: 78px;
  margin-bottom: 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}

header h1 {
  margin: 0;
  font-size: 22px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

button {
  font: inherit;
}

header button,
.graph-toolbar button,
#visual-graph button {
  padding: 8px 11px;
  color: #b5cadd;
  background: #0e2942;
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

/* Вкладки каталога. */
.tabs {
  margin-bottom: 18px;
  display: flex;
  border-bottom: 1px solid var(--line);
}

.catalog-tab {
  padding: 11px 18px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  cursor: pointer;
}

.catalog-tab.active {
  color: #fff;
  border-bottom-color: var(--blue2);
}

/* Панели ввода, формы и управляющие элементы. */
.panel {
  padding: 22px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 9px;
}

.panel h2 {
  margin: 0 0 8px;
  font-size: 18px;
}

.panel p {
  margin: 0 0 20px;
  color: var(--muted);
}

.graph-toolbar input,
.graph-toolbar select,
.catalog-tools input,
.catalog-tools select,
#ask-form input,
#ask-form select {
  padding: 10px 11px;
  color: white;
  background: #081827;
  border: 1px solid var(--line);
  border-radius: 6px;
  outline: none;
}

.primary {
  padding: 10px 16px;
  color: white;
  background: var(--blue);
  border: 0;
  border-radius: 6px;
  font-weight: 650;
  cursor: pointer;
}

/* Текстовый статус запроса. */
.console {
  min-height: 130px;
  max-width: 1100px;
  max-height: 330px;
  padding: 15px;
  overflow: auto;
  color: #9fc8e5;
  background: #050d16;
  border: 1px solid #152f45;
  border-radius: 8px;
  font: 12px/1.6 Consolas, monospace;
  white-space: pre-wrap;
}

.ask-panel {
  padding: 18px;
}

#ask-form {
  display: flex;
  gap: 8px;
}

#ask-form input {
  flex: 1;
}

#ask-form select {
  min-width: 110px;
}

.result {
  margin-top: 12px;
}

.result h3 {
  margin: 0 0 10px;
  font-size: 14px;
}

.result-title {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.result-help {
  position: relative;
  display: inline-grid;
  width: 17px;
  height: 17px;
  place-items: center;
  color: #9ed8ff;
  background: #123451;
  border: 1px solid #245c82;
  border-radius: 50%;
  cursor: help;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
}

.result-help::after {
  position: absolute;
  z-index: 20;
  top: calc(100% + 8px);
  left: 50%;
  width: min(340px, 70vw);
  padding: 9px 11px;
  visibility: hidden;
  opacity: 0;
  color: var(--text);
  background: #0c2234;
  border: 1px solid #2b658e;
  border-radius: 6px;
  box-shadow: 0 8px 24px #0008;
  content: attr(data-tooltip);
  font-size: 12px;
  font-weight: 400;
  line-height: 1.4;
  pointer-events: none;
  transform: translate(-20px, -3px);
  transition: opacity 0.15s, transform 0.15s, visibility 0.15s;
}

.result-help:hover::after,
.result-help:focus::after {
  visibility: visible;
  opacity: 1;
  transform: translate(-20px, 0);
}

.facts {
  display: grid;
  gap: 5px;
}

.fact {
  padding: 9px 11px;
  background: var(--panel2);
  border: 1px solid #14344f;
  border-radius: 6px;
}

.node-link {
  appearance: none;
  padding: 1px 2px;
  color: #8bd4ff;
  background: transparent;
  border: 0;
  border-bottom: 1px dashed #3b8cbd;
  border-radius: 2px;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  text-align: left;
}

.node-link:hover,
.node-link:focus-visible {
  color: #d5f1ff;
  background: #174567;
  border-bottom-color: #d5f1ff;
  outline: none;
}

.book-badges {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 5px;
}

.fact .book-badges {
  margin-top: 7px;
}

.term-use-reason,
.term-definition {
  margin-top: 6px;
  color: var(--muted);
  line-height: 1.45;
}

.term-use-reason {
  color: var(--text);
}

.book-badge {
  display: inline-block;
  padding: 2px 7px;
  color: #9ed8ff;
  background: #123451;
  border: 1px solid #245c82;
  border-radius: 999px;
  font-size: 11px;
  white-space: nowrap;
}

.book-badge.book-unknown {
  color: var(--muted);
  background: transparent;
  border-color: var(--line);
}

.relation {
  color: #54bfff;
  font-family: Consolas, monospace;
}

/* Панель управления и canvas большой карты графа. */
.graph-toolbar {
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.graph-toolbar input {
  width: 300px;
}

.graph-toolbar span {
  margin-left: auto;
  color: var(--muted);
}

.map-wrap {
  position: relative;
  height: calc(100vh - 135px);
  min-height: 600px;
  overflow: hidden;
  background: #050e18;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.map-wrap canvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
}

.map-wrap canvas:active {
  cursor: grabbing;
}

.legend {
  position: absolute;
  left: 12px;
  bottom: 10px;
  padding: 7px 10px;
  color: #7695ad;
  background: #050e18dd;
  border: 1px solid var(--line);
  border-radius: 5px;
  font-size: 11px;
}

/* Фильтры и таблица каталога. */
.catalog-tools {
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.catalog-tools input {
  width: 320px;
}

.catalog-tools span {
  margin-left: auto;
  color: var(--muted);
}

.table-panel {
  max-height: calc(100vh - 185px);
  padding: 0;
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th {
  position: sticky;
  top: 0;
  color: #7f9bb1;
  background: #0b1d2f;
  font-size: 11px;
  letter-spacing: 0.5px;
  text-align: left;
  text-transform: uppercase;
}

th,
td {
  padding: 11px 13px;
  border-bottom: 1px solid #15334d;
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover {
  background: #102a42;
}

td small {
  color: var(--muted);
}

code {
  color: #70c9ff;
}

/* Карточки и диаграммы статистики. */
.stat-grid {
  margin-bottom: 12px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.stat-card {
  padding: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.stat-card strong {
  display: block;
  font-size: 28px;
}

.stat-card span {
  color: var(--muted);
}

.stats-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.stats-columns h2 {
  margin-bottom: 17px;
}

.bar {
  margin: 9px 0;
  display: grid;
  grid-template-columns: 150px 1fr 55px;
  align-items: center;
  gap: 9px;
}

.track {
  height: 6px;
  overflow: hidden;
  background: #071624;
  border-radius: 9px;
}

.fill {
  height: 100%;
  background: var(--blue);
  border-radius: 9px;
}

/* Выдвижная карточка выбранного понятия и затемнение фона. */
.drawer {
  position: fixed;
  top: 0;
  right: -560px;
  z-index: 5;
  width: min(540px, 92vw);
  height: 100%;
  padding: 28px;
  overflow: auto;
  background: #091a2a;
  border-left: 1px solid var(--line);
  transition: 0.2s;
}

.drawer.open {
  right: 0;
}

.drawer > button {
  position: absolute;
  top: 12px;
  right: 16px;
  color: white;
  background: transparent;
  border: 0;
  font-size: 25px;
}

.drawer h2 {
  margin: 5px 0;
}

.drawer .item {
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.drawer .item p {
  color: #a6bdcf;
}

.scrim {
  position: fixed;
  inset: 0;
  z-index: 4;
  display: none;
  background: #0008;
}

.scrim.open {
  display: block;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  padding: 10px 14px;
  opacity: 0;
  background: #123653;
  border: 1px solid #256da4;
  border-radius: 6px;
  transform: translateY(20px);
  transition: 0.2s;
}

.toast.show {
  opacity: 1;
  transform: none;
}

/* Компоновка для планшетов и узких окон. */
@media (max-width: 850px) {
  aside {
    width: 145px;
  }

  main {
    margin-left: 145px;
    padding: 0 14px;
  }

  .stat-grid {
    grid-template-columns: 1fr 1fr;
  }

  .stats-columns {
    grid-template-columns: 1fr;
  }

  .graph-toolbar {
    flex-wrap: wrap;
  }

  .graph-toolbar span {
    margin-left: 0;
  }

  .map-wrap {
    height: 650px;
  }
}

/* Компоновка для телефонов. */
@media (max-width: 600px) {
  aside {
    position: static;
    width: auto;
    height: auto;
  }

  nav {
    grid-template-columns: repeat(4, 1fr);
  }

  .server {
    display: none;
  }

  main {
    margin: 0;
  }

  .stat-grid {
    grid-template-columns: 1fr;
  }

  .catalog-tools {
    flex-wrap: wrap;
  }
}

/* Visual-only datasets share the graph page and have no query/catalog actions. */
[hidden] { display: none !important; }
body[data-visual-only="true"] .nav:not([data-view="graph"]):not([data-view="stats"]),
body[data-visual-only="true"] #export-obsidian { display: none; }
.visual-only-notice {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  padding: 14px 18px;
  margin-bottom: 16px;
  border: 1px solid #42698b;
  border-radius: 8px;
  background: #142b40;
  color: #c9e1f5;
}

#community-statistics { margin-bottom: 24px; }
#community-statistics .stat-grid { margin: 16px 0; }
#community-statistics details { margin: 16px 0; }
#community-statistics .panel { margin-bottom: 16px; }
.metric-table { width: 100%; border-collapse: collapse; }
.metric-table th { text-align: left; font-weight: 500; }
.metric-table th, .metric-table td { padding: 8px; border-bottom: 1px solid var(--line); }
.community-stat-table { min-width: 1050px; }
.community-stat-table small { display: block; max-width: 330px; color: var(--muted); overflow-wrap: anywhere; }
#community-statistics button { cursor: pointer; }
