:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --sidebar: #111827;
  --sidebar-soft: #1f2937;
  --line: #d7deea;
  --line-strong: #b8c3d2;
  --text: #18202d;
  --muted: #667085;
  --accent: #0f766e;
  --accent-soft: #e7f7f4;
  --danger: #b42318;
  --danger-bg: #fff1f0;
  --ok: #067647;
  --ok-bg: #ecfdf3;
  --warn: #b54708;
  --warn-bg: #fffaeb;
  --shadow: 0 10px 28px rgba(20, 31, 46, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
}

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

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 18px 14px;
  background: var(--sidebar);
  color: #fff;
}

.brand {
  padding: 4px 6px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

h1,
h2,
h3,
h4,
p {
  margin: 0;
}

.brand h1 {
  font-size: 20px;
  font-weight: 760;
  letter-spacing: 0;
}

.brand p {
  margin-top: 5px;
  color: #aeb8c8;
  font-size: 12px;
}

.side-nav,
.side-links {
  display: grid;
  gap: 8px;
}

.side-links {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.nav-item,
.side-links a,
.logout-button {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  width: 100%;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: #d6dbe5;
  padding: 0 11px;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

.nav-item:hover,
.side-links a:hover,
.logout-button:hover,
.nav-item.active {
  background: var(--sidebar-soft);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.12);
}

.side-links form {
  margin: 0;
}

.logout-button {
  font: inherit;
}

.nav-item.active {
  box-shadow: inset 3px 0 0 var(--accent);
}

svg {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
}

.workspace {
  min-width: 0;
  padding-bottom: 28px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(12px);
}

.topbar h2 {
  font-size: 20px;
  font-weight: 760;
}

.topbar p,
.view-head p {
  margin-top: 5px;
  color: var(--muted);
}

button,
.refresh,
.mini-actions a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 36px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  padding: 0 12px;
  text-decoration: none;
  cursor: pointer;
}

button:hover,
.refresh:hover,
.mini-actions a:hover {
  border-color: var(--accent);
}

button.danger {
  border-color: #f3b6b1;
  background: var(--danger-bg);
  color: var(--danger);
}

button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.refresh {
  width: 36px;
  padding: 0;
}

.notice {
  margin: 16px 24px 0;
  padding: 10px 12px;
  border-radius: 7px;
  border: 1px solid var(--line);
}

.notice.ok {
  background: var(--ok-bg);
  color: var(--ok);
  border-color: #abefc6;
}

.notice.error {
  background: var(--danger-bg);
  color: var(--danger);
  border-color: #f3b6b1;
}

.view {
  display: none;
  padding: 22px 24px 0;
}

.view.active {
  display: block;
}

.view-head {
  margin-bottom: 16px;
}

.view-head h3 {
  font-size: 22px;
  font-weight: 760;
  letter-spacing: 0;
}

.status-grid,
.build-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(380px, 1fr));
  gap: 18px;
  align-items: start;
}

.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.form-panel {
  max-width: 820px;
}

.section-title,
.mini-actions,
.button-row,
.tabs {
  display: flex;
  align-items: center;
}

.section-title {
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.section-title h4 {
  font-size: 15px;
  font-weight: 740;
}

details.panel > summary.section-title {
  cursor: pointer;
  list-style: none;
}

details.panel > summary.section-title::-webkit-details-marker,
details.relay-action-box > summary::-webkit-details-marker {
  display: none;
}

.advanced-panel:not([open]) {
  box-shadow: none;
}

.advanced-panel .inline-error {
  margin: 12px 16px 0;
}

.table {
  padding: 10px 14px 14px;
}

.thead,
.tr {
  display: grid;
  grid-template-columns: 1fr 1.25fr 84px;
  gap: 10px;
  align-items: center;
  min-height: 38px;
  border-bottom: 1px solid #edf1f6;
}

.lines .thead,
.lines .tr {
  grid-template-columns: 1.35fr 74px 84px 1.1fr;
}

.order-table .thead,
.order-table .tr {
  grid-template-columns: 0.85fr 0.7fr 1fr 0.7fr;
}

.thead {
  color: var(--muted);
  font-size: 12px;
}

.tr span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.badge,
.expiry {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 0 9px;
  font-size: 12px;
  border: 1px solid var(--line);
  white-space: nowrap;
}

.badge.ok,
.expiry.ok {
  background: var(--ok-bg);
  color: var(--ok);
  border-color: #abefc6;
}

.badge.bad,
.expiry.expired {
  background: var(--danger-bg);
  color: var(--danger);
  border-color: #f3b6b1;
}

.expiry.soon {
  background: var(--warn-bg);
  color: var(--warn);
  border-color: #fedf89;
}

.expiry.unknown {
  background: #f8fafc;
  color: var(--muted);
}

.empty {
  color: var(--muted);
  padding: 18px 2px;
}

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

label {
  display: grid;
  gap: 5px;
  min-width: 0;
}

label span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
}

.checkbox-line {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
}

.checkbox-line input {
  width: 16px;
  min-height: 16px;
  box-shadow: none;
}

input,
select,
textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  padding: 8px 9px;
  outline: none;
}

textarea {
  resize: vertical;
  line-height: 1.45;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

.wide,
.button-row {
  grid-column: 1 / -1;
}

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

.balance-panel {
  overflow: hidden;
}

.balance-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfe;
}

.panel-kicker {
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}

.balance-head h4 {
  margin-top: 4px;
  font-size: 22px;
  font-weight: 780;
  overflow-wrap: anywhere;
}

.balance-head p:not(.panel-kicker) {
  margin-top: 6px;
  color: var(--muted);
}

.balance-last-check {
  max-width: 720px;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.balance-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.balance-stats {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  gap: 1px;
  background: var(--line);
  border-bottom: 1px solid var(--line);
}

.balance-stats div {
  display: grid;
  gap: 4px;
  padding: 12px 14px;
  background: #fff;
}

.balance-stats span {
  color: var(--muted);
  font-size: 12px;
}

.balance-stats strong {
  font-size: 22px;
  font-weight: 780;
}

.balance-form {
  display: grid;
  gap: 14px;
  padding: 14px 16px 16px;
}

.balance-config {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(140px, 0.35fr) minmax(150px, 0.4fr) auto;
  gap: 12px;
  align-items: end;
}

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

.pool-member-row {
  display: grid;
  grid-template-columns: minmax(220px, 0.9fr) 110px minmax(300px, 1.25fr);
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.pool-member-row.is-disabled {
  background: #f8fafc;
}

.pool-member-row.is-bad {
  border-color: #f3b6b1;
}

.pool-member-main {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.pool-member-main small,
.pool-member-row small {
  color: var(--muted);
  overflow-wrap: anywhere;
}

.pool-weight input {
  min-height: 34px;
}

.pool-health {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  min-width: 0;
}

.pool-health small {
  flex-basis: 100%;
}

.pool-health button {
  min-height: 30px;
  padding: 0 10px;
  font-size: 12px;
}

.button-row,
.mini-actions {
  gap: 8px;
  flex-wrap: wrap;
}

.mini-actions a {
  min-height: 30px;
  padding: 0 10px;
  font-size: 12px;
}

.tabs {
  gap: 6px;
  padding: 12px 16px 0;
}

.delivery-box {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfe;
}

.delivery-name {
  font-weight: 740;
  overflow-wrap: anywhere;
}

.delivery-link {
  display: block;
  margin-top: 8px;
  color: var(--accent);
  overflow-wrap: anywhere;
}

.delivery-box ol {
  margin: 12px 0 0;
  padding-left: 22px;
  color: var(--text);
  line-height: 1.7;
}

.delivery-expire {
  margin-top: 10px;
  color: var(--danger);
  font-size: 12px;
}

.tab {
  min-height: 32px;
  padding: 0 13px;
}

.tab.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: #115e59;
}

.tab-panel {
  display: none;
  padding: 12px 16px 16px;
}

.tab-panel.active {
  display: block;
}

.output {
  width: 100%;
  min-height: 360px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.55;
  white-space: pre;
}

.qr-grid.active {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}

figure {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 10px;
}

figure img {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: contain;
}

figcaption {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}

.auth-card {
  width: min(420px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 24px;
}

.auth-card h1 {
  font-size: 24px;
  font-weight: 760;
}

.auth-card > p {
  margin-top: 6px;
  color: var(--muted);
}

.auth-form {
  display: grid;
  gap: 14px;
  margin-top: 20px;
}

.auth-form button {
  width: 100%;
}

.auth-link {
  display: inline-block;
  margin-top: 14px;
  color: var(--accent);
  text-decoration: none;
}

.front-page,
.admin-page {
  min-height: 100vh;
  padding-bottom: 28px;
}

.public-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.public-topbar h1 {
  font-size: 22px;
  font-weight: 760;
}

.public-topbar p {
  margin-top: 5px;
  color: var(--muted);
}

.front-grid,
.admin-grid {
  display: grid;
  grid-template-columns: minmax(360px, 0.9fr) minmax(420px, 1.1fr);
  gap: 18px;
  padding: 22px 24px 0;
  align-items: start;
}

.admin-grid {
  grid-template-columns: repeat(3, minmax(320px, 1fr));
}

.stack-grid {
  display: grid;
  gap: 18px;
  max-width: 1180px;
}

.simple-admin-grid {
  grid-template-columns: repeat(3, minmax(320px, 1fr));
}

.relay-manager {
  grid-column: 1 / -1;
}

.relay-list {
  display: grid;
  gap: 10px;
  padding: 14px 16px 16px;
}

.node-list {
  display: grid;
  gap: 12px;
  padding: 14px 16px 16px;
}

.node-tools {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) minmax(140px, 0.35fr) minmax(160px, 0.4fr);
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfe;
}

.relay-card {
  display: grid;
  gap: 12px;
  padding: 12px;
  border: 1px solid #edf1f6;
  border-radius: 8px;
  background: #fbfcfe;
}

.node-card {
  display: grid;
  gap: 12px;
  padding: 12px;
  border: 1px solid #edf1f6;
  border-radius: 8px;
  background: #fbfcfe;
}

.node-card[hidden] {
  display: none;
}

.relay-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid #edf1f6;
}

.node-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid #edf1f6;
}

.relay-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.relay-domain {
  max-width: 320px;
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
  text-align: right;
}

.relay-actions-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(220px, 1fr));
  gap: 12px;
}

.relay-actions-grid.compact-relay-actions {
  grid-template-columns: repeat(2, minmax(220px, 1fr));
}

.node-actions-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(220px, 1fr)) minmax(140px, 0.7fr);
  gap: 12px;
}

.node-inline-actions {
  display: grid;
  gap: 10px;
  align-content: start;
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.node-inline-actions form,
.node-inline-actions button {
  width: 100%;
}

.relay-action-box {
  display: grid;
  gap: 10px;
  align-content: start;
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.relay-action-box button {
  width: fit-content;
}

details.relay-action-box > summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

details.relay-action-box form {
  display: grid;
  gap: 10px;
}

.relay-danger-box {
  background: #fffafa;
}

.relay-danger-box p {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.relay-card strong,
.relay-card small,
.node-card strong,
.node-card small {
  display: block;
  min-width: 0;
  overflow-wrap: anywhere;
}

.relay-card small,
.node-card small {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.compact-check {
  align-self: end;
  min-height: 38px;
}

.dns-list {
  display: grid;
  gap: 10px;
  padding: 0 16px 16px;
}

.dns-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 90px;
  gap: 10px;
  align-items: end;
  padding: 12px;
  border: 1px solid #edf1f6;
  border-radius: 8px;
  background: #fbfcfe;
}

.dns-edit-form {
  display: grid;
  grid-template-columns: minmax(220px, 1.1fr) minmax(180px, 0.9fr) 92px 90px;
  gap: 10px;
  align-items: end;
}

.dns-add-row {
  grid-template-columns: minmax(220px, 1.1fr) minmax(180px, 0.9fr) 92px 90px;
  margin: 16px;
}

.inline-error {
  color: var(--danger);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.copy-source {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.front-orders {
  grid-column: 1 / -1;
}

.one-column {
  grid-template-columns: 1fr;
}

.build-card textarea {
  min-height: 220px;
}

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

.progress-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(6px);
}

.progress-dialog {
  width: min(520px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 22px 70px rgba(15, 23, 42, 0.24);
  padding: 20px;
}

.progress-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}

.progress-head h4 {
  font-size: 18px;
  font-weight: 760;
}

.progress-head p,
.progress-hint {
  margin-top: 6px;
  color: var(--muted);
}

.progress-percent {
  color: var(--accent);
  font-size: 22px;
  font-weight: 780;
}

.progress-track {
  height: 10px;
  margin-top: 18px;
  overflow: hidden;
  border-radius: 999px;
  background: #e6ebf2;
}

.progress-bar {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 220ms ease;
}

.progress-steps {
  display: grid;
  gap: 9px;
  margin: 18px 0 0;
  padding: 0;
  list-style: none;
}

.progress-steps li {
  position: relative;
  padding-left: 24px;
  color: var(--muted);
}

.progress-steps li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 4px;
  width: 12px;
  height: 12px;
  border: 2px solid var(--line-strong);
  border-radius: 999px;
  background: #fff;
}

.progress-steps li.active {
  color: var(--text);
  font-weight: 700;
}

.progress-steps li.active::before {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.progress-steps li.done {
  color: var(--ok);
}

.progress-steps li.done::before {
  border-color: var(--ok);
  background: var(--ok);
}

@media (max-width: 1180px) {
  .status-grid,
  .build-grid,
  .admin-grid {
    grid-template-columns: 1fr;
  }

  .balance-stats {
    grid-template-columns: repeat(3, minmax(120px, 1fr));
  }

  .balance-config,
  .pool-member-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .app-layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

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

  .nav-item {
    justify-content: center;
    padding: 0 8px;
  }

  .nav-item span {
    display: none;
  }

  .side-links {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin-top: 0;
  }

  .topbar {
    position: static;
    padding: 14px;
  }

  .view {
    padding: 16px 14px 0;
  }

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

  .public-topbar {
    align-items: flex-start;
    flex-direction: column;
    padding: 14px;
  }

  .front-grid,
  .admin-grid {
    grid-template-columns: 1fr;
    padding: 14px;
  }

  .relay-actions-grid {
    grid-template-columns: 1fr;
  }

  .node-actions-grid {
    grid-template-columns: 1fr;
  }

  .node-tools {
    grid-template-columns: 1fr;
  }

  .relay-card-head,
  .node-card-head,
  .balance-head {
    display: grid;
  }

  .balance-actions {
    justify-content: flex-start;
  }

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

  .dns-row {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .dns-edit-form,
  .dns-add-row {
    grid-template-columns: 1fr;
  }

  .compact-check {
    align-self: stretch;
  }

  .thead,
  .tr,
  .lines .thead,
  .lines .tr,
  .order-table .thead,
  .order-table .tr {
    grid-template-columns: 1fr;
    gap: 6px;
    padding: 8px 0;
  }
}
