/* Практикум по агентам: страница команды, виды трассы и дашборд.
 *
 * Виды трассы и дашборд (классы pv-*) подключаются ещё и в панели —
 * инспектор запусков и проектор рисуют их тем же кодом. Поэтому префикс:
 * у панели свои .card и .btn, и одноимённые классы здесь столкнулись бы.
 * Оформление страницы команды — классы hap-*.
 */

:root {
  --pv-bg: #f6f7f9;
  --pv-surface: #ffffff;
  --pv-surface-2: #f1f3f6;
  --pv-fg: #16181d;
  --pv-muted: #667085;
  --pv-line: #e3e6eb;
  --pv-accent: #2563eb;
  --pv-on-accent: #ffffff;
  --pv-err: #c62828;
  --pv-err-bg: #fdecec;
  --pv-ok: #15803d;
  --pv-warn-bg: #fff4c2;
  --pv-reveal: #ffe066;

  /* Дорожки: модель и три сервера MCP, плюс навык */
  --pv-lane-model: #2563eb;
  --pv-lane-sales-db: #0d9488;
  --pv-lane-company-notes: #c2410c;
  --pv-lane-dashboard: #7c3aed;
  --pv-lane-skill: #db2777;

  /* Состав контекста */
  --pv-ctx-system: #94a3b8;
  --pv-ctx-skill: #db2777;
  --pv-ctx-card: #f59e0b;
  --pv-ctx-tool_results: #0d9488;
  --pv-ctx-model: #2563eb;

  --pv-chart-1: #2563eb;
  --pv-chart-2: #0d9488;
  /* Серии графиков: различимы между собой и при дальтонизме по яркости */
  --pv-s1: #2563eb;
  --pv-s2: #f59e0b;
  --pv-s3: #10b981;
  --pv-s4: #e11d48;
  --pv-s5: #8b5cf6;
  --pv-s6: #0891b2;
  --pv-radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --pv-bg: #0f1115;
    --pv-surface: #171a21;
    --pv-surface-2: #1f232c;
    --pv-fg: #e7e9ee;
    --pv-muted: #98a2b3;
    --pv-line: #2b303b;
    --pv-accent: #7aa2ff;
    --pv-on-accent: #0f1115;
    --pv-err: #ff8a80;
    --pv-err-bg: #3a1f1f;
    --pv-ok: #6fdc8c;
    --pv-warn-bg: #4a3d0f;
    --pv-reveal: #8a6d00;
    --pv-lane-model: #7aa2ff;
    --pv-lane-sales-db: #2dd4bf;
    --pv-lane-company-notes: #fb923c;
    --pv-lane-dashboard: #a78bfa;
    --pv-lane-skill: #f472b6;
    --pv-ctx-system: #64748b;
    --pv-ctx-tool_results: #2dd4bf;
    --pv-ctx-model: #7aa2ff;
    --pv-chart-1: #7aa2ff;
    --pv-chart-2: #2dd4bf;
    --pv-s1: #7aa2ff;
    --pv-s2: #fbbf24;
    --pv-s3: #34d399;
    --pv-s4: #fb7185;
    --pv-s5: #a78bfa;
    --pv-s6: #22d3ee;
  }
}

/* ------------------------------------------------------------------ */
/* Страница команды                                                    */
/* ------------------------------------------------------------------ */

.hap-body {
  margin: 0;
  background: var(--pv-bg);
  color: var(--pv-fg);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.hap-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  padding: 10px 16px;
  background: var(--pv-surface);
  border-bottom: 1px solid var(--pv-line);
}
.hap-top__title { font-weight: 650; }
.hap-top__team { color: var(--pv-muted); }
.hap-top__grow { flex: 1; }

.hap-phase {
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--pv-surface-2);
  font-size: 13px;
  font-weight: 600;
}

.hap-grid {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(360px, 1.6fr) minmax(320px, 1.2fr);
  gap: 16px;
  padding: 16px;
  align-items: start;
}
@media (max-width: 1100px) {
  .hap-grid { grid-template-columns: 1fr; }
}

.hap-panel {
  background: var(--pv-surface);
  border: 1px solid var(--pv-line);
  border-radius: var(--pv-radius);
  padding: 14px;
  min-width: 0;
}
.hap-panel + .hap-panel { margin-top: 16px; }
.hap-panel h2 {
  margin: 0 0 10px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--pv-muted);
}

.hap-card {
  padding: 12px;
  border-left: 4px solid var(--pv-accent);
  background: var(--pv-surface-2);
  border-radius: 6px;
}
.hap-card__client { font-weight: 650; }
.hap-card__text { font-size: 15px; line-height: 1.45; margin-top: 4px; }

.hap-field { margin-top: 14px; }
.hap-field label { display: flex; justify-content: space-between; font-weight: 600; margin-bottom: 4px; }
.hap-field textarea {
  box-sizing: border-box;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--pv-line);
  border-radius: 6px;
  background: var(--pv-surface);
  color: var(--pv-fg);
  font: 14px/1.4 ui-monospace, SFMono-Regular, Consolas, monospace;
  resize: vertical;
}
.hap-field textarea:disabled { opacity: 0.55; }
.hap-count { font-weight: 400; color: var(--pv-muted); font-size: 13px; }
.hap-lock { font-size: 13px; color: var(--pv-muted); margin-top: 4px; }

.hap-tools { margin: 0; padding: 0; list-style: none; }
.hap-tools li { padding: 8px 0; border-top: 1px solid var(--pv-line); font-size: 13px; }
.hap-tools li:first-child { border-top: 0; }
.hap-tools b { font-family: ui-monospace, Consolas, monospace; }
.hap-tools .hap-tools__server { color: var(--pv-muted); }

.hap-run {
  display: block;
  width: 100%;
  margin-top: 14px;
  padding: 12px;
  border: 0;
  border-radius: 8px;
  background: var(--pv-accent);
  color: var(--pv-on-accent);
  font-size: 16px;
  font-weight: 650;
  cursor: pointer;
}
.hap-run:disabled { opacity: 0.5; cursor: not-allowed; }
.hap-status { margin-top: 8px; font-size: 13px; color: var(--pv-muted); min-height: 1.4em; }
.hap-status.is-error { color: var(--pv-err); }

.hap-meter { font-variant-numeric: tabular-nums; }
.hap-meter__bar {
  height: 8px;
  margin-top: 6px;
  border-radius: 4px;
  background: var(--pv-surface-2);
  overflow: hidden;
}
.hap-meter__fill { height: 100%; background: var(--pv-ok); width: 100%; }
.hap-meter__fill.is-low { background: var(--pv-err); }
.hap-meter__cost { margin-top: 6px; font-size: 13px; color: var(--pv-muted); }

.hap-history { margin: 0; padding: 0; list-style: none; }
.hap-history button {
  display: flex;
  width: 100%;
  gap: 8px;
  justify-content: space-between;
  padding: 7px 8px;
  border: 0;
  border-top: 1px solid var(--pv-line);
  background: none;
  color: inherit;
  text-align: left;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.hap-history button:hover, .hap-history button.is-current { background: var(--pv-surface-2); }

.hap-link {
  border: 0;
  padding: 0;
  background: none;
  color: var(--pv-accent);
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
}

.hap-compare {
  margin: 0 16px 16px;
}
.hap-compare__grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 800px) { .hap-compare__grid { grid-template-columns: 1fr; } }

.hap-closed {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(15, 17, 21, 0.55);
}
.hap-closed[hidden] { display: none; }
.hap-closed__box {
  max-width: 460px;
  padding: 28px;
  border-radius: 14px;
  background: var(--pv-surface);
  text-align: center;
  font-size: 22px;
  font-weight: 650;
}
.hap-closed__box p { font-size: 15px; font-weight: 400; color: var(--pv-muted); }

/* Вход по коду */
.hap-login {
  max-width: 420px;
  margin: 12vh auto 0;
  padding: 0 16px;
  text-align: center;
}
.hap-login h1 { font-size: 24px; }
.hap-login input {
  box-sizing: border-box;
  width: 100%;
  padding: 14px;
  border: 2px solid var(--pv-line);
  border-radius: 10px;
  background: var(--pv-surface);
  color: var(--pv-fg);
  font: 600 28px/1 ui-monospace, Consolas, monospace;
  letter-spacing: 0.15em;
  text-align: center;
  text-transform: uppercase;
}
.hap-error { color: var(--pv-err); }
.hap-note { color: var(--pv-muted); font-size: 13px; }

/* ------------------------------------------------------------------ */
/* Трасса: обнаружение, дорожки, контекст, сводка                      */
/* ------------------------------------------------------------------ */

.pv-trace-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}
.pv-step-counter { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.pv-run-status { color: var(--pv-muted); font-size: 13px; }

.pv-section { margin-top: 14px; }
.pv-section__title { font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--pv-muted); margin-bottom: 6px; }
.pv-empty { color: var(--pv-muted); font-size: 13px; }

.pv-discovery { display: flex; flex-wrap: wrap; gap: 8px; }
.pv-server {
  flex: 1 1 140px;
  padding: 8px 10px;
  border: 1px solid var(--pv-line);
  border-top: 3px solid var(--lane, var(--pv-line));
  border-radius: 8px;
  background: var(--pv-surface);
  font-size: 13px;
}
.pv-server__name { font-weight: 650; }
.pv-server__tool { margin-top: 4px; font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.pv-server__desc { color: var(--pv-muted); font-size: 12px; }

.pv-lanes-wrap { position: relative; overflow-x: auto; padding-bottom: 4px; }
.pv-lanes {
  position: relative;
  display: grid;
  gap: 8px 10px;
  align-items: stretch;
}
.pv-lane-label {
  position: sticky;
  left: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  padding: 4px 6px;
  border-left: 3px solid var(--lane);
  background: var(--pv-surface);
  font-size: 12px;
  font-weight: 650;
}
.pv-cell { display: flex; flex-direction: column; gap: 6px; min-height: 34px; }
.pv-col-head { font-size: 11px; color: var(--pv-muted); text-align: center; }

.pv-card {
  position: relative;
  z-index: 1;
  padding: 6px 8px;
  border: 1px solid var(--pv-line);
  border-left: 3px solid var(--lane);
  border-radius: 6px;
  background: var(--pv-surface);
  font-size: 12px;
  line-height: 1.35;
  text-align: left;
  color: inherit;
  font-family: inherit;
  cursor: pointer;
  animation: pv-in 0.25s ease-out;
}
.pv-card:hover, .pv-card.is-selected { box-shadow: 0 0 0 2px var(--lane); }
.pv-card.is-error { border-color: var(--pv-err); border-left-color: var(--pv-err); background: var(--pv-err-bg); }
.pv-card.is-pending { opacity: 0.7; }
.pv-card__title { font-weight: 650; font-family: ui-monospace, Consolas, monospace; }
.pv-card__text {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  white-space: pre-wrap;
  word-break: break-word;
}
.pv-card__meta { color: var(--pv-muted); font-size: 11px; margin-top: 2px; }
@keyframes pv-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .pv-card { animation: none; } }

.pv-arrows { position: absolute; inset: 0; pointer-events: none; z-index: 0; overflow: visible; }
.pv-arrows path { fill: none; stroke: var(--pv-muted); stroke-width: 1.4; opacity: 0.55; }
.pv-arrows path.is-error { stroke: var(--pv-err); opacity: 0.9; }
.pv-arrows marker path { fill: var(--pv-muted); stroke: none; opacity: 0.8; }

.pv-detail {
  margin-top: 10px;
  padding: 10px;
  border: 1px solid var(--pv-line);
  border-radius: 8px;
  background: var(--pv-surface-2);
  font-size: 13px;
}
.pv-detail[hidden] { display: none; }
.pv-detail__head { display: flex; justify-content: space-between; gap: 8px; font-weight: 650; }
.pv-detail pre {
  max-height: 260px;
  margin: 6px 0 0;
  padding: 8px;
  overflow: auto;
  border-radius: 6px;
  background: var(--pv-surface);
  font: 12px/1.4 ui-monospace, Consolas, monospace;
  white-space: pre-wrap;
  word-break: break-word;
}
.pv-detail__label { margin-top: 8px; color: var(--pv-muted); font-size: 12px; }

.pv-ctx-row { display: grid; grid-template-columns: 52px 1fr 64px; gap: 8px; align-items: center; font-size: 12px; margin-bottom: 4px; }
.pv-ctx-bar { display: flex; height: 14px; border-radius: 3px; overflow: hidden; background: var(--pv-surface-2); }
.pv-ctx-seg { height: 100%; }
.pv-ctx-total { text-align: right; font-variant-numeric: tabular-nums; color: var(--pv-muted); }
.pv-legend { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12px; color: var(--pv-muted); margin-top: 6px; }
.pv-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }

.pv-summary { display: flex; flex-wrap: wrap; gap: 6px; }
.pv-chip { padding: 3px 8px; border-radius: 999px; background: var(--pv-surface-2); font-size: 12px; font-variant-numeric: tabular-nums; }
.pv-chip.is-error { background: var(--pv-err-bg); color: var(--pv-err); }
.pv-compare-line { margin-top: 6px; font-size: 13px; }

/* ------------------------------------------------------------------ */
/* Дашборд                                                             */
/* ------------------------------------------------------------------ */

.pv-dash__title { margin: 0 0 12px; font-size: 19px; line-height: 1.25; }

.pv-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin-bottom: 12px; }
.pv-kpi {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--pv-line);
  border-top: 3px solid var(--pv-s1);
  background: var(--pv-surface);
  min-width: 0;
}
.pv-kpi:nth-child(2) { border-top-color: var(--pv-s2); }
.pv-kpi:nth-child(3) { border-top-color: var(--pv-s3); }
.pv-kpi:nth-child(4) { border-top-color: var(--pv-s4); }
.pv-kpi__label { font-size: 12px; color: var(--pv-muted); }
.pv-kpi__value { margin-top: 2px; font-size: 24px; font-weight: 750; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.pv-kpi__delta { margin-top: 2px; font-size: 12px; font-weight: 650; }
.pv-kpi__delta.is-up { color: var(--pv-ok); }
.pv-kpi__delta.is-down { color: var(--pv-err); }

/* Графики в две колонки, когда место есть (проектор, сравнение раундов);
   в узкой колонке команды — в одну */
.pv-charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 10px; }
.pv-chart { padding: 10px 12px; border: 1px solid var(--pv-line); border-radius: 10px; background: var(--pv-surface); min-width: 0; }
.pv-chart--table { grid-column: 1 / -1; }
.pv-chart.is-reveal { background: var(--pv-warn-bg); box-shadow: 0 0 0 3px var(--pv-reveal); }
.pv-chart__title { font-weight: 650; font-size: 14px; line-height: 1.3; }
.pv-chart__note { margin-top: 6px; padding-left: 8px; border-left: 2px solid var(--pv-line); font-size: 12px; color: var(--pv-muted); }
.pv-chart svg { display: block; width: 100%; height: auto; margin-top: 6px; overflow: visible; }
.pv-chart svg text { fill: var(--pv-muted); font-size: 11px; font-family: system-ui, sans-serif; }
.pv-chart svg .pv-grid { stroke: var(--pv-line); stroke-dasharray: 3 3; }
.pv-chart svg .pv-line { fill: none; stroke: var(--c); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.pv-chart svg .pv-area { fill: var(--c); opacity: 0.18; }
.pv-chart svg .pv-dot { fill: var(--pv-surface); stroke: var(--c); stroke-width: 2; }
.pv-chart svg .pv-bar { fill: var(--c); }
.pv-chart svg .pv-slice { fill: var(--c); stroke: var(--pv-surface); stroke-width: 2; }
.pv-chart svg .pv-value { fill: var(--pv-fg); font-weight: 600; }
.pv-chart svg .pv-band { fill: var(--pv-reveal); opacity: 0.22; }
.pv-chart svg .pv-band__label { fill: var(--pv-fg); font-weight: 600; }
.pv-chart svg .pv-donut__total { fill: var(--pv-fg); font-size: 18px; font-weight: 700; }
.pv-donut { max-width: 190px; margin: 0 auto; }
.pv-donut-wrap { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 4px 14px; }
.pv-legend--chart, .pv-legend--donut { justify-content: center; margin-top: 4px; }
.pv-legend--donut { flex-direction: column; }
.pv-swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; background: var(--c); }

/* Палитра серий. Цвет — переменной на классе: строгая CSP запрещает
   атрибут style, а var() в атрибуте fill браузеры понимают через раз */
.pv-s1 { --c: var(--pv-s1); }
.pv-s2 { --c: var(--pv-s2); }
.pv-s3 { --c: var(--pv-s3); }
.pv-s4 { --c: var(--pv-s4); }
.pv-s5 { --c: var(--pv-s5); }
.pv-s6 { --c: var(--pv-s6); }

.pv-table-wrap { overflow-x: auto; margin-top: 6px; max-height: 260px; }
.pv-table { border-collapse: collapse; font-size: 12px; width: 100%; }
.pv-table th, .pv-table td { padding: 4px 8px; border-bottom: 1px solid var(--pv-line); text-align: left; white-space: nowrap; }
.pv-table th { color: var(--pv-muted); font-weight: 600; }

.pv-notes { margin-top: 12px; padding: 10px 12px; border-radius: 10px; background: var(--pv-warn-bg); font-size: 13px; }
.pv-notes__title { font-weight: 650; margin-bottom: 4px; }
.pv-notes ul { margin: 0; padding-left: 18px; }

/* Приёмка клиента */
.pv-accept { margin: 0; padding: 0; list-style: none; font-size: 13px; }
.pv-accept li { display: flex; gap: 8px; padding: 4px 0; }
.pv-accept__mark { width: 1.1em; flex: none; text-align: center; color: var(--pv-muted); font-weight: 700; }
.pv-accept li.is-ok .pv-accept__mark { color: var(--pv-ok); }
.pv-accept li.is-fail .pv-accept__mark { color: var(--pv-err); }
.pv-accept li.is-fail { color: var(--pv-fg); }
.pv-accept__score { font-size: 22px; font-weight: 750; margin-bottom: 4px; }
.pv-accept__score.is-full { color: var(--pv-ok); }
.pv-badge { display: inline-block; padding: 1px 8px; border-radius: 999px; background: var(--pv-surface-2); font-size: 12px; font-weight: 650; }
.pv-badge.is-full { background: var(--pv-ok); color: var(--pv-on-accent); }

/* Проектор */
.pv-projector { padding: 16px; }
.pv-projector__bar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 16px; }
.pv-projector__bar h1 { margin: 0; font-size: 22px; flex: 1; }
.pv-gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); gap: 16px; }
.pv-gallery__item { padding: 14px; border: 1px solid var(--pv-line); border-radius: var(--pv-radius); background: var(--pv-surface); min-width: 0; }
.pv-gallery__team { font-size: 13px; font-weight: 700; color: var(--pv-accent); margin-bottom: 6px; }

/* Цвет дорожки — классом, а не атрибутом style: строгая CSP страницы
   запрещает inline-стили в разметке */
.pv-lane--model { --lane: var(--pv-lane-model); }
.pv-lane--sales-db { --lane: var(--pv-lane-sales-db); }
.pv-lane--company-notes { --lane: var(--pv-lane-company-notes); }
.pv-lane--dashboard { --lane: var(--pv-lane-dashboard); }
.pv-lane--skill { --lane: var(--pv-lane-skill); }
.pv-lane--unknown { --lane: var(--pv-muted); }
.pv-ctx--system { background: var(--pv-ctx-system); }
.pv-ctx--skill { background: var(--pv-ctx-skill); }
.pv-ctx--card { background: var(--pv-ctx-card); }
.pv-ctx--tool_results { background: var(--pv-ctx-tool_results); }
.pv-ctx--model { background: var(--pv-ctx-model); }

/* В панели у .card потолок 40rem — трассе с дорожками и дашборду этого мало */
.card.pa-wide { max-width: none; }
.table-scroll { overflow-x: auto; }

/* Задание по фазам и советы по навыку */
.hap-task p, .hap-task ol { margin: 0 0 8px; }
.hap-task ol, .hap-tips ul { padding-left: 20px; }
.hap-task li, .hap-tips li { margin-bottom: 4px; }
.hap-task__lead { font-weight: 650; font-size: 16px; }
.hap-task__note { color: var(--pv-muted); font-size: 13px; }
.hap-task code, .hap-tips code { font-size: 12px; padding: 0 3px; border-radius: 3px; background: var(--pv-surface-2); }
.hap-tips { margin-top: 10px; padding: 8px 10px; border: 1px solid var(--pv-line); border-radius: 8px; font-size: 13px; }
.hap-tips summary { cursor: pointer; font-weight: 600; }
.hap-tips ul { margin: 8px 0 0; }

.hap-logout { display: inline; margin: 0; }
.hap-closed__box .hap-logout { display: block; margin-top: 10px; }

.hap-card__ru { margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--pv-line); font-size: 13px; color: var(--pv-muted); }
.hap-card__ru:empty { display: none; }

.pv-gallery__team { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.pv-gallery__item.is-reference { border: 2px solid var(--pv-ok); }
