:root {
  --bg: #1b1b1b;
  --panel: #262626;
  --line: #3a3a3a;
  --text: #e8e8e8;
  --muted: #a7a7a7;
  --accent: #25a6ff;
  --ok: #24c278;
  --warn: #f2bf61;
  --bad: #f06878;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: "Segoe UI", "Inter", sans-serif;
  background: var(--bg);
}
.hidden { display: none !important; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 2px;
  box-shadow: none;
}

.center-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 12px;
}
.login-card {
  width: min(420px, 95vw);
  padding: 20px;
  display: grid;
  gap: 10px;
}
.login-card h1 { margin: 0; }
.login-card p { margin: 0; color: var(--muted); }
label { display: grid; gap: 6px; color: var(--muted); font-size: 14px; }

input, textarea, select, button {
  font: inherit;
  border-radius: 2px;
  border: 1px solid var(--line);
  background: #202020;
  color: var(--text);
  padding: 8px 10px;
}
button {
  border: 1px solid #444;
  background: #2e2e2e;
  color: #fff;
  cursor: pointer;
  font-weight: 500;
}
button:hover { background: #363636; }
button.ghost { background: transparent; border: 1px solid var(--line); }
button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  background: #2a2a2a !important;
  border-color: #404040 !important;
  color: #8f8f8f !important;
}
.error { color: var(--bad); min-height: 20px; }

.app-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 0;
  min-height: 100vh;
}

.sidebar {
  padding: 10px 8px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 10px;
  min-height: 100vh;
  background: #141414;
  border-right: 1px solid #2f2f2f;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand img { width: 32px; height: 32px; }
.brand h2 { margin: 0; font-size: 24px; line-height: 1; }
.brand span { color: var(--accent); font-weight: 700; font-size: 16px; }

.menu { display: grid; gap: 6px; align-content: start; }
.menu button {
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  padding: 6px 8px;
  min-height: 30px;
  font-size: 14px;
}
.menu button.active {
  border-color: #454545;
  background: #222;
  box-shadow: inset 3px 0 0 var(--accent);
}
.sidebar-actions { display: grid; gap: 6px; }

.content {
  min-width: 0;
  display: grid;
  gap: 12px;
  align-content: start;
  padding: 12px;
  background: #1f1f1f;
}
.page-header h1 { margin: 0; }
.page-header p { margin: 4px 0 0; color: var(--muted); }
.page { display: grid; gap: 12px; align-content: start; }

.stat-grid, .server-grid, .service-grid, .vpn-grid, .domain-grid {
  display: grid;
  gap: 10px;
}
.stat-grid { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.server-grid { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.service-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.vpn-grid { grid-template-columns: repeat(auto-fit, minmax(270px, 1fr)); }
.domain-grid { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }

.stat-card, .server-card, .service-card, .vpn-card, .domain-card { padding: 12px; }
.meta { color: var(--muted); font-size: 13px; }
.badge {
  font-size: 12px;
  border-radius: 2px;
  padding: 2px 6px;
  display: inline-block;
  margin-top: 8px;
  font-weight: 700;
}
.badge.online { color: var(--ok); background: rgba(36,194,120,.15); }
.badge.offline, .badge.error { color: var(--bad); background: rgba(240,104,120,.16); }
.badge.degraded, .badge.unknown { color: var(--warn); background: rgba(242,191,97,.15); }

.server-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.inline-actions { display: inline-flex; gap: 8px; align-items: center; }
.danger { border-color: rgba(240,104,120,.45) !important; color: #ffbbc4; }

.chart-wrap { display: grid; gap: 8px; margin-top: 8px; }
.metric-line { display: grid; gap: 4px; }
.metric-line span { font-size: 12px; color: var(--muted); }
.progress {
  position: relative;
  height: 9px;
  border-radius: 2px;
  background: #1a1a1a;
  overflow: hidden;
  border: 1px solid #333;
}
.progress > i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #2f9eff, #53d2ff);
}
.progress.warn > i { background: linear-gradient(90deg, #f0aa38, #ffcf6a); }
.progress.bad > i { background: linear-gradient(90deg, #eb5568, #ff8a97); }

.tabs { display: flex; flex-wrap: wrap; gap: 8px; }
.tabs button {
  background: #262626;
  border: 1px solid #3d3d3d;
  padding: 5px 9px;
  min-height: 30px;
}
.tabs button.active { border-color: #525252; background: #313131; color: #fff; }

.service-card { cursor: pointer; }
.service-card h4 { margin: 0 0 6px; font-size: 14px; }
.service-card:hover { border-color: #525252; }
.domain-card h4 { margin: 0 0 6px; }

#topology {
  width: 100%;
  min-height: 420px;
  border-radius: 2px;
  border: 1px solid var(--line);
  background: #232323;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.66);
  z-index: 1001;
  display: grid;
  place-items: center;
  padding: 12px;
}
.modal-box {
  width: min(960px, 95vw);
  max-height: 92vh;
  overflow: auto;
  padding: 14px;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.modal-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.modal-intro { display: grid; gap: 6px; margin-bottom: 12px; }
.modal-extended { display: grid; gap: 12px; margin-top: 12px; margin-bottom: 12px; }
.mini-card { padding: 12px; display: grid; gap: 10px; }
.mini-card h4 { margin: 0; }
.mini-card textarea { min-height: 90px; resize: vertical; width: 100%; }
.alert-rules-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
}
.alert-rules-grid label {
  color: var(--text);
  font-size: 13px;
}
.check-row {
  display: flex !important;
  align-items: center;
  gap: 8px;
  min-height: 36px;
}
.check-row input[type="checkbox"] {
  width: 16px;
  height: 16px;
  padding: 0;
}
.deploy-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
}

.log-box {
  margin-top: 12px;
  font-family: Consolas, monospace;
  font-size: 12px;
  background: #171717;
  border: 1px solid var(--line);
  border-radius: 2px;
  padding: 10px;
  max-height: 360px;
  overflow: auto;
  white-space: pre-wrap;
}

.vpn-tunnel-list { display: grid; gap: 10px; margin-top: 8px; }
.vpn-tunnel-row {
  display: grid;
  gap: 4px;
  padding-bottom: 8px;
  border-bottom: 1px dashed #444;
}
.vpn-tunnel-row:last-child { border-bottom: 0; padding-bottom: 0; }
.vpn-tunnel-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.vpn-tunnel-title { font-weight: 600; }

.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(3px);
  z-index: 2000;
  display: grid;
  place-items: center;
  gap: 12px;
}
.spinner {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 4px solid rgba(255, 255, 255, 0.2);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
.loading-text { color: var(--muted); }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 920px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { min-height: auto; }
  .modal-actions { display: grid; grid-template-columns: 1fr; }
  .deploy-row { grid-template-columns: 1fr; }
}
