:root {
  color-scheme: dark light;
  --bg: #0e1117;
  --bg-soft: #151a23;
  --line: #232a36;
  --text: #dfe4ec;
  --muted: #7d8697;
  --accent: #4c8dff;
  --bull: #26a67a;
  --bear: #e0475b;
  --radius: 8px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f7f8fa;
    --bg-soft: #ffffff;
    --line: #dfe3ea;
    --text: #1b2430;
    --muted: #6b7688;
    --accent: #2563eb;
    --bull: #0f9d63;
    --bear: #d92b45;
  }
}

* { box-sizing: border-box; }

/* display у .app и .gate перебивает атрибут hidden, поэтому он усилен явно. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, select, input { font: inherit; color: inherit; }

/* --- вход ---------------------------------------------------------------- */

.gate {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  padding: 24px;
}

.gate__card {
  width: min(360px, 100%);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 28px;
  display: grid; gap: 14px;
}

.gate__card h1 { margin: 0; font-size: 18px; font-weight: 600; letter-spacing: .01em; }
.gate__hint { margin: 0; color: var(--muted); font-size: 12px; }
.gate__hint code { background: var(--bg); padding: 1px 5px; border-radius: 4px; }

.gate__card input {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  outline: none;
}
.gate__card input:focus { border-color: var(--accent); }

.gate__card button {
  background: var(--accent);
  color: #fff;
  border: 0; border-radius: var(--radius);
  padding: 10px; cursor: pointer; font-weight: 600;
}

.gate__error { margin: 0; color: var(--bear); font-size: 12px; }

/* --- каркас -------------------------------------------------------------- */

:root { --bar-h: 48px; }

.app { height: 100dvh; display: grid; grid-template-rows: auto 1fr; }

/* Шапка и баннер — один блок: иначе появление баннера добавляет строку в
   сетку и главная область теряет высоту. */
.top { display: grid; }

/* Высота шапки фиксирована: от неё отсчитывается выдвижная панель на узком
   экране, и перенос строки сдвинул бы её на середину графика. */
.bar {
  display: flex; align-items: center; gap: 14px;
  padding: 0 14px;
  flex-wrap: nowrap; overflow: hidden;
  border-bottom: 1px solid var(--line);
  background: var(--bg-soft);
}

.bar__brand { font-weight: 700; letter-spacing: .12em; font-size: 12px; color: var(--muted); flex: none; }

.bar__status {
  margin-left: auto;
  color: var(--muted); font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.bar__icon {
  display: none; flex: none;
  background: none; border: 1px solid var(--line);
  border-radius: var(--radius); padding: 4px 9px; cursor: pointer;
}

.field { display: flex; align-items: center; gap: 6px; flex: none; }
.field > span { color: var(--muted); font-size: 12px; }

.field select {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 5px 8px;
  cursor: pointer;
}

.badge {
  flex: none;
  white-space: nowrap;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 11px;
  color: var(--muted);
}

.main { display: grid; grid-template-columns: 1fr 250px; min-height: 0; }

.chart { position: relative; min-width: 0; }
#canvas { display: block; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }

.legend {
  position: absolute; top: 10px; left: 12px;
  display: flex; flex-wrap: wrap; gap: 4px 12px;
  font-size: 11px; color: var(--muted);
  pointer-events: none;
  text-shadow: 0 1px 2px var(--bg);
}
.legend b { font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }

.tooltip {
  position: absolute;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 10px;
  font-size: 11.5px;
  line-height: 1.5;
  pointer-events: none;
  max-width: 260px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .35);
  z-index: 5;
}
.tooltip h4 { margin: 0 0 4px; font-size: 11.5px; }
.tooltip dl { display: grid; grid-template-columns: auto 1fr; gap: 1px 10px; margin: 0; }
.tooltip dt { color: var(--muted); }
.tooltip dd { margin: 0; font-variant-numeric: tabular-nums; }
.tooltip hr { border: 0; border-top: 1px solid var(--line); margin: 6px 0; }

.panel {
  border-left: 1px solid var(--line);
  background: var(--bg-soft);
  overflow-y: auto;
  padding: 4px 0 16px;
}

.panel__block { padding: 12px 14px; border-bottom: 1px solid var(--line); }
.panel__block h2 {
  margin: 0 0 8px; font-size: 11px; text-transform: uppercase;
  letter-spacing: .08em; color: var(--muted); font-weight: 600;
}

.layers { display: grid; gap: 3px; }

.layers label {
  display: flex; align-items: center; gap: 7px;
  cursor: pointer; padding: 2px 0; font-size: 12px;
}
.layers input { accent-color: var(--accent); margin: 0; }
.layers .swatch { width: 9px; height: 9px; border-radius: 2px; flex: none; }

.state { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; margin: 0; font-size: 12px; }
.state dt { color: var(--muted); }
.state dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.state .bull { color: var(--bull); }
.state .bear { color: var(--bear); }

.signals { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }

.signals li {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
  cursor: pointer;
  font-size: 11.5px;
}
.signals li:hover { border-color: var(--accent); }
.signals time { color: var(--muted); font-variant-numeric: tabular-nums; }
.signals .rule { display: block; font-weight: 600; }
.signals .empty { color: var(--muted); border: 0; padding: 0; cursor: default; }

@media (max-width: 860px) {
  .main { grid-template-columns: 1fr; }
  .bar__icon { display: block; }
  .bar { gap: 10px; }
  .bar__status { display: none; }
  .panel {
    position: fixed; inset: auto 0 0 auto; top: var(--panel-top, 48px); height: auto;
    width: min(300px, 90vw);
    transform: translateX(100%);
    transition: transform .18s ease;
    z-index: 10;
    box-shadow: -12px 0 32px rgba(0, 0, 0, .28);
  }
  .panel.open { transform: none; }
  .field > span { display: none; }
  .legend { font-size: 10px; gap: 2px 8px; }
}

@media (max-width: 420px) {
  .badge { display: none; }
}

/* --- установка, предупреждения, диалоги ---------------------------------- */

.gate__note { margin: 0; color: var(--muted); font-size: 11px; }

.alert {
  padding: 10px 14px;
  background: #7f1d2b;
  color: #fff;
  font-size: 12.5px;
  line-height: 1.5;
}
.alert b { font-weight: 700; }
.alert code {
  background: rgba(0, 0, 0, .28);
  padding: 1px 5px;
  border-radius: 4px;
}


.bar__button, .panel__button {
  flex: none;
  background: none;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 5px 10px;
  cursor: pointer;
  white-space: nowrap;
}
.bar__button:hover, .panel__button:hover { border-color: var(--accent); color: var(--accent); }

/* Имя класса отличается от .empty в списке сигналов намеренно: то правило
   уже занято, а absolute + inset:0 на общем классе перекрывает всю страницу. */
.chart-empty {
  position: absolute; inset: 0;
  display: grid; place-content: center; justify-items: center;
  gap: 6px; text-align: center;
  background: var(--bg);
}
.chart-empty h2 { margin: 0; font-size: 15px; font-weight: 600; }
.chart-empty p { margin: 0 0 8px; color: var(--muted); }

.chart-empty__button {
  background: var(--accent); color: #fff;
  border: 0; border-radius: var(--radius);
  padding: 9px 18px; cursor: pointer; font-weight: 600;
}

.panel__note { margin: 0 0 8px; color: var(--muted); font-size: 11.5px; line-height: 1.5; }

.cron {
  display: block;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 8px;
  font-size: 10.5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  word-break: break-all;
  margin-bottom: 8px;
}

.dialog {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg-soft);
  color: var(--text);
  padding: 22px;
  width: min(360px, 92vw);
}
.dialog::backdrop { background: rgba(0, 0, 0, .55); }
.dialog h2 { margin: 0 0 14px; font-size: 15px; }

.dialog__field { display: grid; gap: 5px; margin-bottom: 14px; }
.dialog__field span { color: var(--muted); font-size: 12px; }

.dialog__field input {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 9px 11px;
  outline: none;
}
.dialog__field input:focus { border-color: var(--accent); }

.dialog__frames {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 9px 11px;
  margin: 0 0 14px;
  display: grid; gap: 4px;
}
.dialog__frames legend { color: var(--muted); font-size: 11px; padding: 0 4px; }
.dialog__frames label { display: flex; align-items: center; gap: 7px; font-size: 12.5px; }

.dialog__actions { display: flex; justify-content: flex-end; gap: 8px; margin: 0; padding: 0; }
.dialog__actions button {
  background: none; border: 1px solid var(--line);
  border-radius: var(--radius); padding: 8px 14px; cursor: pointer;
}
.dialog__actions .primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

.alert--warning { background: #7a5510; }
