:root {
  --bg: #f1f5f9;
  --bg-accent: #e2e8f0;
  --side: #0f172a;
  --side-2: #1e293b;
  --side-text: #94a3b8;
  --side-active: #f8fafc;
  --panel: #ffffff;
  --line: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --accent: #2563eb;
  --accent-2: #1d4ed8;
  --accent-soft: #eff6ff;
  --ok: #059669;
  --ok-bg: #ecfdf5;
  --warn: #d97706;
  --warn-bg: #fffbeb;
  --bad: #dc2626;
  --bad-bg: #fef2f2;
  --radius: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 8px 24px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 12px 40px rgba(15, 23, 42, 0.12);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --header-h: 3.5rem;
  --side-w: 17.5rem;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

body[data-theme="dark"] {
  --bg: #020617;
  --bg-accent: #0f172a;
  --side: #020617;
  --side-2: #111827;
  --side-text: #94a3b8;
  --side-active: #f8fafc;
  --panel: #0f172a;
  --line: #1e293b;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #60a5fa;
  --accent-2: #3b82f6;
  --accent-soft: rgba(59, 130, 246, 0.12);
  --ok: #34d399;
  --ok-bg: rgba(5, 150, 105, 0.16);
  --warn: #fbbf24;
  --warn-bg: rgba(217, 119, 6, 0.16);
  --bad: #f87171;
  --bad-bg: rgba(220, 38, 38, 0.16);
  --shadow-sm: 0 1px 2px rgba(2, 6, 23, 0.45);
  --shadow: 0 1px 3px rgba(2, 6, 23, 0.5), 0 10px 28px rgba(2, 6, 23, 0.35);
  --shadow-lg: 0 14px 42px rgba(2, 6, 23, 0.5);
}

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

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

html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background:
    radial-gradient(900px 420px at 8% -5%, rgba(37, 99, 235, 0.08), transparent 58%),
    radial-gradient(800px 400px at 100% 100%, rgba(15, 23, 42, 0.05), transparent 55%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

img, svg { display: block; max-width: 100%; }

.shell {
  display: grid;
  grid-template-columns: var(--side-w) minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  z-index: 40;
  opacity: 0;
  transition: opacity 0.22s ease;
  backdrop-filter: blur(2px);
}

.side {
  background: linear-gradient(180deg, var(--side) 0%, #111827 100%);
  color: var(--side-text);
  padding: 1.15rem 0.85rem calc(1rem + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 1rem;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 50;
  border-right: 1px solid rgba(148, 163, 184, 0.08);
}

.brand {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  padding: 0.25rem 0.5rem 0.85rem;
  border-bottom: 1px solid rgba(148, 163, 184, 0.15);
}

.brand strong {
  display: block;
  color: #fff;
  font-size: 0.98rem;
  letter-spacing: -0.02em;
  font-weight: 700;
}

.brand small {
  color: var(--side-text);
  font-size: 0.7rem;
  word-break: break-all;
  line-height: 1.35;
}

.brand-mark {
  width: 2.35rem;
  height: 2.35rem;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, #3b82f6, #1d4ed8);
  color: #fff;
  font-weight: 700;
  flex-shrink: 0;
  box-shadow: 0 6px 18px rgba(37, 99, 235, 0.35);
  overflow: hidden;
}

.brand-mark img,
.brand-mark svg {
  width: 100%;
  height: 100%;
}

.nav-section {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: #64748b;
  padding: 0.35rem 0.75rem;
  margin-top: 0.15rem;
}

.side nav {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  flex: 1;
  overflow: auto;
  overscroll-behavior: contain;
  padding-right: 0.15rem;
}

.side nav::-webkit-scrollbar { width: 4px; }
.side nav::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.35);
  border-radius: 999px;
}

.side nav a {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  color: var(--side-text);
  padding: 0.62rem 0.75rem;
  border-radius: 10px;
  text-decoration: none;
  font-weight: 500;
  font-size: 0.9rem;
  transition: background 0.15s ease, color 0.15s ease;
}

.side nav a svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: 0.88;
}

.side nav a:hover,
.side nav a.active {
  background: rgba(255, 255, 255, 0.08);
  color: var(--side-active);
  text-decoration: none;
}

.side nav a.active {
  background: rgba(37, 99, 235, 0.24);
  color: #fff;
}

.theme-toggle {
  width: 100%;
}

.theme-toggle-icon {
  font-size: 0.95rem;
  line-height: 1;
}

.theme-toggle-compact {
  width: 2.5rem;
}

.side-foot {
  border-top: 1px solid rgba(148, 163, 184, 0.15);
  padding-top: 0.85rem;
  display: grid;
  gap: 0.55rem;
}

.who {
  font-size: 0.8rem;
  color: #cbd5e1;
  padding: 0 0.35rem;
  word-break: break-word;
}

.who span {
  display: block;
  color: #64748b;
  font-size: 0.7rem;
  margin-top: 0.12rem;
}

.content-wrap {
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.mobile-header {
  display: none;
  align-items: center;
  gap: 0.75rem;
  padding: calc(0.65rem + var(--safe-top)) 1rem 0.65rem;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 30;
  backdrop-filter: blur(10px);
}

.mobile-header .brand {
  border: 0;
  padding: 0;
  flex: 1;
  min-width: 0;
}

.mobile-header .brand strong { color: var(--text); font-size: 0.95rem; }
.mobile-header .brand small { color: var(--muted); }

.nav-toggle {
  width: 2.5rem;
  height: 2.5rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  display: grid;
  place-items: center;
  cursor: pointer;
  flex-shrink: 0;
  padding: 0;
}

.nav-toggle svg { width: 1.15rem; height: 1.15rem; }

.main {
  padding: 1.35rem clamp(1rem, 3vw, 1.75rem) calc(2.5rem + var(--safe-bottom));
  width: 100%;
  max-width: 1200px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(1.35rem, 2.5vw, 1.65rem);
  letter-spacing: -0.03em;
  font-weight: 700;
  line-height: 1.2;
}

.subtitle {
  color: var(--muted);
  margin: 0.35rem 0 0;
  font-size: clamp(0.88rem, 2vw, 0.95rem);
  max-width: 42rem;
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
}

.grid { display: grid; gap: 1rem; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }

.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}

.stat::after {
  content: "";
  position: absolute;
  inset: auto -20% -45% auto;
  width: 88px;
  height: 88px;
  border-radius: 50%;
  background: var(--accent-soft);
  opacity: 0.75;
}

.stat .label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
  position: relative;
  z-index: 1;
}

.stat .value {
  font-size: clamp(1.45rem, 3vw, 1.75rem);
  font-weight: 700;
  margin-top: 0.2rem;
  letter-spacing: -0.03em;
  position: relative;
  z-index: 1;
}

.stat .hint {
  color: var(--muted);
  font-size: 0.76rem;
  margin-top: 0.3rem;
  position: relative;
  z-index: 1;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: clamp(0.95rem, 2.5vw, 1.2rem);
  box-shadow: var(--shadow-sm);
  margin-bottom: 1rem;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
  flex-wrap: wrap;
}

.panel h2 {
  margin: 0;
  font-size: clamp(0.95rem, 2vw, 1.02rem);
  font-weight: 700;
  letter-spacing: -0.01em;
}

.panel .muted { color: var(--muted); font-size: 0.84rem; }

.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -0.25rem;
  padding: 0 0.25rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  min-width: 560px;
}

th, td {
  text-align: left;
  padding: 0.7rem 0.55rem;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #f8fafc; }
body[data-theme="dark"] tbody tr:hover { background: rgba(148, 163, 184, 0.06); }

.mono {
  font-family: var(--mono);
  font-size: 0.82rem;
  word-break: break-all;
}

.btn, button.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  border: 1px solid transparent;
  background: var(--accent);
  color: #fff;
  border-radius: 10px;
  padding: 0.55rem 0.95rem;
  font: inherit;
  font-weight: 600;
  font-size: 0.86rem;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  min-height: 2.5rem;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

.btn:hover { background: var(--accent-2); text-decoration: none; color: #fff; }
.btn:active { transform: translateY(1px); }

.btn-ghost {
  background: var(--panel);
  border-color: var(--line);
  color: var(--text);
}

.btn-ghost:hover { background: color-mix(in srgb, var(--panel) 80%, var(--text) 4%); color: var(--text); }
.btn-danger { background: var(--bad); }
.btn-danger:hover { background: #b91c1c; }
.btn-ok { background: var(--ok); }
.btn-sm { padding: 0.35rem 0.65rem; font-size: 0.78rem; border-radius: 8px; min-height: 2rem; }
.actions { display: flex; flex-wrap: wrap; gap: 0.35rem; align-items: center; }

form.inline { display: inline; }

.form-grid {
  display: grid;
  gap: 0.85rem;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
  align-items: end;
}

label {
  display: grid;
  gap: 0.32rem;
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 600;
}

input, select, textarea {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 10px;
  padding: 0.62rem 0.72rem;
  font: inherit;
  min-height: 2.65rem;
}

input:focus, select:focus, textarea:focus {
  outline: 2px solid rgba(37, 99, 235, 0.18);
  border-color: var(--accent);
}

.row-end {
  display: flex;
  align-items: end;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}

.search {
  min-width: min(320px, 100%);
  background: var(--panel) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%2394a3b8' stroke-width='2' viewBox='0 0 24 24'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3-3'/%3E%3C/svg%3E") 0.75rem center no-repeat;
  padding-left: 2.2rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.16rem 0.52rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
  white-space: nowrap;
}

.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-bad { background: var(--bad-bg); color: var(--bad); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-info { background: var(--accent-soft); color: var(--accent); }

.flash {
  border-radius: 12px;
  padding: 0.82rem 0.95rem;
  margin-bottom: 1rem;
  border: 1px solid var(--line);
  font-weight: 500;
  font-size: 0.9rem;
}

.flash-ok { background: var(--ok-bg); border-color: #a7f3d0; color: #065f46; }
.flash-error { background: var(--bad-bg); border-color: #fecaca; color: #991b1b; }
.flash-warn { background: var(--warn-bg); border-color: #fde68a; color: #92400e; }

.status-list { display: grid; gap: 0.42rem; }

.status-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.62rem 0.75rem;
  background: color-mix(in srgb, var(--panel) 82%, var(--bg) 18%);
  border: 1px solid var(--line);
  border-radius: 10px;
  flex-wrap: wrap;
}

.progress {
  height: 8px;
  background: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
  margin-top: 0.5rem;
}

.progress > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #3b82f6, #2563eb);
}

.dns-block, .log-block {
  background: #0b1220;
  color: #e2e8f0;
  border-radius: 12px;
  padding: 0.95rem;
  overflow: auto;
  font-family: var(--mono);
  font-size: clamp(0.72rem, 2vw, 0.78rem);
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: min(60vh, 480px);
}

.copy-row { display: flex; gap: 0.5rem; align-items: start; flex-wrap: wrap; }
.copy-row .dns-block { flex: 1; min-width: min(100%, 280px); }

.empty {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--muted);
}

.empty strong {
  display: block;
  color: var(--text);
  margin-bottom: 0.35rem;
}

.auth-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: calc(1.25rem + var(--safe-top)) 1rem calc(1.25rem + var(--safe-bottom));
  background:
    radial-gradient(900px 420px at 8% -5%, rgba(37, 99, 235, 0.14), transparent 58%),
    radial-gradient(700px 360px at 100% 100%, rgba(15, 23, 42, 0.07), transparent 55%),
    var(--bg);
}

.auth-card {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: clamp(1.25rem, 4vw, 1.85rem);
  box-shadow: var(--shadow-lg);
}

.auth-actions {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 0.75rem;
}

.auth-card .brand {
  border: 0;
  padding: 0 0 1rem;
  justify-content: center;
}

.brand-center { justify-content: center; }

.auth-card .brand strong { color: var(--text); text-align: center; }
.auth-card .brand small { text-align: center; color: var(--muted); }
.auth-card form { display: grid; gap: 0.85rem; }
.auth-note { text-align: center; color: var(--muted); font-size: 0.84rem; margin: 1rem 0 0; }

body[data-theme="dark"] .flash-ok { border-color: rgba(52, 211, 153, 0.35); color: #a7f3d0; }
body[data-theme="dark"] .flash-error { border-color: rgba(248, 113, 113, 0.35); color: #fecaca; }
body[data-theme="dark"] .flash-warn { border-color: rgba(251, 191, 36, 0.35); color: #fde68a; }

.health-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 0.35rem;
}

.health-dot.on { background: var(--ok); box-shadow: 0 0 0 3px rgba(5, 150, 105, 0.15); }
.health-dot.off { background: var(--bad); box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.12); }

body.sidebar-open { overflow: hidden; }

/* Tablet */
@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .span-2 { grid-column: auto; }
}

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }

  .sidebar-backdrop {
    display: block;
    pointer-events: none;
  }

  .side {
    position: fixed;
    left: 0;
    top: 0;
    width: min(var(--side-w), 88vw);
    height: 100dvh;
    transform: translateX(-105%);
    transition: transform 0.24s ease;
    box-shadow: var(--shadow-lg);
  }

  body.sidebar-open .side { transform: translateX(0); }
  body.sidebar-open .sidebar-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  .mobile-header { display: flex; }

  .main {
    padding-top: 1rem;
    max-width: none;
  }

  .grid-2 { grid-template-columns: 1fr; }
}

/* Mobile */
@media (max-width: 640px) {
  .grid-4,
  .grid-3,
  .grid-2 { grid-template-columns: 1fr; }

  .topbar { flex-direction: column; align-items: stretch; }
  .topbar-actions { width: 100%; }
  .topbar-actions .btn { flex: 1 1 auto; justify-content: center; }

  .panel-head { align-items: flex-start; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .search { min-width: 100%; }

  .actions .btn,
  .actions form { width: auto; }

  table { min-width: 520px; }

  .status-row { flex-direction: column; align-items: flex-start; }
}

@media (max-width: 420px) {
  .main { padding-left: 0.85rem; padding-right: 0.85rem; }
  .btn { width: 100%; }
  .topbar-actions .btn { width: 100%; }
  .row-end .btn { width: 100%; }
  .auth-actions .btn { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
