:root {
  --bg: #0d1117;
  --bg-soft: #131a23;
  --panel: #161d27;
  --panel-2: #1c2531;
  --line: #26303d;
  --text: #e6edf3;
  --muted: #8b98a5;
  --accent: #2f81f7;
  --ok: #3fb950;
  --warn: #d29922;
  --bad: #f85149;
  --radius: 10px;
  /* 顶部导航与中间内容区共用同一宽度，保证左右边缘对齐 */
  --shell-w: 1400px;
  --shell-pad: 20px;
  /* 顶栏高度（用于左侧菜单 sticky 定位）与侧边菜单宽度 */
  --topbar-h: 64px;
  --side-w: 200px;
}

/* 统一的页面外壳：顶栏内容、提示条、主内容区均使用它，宽度一致 */
.shell {
  width: 100%;
  max-width: var(--shell-w);
  margin: 0 auto;
  padding-left: var(--shell-pad);
  padding-right: var(--shell-pad);
}

* { box-sizing: border-box; }

/* ---------- 隐藏滚动条（保留滚动能力） ----------
   页面及各内部滚动容器（表格、事件列表、抽屉、客户端列表等）
   内容超出高度/宽度时仍可正常滚动，只是不再显示滚动条。 */
html, body {
  scrollbar-width: none;          /* Firefox */
  -ms-overflow-style: none;       /* 旧版 Edge / IE */
  scrollbar-color: transparent transparent;
}
html::-webkit-scrollbar,
body::-webkit-scrollbar { width: 0; height: 0; }

*, *::before, *::after {
  scrollbar-width: none;
  -ms-overflow-style: none;
  scrollbar-color: transparent transparent;
}
*::-webkit-scrollbar { width: 0; height: 0; background: transparent; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: transparent; border: 0; }
*::-webkit-scrollbar-corner { background: transparent; }

/* 例外：需要保留可见滚动条的元素加 class="show-scrollbar" 即可 */
.show-scrollbar { scrollbar-width: auto; -ms-overflow-style: auto; scrollbar-color: inherit; }
.show-scrollbar::-webkit-scrollbar { width: 8px; height: 8px; }
.show-scrollbar::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }
.show-scrollbar::-webkit-scrollbar-track { background: transparent; }

/* hidden 属性必须优先于任何 display 规则（如 .login-wrap/.drawer 的 flex） */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.6;
}

h1, h2, h3 { margin: 0 0 8px; font-weight: 600; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; margin-top: 18px; }
.muted { color: var(--muted); }
.small-text { font-size: 12px; }

/* 首屏加载态：会话校验完成前占位，避免刷新时先闪出登录页 */
.boot {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1000px 500px at 50% -10%, #1b2735 0%, var(--bg) 60%);
}
.boot-card { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.boot-card .logo { animation: boot-pulse 1.2s ease-in-out infinite; }
@keyframes boot-pulse {
  0%, 100% { opacity: 1; transform: none; }
  50% { opacity: .55; transform: scale(.94); }
}

/* ---------- 登录 ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background: radial-gradient(1000px 500px at 50% -10%, #1b2735 0%, var(--bg) 60%);
}
.login-card {
  width: 100%; max-width: 380px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 28px;
  box-shadow: 0 12px 40px rgba(0,0,0,.45);
}
.brand { display: flex; gap: 12px; align-items: center; margin-bottom: 18px; }
.brand.small { margin: 0; }
.logo {
  width: 40px; height: 40px; flex: 0 0 40px;
  border-radius: 9px; background: linear-gradient(135deg, var(--accent), #1f6feb);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; letter-spacing: .5px;
}
label { display: block; margin: 12px 0 6px; color: var(--muted); font-size: 13px; }
input, select, textarea {
  width: 100%; padding: 9px 11px;
  background: var(--bg-soft); color: var(--text);
  border: 1px solid var(--line); border-radius: 7px;
  font-family: inherit; font-size: 14px;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
.hint { color: var(--muted); font-size: 12px; margin-top: 14px; }

/* ---------- 按钮 ---------- */
.btn {
  padding: 7px 14px; border-radius: 7px; cursor: pointer;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); font-family: inherit; font-size: 13px;
  transition: background .15s, border-color .15s;
}
.btn:hover:not(:disabled) { background: #243040; border-color: #35435a; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { background: #4a92f8; }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; margin-top: 18px; padding: 10px; }
.btn.tiny { padding: 4px 9px; font-size: 12px; }

/* ---------- 顶栏 ---------- */
.topbar {
  background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.topbar-inner {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding-top: 12px; padding-bottom: 12px; flex-wrap: wrap;
}
.top-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
/* ---------- 左侧菜单 + 右侧内容 ---------- */
/* 注意：不要在此覆盖 .shell 的 margin: 0 auto，否则宽屏下内容区与顶栏无法对齐 */
.app-body {
  display: flex; align-items: flex-start; gap: 18px;
  padding-top: 14px; padding-bottom: 60px;
}

.sidebar {
  position: sticky; top: calc(var(--topbar-h) + 14px);
  flex: 0 0 var(--side-w); width: var(--side-w);
  max-height: calc(100vh - var(--topbar-h) - 28px);
  overflow-y: auto; padding: 10px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius);
}
.side-title { padding: 6px 10px 10px; color: var(--muted); font-size: 12px; letter-spacing: .5px; }
.side-item {
  display: flex; align-items: center; gap: 9px; width: 100%;
  padding: 9px 10px; margin-bottom: 4px;
  background: transparent; border: 1px solid transparent; border-radius: 7px;
  color: var(--text); font-family: inherit; font-size: 14px;
  text-align: left; cursor: pointer; transition: background .15s, border-color .15s;
}
.side-item:hover { background: var(--panel-2); }
.side-item.active {
  background: rgba(47,129,247,.14); border-color: rgba(47,129,247,.45);
  color: #cfe4ff; font-weight: 600;
}
.side-item .ico { width: 18px; text-align: center; color: var(--muted); font-size: 13px; }
.side-item.active .ico { color: var(--accent); }
.side-foot {
  margin-top: 10px; padding: 10px; border-top: 1px solid var(--line);
  color: var(--muted); font-size: 12px; line-height: 1.5;
}

.content { flex: 1; min-width: 0; }
.view { animation: view-fade .18s ease; }
@keyframes view-fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.view-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 12px; }
.view-head h2 { margin: 0; }
.content .card:last-child { margin-bottom: 0; }

.banner-wrap { padding-top: 12px; }
.banner {
  padding: 10px 14px;
  background: rgba(210,153,34,.12); border: 1px solid rgba(210,153,34,.4);
  color: #f0c674; border-radius: 8px; font-size: 13px;
}

/* ---------- 登录 / 注册 ---------- */
.tabs { display: flex; gap: 6px; margin-bottom: 16px; border-bottom: 1px solid var(--line); }
.tab {
  padding: 8px 14px; background: transparent; border: none; border-bottom: 2px solid transparent;
  color: var(--muted); cursor: pointer; font-family: inherit; font-size: 14px;
}
.tab.active { color: var(--text); border-bottom-color: var(--accent); }

/* ---------- 角色徽章 / 筛选 / 弹窗 ---------- */
.role-badge {
  font-size: 12px; padding: 2px 9px; border-radius: 20px;
  border: 1px solid var(--accent); color: var(--accent);
}
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px 4px 12px; border-radius: 20px; cursor: pointer;
  background: var(--panel-2); color: var(--muted);
  border: 1px solid var(--line); font-family: inherit; font-size: 13px;
  line-height: 20px;
}
.chip:hover { color: var(--text); border-color: #35435a; }
.chip.active { background: rgba(47,129,247,.16); border-color: var(--accent); color: var(--text); }
/* 计数徽标：不参与换行，等宽数字保证多行对齐 */
.chip > span {
  min-width: 20px; padding: 0 6px; border-radius: 10px;
  background: rgba(255,255,255,.06); color: var(--muted);
  font-family: Consolas, "Courier New", monospace; font-size: 11px;
  line-height: 17px; text-align: center; font-variant-numeric: tabular-nums;
}
.chip.active > span { background: rgba(47,129,247,.3); color: #cfe4ff; }

.modal {
  position: fixed; z-index: 60; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(420px, calc(100vw - 32px));
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 22px; box-shadow: 0 18px 50px rgba(0,0,0,.5);
}
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.inline-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 8px 0; }
.inline-form input { width: auto; flex: 1 1 160px; }
.inline-form select { width: auto; min-width: 110px; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; white-space: nowrap; }

/* ---------- 卡片 / 指标 ---------- */
.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px; margin-bottom: 18px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.head-tools { display: flex; gap: 8px; }
.search { width: 240px; }

.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.metrics .card { margin: 0; display: flex; flex-direction: column; gap: 4px; }
.metric .label { color: var(--muted); font-size: 12px; }
.metric .value { font-size: 26px; font-weight: 600; }
.metric .value.small-value { font-size: 18px; }
#proxy-types { margin-top: 10px; }
#proxy-types .tag b { color: var(--text); margin-left: 3px; }
.frps-cfg { margin-bottom: 12px; }
.kv.wide { grid-column: 1 / -1; }
.metric.ok .value { color: var(--ok); }
.metric.warn .value { color: var(--warn); }
.metric.bad .value { color: var(--bad); }

/* ---------- 表格 ---------- */
.table-scroll { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; min-width: 720px; }
table.grid.small { min-width: 420px; }
table.grid th, table.grid td {
  padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--line); font-size: 13px;
}
table.grid th { color: var(--muted); font-weight: 500; background: var(--bg-soft); }
table.grid tbody tr:hover { background: rgba(47,129,247,.06); }
table.grid td.mono, b.mono, .mono { font-family: Consolas, "Courier New", monospace; font-size: 12px; }
.empty { text-align: center; color: var(--muted); padding: 22px; }
tr.clickable { cursor: pointer; }

.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; padding: 2px 9px; border-radius: 20px; border: 1px solid var(--line); }
.badge .dot { width: 7px; height: 7px; border-radius: 50%; }
.badge.online { color: var(--ok); border-color: rgba(63,185,80,.4); background: rgba(63,185,80,.1); }
.badge.online .dot { background: var(--ok); }
.badge.offline { color: var(--muted); }
.badge.offline .dot { background: var(--muted); }
.badge.degraded { color: var(--warn); border-color: rgba(210,153,34,.4); background: rgba(210,153,34,.1); }
.badge.degraded .dot { background: var(--warn); }
.badge .dot.gray { background: var(--muted); }
.tag { font-size: 12px; padding: 1px 8px; border-radius: 5px; background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); }
.tag.running { color: var(--ok); border-color: rgba(63,185,80,.35); }
.tag.stopped { color: var(--muted); }

/* ---------- 事件 ---------- */
.events { list-style: none; margin: 0; padding: 0; max-height: 380px; overflow-y: auto; }
.events li { padding: 8px 10px; border-bottom: 1px solid var(--line); display: flex; gap: 10px; font-size: 13px; }
.events li:last-child { border-bottom: none; }
.events .time { color: var(--muted); font-family: Consolas, monospace; font-size: 12px; flex: 0 0 140px; }
.events .kind { flex: 0 0 96px; color: var(--accent); font-size: 12px; }
.events .msg { flex: 1; }
.events .detail { color: var(--muted); font-size: 12px; }

/* ---------- 抽屉 ---------- */
.mask { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 40; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: min(720px, 100%); z-index: 50;
  background: var(--panel); border-left: 1px solid var(--line);
  display: flex; flex-direction: column;
  box-shadow: -12px 0 40px rgba(0,0,0,.5);
}
.drawer-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  padding: 16px; border-bottom: 1px solid var(--line);
}
.drawer-body { padding: 16px; overflow-y: auto; flex: 1; }
.action-bar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 8px; }
.kv { display: flex; justify-content: space-between; gap: 10px; background: var(--bg-soft); border: 1px solid var(--line); border-radius: 7px; padding: 7px 10px; font-size: 13px; }
.kv span { color: var(--muted); }
.editor-tools { display: flex; align-items: center; gap: 8px; margin: 8px 0; flex-wrap: wrap; }
.editor-tools select { width: auto; min-width: 150px; }
.note-input { flex: 1 1 240px; width: auto; }
.note-cell { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.editor {
  width: 100%; min-height: 300px; resize: vertical;
  font-family: Consolas, "Courier New", monospace; font-size: 13px; line-height: 1.55;
  background: #0b1017;
}

.error {
  margin: 10px 0; padding: 9px 12px; border-radius: 7px;
  background: rgba(248,81,73,.12); border: 1px solid rgba(248,81,73,.4);
  color: #ff9c96; font-size: 13px; word-break: break-all;
}
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--line);
  padding: 10px 18px; border-radius: 8px; z-index: 90;
  box-shadow: 0 8px 30px rgba(0,0,0,.5); font-size: 13px; max-width: 90vw;
}

/* ---------- FRP 客户端 / 代理视图 ---------- */
.filter-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.filter-row .chips { flex: 0 0 auto; }
.search.grow { flex: 1 1 240px; width: auto; }
/* 下拉框不跟随输入框的 100% 宽度，避免被挤到单独一行 */
.filter-row select { width: auto; flex: 0 0 auto; min-width: 190px; }
#proxy-type-chips { margin: 2px 0 14px; }
.client-list { display: flex; flex-direction: column; gap: 10px; }
.item-card {
  display: flex; align-items: center; gap: 14px;
  background: var(--bg-soft); border: 1px solid var(--line);
  border-radius: 10px; padding: 14px 16px; cursor: pointer;
  transition: border-color .15s, background .15s;
}
.item-card:hover { border-color: rgba(47,129,247,.5); background: var(--panel-2); }
.item-card.static { cursor: default; }
.item-card.static:hover { border-color: var(--line); background: var(--bg-soft); }
.avatar {
  width: 38px; height: 38px; flex: 0 0 38px; border-radius: 9px;
  background: linear-gradient(135deg, #4a92f8, #1f6feb);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 16px; color: #fff; text-transform: uppercase;
}
.item-main { flex: 1; min-width: 0; }
.item-title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-weight: 600; }
.item-title .muted { font-weight: 400; }
.item-meta { display: flex; align-items: center; gap: 14px; color: var(--muted); font-size: 12px; margin-top: 3px; flex-wrap: wrap; }
.item-side { display: flex; align-items: center; gap: 14px; flex-shrink: 0; }
.traffic {
  display: flex; flex-direction: column; gap: 2px; font-size: 12px;
  font-family: Consolas, monospace; align-items: flex-end;
  min-width: 92px; font-variant-numeric: tabular-nums;
}
.traffic span { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
.traffic i { font-style: normal; font-size: 11px; opacity: .8; }
.traffic .in { color: var(--ok); }
.traffic .out { color: var(--bad); }
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; }
.dot.ok { background: var(--ok); }
.dot.gray { background: var(--muted); }
.chip .dot { margin-right: 2px; }
.crumb { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; font-size: 14px; }
.link-btn {
  background: transparent; border: none; color: var(--accent); cursor: pointer;
  font-family: inherit; font-size: 14px; padding: 0;
}
.link-btn:hover { text-decoration: underline; }
.btn.danger { color: var(--bad); border-color: rgba(248,81,73,.45); }
.btn.danger:hover:not(:disabled) { background: rgba(248,81,73,.12); }
.host-badge { font-size: 11px; padding: 1px 7px; border-radius: 5px; background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); font-family: Consolas, monospace; }
.detail-row { display: flex; gap: 18px; flex-wrap: wrap; color: var(--muted); font-size: 12px; margin-top: 10px; }
.detail-row b { color: var(--text); font-weight: 500; margin-left: 4px; }

/* ---------- 代理列表：整块容器 + 分隔行（避免卡片套卡片） ---------- */
#proxy-list {
  gap: 0; overflow: hidden;
  background: var(--bg-soft); border: 1px solid var(--line); border-radius: 10px;
}
#proxy-list > .item-card {
  padding: 12px 16px; border: none; border-bottom: 1px solid var(--line);
  border-radius: 0; background: transparent;
  transition: background .15s;
}
#proxy-list > .item-card:last-child { border-bottom: none; }
#proxy-list > .item-card:hover { background: rgba(47,129,247,.06); }
#proxy-list > .empty { padding: 28px 16px; }
/* 标题行与信息行紧凑一点，信息之间用分隔点代替大片留白 */
#proxy-list .item-title { gap: 8px; font-size: 14px; line-height: 22px; }
#proxy-list .item-meta { gap: 0; margin-top: 4px; }
#proxy-list .item-meta > span { display: inline-flex; align-items: center; gap: 5px; }
#proxy-list .item-meta > span:not(:first-child)::before { content: "·"; margin: 0 9px; color: #4a5a6d; }
#proxy-list .item-meta b { color: var(--text); font-weight: 500; }
#proxy-list .item-side { gap: 16px; }
#proxy-list .badge { white-space: nowrap; }

/* ---------- 系统更新页 ---------- */
.rel-form { margin: 4px 0 18px; }
.rel-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; }
.rel-grid label { display: flex; flex-direction: column; gap: 6px; margin: 0; font-size: 12px; }
.rel-grid label.wide { grid-column: 1 / -1; }
.rel-grid input[type="file"] { padding: 6px; font-size: 12px; }
.chk { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.chk input { width: auto; margin: 0; }
#pv-status { min-height: 16px; margin: 2px 0 0; }

/* ---------- 响应式 ---------- */
@media (max-width: 720px) {
  :root { --shell-pad: 12px; }
  /* 窄屏：左侧菜单转为顶部横向滚动条 */
  .app-body { display: block; padding-top: 10px; }
  .sidebar {
    position: static; width: auto; max-height: none;
    display: flex; align-items: center; gap: 6px; overflow-x: auto; padding: 6px;
  }
  .side-title, .side-foot { display: none; }
  .side-item { width: auto; flex: 0 0 auto; margin: 0; white-space: nowrap; }
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .search { width: 100%; }
  .head-tools { width: 100%; }
  .drawer { width: 100%; }
  .events li { flex-direction: column; gap: 2px; }
  .events .time { flex: none; }
  .inline-form input, .inline-form select { flex: 1 1 100%; }
  /* 代理行在窄屏下换行：信息占满一行，流量与状态另起一行 */
  #proxy-list > .item-card { flex-wrap: wrap; }
  #proxy-list .item-side { width: 100%; justify-content: space-between; gap: 12px; }
  #proxy-list .traffic { align-items: flex-start; }
}
