:root {
  --bg: #0f1419;
  --surface: #181e26;
  --surface2: #202832;
  --surface3: #28323e;
  --border: #2c3644;
  --border-soft: #232b36;
  --text: #e8edf4;
  --muted: #8a96a6;
  --dim: #5f6b7a;
  --accent: #5ee6b5;
  --accent-dim: #2e7a63;
  --danger: #ff6b6b;
  --warn: #ffb84d;
  --info: #7ab8ff;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

/* Скрытие должно перебивать любые display у блоков */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* ---------- вход ---------- */
.gate { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.gate-card {
  width: 100%; max-width: 360px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 26px;
  display: flex; flex-direction: column; gap: 14px;
}
.gate-card h1 { margin: 0; font-size: 19px; font-weight: 600; letter-spacing: -.2px; }
.gate-card .sub { margin: -8px 0 4px; font-size: 12.5px; color: var(--dim); }

/* ---------- шапка ---------- */
#top {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 20px; border-bottom: 1px solid var(--border-soft);
  background: var(--surface); position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 600; letter-spacing: -.2px; }
#top .spacer { flex: 1 1 auto; }
#acct-select { width: auto; min-width: 240px; max-width: 380px; }
#bm-select { width: auto; min-width: 150px; max-width: 220px; }
#acct-search { width: 150px; }
#acct-count { font-size: 11.5px; color: var(--dim); }
#acct-meta { font-family: var(--mono); font-size: 11.5px; color: var(--dim); }
#who { font-size: 12.5px; color: var(--muted); }

/* ---------- вкладки ---------- */
#tabs {
  display: flex; gap: 20px; padding: 0 20px;
  border-bottom: 1px solid var(--border-soft); background: var(--surface);
}
#tabs, #top { padding-left: max(20px, calc((100vw - 1100px) / 2)); padding-right: 20px; }
#tabs button {
  background: none; border: none; color: var(--muted); font-family: inherit;
  padding: 11px 0; font-size: 13.5px; cursor: pointer; border-bottom: 2px solid transparent;
}
#tabs button.active { color: var(--text); border-bottom-color: var(--accent); }

main { padding: 18px 20px 60px; max-width: 1100px; margin: 0 auto; width: 100%; }

/* ---------- блоки ---------- */
.card { border: 1px solid var(--border-soft); border-radius: 8px; background: var(--surface); margin-bottom: 12px; }
.card > .head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 11px 14px; border-bottom: 1px solid var(--border-soft);
}
.card > .body { padding: 14px; }
.card h3 { margin: 0; font-size: 14px; font-weight: 600; }
.card .sub { font-size: 11.5px; color: var(--dim); margin-top: 2px; }

/* ---------- поля ---------- */
label.field { display: flex; flex-direction: column; gap: 5px; }
label.field > span { font-size: 11.5px; color: var(--muted); }
label.field .hint { font-size: 10.5px; color: var(--dim); }
input, select, textarea {
  background: var(--surface2); border: 1px solid var(--border); border-radius: 6px;
  color: var(--text); padding: 8px 10px; font-size: 13.5px; font-family: var(--mono);
  outline: none; width: 100%;
}
select { font-family: inherit; }
textarea { min-height: 90px; resize: vertical; font-size: 11.5px; word-break: break-all; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
/* Поля выравниваются по верху и растягиваются равномерно,
   чтобы подсказки под ними не толкали соседей вниз. */
.row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px 16px;
  align-items: start;
}
.row > label.field { width: auto; min-width: 0; }
.row > label.field.wide { grid-column: span 2; }
.row > label.field .hint { min-height: 26px; }
.grow { flex: 1 1 200px; min-width: 0; }

/* Строки со списками остаются гибкими */
.listrow { display: flex; }

/* ---------- тумблер ---------- */
.toggle { display: flex; align-items: center; gap: 9px; }
.toggle > button {
  width: 34px; height: 19px; border-radius: 10px; position: relative; flex: none;
  background: var(--surface2); border: 1px solid var(--border); cursor: pointer; padding: 0;
}
.toggle > button::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 13px; height: 13px;
  border-radius: 50%; background: var(--dim); transition: left .15s;
}
.toggle > button[aria-pressed="true"] { background: var(--accent-dim); border-color: var(--accent-dim); }
.toggle > button[aria-pressed="true"]::after { left: 17px; background: var(--accent); }
.toggle .label { font-size: 13.5px; color: var(--muted); font-weight: 500; }
.toggle > button[aria-pressed="true"] ~ .label { color: var(--text); }
.tag {
  font-size: 9px; letter-spacing: .6px; text-transform: uppercase; color: var(--warn);
  border: 1px solid rgba(255,184,77,.27); border-radius: 3px; padding: 1px 5px;
}

/* ---------- кнопки ---------- */
button.btn {
  border-radius: 6px; padding: 8px 13px; font-size: 13px; cursor: pointer; font-family: inherit;
  background: var(--surface2); color: var(--text); border: 1px solid var(--border);
}
button.btn.primary { background: var(--accent); color: #06251c; border: none; font-weight: 600; }
button.btn.danger { background: transparent; color: var(--danger); border-color: rgba(255,107,107,.27); }
button.btn:disabled { opacity: .45; cursor: not-allowed; }
.row > button.btn { align-self: end; margin-bottom: 1px; }
button.link { background: none; border: none; color: var(--info); font-size: 12.5px; cursor: pointer; font-family: inherit; padding: 0; }
.spread { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- чипы профилей ---------- */
#chips { display: flex; gap: 7px; flex-wrap: wrap; margin-bottom: 12px; }
#chips button {
  background: transparent; border: 1px solid var(--border-soft); color: var(--muted);
  border-radius: 6px; padding: 7px 12px; font-size: 13px; cursor: pointer; font-family: inherit;
}
#chips button.active { background: var(--surface3); border-color: var(--border); color: var(--text); }

/* ---------- заметки ---------- */
.note { font-size: 12px; color: var(--dim); line-height: 1.5; margin-bottom: 11px; }
.note.warn { color: var(--warn); background: #241c0c; border: 1px solid rgba(255,184,77,.2); border-radius: 6px; padding: 10px 12px; }
.note.bad { color: var(--danger); background: #241214; border: 1px solid rgba(255,107,107,.2); border-radius: 6px; padding: 10px 12px; }

/* ---------- правила ---------- */
.rule { border-left: 2px solid var(--border); background: var(--bg); border-radius: 0 6px 6px 0; padding: 10px 12px; margin-bottom: 6px; }
.rule.stop { border-left-color: var(--danger); }
.rule.on { border-left-color: var(--warn); }
.rule.scale { border-left-color: var(--accent); }
.rule.alert { border-left-color: var(--info); }
.rule .name { font-size: 12.5px; margin-bottom: 3px; }
.rule .cond, .rule .act { font-family: var(--mono); font-size: 11.5px; color: var(--muted); line-height: 1.55; }
.rule .act { color: var(--dim); }

.ladder {
  border: 1px solid var(--border-soft); border-radius: 6px; padding: 10px 12px; background: var(--bg);
  font-family: var(--mono); font-size: 12px; color: var(--muted); line-height: 1.85;
  white-space: pre-wrap; user-select: text;
}
.ladder .cap { color: var(--text); }

.listrow {
  display: flex; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--border-soft);
  align-items: flex-start;
}
.listrow .name { font-size: 13px; margin-bottom: 2px; }
.listrow .meta { font-family: var(--mono); font-size: 11px; color: var(--dim); }

.log { font-family: var(--mono); font-size: 11.5px; color: var(--muted); line-height: 1.8; }

#toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 22px;
  background: var(--surface3); border: 1px solid var(--border); border-radius: 8px;
  padding: 11px 16px; font-size: 13px; box-shadow: 0 10px 34px rgba(0,0,0,.5); max-width: 90vw;
}
#toast.bad { border-color: rgba(255,107,107,.4); color: var(--danger); }

/* ---------- таблица кампаний ---------- */
.stats { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.stats th {
  text-align: right; font-weight: 500; color: var(--muted); font-size: 11px;
  padding: 6px 8px; border-bottom: 1px solid var(--border-soft); white-space: nowrap;
}
.stats th:first-child, .stats td:first-child { text-align: left; }
.stats td {
  padding: 9px 8px; border-bottom: 1px solid var(--border-soft);
  text-align: right; font-family: var(--mono); white-space: nowrap;
}
.stats td:first-child { font-family: inherit; white-space: normal; min-width: 200px; }
.stats tr:hover td { background: var(--surface2); }
.stats tfoot td { border-bottom: none; color: var(--text); font-weight: 600; padding-top: 12px; }
.st-dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; margin-right: 7px; vertical-align: middle; }
.st-on { background: var(--accent); }
.st-off { background: var(--dim); }
.st-warn { background: var(--warn); }
.st-dead { background: var(--danger); }
.bad-text { color: var(--danger); }
.muted { color: var(--dim); }
.tbl-wrap { overflow-x: auto; }

/* ---------- полоса предупреждений ---------- */
#alerts {
  background: #2a1a0a;
  border-bottom: 1px solid rgba(255,184,77,.3);
  padding: 10px 20px;
  padding-left: max(20px, calc((100vw - 1100px) / 2));
  font-size: 12.5px;
  color: var(--warn);
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
}
#alerts .msg { flex: 1 1 320px; line-height: 1.5; }
#alerts button.btn { border-color: rgba(255,184,77,.35); color: var(--warn); background: transparent; }

.range-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.range-row input[type="date"] { width: auto; font-size: 12.5px; padding: 6px 8px; }

/* Длинные списки прокручиваются внутри блока, а не тянут страницу */
.scroll-box {
  max-height: 300px;
  overflow-y: auto;
  padding-right: 6px;
  border: 1px solid var(--border-soft);
  border-radius: 6px;
  padding: 10px 12px;
  background: var(--bg);
}
.scroll-box::-webkit-scrollbar { width: 8px; }
.scroll-box::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.scroll-box::-webkit-scrollbar-track { background: transparent; }
