:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --border: #e5e8ef;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --accent: #0f9d8f;
  --danger: #dc2626;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px rgba(16, 24, 40, .06);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 600; }
code { font-family: "SFMono-Regular", Consolas, monospace; }

/* ---------- 通用控件 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px; border: 1px solid var(--border); border-radius: 7px;
  background: var(--surface); color: var(--text); font-size: 13px; cursor: pointer;
  text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: #c9d2e3; background: #f9fafc; text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-block { width: 100%; height: 40px; font-size: 15px; font-weight: 600; }
.btn:disabled { opacity: .6; cursor: not-allowed; }
.btn-link {
  border: 0; background: none; color: var(--primary); cursor: pointer;
  padding: 0 6px; font-size: 13px; text-decoration: none;
}
.btn-link:hover { text-decoration: underline; }
.btn-link.danger { color: var(--danger); }
input, select {
  width: 100%; height: 36px; padding: 0 11px; border: 1px solid var(--border);
  border-radius: 7px; background: var(--surface); color: var(--text); font: inherit;
  outline: none;
}
input:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .12); }
input[readonly] { background: #f8fafc; color: #64748b; cursor: default; }
label { display: block; font-size: 13px; color: #374151; font-weight: 500; }
label input, label select { margin-top: 6px; font-weight: 400; }
.hint { color: var(--muted); font-size: 12px; margin: 8px 0 0; }
.empty { color: var(--muted); text-align: center; padding: 32px 0; font-size: 13px; }
.muted { color: var(--muted); }
.strong { font-weight: 600; }
.mono { font-family: "SFMono-Regular", Consolas, monospace; }

/* ---------- 登录页 ---------- */
.login-body { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #eef2fb 0%, #f7f9fc 60%, #eaf6f4 100%); }
.login-card { width: 400px; max-width: calc(100vw - 32px); padding: 34px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); }
.login-brand { margin-bottom: 26px; }
.login-card form label { margin-bottom: 16px; }
.login-card form .btn { margin-top: 8px; }
.login-tip { margin: 20px 0 0; font-size: 12px; color: var(--muted); text-align: center; }
.alert { padding: 10px 12px; border-radius: 7px; font-size: 13px; margin-bottom: 16px; }
.alert-error { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }

/* ---------- 品牌 / 布局 ---------- */
.brand { display: flex; align-items: center; gap: 11px; padding: 22px 20px 18px; }
.brand-mark {
  width: 36px; height: 36px; flex: 0 0 36px; border-radius: 9px;
  background: var(--primary); color: #fff; display: flex; align-items: center;
  justify-content: center; font-weight: 700; font-size: 14px; letter-spacing: .5px;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.35; }
.brand-text strong { font-size: 15px; }
.brand-text span { font-size: 11px; color: var(--muted); }
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px; flex: 0 0 232px; background: var(--surface);
  border-right: 1px solid var(--border); display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.menu { flex: 1; padding: 8px 12px; overflow-y: auto; }
.menu-label { padding: 10px 10px 6px; font-size: 11px; color: #9ca3af; letter-spacing: .08em; }
.menu-item {
  display: flex; align-items: center; gap: 9px; height: 38px; padding: 0 11px;
  border-radius: 7px; color: #4b5563; font-size: 13.5px; text-decoration: none; margin-bottom: 2px;
}
.menu-item:hover { background: #f5f7fb; text-decoration: none; color: var(--text); }
.menu-item.active { background: #eaf1ff; color: var(--primary); font-weight: 600; }
.mi-icon { width: 16px; text-align: center; font-size: 14px; color: #9ca3af; }
.menu-item.active .mi-icon { color: var(--primary); }
.caret { margin-left: auto; color: #9ca3af; font-size: 16px; }
.submenu { margin: 2px 0 6px 18px; padding-left: 10px; border-left: 1px solid var(--border); }
.menu-item.sub { height: 32px; font-size: 13px; gap: 7px; }
.dot { width: 5px; height: 5px; border-radius: 50%; background: #cbd5e1; flex: 0 0 5px; }
.menu-item.sub.active .dot { background: var(--primary); }
.badge { margin-left: auto; font-size: 11px; color: var(--muted); background: #f1f3f7; border-radius: 10px; padding: 0 7px; }
.submenu-empty { padding: 6px 11px; font-size: 12px; color: #9ca3af; }
.sidebar-footer { border-top: 1px solid var(--border); padding: 14px 18px; display: flex; align-items: center; justify-content: space-between; }
.avatar { font-size: 13px; font-weight: 600; color: #374151; }

.main { flex: 1; min-width: 0; padding: 0 28px 40px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 26px 0 22px; }
.topbar h1 { font-size: 22px; }
.subtitle { margin: 4px 0 0; color: var(--muted); font-size: 12.5px; }
.env-tag { font-size: 12px; color: var(--accent); background: #e8f7f4; border: 1px solid #cdeee8; padding: 5px 11px; border-radius: 20px; white-space: nowrap; }

/* ---------- 统计 KPI：数字为唯一视觉主角（参考 Stripe / Vercel） ---------- */
.cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 32px; }
.stat-card {
  padding: 22px 24px 24px; background: var(--surface);
  border: 1px solid rgba(16, 24, 40, .07); border-radius: 12px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, .03);
}
.stat-label { display: block; font-size: 11px; font-weight: 600; letter-spacing: .06em; color: var(--muted); }
.stat-card strong {
  display: block; margin-top: 10px; color: #111827;
  font-size: 34px; line-height: 1.1; font-weight: 650;
  letter-spacing: -.03em; font-variant-numeric: tabular-nums;
}

/* ---------- 分段选项卡（shadcn/ui segmented control） ---------- */
.section { margin-bottom: 24px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; margin: 0 0 16px; }
.section-head .btn-link { white-space: nowrap; font-size: 12.5px; }
.tabs {
  display: inline-flex; align-items: center; gap: 4px; padding: 4px;
  background: #eef1f6; border: 1px solid rgba(16, 24, 40, .05); border-radius: 10px;
}
.tab {
  display: inline-flex; align-items: center; gap: 8px; height: 32px; padding: 0 14px;
  border: 0; border-radius: 7px; background: transparent; color: #64748b;
  font-family: inherit; font-size: 13px; font-weight: 500; line-height: 1; cursor: pointer;
  transition: background .18s cubic-bezier(.25, 1, .5, 1), color .18s cubic-bezier(.25, 1, .5, 1), box-shadow .18s cubic-bezier(.25, 1, .5, 1);
}
.tab:hover { color: #111827; }
.tab.active { background: var(--surface); color: #111827; font-weight: 600; box-shadow: 0 1px 3px rgba(16, 24, 40, .10); }
.tab:focus-visible, .entity-card:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.tab-count {
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 5px;
  display: inline-flex; align-items: center; justify-content: center;
  background: rgba(16, 24, 40, .06); color: #64748b;
  font-size: 11px; font-weight: 600; font-variant-numeric: tabular-nums;
}
.tab.active .tab-count { background: #eaf1ff; color: var(--primary); }
.tab-panel { animation: panel-in .2s cubic-bezier(.25, 1, .5, 1); }
@keyframes panel-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---------- 实体卡片：应用组 / 应用共用同一套表面与节奏 ---------- */
.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(268px, 1fr)); gap: 16px; }
.entity-card {
  display: flex; flex-direction: column; min-height: 196px;
  padding: 20px 22px 18px; background: var(--surface);
  border: 1px solid rgba(16, 24, 40, .08); border-radius: 12px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, .03);
  color: var(--text); text-decoration: none;
  transition: transform .18s cubic-bezier(.25, 1, .5, 1), border-color .18s cubic-bezier(.25, 1, .5, 1), box-shadow .18s cubic-bezier(.25, 1, .5, 1);
}
.entity-card:hover {
  transform: translateY(-2px); border-color: rgba(37, 99, 235, .28); text-decoration: none; color: var(--text);
  box-shadow: 0 4px 12px rgba(16, 24, 40, .06), 0 12px 28px rgba(16, 24, 40, .05);
}
.ec-head { display: flex; align-items: center; gap: 12px; }
.ec-avatar {
  width: 38px; height: 38px; flex: 0 0 38px; border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  background: #f1f5f9; color: #475569; font-size: 14px; font-weight: 650;
  border: 1px solid rgba(16, 24, 40, .04);
}
.ec-avatar.alt { background: #eef4ff; color: var(--primary); border-color: rgba(37, 99, 235, .08); }
.ec-title { display: flex; flex-direction: column; min-width: 0; gap: 1px; }
.ec-title strong { font-size: 14px; font-weight: 600; letter-spacing: -.01em; color: #111827; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ec-title small { font-size: 11px; color: #94a3b8; }
.ec-badge {
  margin-left: auto; flex: 0 0 auto; max-width: 104px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  padding: 3px 8px; border-radius: 6px; background: #f5f7fa; border: 1px solid rgba(16, 24, 40, .04);
  color: #64748b; font-size: 11px; font-weight: 600; font-variant-numeric: tabular-nums;
}
.ec-metric { display: flex; align-items: baseline; gap: 8px; margin: 20px 0 14px; }
.ec-metric b { font-size: 32px; line-height: 1; font-weight: 650; letter-spacing: -.03em; font-variant-numeric: tabular-nums; color: #111827; }
.app-card .ec-metric b { font: 650 27px/1 "SFMono-Regular", Consolas, monospace; letter-spacing: -.02em; }
.ec-metric span { font-size: 12px; color: var(--muted); }
.ec-slot { height: 24px; box-sizing: border-box; display: flex; align-items: center; }
.ec-bar { width: 100%; height: 4px; background: #eef1f6; border-radius: 999px; overflow: hidden; }
.ec-bar i { display: block; height: 100%; background: var(--primary); border-radius: 999px; }
.ec-slot.ec-domain {
  display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font: 12.5px/24px "SFMono-Regular", Consolas, monospace; color: #475569;
}
.ec-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; min-height: 22px; }
.ec-chip {
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  padding: 3px 8px; border-radius: 5px; background: #f5f7fa; color: #64748b; font-size: 11px;
}
.ec-chip.ghost { max-width: 140px; background: transparent; border: 1px solid rgba(16, 24, 40, .06); color: #94a3b8; }
.ec-chip.range { font-family: "SFMono-Regular", Consolas, monospace; color: #475569; background: #eef2f7; }
.ec-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  margin-top: auto; padding-top: 16px; font-size: 11.5px; color: #94a3b8;
}
.ec-foot > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ec-arrow { color: #cbd5e1; font-size: 14px; transition: transform .18s cubic-bezier(.25, 1, .5, 1), color .18s cubic-bezier(.25, 1, .5, 1); }
.entity-card:hover .ec-arrow { color: var(--primary); transform: translateX(3px); }
.card-empty {
  grid-column: 1 / -1; padding: 40px 16px; text-align: center; color: var(--muted);
  background: var(--surface); border: 1px dashed rgba(16, 24, 40, .12); border-radius: 12px; font-size: 13px;
}

/* ---------- 面板 / 表格 ---------- */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 20px 22px; box-shadow: var(--shadow); margin-bottom: 16px; }
.panel h2 { font-size: 15px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 16px; flex-wrap: wrap; }
.panel-head h2 { margin-bottom: 0; }
.panel-head .hint { margin: 3px 0 0; }
.search { display: flex; align-items: center; gap: 8px; }
.search input { width: 260px; }
.search .btn-link { white-space: nowrap; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { text-align: left; color: var(--muted); font-weight: 500; font-size: 12px; padding: 10px 12px; background: #f8fafc; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 11px 12px; border-bottom: 1px solid #f0f2f6; vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #fafbfe; }
.col-ops { width: 150px; }
.ops { white-space: nowrap; }
.tag { display: inline-block; background: #eef2ff; color: #4f46e5; border-radius: 5px; padding: 2px 8px; font-size: 12px; }
.port { display: inline-block; font-family: "SFMono-Regular", Consolas, monospace; background: #f1f5f9; color: #334155; border-radius: 5px; padding: 2px 8px; font-size: 12.5px; font-weight: 600; }
.domain { word-break: break-all; }
.code { display: block; background: #0f172a; color: #e2e8f0; padding: 9px 13px; border-radius: 7px; font-size: 12.5px; margin: 10px 0 4px; white-space: pre-wrap; word-break: break-all; }

/* ---------- 应用组可展开列表（默认合起） ---------- */
.group-table .col-toggle { width: 38px; padding-left: 12px; padding-right: 0; }
.row-toggle {
  width: 24px; height: 24px; padding: 0; display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border); border-radius: 6px; background: var(--surface);
  color: #94a3b8; cursor: pointer; line-height: 1;
  transition: background .16s ease, color .16s ease, border-color .16s ease;
}
.row-toggle:hover { background: #f1f5fb; color: var(--primary); border-color: #c9d8f5; }
.row-toggle:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.row-toggle .chev { display: inline-block; font-size: 17px; transform: translateY(-1px); transition: transform .18s cubic-bezier(.25, 1, .5, 1); }
.row-toggle.open .chev { color: var(--primary); transform: rotate(90deg) translateX(-1px); }
.group-row.expanded td { background: #f8faff; border-bottom-color: transparent; }
.range-tag {
  display: inline-block; white-space: nowrap; padding: 3px 8px; border-radius: 5px;
  background: #f1f5f9; color: #475569; font: 600 12px/1.4 "SFMono-Regular", Consolas, monospace;
}
.group-detail > td { padding: 0 12px 16px; background: #f8faff; }
.detail-box { border: 1px solid #e3e9f5; border-radius: 9px; background: var(--surface); overflow: hidden; }
.detail-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 12px 14px; background: #fbfcff; border-bottom: 1px solid var(--border);
}
.detail-head .hint { display: inline; margin-left: 8px; }
.btn-sm { height: 30px; padding: 0 11px; font-size: 12.5px; }
.inner-table th { background: var(--surface); }
.inner-table td:first-child, .inner-table th:first-child { padding-left: 16px; }
.inner-table .empty { padding: 22px 0; }
/* 端口段输入框下方实时换算出的区间预览 */
.block-preview {
  margin: -4px 0 12px; padding: 9px 11px; border: 1px solid #dbe6fb; border-radius: 7px;
  background: #f4f8ff; color: #1d4ed8;
  font: 600 13px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-variant-numeric: tabular-nums;
}
.block-preview.invalid { background: #fff7ed; border-color: #fed7aa; color: #b45309; }
#g-port-block { font: 600 15px/1.4 "SFMono-Regular", Consolas, monospace; letter-spacing: .5px; }

/* ---------- 设置 ---------- */
.settings-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.stack-form label { margin-bottom: 14px; }
.stack-form .btn { margin-top: 4px; }

/* ---------- 弹窗 / 提示 ---------- */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(15, 23, 42, .42); display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal-box { width: 440px; max-width: 100%; max-height: 90vh; overflow-y: auto; background: var(--surface); border-radius: 12px; box-shadow: 0 20px 60px rgba(15, 23, 42, .2); padding: 22px 24px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.modal-head h3 { font-size: 16px; }
.modal-close { border: 0; background: none; font-size: 22px; line-height: 1; color: #9ca3af; cursor: pointer; }
.modal form label { margin-bottom: 14px; }
.form-tip { font-size: 12px; color: var(--muted); margin: -2px 0 12px; }
#group-range-used { line-height: 1.6; margin-bottom: 8px; }
.form-tip.warn { color: #b45309; background: #fffbeb; padding: 8px 10px; border-radius: 6px; line-height: 1.6; }
#force-password-modal .form-tip.warn { margin: 0 0 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 20px; }
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 12px);
  background: #1f2937; color: #fff; padding: 10px 18px; border-radius: 8px;
  font-size: 13px; opacity: 0; pointer-events: none; transition: all .2s ease; z-index: 100;
  max-width: min(560px, 90vw); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: #b91c1c; }
.toast.ok { background: #0f766e; }

@media (max-width: 1000px) {
  .cards { grid-template-columns: repeat(2, 1fr); }
  .settings-grid { grid-template-columns: 1fr; }
  .sidebar { width: 190px; flex-basis: 190px; }
  .main { padding: 0 16px 30px; }
  .search input { width: 180px; }
  .card-grid { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
  .panel { overflow-x: auto; }
  .group-table { min-width: 640px; }
}
@media (max-width: 640px) {
  .cards { gap: 12px; }
  .stat-card { padding: 18px 20px; }
  .stat-card strong { font-size: 30px; }
  .card-grid { grid-template-columns: 1fr; }
}
