/* IPCalc — дизайн-система
   Тема та же, что у passbox/genpass (единая визуальная идентичность
   adminotes.ru): тёплый «бумажный» светлый фон, один акцентный цвет,
   карточка по центру, моноширинный шрифт для всего технического.
   Палитра идентична passbox, чтобы переход между инструментами
   воспринимался как один и тот же сервис, а не три разных сайта. */

:root {
  --bg: #f7f5f1;
  --bg-elevated: #ffffff;
  --text: #1c1b19;
  --text-muted: #6b6358;
  --border: #e3ddd2;
  --border-strong: #cdc4b4;
  --accent: #a33b2b;
  --accent-text: #ffffff;
  --accent-soft: #f3e2dc;
  --danger: #a33b2b;
  --success: #3f6b4a;
  --shadow: 0 1px 2px rgba(28, 27, 25, 0.04), 0 8px 24px rgba(28, 27, 25, 0.06);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --font-sans: -apple-system, "Inter", "Segoe UI", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15140f;
    --bg-elevated: #1e1c16;
    --text: #ede9e1;
    --text-muted: #9a9286;
    --border: #34302675;
    --border-strong: #4a4436;
    --accent: #d6694f;
    --accent-text: #1c1006;
    --accent-soft: #3a2018;
    --danger: #e07a5f;
    --success: #6ea37c;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 12px 32px rgba(0, 0, 0, 0.4);
  }
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.wrap {
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
  padding: 0 20px;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  padding: 28px 0 12px;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
}

a:hover {
  color: #C4302B;
}

.brand__mark {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 0.02em;
  color: var(--accent);
}

.brand__name {
  font-size: 15px;
  color: var(--text-muted);
}

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 24px 0 24px;
}

.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 32px;
}

@media (max-width: 480px) {
  .card { padding: 24px 20px; }
  .wrap { padding: 0 14px; }
}

h1 {
  font-size: 22px;
  font-weight: 650;
  margin: 0 0 6px;
  letter-spacing: -0.01em;
}

h2 {
  font-size: 17px;
  font-weight: 650;
  margin: 0 0 10px;
}

h3 {
  font-size: 14.5px;
  font-weight: 650;
  margin: 0 0 6px;
}

.lede {
  color: var(--text-muted);
  font-size: 14.5px;
  margin: 0 0 24px;
}

/* ---------- Табы инструментов ---------- */

.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 24px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0;
}

.tab {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 13.5px;
  font-weight: 600;
  padding: 10px 14px;
  cursor: pointer;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
  white-space: nowrap;
}

.tab:hover {
  color: var(--text);
  background: var(--accent-soft);
}

.tab.is-active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.subtabs {
  display: inline-flex;
  gap: 4px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 4px;
}

.subtabs .tab {
  border-radius: var(--radius-sm);
  border-bottom: none;
  margin-bottom: 0;
  padding: 7px 13px;
}

.subtabs .tab.is-active {
  background: var(--accent-soft);
  border-bottom: none;
}

/* ---------- Форма ---------- */


#tab-content form {
	margin: 10px 0;
}

label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.field {
  margin-bottom: 20px;
}

.field__hint {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-top: 6px;
}

.input-row {
  display: flex;
  gap: 8px;
}

textarea, input[type="text"], select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 15px;
  padding: 12px 14px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

select {
  font-family: var(--font-sans);
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%236b6358' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}

textarea:focus, input[type="text"]:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.row-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 16px;
}

@media (max-width: 480px) {
  .row-2, .row-3 { grid-template-columns: 1fr; gap: 14px; }
}

.icon-btn {
  flex-shrink: 0;
  width: 44px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--bg);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.icon-btn:hover {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
}

.icon-btn svg {
  width: 18px;
  height: 18px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  border: none;
  border-radius: var(--radius-md);
  background: var(--accent);
  color: var(--accent-text);
  font-size: 15px;
  font-weight: 650;
  padding: 13px 20px;
  cursor: pointer;
  transition: filter 0.15s ease, transform 0.05s ease;
}

.btn:hover { filter: brightness(1.08); }
.btn:active { transform: scale(0.99); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

.btn--ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border-strong);
}

.btn--ghost:hover {
  filter: none;
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.btn--sm {
  width: auto;
  padding: 8px 14px;
  font-size: 13.5px;
}

.hint {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 10px;
  line-height: 1.5;
}

.hint strong { color: var(--text); }

/* ---------- Результаты: таблица "ключ-значение" ---------- */

.result-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  margin: 20px 0;
}

@media (max-width: 480px) {
  .result-grid { grid-template-columns: 1fr; }
}

.result-cell {
  background: var(--bg-elevated);
  padding: 12px 16px;
}

.result-cell__label {
  font-size: 11.5px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}

.result-cell__value {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 600;
  word-break: break-all;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.result-cell__value .copy-mini {
  flex-shrink: 0;
  opacity: 0;
  cursor: pointer;
  color: var(--text-muted);
  background: none;
  border: none;
  padding: 2px 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  line-height: 1;
  transition: opacity 0.12s ease, color 0.12s ease;
  width: 20px;
  height: 20px;
}

/* Иконка копирования через CSS — два перекрывающихся прямоугольника.
   Работает без SVG в innerHTML (надёжнее в контексте <table> и IIS). */
.copy-mini::before {
  content: '';
  display: block;
  width: 9px;
  height: 9px;
  border: 1.5px solid currentColor;
  border-radius: 1.5px;
  position: relative;
  box-shadow: 2.5px -2.5px 0 -0.5px currentColor, 2.5px -2.5px 0 0.5px currentColor;
}

.result-cell:hover .copy-mini { opacity: 1; }
.result-cell__value .copy-mini:hover { color: var(--accent); }

/* Иконка копирования в таблице подсетей — всегда видима */
.subnet-table .copy-mini {
  opacity: 1;
  display: inline-flex;
  vertical-align: middle;
  margin-left: 4px;
  width: 18px;
  height: 18px;
}

.result-cell--accent .result-cell__value { color: var(--accent); }
.result-cell--full { grid-column: 1 / -1; }

.binary-view {
  font-family: var(--font-mono);
  font-size: 13px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin: 16px 0;
  overflow-x: auto;
  white-space: nowrap;
  letter-spacing: 0.02em;
}

.binary-view .bit-net { color: var(--accent); font-weight: 600; }
.binary-view .bit-host { color: var(--text-muted); }
.binary-view .bit-sep { color: var(--border-strong); padding: 0 2px; }

.meta-pills {
  display: flex;
  gap: 10px;
  justify-content: flex-start;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.pill {
  font-size: 12.5px;
  font-family: var(--font-mono);
  color: var(--text-muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 12px;
}

.pill--accent {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-soft);
}

.status {
  font-size: 14px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  text-align: left;
}

.status--error {
  background: var(--accent-soft);
  color: var(--danger);
}

.status--success {
  background: rgba(63, 107, 74, 0.12);
  color: var(--success);
}

/* ---------- Таблица подсетей (VLSM / split) ---------- */

.subnet-table-wrap {
  overflow-x: auto;
  margin: 20px 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

table.subnet-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  font-family: var(--font-mono);
  white-space: nowrap;
}

table.subnet-table th {
  text-align: left;
  font-family: var(--font-sans);
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  background: var(--bg);
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
}

table.subnet-table td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}

table.subnet-table tr:last-child td { border-bottom: none; }
table.subnet-table tr:hover td { background: var(--accent-soft); }

table.subnet-table td.error-row {
  color: var(--danger);
  font-family: var(--font-sans);
}

@media (max-width: 600px) {
  /* На узких экранах таблица превращается в стек карточек —
     горизонтальный скролл в таблице с 5 колонками неудобен на телефоне,
     а так каждая подсеть читается сверху вниз как мини-карточка. */
  .subnet-table-wrap {
    overflow-x: visible;
    border: none;
    background: transparent;
  }
  table.subnet-table, table.subnet-table thead, table.subnet-table tbody,
  table.subnet-table th, table.subnet-table td, table.subnet-table tr {
    display: block;
    white-space: normal;
  }
  table.subnet-table thead { display: none; }
  table.subnet-table tr {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    margin-bottom: 10px;
    padding: 4px 0;
  }
  table.subnet-table tr:last-child { margin-bottom: 0; }
  table.subnet-table td {
    border-bottom: none;
    padding: 6px 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
  }
  table.subnet-table td::before {
    content: attr(data-label);
    font-family: var(--font-sans);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-muted);
    flex-shrink: 0;
  }
  table.subnet-table td.error-row {
    display: block;
  }
  table.subnet-table td.error-row::before {
    content: none;
  }
}

/* ---------- SEO / описание ---------- */

.toggle-btn {
  display: block;
  margin: 16px auto;
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  border-radius: 999px;
  padding: 10px 20px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: filter 0.15s ease;
}

.toggle-btn:hover { filter: brightness(1.08); }

#seo-content {
  font-size: 14.5px;
  color: var(--text);
}

#seo-content p { color: var(--text-muted); line-height: 1.65; }
#seo-content section { margin-bottom: 22px; }
#seo-content ul, #seo-content ol { color: var(--text-muted); line-height: 1.7; padding-left: 4px; }
#seo-content li { margin-bottom: 6px; }
#seo-content li strong { color: var(--text); }
#seo-content h3 { color: var(--text); margin-top: 14px; }

.related-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0 4px;
}

.related-tools a {
  font-size: 13px;
  color: var(--text-muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 13px;
  text-decoration: none;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.related-tools a:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(0);
  background: var(--text);
  color: var(--bg);
  font-size: 13.5px;
  padding: 10px 18px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 10;
}

.toast--visible {
  opacity: 1;
  transform: translateX(-50%) translateY(-6px);
}

footer.footer {
  text-align: center;
  padding: 20px 0 32px;
  font-size: 12.5px;
  color: var(--text-muted);
}

footer.footer a {
  color: var(--text-muted);
  text-decoration: underline;
  text-decoration-color: var(--border-strong);
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  .spinner { animation: none; }
  * { transition: none !important; }
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}
