:root {
  --ink: #17201d;
  --muted: #66736e;
  --paper: #f5f7f4;
  --card: #ffffff;
  --line: #dce3df;
  --green: #17694d;
  --green-dark: #0c4f38;
  --green-soft: #e4f3ec;
  --amber: #9b6113;
  --amber-soft: #fff2d8;
  --red: #a53f3f;
  --red-soft: #fbeaea;
  --shadow: 0 16px 45px rgba(19, 44, 35, .08);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--paper);
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--paper); }
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; text-decoration: none; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid rgba(220, 227, 223, .9);
  background: rgba(255, 255, 255, .9);
  backdrop-filter: blur(18px);
}
.topbar-inner {
  width: min(1120px, calc(100% - 40px));
  height: 72px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand, .admin-area { display: flex; align-items: center; gap: 12px; }
.brand strong { display: block; font-size: 15px; letter-spacing: .02em; }
.brand small { display: block; margin-top: 2px; color: var(--muted); font-size: 10px; letter-spacing: .12em; text-transform: uppercase; }
.brand-mini, .brand-mark {
  display: grid;
  place-items: center;
  color: white;
  background: var(--green-dark);
  border-radius: 12px;
  font-family: Georgia, serif;
  font-weight: 700;
}
.brand-mini { width: 38px; height: 38px; }
.admin-area { color: var(--muted); font-size: 14px; }
.admin-area form { margin: 0; }

.container { width: min(1120px, calc(100% - 40px)); margin: 0 auto; padding: 46px 0 32px; }
.hero { display: flex; justify-content: space-between; align-items: flex-end; gap: 32px; margin-bottom: 30px; }
.hero h1 { margin: 4px 0 8px; font-family: Georgia, "Songti SC", serif; font-size: clamp(34px, 6vw, 54px); font-weight: 500; letter-spacing: -.04em; }
.hero p { margin: 0; color: var(--muted); }
.eyebrow { margin: 0; color: var(--green); font-size: 11px; font-weight: 800; letter-spacing: .18em; }
.service-status { flex: 0 0 auto; display: inline-flex; align-items: center; gap: 9px; padding: 10px 14px; border: 1px solid var(--line); border-radius: 999px; background: white; color: var(--muted); font-size: 13px; }
.service-status i { width: 9px; height: 9px; border-radius: 50%; background: currentColor; box-shadow: 0 0 0 4px rgba(23, 105, 77, .1); }
.status-good { color: var(--green); }
.status-bad { color: var(--red); }

.metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 20px; }
.metric { padding: 22px; border: 1px solid var(--line); border-radius: 18px; background: var(--card); }
.metric span, .metric small { display: block; color: var(--muted); font-size: 12px; }
.metric strong { display: block; margin: 9px 0 4px; font-family: Georgia, serif; font-size: 28px; font-weight: 500; }

.panel { border: 1px solid var(--line); border-radius: 22px; background: var(--card); box-shadow: var(--shadow); }
.add-panel { padding: 26px; margin-bottom: 42px; }
.section-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 30px; margin-bottom: 20px; }
.section-heading h2, .security-panel h2 { margin: 4px 0 0; font-family: Georgia, "Songti SC", serif; font-size: 25px; font-weight: 500; }
.section-heading > p, .security-panel p { max-width: 460px; margin: 0; color: var(--muted); font-size: 13px; line-height: 1.6; }
.add-form { display: grid; grid-template-columns: 1.25fr .8fr .9fr; gap: 14px; }
label > span, .link-block label { display: block; margin-bottom: 7px; color: var(--muted); font-size: 12px; font-weight: 650; }
input {
  width: 100%;
  height: 44px;
  border: 1px solid #ccd6d1;
  border-radius: 10px;
  padding: 0 12px;
  color: var(--ink);
  background: #fbfcfb;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(23, 105, 77, .12); }
select {
  width: 100%;
  height: 44px;
  border: 1px solid #ccd6d1;
  border-radius: 10px;
  padding: 0 12px;
  color: var(--ink);
  background: #fbfcfb;
  outline: none;
}
select:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(23, 105, 77, .12); }
.note-field { grid-column: span 2; }
.add-submit { align-self: end; }

.rules-panel { padding: 26px; margin-bottom: 42px; }
.rules-panel .section-heading h2 { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.rule-form { display: grid; grid-template-columns: 1.4fr .8fr auto; gap: 14px; align-items: end; }
.rules-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-top: 18px; color: var(--muted); font-size: 12px; }
.rules-toolbar form { margin: 0; }
.rule-list { display: grid; gap: 8px; margin: 16px 0 0; padding: 0; list-style: none; }
.rule-row { display: grid; grid-template-columns: 1fr auto auto; gap: 12px; align-items: center; min-height: 44px; padding: 7px 10px; border: 1px solid #edf0ee; border-radius: 10px; background: #fbfcfb; }
.rule-row form { margin: 0; }
.rule-target { display: inline-flex; align-items: center; min-height: 24px; padding: 0 9px; border-radius: 999px; font-size: 11px; font-weight: 750; }
.rule-direct { color: var(--green); background: var(--green-soft); }
.rule-proxy { color: #5d4b98; background: #eeeafd; }
.button-small { min-height: 32px; padding: 6px 10px; font-size: 12px; }
.rules-empty { padding: 16px 10px; color: var(--muted); font-size: 12px; }

.button {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 9px 14px;
  cursor: pointer;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 700;
  transition: transform .12s, background .12s, border-color .12s;
}
.button:hover { transform: translateY(-1px); }
.button:disabled, a.button[disabled] { opacity: .45; pointer-events: none; }
.button-primary { color: white; background: var(--green); }
.button-primary:hover { background: var(--green-dark); }
.button-quiet { border-color: var(--line); background: white; color: #44504b; }
.button-quiet:hover { border-color: #b4c0ba; background: #f8faf8; }
.button-warning { color: var(--amber); border-color: #efd8ab; background: var(--amber-soft); }
.button-danger { color: var(--red); border-color: #efcaca; background: var(--red-soft); }
.button-copy { color: white; background: var(--ink); }
.button-full { width: 100%; }

.members-section { margin-bottom: 42px; }
.user-list { display: grid; gap: 13px; }
.user-card { padding: 22px; border: 1px solid var(--line); border-radius: 18px; background: var(--card); }
.user-main { display: flex; align-items: center; gap: 13px; }
.avatar { flex: 0 0 auto; width: 43px; height: 43px; display: grid; place-items: center; border-radius: 50%; background: var(--green-soft); color: var(--green-dark); font-family: Georgia, serif; font-size: 18px; }
.user-identity { min-width: 0; }
.user-title { display: flex; align-items: center; gap: 10px; }
.user-title h3 { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 16px; }
.user-identity p { margin: 5px 0 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
code { padding: 1px 5px; border-radius: 5px; color: var(--green-dark); background: var(--green-soft); }
.pill { display: inline-flex; align-items: center; height: 23px; padding: 0 8px; border-radius: 999px; font-size: 11px; font-weight: 750; }
.pill-online { color: var(--green); background: var(--green-soft); }
.pill-warn { color: var(--amber); background: var(--amber-soft); }
.pill-off { color: var(--muted); background: #edf0ee; }
.usage-block { margin: 18px 0 16px; }
.usage-label { display: flex; justify-content: space-between; margin-bottom: 7px; color: var(--muted); font-size: 11px; }
.progress { display: block; width: 100%; height: 6px; overflow: hidden; border: 0; border-radius: 99px; background: #e9eeeb; appearance: none; }
.progress::-webkit-progress-bar { border-radius: 99px; background: #e9eeeb; }
.progress::-webkit-progress-value { border-radius: 99px; background: linear-gradient(90deg, var(--green), #3d9a72); }
.progress::-moz-progress-bar { border-radius: 99px; background: linear-gradient(90deg, var(--green), #3d9a72); }
.copy-row { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; }
.copy-row input { min-width: 0; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; }
.actions { margin-top: 14px; border-top: 1px solid #edf0ee; padding-top: 12px; }
.actions summary { width: fit-content; color: var(--muted); cursor: pointer; font-size: 12px; font-weight: 700; }
.action-grid { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.action-grid form { margin: 0; }
.empty-state { padding: 52px 20px; border: 1px dashed #bcc9c3; border-radius: 18px; text-align: center; color: var(--muted); background: rgba(255,255,255,.55); }
.empty-state h3 { margin: 12px 0 6px; color: var(--ink); }
.empty-state p { margin: 0; }
.empty-icon { width: 42px; height: 42px; margin: 0 auto; display: grid; place-items: center; border-radius: 50%; background: var(--green-soft); color: var(--green); font-size: 24px; }

.security-panel { display: grid; grid-template-columns: .8fr 1.2fr; gap: 35px; align-items: end; padding: 26px; }
.password-form { display: grid; grid-template-columns: repeat(3, 1fr) auto; gap: 10px; align-items: end; }
footer { display: flex; justify-content: space-between; padding: 24px 4px 0; color: #86908c; font-size: 11px; }
.alert { margin-bottom: 18px; padding: 13px 15px; border: 1px solid; border-radius: 12px; font-size: 13px; }
.alert-success { color: var(--green-dark); border-color: #bedbce; background: var(--green-soft); }
.alert-error { color: #7f2d2d; border-color: #efcaca; background: var(--red-soft); }

.login-page { background: #edf2ee; }
.login-page::before { content: ""; position: fixed; inset: 0; pointer-events: none; background: radial-gradient(circle at 20% 10%, rgba(77, 151, 116, .16), transparent 35%), radial-gradient(circle at 85% 90%, rgba(18, 78, 56, .12), transparent 38%); }
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { position: relative; width: min(430px, 100%); padding: 42px; border: 1px solid rgba(255,255,255,.85); border-radius: 26px; background: rgba(255,255,255,.9); box-shadow: 0 26px 80px rgba(20, 52, 40, .14); backdrop-filter: blur(16px); }
.brand-mark { width: 54px; height: 54px; margin-bottom: 28px; font-size: 24px; }
.login-card h1 { margin: 6px 0 9px; font-family: Georgia, "Songti SC", serif; font-size: 31px; font-weight: 500; }
.muted { color: var(--muted); line-height: 1.6; }
.stack { display: grid; gap: 16px; }
.login-form { margin-top: 26px; }
.login-foot { margin: 22px 0 0; color: #8b9691; text-align: center; font-size: 11px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 16px); opacity: 0; pointer-events: none; padding: 10px 15px; border-radius: 10px; color: white; background: var(--ink); box-shadow: var(--shadow); font-size: 13px; transition: opacity .18s, transform .18s; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 820px) {
  .metrics { grid-template-columns: 1fr; }
  .add-form { grid-template-columns: 1fr 1fr; }
  .note-field { grid-column: 1 / -1; }
  .add-submit { grid-column: 1 / -1; }
  .security-panel { grid-template-columns: 1fr; }
  .password-form { grid-template-columns: 1fr; }
  .rule-form { grid-template-columns: 1fr 1fr; }
  .rule-form button { grid-column: 1 / -1; }
}

@media (max-width: 560px) {
  .topbar-inner, .container { width: min(100% - 24px, 1120px); }
  .container { padding-top: 30px; }
  .topbar-inner { height: 64px; }
  .admin-area > span, .brand small { display: none; }
  .hero { align-items: flex-start; flex-direction: column; gap: 18px; }
  .hero h1 { font-size: 38px; }
  .section-heading { align-items: flex-start; flex-direction: column; gap: 8px; }
  .add-panel, .user-card, .security-panel, .rules-panel { padding: 18px; }
  .add-form { grid-template-columns: 1fr; }
  .note-field, .add-submit { grid-column: auto; }
  .rule-form { grid-template-columns: 1fr; }
  .rule-form button { grid-column: auto; }
  .rules-toolbar { align-items: flex-start; flex-direction: column; }
  .rules-toolbar .button { width: 100%; }
  .rule-row { grid-template-columns: 1fr auto; }
  .rule-row .rule-target { grid-column: 1; grid-row: 2; width: fit-content; }
  .rule-row form { grid-column: 2; grid-row: 1 / span 2; }
  .copy-row { grid-template-columns: 1fr 1fr; }
  .copy-row input { grid-column: 1 / -1; }
  .button-copy, .copy-row .button-quiet { width: 100%; }
  .login-card { padding: 30px 24px; }
  footer { flex-direction: column; gap: 7px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
