:root {
  --bg: #0a1016;
  --bg-deep: #06090d;
  --card: #151b24;
  --card-edge: #1f2733;
  --ink: #e6edf6;
  --muted: #8b98ad;
  --accent: #14c8a2;
  --accent-2: #29d3ff;
  --border: #2a3342;
  --card-font: "IBM Plex Sans", "Segoe UI", sans-serif;
  --safe-top: env(safe-area-inset-top);
  --safe-bottom: env(safe-area-inset-bottom);
  --safe-left: env(safe-area-inset-left);
  --safe-right: env(safe-area-inset-right);
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; }
html { background-color: var(--bg-deep); }
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Space Grotesk", "IBM Plex Sans", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(900px 500px at 15% 10%, rgba(20, 200, 162, 0.12), transparent 60%),
    radial-gradient(800px 500px at 85% 10%, rgba(41, 211, 255, 0.12), transparent 60%),
    linear-gradient(120deg, var(--bg-deep), var(--bg));
  background-color: var(--bg-deep);
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: -100px;
  background-image:
    linear-gradient(rgba(255,255,255,0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.03) 1px, transparent 1px);
  background-size: 36px 36px;
  mask-image: radial-gradient(circle at center, rgba(0,0,0,0.8), transparent 70%);
  pointer-events: none;
  z-index: 0;
}

.app-shell {
  display: flex;
  min-height: 100vh;
  position: relative;
  z-index: 1;
}

.sidebar {
  flex: 0 0 240px;
  padding: calc(20px + var(--safe-top)) max(16px, var(--safe-right)) calc(20px + var(--safe-bottom)) max(16px, var(--safe-left));
  border-right: 1px solid var(--border);
  background: linear-gradient(180deg, #121826, #0e141f 60%, #0b111b);
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand-head {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-copy {
  display: grid;
  gap: 2px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid #24334a;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
  flex: 0 0 auto;
}

.brand-title {
  font-weight: 700;
  letter-spacing: 0.4px;
  color: #3de8c4;
  font-size: 1.1rem;
}

.brand-sub {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: #6d7c93;
}

.nav {
  margin-top: 20px;
  display: grid;
  gap: 8px;
}

.nav-item {
  color: #c8d5ea;
  text-decoration: none;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid transparent;
}

.nav-item.active,
.nav-item:hover {
  background: #1b2332;
  border-color: #243148;
}

.mobile-menu-toggle {
  display: none;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: 1px solid rgba(20, 200, 162, 0.55);
  background: linear-gradient(180deg, rgba(20, 200, 162, 0.18), rgba(20, 200, 162, 0.05));
  color: var(--accent);
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex: 0 0 auto;
}

.mobile-menu-toggle .icon {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
}

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4, 8, 14, 0.58);
  backdrop-filter: blur(3px);
  z-index: 70;
  display: none;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
}

.sidebar-backdrop.is-open {
  display: block;
  opacity: 1;
  pointer-events: auto;
}

.content {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  flex: 1;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(16px + var(--safe-top)) max(24px, var(--safe-right)) max(16px, var(--safe-bottom)) max(24px, var(--safe-left));
  border-bottom: 1px solid var(--border);
  background: rgba(15, 20, 28, 0.9);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.page-title { font-weight: 600; color: var(--accent); margin: 0; }
.page-subtitle { color: var(--muted); font-size: 0.88rem; margin-top: 4px; }
.user-pill {
  padding: 0;
  border-radius: 0;
  background: transparent;
  color: var(--accent);
  font-weight: 600;
  font-size: 0.85rem;
}

.user-actions {
  position: relative;
}

.user-menu {
  position: relative;
}

.user-menu-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  background: #0f1520;
  color: var(--ink);
  padding: 8px 12px;
  border-radius: 12px;
  cursor: pointer;
  min-height: 38px;
}

.user-menu-caret {
  color: #9db1cf;
  font-size: 0.78rem;
  transform: translateY(1px);
}

.user-menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  min-width: 180px;
  display: none;
  background: linear-gradient(180deg, #151b28, #101621);
  border: 1px solid #1f2b3f;
  border-radius: 12px;
  box-shadow: 0 18px 40px rgba(0,0,0,0.35);
  padding: 8px;
  z-index: 100;
}

.user-menu-panel.is-open {
  display: grid;
  gap: 4px;
}

.user-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  color: #d7e6ff;
  background: transparent;
  border: 0;
  border-radius: 10px;
  text-decoration: none;
  padding: 9px 10px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
}

.user-menu-item:hover,
.user-menu-item.active {
  background: #1b2332;
}

.user-menu-item.danger {
  color: #ff9aa8;
}

.user-menu-item.danger:hover {
  background: #2d1016;
}

.container {
  padding: 24px max(24px, var(--safe-right)) max(24px, var(--safe-bottom)) max(24px, var(--safe-left));
  position: relative;
  z-index: 1;
  width: 100%;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.card {
  background: var(--card);
  border: 1px solid var(--card-edge);
  padding: 20px;
  border-radius: 14px;
  box-shadow: 0 12px 30px rgba(0,0,0,0.35);
  font-family: var(--card-font);
}

.stat { background: linear-gradient(180deg, #141b27, #111722); }
.stat-label {
  color: var(--muted);
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.06em;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  margin-top: 6px;
}

.grid-two {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 12px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

button, .btn {
  background: linear-gradient(90deg, var(--accent), #19d7a9);
  color: #06251f;
  border: none;
  padding: 10px 14px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
}

.btn.ghost {
  background: #0f1520;
  color: var(--ink);
  border: 1px solid var(--border);
}

.btn.danger {
  background: linear-gradient(90deg, #7a1f2f, #b12f48);
  color: #ffe8ec;
  border: 1px solid #9b2a40;
}

textarea {
  width: 100%;
  min-height: 520px;
  resize: vertical;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #101622;
  color: var(--ink);
  font-family: "IBM Plex Mono", "Courier New", monospace;
  font-size: 0.92rem;
  line-height: 1.45;
}

pre {
  margin: 0;
  background: #0f1520;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  white-space: pre-wrap;
  word-break: break-word;
  color: #cfd8e6;
  min-height: 120px;
}

#command-output {
  font-size: 0.82rem;
  line-height: 1.35;
}

.list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.list-item {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #0f1520;
}

.clickable-item {
  cursor: pointer;
}

.clickable-item:hover {
  border-color: rgba(20, 200, 162, 0.5);
  background: #122030;
}

.entry-form {
  display: grid;
  gap: 10px;
}

.entry-inputs {
  display: grid;
  grid-template-columns: 1fr 1.3fr;
  gap: 10px;
}

.entry-inputs input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #101622;
  color: var(--ink);
}

.entry-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.entry-main {
  min-width: 0;
}

.entry-host {
  font-weight: 700;
  color: #d7e6ff;
}

.entry-upstreams {
  color: var(--muted);
  font-family: "IBM Plex Mono", "Courier New", monospace;
  font-size: 0.86rem;
  word-break: break-all;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

th, td {
  text-align: left;
  border-bottom: 1px solid var(--border);
  padding: 9px 8px;
  vertical-align: middle;
  word-break: break-word;
}

th {
  color: var(--muted);
  font-weight: 500;
}

.muted { color: var(--muted); font-size: 0.9rem; }
.pill { padding: 3px 8px; border-radius: 999px; font-size: 0.74rem; }
.pill-ok { background: #0d2c24; color: #1ad9a6; }
.pill-warn { background: #2b1f10; color: #f4c36b; }
.pill-err { background: #2d1016; color: #f08c9d; }
.pill-white { background: #10273c; color: #66d2ff; }
.pill-new { background: #0e2b24; color: #3ee8be; }
.pill-known { background: #2a1c0f; color: #f5bf71; }

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: calc(32px + var(--safe-top)) 32px calc(32px + var(--safe-bottom));
}

.login-card {
  width: 420px;
  max-width: 92vw;
  padding: 26px 26px 20px;
  border-radius: 16px;
  background: linear-gradient(180deg, #151c27, #111722);
  border: 1px solid #253043;
  box-shadow: 0 20px 50px rgba(0,0,0,0.5);
}

input[type="password"] {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #101622;
  color: var(--ink);
  margin: 10px 0 14px;
}

input[type="text"] {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #101622;
  color: var(--ink);
  margin: 10px 0 14px;
}

.profile-card {
  max-width: 640px;
}

.profile-form {
  display: grid;
}

.profile-ok {
  color: #1ad9a6;
}

.error { color: #f08c9d; min-height: 20px; }

.link-danger {
  background: transparent;
  border: none;
  color: #ff9aa8;
  cursor: pointer;
  padding: 0;
  margin-left: 4px;
  text-decoration: underline;
  font-size: 0.78rem;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(5, 10, 16, 0.72);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 5000;
}

.modal.is-open {
  display: flex;
}

.modal-card {
  width: min(760px, 100%);
  max-height: 88vh;
  overflow: auto;
  background: linear-gradient(180deg, #151c27, #111722);
  border: 1px solid #253043;
  border-radius: 14px;
  padding: 16px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.5);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}

.modal-head h2 {
  margin: 0;
}

.modal-close {
  background: #0f1520;
  color: var(--ink);
  border: 1px solid var(--border);
  padding: 8px 10px;
  border-radius: 8px;
}

@media (max-width: 1100px) {
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-two { grid-template-columns: 1fr; }
}

@media (max-width: 820px) {
  body.is-drawer-open {
    overflow: hidden;
  }
  .mobile-menu-toggle {
    display: inline-flex;
    position: fixed;
    top: calc(12px + var(--safe-top));
    left: max(12px, var(--safe-left));
    z-index: 90;
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.35);
  }
  body.is-drawer-open .mobile-menu-toggle {
    opacity: 0;
    pointer-events: none;
  }
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: min(300px, 84vw);
    height: 100dvh;
    z-index: 80;
    border-right: 1px solid var(--border);
    border-bottom: none;
    padding: calc(12px + var(--safe-top)) max(12px, var(--safe-right)) calc(12px + var(--safe-bottom)) max(12px, var(--safe-left));
    transform: translateX(-105%);
    transition: transform 220ms ease;
    overflow-y: auto;
    box-shadow: 16px 0 34px rgba(0, 0, 0, 0.5);
    pointer-events: none;
  }
  .sidebar.is-open {
    transform: translateX(0);
    pointer-events: auto;
  }
  .sidebar-backdrop {
    z-index: 70;
  }
  .sidebar-backdrop.is-open {
    left: min(300px, 84vw);
  }
  .brand-mark {
    width: 36px;
    height: 36px;
  }
  .nav {
    margin-top: 14px;
    display: grid;
    gap: 8px;
    overflow: visible;
    padding-bottom: 0;
  }
  .nav-item {
    white-space: normal;
    flex: none;
    min-height: 40px;
  }
  .container {
    padding: 14px max(14px, var(--safe-right)) calc(18px + var(--safe-bottom)) max(14px, var(--safe-left));
  }
  .topbar {
    padding: calc(12px + var(--safe-top)) max(14px, var(--safe-right)) 12px calc(max(14px, var(--safe-left)) + 52px);
  }
  .entry-inputs { grid-template-columns: 1fr; }
  .entry-row { flex-direction: column; align-items: flex-start; }
  textarea { min-height: 300px; }
  button, .btn { min-height: 42px; }
  .user-menu-toggle { min-height: 42px; }
  table, thead, tbody, th, td, tr { display: block; }
  thead { display: none; }
  table tr {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 8px 10px;
    margin-bottom: 10px;
    background: #0f1520;
  }
  table td {
    border: none;
    padding: 6px 0;
    display: grid;
    grid-template-columns: 110px 1fr;
    gap: 10px;
    align-items: center;
  }
  table td::before {
    content: attr(data-label);
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-size: 0.68rem;
  }
}
