:root {
  --bg: #f5f7f9;
  --panel: #ffffff;
  --ink: #17232d;
  --muted: #6b7b88;
  --line: #e3e9ee;
  --accent: #16856a;
  --accent-soft: #e7f5f0;
  --blue: #2878c8;
  --blue-soft: #e9f2fc;
  --amber: #b87910;
  --amber-soft: #fdf3dd;
  --red: #c0443f;
  --red-soft: #fdeceb;
  --shadow: 0 1px 2px rgba(20, 40, 55, .05), 0 8px 24px rgba(20, 40, 55, .06);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
}
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 12px; }
.error-text { color: var(--red); font-size: 13px; min-height: 20px; }

/* ---------- login ---------- */
.login-screen {
  min-height: 100vh; display: grid; place-items: center;
  background: radial-gradient(circle at 20% 15%, #e7f5f0, transparent 45%),
              radial-gradient(circle at 80% 85%, #e9f2fc, transparent 40%), var(--bg);
}
.login-card {
  width: 360px; padding: 36px; background: var(--panel); border-radius: 18px;
  box-shadow: var(--shadow); text-align: center;
}
.login-logo { font-size: 40px; }
.login-card h1 { margin: 12px 0 2px; font-size: 24px; }
.login-card p { margin: 0 0 22px; }
.login-card input {
  width: 100%; padding: 11px 13px; margin-bottom: 14px; border: 1px solid var(--line);
  border-radius: 10px; font-size: 14px; outline: none;
}
.login-card input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ---------- shell ---------- */
.topbar {
  height: 68px; padding: 0 28px; background: var(--panel); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; gap: 20px;
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 11px; background: var(--accent-soft);
  display: grid; place-items: center; font-size: 20px;
}
.brand-title { font-weight: 700; font-size: 17px; letter-spacing: .2px; }
.brand-sub { font-size: 11px; color: var(--muted); }
.topbar-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.server-time { color: var(--muted); font-size: 12px; margin-right: 4px; }
.toggle { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); cursor: pointer; }
.toggle input { accent-color: var(--accent); }

.btn {
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  padding: 8px 14px; border-radius: 9px; cursor: pointer; font-size: 13px;
  transition: all .15s ease; white-space: nowrap;
}
.btn:hover { border-color: #c4d0d8; background: #f9fbfc; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #107156; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--red); border-color: #f0c9c6; background: var(--red-soft); }
.btn.danger:hover { background: #fbdedc; }
.btn.icon { padding: 7px 10px; font-size: 15px; }
.btn.block { width: 100%; }
.btn.small { padding: 5px 9px; font-size: 12px; border-radius: 7px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.main { max-width: 1440px; margin: 0 auto; padding: 26px 28px 60px; }
.summary { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 16px 18px; box-shadow: var(--shadow);
}
.stat-label { font-size: 12px; color: var(--muted); }
.stat-value { font-size: 27px; font-weight: 700; margin-top: 4px; line-height: 1.2; }
.stat-value.warn { color: var(--amber); }
.stat-value.good { color: var(--accent); }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); }
.panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 18px 20px; border-bottom: 1px solid var(--line);
}
.panel-head h2 { margin: 0 0 2px; font-size: 16px; }
.filters { display: flex; gap: 8px; }
.filters input, .filters select {
  border: 1px solid var(--line); border-radius: 9px; padding: 7px 10px; font-size: 13px;
  background: #fff; outline: none;
}
.filters input { width: 230px; }
.filters input:focus, .filters select:focus { border-color: var(--accent); }

.site-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px; padding: 18px 20px 22px;
}
.site-card {
  border: 1px solid var(--line); border-radius: 13px; padding: 16px;
  background: linear-gradient(180deg, #fff, #fcfdfd); cursor: pointer;
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.site-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: #c9d7dd; }
.card-top { display: flex; justify-content: space-between; align-items: flex-start; }
.card-port { font-size: 22px; font-weight: 700; letter-spacing: -.5px; }
.card-path { font-size: 11px; color: var(--muted); margin-top: 2px; }
.card-rows { margin-top: 14px; display: grid; gap: 7px; }
.card-row { display: flex; justify-content: space-between; gap: 10px; font-size: 12px; }
.card-row .k { color: var(--muted); }
.card-row .v { font-weight: 600; text-align: right; }
.card-note {
  margin-top: 12px; padding: 8px 10px; background: #f7f9fa; border-radius: 8px;
  font-size: 12px; color: #52636f; min-height: 30px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 8px;
  border-radius: 20px; font-size: 11px; font-weight: 600;
}
.badge.running { background: var(--accent-soft); color: var(--accent); }
.badge.stopped { background: #eef1f4; color: #667784; }
.badge.missing { background: var(--red-soft); color: var(--red); }
.badge.active { background: var(--blue-soft); color: var(--blue); }
.badge.soon { background: var(--amber-soft); color: var(--amber); }
.badge.expired { background: var(--red-soft); color: var(--red); }
.badge.unknown { background: #eef1f4; color: #667784; }
.dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.empty { padding: 48px 20px; text-align: center; color: var(--muted); }

/* ---------- drawer ---------- */
.backdrop { position: fixed; inset: 0; background: rgba(18, 32, 42, .35); z-index: 30; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(860px, 96vw);
  background: var(--bg); z-index: 31; display: flex; flex-direction: column;
  box-shadow: -12px 0 36px rgba(20, 40, 55, .14); animation: slide .18s ease;
}
@keyframes slide { from { transform: translateX(24px); opacity: .6; } to { transform: none; opacity: 1; } }
.drawer-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 18px 22px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.drawer-title { font-size: 18px; font-weight: 700; }
.drawer-body { overflow-y: auto; padding: 20px 22px 50px; }
.section { background: var(--panel); border: 1px solid var(--line); border-radius: 13px; padding: 18px; margin-bottom: 16px; }
.section h3 { margin: 0 0 14px; font-size: 14px; }
.section h3 small { font-weight: 400; color: var(--muted); margin-left: 8px; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 10px 14px; font-size: 13px; align-items: center; }
.kv .k { color: var(--muted); }
.kv .v { word-break: break-all; }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }
.secret { filter: blur(5px); user-select: none; }
.secret.revealed { filter: none; user-select: text; }
.copy-btn { margin-left: 6px; }
.form-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px;
  font-size: 13px; outline: none; background: #fff; color: var(--ink);
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field textarea { min-height: 74px; resize: vertical; }
.computed {
  margin-top: 14px; padding: 12px 14px; background: var(--accent-soft);
  border-radius: 10px; display: flex; flex-wrap: wrap; gap: 18px; font-size: 13px;
}
.computed b { font-size: 15px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.danger-zone { border-color: #f0d3d1; }
.account-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.account-table th, .account-table td { padding: 9px 8px; text-align: left; border-bottom: 1px solid var(--line); }
.account-table th { color: var(--muted); font-weight: 600; white-space: nowrap; }
.account-table tr:last-child td { border-bottom: 0; }
.account-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.account-name { display: flex; align-items: center; gap: 8px; }
.avatar { width: 26px; height: 26px; border-radius: 50%; object-fit: cover; background: #eef1f4; }
.avatar-fallback {
  width: 26px; height: 26px; border-radius: 50%; background: var(--blue-soft);
  color: var(--blue); display: grid; place-items: center; font-size: 11px; font-weight: 700;
}
.note-input { width: 100%; min-width: 90px; border: 1px dashed var(--line); border-radius: 6px; padding: 4px 6px; font-size: 12px; }
.note-input:focus { border-style: solid; border-color: var(--accent); outline: none; }
.tag { font-size: 10px; padding: 1px 5px; border-radius: 5px; background: #eef1f4; color: #667784; }
.tag.wx { background: var(--accent-soft); color: var(--accent); }
.tag.qq { background: var(--blue-soft); color: var(--blue); }

/* ---------- modal / busy / toast ---------- */
.modal {
  position: fixed; z-index: 41; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: min(460px, 94vw); background: var(--panel); border-radius: 15px;
  box-shadow: 0 20px 60px rgba(15, 30, 40, .24);
}
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 15px; }
.modal-body { padding: 18px; font-size: 13px; }
.modal-body p { margin: 0 0 12px; color: var(--muted); }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 18px; border-top: 1px solid var(--line); }
.toast-wrap { position: fixed; right: 22px; bottom: 22px; z-index: 60; display: grid; gap: 8px; }
.toast {
  background: #1f303b; color: #fff; padding: 10px 14px; border-radius: 9px;
  font-size: 13px; box-shadow: var(--shadow); animation: pop .18s ease;
}
.toast.error { background: var(--red); }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
.busy {
  position: fixed; inset: 0; z-index: 70; background: rgba(245, 247, 249, .78);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  font-size: 14px; color: var(--ink);
}
.spinner {
  width: 34px; height: 34px; border: 3px solid #d9e3e8; border-top-color: var(--accent);
  border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 1000px) {
  .summary { grid-template-columns: repeat(2, 1fr); }
  .topbar { height: auto; padding: 12px 16px; flex-wrap: wrap; }
  .main { padding: 18px 16px 40px; }
  .form-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 640px) {
  .summary { grid-template-columns: 1fr 1fr; }
  .filters { flex-direction: column; }
  .filters input { width: 100%; }
  .form-grid { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 88px 1fr; }
  .account-table { font-size: 11px; }
}
