/* ============================================================================
   panels.css — дерево файлов, правая панель (оглавление, формулы, проблемы,
   статистика) и поповер палитры символов/сниппетов.
   ========================================================================== */

/* ------------------------------- Дерево файлов ------------------------------- */

.tree {
  display: flex;
  flex-direction: column;
  gap: 1px;
  font-size: var(--fs-sm);
}
.tree__row {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border-left: 2px solid transparent;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--fg);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.tree__row:hover {
  background: var(--bg-hover);
}
.tree__row.is-selected {
  background: var(--accent-soft);
  border-left-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}
.tree__row.is-dirty .tree__name {
  font-weight: 700;
}
.tree__row.is-dirty .tree__name::after {
  content: "•";
  margin-left: 4px;
  color: var(--accent);
}
.tree__row.is-dir {
  font-weight: 600;
}
.tree__toggle {
  flex: 0 0 auto;
  width: 13px;
  color: var(--fg-faint);
  font-size: 9px;
  text-align: center;
}
.tree__icon {
  flex: 0 0 auto;
  width: 15px;
  font-size: 12px;
  text-align: center;
  color: var(--fg-muted);
}
.tree__name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tree__meta {
  flex: 0 0 auto;
  margin-left: 6px;
  color: var(--fg-faint);
  font-size: var(--fs-xs);
  font-variant-numeric: tabular-nums;
}
.tree__children {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

/* ------------------------------- Правая панель ------------------------------- */

.panel-tabs {
  flex: 0 0 auto;
  display: flex;
  align-items: stretch;
  overflow-x: auto;
  border-bottom: 1px solid var(--border);
  background: var(--bg-sunken);
}
.panel-tabs__btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 7px 9px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--fg-muted);
  font-family: inherit;
  font-size: var(--fs-xs);
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.panel-tabs__btn:hover {
  background: var(--bg-hover);
  color: var(--fg);
}
.panel-tabs__btn.is-active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  background: var(--bg);
}
.panel-page {
  display: none;
}
.panel-page.is-active {
  display: block;
}

/* ------------------------------- Оглавление ------------------------------- */

.toc {
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.toc__item {
  border-radius: var(--radius-sm);
}
.toc__link {
  display: block;
  padding: 3px 8px;
  border: 0;
  background: transparent;
  color: var(--fg);
  font-family: inherit;
  font-size: var(--fs-sm);
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.toc__link:hover {
  background: var(--bg-hover);
  color: var(--accent);
}
.toc__item--l1 {
  margin-left: 0;
  font-weight: 700;
}
.toc__item--l2 {
  margin-left: 10px;
  font-weight: 600;
}
.toc__item--l3 {
  margin-left: 20px;
}
.toc__item--l4 {
  margin-left: 30px;
  font-size: var(--fs-xs);
}
.toc__item--l5 {
  margin-left: 40px;
  font-size: var(--fs-xs);
  color: var(--fg-muted);
}
.toc__item--l6 {
  margin-left: 50px;
  font-size: var(--fs-xs);
  color: var(--fg-muted);
}

/* ------------------------------- Формулы ------------------------------- */

.formulas {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.formulas__item {
  padding: 7px 8px;
  border: 1px solid var(--border);
  border-left: 3px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--bg);
  transition: border-color 0.12s, background 0.12s;
}
.formulas__item:hover {
  border-color: var(--border-strong);
}
.formulas__item.is-active {
  border-left-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 6%, var(--bg));
}
.formulas__head {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 5px;
}
.formulas__num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  padding: 1px 6px;
  border-radius: 9px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: var(--fs-xs);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.formulas__num--none {
  background: var(--bg-active);
  color: var(--fg-faint);
  font-weight: 400;
}
.formulas__label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--fg-muted);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
}
.formulas__line {
  margin-left: auto;
  color: var(--fg-faint);
  font-size: var(--fs-xs);
  font-variant-numeric: tabular-nums;
}
.formulas__latex {
  max-height: 5.4em;
  margin: 0 0 6px;
  padding: 5px 7px;
  border-radius: var(--radius-sm);
  background: var(--code-bg);
  color: var(--fg);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  line-height: 1.45;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  cursor: pointer;
}
.formulas__actions {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}
.formulas__btn {
  padding: 2px 7px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-elev);
  color: var(--fg-muted);
  font-family: inherit;
  font-size: var(--fs-xs);
  cursor: pointer;
}
.formulas__btn:hover {
  background: var(--bg-hover);
  color: var(--accent);
  border-color: var(--accent);
}
.formulas__btn.is-copied {
  color: var(--ok);
  border-color: var(--ok);
}

/* ------------------------------- Проблемы ------------------------------- */

.problems {
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.problems__item {
  padding: 7px 9px;
  border: 1px solid color-mix(in srgb, var(--error) 30%, var(--border));
  border-left: 3px solid var(--error);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--error) 5%, var(--bg));
}
/* Предупреждение (например, битая диаграмма Mermaid): не ошибка формулы. */
.problems__item--warn {
  border-color: color-mix(in srgb, var(--warn) 35%, var(--border));
  border-left-color: var(--warn);
  background: color-mix(in srgb, var(--warn) 6%, var(--bg));
}
.problems__item--warn .problems__message {
  color: var(--warn);
}
.problems__location {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
  color: var(--fg-muted);
  font-size: var(--fs-xs);
  font-variant-numeric: tabular-nums;
}
.problems__engine {
  padding: 0 5px;
  border-radius: 8px;
  background: var(--bg-active);
  font-family: var(--font-mono);
}
.problems__message {
  color: var(--error);
  font-size: var(--fs-sm);
  line-height: 1.4;
  word-break: break-word;
}
.problems__latex {
  margin: 5px 0 0;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  background: var(--code-bg);
  color: var(--fg);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
  cursor: pointer;
}
.problems__actions {
  display: flex;
  gap: 4px;
  margin-top: 6px;
}
.problems__ok {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 10px;
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--ok) 8%, transparent);
  color: var(--ok);
  font-size: var(--fs-sm);
}

/* ------------------------------- Статистика ------------------------------- */

.stats {
  display: flex;
  flex-direction: column;
  gap: 0;
}
.stats__grid {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 3px 12px;
  align-items: baseline;
}
.stats__label {
  color: var(--fg-muted);
  font-size: var(--fs-sm);
  padding: 3px 0;
  border-bottom: 1px dotted var(--border);
}
.stats__value {
  padding: 3px 0;
  border-bottom: 1px dotted var(--border);
  color: var(--fg);
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}
.stats__note {
  margin-top: 12px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  color: var(--fg-faint);
  font-size: var(--fs-xs);
  line-height: 1.5;
}

/* ============================================================================
   Поповер палитры символов и сниппетов
   ========================================================================== */

.popover {
  position: fixed;
  z-index: 120;
  display: flex;
  flex-direction: column;
  width: 430px;
  max-width: calc(100vw - 24px);
  max-height: min(70vh, 620px);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg-elev);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.popover__head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px 7px 11px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-sunken);
}
.popover__title {
  font-size: var(--fs-sm);
  font-weight: 700;
  color: var(--fg);
}
.popover__modes {
  display: inline-flex;
  margin-left: auto;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.popover__mode {
  padding: 3px 9px;
  border: 0;
  border-right: 1px solid var(--border);
  background: transparent;
  color: var(--fg-muted);
  font-family: inherit;
  font-size: var(--fs-xs);
  cursor: pointer;
}
.popover__mode:last-child {
  border-right: 0;
}
.popover__mode.is-active {
  background: var(--accent);
  color: var(--accent-fg);
  font-weight: 600;
}
.popover__close {
  margin-left: 2px;
}
.popover__filter {
  flex: 0 0 auto;
  margin: 8px;
  padding: 5px 9px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--fg);
  font-family: inherit;
  font-size: var(--fs-sm);
}
.popover__filter:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 2px var(--accent-soft);
}
.popover__body {
  flex: 1 1 auto;
  min-height: 0;
  padding: 0 8px 8px;
  overflow: auto;
}
.popover__foot {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 9px;
  border-top: 1px solid var(--border);
  background: var(--bg-sunken);
  font-size: var(--fs-xs);
}
.popover__hint {
  margin-left: auto;
  color: var(--fg-faint);
  text-align: right;
}

.symbol-group {
  margin-bottom: 12px;
}
.symbol-group__title,
.snippet-group__title {
  position: sticky;
  top: 0;
  z-index: 1;
  margin: 0 -8px 6px;
  padding: 5px 8px;
  background: var(--bg-elev);
  color: var(--fg-muted);
  font-size: var(--fs-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.symbol-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(38px, 1fr));
  gap: 4px;
}
.symbol-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 34px;
  padding: 0 3px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-math);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  overflow: hidden;
}
.symbol-btn:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}
.symbol-btn:active {
  transform: translateY(1px);
}
.symbol-btn__glyph {
  white-space: nowrap;
}

.snippets {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.snippet-group {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.snippet-item {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 5px 7px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--fg);
  font-family: inherit;
  font-size: var(--fs-sm);
  text-align: left;
  cursor: pointer;
  width: 100%;
}
.snippet-item:hover {
  border-color: var(--border);
  background: var(--bg-hover);
}
.snippet-item__title {
  flex: 0 0 auto;
  max-width: 46%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.snippet-item__code {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--fg-muted);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
}
.snippet-item__accel,
.snippet-item__hint {
  flex: 0 0 auto;
  padding: 1px 5px;
  border: 1px solid var(--border-strong);
  border-radius: 3px;
  background: var(--bg-sunken);
  color: var(--fg-faint);
  font-family: var(--font-mono);
  font-size: 10px;
  white-space: nowrap;
}
.snippet-item__hint {
  border-color: transparent;
  background: transparent;
  font-family: var(--font-ui);
}
