* { box-sizing: border-box; }
body.hf-graph-page {
  font-family: system-ui, -apple-system, Segoe UI, sans-serif;
  margin: 0;
  padding: 0;
  padding-bottom: 1rem;
  background: var(--hf-bg);
  color: var(--hf-text);
  line-height: 1.45;
  max-width: none;
}
/* Контент страницы: горизонтальные поля задаёт site-chrome для body; блок секций на всю ширину под широкий график */
body.hf-graph-page > .ui-sections {
  max-width: none;
  width: 100%;
  box-sizing: border-box;
}
a { color: var(--hf-link); }
h1 { font-size: 1.35rem; margin: 0 0 0.5rem; font-weight: 600; }
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 1rem;
  align-items: flex-end;
  margin-bottom: 0.75rem;
  padding: 0.75rem;
  background: var(--hf-bg-panel-solid);
  border: 1px solid var(--hf-border);
  border-radius: 8px;
}
.field label { display: block; font-size: 0.75rem; color: var(--hf-muted); margin-bottom: 0.2rem; }
/* Подписи в блоке «Фильтры/разрыв/порог» — крупнее обычной .field label, чтобы их
   можно было читать с расстояния (запрос оператора). */
.filters-gap-row > .field > label,
.gap-controls > .field > label {
  font-size: 1rem;
  line-height: 1.35;
  color: var(--hf-text);
  margin-bottom: 0.3rem;
}
.field select, input[type="datetime-local"] {
  padding: 0.35rem 0.5rem;
  min-width: 10rem;
  background: var(--hf-input-bg);
  border: 1px solid var(--hf-border);
  color: var(--hf-text);
  border-radius: 4px;
}
#deviceId { min-width: 14rem; }
#correspondent { min-width: 18rem; }
button {
  padding: 0.4rem 0.75rem;
  background: var(--hf-btn);
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
}
button:hover { background: var(--hf-btn-hover); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.secondary { background: var(--hf-btn-secondary); color: var(--hf-text); }
button.secondary:hover { filter: brightness(1.08); }
.row { display: flex; flex-wrap: wrap; gap: 0.75rem 1rem; align-items: flex-end; margin-bottom: 0.75rem; }
.gap-controls {
  display: inline-flex;
  flex-wrap: nowrap;
  align-items: flex-end;
  gap: 0.45rem;
}
.gap-controls .field { margin: 0; }
.gap-controls #btnToggleHampel { white-space: nowrap; }
/* ~80% ширины окна; высота — остаток до низа вьюпорта с запасом под блок «Период» (пресеты 6 ч … видны без прокрутки при типичной раскладке) */
#chartWrap {
  margin: 0 auto 0.35rem;
  width: min(80vw, 100%);
  max-width: 100%;
  height: max(200px, calc(100vh - 26rem));
  position: relative;
}
#chartWrap canvas {
  touch-action: none;
  cursor: crosshair;
}
/* Прогресс-бар загрузки данных графика — индетерминированный, поверх области canvas.
   Прячется, когда график построен; показывается на время fetch /series/multi. */
.chart-progress {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: rgba(128, 128, 160, 0.18);
  overflow: hidden;
  display: none;
  z-index: 5;
  pointer-events: none;
  border-radius: 2px;
}
.chart-progress.is-active { display: block; }
.chart-progress__bar {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 40%;
  background: var(--hf-btn);
  border-radius: 2px;
  animation: chart-progress-slide 1.2s ease-in-out infinite;
}
@keyframes chart-progress-slide {
  0%   { left: -42%; }
  60%  { left: 60%; }
  100% { left: 102%; }
}
/* Полупрозрачная подложка с центральной подписью «Загрузка…» — клиенту так
   виднее, что график именно обновляется, а не «застрял». Показывается одновременно
   с прогресс-баром через тот же класс .is-active на родителе #chartWrap. */
#chartWrap.is-loading::after {
  content: 'Загрузка данных…';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  font-weight: 600;
  color: var(--hf-muted);
  background: rgba(0, 0, 0, 0.04);
  pointer-events: none;
  z-index: 4;
}
html[data-theme="light"] #chartWrap.is-loading::after {
  background: rgba(255, 255, 255, 0.55);
}

.hf-chart-tooltip {
  pointer-events: none;
  max-width: min(96vw, 22rem);
}
.hf-chart-tooltip .hf-tooltip-inner {
  background: var(--hf-popup-bg);
  border: 1px solid var(--hf-popup-border);
  border-radius: 6px;
  padding: 0.45rem 0.65rem;
  font-size: 0.82rem;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}
.hf-chart-tooltip .hf-tooltip-title {
  color: var(--hf-text);
  font-weight: 600;
  margin-bottom: 0.35rem;
  white-space: nowrap;
}
.hf-chart-tooltip .hf-tooltip-line {
  margin: 0.15rem 0;
  line-height: 1.35;
}
.hf-chart-tooltip .hf-tooltip-line.hf-trend-up {
  color: var(--hf-trend-up);
}
.hf-chart-tooltip .hf-tooltip-line.hf-trend-down {
  color: var(--hf-trend-down);
}
.hf-chart-tooltip .hf-tooltip-line.hf-trend-neutral {
  color: var(--hf-muted);
}
/* Статус построения и сброс масштаба — в секции периода */
#secPeriod #ok.graph-build-status {
  width: 100%;
  max-width: 48rem;
  margin: 0.75rem auto 0;
  text-align: center;
  font-weight: 500;
  transition: color 0.18s ease, background 0.18s ease, border-color 0.18s ease;
}
/* «Красная» индикация: автообновление графика опоздало (плановый момент уже прошёл).
   Сама строка остаётся центральным монитором — насыщенный фон, белый текст. */
#secPeriod #ok.graph-build-status.is-stale {
  color: #fff;
  background: #d93636;
  border: 1px solid #ff6f6f;
  border-radius: 6px;
  padding: 0.35rem 0.65rem;
  font-weight: 600;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.35);
}
.filters-gap-row {
  margin-top: 0.65rem;
}
/* Блок «Период»: пресеты и поля по центру */
#secPeriod .section-body {
  display: flex;
  flex-direction: column;
  align-items: center;
}
#secPeriod .graph-period-presets {
  justify-content: center;
  width: 100%;
}
#secPeriod .row {
  justify-content: center;
}
.graph-period-presets {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.5rem;
  margin: 0.35rem 0 0.75rem;
  font-size: 0.78rem;
  color: var(--hf-muted);
}
.graph-period-presets button { padding: 0.25rem 0.5rem; font-size: 0.78rem; }
.graph-period-presets .graph-period-preset.active {
  background: var(--hf-btn);
  color: #fff;
  border-color: transparent;
}
h2.graph-section-title { font-size: 1rem; margin: 0 0 0.5rem; font-weight: 600; }
.err { color: #f88; font-size: 0.9rem; margin-top: 0.5rem; white-space: pre-wrap; }
.ok { color: #5be84d; font-size: 0.85rem; margin-top: 0.5rem; }
.cap { color: #fa0; font-size: 0.85rem; margin-top: 0.35rem; }
.warn { color: #fc6; font-size: 0.85rem; margin-top: 0.35rem; }
.named-pick-sink {
  display: none;
}
.mono { font-family: ui-monospace, monospace; font-size: 0.78rem; }
.toolbar-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: flex-end; }
.chart-data-sheet {
  margin-top: 0.75rem;
  border: 1px solid var(--hf-border);
  border-radius: 8px;
  background: var(--hf-bg-panel-solid);
  overflow: hidden;
}
.chart-data-sheet > summary {
  cursor: pointer;
  padding: 0.55rem 0.75rem;
  font-size: 0.88rem;
  color: var(--hf-text);
  font-weight: 600;
  list-style-position: inside;
  user-select: none;
}
.chart-data-sheet > summary:hover { background: rgba(128, 128, 160, 0.06); }
.chart-data-sheet-body {
  padding: 0 0.75rem 0.75rem;
  font-size: 0.78rem;
  max-height: 75vh;
  overflow: auto;
}
.sheet-series-table { width: 100%; border-collapse: collapse; margin-bottom: 0.65rem; }
.sheet-series-table th, .sheet-series-table td {
  padding: 0.35rem 0.45rem;
  text-align: left;
  border-bottom: 1px solid var(--hf-border);
  vertical-align: top;
}
.sheet-series-table th { color: var(--hf-muted); font-weight: 600; font-size: 0.74rem; white-space: nowrap; }
.sheet-points-pre {
  margin: 0 0 0.85rem;
  padding: 0.45rem 0.5rem;
  background: var(--hf-bg);
  border: 1px solid var(--hf-border);
  border-radius: 6px;
  max-height: 14rem;
  overflow: auto;
  white-space: pre;
  font-size: 0.72rem;
}
.param-empty-hint {
  display: none;
  margin: 0 0 0.65rem;
  font-size: 0.88rem;
  color: var(--hf-muted);
  line-height: 1.5;
}
.param-empty-hint.is-visible {
  display: block;
}
.param-empty-hint a {
  color: var(--hf-link);
}
/* Блок параметров: кнопки и текст по центру */
#secParams .section-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}
.param-btns {
  display: flex;
  flex-direction: column;
  gap: 0.35rem 0.4rem;
  margin-bottom: 0.5rem;
  min-height: 0;
  align-items: stretch;
}
.param-btns:empty { display: none; }
/* Одна строка = один корреспондент (маяк). Сверху — его метка с карты,
   снизу — все его «слоты» в порядке передачи. */
.param-row {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0.25rem 0.4rem;
  border-radius: 6px;
  background: rgba(128, 144, 176, 0.07);
  border: 1px solid rgba(128, 144, 176, 0.15);
}
.param-row-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--hf-muted);
  padding: 0 0.1rem;
  text-align: left;
}
.param-row-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.4rem;
  justify-content: flex-start;
}
.param-btn {
  padding: 0.28rem 0.7rem;
  font-size: 0.8rem;
  border-radius: 999px;
  background: var(--hf-btn-secondary);
  color: var(--hf-text);
  border: 1px solid var(--hf-border);
  white-space: nowrap;
  max-width: 18rem;
  overflow: hidden;
  text-overflow: ellipsis;
}
.param-btn:hover { filter: brightness(1.12); background: var(--hf-btn-secondary); }
.param-btn.active {
  background: var(--hf-btn);
  color: #fff;
  border-color: transparent;
}
/* Лента маяков — всегда сверху списка параметров; при росте количества прокручивается
   горизонтально, не переносится на несколько строк. */
.param-beacon-strip {
  width: 100%;
  margin: 0 0 0.5rem;
  overflow-x: auto;
  overflow-y: hidden;
  /* Тонкая полоса прокрутки в системных тёмных темах. */
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
}
.param-beacon-list {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.4rem 0.5rem;
  padding: 0.1rem 0.1rem 0.4rem;
  width: max-content;
  min-width: 100%;
  /* По центру, как и кнопки слотов. Когда маяков становится больше ширины ленты,
     width: max-content превышает min-width: 100%, и justify-content уже не влияет —
     активируется горизонтальная прокрутка родителя .param-beacon-strip. */
  justify-content: center;
  align-items: center;
}
.param-beacon-btn {
  flex: 0 0 auto;
  padding: 0.45rem 0.95rem;
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: 999px;
  background: var(--hf-btn-secondary);
  color: var(--hf-text);
  border: 1px solid var(--hf-border);
  max-width: 22rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.param-beacon-btn:hover { filter: brightness(1.12); background: var(--hf-btn-secondary); }
.param-beacon-btn.active {
  background: var(--hf-btn);
  color: #fff;
  border-color: transparent;
}
body[data-graph-view-mode="beacons"] #paramBtns,
body[data-graph-view-mode="slots"] #paramBtns {
  align-items: stretch;
}
.ui-sections {
  display: grid;
  gap: 0.6rem;
}
.ui-section {
  border: 1px solid var(--hf-border);
  border-radius: 8px;
  background: var(--hf-bg-panel-solid);
  overflow: hidden;
}
.ui-section > summary {
  cursor: pointer;
  padding: 0.6rem 0.75rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--hf-text);
  list-style-position: inside;
  user-select: none;
}
.ui-section > summary:hover { background: rgba(128, 128, 160, 0.06); }
.section-body { padding: 0.6rem 0.75rem 0.75rem; }
.help-list {
  margin: 0;
  padding-left: 1.15rem;
  color: var(--hf-muted);
  /* По запросу оператора текст справки увеличен — читался слишком мелко. */
  font-size: 1rem;
  line-height: 1.55;
}
.help-list li { margin: 0.25rem 0; }
@media (max-width: 640px) {
  body.hf-graph-page #chartWrap {
    width: min(92vw, 100%);
    height: max(180px, calc(100vh - 24rem));
  }
  .row { gap: 0.55rem; align-items: stretch; }
  .row .field, .row > button { width: 100%; }
  .row .field select, .row input[type="datetime-local"] { width: 100%; min-width: 0; }
  .row > button { justify-content: center; }
  .graph-period-presets { gap: 0.35rem; }
  .graph-period-presets button { flex: 1 1 calc(50% - 0.35rem); min-width: 0; }
  .gap-controls {
    width: 100%;
    flex-wrap: nowrap;
    align-items: stretch;
    gap: 0.4rem;
  }
  .gap-controls .field { flex: 1 1 auto; min-width: 0; }
  .gap-controls #btnToggleHampel {
    flex: 0 0 auto;
    width: auto;
  }
}
