:root {
  --bg: #0b0d12;
  --surface: #141820;
  --surface-2: #1c2230;
  --text: #eef2f8;
  --muted: #7d8aa5;
  --accent: #5b8def;
  --accent-hover: #4a7de0;
  --ok: #34d399;
  --warn: #fbbf24;
  --err: #f87171;
  --border: rgba(255, 255, 255, 0.07);
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  background:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(91, 141, 239, 0.18), transparent),
    var(--bg);
  color: var(--text);
  line-height: 1.45;
}

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

.center {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.shell {
  width: min(720px, 100%);
  margin: 0 auto;
  padding: 20px 16px 32px;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
}

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

.logo {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  background: linear-gradient(135deg, #5b8def, #3b5bdb);
  display: grid;
  place-items: center;
  font-size: 16px;
  box-shadow: 0 4px 14px rgba(91, 141, 239, 0.35);
}

.brand h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.brand p {
  margin: 1px 0 0;
  font-size: 12px;
  color: var(--muted);
}

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

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.login-card {
  width: min(360px, 100%);
  padding: 28px 24px;
}

.login-card h1 {
  margin: 0 0 4px;
  font-size: 1.25rem;
}

.toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.toolbar input {
  flex: 1;
  min-width: 0;
}

input {
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}

input:focus {
  border-color: rgba(91, 141, 239, 0.55);
}

label {
  display: grid;
  gap: 6px;
  margin: 16px 0;
  font-size: 13px;
  color: var(--muted);
}

button, .btn {
  border: 0;
  border-radius: 8px;
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, opacity 0.15s;
}

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

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

.btn-ghost {
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--border);
}

.btn-ghost:hover { color: var(--text); }

.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--border);
  font-size: 15px;
}

.btn-icon:hover { color: var(--text); background: #252d3d; }

.btn-danger {
  background: transparent;
  color: var(--err);
  border: 1px solid rgba(248, 113, 113, 0.25);
  padding: 6px 10px;
  font-size: 12px;
}

.btn-danger:hover { background: rgba(248, 113, 113, 0.1); }

.flash {
  padding: 10px 12px;
  border-radius: 8px;
  margin-bottom: 12px;
  font-size: 13px;
}

.flash.ok {
  background: rgba(52, 211, 153, 0.12);
  border: 1px solid rgba(52, 211, 153, 0.25);
  color: #6ee7b7;
}

.flash.error {
  background: rgba(248, 113, 113, 0.1);
  border: 1px solid rgba(248, 113, 113, 0.25);
  color: #fca5a5;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.count {
  background: var(--surface-2);
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
}

.client-list {
  list-style: none;
  margin: 0;
  padding: 6px;
}

.client {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px 12px;
  padding: 10px 12px;
  border-radius: 8px;
  transition: background 0.12s;
}

.client:hover { background: var(--surface-2); }

.client-main {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--muted);
}

.status-dot.active {
  background: var(--ok);
  box-shadow: 0 0 8px rgba(52, 211, 153, 0.6);
}

.status-dot.no_handshake { background: var(--warn); }

.client-info { min-width: 0; }

.client-name {
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.client-name-row {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}

.client-name-row .btn-rename {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s;
}

.client:hover .client-name-row .btn-rename,
.client-name-row.is-editing .btn-rename {
  opacity: 1;
  pointer-events: auto;
}

.client-name-row.is-editing .client-name,
.client-name-row.is-editing .btn-rename {
  display: none;
}

.rename-form[hidden] {
  display: none !important;
}

.rename-form:not([hidden]) {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
  min-width: 0;
}

.rename-form input {
  flex: 1;
  min-width: 0;
  padding: 4px 8px;
  font-size: 13px;
}

.btn-tiny {
  width: 26px;
  height: 26px;
  font-size: 12px;
  flex-shrink: 0;
}

.client-meta {
  font-size: 12px;
  color: var(--muted);
  margin-top: 1px;
}

.client-meta code {
  font-size: 11px;
  background: rgba(255, 255, 255, 0.05);
  padding: 1px 5px;
  border-radius: 4px;
  color: #a8b4cc;
}

.client-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.empty {
  padding: 32px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

.modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  place-items: center;
  padding: 20px;
}

.modal.open { display: grid; }

.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  text-align: center;
  box-shadow: var(--shadow);
  max-width: min(420px, 92vw);
  width: 100%;
}

.modal-box h3 {
  margin: 0 0 18px;
  font-size: 17px;
}

.modal-box img {
  width: min(340px, 78vw);
  height: min(340px, 78vw);
  background: #fff;
  border-radius: 10px;
  padding: 12px;
  image-rendering: pixelated;
}

.modal-close {
  margin-top: 14px;
  width: 100%;
}

@media (max-width: 520px) {
  .client {
    grid-template-columns: 1fr;
  }
  .client-actions { justify-content: flex-end; }
}
