/* ip.midgard.com.hr — light / dark via tokens.
   Theme: system by default; [data-theme] on <html> forces light or dark. */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e3e6eb;
  --border-strong: #cfd4dc;
  --text: #16181d;
  --text-2: #4b5260;
  --muted: #7a8190;
  --accent: #2563eb;
  --accent-hover: #1d4fd7;
  --accent-soft: #e8efff;
  --on-accent: #ffffff;
  --bit-net: #2563eb;
  --bit-sub: #c2410c;
  --bit-host: #0f8a5f;
  --danger: #c4312b;
  --danger-soft: #fdecea;
  --toolbar-bg: rgba(255, 255, 255, 0.82);
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 3px rgba(16, 24, 40, 0.06);
  --radius: 12px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115;
    --surface: #171a20;
    --surface-2: #1e222a;
    --border: #2a2f39;
    --border-strong: #3a404c;
    --text: #e8eaef;
    --text-2: #b3b9c5;
    --muted: #858c99;
    --accent: #6c9bff;
    --accent-hover: #8bb0ff;
    --accent-soft: #1c2742;
    --on-accent: #0b1020;
    --bit-net: #7aa5ff;
    --bit-sub: #f0a45b;
    --bit-host: #4fd1a1;
    --danger: #ff7b72;
    --danger-soft: #3a1d1d;
    --toolbar-bg: rgba(15, 17, 21, 0.8);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0f1115;
  --surface: #171a20;
  --surface-2: #1e222a;
  --border: #2a2f39;
  --border-strong: #3a404c;
  --text: #e8eaef;
  --text-2: #b3b9c5;
  --muted: #858c99;
  --accent: #6c9bff;
  --accent-hover: #8bb0ff;
  --accent-soft: #1c2742;
  --on-accent: #0b1020;
  --bit-net: #7aa5ff;
  --bit-sub: #f0a45b;
  --bit-host: #4fd1a1;
  --danger: #ff7b72;
  --danger-soft: #3a1d1d;
  --toolbar-bg: rgba(15, 17, 21, 0.8);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

code { font-family: var(--mono); font-size: 0.95em; }

svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.muted { color: var(--muted); font-weight: 400; }
.small { font-size: 0.875rem; }

/* ---------- Toolbar ---------- */
.toolbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--toolbar-bg);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}

.toolbar-inner {
  max-width: 980px;
  margin: 0 auto;
  padding: 0 16px;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-weight: 650;
  letter-spacing: -0.01em;
  flex-shrink: 0;
}
.brand:hover { text-decoration: none; }

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: var(--accent);
  color: var(--on-accent);
  font: 700 12px/1 var(--mono);
}

.nav {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-left: auto;
}

.nav-link {
  padding: 6px 12px;
  border-radius: 8px;
  color: var(--text-2);
  font-weight: 500;
  font-size: 0.93rem;
  white-space: nowrap;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-link[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.nav-api { font-family: var(--mono); font-size: 0.85rem; }

.nav-sep {
  width: 1px;
  height: 20px;
  margin: 0 8px;
  background: var(--border-strong);
}

.theme-toggle {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  color: var(--text-2);
  cursor: pointer;
  flex-shrink: 0;
}
.theme-toggle:hover { color: var(--text); border-color: var(--border-strong); }
.theme-toggle svg { display: none; }
.theme-toggle .fill { fill: currentColor; stroke: none; }
.theme-toggle:not([data-mode]) .i-auto,
.theme-toggle[data-mode="system"] .i-auto,
.theme-toggle[data-mode="light"] .i-light,
.theme-toggle[data-mode="dark"] .i-dark { display: block; }

/* ---------- Layout ---------- */
.main {
  flex: 1;
  width: 100%;
  max-width: 980px;
  margin: 0 auto;
  padding: 32px 16px 48px;
}

.page-title {
  margin: 0 0 20px;
  font-size: 1.6rem;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}

.card-title {
  margin: 0 0 12px;
  font-size: 1rem;
  font-weight: 600;
}

.footer {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 24px 16px;
  color: var(--muted);
  font-size: 0.85rem;
  border-top: 1px solid var(--border);
}
.footer a { color: var(--muted); font-family: var(--mono); }
.footer a:hover { color: var(--text); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 38px;
  padding: 0 16px;
  border-radius: 9px;
  border: 1px solid transparent;
  font: 500 0.93rem/1 var(--sans);
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { background: var(--surface); color: var(--text-2); border-color: var(--border); }
.btn-ghost:hover { color: var(--text); border-color: var(--border-strong); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 0.83rem; }
.btn.copied { color: var(--bit-host); border-color: var(--bit-host); }
.btn.copied span, .btn-sm.copied { font-size: 0; }
.btn.copied span::after, .btn-sm.copied::after { content: "Copied"; font-size: 0.93rem; }
.btn-sm.copied::after { font-size: 0.83rem; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  margin-left: 6px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  vertical-align: middle;
  opacity: 0;
  transition: opacity 0.12s;
  flex-shrink: 0;
}
.icon-btn svg { width: 15px; height: 15px; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.copied { color: var(--bit-host); opacity: 1; }
.r-row:hover .icon-btn, .kv-v:hover .icon-btn, .icon-btn:focus-visible { opacity: 1; }
@media (hover: none) { .icon-btn { opacity: 1; } }

/* ---------- Landing ---------- */
.hero {
  padding: 40px 0 36px;
  text-align: center;
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.hero-ip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 12px 16px;
}

.hero-ip code {
  font-size: clamp(2rem, 7vw, 3.4rem);
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.15;
  overflow-wrap: anywhere;
}
.hero-ip code.is-v6 { font-size: clamp(1.3rem, 4.4vw, 2.4rem); }

.chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin: 20px 0 0;
}

.chip {
  padding: 3px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-2);
  font-size: 0.83rem;
  max-width: 100%;
  overflow-wrap: anywhere;
}
.chip-accent { background: var(--accent-soft); border-color: transparent; color: var(--accent); font-weight: 600; }
.chip-mono { font-family: var(--mono); font-size: 0.8rem; }

.hero-actions { margin: 28px 0 0; }

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin-bottom: 16px;
}

.tile {
  display: block;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  color: var(--text-2);
  transition: border-color 0.12s, transform 0.12s;
}
.tile:hover { border-color: var(--accent); text-decoration: none; }
.tile h2 { margin: 0 0 6px; color: var(--text); font-size: 1rem; font-weight: 600; }
.tile h2::after { content: " →"; color: var(--accent); }
.tile p { margin: 0; font-size: 0.9rem; }

.cli { display: grid; gap: 8px; }
.cli-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 8px 8px 14px;
  border-radius: 9px;
  background: var(--surface-2);
}
.cli-row code { overflow-wrap: anywhere; }
.cli + p { margin: 12px 0 0; }

/* ---------- Calculator form ---------- */
.calc-form {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  gap: 16px;
  align-items: start;
}

.field { display: grid; gap: 6px; min-width: 0; }
.field label { font-size: 0.85rem; font-weight: 600; color: var(--text-2); }
.field input {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  background: var(--surface);
  color: var(--text);
  font: 1rem var(--mono);
}
.field input::placeholder { color: var(--muted); opacity: 0.7; }
.field input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field input[aria-invalid="true"] { border-color: var(--danger); }
.hint { font-size: 0.8rem; color: var(--muted); }
.hint code { font-size: 0.78rem; }

.form-actions { grid-column: 1 / -1; display: flex; gap: 8px; }

.form-error {
  grid-column: 1 / -1;
  margin: 0;
  padding: 10px 12px;
  border-radius: 9px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 0.9rem;
}

/* ---------- Results ---------- */
.legend { display: flex; gap: 14px; justify-content: flex-end; margin: -4px 0 8px; font-size: 0.78rem; }
.lg::before { content: ""; display: inline-block; width: 9px; height: 9px; margin-right: 6px; border-radius: 2px; background: currentColor; vertical-align: 0; }

.r-row {
  display: grid;
  grid-template-columns: 110px minmax(0, 1fr) auto;
  align-items: center;
  gap: 4px 16px;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
}
.r-row:last-child { border-bottom: 0; }

.r-label { color: var(--muted); font-size: 0.88rem; }

.r-value {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  min-width: 0;
}
.r-value code { font-size: 1rem; font-weight: 500; overflow-wrap: anywhere; }
.r-note { margin-left: 10px; color: var(--muted); font-size: 0.85rem; font-family: var(--mono); overflow-wrap: anywhere; }

.r-bin {
  font: 0.86rem/1.6 var(--mono);
  letter-spacing: 0.02em;
  text-align: right;
}

.r-sep {
  padding: 6px 0;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.b-net { color: var(--bit-net); }
.b-sub { color: var(--bit-sub); }
.b-host { color: var(--bit-host); }
.b-dot { color: var(--muted); }
.b-grp { display: inline-block; }

/* IPv6 binary is 128 bits: give it a full-width line under the value. */
.r-row:has(.b-grp) { grid-template-columns: 110px minmax(0, 1fr); }
.r-row:has(.b-grp) .r-bin { grid-column: 2; text-align: left; font-size: 0.8rem; }

.summary { margin: 0 0 12px; color: var(--text-2); }
.summary code { font-size: 0.9em; }
.card .summary + .r-row { border-top: 1px solid var(--border); }

.kv {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  gap: 0 16px;
}
.kv-k, .kv-v { padding: 7px 0; border-bottom: 1px solid var(--border); }
.kv-k { color: var(--muted); font-size: 0.88rem; }
.kv-v { display: flex; align-items: center; flex-wrap: wrap; gap: 0 6px; min-width: 0; }
.kv-v code { overflow-wrap: anywhere; }
.kv-v .icon-btn { margin-left: 0; }
.kv > :nth-last-child(-n + 2) { border-bottom: 0; }

.table-wrap { overflow-x: auto; margin: 0 -20px -20px; border-top: 1px solid var(--border); }
.tbl { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.tbl th, .tbl td { padding: 7px 20px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
.tbl th { position: sticky; top: 0; background: var(--surface-2); color: var(--muted); font-weight: 600; font-size: 0.8rem; }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl tbody tr:hover { background: var(--surface-2); }
.tbl .num { color: var(--muted); text-align: right; width: 1%; }

/* ---------- Responsive ---------- */
@media (max-width: 760px) {
  .r-row { grid-template-columns: 96px minmax(0, 1fr); }
  .r-bin, .r-row:has(.b-grp) .r-bin { grid-column: 1 / -1; text-align: left; font-size: 0.78rem; }
  .calc-form { grid-template-columns: 1fr 1fr; }
  .field-wide { grid-column: 1 / -1; }
}

@media (max-width: 560px) {
  .main { padding-top: 20px; }
  .toolbar-inner { gap: 8px; }
  .brand-name { display: none; }
  .nav-link { padding: 6px 8px; }
  .nav-sep { margin: 0 4px; }
  .grid-2 { grid-template-columns: 1fr; }
  .calc-form { grid-template-columns: 1fr; }
  .card { padding: 16px; }
  .table-wrap { margin: 0 -16px -16px; }
  .tbl th, .tbl td { padding: 7px 16px; }
  .r-row, .r-row:has(.b-grp) { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .r-row .r-bin { grid-column: 1; }
  .r-label { font-size: 0.8rem; }
  .r-value { flex-wrap: nowrap; }
  .r-value code { min-width: 0; }
  .r-note { flex-shrink: 0; max-width: 45%; }
  .kv { grid-template-columns: 1fr; }
  .kv-k { padding-bottom: 0; border-bottom: 0; font-size: 0.8rem; }
  .kv > :nth-last-child(2) { border-bottom: 0; }
}
