:root {
  color-scheme: dark;
  --bg: #09090b;
  --panel: #141014;
  --panel-2: #1d1418;
  --line: #332126;
  --text: #f8fafc;
  --muted: #a1a1aa;
  --red: #ef4444;
  --red-dark: #991b1b;
  --amber: #f59e0b;
  --green: #22c55e;
  --shadow: 0 22px 70px rgba(0, 0, 0, 0.36);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

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

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 1px solid rgba(239, 68, 68, 0.45);
  border-radius: 7px;
  background: #231216;
  color: var(--text);
  cursor: pointer;
  min-height: 38px;
  padding: 0 14px;
}

button:hover {
  border-color: var(--red);
  background: #35161b;
}

button.primary,
.icon-btn.primary,
.login-box button,
.settings-form > button,
.panel > button {
  background: linear-gradient(135deg, var(--red), var(--red-dark));
  border-color: transparent;
}

button.danger {
  border-color: rgba(239, 68, 68, 0.55);
  color: #fecaca;
}

button.small {
  min-height: 30px;
  padding-inline: 10px;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 244px;
  padding: 22px 16px;
  border-right: 1px solid var(--line);
  background: #0c090b;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  font-weight: 800;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 7px;
  background: var(--red);
  color: white;
  box-shadow: 0 0 28px rgba(239, 68, 68, 0.35);
}

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

.nav a,
.logout button {
  width: 100%;
  min-height: 40px;
  padding: 10px 12px;
  border-radius: 7px;
  color: var(--muted);
  text-align: left;
}

.nav a:hover {
  background: #1a1013;
  color: var(--text);
}

.logout {
  margin-top: auto;
}

.main {
  margin-left: 244px;
  padding: 28px;
}

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

.eyebrow {
  margin: 0 0 5px;
  color: var(--red);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 34px;
  line-height: 1.05;
}

h2 {
  font-size: 18px;
}

.icon-btn {
  width: 44px;
  height: 44px;
  padding: 0;
  font-size: 24px;
  line-height: 1;
}

.grid-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}

.row-list {
  display: grid;
  gap: 12px;
  width: 100%;
}

.server-card,
.config-card,
.panel,
.table-panel {
  border: 1px solid color-mix(in srgb, var(--accent, var(--red)) 36%, var(--line));
  border-radius: 8px;
  background: color-mix(in srgb, var(--accent, var(--red)) 10%, var(--panel));
  box-shadow: var(--shadow);
}

.server-card,
.config-card {
  padding: 16px;
}

.server-card {
  display: grid;
  grid-template-columns: 112px minmax(220px, 1fr) minmax(170px, 0.8fr) auto;
  align-items: center;
  gap: 14px;
  min-height: 92px;
}

.config-card {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(220px, 1fr) auto;
  align-items: center;
  gap: 14px;
  min-height: 76px;
}

.avatar {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  font-weight: 900;
}

.svg-avatar svg {
  width: 34px;
  height: 34px;
}

.card-body {
  min-width: 0;
}

.card-title {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

.server-avatar-stack {
  display: grid;
  justify-items: center;
  gap: 7px;
}

.ip-chip {
  max-width: 108px;
  min-height: 24px;
  border: 1px solid rgba(239, 68, 68, 0.34);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.18);
  color: var(--muted);
  padding: 3px 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}

button.ip-chip {
  cursor: pointer;
}

.copy-animated.copied {
  color: #bbf7d0;
  border-color: rgba(34, 197, 94, 0.55);
  transform: scale(1.04);
  transition: transform 140ms ease, border-color 140ms ease, color 140ms ease;
}

.server-main {
  display: grid;
  gap: 5px;
}

.server-main .status {
  justify-self: start;
}

.server-main h2,
.config-card h2 {
  margin: 0;
}

.server-main > span,
.last-seen span,
.config-server span {
  color: var(--muted);
  font-size: 13px;
}

.last-seen {
  display: grid;
  gap: 5px;
}

.last-seen b {
  font-size: 13px;
}

.card-title h2 {
  margin-bottom: 6px;
}

.card-title span,
.meta span {
  color: var(--muted);
  font-size: 13px;
}

.meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin: 12px 0;
}

.copy-chip {
  min-height: 28px;
  padding: 0 10px;
  font-size: 12px;
}

.command {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

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

.card-actions form {
  margin: 0;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #0f0d0f;
  color: var(--text);
  min-height: 38px;
  padding: 9px 10px;
}

textarea {
  min-height: 120px;
  resize: vertical;
  overflow: auto;
  white-space: pre;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

dialog {
  width: min(720px, calc(100vw - 26px));
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  padding: 0;
  box-shadow: var(--shadow);
  max-height: 92vh;
  overflow: auto;
}

dialog.wide-dialog {
  width: min(1320px, calc(100vw - 28px));
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.72);
}

.modal-form {
  padding: 18px;
}

.modal-form header,
.modal-form footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-form header {
  margin-bottom: 18px;
}

.modal-form footer {
  justify-content: flex-end;
  margin-top: 18px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.form-grid.single {
  grid-template-columns: 1fr;
  align-content: start;
}

.wide {
  grid-column: 1 / -1;
}

.inline-field {
  display: grid;
  grid-template-columns: 1fr 42px;
  gap: 8px;
}

.ghost {
  width: 36px;
  min-height: 36px;
  padding: 0;
  border-color: transparent;
  background: transparent;
  font-size: 24px;
}

.wide-modal {
  width: 100%;
  min-width: 0;
}

.split-form,
.generator-grid,
.workbench {
  display: grid;
  grid-template-columns: minmax(260px, 0.8fr) minmax(360px, 1.2fr);
  gap: 16px;
}

.config-split {
  grid-template-columns: minmax(300px, 360px) minmax(640px, 1fr);
  align-items: start;
}

.config-text textarea,
#generated-config {
  min-height: 430px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  line-height: 1.45;
}

.config-text textarea {
  max-width: 100%;
}

.field-error {
  min-height: 18px;
  color: #fca5a5;
}

.config-card pre {
  overflow: auto;
  min-height: 116px;
  max-height: 180px;
  padding: 12px;
  border-radius: 7px;
  background: rgba(0, 0, 0, 0.22);
  color: #fecaca;
}

.search-bar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(120px, auto);
  gap: 10px;
  margin-bottom: 16px;
}

.search-bar:has(input + input) {
  grid-template-columns: minmax(180px, 1fr) minmax(180px, 1fr) minmax(110px, auto);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.stat-card,
.topology-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.stat-card {
  display: grid;
  gap: 8px;
  padding: 18px;
}

.stat-card span {
  color: var(--muted);
  font-size: 13px;
}

.stat-card b {
  font-size: 34px;
}

.topology-panel {
  padding: 18px;
}

.topology-canvas {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(330px, 1fr));
  gap: 18px;
  min-height: 420px;
}

.server-orbit {
  position: relative;
  min-height: 360px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(rgba(239, 68, 68, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(239, 68, 68, 0.08) 1px, transparent 1px),
    radial-gradient(circle at center, rgba(239, 68, 68, 0.08), transparent 52%),
    rgba(255, 255, 255, 0.02);
  background-size: 22px 22px, 22px 22px, auto, auto;
}

.orbit-center {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 2;
  display: grid;
  grid-template-columns: 58px minmax(0, 160px);
  align-items: center;
  gap: 12px;
  transform: translate(-50%, -50%);
  padding: 12px;
  border: 1px solid color-mix(in srgb, var(--accent) 50%, var(--line));
  border-radius: 8px;
  background: var(--panel);
}

.orbit-center span,
.orbit-empty {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.orbit-line {
  position: absolute;
  z-index: 0;
  height: 2px;
  transform-origin: left center;
  background: var(--accent);
  box-shadow: 0 0 14px color-mix(in srgb, var(--accent) 65%, transparent);
}

.domain-node {
  position: absolute;
  z-index: 1;
  max-width: 150px;
  transform: translate(-50%, -50%);
  border: 1px solid color-mix(in srgb, var(--accent) 54%, var(--line));
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 18%, var(--panel));
  padding: 7px 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.orbit-empty {
  position: absolute;
  left: 50%;
  top: calc(50% + 76px);
  transform: translateX(-50%);
}

.task-extra {
  display: grid;
  gap: 12px;
}

.compact-filter {
  display: flex;
  justify-content: flex-end;
  margin-top: -42px;
  margin-bottom: 12px;
}

.compact-filter label {
  width: 130px;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  padding-top: 14px;
  color: var(--muted);
}

.pagination a {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 7px 10px;
  color: var(--text);
}

.logo-picker {
  display: grid;
  gap: 8px;
}

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

.server-fields {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.logo-picker-top {
  justify-self: end;
  width: 292px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.02);
}

.logo-choice-grid {
  display: grid;
  grid-template-columns: repeat(6, 42px);
  gap: 8px;
}

.logo-choice {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  padding: 0;
}

.logo-choice svg {
  width: 24px;
  height: 24px;
}

.logo-choice.selected {
  border-color: var(--red);
  background: rgba(239, 68, 68, 0.24);
}

.install-box {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.icon-square {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  min-height: 42px;
  padding: 0;
}

.icon-square svg {
  width: 20px;
  height: 20px;
}

button[disabled] {
  cursor: not-allowed;
  opacity: 0.45;
}

button.loading {
  color: transparent;
  position: relative;
}

button.loading::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.flash-stack,
.toast-stack {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  display: grid;
  gap: 10px;
  width: min(360px, calc(100vw - 36px));
}

.toast,
.flash {
  padding: 12px 14px;
  border: 1px solid rgba(239, 68, 68, 0.4);
  border-radius: 8px;
  background: #160d10;
  box-shadow: var(--shadow);
}

.toast.success,
.flash.success {
  border-color: rgba(34, 197, 94, 0.45);
}

.toast.error,
.flash.error {
  border-color: rgba(239, 68, 68, 0.65);
}

.panel,
.table-panel {
  padding: 18px;
}

.generator-form,
.settings-form,
.panel {
  display: grid;
  gap: 14px;
}

.log-list {
  display: grid;
  gap: 8px;
  max-height: 380px;
  overflow: auto;
  color: var(--muted);
  font-size: 13px;
}

.domain-add-form {
  grid-template-columns: minmax(220px, 420px) auto;
  justify-content: start;
}

.domain-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 14px;
}

.cert-card {
  display: grid;
  gap: 16px;
  min-height: 282px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  transition: filter 160ms ease, opacity 160ms ease, border-color 160ms ease;
}

.cert-card.cert-expired {
  border-color: rgba(239, 68, 68, 0.78);
}

.cert-card.is-checking {
  filter: blur(1.6px);
  opacity: 0.72;
  pointer-events: none;
}

.cert-card-top,
.cert-card-actions,
.cert-right-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.cert-card-top,
.cert-card-actions {
  justify-content: space-between;
}

.domain-copy {
  min-width: 0;
  max-width: calc(100% - 34px);
  min-height: 32px;
  padding: 0;
  border: 0;
  background: transparent;
  overflow: hidden;
  color: var(--text);
  font-size: 18px;
  font-weight: 800;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.domain-copy:hover {
  background: transparent;
}

.domain-copy.expired,
.cert-expiry.expired b {
  color: #f87171;
}

.live-dot {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--red);
  box-shadow: 0 0 16px rgba(239, 68, 68, 0.55);
}

.live-dot.ok {
  background: var(--green);
  box-shadow: 0 0 16px rgba(34, 197, 94, 0.55);
}

.live-dot.bad {
  background: var(--red);
}

.cert-card-body {
  display: grid;
  gap: 9px;
}

.cert-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 7px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.cert-row span,
.muted-row b {
  color: var(--muted);
  font-size: 13px;
}

.cert-row b {
  min-width: 0;
  overflow-wrap: anywhere;
  text-align: right;
}

.cert-error {
  margin: 2px 0 0;
  color: #fca5a5;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.cert-card-actions a.icon-square {
  border: 1px solid rgba(239, 68, 68, 0.45);
  border-radius: 7px;
  background: #231216;
}

.cert-card-actions a.icon-square:hover {
  border-color: var(--red);
  background: #35161b;
}

.refresh-round {
  border-radius: 50%;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th,
td {
  padding: 11px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

code {
  color: #fecaca;
}

.status {
  display: inline-flex;
  border-radius: 999px;
  padding: 4px 8px;
  background: #231216;
  color: #fecaca;
}

.status.done {
  color: #bbf7d0;
  background: rgba(34, 197, 94, 0.12);
}

.status.running {
  color: #fde68a;
  background: rgba(245, 158, 11, 0.14);
}

.empty {
  color: var(--muted);
}

.login-page {
  display: grid;
  place-items: center;
  padding: 22px;
}

.login-box {
  display: grid;
  gap: 16px;
  width: min(390px, 100%);
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

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

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

input[type="checkbox"],
.switch input {
  width: 18px;
  min-height: 18px;
  padding: 0;
}

@media (max-width: 860px) {
  .sidebar {
    position: static;
    width: auto;
    min-height: 0;
  }

  .main {
    margin-left: 0;
    padding: 18px;
  }

  .nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .split-form,
  .generator-grid,
  .workbench,
  .form-grid,
  .server-form-layout,
  .stats-grid,
  .search-bar,
  .search-bar:has(input + input) {
    grid-template-columns: 1fr;
  }

  .server-card {
    grid-template-columns: 1fr;
  }

  .card-actions {
    grid-column: 1 / -1;
  }

  .config-card {
    grid-template-columns: 1fr;
  }

  .config-split {
    grid-template-columns: 1fr;
  }

  .logo-picker-top {
    justify-self: stretch;
    width: auto;
  }

  .topology-canvas {
    grid-template-columns: 1fr;
  }

  .install-box {
    grid-template-columns: 1fr;
  }

  .domain-add-form {
    grid-template-columns: 1fr;
  }
}
