/* =====================================================================
   Global Theme Colours
   ===================================================================== */
:root {
  --bg: #0b1020;
  --fg: #e6ecf3;
  --muted: #93a2b4;
  --card: #121a2e;
  --line: #26324a;
  --brand: #14b8a6;
}

body.theme-light {
  --bg: #f6f8fb;
  --fg: #0b1020;
  --muted: #516074;
  --card: #ffffff;
  --line: #d8e0ea;
}

/* =====================================================================
   Base Layout & Typography
   ===================================================================== */
html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.5 Inter, system-ui, Segoe UI, Roboto, Arial, sans-serif;
  transition: background 0.3s ease, color 0.3s ease;
}

/* Wider wrapper on desktop while staying fluid */
.container {
  max-width: min(92vw, 1280px);
  margin: auto;
  padding: 2rem 1rem;
  position: relative;
  z-index: 1; /* content layer */
}

/* =====================================================================
   Header
   ===================================================================== */
.site-header {
  border-bottom: 1px solid var(--line);
  padding: 1rem 1rem 2.25rem; /* extra bottom pad to ensure no overlap */
  position: relative;
  background: var(--bg);
  z-index: 1; /* keep header below interactive cards */
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: center; /* centre the title */
  position: relative;
  flex-wrap: wrap;
}

.logo {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 700;
  text-align: center;
  letter-spacing: 0.25px;
}

.logo a { color: inherit; text-decoration: none; }
.logo a:hover { text-decoration: underline; }

/* Keep toggle within the header corner; small, non-overlapping click area */
#theme-toggle {
  position: absolute;
  right: 0.5rem;
  top: 0.5rem;     /* previously 50% could overlap form content */
  z-index: 3;      /* above header chrome, below cards */
}

/* =====================================================================
   Footer
   ===================================================================== */
.site-footer {
  border-top: 1px solid var(--line);
  border-bottom: 0;
  padding: 1rem;
  text-align: centre;  /* British English spelling ok in CSS comments; value remains 'center' */
  text-align: center;
}

.footer-nav a { color: inherit; text-decoration: none; }
.footer-nav a:hover { text-decoration: underline; }

/* =====================================================================
   Tabs
   ===================================================================== */
.tabs {
  display: flex;
  gap: 0.5rem;
  margin: 1rem 0;
  justify-content: center;
  flex-wrap: wrap;
}

.tab {
  padding: 0.5rem 1rem;
  border: 1px solid var(--line);
  border-radius: 0.75rem;
  text-decoration: none;
  color: inherit;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.tab.active {
  background: var(--card);
  border-color: var(--brand);
}

/* =====================================================================
   Card / Section Containers
   ===================================================================== */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 1rem;
  padding: 1.25rem;
  margin-top: 1rem;
  box-shadow: 0 2px 4px rgba(0,0,0,0.15);
  position: relative;
  z-index: 2; /* ensure cards (forms/buttons) sit above header layer */
}

/* Let long result content breathe / scroll horizontally if needed */
.results { overflow-x: auto; }

.card .results pre,
.card .results code.mono {
  white-space: pre;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9rem;
}

/* =====================================================================
   Grid Layouts
   ===================================================================== */
.grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: 1fr;
}

.grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

/* =====================================================================
   Form Elements
   ===================================================================== */
label span {
  display: block;
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

input,
select {
  width: 100%;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 0.6rem;
  background: transparent;
  color: inherit;
  font-size: 1rem;
}

select { appearance: auto; }

/* =====================================================================
   Buttons
   ===================================================================== */
.actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
}

.btn {
  padding: 0.6rem 0.9rem;
  border-radius: 0.6rem;
  border: 1px solid var(--line);
  background: var(--brand);
  color: #062a27;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
  position: relative;
  z-index: 1; /* keep above any accidental overlays */
}

.btn:hover { background: #0d9488; }
.btn.ghost { background: transparent; color: inherit; }
a.btn { display: inline-flex; text-decoration: none; }

/* =====================================================================
   Alerts & Result Blocks
   ===================================================================== */
.alert {
  display: block;
  border-radius: 0.6rem;
  padding: 0.75rem;
  margin: 0.75rem 0 0;
  border: 1px solid transparent;
  font-weight: 500;
}

/* Dark mode error styling */
.alert.error {
  border-color: #b91c1c;      /* red-700 */
  background: #2a0f12;        /* deep red-brown */
  color: #ffecec;             /* high contrast text */
}

/* Light mode error styling */
body.theme-light .alert.error {
  background: #fee2e2;        /* red-200 */
  border-color: #ef4444;      /* red-500 */
  color: #7f1d1d;             /* red-900 text */
}

/* Make code inside alerts readable */
.alert code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* Result key-value grid */
.kv {
  display: grid;
  grid-template-columns: 220px 1fr auto;  /* widen label column */
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0;
  border-bottom: 1px dashed var(--line);
}

/* Keep binary/hex blocks unwrapped and scrollable if needed */
.kv code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre;
  overflow-x: auto;
}

/* Two-column KV used in IPv6 section */
.kv-2col {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: .5rem;
  padding: .35rem 0;
  border-bottom: 1px dashed var(--line);
}

/* =====================================================================
   Utility & Typography Helpers
   ===================================================================== */
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.small { font-size: 0.9rem; }
.muted { color: var(--muted); }
.mt { margin-top: 1rem; }

pre {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 0.6rem;
  padding: 0.75rem;
  overflow-x: auto;
}

/* Make <details> obvious to click */
details > summary {
  cursor: pointer;
  user-select: none;
}

/* =====================================================================
   Responsive Adjustments
   ===================================================================== */
@media (max-width: 720px) {
  .grid.two { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; }
  .kv-2col { grid-template-columns: 1fr; }

  #theme-toggle {
    position: static;     /* stack nicely on mobile */
    transform: none;
    margin-top: 0.75rem;
    align-self: center;
    z-index: 1;
  }

  .header-inner { flex-direction: column; }
  .logo { text-align: center; }
}

/* Subnet result table/details styles */
table.subs{width:100%;border-collapse:collapse}
    table.subs th,table.subs td{border-bottom:1px dashed var(--line);padding:.4rem .3rem;text-align:left}
    table.subs th{color: var(--muted);font-weight:600}
    table.subs tr.highlight td{font-weight:700}
    .chip{display:inline-block;padding:.1rem .4rem;border:1px solid var(--line);border-radius:.5rem;font-size:.85rem;color:var(--muted)}
    .kv-2col{display:grid;grid-template-columns:240px 1fr;gap:.5rem;padding:.35rem 0;border-bottom:1px dashed var(--line)}
    @media (max-width:720px){.kv-2col{grid-template-columns:1fr}}
    a.btn{display:inline-flex;text-decoration:none}
    .link-list a{display:block;margin:.25rem 0;text-decoration:none}
    .link-list a:hover{text-decoration:underline}
    .det-note{margin:.25rem 0 0;color:var(--muted);font-size:.9rem}
    .btn[aria-disabled="true"]{opacity:.5;pointer-events:none}

.form-actions {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
}

.form-actions .form-action-btn {
  box-sizing: border-box;
  flex: 0 0 9.75rem;
  width: 9.75rem;
  height: 3rem;
  align-items: center;
  justify-content: center;
  padding: 0;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1;
  text-align: center;
}
