:root {
  --bg: #0b1220;
  --panel: #111827;
  --panel-2: #162033;
  --panel-3: #1d2940;
  --line: #2c3a54;
  --text: #e5edf8;
  --muted: #8ea0b9;
  --blue: #3b82f6;
  --blue-2: #60a5fa;
  --ok: #22c55e;
  --bad: #ef4444;
  --warn: #f59e0b;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  color: var(--text);
  background: var(--bg);
  font: 15px/1.45 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a { color: inherit; text-decoration: none; }
svg { width: 18px; height: 18px; flex: 0 0 auto; }

.sidebar {
  width: 256px;
  min-height: 100vh;
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  background: #08101e;
  border-right: 1px solid var(--line);
}

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

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--blue);
  color: white;
  font-weight: 800;
}

.brand strong, .brand span { display: block; }
.brand span { color: var(--muted); font-size: 13px; }

nav {
  display: grid;
  gap: 6px;
}

nav a, .ghost {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 42px;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
  font: inherit;
  cursor: pointer;
}

nav a.active, nav a:hover, .ghost:hover {
  color: var(--text);
  background: var(--panel-2);
  border-color: var(--line);
}

.sidebar form { margin-top: auto; }

.main {
  width: calc(100% - 256px);
  min-height: 100vh;
  padding: 32px;
  background: linear-gradient(180deg, #0d1728 0%, var(--bg) 220px);
}

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}

h1 { margin: 0; font-size: 30px; line-height: 1.15; letter-spacing: 0; }
p { margin: 6px 0 0; color: var(--muted); }

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  gap: 16px;
}

.stat, .server-row, .empty, .form-grid, .login-box, .panel-form, .data-panel, .table-panel, .mesh-map {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 18px 40px rgba(0, 0, 0, .25);
}

.stat {
  padding: 20px;
  display: grid;
  gap: 8px;
}

.stat span { color: var(--muted); }
.stat strong { font-size: 36px; line-height: 1; }

.server-list { display: grid; gap: 10px; }

.mesh-map {
  position: relative;
  min-height: 560px;
  margin-top: 18px;
  overflow: hidden;
  background:
    linear-gradient(rgba(96,165,250,.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(96,165,250,.06) 1px, transparent 1px),
    var(--panel);
  background-size: 42px 42px;
}

.mesh-lines {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.mesh-lines line {
  stroke: rgba(96,165,250,.72);
  stroke-width: 2.5;
  stroke-linecap: round;
  filter: drop-shadow(0 0 8px rgba(59,130,246,.35));
}

.mesh-nodes {
  position: absolute;
  inset: 0;
}

.mesh-node {
  position: absolute;
  width: 150px;
  min-height: 132px;
  transform: translate(-50%, -50%);
  display: grid;
  justify-items: center;
  gap: 4px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(17, 24, 39, .92);
  box-shadow: 0 18px 38px rgba(0,0,0,.32);
  text-align: center;
}

.node-status {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 12px;
  height: 12px;
  border-radius: 999px;
  border: 2px solid rgba(255,255,255,.22);
  background: #64748b;
  box-shadow: 0 0 0 4px rgba(100,116,139,.12);
}

.node-status.fresh {
  background: var(--ok);
  box-shadow: 0 0 0 4px rgba(34,197,94,.14), 0 0 18px rgba(34,197,94,.45);
}

.node-status.warn {
  background: var(--warn);
  box-shadow: 0 0 0 4px rgba(245,158,11,.14), 0 0 18px rgba(245,158,11,.42);
}

.node-status.stale {
  background: var(--bad);
  box-shadow: 0 0 0 4px rgba(239,68,68,.14), 0 0 18px rgba(239,68,68,.38);
}

.node-status.never {
  background: #64748b;
}

.mesh-node .avatar {
  width: 54px;
  height: 54px;
}

.mesh-node strong {
  max-width: 126px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mesh-node span, .mesh-node small {
  color: var(--muted);
  font-size: 12px;
}

.mesh-node .public-ip {
  max-width: 126px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.server-row {
  min-height: 78px;
  padding: 12px 14px;
  display: grid;
  grid-template-columns: 52px minmax(180px, 1fr) 150px 42px;
  align-items: center;
  gap: 14px;
}

.table-panel { overflow: hidden; }

.server-table {
  display: grid;
}

.server-table-head, .server-table-row {
  display: grid;
  grid-template-columns: minmax(260px, 1.4fr) minmax(170px, .9fr) minmax(110px, .55fr) 90px minmax(230px, .95fr);
  gap: 14px;
  align-items: center;
  padding: 12px 14px;
}

.server-table-head {
  color: var(--muted);
  background: var(--panel-2);
  border-bottom: 1px solid var(--line);
  font-size: 13px;
  font-weight: 700;
}

.server-table-row {
  min-height: 82px;
  border-bottom: 1px solid rgba(44,58,84,.65);
}

.server-table-row:last-child { border-bottom: 0; }

.server-cell-main {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.server-info small {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.row-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.row-actions form { margin: 0; }

.version-pill {
  display: inline-flex;
  min-width: 42px;
  justify-content: center;
  border-radius: 999px;
  padding: 4px 8px;
  background: rgba(96,165,250,.12);
  color: #bfdbfe;
  border: 1px solid rgba(96,165,250,.35);
}

.avatar, .avatar-preview {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: white;
  border: 1px solid rgba(255,255,255,.18);
}

.server-info strong, .server-info span { display: block; }
.server-info span, .server-ip { color: var(--muted); font-size: 14px; }
.server-ip { text-align: right; }

.icon-button, .button, button.primary {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

.icon-button { width: 42px; padding: 0; }
.button:hover, .icon-button:hover { border-color: var(--blue-2); }
.button.danger { color: #fecaca; border-color: rgba(239,68,68,.4); }
.button.danger:hover { border-color: var(--bad); }
.icon-button.danger {
  color: #fecaca;
  border-color: rgba(239,68,68,.38);
  background: rgba(127,29,29,.18);
}
.icon-button.danger:hover {
  border-color: var(--bad);
  background: rgba(127,29,29,.32);
}
.icon-button:disabled, .button:disabled, button.primary:disabled {
  cursor: not-allowed;
  opacity: .45;
  border-color: var(--line);
}
.primary, button.primary {
  border-color: var(--blue);
  background: var(--blue);
  color: white;
}

.form-grid, .panel-form {
  padding: 20px;
  display: grid;
  grid-template-columns: repeat(2, minmax(240px, 1fr));
  gap: 16px;
}

label, .compact-label {
  display: grid;
  gap: 7px;
  color: #c6d3e6;
  font-weight: 600;
}

input, select, textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
  color: var(--text);
  background: #0d1627;
  font: inherit;
  font-weight: 400;
}

textarea { resize: vertical; }
input[readonly] { background: #111827; color: var(--muted); }
.wide { grid-column: 1 / -1; }
.form-actions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; }
.form-hint { margin-right: auto; color: var(--warn); }

.input-action {
  display: flex;
  gap: 8px;
  align-items: center;
}

.input-action input { min-width: 0; }
.input-action .button { white-space: nowrap; }

.install-command {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #0d1627;
}

.install-command span {
  color: #c6d3e6;
  font-weight: 700;
}

.install-command code {
  display: block;
  overflow-x: auto;
  padding: 10px;
  border-radius: 8px;
  background: #07101f;
  color: #bfdbfe;
  white-space: nowrap;
}

.server-editor {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.avatar-builder {
  position: sticky;
  top: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 18px;
  display: grid;
  justify-items: center;
  gap: 16px;
}

.avatar-preview {
  width: 112px;
  height: 112px;
  border: 0;
  cursor: pointer;
}

.avatar-preview svg { width: 42px; height: 42px; }
.avatar-picker { display: grid; gap: 14px; width: 100%; }

.logo-grid, .color-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.logo-choice, .color-choice {
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
}

.logo-choice.selected, .color-choice.selected {
  outline: 2px solid var(--blue-2);
  border-color: transparent;
}

.color-choice { min-width: 0; }

.switch-line {
  grid-template-columns: 18px 1fr;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--panel-2);
}

.switch-line input {
  width: 18px;
  min-height: 18px;
}

.tasks-layout {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.toolbar-form {
  max-width: 360px;
  margin-bottom: 16px;
}

.param-grid {
  display: grid;
  grid-template-columns: 1fr 120px;
  gap: 12px;
}

.tasks-layout .panel-form {
  grid-template-columns: 1fr;
  position: sticky;
  top: 24px;
}

.task-panels {
  display: grid;
  gap: 18px;
}

.data-panel { overflow: hidden; }

.panel-head {
  min-height: 48px;
  padding: 0 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  background: var(--panel-2);
}

.timeline {
  display: grid;
  gap: 10px;
  padding: 12px;
  max-height: 420px;
  overflow: auto;
}

.timeline-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #0d1627;
  display: grid;
  gap: 6px;
}

.timeline-item div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.timeline-item code {
  padding: 8px;
  border-radius: 8px;
  background: #07101f;
  color: #c7d2fe;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.timeline-item small { color: var(--muted); }

.timeline-item .button {
  justify-self: start;
  min-height: 34px;
}

.badge {
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px;
  border: 1px solid var(--line);
  color: var(--muted);
}

.badge.done { color: var(--ok); border-color: rgba(34,197,94,.45); }
.badge.failed { color: var(--bad); border-color: rgba(239,68,68,.45); }
.badge.running { color: var(--blue-2); border-color: rgba(96,165,250,.45); }
.badge.queued { color: var(--warn); border-color: rgba(245,158,11,.45); }

.inline-message { min-height: 20px; color: var(--muted); }
.inline-message.error { color: var(--bad); }
.inline-message.success { color: var(--ok); }

.flashes {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

.flash {
  border-radius: 8px;
  padding: 10px 12px;
  background: rgba(59,130,246,.12);
  color: #bfdbfe;
  border: 1px solid rgba(96,165,250,.35);
}

.flash.error {
  background: rgba(239,68,68,.12);
  color: #fecaca;
  border-color: rgba(239,68,68,.35);
}

.flash.success {
  background: rgba(34,197,94,.12);
  color: #bbf7d0;
  border-color: rgba(34,197,94,.35);
}

.empty { padding: 24px; color: var(--muted); }
.empty.slim { padding: 12px; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(3, 7, 18, .72);
}

.modal-backdrop[hidden] { display: none; }

.modal {
  width: min(920px, 100%);
  max-height: min(760px, 90vh);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 28px 80px rgba(0,0,0,.5);
  overflow: hidden;
}

.modal header {
  min-height: 58px;
  padding: 0 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  background: var(--panel-2);
}

.modal header strong, .modal header span { display: block; }
.modal header span { color: var(--muted); font-size: 13px; }

.modal pre {
  margin: 0;
  padding: 16px;
  max-height: 680px;
  overflow: auto;
  white-space: pre-wrap;
  color: #dbeafe;
  background: #07101f;
  font-size: 13px;
  line-height: 1.5;
}

.log-table {
  display: grid;
}

.log-table-head, .log-row {
  display: grid;
  grid-template-columns: 180px 150px 180px 140px minmax(220px, 1fr);
  gap: 12px;
  align-items: center;
  padding: 11px 14px;
}

.log-table-head {
  color: var(--muted);
  background: var(--panel-2);
  border-bottom: 1px solid var(--line);
  font-weight: 700;
  font-size: 13px;
}

.log-row {
  border-bottom: 1px solid rgba(44,58,84,.65);
}

.log-row:last-child { border-bottom: 0; }

.login-page {
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(circle at top left, #12325f 0, transparent 34%), var(--bg);
}

.login-box {
  width: min(420px, 100%);
  padding: 24px;
  display: grid;
  gap: 16px;
}

.login-brand { margin-bottom: 8px; }

@media (max-width: 920px) {
  body { display: block; }
  .sidebar {
    width: 100%;
    min-height: auto;
    position: sticky;
    top: 0;
    z-index: 10;
  }
  nav { grid-template-columns: repeat(5, 1fr); }
  .sidebar form { display: none; }
  .main { width: 100%; padding: 20px; }
  .stats, .form-grid, .panel-form, .server-editor, .tasks-layout { grid-template-columns: 1fr; }
  .avatar-builder, .tasks-layout .panel-form { position: static; }
  .server-row { grid-template-columns: 52px minmax(0, 1fr) 42px; }
  .server-table-head { display: none; }
  .server-table-row {
    grid-template-columns: 1fr;
    align-items: stretch;
  }
  .row-actions { justify-content: flex-start; flex-wrap: wrap; }
  .log-table-head { display: none; }
  .log-row { grid-template-columns: 1fr; }
  .param-grid { grid-template-columns: 1fr; }
  .mesh-map { min-height: 620px; }
  .server-ip { display: none; }
}
