@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

/* ── Reset ───────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Tokens ──────────────────────────────────────────────────────────────── */
:root {
  --bg:         #0f1117;
  --surface:    #161b27;
  --surface2:   #1c2233;
  --border:     #252d40;
  --border2:    #2e3a52;
  --text:       #dde6f5;
  --muted:      #667698;
  --accent:     #4a9eff;
  --accent-dim: rgba(74,158,255,.13);
  --green:      #34d399;
  --green-dim:  rgba(52,211,153,.12);
  --red:        #f87171;
  --red-dim:    rgba(248,113,113,.12);
  --yellow:     #fbbf24;
  --yellow-dim: rgba(251,191,36,.12);

  --sidebar-w: 224px;
  --bnav-h:    62px;
  --topbar-h:  52px;

  --radius-sm: 6px;
  --radius:    10px;
  --radius-lg: 14px;

  --font:      'Outfit', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  --shadow:    0 2px 12px rgba(0,0,0,.4);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.55);
}

/* ── Base ────────────────────────────────────────────────────────────────── */
html { -webkit-text-size-adjust: 100%; }

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

a { color: inherit; text-decoration: none; }

/* ══════════════════════════════════════════════════════════════════════════
   MOBILE LAYOUT  (default – no sidebar, bottom nav)
══════════════════════════════════════════════════════════════════════════ */

/* ── Mobile top bar ──────────────────────────────────────────────────────── */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 18px;
  z-index: 40;
}
.topbar-logo {
  font-size: 17px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: .5px;
}

/* ── Bottom navigation ───────────────────────────────────────────────────── */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--bnav-h);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  z-index: 40;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.bnav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: .3px;
  text-transform: uppercase;
  padding: 8px 4px;
  cursor: pointer;
  border: none;
  background: none;
  transition: color .15s;
  width: 100%;
  -webkit-tap-highlight-color: transparent;
}
.bnav-item svg { width: 22px; height: 22px; flex-shrink: 0; }
.bnav-item.active { color: var(--accent); }
.bnav-item:hover  { color: var(--text); }

/* ── More menu (mobile overflow nav) ─────────────────────────────────────── */
.more-backdrop {
  display: none;
  position: fixed; inset: 0;
  z-index: 48;
}
.more-backdrop.open { display: block; }

.more-menu {
  position: fixed;
  bottom: calc(var(--bnav-h) + 8px);
  right: 8px;
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  min-width: 180px;
  z-index: 49;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity .15s, transform .15s;
}
.more-menu.open {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}
.more-menu a,
.more-menu button {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  width: 100%;
  background: none;
  border: none;
  cursor: pointer;
  transition: background .12s;
  text-decoration: none;
}
.more-menu a:hover,
.more-menu button:hover { background: rgba(255,255,255,.06); }
.more-menu a.active { color: var(--accent); background: var(--accent-dim); }
.more-menu svg { width: 16px; height: 16px; flex-shrink: 0; opacity: .7; }
.more-divider { height: 1px; background: var(--border); margin: 4px 0; }
.more-logout { color: var(--red) !important; }

/* ── Sidebar (desktop – hidden on mobile) ────────────────────────────────── */
.sidebar { display: none; }

/* ── Content area ────────────────────────────────────────────────────────── */
.content {
  padding: calc(var(--topbar-h) + 18px) 16px calc(var(--bnav-h) + 18px);
}

/* ══════════════════════════════════════════════════════════════════════════
   COMPONENTS
══════════════════════════════════════════════════════════════════════════ */

/* ── Page titles ──────────────────────────────────────────────────────────── */
.page-title {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 18px;
  letter-spacing: -.2px;
}
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 18px;
}
.page-header .page-title { margin-bottom: 0; }

/* ── Stat cards ───────────────────────────────────────────────────────────── */
.card-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 18px;
}
.card-grid-3 { grid-template-columns: repeat(2, 1fr); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  transition: border-color .15s;
}
.card:hover { border-color: var(--border2); }
.card-warn  { border-color: var(--yellow); }

.card-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .9px;
  color: var(--muted);
  margin-bottom: 6px;
}
.card-value {
  font-family: var(--font-mono);
  font-size: 28px;
  font-weight: 500;
  line-height: 1.1;
  letter-spacing: -.5px;
}
.card-value-sm {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 500;
  word-break: break-all;
  line-height: 1.3;
}
.card-sub {
  font-size: 11px;
  color: var(--muted);
  margin-top: 5px;
}

/* ── Panels ───────────────────────────────────────────────────────────────── */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}
.panel-title {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: .1px;
  margin-bottom: 14px;
  color: var(--text);
}
.panel-actions { margin-top: 12px; }
.row-2 { display: grid; grid-template-columns: 1fr; gap: 14px; }

/* ── Tables ───────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; min-width: 500px; }
.table th,
.table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.table th {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .7px;
  color: var(--muted);
  white-space: nowrap;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: rgba(255,255,255,.025); }
.actions { white-space: nowrap; }

/* ── Badges ───────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .2px;
}
.badge::before { content: ''; width: 5px; height: 5px; border-radius: 50%; flex-shrink: 0; }
.badge-green  { background: var(--green-dim);  color: var(--green);  }
.badge-green::before  { background: var(--green); }
.badge-red    { background: var(--red-dim);    color: var(--red);    }
.badge-red::before    { background: var(--red); }
.badge-gray   { background: rgba(77,96,128,.15); color: var(--muted); }
.badge-gray::before   { background: var(--muted); opacity: .5; }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 18px;
  min-height: 42px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background .12s, border-color .12s, box-shadow .12s;
  text-decoration: none;
  white-space: nowrap;
  letter-spacing: .1px;
}
.btn:hover {
  background: #1e2a3a;
  border-color: var(--border2);
}
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 0 0 0 rgba(61,142,247,0);
}
.btn-primary:hover {
  background: #2f7de8;
  border-color: #2f7de8;
  box-shadow: 0 0 16px rgba(61,142,247,.25);
}
.btn-danger {
  background: var(--red-dim);
  border-color: rgba(255,77,109,.4);
  color: var(--red);
}
.btn-danger:hover {
  background: rgba(255,77,109,.2);
}
.btn-sm { padding: 5px 12px; min-height: 32px; font-size: 12px; }
.btn-full { width: 100%; }
.btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.time-btns { display: flex; gap: 6px; flex-wrap: wrap; }

/* ── Progress ─────────────────────────────────────────────────────────────── */
.progress {
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  margin-top: 10px;
  overflow: hidden;
}
.progress-bar { height: 100%; background: var(--accent); border-radius: 2px; transition: width .4s; }
.bar-yellow { background: var(--yellow); }
.bar-red    { background: var(--red); }

/* ── Forms ────────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .6px;
}
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 10px 13px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  transition: border-color .12s, box-shadow .12s;
  -webkit-appearance: none;
  appearance: none;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(61,142,247,.1);
}

/* ── Alerts ───────────────────────────────────────────────────────────────── */
.alert { padding: 12px 16px; border-radius: var(--radius-sm); margin-bottom: 18px; font-size: 13px; }
.alert-error { background: var(--red-dim); border: 1px solid rgba(255,77,109,.3); color: #fca5a5; }
.alert-warn  { background: var(--yellow-dim); border: 1px solid rgba(251,191,36,.3); color: #fcd34d; }

/* ── Modals ───────────────────────────────────────────────────────────────── */
.modal-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.65);
  backdrop-filter: blur(4px);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: var(--radius-lg);
  padding: 26px;
  width: 460px;
  max-width: 100%;
  max-height: 90dvh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
.modal h2 { margin-bottom: 20px; font-size: 17px; font-weight: 600; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }

/* ── WireGuard peer add result ─────────────────────────────────────────────── */
.add-result { text-align: center; }
.add-result svg { max-width: 200px; margin: 0 auto 16px; display: block; }
.conf-block {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  font-family: var(--font-mono);
  font-size: 11px;
  text-align: left;
  white-space: pre-wrap;
  word-break: break-all;
  margin-bottom: 16px;
  max-height: 200px;
  overflow-y: auto;
}
.success-msg { color: var(--green); margin-bottom: 16px; font-weight: 600; }

/* ── WireGuard peer detail cards ─────────────────────────────────────────── */
.peer-detail-cards {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

/* ── fail2ban settings grid ──────────────────────────────────────────────── */
.f2b-settings-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  margin-bottom: 24px;
}

/* ── Login page ───────────────────────────────────────────────────────────── */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 20px;
  background: var(--bg) radial-gradient(ellipse at 50% 0%, rgba(74,158,255,.07) 0%, transparent 55%);
}
.login-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 36px 30px;
  width: 100%;
  max-width: 360px;
  box-shadow: var(--shadow-lg);
}
.login-logo {
  font-size: 24px;
  font-weight: 700;
  color: var(--accent);
  text-align: center;
  margin-bottom: 4px;
  letter-spacing: -.3px;
}
.login-sub {
  text-align: center;
  color: var(--muted);
  margin-bottom: 28px;
  font-size: 13px;
}

/* ── Settings ─────────────────────────────────────────────────────────────── */
.settings-form { max-width: 420px; }
.panel-divider { border: none; border-top: 1px solid var(--border); margin: 20px 0; }
.sub-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .8px;
  margin-bottom: 12px;
}
.f2b-jail { margin-bottom: 16px; }
.f2b-jail-header { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; flex-wrap: wrap; }
.inline-form { display: inline; }
.inline-form-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.form-input-sm {
  padding: 7px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  min-height: 34px;
  transition: border-color .12s;
}
.form-input-sm:focus { outline: none; border-color: var(--accent); }
.row-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

.code-block {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.7;
  white-space: pre;
  overflow-x: auto;
  color: var(--text);
}
.code-editor {
  width: 100%;
  min-height: 260px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.7;
  color: var(--text);
  resize: vertical;
  transition: border-color .12s;
}
.code-editor:focus { outline: none; border-color: var(--accent); }

/* ── Misc utilities ──────────────────────────────────────────────────────── */
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }
.mt-1 { margin-top: 12px; }
.mb-2 { margin-bottom: 16px; }
code {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--muted);
  background: rgba(255,255,255,.04);
  padding: 1px 5px;
  border-radius: 3px;
}
.updates-list {
  margin-top: 12px;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  line-height: 1.7;
}

/* ══════════════════════════════════════════════════════════════════════════
   TABLET  768px+  –  side navigation appears
══════════════════════════════════════════════════════════════════════════ */
@media (min-width: 768px) {
  body { display: flex; }

  /* Hide mobile chrome */
  .topbar      { display: none; }
  .bottom-nav  { display: none; }
  .more-menu   { display: none !important; }
  .more-backdrop { display: none !important; }

  /* Sidebar */
  .sidebar {
    display: flex;
    flex-direction: column;
    width: var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 30;
    padding: 22px 0;
    overflow-y: auto;
    overflow-x: hidden;
  }

  .sidebar-logo {
    font-size: 17px;
    font-weight: 700;
    color: var(--accent);
    padding: 0 20px 22px;
    letter-spacing: .4px;
  }

  .nav-section-label {
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: var(--muted);
    padding: 14px 20px 5px;
    opacity: .6;
  }

  .nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 20px;
    min-height: 40px;
    color: var(--muted);
    font-size: 14px;
    font-weight: 500;
    letter-spacing: .1px;
    transition: color .12s, background .12s;
    border-left: 2px solid transparent;
  }
  .nav-item:hover { color: var(--text); background: rgba(255,255,255,.04); }
  .nav-item.active {
    color: var(--accent);
    background: var(--accent-dim);
    border-left-color: var(--accent);
  }
  .nav-icon { font-size: 9px; opacity: .7; flex-shrink: 0; }
  .nav-version {
    margin-top: auto;
    padding: 10px 20px 2px;
    font-size: 11px;
    font-family: var(--font-mono);
    color: var(--muted);
    opacity: .55;
    letter-spacing: .3px;
  }
  .nav-logout { padding-top: 8px; color: var(--red); border-top: 1px solid var(--border); margin-top: 8px; }
  .nav-logout:hover { color: #ff6b6b; background: var(--red-dim); }

  /* Content */
  .content {
    margin-left: var(--sidebar-w);
    flex: 1;
    padding: 26px 24px;
    min-height: 100vh;
    min-width: 0;
  }

  /* Layout improvements */
  .card-grid {
    grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
    gap: 14px;
    margin-bottom: 22px;
  }
  .card-grid-3 { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }

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

  .panel { padding: 20px; margin-bottom: 18px; }

  .peer-detail-cards { grid-template-columns: repeat(5, 1fr); }
  .f2b-settings-grid { grid-template-columns: repeat(3, 1fr); }
}

/* ══════════════════════════════════════════════════════════════════════════
   DESKTOP  1024px+
══════════════════════════════════════════════════════════════════════════ */
@media (min-width: 1024px) {
  .content { padding: 30px 28px; }

  .page-title { font-size: 22px; font-weight: 700; margin-bottom: 22px; }
  .page-header { margin-bottom: 22px; }
  .card-grid   { margin-bottom: 22px; }
}

@media (min-width: 1280px) {
  .content { max-width: calc(1260px + var(--sidebar-w)); }
}

/* ── Toast notifications ──────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: calc(var(--bnav-h) + 12px);
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 200;
  pointer-events: none;
}
@media (min-width: 768px) {
  #toast-container { bottom: 20px; }
}
.toast {
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  padding: 10px 16px;
  box-shadow: var(--shadow-lg);
  max-width: 320px;
  opacity: 0;
  transform: translateX(20px);
  transition: opacity .2s, transform .2s;
  pointer-events: auto;
}
.toast.show      { opacity: 1; transform: translateX(0); }
.toast-success   { border-left-color: var(--green); }
.toast-error     { border-left-color: var(--red); }
.toast-warn      { border-left-color: var(--yellow); }

/* ── DNS / misc helpers ───────────────────────────────────────────────────── */
.section-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .7px;
  color: var(--muted);
  margin-bottom: 10px;
}

.input-sm {
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  padding: 5px 10px;
  outline: none;
  transition: border-color .15s;
}
.input-sm:focus { border-color: var(--accent); }
