/* Лейаут «прибор»: сверху ввод и битовая карта адреса, ниже сетка результатов */
:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --ink: #142233;
  --muted: #5d6b7c;
  --line: #dbe1e8;
  --net: #2c56d6;        /* биты сети */
  --net-soft: #e3eafc;
  --host: #d9822b;       /* биты хоста */
  --host-soft: #fbeedd;
  --ok: #1f8a5b;
  --bad: #c2413a;
  --priv: #0f766e;       /* частные адреса: спокойный бирюзовый */
  --priv-soft: #e3f4f1;
  --f-display: "Unbounded", "Segoe UI", system-ui, sans-serif;
  --f-body: "Golos Text", "Segoe UI", system-ui, sans-serif;
  --f-mono: "JetBrains Mono", ui-monospace, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1620; --surface: #172230; --ink: #e4ebf3; --muted: #93a2b4; --line: #2a3747;
    --net: #7c9cff; --net-soft: #1f2d52; --host: #f0a75a; --host-soft: #3d2c19;
    --ok: #4cc28c; --bad: #ef7a72; --priv: #5fd4c3; --priv-soft: #133733; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1620; --surface: #172230; --ink: #e4ebf3; --muted: #93a2b4; --line: #2a3747;
  --net: #7c9cff; --net-soft: #1f2d52; --host: #f0a75a; --host-soft: #3d2c19;
  --ok: #4cc28c; --bad: #ef7a72; --priv: #5fd4c3; --priv-soft: #133733; color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
/* пиксель Метрики для посетителей без JS; inline-style запрещён CSP, поэтому классом */
.metrika-pixel { position: absolute; left: -9999px; }
html:not(.js) .js-only { display: none !important; }
.js .nojs { display: none !important; }

body {
  margin: 0;
  background: var(--bg); color: var(--ink);
  font-family: var(--f-body); font-size: 15px; line-height: 1.5;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 24px 48px;
}
a { color: var(--net); }
.wrap { max-width: 1080px; margin: 0 auto; display: grid; gap: 32px; }
main { display: grid; gap: 28px; }
h1, h2, h3, .h3 { text-wrap: balance; margin: 0; }
h1 { font-family: var(--f-display); font-weight: 700; font-size: clamp(24px, 3.6vw, 34px); letter-spacing: -0.01em; }
h2 { font-family: var(--f-display); font-weight: 500; font-size: 20px; }
h3, .h3 { font-family: var(--f-body); font-size: 16px; font-weight: 600; }
p { margin: 0; }
code { font-family: var(--f-mono); font-size: .92em; background: var(--surface); border: 1px solid var(--line); padding: 0 5px; border-radius: 4px; }
.mono { font-family: var(--f-mono); font-variant-numeric: tabular-nums; }
.eyebrow { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; }
.lead { color: var(--muted); }
.hint { font-size: 13px; color: var(--muted); }
.err { color: var(--bad); font-size: 14px; }
.stack { display: grid; gap: 22px; }
.intro { display: grid; gap: 8px; }
:focus-visible { outline: 2px solid var(--net); outline-offset: 2px; }

/* ===== Шапка и меню ===== */
header.site { display: grid; gap: 14px; }
header.site .top { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; text-decoration: none; color: var(--ink); }
.brand .logo { font-family: var(--f-display); font-weight: 700; font-size: 22px; line-height: 1; }
/* квадратная точка в «ip.kits», как разделитель октетов */
.brand .logo .sq { display: inline-block; width: .26em; height: .26em; background: var(--host); border-radius: 2px; margin: 0 .07em; }
/* знак: плашка цвета текста, буквы цвета карточки — в тёмной теме инвертируется сам */
.brand-mark { width: 34px; height: 34px; flex: none; }
.brand-mark .lm-bg { fill: var(--ink); }
.brand-mark .lm-fg { fill: var(--surface); }
.brand-mark .lm-ring { fill: none; stroke: var(--surface); stroke-width: 5.5; }
.brand-mark .lm-dot { fill: var(--host); }
.brand .tag { font-family: var(--f-mono); font-size: 13px; color: var(--net); }
.theme-toggle {
  display: grid; place-items: center; width: 40px; height: 40px; padding: 0; cursor: pointer;
  border: 1px solid var(--line); border-radius: 50%; background: var(--surface); color: var(--ink);
}
.theme-toggle:hover { border-color: var(--net); color: var(--net); }
.theme-toggle .i-sun { display: none; }
/* иконка показывает действие: в тёмной теме (явной или системной) — солнце */
:root[data-theme="dark"] .theme-toggle .i-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .i-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .i-sun { display: block; }
  :root:not([data-theme="light"]) .theme-toggle .i-moon { display: none; }
}
@media (prefers-reduced-motion: no-preference) {
  .theme-toggle svg { transition: transform .3s ease; }
  .theme-toggle:hover svg { transform: rotate(-20deg); }
}
/* пунктов много: на широком экране переносятся, на телефоне листаются вбок */
.nav { display: flex; gap: 6px; flex-wrap: wrap; padding-bottom: 2px; }
@media (max-width: 560px) { .nav { flex-wrap: nowrap; overflow-x: auto; } }
.nav a {
  font: 600 14px var(--f-body); color: var(--muted); background: var(--surface); border: 1px solid var(--line);
  border-radius: 999px; padding: 7px 14px; white-space: nowrap; text-decoration: none;
}
.nav a:hover { color: var(--ink); }
.nav a[aria-current="page"] { background: var(--ink); color: var(--surface); border-color: var(--ink); }
footer.site { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; font-size: 13px; color: var(--muted); border-top: 1px solid var(--line); padding-top: 14px; }

/* ===== Инструмент ===== */
.tool { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tabs a {
  font: 600 14px var(--f-body); color: var(--muted); text-decoration: none;
  padding: 14px 20px; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--net); }
.pane { padding: 22px; display: grid; gap: 20px; }

.inputrow { display: grid; grid-template-columns: 1fr auto auto; gap: 12px; align-items: end; }
.inputrow.two { grid-template-columns: 1fr 1fr auto; }
.field { display: grid; gap: 6px; min-width: 0; align-content: start; }
.field label { font-size: 13px; color: var(--muted); font-weight: 500; }
.field input, .field select, .field textarea {
  font: 500 20px var(--f-mono); color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; width: 100%; min-width: 0;
}
.field select { font-size: 15px; padding: 14px 12px; }
.field textarea { font-size: 15px; line-height: 1.6; resize: vertical; min-height: 260px; }

.btn {
  display: inline-block; font: 600 14px var(--f-body); color: var(--surface); background: var(--net); border: 0; border-radius: 8px;
  padding: 11px 18px; cursor: pointer; justify-self: start; text-decoration: none;
}
.btn.small { padding: 6px 12px; }
.btn.done { background: var(--ok); }

/* подпись в колонке фиксированной ширины, чтобы чипы «Примеров» и «Недавних» начинались с одной линии */
.examples { display: grid; grid-template-columns: 5.5rem 1fr; gap: 8px; align-items: baseline; }
.examples > .hint { padding-top: 5px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; min-width: 0; }
.examples-group { display: grid; gap: 8px; }
@media (max-width: 560px) { .examples { grid-template-columns: 1fr; gap: 6px; } .examples > .hint { padding-top: 0; } }
.chip {
  font: 500 13px var(--f-mono); color: var(--ink); background: var(--bg); border: 1px solid var(--line);
  border-radius: 999px; padding: 4px 11px; text-decoration: none;
}
.chip:hover { border-color: var(--net); }

/* Битовая карта */
.bits { display: grid; gap: 10px; }
.bits-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.bits-title { display: grid; gap: 1px; }
.bits-note { font-size: 12px; color: var(--muted); }
.legend { display: flex; gap: 14px; font-size: 13px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.sw-net { background: var(--net); }
.sw-host { background: var(--host); }
.bitgrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.bitgrid.v6 { grid-template-columns: repeat(8, 1fr); gap: 8px; }
.octet { display: grid; gap: 6px; min-width: 0; }
.octet .cells { display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; }
.bitgrid.v6 .cells { grid-template-columns: repeat(4, 1fr); }
.cell {
  display: grid; place-items: center; font: 600 13px var(--f-mono); height: 34px; border-radius: 4px;
  background: var(--host-soft); color: var(--host); text-decoration: none;
}
.cell.n { background: var(--net-soft); color: var(--net); }
.cell.edge { box-shadow: inset -3px 0 0 var(--net); }
.cell:hover { outline: 2px solid var(--net); outline-offset: -2px; }
.octet .dec { font: 600 15px var(--f-mono); text-align: center; }
.slider { display: grid; grid-template-columns: auto 1fr auto; gap: 14px; align-items: center; }
.slider input[type=range] { width: 100%; accent-color: var(--net); }
.slider .val { font: 700 18px var(--f-mono); color: var(--net); min-width: 3ch; text-align: right; }

/* Результаты */
.summary { display: flex; flex-wrap: wrap; gap: 8px; }
.pill { font-size: 13px; font-weight: 600; padding: 4px 10px; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); }
.pill.priv { color: var(--priv); background: var(--priv-soft); border-color: transparent; }
.pill.pub { color: var(--net); border-color: color-mix(in srgb, var(--net) 40%, transparent); }
.pill.spec { color: var(--host); border-color: color-mix(in srgb, var(--host) 40%, transparent); }

.results { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.r { background: var(--surface); padding: 12px 14px; display: grid; gap: 2px; min-width: 0; position: relative; }
.r .k { font-size: 12px; color: var(--muted); }
.r .v { font: 500 15px var(--f-mono); overflow-wrap: anywhere; padding-right: 26px; }
.r .v.big { font-size: 18px; font-weight: 600; }
.copy {
  position: absolute; top: 10px; right: 8px; width: 26px; height: 26px; border: 0; border-radius: 6px;
  background: transparent; color: var(--muted); cursor: pointer; font-size: 14px; line-height: 1;
}
.copy:hover { background: var(--bg); color: var(--ink); }
.copy.done { color: var(--ok); }

/* Разбиение на подсети */
.split { display: grid; gap: 12px; }
.split-head { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.split-head select { font: 500 14px var(--f-mono); padding: 6px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); }
.smap { display: flex; height: 40px; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.smap a {
  flex: 1 1 0; min-width: 0; display: grid; place-items: center; border-right: 1px solid var(--surface);
  background: var(--host-soft); color: var(--host); font: 600 11px var(--f-mono); overflow: hidden; text-decoration: none;
}
.smap a:last-child { border-right: 0; }
.smap a:hover { background: var(--net-soft); color: var(--net); }
.smap a.cur { background: var(--net); color: var(--surface); }

/* Дерево подсетей: родитель сверху, дети со сдвигом и линиями-ветками */
.tree { overflow-x: auto; padding-bottom: 2px; }
.tree, .tree ul { list-style: none; margin: 0; padding: 0; }
.tree ul { margin-left: 10px; padding-left: 12px; border-left: 1px solid var(--line); }
.tree ul > li { position: relative; }
.tree ul > li::before { content: ""; position: absolute; left: -12px; top: 18px; width: 9px; border-top: 1px solid var(--line); }
/* обрезаем вертикальную линию после последнего ребёнка */
.tree ul > li:last-child::after { content: ""; position: absolute; left: -13px; top: 19px; bottom: 0; width: 1px; background: var(--surface); }
.tnode {
  display: grid; gap: 12px; align-items: baseline; padding: 6px 10px; border-radius: 8px;
  font-family: var(--f-mono); font-size: 14px; font-variant-numeric: tabular-nums; min-width: 0;
}
.tnode.group { grid-template-columns: minmax(0, 1fr) auto; }
/* ширина колонок в символах: самый длинный адрес «255.255.255.255/32» = 18 */
.tnode.leaf { grid-template-columns: 19ch 34ch auto; justify-content: start; gap: 16px; }
.tnode.leaf > * { white-space: nowrap; }
/* Место считаем по ширине самой строки (на глубоких уровнях её меньше):
   не влезает broadcast — прячем его в подсказку (title), совсем узко — колонки в столбик */
.leaf-li { container-type: inline-size; }
@container (max-width: 660px) {
  .tnode.leaf { grid-template-columns: 19ch 34ch; }
  .tnode.leaf .bc { display: none; }
}
@container (max-width: 470px) {
  .tnode.leaf { grid-template-columns: 1fr; gap: 0; }
  .tnode.leaf .hosts { white-space: normal; }
}
.tnode .cidr { white-space: nowrap; }
.tnode .cidr { color: var(--ink); text-decoration: none; font-weight: 500; }
.tnode a.cidr:hover { color: var(--net); }
.tnode .meta, .tnode .hosts, .tnode .bc { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.tnode .tw { display: inline-block; width: 1.2em; color: var(--muted); }
.tnode.group.cur .cidr { color: var(--net); }
.tnode.leaf.cur { background: var(--net-soft); }
.tnode.leaf.cur .cidr, .tnode.leaf.cur .hosts { color: var(--net); }
.tnode.folded { text-decoration: none; }
.tnode.folded:hover { background: var(--bg); }
.tnode.folded .meta { color: var(--net); }
@media (max-width: 560px) {
  .tnode.group { grid-template-columns: 1fr; gap: 0; }
  .tnode.group .meta { padding-left: 1.2em; }
  .tree ul { margin-left: 6px; padding-left: 10px; }
  .tree ul > li::before { left: -10px; width: 7px; }
  .tree ul > li:last-child::after { left: -11px; }
}

.tablebox { overflow: auto; max-height: 320px; border: 1px solid var(--line); border-radius: 10px; }
.tablebox.tall { max-height: 380px; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { text-align: left; padding: 7px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: 12px; color: var(--muted); font-weight: 600; position: sticky; top: 0; background: var(--surface); }
td { font-family: var(--f-mono); font-variant-numeric: tabular-nums; }
td a { text-decoration: none; font-weight: 600; }
tr.cur td { background: var(--net-soft); }
.ref { display: grid; gap: 12px; }

/* SEO-тексты под инструментом */
.prose { display: grid; gap: 14px; }
.prose h2 { font-size: 19px; padding-top: 14px; }
.prose h3 { font-size: 16px; }
.prose ul { margin: 0; padding-left: 20px; display: grid; gap: 6px; }
.prose p, .prose li { color: var(--ink); }
.prose .mono { font-size: .95em; }
/* FAQ на всю ширину: две колонки карточек, на телефоне одна */
.faq { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 12px; }
.faq div {
  display: grid; gap: 4px; align-content: start; min-width: 0;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px;
}
@media (max-width: 560px) { .faq { grid-template-columns: 1fr; } }
.faq p { color: var(--muted); }

/* Утилиты */
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.out {
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px;
  display: grid; align-content: start; gap: 4px; font-family: var(--f-mono); font-variant-numeric: tabular-nums; min-width: 0;
}
.out .line { display: flex; justify-content: space-between; gap: 12px; font-size: 15px; }
.out .line span:last-child { color: var(--muted); font-size: 13px; }
.myip { font-size: clamp(26px, 5vw, 44px); font-weight: 600; overflow-wrap: anywhere; }

/* ===== Утилиты: общие элементы ===== */
.field textarea.short { min-height: 170px; }
.field fieldset, fieldset.field { border: 0; margin: 0; padding: 0; min-width: 0; }
fieldset.field legend { font-size: 13px; color: var(--muted); font-weight: 500; padding: 0; margin-bottom: 6px; }
.check { display: flex; align-items: baseline; gap: 8px; font-size: 14px; color: var(--ink); cursor: pointer; }
/* сбрасываем стили текстовых полей .field input для чекбоксов */
.field .check input, .check input { width: auto; padding: 0; font: inherit; border: 0; background: none; accent-color: var(--net); flex: none; }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 6px 16px; }
.inputrow.compact .field input, .inputrow.compact .field select { font-size: 15px; padding: 10px 12px; }
.field select#afmt { font-size: 15px; }
td.txt { font-family: var(--f-body); }
.yes { color: var(--priv); font-weight: 600; }
.no { color: var(--muted); }
.notes { margin: 0; padding-left: 18px; display: grid; gap: 4px; font-size: 14px; color: var(--muted); }
.notes b { color: var(--ink); font-weight: 500; }
pre.code {
  margin: 0; padding: 14px 16px; overflow-x: auto; background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
  font: 14px/1.6 var(--f-mono); color: var(--ink); white-space: pre;
}

/* VLSM: карта занятости и цвета подсетей (6 по кругу) */
.vmap { width: 100%; height: 44px; display: block; border-radius: 8px; overflow: hidden; }
.vmap-free { fill: var(--bg); stroke: var(--line); }
.c0 { --seg: var(--net); } .c1 { --seg: var(--host); } .c2 { --seg: var(--priv); }
.c3 { --seg: #8b5cf6; } .c4 { --seg: #db2777; } .c5 { --seg: #64748b; }
.vmap-seg { fill: var(--seg); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; background: var(--seg); margin-right: 8px; vertical-align: -1px; }

/* MAC: производитель */
.vendor { display: grid; gap: 2px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.vendor-name { font: 600 20px var(--f-body); color: var(--ink); overflow-wrap: anywhere; }

/* Конвертер: блок ULA */
.ula { display: grid; gap: 10px; padding-top: 6px; border-top: 1px solid var(--line); }
.ula-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; padding-top: 14px; }

/* Скорость и MTU */
.inputrow.speedrow { grid-template-columns: 2fr 1fr 2fr 1fr; }
.mturow { display: grid; grid-template-columns: 200px 1fr; gap: 20px; align-items: start; }
@media (max-width: 760px) {
  .inputrow.speedrow { grid-template-columns: 1fr 1fr; }
  .mturow { grid-template-columns: 1fr; }
}

@media (max-width: 820px) {
  .bitgrid.v6 { grid-template-columns: repeat(4, 1fr); }
}
@media (max-width: 560px) {
  .bitgrid { grid-template-columns: repeat(2, 1fr); }
  .bitgrid.v6 { grid-template-columns: repeat(2, 1fr); }
  .inputrow, .inputrow.two, .cols { grid-template-columns: 1fr; }
  .pane { padding: 16px; }
  .cell { height: 30px; font-size: 12px; }
}
@media (prefers-reduced-motion: no-preference) {
  .cell, .smap a { transition: background-color .15s, color .15s; }
}
