/* Nap - purple, dark first, no framework. */
:root {
  --accent: #8b5cf6;
  --accent-strong: #6d28d9;
  --accent-soft: rgba(139, 92, 246, 0.16);
  --accent-line: rgba(139, 92, 246, 0.38);

  --bg: #0c0716;
  --bg-2: #120c22;
  --surface: #171029;
  --surface-2: #1e1636;
  --line: rgba(160, 130, 235, 0.16);
  --line-strong: rgba(160, 130, 235, 0.32);

  --text: #ece8f8;
  --muted: #a294c4;
  --ok: #4ade80;
  --warn: #fbbf24;
  --bad: #f87171;

  --radius: 14px;
  --radius-sm: 9px;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Inter, sans-serif;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f7f5fc;
    --bg-2: #efeaf9;
    --surface: #ffffff;
    --surface-2: #f4f0fd;
    --line: rgba(109, 40, 217, 0.14);
    --line-strong: rgba(109, 40, 217, 0.28);
    --text: #1e1533;
    --muted: #6b5f88;
    --accent: #6d28d9;
    --accent-strong: #5b21b6;
    --accent-soft: rgba(109, 40, 217, 0.1);
    --ok: #16a34a;
    --warn: #b45309;
    --bad: #dc2626;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--sans);
  color: var(--text);
  background:
    radial-gradient(1100px 600px at 12% -10%, var(--accent-soft), transparent 60%),
    radial-gradient(900px 500px at 100% 0%, rgba(109, 40, 217, 0.14), transparent 55%),
    var(--bg);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; line-height: 1.25; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 2rem; }
h2 { font-size: 1.05rem; }
p { margin: 0; }
code, pre { font-family: var(--mono); }

.muted { color: var(--muted); }
.small { font-size: 0.82rem; }
.block { display: block; }
.spacer { flex: 1; }
.mono { font-family: var(--mono); font-size: 0.84rem; }
.wrap { overflow-wrap: anywhere; }
.error { color: var(--bad); font-size: 0.86rem; min-height: 0; }
.error:empty { display: none; }

/* ---------------------------------------------------------------- layout */
.appbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem clamp(0.9rem, 3vw, 1.6rem);
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: blur(14px);
  position: sticky;
  top: 0;
  z-index: 20;
}
.logo { width: 46px; height: auto; }
.brand { display: flex; flex-direction: column; line-height: 1.15; }
.brand strong { font-size: 1.05rem; letter-spacing: 0.01em; }

.layout {
  display: grid;
  grid-template-columns: 216px minmax(0, 1fr);
  gap: clamp(1rem, 3vw, 2rem);
  max-width: 1180px;
  margin: 0 auto;
  padding: clamp(1rem, 3vw, 2rem) clamp(0.9rem, 3vw, 1.6rem) 4rem;
}
.nav { display: flex; flex-direction: column; gap: 0.2rem; position: sticky; top: 5rem; align-self: start; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 0.7rem;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.92rem;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s, color 0.15s;
}
.nav-item:hover { background: var(--surface); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--text); box-shadow: inset 2px 0 0 var(--accent); }
.main { min-width: 0; }

@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; padding-top: 0.8rem; }
  .nav { flex-direction: row; overflow-x: auto; position: static; padding-bottom: 0.3rem; }
  .nav-item span { display: none; }
  .nav-item { padding: 0.55rem 0.8rem; }
  .appbar .pill { display: none; }
}

/* ----------------------------------------------------------------- cards */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem;
}
.card-head { display: flex; align-items: center; gap: 0.7rem; margin-bottom: 0.9rem; flex-wrap: wrap; }
.card-head h2 { margin-right: auto; }
.stack { display: flex; flex-direction: column; gap: 0.85rem; }
.stack.tight { gap: 0.4rem; }
.stack.lg { gap: 1.1rem; }
.row { display: flex; gap: 0.5rem; align-items: center; flex-wrap: nowrap; }
.row.wrap { flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.row.center { align-items: center; }

.grid.stats { display: grid; gap: 0.8rem; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.stat { display: flex; flex-direction: column; gap: 0.15rem; padding: 0.9rem 1rem; }
.stat-label { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); }
.stat-value { font-size: 1.3rem; }

.card.empty { text-align: center; display: flex; flex-direction: column; gap: 0.6rem; align-items: center; padding: 2rem 1rem; }

.notice {
  display: flex;
  gap: 0.9rem;
  align-items: center;
  padding: 0.9rem 1.1rem;
  border: 1px solid var(--accent-line);
  border-radius: var(--radius);
  background: var(--accent-soft);
}
.notice .icon { color: var(--accent); flex: 0 0 auto; }
.notice > div { flex: 1; min-width: 0; }
.notice .btn { flex: 0 0 auto; }

.danger-zone { border-color: color-mix(in srgb, var(--bad) 42%, transparent); }

/* --------------------------------------------------------------- buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.52rem 0.95rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 550;
  cursor: pointer;
  white-space: nowrap;
  transition: filter 0.15s, background 0.15s, border-color 0.15s;
}
.btn:hover { filter: brightness(1.12); }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: linear-gradient(180deg, var(--accent), var(--accent-strong));
  border-color: transparent;
  color: #fff;
  box-shadow: 0 6px 18px -8px var(--accent-strong);
}
.btn.ghost { background: transparent; }
.btn.danger { border-color: color-mix(in srgb, var(--bad) 55%, transparent); color: var(--bad); background: transparent; }
.btn.danger:not(.ghost) { background: color-mix(in srgb, var(--bad) 14%, transparent); }
.btn.small { padding: 0.34rem 0.65rem; font-size: 0.82rem; }
.btn.block { width: 100%; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  flex: 0 0 auto;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}
.icon-btn:hover { color: var(--text); background: var(--surface-2); }
.icon-btn.ok { color: var(--ok); }
.icon { display: inline-flex; width: 20px; height: 20px; }
.icon svg { width: 100%; height: 100%; stroke-linecap: round; stroke-linejoin: round; }

.choice {
  display: flex;
  flex-direction: column;
  gap: 0.12rem;
  align-items: flex-start;
  text-align: left;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font: inherit;
  cursor: pointer;
}
.choice.active { border-color: var(--accent); background: var(--accent-soft); }

/* ---------------------------------------------------------------- fields */
.field { display: flex; flex-direction: column; gap: 0.25rem; min-width: 0; }
.field-label, .form-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 600;
}
.field-body {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.45rem 0.45rem 0.45rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg-2);
  min-width: 0;
}
.field-body code { flex: 1; min-width: 0; }

.form-field { display: flex; flex-direction: column; gap: 0.3rem; }
.form-hint { font-size: 0.78rem; color: var(--muted); }
input[type="text"], input[type="password"], input:not([type]), textarea, select {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: var(--bg-2);
  color: var(--text);
  font: inherit;
  font-size: 0.92rem;
}
textarea { font-family: var(--mono); font-size: 0.82rem; resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
input[type="file"] { padding: 0.4rem; }
.check { display: flex; gap: 0.55rem; align-items: flex-start; cursor: pointer; font-size: 0.9rem; }
.check.small { font-size: 0.82rem; color: var(--muted); }
.check input { width: 16px; height: 16px; margin-top: 0.2rem; accent-color: var(--accent); flex: 0 0 auto; }

.keybox {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  padding: 0.75rem 0.9rem;
  border-radius: var(--radius-sm);
  border: 1px dashed var(--accent-line);
  background: var(--accent-soft);
}
.keybox.subtle { border-style: solid; border-color: var(--line); background: var(--bg-2); }

.pill { padding: 0.28rem 0.6rem; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.16rem 0.55rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  border: 1px solid var(--line-strong);
  color: var(--muted);
  white-space: nowrap;
}
.badge.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 45%, transparent); background: color-mix(in srgb, var(--ok) 12%, transparent); }
.badge.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 45%, transparent); background: color-mix(in srgb, var(--warn) 12%, transparent); }
.badge.bad { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 45%, transparent); background: color-mix(in srgb, var(--bad) 12%, transparent); }
.badge.accent { color: var(--accent); border-color: var(--accent-line); background: var(--accent-soft); }

/* --------------------------------------------------------------- subkeys */
.subkey-head { display: flex; align-items: flex-start; gap: 0.6rem; flex-wrap: wrap; margin-bottom: 0.6rem; }
.subkey-title { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; margin-right: auto; }
.subkey-body { margin-top: 0.6rem; }
.subkey-foot {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-top: 0.75rem;
  padding-top: 0.65rem;
  border-top: 1px solid var(--line);
}
.event-row {
  display: flex;
  gap: 0.7rem;
  align-items: center;
  flex-wrap: wrap;
  padding: 0.55rem 0.7rem;
  border-radius: var(--radius-sm);
  background: var(--bg-2);
  font-size: 0.88rem;
}
.event-row.dim { opacity: 0.62; }
.event-row > span:first-child { min-width: 150px; }

ul.plain { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.85rem; }
ul.plain li { color: var(--muted); }
li.rv { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }

details.raw summary { cursor: pointer; font-size: 0.85rem; color: var(--muted); }
details.raw pre {
  margin: 0.5rem 0 0;
  padding: 0.7rem;
  border-radius: var(--radius-sm);
  background: var(--bg-2);
  border: 1px solid var(--line);
  overflow: auto;
  max-height: 260px;
  font-size: 0.76rem;
}

/* ---------------------------------------------------------------- modals */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(6, 3, 14, 0.66);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 50;
  animation: fade 0.14s ease-out;
}
.modal {
  width: min(460px, 100%);
  max-height: 88vh;
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow: 0 30px 70px -25px rgba(0, 0, 0, 0.75);
  animation: rise 0.16s ease-out;
}
.modal.wide { width: min(560px, 100%); }
.modal-head { display: flex; align-items: center; gap: 0.6rem; padding: 1rem 1.1rem 0.5rem; }
.modal-head h2 { margin-right: auto; }
.modal-body { padding: 0.4rem 1.1rem 1.1rem; }

@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }

.qr-wrap { display: flex; justify-content: center; }
.qr { padding: 10px; background: #fff; border-radius: var(--radius-sm); line-height: 0; }

/* ---------------------------------------------------------------- welcome */
.welcome { max-width: 460px; margin: 0 auto; padding: clamp(2rem, 8vh, 5rem) 1.1rem 3rem; display: flex; flex-direction: column; gap: 1.4rem; }
.welcome-hero { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 0.4rem; }
.logo-xl { width: 156px; height: auto; margin-bottom: 0.4rem; }
.lead { color: var(--muted); }
.welcome-card { padding: 0.5rem 1.1rem 1.2rem; }
.fineprint { text-align: center; font-size: 0.76rem; color: var(--muted); }

.tabs { display: flex; gap: 0.15rem; border-bottom: 1px solid var(--line); margin-bottom: 1.1rem; overflow-x: auto; }
.tab {
  padding: 0.7rem 0.55rem;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.86rem;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.tab.active { color: var(--text); border-bottom-color: var(--accent); }

/* ------------------------------------------------------------------- log */
.log { display: flex; flex-direction: column; gap: 0.1rem; max-height: 62vh; overflow: auto; font-size: 0.82rem; }
.log-line { display: flex; gap: 0.7rem; padding: 0.3rem 0.45rem; border-radius: 6px; }
.log-line:nth-child(odd) { background: var(--bg-2); }
.log-time { color: var(--muted); font-family: var(--mono); font-size: 0.75rem; flex: 0 0 auto; }
.log-text { overflow-wrap: anywhere; }
.log-line.warn .log-text { color: var(--warn); }
.log-line.error .log-text { color: var(--bad); }
.log-line.ok .log-text { color: var(--ok); }

/* ----------------------------------------------------------------- misc */
.busy {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 1rem;
  padding: 0.55rem 0.9rem;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  border: 1px solid var(--accent-line);
  font-size: 0.86rem;
}
.spinner {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  border: 2px solid var(--accent-line);
  border-top-color: var(--accent);
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  transform: translate(-50%, 130%);
  padding: 0.6rem 1.1rem;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  box-shadow: 0 16px 40px -18px rgba(0, 0, 0, 0.8);
  font-size: 0.88rem;
  z-index: 80;
  transition: transform 0.22s ease-out, opacity 0.22s;
  opacity: 0;
  max-width: min(92vw, 460px);
  text-align: center;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }
.toast.error { border-color: color-mix(in srgb, var(--bad) 55%, transparent); color: var(--bad); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 99px; border: 3px solid transparent; background-clip: content-box; }

.gap { margin-top: 0.6rem; }
