:root {
  color-scheme: light;
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-soft: #f8fbff;
  --line: #d8e1ec;
  --line-strong: #b9c8d8;
  --text: #16202b;
  --muted: #64748b;
  --accent: #2563eb;
  --accent-soft: #e8f0ff;
  --green: #16845b;
  --green-soft: #e6f6ef;
  --amber: #a76608;
  --amber-soft: #fff4d8;
  --red: #bf2e3a;
  --red-soft: #ffe8eb;
  --violet: #6d4ed8;
  --violet-soft: #f0edff;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  font: 14px/1.45 ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    linear-gradient(180deg, #eef5ff 0, #f4f7fb 220px),
    var(--bg);
  color: var(--text);
}

header {
  padding: 12px 20px;
  background: rgba(255, 255, 255, .94);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 10px 30px rgba(35, 55, 80, .08);
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 5;
  backdrop-filter: blur(12px);
}

header h1 {
  font-size: 16px;
  margin: 0;
  color: #0f172a;
  font-weight: 700;
}

header .spacer { flex: 1; }
.status { color: var(--muted); font-size: 12px; }

input, select, button, textarea {
  font: inherit;
  background: #fff;
  color: var(--text);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 7px 10px;
}

input:focus, select:focus, textarea:focus {
  outline: 3px solid rgba(37, 99, 235, .16);
  border-color: var(--accent);
}

button {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  cursor: pointer;
  font-weight: 650;
  box-shadow: 0 1px 2px rgba(15, 23, 42, .08);
}

button.secondary {
  background: #fff;
  border-color: var(--line-strong);
  color: #334155;
}

button.danger {
  background: var(--red-soft);
  border-color: #f0a7ae;
  color: var(--red);
  padding: 5px 8px;
}

button.warn {
  background: var(--amber-soft);
  border-color: #efc56e;
  color: #7a4a06;
}

button:disabled { cursor: not-allowed; opacity: .55; }

main {
  padding: 20px;
  max-width: 1320px;
  margin: 0 auto;
}

section {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 16px;
  overflow: hidden;
  box-shadow: 0 10px 26px rgba(30, 50, 80, .06);
}

section > h2 {
  font-size: 14px;
  margin: 0;
  padding: 12px 16px;
  background: var(--surface-soft);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 10px;
}

section > h2 .count {
  color: var(--muted);
  font-weight: 500;
  font-size: 12px;
}

.body {
  padding: 15px 16px;
  overflow-x: auto;
}

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

th, td {
  text-align: left;
  padding: 8px 8px;
  border-bottom: 1px solid #e7edf4;
  vertical-align: top;
}

th {
  color: #526579;
  font-weight: 700;
  background: #fbfdff;
}

tbody tr:hover { background: #f8fbff; }

.mono {
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 12px;
  color: #3f5368;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }

.section-note {
  margin: 0 0 12px;
  color: #4b6076;
  max-width: 980px;
}

.form {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 10px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px dashed var(--line-strong);
  align-items: end;
}

.form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: #516276;
  font-weight: 650;
}

.checkline {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 35px;
  color: #516276;
}

.checkline input {
  width: auto;
}

.form .full { grid-column: 1 / -1; }
.form .actions {
  grid-column: 1 / -1;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.obf {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 8px;
  padding: 12px;
  background: #fbfdff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.obf > .obftitle {
  grid-column: 1/-1;
  font-size: 12px;
  color: #516276;
  font-weight: 700;
  margin-bottom: -2px;
}

.nodes {
  grid-column: 1/-1;
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  padding: 10px 12px;
  background: #fbfdff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.nodes label {
  flex-direction: row;
  align-items: center;
  gap: 6px;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
}

.double-hop-fields {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
  padding: 12px;
  background: linear-gradient(180deg, #fbfdff, #f7fbff);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.double-hop-fields .obf {
  margin-top: 2px;
}

.double-hop-advanced {
  padding: 0;
  background: #fbfdff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.double-hop-advanced summary {
  cursor: pointer;
  padding: 10px 12px;
  color: #516276;
  font-weight: 700;
}

.double-hop-advanced .double-hop-fields {
  border: 0;
  border-top: 1px solid var(--line);
  border-radius: 0 0 8px 8px;
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  background: var(--green-soft);
  color: var(--green);
  border: 1px solid #a8dbc2;
  margin-right: 4px;
}

.pill.off {
  background: var(--violet-soft);
  color: var(--violet);
  border-color: #c8bdf6;
}

.pill.warn {
  background: var(--amber-soft);
  color: var(--amber);
  border-color: #efc56e;
}

.pill.bad {
  background: var(--red-soft);
  color: var(--red);
  border-color: #f0a7ae;
}

.node-health {
  display: grid;
  gap: 4px;
  align-items: start;
}

.node-health-sub {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
}

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

.metric {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: linear-gradient(180deg, #ffffff, #f9fbff);
}

.metric .k {
  color: #516276;
  font-size: 12px;
  font-weight: 700;
}

.metric .v {
  font-size: 22px;
  line-height: 1.1;
  margin-top: 5px;
  color: #0f172a;
  font-weight: 750;
}

.metric .s {
  color: var(--muted);
  font-size: 12px;
  margin-top: 5px;
}

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

.notice {
  border: 1px solid var(--line);
  border-left-width: 4px;
  border-radius: 8px;
  padding: 11px 12px;
  background: #fff;
}

.notice.ok { border-left-color: var(--green); background: #fbfffd; }
.notice.info { border-left-color: var(--accent); background: #fbfdff; }
.notice.warn { border-left-color: #d1941f; background: #fffdf7; }
.notice.bad { border-left-color: var(--red); background: #fffafa; }

.notice-head {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.notice-head strong {
  color: #0f172a;
}

.notice-badge {
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 800;
  background: var(--accent-soft);
  color: var(--accent);
}

.notice.warn .notice-badge {
  background: var(--amber-soft);
  color: var(--amber);
}

.notice.bad .notice-badge {
  background: var(--red-soft);
  color: var(--red);
}

.notice.ok .notice-badge {
  background: var(--green-soft);
  color: var(--green);
}

.notice-text {
  color: #42576d;
  margin: 7px 0 0;
  max-width: 980px;
}

.notice-detail {
  margin-top: 8px;
  padding: 8px 10px;
  background: #f6f9fc;
  border: 1px solid #e4ebf3;
  border-radius: 6px;
}

.notice-action {
  margin-top: 8px;
  color: #213244;
  font-weight: 650;
}

.help-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 10px;
}

.user-links .form {
  margin-top: 4px;
}

.link-hints {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.help-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfdff;
}

.help-item h3 {
  margin: 0 0 6px;
  font-size: 13px;
}

.help-item p {
  margin: 0;
  color: #4b6076;
}

.err {
  color: var(--red);
  padding: 0 20px 12px;
  font-weight: 700;
}

.auth-panel {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 12px;
}

.auth-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, #fff, #f9fbff);
  padding: 14px;
}

.auth-card h3 {
  margin: 0 0 8px;
  font-size: 15px;
}

.auth-card p {
  margin: 0 0 12px;
  color: #4b6076;
}

.auth-card label {
  display: grid;
  gap: 5px;
  color: #516276;
  font-size: 12px;
  font-weight: 650;
  margin-bottom: 10px;
}

.auth-actions {
  display: flex;
  justify-content: flex-start;
  gap: 8px;
  flex-wrap: wrap;
}

.auth-reset summary {
  cursor: pointer;
  font-weight: 750;
  color: #334155;
}

.auth-reset > .auth-card {
  margin-top: 12px;
  padding: 0;
  border: 0;
  background: transparent;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .42);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 20;
  padding: 16px;
}

.overlay.open { display: flex; }

.overlay .card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  width: min(760px, 92vw);
  box-shadow: 0 30px 80px rgba(15, 23, 42, .22);
}

.overlay textarea {
  width: 100%;
  height: min(62vh, 620px);
}

.overlay .card h3 {
  margin: 0 0 8px;
  font-size: 14px;
}

.overlay-actions {
  margin-top: 10px;
  text-align: right;
}

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

.overlay .overlay-actions .spacer { flex: 1; }

.deploy-log {
  width: 100%;
  height: min(62vh, 620px);
  margin: 0;
  overflow: auto;
  background: #0f172a;
  color: #e2e8f0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.45;
  padding: 12px;
  border-radius: 8px;
  white-space: pre-wrap;
  word-break: break-word;
}

#deploy-status.ok { color: #34d399; }
#deploy-status.fail { color: #f87171; }

@media (max-width: 720px) {
  main { padding: 12px; }
  header { padding: 10px 12px; }
  header input { width: min(100%, 220px); }
  table { min-width: 720px; font-size: 12px; }
  th, td { padding: 7px 6px; }
  .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric .v { font-size: 19px; }
}
