/* =========================================================================
   Design System v2 — b0nk13.nl
   ========================================================================= */

/* ---------- 1. Tokens ---------- */
:root {
  --bg:        #0a0b0d;
  --surface:   #12151a;
  --surface-2: #1a1f26;
  --border:    #23272e;
  --text:      #e6edf3;
  --muted:     #8b949e;
  --accent:    #00e5ff;
  --accent-dim: rgba(0, 229, 255, 0.15);

  /* Matrix green (VPN logo) */
  --green:      #00ff41;
  --green-dim:  rgba(0, 255, 65, 0.6);

  --red:       #ff5c7a;
  --red-dim:   rgba(255, 92, 122, 0.08);

  --font: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --radius: 14px;

  /* Layout tokens */
  --rail-w: 56px;
  --rail-expanded: 240px;
  --header-h: 58px;
  --footer-h: 3.5rem;

  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg:        #f7f9fb;
  --surface:   #ffffff;
  --surface-2: #eef2f6;
  --border:    #e2e6ea;
  --text:      #0a0b0d;
  --muted:     #5b6470;
  --accent:    #00b8cc;
  --accent-dim: rgba(0, 229, 255, 0.2);

  --green:     #008f11;
  --green-dim: transparent;

  --red:       #d43f5a;
  --red-dim:   rgba(212, 63, 90, 0.08);

  color-scheme: light;
}

/* ---------- 2. Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- 3. Scanline overlay ---------- */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  background: repeating-linear-gradient(
    0deg,
    rgba(255, 255, 255, 0.025) 0px,
    rgba(255, 255, 255, 0.025) 1px,
    transparent 1px,
    transparent 3px
  );
  mix-blend-mode: overlay;
}
:root[data-theme="light"] body::after {
  background: repeating-linear-gradient(
    0deg,
    rgba(0, 0, 0, 0.025) 0px,
    rgba(0, 0, 0, 0.025) 1px,
    transparent 1px,
    transparent 3px
  );
}

/* ---------- 4. Shell ---------- */
.page {
  display: flex;
  flex-direction: column;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem clamp(1rem, 4vw, 2rem);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: .75rem;
}

.site-footer {
  min-height: var(--footer-h);
  padding: 0 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: .72rem;
  color: var(--muted);
  border-top: 1px solid var(--border);
  box-sizing: border-box;
}

/* ---------- 5. Brand / logo ---------- */
.brand {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
  letter-spacing: -0.01em;
}
.brand:hover { text-decoration: none; }
.brand .logo { white-space: nowrap; }
.brand .logo .tld { color: var(--muted); }

/* VPN additions — matrix green for "vpn" */
.brand .logo .vpn {
  color: var(--green);
  text-shadow: 0 0 10px var(--green-dim);
}

/* ---------- 6. Theme toggle ---------- */
.theme-toggle {
  font-size: .8rem;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .35rem .65rem;
  cursor: pointer;
  line-height: 1;
  transition: color .15s, border-color .15s;
}
.theme-toggle:hover {
  color: var(--accent);
  border-color: var(--accent);
}

/* ---------- 7. Layout ---------- */
.page-main {
  flex: 1;
  padding: clamp(1.5rem, 6vw, 4rem) 1rem;
}
.page-center {
  display: grid;
  place-items: center;
}

/* ---------- 8. Cards ---------- */
.card {
  width: min(100%, 440px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: clamp(1.5rem, 4vw, 2.25rem);
  box-shadow: 0 24px 70px rgba(0, 0, 0, .45);
}
:root[data-theme="light"] .card {
  box-shadow: 0 18px 50px rgba(10, 11, 13, .08);
}

.card-title {
  margin: 0 0 .35rem;
  font-size: 1.35rem;
  line-height: 1.2;
}
.card-sub {
  margin: 0 0 1.5rem;
  font-size: .85rem;
  color: var(--muted);
}
.eyebrow {
  margin: 0 0 .6rem;
  font-size: .7rem;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--green);
}

/* ---------- 9. Forms ---------- */
.form-field {
  display: grid;
  gap: .4rem;
  margin-bottom: 1rem;
}
.form-field label {
  font-size: .72rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}

.input {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .7rem .85rem;
  font-size: .95rem;
  transition: border-color .15s, box-shadow .15s;
}
.input::placeholder { color: var(--muted); opacity: .6; }
.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.pw-wrap { position: relative; }
.pw-wrap .input { padding-right: 5.75rem; }
.pw-toggle {
  position: absolute;
  top: 50%;
  right: .45rem;
  transform: translateY(-50%);
  background: transparent;
  border: 0;
  padding: .3rem .45rem;
  font-size: .72rem;
  color: var(--muted);
  border-radius: 6px;
  cursor: pointer;
}
.pw-toggle:hover { color: var(--accent); }

/* ---------- 10. Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  font-weight: 700;
  letter-spacing: .04em;
  padding: .7rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  transition: filter .15s, box-shadow .15s, transform .05s, color .15s, border-color .15s;
  text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .6; cursor: progress; }

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #04181c;
}
.btn.primary:hover {
  filter: brightness(1.08);
  box-shadow: 0 0 24px var(--accent-dim);
}

.btn.ghost {
  font-size: .8rem;
  color: var(--muted);
  padding: .4rem .7rem;
}
.btn.ghost:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.btn-block { width: 100%; margin-top: .25rem; }

/* ---------- 11. Flash / alerts ---------- */
.flash {
  margin-bottom: 1rem;
  padding: .6rem .8rem;
  font-size: .85rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
}
.flash.error {
  color: var(--red);
  background: var(--red-dim);
  border-color: var(--red);
}
.flash.info {
  color: var(--accent);
  background: var(--accent-dim);
  border-color: var(--accent);
}

/* ---------- 12. Dashboard bits ---------- */
.user-pill {
  font-size: .75rem;
  color: var(--muted);
  padding: .3rem .6rem;
  border: 1px dashed var(--border);
  border-radius: 999px;
  max-width: 18ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.kv {
  margin: 1rem 0 0;
  display: grid;
  gap: .5rem;
  font-size: .85rem;
}
.kv > div {
  display: flex;
  justify-content: space-between;
  border-bottom: 1px dashed var(--border);
  padding-bottom: .5rem;
}
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 8px var(--green-dim);
  margin-right: .35rem;
  vertical-align: middle;
}

/* ---------- 13. Utilities ---------- */
.muted { color: var(--muted); }
.mono  { font-family: var(--font); }

/* ---------- 14. Ban page ---------- */
.ban-card {
  border-color: var(--red);
  border-left-width: 4px;
}
.eyebrow.danger { color: var(--red); }

/* ---------- 15. Dashboard layout ---------- */
.page-dash {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}
.page-dash > * {
  width: min(100%, 1366px);
}
.page-dash .card {
  width: 100%;
  max-width: none;
}
.page-dash .dashboard-card {
  width: min(100%, 620px);
  align-self: center;
}

/* ---------- 16. Stats bar ---------- */
.stats-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: .75rem;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: .15rem;
  padding: .85rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.stat-value {
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1;
  color: var(--text);
}
.stat-value.danger { color: var(--red); }
.stat-label {
  font-size: .7rem;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ---------- 17. Activity grid ---------- */
.activity-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}
@media (min-width: 780px) {
  .activity-grid { grid-template-columns: 1fr 1fr; }
}

.activity-card { padding: 1.1rem 1.25rem; }

.activity-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  margin-bottom: .75rem;
  padding-bottom: .65rem;
  border-bottom: 1px solid var(--border);
}
.activity-title {
  margin: 0;
  font-size: .95rem;
  letter-spacing: .02em;
}
.activity-badge {
  font-size: .68rem;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
  padding: .2rem .5rem;
  border: 1px solid var(--border);
  border-radius: 999px;
}
.activity-badge.warn {
  color: var(--red);
  border-color: var(--red);
  background: var(--red-dim);
}

.activity-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: .3rem;
  max-height: 320px;
  overflow-y: auto;
  scrollbar-width: thin;
}
.activity-list::-webkit-scrollbar { width: 6px; }
.activity-list::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.activity-row {
  display: flex;
  align-items: flex-start;
  gap: .55rem;
  padding: .4rem .15rem;
  border-bottom: 1px dashed var(--border);
  font-size: .82rem;
}
.activity-row:last-child { border-bottom: 0; }

.activity-status {
  flex: 0 0 auto;
  width: 1.1rem;
  text-align: center;
  font-weight: 700;
}
.activity-row.ok   .activity-status { color: var(--green); }
.activity-row.fail .activity-status,
.activity-row.ban  .activity-status { color: var(--red); }

.activity-main {
  display: flex;
  flex-direction: column;
  gap: .1rem;
  flex: 1 1 auto;
  min-width: 0;
}
.activity-email,
.activity-ip {
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.activity-ip { font-family: var(--font); }
.activity-meta {
  font-size: .72rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.activity-time {
  flex: 0 0 auto;
  font-size: .72rem;
  color: var(--muted);
  white-space: nowrap;
  text-align: right;
}
.activity-action { flex: 0 0 auto; margin-left: .25rem; }

.activity-empty {
  margin: 0;
  padding: .75rem 0;
  font-size: .82rem;
  color: var(--muted);
  text-align: center;
}

.btn.tiny {
  font-size: .7rem;
  padding: .25rem .5rem;
  border-radius: 6px;
  letter-spacing: .04em;
}

.danger { color: var(--red); }

@media (max-width: 520px) {
  .stats-bar { grid-template-columns: 1fr; }
}

/* ============================================================
   Sidebar — collapsed rail, expands on hover / tap
   ============================================================ */

.sidebar {
  position: fixed;
  top: var(--header-h);
  left: 0;
  bottom: 0;
  width: var(--rail-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  z-index: 40;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width .28s cubic-bezier(0.4, 0, 0.2, 1),
              box-shadow .28s ease;
}

.sidebar:hover,
.sidebar.is-open {
  width: var(--rail-expanded);
  box-shadow: 8px 0 24px rgba(0, 0, 0, .40);
}

:root[data-theme="light"] .sidebar:hover,
:root[data-theme="light"] .sidebar.is-open {
  box-shadow: 8px 0 24px rgba(10, 11, 13, .12);
}

/* Main + footer: permanent rail offset only — no transition */
body.has-sidebar .page-main,
body.has-sidebar .site-footer {
  margin-left: var(--rail-w);
}

/* Nav + menu */
.sidebar-nav {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  padding: .75rem .5rem;
}

.sidebar-menu,
.sidebar-submenu {
  list-style: none;
  margin: 0;
  padding: 0;
}

.sidebar-item + .sidebar-item {
  margin-top: .15rem;
}

/* Link / button row */
.sidebar-link {
  display: flex;
  align-items: center;
  gap: .75rem;
  width: 100%;
  padding: .55rem .65rem;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
  border: 0;
  font: inherit;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color .15s, color .15s, box-shadow .15s;
}

button.sidebar-link {
  appearance: none;
  -webkit-appearance: none;
}

.sidebar-link:hover,
.sidebar-link:focus-visible {
  background: var(--surface-2);
  color: var(--text);
  outline: none;
  text-decoration: none;
}

.sidebar-item.active > .sidebar-link {
  color: var(--text);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  box-shadow: inset 3px 0 0 var(--accent);
}

/* Icon */
.sidebar-icon {
  flex: 0 0 20px;
  width: 20px;
  height: 20px;
  display: grid;
  place-items: center;
  color: inherit;
}
.sidebar-icon svg {
  width: 16px;
  height: 16px;
}

/* Label — fades in when expanded */
.sidebar-label {
  flex: 1 1 auto;
  font-size: .85rem;
  font-weight: 500;
  opacity: 0;
  white-space: nowrap;
  transition: opacity .12s ease;
}

.sidebar:hover .sidebar-label,
.sidebar.is-open .sidebar-label {
  opacity: 1;
  transition-delay: .07s;
}

/* Chevron */
.sidebar-chevron {
  flex: 0 0 auto;
  font-size: 1rem;
  line-height: 1;
  color: var(--muted);
  opacity: 0;
  transition: transform .2s ease, opacity .12s ease;
}

.sidebar:hover .sidebar-chevron,
.sidebar.is-open .sidebar-chevron {
  opacity: 1;
  transition-delay: .07s;
}

.sidebar-item.open > .sidebar-toggle .sidebar-chevron {
  transform: rotate(90deg);
}

/* Submenu */
.sidebar-submenu {
  max-height: 0;
  overflow: hidden;
  margin-left: 1.75rem;
  padding-left: .25rem;
  transition: max-height .25s ease;
}

/* Force-closed while the rail is collapsed */
.sidebar:not(:hover):not(.is-open) .sidebar-submenu {
  max-height: 0 !important;
  transition: none;
}

.sidebar-item.open > .sidebar-submenu {
  max-height: 300px;
}

.sidebar-sublink {
  display: block;
  padding: .4rem .6rem;
  font-size: .78rem;
  color: var(--muted);
  text-decoration: none;
  border-radius: 6px;
  white-space: nowrap;
  transition: background-color .15s, color .15s;
}

.sidebar-sublink:hover,
.sidebar-sublink:focus-visible {
  background: var(--surface-2);
  color: var(--text);
  outline: none;
  text-decoration: none;
}

.sidebar-sublink[aria-disabled="true"] {
  opacity: .5;
  cursor: not-allowed;
}

/* Footer of sidebar (sign out) */
.sidebar-foot {
  padding: .5rem;
  border-top: 1px solid var(--border);
}

/* Touch devices: no hover-expand — only .is-open */
@media (hover: none) {
  .sidebar:hover:not(.is-open) {
    width: var(--rail-w);
  }
  .sidebar:hover:not(.is-open) .sidebar-label,
  .sidebar:hover:not(.is-open) .sidebar-chevron {
    opacity: 0;
    transition-delay: 0s;
  }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .btn, .input, .theme-toggle { transition: none; }
  .btn:active { transform: none; }
  .sidebar,
  .sidebar-label,
  .sidebar-chevron,
  .sidebar-submenu {
    transition: none;
  }
}

/* ============================================================
   WireGuard generator — full-bleed iframe
   ============================================================ */
.wg-frame {
  width: 100%;
  flex: 1 1 auto;
  display: flex;
}

.wg-frame iframe {
  width: 100%;
  height: calc(100vh - var(--header-h) - var(--footer-h) - 5rem);
  min-height: 560px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 18px 50px rgba(0, 0, 0, .35);
}

:root[data-theme="light"] .wg-frame iframe {
  box-shadow: 0 12px 32px rgba(10, 11, 13, .08);
}

/* ============================================================
   WireGuard generator — redesign naar design system
   ============================================================ */

.wg-gen {
  width: 100%;
  max-width: 1366px;
  margin: 0 auto;
}

.wg-gen .container {
  background: transparent;
  padding: 0;
  border-radius: 0;
  box-shadow: none;
  max-width: none;
}

.wg-gen h1 {
  text-align: center;
  color: var(--text);
  font-size: 1.35rem;
  margin: 0 0 1.5rem;
}

.wg-gen .form-sections {
  display: flex;
  align-items: stretch;
  gap: 1rem;
  margin-bottom: 2rem;
  flex-wrap: wrap;
}

.wg-gen .form-section {
  flex: 1 1 300px;
  padding: 1.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.wg-gen .form-section h2 {
  margin-top: 0;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  padding-bottom: .75rem;
  font-size: 1rem;
}

.wg-gen .form-group {
  margin-bottom: 1rem;
}

.wg-gen label {
  display: block;
  margin-bottom: .4rem;
  font-weight: 500;
  color: var(--muted);
  font-size: .72rem;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.wg-gen input[type="text"],
.wg-gen input[type="number"],
.wg-gen textarea {
  width: 100%;
  padding: .7rem .85rem;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-sizing: border-box;
  font: inherit;
  font-family: var(--font);
  transition: border-color .15s, box-shadow .15s;
}

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

.wg-gen textarea {
  resize: vertical;
  min-height: 60px;
}

.wg-gen button {
  background: var(--accent);
  color: #04181c;
  padding: .7rem 1rem;
  border: 1px solid var(--accent);
  border-radius: 8px;
  cursor: pointer;
  font-size: .9rem;
  font-weight: 700;
  letter-spacing: .04em;
  display: block;
  margin: 1.25rem auto;
  transition: filter .15s, box-shadow .15s;
}

.wg-gen button:hover {
  filter: brightness(1.08);
  box-shadow: 0 0 24px var(--accent-dim);
}

.wg-gen .result-section {
  margin-bottom: 1.5rem;
  padding: 1.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.wg-gen .result-section h3 {
  margin-top: 0;
  color: var(--text);
  font-size: .95rem;
}

.wg-gen .config-textarea {
  width: 100%;
  height: 200px;
  font-family: var(--font);
  font-size: 12px;
  padding: .75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  resize: vertical;
  background: var(--bg);
  color: var(--text);
  box-sizing: border-box;
}

.wg-gen .client-container {
  display: flex;
  gap: 1.25rem;
  align-items: flex-start;
  flex-wrap: wrap;
}

.wg-gen .client-config {
  flex: 1 1 300px;
}

.wg-gen .qr-code {
  flex: 0 0 auto;
  text-align: center;
}

.wg-gen .qr-code img {
  max-width: 200px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
  padding: 8px;
}

.wg-gen .qr-code p {
  margin-top: .5rem;
  font-size: .72rem;
  color: var(--muted);
}

.wg-gen .error {
  color: var(--red);
  padding: .65rem .85rem;
  background: var(--red-dim);
  border: 1px solid var(--red);
  border-radius: 8px;
  font-size: .85rem;
}

.wg-gen .peers-toggle-btn {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: .2rem .5rem;
  cursor: pointer;
  font-size: .7rem;
  font-weight: 700;
  line-height: 1.2;
  height: auto;
  margin: 0;
}

.wg-gen .peers-toggle-btn:hover {
  background: var(--border);
}

.wg-gen .current-peers-container {
  display: none;
  padding: .65rem;
  margin-top: .5rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: var(--font);
  font-size: 12px;
  color: var(--text);
}

.wg-gen .current-peers-container.visible {
  display: block;
}

.wg-gen .label-with-button {
  display: flex;
  align-items: baseline;
  gap: .4rem;
  margin-bottom: 0;
}

@media (max-width: 768px) {
  .wg-gen .form-sections,
  .wg-gen .client-container {
    flex-direction: column;
  }
}