:root {
  --bg: #0e1116;
  --surface: #161b22;
  --surface-2: #1c2430;
  --border: #262d38;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #4c8dff;
  --accent-dim: #1f3a63;
  --green: #3fb950;
  --amber: #d29922;
  --red: #f85149;
  --radius: 12px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f8fa; --surface: #ffffff; --surface-2: #f0f3f6; --border: #d8dee4;
    --text: #1f2328; --muted: #636c76; --accent: #0969da; --accent-dim: #ddebff;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }

/* --- login --- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 340px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 32px 28px; text-align: center;
  box-shadow: 0 24px 60px rgba(0,0,0,.35);
}
.login-logo { font-size: 34px; margin-bottom: 8px; }
.login-card h1 { font-size: 18px; margin: 0 0 20px; font-weight: 600; }
.login-card input { margin-bottom: 12px; }

/* --- layout --- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 20px; border-bottom: 1px solid var(--border); background: var(--surface);
  position: sticky; top: 0; z-index: 20;
}
.brand { font-weight: 640; display: flex; align-items: center; gap: 9px; letter-spacing: -.01em; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 3px rgba(63,185,80,.18); }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.host { color: var(--muted); font-size: 13px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
main { max-width: 940px; margin: 0 auto; padding: 22px 16px 80px; }

.tabs { display: flex; gap: 6px; margin-bottom: 18px; }
.tab {
  background: transparent; border: 1px solid transparent; color: var(--muted);
  padding: 9px 14px; border-radius: 10px; cursor: pointer; font-size: 14px; font-weight: 520;
  display: flex; align-items: center; gap: 8px; font-family: inherit;
}
.tab:hover { color: var(--text); background: var(--surface); }
.tab.active { color: var(--text); background: var(--surface); border-color: var(--border); }
.count {
  background: var(--surface-2); border-radius: 20px; padding: 1px 8px;
  font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums;
}

.panel-head { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.stats { color: var(--muted); font-size: 13px; }
.stats b { color: var(--text); font-weight: 600; }
.head-actions { display: flex; gap: 10px; align-items: center; margin-left: auto; }
.filter { display: flex; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 3px; }
.chip {
  border: 0; background: transparent; color: var(--muted); padding: 5px 11px;
  border-radius: 7px; cursor: pointer; font-size: 13px; font-family: inherit;
}
.chip.active { background: var(--surface-2); color: var(--text); }

/* --- key list --- */
.keys { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.key {
  display: flex; align-items: center; gap: 14px; padding: 13px 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  cursor: pointer; transition: border-color .12s, transform .12s;
}
.key:hover { border-color: var(--accent); }
.key.disabled { opacity: .5; }
.badge {
  width: 34px; height: 34px; flex: none; border-radius: 9px; display: grid; place-items: center;
  background: var(--surface-2); font-size: 15px;
}
.key-main { min-width: 0; flex: 1; }
.key-name { font-weight: 560; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.key-sub {
  color: var(--muted); font-size: 12.5px; margin-top: 2px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.state { font-size: 12px; padding: 4px 10px; border-radius: 20px; white-space: nowrap; flex: none; }
.state.free { background: rgba(63,185,80,.14); color: var(--green); }
.state.taken { background: rgba(210,153,34,.15); color: var(--amber); }
.state.off { background: rgba(248,81,73,.14); color: var(--red); }
.more {
  flex: none; width: 32px; height: 32px; border-radius: 8px; border: 1px solid transparent;
  background: transparent; color: var(--muted); cursor: pointer; font-size: 18px; line-height: 1;
  font-family: inherit;
}
.more:hover { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.empty { text-align: center; color: var(--muted); padding: 48px 0; }

/* --- buttons --- */
.btn {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  padding: 9px 16px; border-radius: 10px; cursor: pointer; font-size: 14px;
  font-weight: 520; font-family: inherit; transition: filter .12s;
}
.btn:hover { filter: brightness(1.15); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn.block { width: 100%; }

input[type=text], input[type=password] {
  width: 100%; padding: 10px 13px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font-size: 14px; font-family: inherit;
}
input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }

/* --- popover --- */
.popover {
  position: absolute; z-index: 60; min-width: 214px; padding: 5px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 11px;
  box-shadow: 0 16px 40px rgba(0,0,0,.4); display: flex; flex-direction: column;
}
.popover button {
  text-align: left; background: transparent; border: 0; color: var(--text);
  padding: 9px 11px; border-radius: 8px; cursor: pointer; font-size: 14px; font-family: inherit;
}
.popover button:hover { background: var(--surface-2); }
.popover button.danger { color: var(--red); }

/* --- modal --- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); backdrop-filter: blur(3px);
  display: grid; place-items: center; padding: 20px; z-index: 50;
}
.modal {
  position: relative; width: 100%; max-width: 430px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 16px; padding: 26px;
  box-shadow: 0 30px 70px rgba(0,0,0,.5); max-height: 88dvh; overflow-y: auto;
}
.modal-close {
  position: absolute; top: 14px; right: 14px; width: 30px; height: 30px; border-radius: 8px;
  border: 0; background: transparent; color: var(--muted); font-size: 22px; cursor: pointer;
  line-height: 1; font-family: inherit;
}
.modal-close:hover { background: var(--surface-2); color: var(--text); }
.modal-kind { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .07em; }
.modal h2 { margin: 4px 0 18px; font-size: 19px; font-weight: 620; }
.field { display: block; margin-bottom: 16px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field em { font-style: normal; opacity: .7; }
.hint { color: var(--muted); font-size: 12px; margin-top: 6px; display: block; }
.meta { margin: 0 0 18px; display: grid; grid-template-columns: auto 1fr; gap: 5px 14px; font-size: 13px; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; word-break: break-all; }
.modal-actions { display: flex; gap: 9px; flex-wrap: wrap; }
.modal-actions .btn { flex: 1; min-width: 110px; }
.qr-box { margin-top: 20px; text-align: center; }
.qr-box img { width: 236px; height: 236px; background: #fff; padding: 10px; border-radius: 12px; }
.error { color: var(--red); font-size: 13px; min-height: 18px; margin: 10px 0 0; }

/* --- toast --- */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
  padding: 11px 18px; border-radius: 11px; box-shadow: 0 12px 34px rgba(0,0,0,.45);
  z-index: 90; font-size: 14px;
}

@media (max-width: 560px) {
  .head-actions { width: 100%; }
  .head-actions .btn.primary { flex: 1; }
  .key-sub { display: none; }
  .host { display: none; }
}
