﻿/* dn42 Autopeer WebUI — clean light dashboard.
   Single stylesheet, no build step. Design tokens first, then layout, then components. */

:root {
  color-scheme: light;

  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --line: #e2e8f0;
  --line-strong: #cbd5e1;

  --fg: #0f172a;
  --muted: #64748b;
  --faint: #94a3b8;

  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #eff6ff;
  --accent-fg: #ffffff;

  --ok: #166534;
  --ok-bg: #dcfce7;
  --warn: #92400e;
  --warn-bg: #fef3c7;
  --bad: #991b1b;
  --bad-bg: #fee2e2;
  --neutral: #475569;
  --neutral-bg: #f1f5f9;

  --code-bg: #0f172a;
  --code-fg: #e2e8f0;

  --radius: 10px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 10px 25px rgba(15, 23, 42, 0.08);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
}

h1 {
  font-size: 1.55rem;
  margin: 0 0 4px;
}

h2 {
  font-size: 1.15rem;
  margin: 0 0 14px;
}

h3 {
  font-size: 1rem;
  margin: 0 0 10px;
}

p {
  margin: 0 0 10px;
}

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

a:hover {
  text-decoration: underline;
}

code {
  font-family: var(--mono);
  font-size: 0.86em;
}

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

.faint {
  color: var(--faint);
}

.nowrap {
  white-space: nowrap;
}

/* ---------- top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.topbar-inner {
  width: min(1200px, calc(100vw - 32px));
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 22px;
  height: 58px;
}

.brand {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--fg);
}

.brand:hover {
  text-decoration: none;
}

.topnav {
  display: flex;
  gap: 4px;
  flex: 1;
  flex-wrap: wrap;
}

.navlink {
  color: var(--muted);
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  font-weight: 500;
}

.navlink:hover {
  color: var(--fg);
  background: var(--surface-2);
  text-decoration: none;
}

.navlink.active {
  color: var(--accent);
  background: var(--accent-soft);
}

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

.user-chip {
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

/* ---------- layout ---------- */

.main {
  width: min(1200px, calc(100vw - 32px));
  margin: 26px auto 60px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}

.card.narrow,
.center-card {
  max-width: 460px;
  margin-inline: auto;
}

.center-card {
  margin-top: 64px;
  text-align: center;
}

.page-header {
  margin-bottom: 18px;
}

.page-header h1 {
  margin-bottom: 2px;
}

.section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.section-title h2 {
  margin: 0;
}

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

/* ---------- admin shell (sidebar + content) ---------- */

.admin-shell {
  display: grid;
  grid-template-columns: 216px 1fr;
  gap: 24px;
  align-items: start;
}

.sidebar {
  position: sticky;
  top: 78px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--faint);
  padding: 10px 12px 4px;
}

.sidebar a {
  color: var(--fg);
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  font-weight: 500;
  font-size: 0.92rem;
}

.sidebar a:hover {
  background: var(--surface-2);
  text-decoration: none;
}

.sidebar a.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.admin-content {
  min-width: 0; /* let wide tables scroll instead of blowing out the grid */
}

/* ---------- stat cards ---------- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 4px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
  display: block;
  color: var(--fg);
}

a.stat-card:hover {
  text-decoration: none;
  box-shadow: var(--shadow-lg);
  transform: translateY(-1px);
  transition: box-shadow 0.12s, transform 0.12s;
}

.stat-value {
  font-size: 1.9rem;
  font-weight: 700;
  line-height: 1.1;
}

.stat-label {
  color: var(--muted);
  font-size: 0.86rem;
  margin-top: 2px;
}

.stat-sub {
  color: var(--faint);
  font-size: 0.78rem;
  margin-top: 4px;
}

.stat-ok {
  border-left-color: var(--ok);
}

.stat-warn {
  border-left-color: var(--warn);
}

.stat-bad {
  border-left-color: var(--bad);
}

.stat-accent {
  border-left-color: var(--accent);
}

/* ---------- badges ---------- */

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 600;
  line-height: 1.5;
  white-space: nowrap;
}

.badge-ok {
  background: var(--ok-bg);
  color: var(--ok);
}

.badge-warn {
  background: var(--warn-bg);
  color: var(--warn);
}

.badge-bad {
  background: var(--bad-bg);
  color: var(--bad);
}

.badge-neutral {
  background: var(--neutral-bg);
  color: var(--neutral);
}

/* ---------- tables ---------- */

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

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

thead th {
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 600;
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  text-align: left;
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

tbody td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr:hover td {
  background: var(--surface-2);
}

td.mono,
.mono {
  font-family: var(--mono);
  font-size: 0.82rem;
}

td input,
td select {
  width: 100%;
  min-width: 120px;
}

.truncate {
  display: inline-block;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
}

.node-health {
  min-width: 120px;
}

.online-state {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.online-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  box-shadow: 0 0 0 3px currentColor;
  opacity: 0.78;
}

.online-state.is-online {
  color: var(--ok);
}

.online-state.is-offline {
  color: var(--bad);
}

.system-summary {
  display: inline-block;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
}

.node-system {
  min-width: 280px;
}

.resource-metrics {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 6px;
}

.resource-metric {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--fg);
  font-family: var(--mono);
  font-size: 0.72rem;
  white-space: nowrap;
}

.resource-metric span {
  color: var(--muted);
  font-family: var(--sans);
  font-weight: 700;
}

.node-status-details {
  margin-top: 6px;
}

.node-status-details summary {
  width: fit-content;
}

.status-label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 0 4px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
}

.node-status-output {
  max-height: 260px;
  min-width: 420px;
  min-height: 44px;
  padding: 12px;
  font-size: 0.78rem;
}

/* ---------- forms ---------- */

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

.field {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 500;
}

label.field {
  margin: 0;
}

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

input,
select,
textarea {
  min-height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 0 11px;
  background: var(--surface);
  color: var(--fg);
}

textarea {
  padding: 9px 11px;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--fg);
  font-weight: 500;
}

.checkbox-label input {
  min-height: auto;
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

/* ---------- buttons ---------- */

.btn,
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--accent-fg);
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
}

.btn:hover,
button:hover {
  text-decoration: none;
}

.btn-primary,
button[type="submit"]:not(.btn-secondary):not(.btn-danger):not(.btn-ghost):not(.copy-btn) {
  background: var(--accent);
  color: var(--accent-fg);
}

.btn-primary:hover,
button[type="submit"]:not(.btn-secondary):not(.btn-danger):not(.btn-ghost):not(.copy-btn):hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--surface);
  color: var(--accent);
  border-color: var(--line-strong);
}

.btn-secondary:hover {
  background: var(--accent-soft);
}

.btn-danger {
  background: var(--surface);
  color: var(--bad);
  border-color: #fca5a5;
}

.btn-danger:hover {
  background: var(--bad-bg);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border-color: transparent;
}

.btn-ghost:hover {
  background: var(--surface-2);
  color: var(--fg);
}

.btn-sm {
  min-height: 32px;
  padding: 0 10px;
  font-size: 0.82rem;
}

.btn.disabled,
.btn:disabled,
button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ---------- code / terminal ---------- */

.codewrap {
  position: relative;
}

.terminal {
  overflow-x: auto;
  margin: 0;
  padding: 16px;
  background: var(--code-bg);
  color: var(--code-fg);
  border-radius: var(--radius-sm);
  font-family: var(--mono);
  font-size: 0.84rem;
  line-height: 1.5;
  min-height: 56px;
  white-space: pre-wrap;
  word-break: break-word;
}

.terminal.ok {
  border-left: 4px solid #22c55e;
}

.terminal.bad {
  border-left: 4px solid #ef4444;
}

.terminal.muted-empty {
  color: var(--faint);
  font-style: italic;
}

.copy-btn {
  background: rgba(148, 163, 184, 0.18);
  color: var(--muted);
  border: 1px solid var(--line);
  min-height: 28px;
  padding: 0 10px;
  font-size: 0.76rem;
  font-weight: 600;
}

.codewrap .copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(15, 23, 42, 0.6);
  color: #e2e8f0;
  border-color: rgba(226, 232, 240, 0.2);
}

.copy-btn:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.copy-inline {
  vertical-align: middle;
}

/* ---------- flash ---------- */

.flash-area {
  width: min(1200px, calc(100vw - 32px));
  margin: 16px auto 0;
  display: grid;
  gap: 10px;
}

.flash {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 0.9rem;
}

.flash-error {
  background: var(--bad-bg);
  color: var(--bad);
  border-color: #fca5a5;
}

.flash-success {
  background: var(--ok-bg);
  color: var(--ok);
  border-color: #86efac;
}

.flash-info {
  background: var(--accent-soft);
  color: var(--accent-hover);
  border-color: #bfdbfe;
}

.flash-close {
  background: transparent;
  border: none;
  color: inherit;
  font-size: 1.2rem;
  min-height: auto;
  padding: 0 4px;
  cursor: pointer;
  line-height: 1;
}

.flash-close:hover {
  background: transparent;
  opacity: 0.7;
}

/* ---------- pager ---------- */

.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-top: 16px;
}

.pager-info {
  color: var(--muted);
  font-size: 0.85rem;
}

/* ---------- misc ---------- */

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 36px 16px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.error-code {
  font-size: 3.4rem;
  font-weight: 800;
  color: var(--accent);
  line-height: 1;
}

.detail-row td {
  background: var(--surface-2);
}

.detail-row .terminal {
  margin-top: 6px;
}

details > summary {
  cursor: pointer;
  color: var(--accent);
  font-size: 0.85rem;
}

.activity-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.activity-list li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.88rem;
}

.activity-list li:last-child {
  border-bottom: none;
}

/* key/value rows (e.g. the "our side" peering details under a deployed peer) */
.kv {
  display: grid;
  gap: 8px;
  margin: 8px 0 4px;
}

.kv-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.kv-key {
  color: var(--muted);
  font-size: 0.82rem;
  min-width: 210px;
}

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

.split-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

hr.divider {
  border: none;
  border-top: 1px solid var(--line);
  margin: 22px 0;
}

/* ---------- home / hero ---------- */

.hero {
  text-align: center;
  padding: 42px 24px;
}

.hero h1 {
  font-size: 2rem;
}

.hero-asn {
  font-family: var(--mono);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--accent);
  margin: 0 0 12px;
}

.hero-tagline {
  max-width: 640px;
  margin: 0 auto 22px;
}

.hero-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

/* ---------- PoP status grid ---------- */

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

.pop-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}

.pop-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.pop-name {
  font-weight: 700;
  font-size: 1.02rem;
}

.pop-loc {
  color: var(--muted);
  font-size: 0.85rem;
  margin-left: 6px;
}

.pop-summary {
  color: var(--muted);
  font-size: 0.82rem;
  word-break: break-word;
}

.pop-card .resource-metrics {
  margin-top: 10px;
}

/* ---------- admin edit pages ---------- */

/* Each action on an edit page is its own <form>; keep them on one wrapping row. */
.edit-actions form {
  margin: 0;
}

/* ---------- Kioubit auth button (centred on the login / telegram cards) ---------- */
/* The button lives in a closed shadow DOM and is display:flex, so text-align can't centre it. */
.center-card kioubit-auth-btn {
  display: flex;
  justify-content: center;
  margin-top: 14px;
}

/* ---------- responsive ---------- */

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

  .sidebar {
    position: static;
    flex-direction: row;
    flex-wrap: wrap;
    top: 0;
  }

  .sidebar-label {
    display: none;
  }

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

@media (max-width: 560px) {
  .topbar-inner {
    height: auto;
    flex-wrap: wrap;
    padding: 10px 0;
    gap: 10px;
  }

  .topnav {
    order: 3;
    flex-basis: 100%;
  }
}

