:root {
  --bg: #f3f5f8;
  --bg-elev: #ffffff;
  --bg-soft: #f6f8fb;
  --line: #e4e8ee;
  --text: #1c2430;
  --muted: #667085;
  --accent: #3b6fd8;
  --accent-dim: rgba(59, 111, 216, 0.12);
  --accent-text: #2b57b0;
  --warn-bg: #fff7ea;
  --warn-text: #8a5a12;
  --ok-bg: #e8f7ee;
  --ok-text: #18794a;
  --danger: #d14343;
  --danger-bg: #fdecec;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 8px 24px rgba(16, 24, 40, 0.05);
  --font: "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  --mono: "Cascadia Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; width: 100%; min-height: 100%; }
body {
  min-height: 100vh;
  width: 100%;
  display: flex;
  flex-direction: column;
  font-family: var(--font);
  background: #e8edf3;
  color: var(--text);
  line-height: 1.45;
}

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(12px);
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 20px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none !important;
  color: var(--text);
  font-weight: 700;
  letter-spacing: 0.02em;
}
.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: #3b6fd8;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
}
.brand-text { font-size: 15px; }
.nav {
  display: flex;
  gap: 4px;
  flex: 1;
}
.nav a {
  color: var(--muted);
  text-decoration: none !important;
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
}
.nav a:hover { color: var(--text); background: var(--bg-soft); }
.nav a.active {
  color: var(--accent-text);
  background: var(--accent-dim);
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}
.admin-chip {
  font-size: 12px;
  color: var(--muted);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  padding: 5px 10px;
  border-radius: 999px;
}

.wrap {
  width: 100%;
  max-width: none;
  margin: 0;
  flex: 1;
  padding: 16px 16px 32px;
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.page-head h1 {
  margin: 0 0 6px;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.page-head .hint {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  max-width: 720px;
}

.panel {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 18px;
  overflow: hidden;
}
.panel-hd {
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.panel-hd h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.panel-bd { padding: 18px; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
  align-items: end;
}
.form-grid .span-2 { grid-column: span 2; }
.form-grid .span-3 { grid-column: span 3; }
.field label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
  font-weight: 500;
}
.field input,
.field select,
input, select, textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  outline: none;
}
.field input:focus,
.field select:focus,
input:focus, select:focus {
  border-color: rgba(59, 111, 216, 0.45);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 14px;
  border-radius: 10px;
  border: 0;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  text-decoration: none !important;
  white-space: nowrap;
}
.btn:hover { filter: brightness(1.06); }
.btn-sm { padding: 7px 10px; font-size: 12px; }
.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
}
.btn-ghost:hover { color: var(--text); background: var(--bg-soft); }
.btn-soft {
  background: var(--bg-soft);
  color: var(--text);
  border: 1px solid var(--line);
}
.btn-danger {
  background: var(--danger-bg);
  color: #b42323;
  border: 1px solid #f3c2c2;
}
.btn-danger:hover { background: #f8d4d4; }
.btn[disabled], button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.alert {
  padding: 12px 14px;
  border-radius: 12px;
  margin-bottom: 16px;
  font-size: 14px;
}
.alert-warn { background: var(--warn-bg); color: var(--warn-text); border: 1px solid #f0d7b0; }
.alert-ok { background: var(--ok-bg); color: var(--ok-text); border: 1px solid #b7e4c8; }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  width: 100%;
  margin-bottom: 18px;
}
.stat {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 18px 16px;
  box-shadow: var(--shadow);
}
.stat .label { color: var(--muted); font-size: 12px; font-weight: 500; margin-bottom: 8px; }
.stat .n {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}
.stat .sub { margin-top: 6px; color: var(--muted); font-size: 12px; }

.table-wrap { overflow-x: auto; }
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 16px;
}
table.data th {
  text-align: left;
  padding: 14px 16px;
  color: var(--muted);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.02em;
  border-bottom: 1px solid var(--line);
  background: #f7f9fc;
  white-space: nowrap;
}
table.data td {
  padding: 16px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
table.data tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover td { background: #f7f9fc; }
table.data .tag,
table.data .btn-sm,
table.data .muted {
  font-size: 14px;
}

.mono { font-family: var(--mono); font-size: 12px; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }

.tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.tag-shared { background: rgba(59, 111, 216, 0.12); color: #2b57b0; }
.tag-priv { background: rgba(180, 110, 20, 0.14); color: #9a5b12; }
.tag-ok { background: rgba(21, 122, 69, 0.12); color: #157a45; }
.tag-off { background: rgba(93, 107, 128, 0.12); color: #5d6b80; }
.tag-dead { background: rgba(209, 67, 67, 0.12); color: #b42323; }

.bar {
  height: 6px;
  background: var(--bg);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 8px;
  border: 1px solid var(--line);
}
.bar > i {
  display: block;
  height: 100%;
  background: #3b6fd8;
  border-radius: 999px;
}

.ops {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
form.inline { display: inline; margin: 0; }

.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}
.dot.on { background: #34d399; box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.2); }
.dot.off { background: #64748b; }
.on { color: #157a45; }
.off { color: var(--muted); }

.key-cell {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 180px;
}
.key-mask { font-family: var(--mono); font-size: 12px; color: var(--text); }
.key-full {
  display: none;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  word-break: break-all;
}
.key-cell.open .key-full { display: block; }
.key-cell.open .key-mask { display: none; }

.mode-cell { min-width: 140px; }
.mode-cell .who { margin-top: 4px; font-size: 12px; color: var(--muted); }
.mode-cell details {
  margin-top: 8px;
}
.mode-cell summary {
  cursor: pointer;
  color: var(--accent-text);
  font-size: 12px;
  list-style: none;
  user-select: none;
}
.mode-cell summary::-webkit-details-marker { display: none; }
.mode-edit {
  margin-top: 10px;
  display: grid;
  gap: 8px;
  padding: 10px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.mode-edit .row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.mode-edit select { width: auto; min-width: 110px; }

.usage-cell { min-width: 160px; }
.usage-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
}
.usage-top .left { color: var(--muted); }

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 32px 28px;
  box-shadow: var(--shadow);
}
.login-card h1 {
  margin: 0 0 6px;
  font-size: 22px;
}
.login-card .sub {
  color: var(--muted);
  font-size: 13px;
  margin: 0 0 22px;
}
.login-card .field { margin-bottom: 14px; }
.login-card .btn { width: 100%; margin-top: 8px; padding: 12px; }

.foot-note {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

.search-form {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  gap: 8px;
  margin: 0 0 0 auto;
  flex: 0 0 auto;
}
.list-hd {
  flex-wrap: nowrap;
}
.list-hd-title {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex: 0 0 auto;
}
.list-hd-title h2 { text-transform: none; letter-spacing: 0; font-size: 16px; color: var(--text); }
.search-form input {
  width: 280px;
  min-width: 280px;
  max-width: 280px;
  flex: 0 0 280px;
  padding: 8px 12px;
}

@media (max-width: 960px) {
  .form-grid { grid-template-columns: 1fr 1fr; }
  .form-grid .span-2, .form-grid .span-3 { grid-column: span 2; }
  .nav { display: none; }
}
@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2, .form-grid .span-3 { grid-column: span 1; }
  .topbar-inner { padding: 10px 14px; }
  .wrap { padding: 18px 14px 40px; }
}

dialog.modal {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0;
  width: min(420px, calc(100vw - 32px));
  background: #fff;
  color: var(--text);
  box-shadow: 0 24px 64px rgba(16, 24, 40, 0.18);
}
dialog.modal::backdrop {
  background: rgba(16, 24, 40, 0.42);
}
.modal form {
  display: grid;
  gap: 12px;
  padding: 20px;
}
.modal h2 {
  margin: 0;
  font-size: 18px;
}
.modal .sub {
  margin: -4px 0 4px;
  color: var(--muted);
  font-size: 13px;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}
