:root {
  color-scheme: dark;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  --bg: #070b14;
  --surface: #0f172a;
  --surface-raised: #151f34;
  --line: #27344c;
  --line-soft: rgba(148, 163, 184, 0.16);
  --text: #f8fafc;
  --muted: #94a3b8;
  --accent: #20a8ff;
  --accent-strong: #1688dd;
  --success: #2dd4bf;
  --danger: #fb7185;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.38);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at 15% 0%, rgba(32, 168, 255, 0.13), transparent 30rem),
    radial-gradient(circle at 90% 20%, rgba(45, 212, 191, 0.08), transparent 28rem),
    var(--bg);
}

button, input, select { font: inherit; }
button { color: inherit; }

input, select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.7rem 0.85rem;
  color: var(--text);
  background: #0b1220;
  outline: none;
  transition: border-color 140ms ease, box-shadow 140ms ease, background 140ms ease;
}

input:focus, select:focus {
  border-color: var(--accent);
  background: #0d1728;
  box-shadow: 0 0 0 3px rgba(32, 168, 255, 0.16);
}

button:focus-visible, .key-select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.app-shell { min-height: 100vh; }
.panel {
  border: 1px solid var(--line-soft);
  border-radius: 16px;
  background: rgba(15, 23, 42, 0.92);
  box-shadow: var(--shadow);
}

.eyebrow {
  margin: 0 0 0.35rem;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.14em;
}

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(1.35rem, 2vw, 1.9rem); }
h2 { margin-bottom: 0; font-size: 1.12rem; }
.muted { color: var(--muted); }

.brand-mark {
  display: grid;
  place-items: center;
  width: 66px;
  height: 66px;
  flex: 0 0 auto;
  border: 1px solid rgba(32, 168, 255, 0.4);
  border-radius: 18px;
  color: var(--accent);
  background: linear-gradient(145deg, rgba(32, 168, 255, 0.18), rgba(45, 212, 191, 0.08));
  font-size: 2.5rem;
  box-shadow: inset 0 0 24px rgba(32, 168, 255, 0.12);
}

.brand-mark.compact { width: 46px; height: 46px; border-radius: 13px; font-size: 1.8rem; }

.login-layout {
  width: min(1060px, calc(100% - 2rem));
  min-height: 100vh;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1.25fr minmax(320px, 420px);
  align-items: center;
  gap: clamp(2rem, 8vw, 8rem);
}

.brand-block { display: flex; align-items: center; gap: 1.25rem; }
.brand-block .muted { max-width: 34rem; margin: 0.8rem 0 0; line-height: 1.75; }
.login-card { display: grid; gap: 1rem; padding: 2rem; }
.login-card label, .field label, .search-label { color: #cbd5e1; font-size: 0.84rem; font-weight: 650; }

.button {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 0.58rem 1rem;
  cursor: pointer;
  font-weight: 700;
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease;
}
.button:hover { transform: translateY(-1px); }
.button:active { transform: translateY(0); }
.button.primary { color: #04111c; background: linear-gradient(135deg, #54c2ff, var(--accent)); }
.button.primary:hover { background: linear-gradient(135deg, #7ad0ff, #29b3ff); }
.button.ghost { border-color: var(--line); color: #cbd5e1; background: rgba(15, 23, 42, 0.7); }
.button.danger-button { border-color: rgba(251, 113, 133, 0.45); color: #fff1f2; background: rgba(190, 24, 93, 0.35); }
.compact-button { min-height: 36px; padding: 0.42rem 0.8rem; }

.form-message { min-height: 1.2rem; margin: 0; color: var(--success); font-size: 0.86rem; }
.form-message.error { color: var(--danger); }

.dashboard { width: min(1500px, calc(100% - 2rem)); margin: 0 auto; padding-bottom: 3rem; }
.topbar {
  min-height: 84px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 1px solid var(--line-soft);
}
.topbar-brand, .topbar-actions { display: flex; align-items: center; gap: 0.9rem; }
.live-pill, .version-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  border: 1px solid rgba(45, 212, 191, 0.26);
  border-radius: 999px;
  padding: 0.4rem 0.7rem;
  color: #99f6e4;
  background: rgba(20, 184, 166, 0.08);
  font-size: 0.75rem;
}
.live-pill span { width: 7px; height: 7px; border-radius: 50%; background: var(--success); box-shadow: 0 0 0 5px rgba(45, 212, 191, 0.1); }

.one-time-key {
  margin: 1.25rem 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  border: 1px solid rgba(32, 168, 255, 0.38);
  border-radius: 14px;
  padding: 1.1rem 1.25rem;
  background: linear-gradient(90deg, rgba(32, 168, 255, 0.12), rgba(45, 212, 191, 0.06));
}
.one-time-key h2 { margin-bottom: 0.7rem; }
.one-time-key code { color: #bae6fd; word-break: break-all; }
.key-actions { display: flex; gap: 0.65rem; flex-wrap: wrap; }

.workspace { display: grid; grid-template-columns: minmax(290px, 360px) 1fr; gap: 1.25rem; margin-top: 1.25rem; align-items: start; }
.key-sidebar { position: sticky; top: 1rem; padding: 1.1rem; min-height: 560px; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.search-label { display: block; margin: 0 0 0.45rem; }
.status-line { min-height: 1.2rem; margin: 0.7rem 0; font-size: 0.8rem; }

.key-list { display: grid; gap: 0.65rem; margin: 0; padding: 0; list-style: none; }
.key-row { overflow: hidden; border: 1px solid var(--line-soft); border-radius: 11px; background: #0b1220; }
.key-row.selected { border-color: rgba(32, 168, 255, 0.65); box-shadow: 0 0 0 2px rgba(32, 168, 255, 0.08); }
.key-row.disabled { opacity: 0.64; }
.key-select { width: 100%; border: 0; padding: 0.85rem; text-align: left; color: inherit; background: transparent; cursor: pointer; }
.key-row-title, .key-row-meta { display: block; }
.key-row-title { font-weight: 750; }
.key-row-meta { margin-top: 0.35rem; color: var(--muted); font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 0.73rem; }
.row-actions { display: grid; grid-template-columns: repeat(4, 1fr); border-top: 1px solid var(--line-soft); }
.icon-button { border: 0; border-right: 1px solid var(--line-soft); padding: 0.48rem 0.2rem; color: #94a3b8; background: transparent; cursor: pointer; font-size: 0.73rem; }
.icon-button:last-child { border-right: 0; }
.icon-button:hover { color: var(--text); background: rgba(148, 163, 184, 0.08); }
.icon-button.danger:hover { color: #fecdd3; background: rgba(244, 63, 94, 0.1); }

.editor { padding: clamp(1rem, 2.3vw, 1.8rem); }
.editor-heading { padding-bottom: 1rem; border-bottom: 1px solid var(--line-soft); }
.version-pill { color: #bae6fd; border-color: rgba(32, 168, 255, 0.25); background: rgba(32, 168, 255, 0.08); }
fieldset { margin: 0; border: 0; border-bottom: 1px solid var(--line-soft); padding: 1.25rem 0; }
fieldset:last-of-type { border-bottom: 0; }
legend { padding: 0 0 0.9rem; color: #e2e8f0; font-weight: 800; }
.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.field-grid.single { grid-template-columns: minmax(0, 1fr); }
.metrics-grid { grid-template-columns: repeat(4, minmax(120px, 1fr)); }
.field { display: grid; align-content: start; gap: 0.48rem; }
.form-actions { display: flex; justify-content: flex-end; gap: 0.7rem; padding-top: 1rem; }

dialog { width: min(420px, calc(100% - 2rem)); border: 1px solid var(--line); border-radius: 15px; padding: 1.25rem; color: var(--text); background: var(--surface); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(2, 6, 23, 0.76); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 0.7rem; }
.toast { position: fixed; right: 1.25rem; bottom: 1.25rem; z-index: 20; max-width: min(360px, calc(100% - 2.5rem)); border: 1px solid var(--line); border-radius: 11px; padding: 0.8rem 1rem; color: var(--text); background: #111827; box-shadow: var(--shadow); }

@media (max-width: 900px) {
  .login-layout { grid-template-columns: 1fr; align-content: center; max-width: 560px; gap: 2rem; }
  .workspace { grid-template-columns: 1fr; }
  .key-sidebar { position: static; min-height: auto; }
  .metrics-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 600px) {
  .dashboard { width: min(100% - 1rem, 1500px); }
  .topbar { align-items: flex-start; padding: 0.8rem 0; }
  .topbar-actions { align-items: flex-end; flex-direction: column; }
  .live-pill { display: none; }
  .brand-mark.compact { display: none; }
  .one-time-key { align-items: stretch; flex-direction: column; }
  .field-grid, .metrics-grid { grid-template-columns: 1fr; }
  .form-actions, .key-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .row-actions { grid-template-columns: repeat(2, 1fr); }
  .icon-button:nth-child(2) { border-right: 0; }
  .icon-button:nth-child(-n + 2) { border-bottom: 1px solid var(--line-soft); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}
