/*
  Данные: панель, KPI-карточки, дельты, легенда, таблица, дерево, пагинация.
  Язык «факт / оценка»: сплошное — подтверждено, пунктир — оценка (CLAUDE.md, принцип 6).
*/

/* ---------- Панель (секция таблицы или графика) ---------- */
.mh-panel {
  border: 1px solid var(--line); border-radius: var(--radius-lg);
  background: var(--surface); box-shadow: var(--shadow-card);
  padding: var(--space-5); min-width: 0;
}
.mh-panel--narrow { max-width: 480px; }
.mh-panel__head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-4); }
.mh-panel__title { margin: 0; font: 700 16px/22px var(--font-sans); color: var(--ink); }
.mh-panel__sub { margin: 2px 0 0; font-size: 12px; line-height: 16px; color: var(--ink-muted); max-width: 60ch; }
.mh-panel__tools { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.mh-empty { margin: 0; color: var(--ink-muted); }

/* Список «название — значение»: профиль, карточки сущностей. */
.mh-props { display: grid; grid-template-columns: minmax(110px, max-content) minmax(0, 1fr); gap: 10px var(--space-4); margin: 0; align-items: center; }
.mh-props dt { color: var(--ink-muted); font-size: 13px; }
.mh-props dd { margin: 0; color: var(--ink); font-weight: 600; overflow-wrap: anywhere; }
.mh-note { margin: var(--space-4) 0 0; font-size: 12px; line-height: 16px; color: var(--ink-faint); }

/* ---------- KPI ---------- */
.mh-kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: var(--space-3); }
/* Пять в ряд на широком экране: десять карточек Сводки — два ровных ряда. */
@media (min-width: 1100px) { .mh-kpis--five { grid-template-columns: repeat(5, minmax(0, 1fr)); } }
.mh-kpi {
  display: grid; gap: 6px; align-content: start; min-width: 0;
  padding: var(--space-4); border: 1px solid var(--line); border-radius: var(--radius-lg);
  background: var(--surface); box-shadow: var(--shadow-card);
  transition: box-shadow .2s ease;
}
.mh-kpi:hover { box-shadow: var(--shadow-glow); }
.mh-kpi__label { display: flex; align-items: center; gap: 6px; font: 700 11px/14px var(--font-sans); letter-spacing: .08em; text-transform: uppercase; color: var(--ink-muted); }
.mh-kpi__value { font: 600 26px/30px var(--font-mono); letter-spacing: -0.02em; font-variant-numeric: tabular-nums; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mh-kpi__foot { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 12px; line-height: 16px; color: var(--ink-faint); }
.mh-kpi__state { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.mh-kpi--confirmed .mh-kpi__state { background: var(--cyan); box-shadow: var(--shadow-glow-cyan); }
.mh-kpi--expected {
  border: 1px dashed var(--line-strong);
  background: repeating-linear-gradient(135deg, transparent 0 10px, var(--accent-soft) 10px 11px), var(--surface);
}
.mh-kpi--expected .mh-kpi__state { border: 1.5px dashed var(--accent); }
.mh-kpi--expected .mh-kpi__value { color: var(--accent); }
.mh-kpi__value.is-gain { color: var(--gain); }
.mh-kpi__value.is-loss { color: var(--loss); }

.mh-delta { display: inline-flex; align-items: center; gap: 2px; font: 600 12px/16px var(--font-mono); font-variant-numeric: tabular-nums; }
.mh-delta--up { color: var(--gain); }
.mh-delta--down { color: var(--loss); }
.mh-delta--flat { color: var(--ink-muted); }

/* ---------- Легенда графиков ---------- */
.mh-legend { display: flex; flex-wrap: wrap; gap: var(--space-4); font-size: 12px; color: var(--ink-muted); }
.mh-legend__item { display: inline-flex; align-items: center; gap: 6px; }
.mh-swatch { width: 18px; height: 0; border-top: 2px solid var(--chart-confirmed); }
.mh-swatch--confirmed { border-top-color: var(--chart-confirmed); }
.mh-swatch--expected { border-top: 2px dashed var(--chart-expected); }
.mh-swatch--cost { border-top-color: var(--chart-cost); }
/* Холст графика: высота задана, Chart.js растягивает по ширине панели. */
.mh-chart { position: relative; height: 280px; }

/* ---------- Карта мира (ui/components/geo_map.html) ---------- */
.mh-geo { position: relative; display: grid; gap: var(--space-3); }
.mh-geo__canvas svg { display: block; width: 100%; height: auto; max-height: 440px; }
.mh-geo__tools { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-2); }
.mh-geo__canvas path { transition: fill-opacity .15s ease; }
.mh-geo__canvas path:hover { stroke: var(--cyan); stroke-width: 1.2; }
.mh-geo__legend { display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-4); font: 500 12px/16px var(--font-mono); color: var(--ink-muted); }
.mh-geo__key { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.mh-geo__swatch { width: 14px; height: 10px; border-radius: 2px; }
.mh-geo__swatch--empty { background: var(--surface-sunken); border: 1px solid var(--line-strong); }
.mh-geo__swatch--zero { background: var(--line); }
.mh-geo__tip-sep { height: 1px; margin: 2px 0; background: var(--line); }
.mh-geo__tip {
  position: absolute; z-index: 5; min-width: 160px; max-width: 240px; padding: var(--space-2) var(--space-3);
  display: grid; gap: 4px; pointer-events: none;
  border: 1px solid var(--line-strong); border-radius: var(--radius-md); background: var(--surface-raised); box-shadow: var(--shadow-card);
  font-size: 12px; line-height: 16px;
}
.mh-geo__tip[hidden] { display: none; }
.mh-geo__tip-name { font-size: 13px; }
.mh-geo__tip-row { display: flex; justify-content: space-between; gap: var(--space-3); color: var(--ink-muted); }
.mh-geo__tip-row b { color: var(--ink); }

/* ---------- Таблица ---------- */
.mh-table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface); }
.mh-table { width: 100%; border-collapse: collapse; font-size: 13px; line-height: 18px; }
.mh-table th {
  position: sticky; top: 0; z-index: 1; padding: 10px var(--space-3);
  background: var(--surface-sunken); color: var(--ink-muted); text-align: left; white-space: nowrap;
  font: 700 11px/14px var(--font-sans); letter-spacing: .08em; text-transform: uppercase;
  border-bottom: 1px solid var(--line);
}
.mh-table td { padding: 9px var(--space-3); border-bottom: 1px solid var(--line); white-space: nowrap; }
.mh-table .num { text-align: right; font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.mh-table th.num { font-family: var(--font-sans); }
.mh-table tbody tr:hover { background: var(--row-hover); }
.mh-table tbody tr.is-active { background: var(--accent-soft); box-shadow: inset 2px 0 0 var(--accent), inset -2px 0 0 var(--accent); }
.mh-table tfoot td { background: var(--surface-raised); font-weight: 700; border-top: 1px solid var(--line-strong); border-bottom: 0; }
.mh-table a { color: var(--accent); text-decoration: none; font-weight: 700; }
.mh-table a:hover { text-decoration: underline; }
.mh-table .is-expected { color: var(--accent); }
.mh-table .is-gain { color: var(--gain); }
.mh-table .is-loss { color: var(--loss); }

.mh-table th .mh-sort { display: inline-flex; align-items: center; gap: 4px; color: inherit; font-weight: inherit; text-decoration: none; }
.mh-table th .mh-sort svg { width: 10px; height: 10px; opacity: .45; }
.mh-table th .mh-sort:hover, .mh-table th .mh-sort[aria-sort] { color: var(--ink); text-decoration: none; }
.mh-table th .mh-sort[aria-sort] svg { opacity: 1; color: var(--accent); }

/* Дерево «хед → тимлид → байер → кампания → объявление» (ТЗ §6.2). */
.mh-tree { display: inline-flex; align-items: center; gap: 6px; padding-left: calc(var(--level, 0) * 18px); }
.mh-tree__btn { width: 20px; height: 20px; display: inline-grid; place-items: center; padding: 0; border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--ink-muted); cursor: pointer; }
.mh-tree__btn:hover { background: var(--surface-sunken); color: var(--ink); }
.mh-tree__btn svg { width: 12px; height: 12px; transition: transform .15s ease; }
.mh-tree__btn[aria-expanded="true"] svg { transform: rotate(90deg); }
.mh-tree__leaf { width: 20px; }
.mh-tree__role { font: 700 10px/1 var(--font-sans); letter-spacing: .08em; text-transform: uppercase; color: var(--ink-faint); }

/* Гибридная пагинация MontaCRM: назад · сторінка X з Y · далі. */
.mh-pager { display: flex; align-items: center; justify-content: flex-end; gap: var(--space-2); padding-top: var(--space-3); font-size: 12px; color: var(--ink-muted); }
.mh-pager__info { font-family: var(--font-mono); }

@media (max-width: 640px) {
  .mh-panel { padding: var(--space-4); }
  .mh-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .mh-kpi { padding: var(--space-3); }
  .mh-kpi__value { font-size: 20px; line-height: 24px; }
  .mh-chart { height: 220px; }
  /* Широкая таблица на телефоне прокручивается вбок, а название строки остаётся на месте. */
  .mh-table th:first-child, .mh-table td:first-child { position: sticky; left: 0; z-index: 2; background: var(--surface); box-shadow: 1px 0 0 var(--line); }
  .mh-table th:first-child { background: var(--surface-sunken); z-index: 3; }
  .mh-table tbody tr.is-active td:first-child { background: var(--accent-soft); }
  .mh-table tfoot td:first-child { background: var(--surface-raised); }
  /* Дерево на телефоне уже: уровни видны по отступу, подпись роли прячем. */
  .mh-tree { padding-left: calc(var(--level, 0) * 10px); }
  .mh-tree__role { display: none; }
}
@media (pointer: coarse) {
  .mh-tree__btn { width: 32px; height: 32px; }
  .mh-tree__leaf { width: 32px; }
}
