:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --border: #e5e7eb;
  --text: #111827;
  --muted: #6b7280;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --danger: #ef4444;
  --danger-dark: #dc2626;
  --success: #059669;
  --sidebar-bg: #111827;
  --sidebar-text: #d1d5db;
  --sidebar-active: #1f2937;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

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

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

.hidden { display: none !important; }

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  border-radius: 6px;
  padding: 0.5rem 0.9rem;
  font-size: 0.85rem;
  font-weight: 500;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
}
button:hover { background: #f3f4f6; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

button.primary { background: var(--primary); color: white; border-color: var(--primary); }
button.primary:hover { background: var(--primary-dark); }
button.danger { background: var(--danger); color: white; border-color: var(--danger); }
button.danger:hover { background: var(--danger-dark); }
button.small { padding: 0.3rem 0.6rem; font-size: 0.75rem; }
button.icon { padding: 0.3rem 0.5rem; }

input, select, textarea {
  font-family: inherit;
  font-size: 0.875rem;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  width: 100%;
  background: white;
  color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }

label { font-size: 0.8rem; font-weight: 600; color: var(--muted); display: block; margin-bottom: 0.3rem; }
.field { margin-bottom: 0.9rem; }
.field small { color: var(--muted); display: block; margin-top: 0.25rem; }

/* ---- layout ---- */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 1.25rem 0.75rem;
}
.sidebar .brand {
  font-weight: 700;
  font-size: 1.05rem;
  color: white;
  padding: 0 0.5rem 1.25rem;
}
.sidebar .brand span { color: var(--primary); }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidebar nav button {
  background: transparent;
  border: none;
  color: var(--sidebar-text);
  text-align: left;
  padding: 0.6rem 0.75rem;
  border-radius: 6px;
  font-size: 0.875rem;
}
.sidebar nav button:hover { background: #1f2937; color: white; }
.sidebar nav button.active { background: var(--sidebar-active); color: white; font-weight: 600; }
.sidebar .footer { font-size: 0.75rem; color: #6b7280; padding: 0.5rem; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 1.15rem; margin: 0; }
.topbar .actions { display: flex; gap: 0.5rem; align-items: center; }

.content { padding: 1.5rem; flex: 1; overflow-x: auto; }

.view { display: none; }
.view.active { display: block; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}
.card h2 { margin: 0 0 1rem; font-size: 1rem; }
.card .card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.card .card-header h2 { margin: 0; }

.toast-container { position: fixed; top: 1rem; right: 1rem; z-index: 200; display: flex; flex-direction: column; gap: 0.5rem; }
.toast {
  background: #111827; color: white; padding: 0.6rem 1rem; border-radius: 8px;
  font-size: 0.85rem; box-shadow: 0 4px 12px rgba(0,0,0,0.15); max-width: 320px;
}
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }

/* ---- table ---- */
table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
th, td { text-align: left; padding: 0.6rem 0.6rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.03em; }
tr:last-child td { border-bottom: none; }
td.actions-cell { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.empty-row td { color: var(--muted); text-align: center; padding: 2rem; }

.mono { font-family: var(--mono); font-size: 0.8rem; }
.pubkey {
  display: inline-flex; align-items: center; gap: 0.35rem;
  background: #f3f4f6; padding: 0.2rem 0.5rem; border-radius: 6px;
  font-family: var(--mono); font-size: 0.75rem; max-width: 160px;
}
.pubkey span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pubkey button { border: none; background: none; padding: 0 0.15rem; font-size: 0.8rem; }

.pubkey.key-reveal { max-width: none; width: 100%; }
.pubkey.key-reveal span { white-space: normal; word-break: break-all; user-select: all; }

.badge {
  display: inline-block; padding: 0.15rem 0.5rem; border-radius: 999px;
  font-size: 0.7rem; font-weight: 600; background: #eef2ff; color: var(--primary);
}
.badge.gray { background: #f3f4f6; color: var(--muted); }

/* ---- server cards ---- */
.server-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }
.server-card { border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; background: var(--panel); }
.server-card h3 { margin: 0 0 0.5rem; font-size: 0.95rem; display: flex; align-items: center; gap: 0.5rem; }
.server-card dl { margin: 0; font-size: 0.8rem; }
.server-card dt { color: var(--muted); margin-top: 0.4rem; }
.server-card dd { margin: 0; font-family: var(--mono); word-break: break-all; }

/* ---- modal ---- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(17,24,39,0.5);
  display: flex; align-items: center; justify-content: center; z-index: 100; padding: 1rem;
}
.modal {
  background: var(--panel); border-radius: var(--radius); padding: 1.5rem;
  width: 100%; max-width: 420px; max-height: 90vh; overflow-y: auto;
  box-shadow: 0 20px 40px rgba(0,0,0,0.2);
}
.modal h2 { margin: 0 0 1rem; font-size: 1.05rem; }
.modal .modal-footer { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 1.25rem; }
.modal.qrcode { text-align: center; }
.modal.qrcode img { width: 220px; height: 220px; margin: 0.5rem auto; display: block; }
.modal .close-x {
  float: right; background: none; border: none; font-size: 1.2rem; color: var(--muted); padding: 0;
}

.nat-list { list-style: none; margin: 0.5rem 0; padding: 0; font-size: 0.8rem; }
.nat-list li { display: flex; justify-content: space-between; align-items: center; padding: 0.4rem 0; border-bottom: 1px solid var(--border); }
.nat-list li:last-child { border-bottom: none; }

/* ---- login ---- */
.login-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg);
}
.login-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 2rem; width: 100%; max-width: 380px; text-align: center;
  box-shadow: 0 10px 30px rgba(0,0,0,0.06);
}
.login-card h1 { margin: 0 0 0.25rem; font-size: 1.25rem; }
.login-card p { color: var(--muted); font-size: 0.875rem; margin-top: 0; margin-bottom: 1.5rem; }
.login-card .field { text-align: left; }
.login-card button { width: 100%; }
.login-status { margin-top: 1rem; font-size: 0.85rem; color: var(--success); }
.login-error { margin-top: 1rem; font-size: 0.85rem; color: var(--danger); }

.spinner { color: var(--muted); font-size: 0.85rem; padding: 1rem 0; }
