:root {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #182230;
  --muted: #667085;
  --line: #e4e7ec;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #dbeafe;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --success: #16a34a;
  --success-soft: #dcfce7;
  --shadow: 0 12px 36px rgba(15, 23, 42, .08);
  --radius: 16px;
  --sidebar: 228px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(1000px 500px at 0% 0%, #e8f0ff 0%, transparent 55%),
    var(--bg);
  color: var(--text);
  font: 14px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }

.app { min-height: 100vh; }
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar);
  padding: 20px 14px;
  background: rgba(255,255,255,.92);
  border-right: 1px solid var(--line);
  backdrop-filter: blur(12px);
  display: flex;
  flex-direction: column;
  z-index: 20;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px 22px;
  font-weight: 700;
  letter-spacing: .2px;
}
.brand-mark {
  width: 36px; height: 36px; border-radius: 11px;
  display: grid; place-items: center;
  color: #fff; font-size: 13px; font-weight: 800;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  box-shadow: 0 8px 20px rgba(37,99,235,.28);
}
.brand small { display: block; color: var(--muted); font-size: 11px; font-weight: 500; }
.nav { display: grid; gap: 6px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 12px; border-radius: 10px;
  color: #475467; font-weight: 600;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--primary-soft); color: var(--primary-dark); }
.nav .ico { width: 20px; text-align: center; font-size: 15px; }
.sidebar-foot { margin-top: auto; color: var(--muted); font-size: 11px; padding: 12px 10px 0; }

.main { margin-left: var(--sidebar); padding: 26px; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; margin-bottom: 22px;
}
.topbar h1 { margin: 0; font-size: 24px; line-height: 1.25; letter-spacing: -.3px; }
.topbar p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.user-chip {
  padding: 8px 12px; border-radius: 999px; background: var(--surface);
  border: 1px solid var(--line); color: var(--muted); white-space: nowrap;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.card + .card { margin-top: 18px; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card-head h2 { margin: 0; font-size: 16px; }
.card-head p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }

.flash {
  margin-bottom: 16px; padding: 12px 14px; border-radius: 12px;
  background: var(--success-soft); color: #166534; border: 1px solid #bbf7d0;
}
.flash.error { background: var(--danger-soft); color: #991b1b; border-color: #fecaca; }

textarea, input[type=text], input[type=password], select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 11px 12px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  outline: none;
  transition: border .15s, box-shadow .15s, background .15s;
}
textarea:focus, input:focus, select:focus {
  border-color: #93c5fd; box-shadow: 0 0 0 4px rgba(37,99,235,.12); background: #fff;
}
textarea.editor {
  min-height: 430px;
  resize: vertical;
  font: 13px/1.6 ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  white-space: pre;
  overflow: auto;
}
.btn {
  appearance: none; border: 0; cursor: pointer;
  padding: 10px 15px; border-radius: 10px;
  font-weight: 700; font-size: 13px;
  background: var(--primary); color: #fff;
  /* 关键：按钮在 flex 容器里会被 shrink，中文没有空格可断，一旦宽度不足就逐字竖排。
     全局禁止换行 + 禁止收缩，所有按钮都不会再被挤成竖的。 */
  white-space: nowrap; flex: 0 0 auto;
  box-shadow: 0 7px 16px rgba(37,99,235,.2);
}
.btn:hover { background: var(--primary-dark); }
.btn.ghost { background: var(--surface-2); color: #344054; border: 1px solid var(--line); box-shadow: none; }
.btn.small { padding: 7px 10px; font-size: 12px; }
.btn.danger { background: var(--danger); box-shadow: 0 7px 16px rgba(220,38,38,.18); }
.actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 14px; }
.hint { color: var(--muted); font-size: 12px; }
code {
  background: #eef2f7; border: 1px solid #e5eaf1; border-radius: 6px;
  padding: 2px 6px; font: 12px ui-monospace, Consolas, monospace;
}

.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 12px; }
table { width: 100%; border-collapse: collapse; background: #fff; min-width: 760px; }
th {
  text-align: left; font-size: 11px; color: var(--muted);
  letter-spacing: .4px; text-transform: uppercase;
  background: var(--surface-2); padding: 11px 12px;
  border-bottom: 1px solid var(--line); white-space: nowrap;
}
td { padding: 12px; border-bottom: 1px solid #f1f3f7; vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fbfcff; }
.row-actions { display: flex; gap: 8px; align-items: center; }
/* 表格里操作列的紧凑输入框：局部覆盖全局 input[type=text]{width:100%}，
   否则输入框撑满整格、把按钮挤到下一行。 */
.nowrap { white-space: nowrap; }
.md5-input-sm {
  width: 150px !important; min-width: 150px; max-width: 150px; flex: 0 0 150px;
  padding: 6px 9px; font-size: 12px;
}
/* 端口绑定「重置 MD5」列：输入框靠左、重置靠右，删除再往右，三者之间留出间隔 */
.md5-cell { display: flex; align-items: center; gap: 10px; min-width: 300px; }
.md5-form { display: flex; align-items: center; justify-content: space-between;
            gap: 14px; margin: 0; flex: 1 1 auto; min-width: 0; }
.del-form { margin: 0; flex: 0 0 auto; }
/* 端口绑定表：操作列固定不换行，表格按内容自适应而不被撑爆 */
.ip-card .table-wrap table td.nowrap { vertical-align: middle; }
.badge { display: inline-flex; padding: 4px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.badge.on { background: var(--success-soft); color: #15803d; }
.badge.off { background: #f1f5f9; color: #64748b; }
.badge.warn { background: #fef3c7; color: #a16207; }
.mono { font: 12px ui-monospace, Consolas, monospace; white-space: nowrap; }

.login-page {
  min-height: 100vh; display: grid; place-items: center; padding: 22px;
}
.login-card {
  width: min(420px, 100%);
  background: rgba(255,255,255,.96);
  border: 1px solid rgba(228,231,236,.9);
  border-radius: 22px;
  padding: 30px;
  box-shadow: 0 22px 70px rgba(15,23,42,.14);
}
.login-logo { display: flex; align-items: center; gap: 12px; margin-bottom: 26px; }
.login-logo .brand-mark { width: 44px; height: 44px; border-radius: 13px; }
.login-logo h1 { margin: 0; font-size: 21px; letter-spacing: -.3px; }
.login-logo p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.login-card .btn { width: 100%; margin-top: 14px; padding: 12px; }
.field { margin-top: 14px; }
.field label { display: block; margin-bottom: 6px; font-size: 12px; color: #475467; font-weight: 600; }
.login-error { margin-top: 14px; padding: 10px 12px; border-radius: 10px; background: var(--danger-soft); color: #991b1b; font-size: 12px; }

.empty { text-align: center; color: var(--muted); padding: 38px 12px; }
@media (max-width: 760px) {
  :root { --sidebar: 0px; }
  .sidebar {
    inset: auto 0 0 0; width: 100%; height: 64px;
    padding: 8px; border-right: 0; border-top: 1px solid var(--line);
    flex-direction: row; backdrop-filter: blur(16px);
  }
  .brand, .sidebar-foot { display: none; }
  .nav { display: flex; width: 100%; justify-content: space-around; gap: 2px; }
  .nav a { flex-direction: column; gap: 2px; font-size: 10px; padding: 6px 9px; border-radius: 9px; }
  .nav .ico { font-size: 17px; }
  .main { margin-left: 0; padding: 16px 14px 86px; }
  .topbar { margin-bottom: 14px; }
  .topbar h1 { font-size: 20px; }
  .topbar p, .user-chip { display: none; }
  .card { border-radius: 14px; padding: 15px; }
  textarea.editor { min-height: 340px; font-size: 12px; }
  .actions { align-items: stretch; flex-direction: column-reverse; }
  .actions .btn { width: 100%; }
  .table-wrap { border-radius: 10px; }
  table { min-width: 700px; }
  .login-card { padding: 24px; border-radius: 18px; }
}

.ip-card { border-left: 4px solid hsl(var(--ip-hue, 220) 78% 58%); }
.ip-card .card-head h2 { display: flex; align-items: center; gap: 8px; }
.ip-dot { width: 9px; height: 9px; border-radius: 999px; background: hsl(var(--ip-hue, 220) 78% 58%); box-shadow: 0 0 0 4px hsl(var(--ip-hue, 220) 78% 58% / .13); }

details.ip-card { padding: 0; overflow: hidden; }
details.ip-card > summary {
  list-style: none; cursor: pointer; padding: 18px 20px;
  display: flex; align-items: center; gap: 12px; user-select: none;
}
details.ip-card > summary::-webkit-details-marker { display: none; }
details.ip-card > summary:hover { background: #fbfcff; }
details.ip-card .ip-main { display: grid; gap: 2px; min-width: 0; }
details.ip-card .ip-main strong { font-size: 15px; }
details.ip-card .ip-main small { color: var(--muted); font: 12px ui-monospace, Consolas, monospace; }

details.ip-card[open] > summary { border-bottom: 1px solid var(--line); }
.ip-card-body { padding: 18px 20px 20px; }
@media (max-width: 760px) {
  details.ip-card > summary { padding: 15px; }
  .ip-card-body { padding: 14px; }
}

.ops-grid { display:grid; grid-template-columns:1fr 2fr; gap:12px; }
.svc-actions { display:flex; flex-wrap:wrap; gap:8px; margin-top:14px; padding-top:14px; border-top:1px solid var(--line); }
.svc-actions .btn { flex:1; min-width:110px; }
@media (max-width:760px){ .ops-grid{grid-template-columns:1fr} .svc-actions .btn{flex:1 1 45%} }

details.ip-card > summary .port-badge { margin-left: auto; }

/* Account password console: fill available window width */
.account-card { width: 100%; max-width: none; }
.account-grid { grid-template-columns: minmax(260px, 1fr) minmax(320px, 1.2fr); }
.account-card .table-wrap table { min-width: 620px; }
@media (max-width: 760px) {
  .account-grid { grid-template-columns: 1fr; }
  .account-card .table-wrap table { min-width: 560px; }
}


/* ===== 运行错误页：IP 卡片 / 端口块 / 错误条目 ===== */
.err-summary {
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
  padding-top: 12px; border-top: 1px solid var(--line);
}
.err-stat { display: flex; align-items: baseline; gap: 6px; }
.err-stat b { font-size: 19px; letter-spacing: -.4px; color: var(--text); }
.err-stat i { font-style: normal; color: var(--muted); font-size: 12px; }

details.port-block {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
  overflow: hidden;
}
details.port-block + details.port-block { margin-top: 10px; }
details.port-block > summary {
  list-style: none; cursor: pointer; user-select: none;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 11px 14px;
}
details.port-block > summary::-webkit-details-marker { display: none; }
details.port-block > summary:hover { background: #eef4ff; }
details.port-block > summary::before { content: "\25B8"; color: var(--muted); font-size: 11px; width: 12px; }
details.port-block[open] > summary::before { content: "\25BE"; }
details.port-block[open] > summary { background: #fff; border-bottom: 1px solid var(--line); }

.port-num { font-weight: 700; font-size: 14px; color: var(--primary-dark); }
.port-time { margin-left: auto; }
.port-body { padding: 12px 14px; display: grid; gap: 10px; background: #fff; }

.err-item {
  border: 1px solid var(--line);
  border-left: 3px solid var(--danger);
  border-radius: 10px;
  padding: 10px 12px;
  background: #fff;
}
.err-top { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.err-loc { font-weight: 700; color: #b91c1c; }
.err-when { margin-left: auto; }
.err-cond {
  margin-top: 6px; padding: 6px 9px;
  background: var(--surface-2); border-radius: 7px;
  color: #344054; white-space: pre-wrap; word-break: break-word;
}
.err-func { margin-top: 6px; color: var(--muted); white-space: pre-wrap; word-break: break-word; }

details.err-raw { margin-top: 8px; }
details.err-raw > summary {
  cursor: pointer; color: var(--muted); font-size: 11px;
  list-style: none; user-select: none;
}
details.err-raw > summary::-webkit-details-marker { display: none; }
details.err-raw > summary::before { content: "\25B8 "; }
details.err-raw[open] > summary::before { content: "\25BE "; }
.err-pre {
  margin: 8px 0 0; padding: 10px 12px;
  background: #0f172a; color: #e2e8f0;
  border-radius: 9px; overflow: auto;
  font: 12px/1.6 ui-monospace, SFMono-Regular, Consolas, monospace;
  white-space: pre-wrap; word-break: break-all;
  max-height: 260px;
}

@media (max-width: 760px) {
  .err-summary { gap: 12px; }
  .err-stat b { font-size: 16px; }
  details.port-block > summary { padding: 10px 12px; }
  .port-time { width: 100%; margin-left: 22px; }
  .err-when { margin-left: 0; width: 100%; }
  .port-body { padding: 10px; }
}


/* ===== 运行错误页：窄屏响应式修正 ===== */
.err-head-row {
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px; flex-wrap: wrap; width: 100%;
}
.err-tip { margin-left: auto; }
details.ip-card > summary { flex-wrap: wrap; }

@media (max-width: 760px) {
  /* 日期 + 删除按钮纵向堆叠，避免按钮被挤出屏幕 */
  .err-head-row { flex-direction: column; align-items: stretch; }
  .err-head-row .row-actions { justify-content: flex-start; flex-wrap: wrap; }
  .err-tip { margin-left: 0; }
  /* 统计栏改为竖排，防止提示文字溢出 */
  .err-summary { flex-direction: column; align-items: stretch; gap: 8px; }
  /* IP 卡片头的次数标签回到左侧，避免越界 */
  details.ip-card > summary .port-badge { margin-left: 0; }
  .port-body { padding: 10px 8px; }
  .err-item { padding: 9px 10px; }
}


/* ===== 端口展开区：错误明细表格 ===== */
.port-body { display: block; padding: 12px; }
.err-table { min-width: 700px; table-layout: auto; }
.err-table th { white-space: nowrap; }
.err-table td { padding: 9px 10px; vertical-align: top; font-size: 12px; }
.err-table .err-loc-cell { font-weight: 700; color: #b91c1c; white-space: nowrap; }
.err-table .err-cond-cell { white-space: normal; word-break: break-all; color: #344054; }
.err-table .err-func-cell { white-space: normal; word-break: break-all; color: var(--muted); }
.err-table tbody tr:hover { background: #fbfcff; }

@media (max-width: 760px) {
  .port-body { padding: 8px; }
  .err-table { min-width: 640px; }
  .err-table td { padding: 8px; }
}


/* ===== 窄屏：错误表格精简列，减少横向滚动 ===== */
@media (max-width: 760px) {
  .err-table { min-width: 470px; }
  /* 隐藏「函数」列（第 3 列），位置/断言/次数/首次/最后 仍可见 */
  .err-table th:nth-child(3),
  .err-table td:nth-child(3) { display: none; }
  .err-table td { padding: 7px 6px; font-size: 11px; }
  .err-table th { font-size: 10px; padding: 8px 6px; }
  .err-table .err-loc-cell { width: 96px; }
}


/* ===== 窄屏：错误表格只保留 位置/断言/次数/最后 ===== */
@media (max-width: 760px) {
  .err-table { min-width: 0; width: 100%; }
  .err-table th:nth-child(3), .err-table td:nth-child(3) { display: none; }  /* 函数 */
  .err-table th:nth-child(5), .err-table td:nth-child(5) { display: none; }  /* 首次 */
  .err-table th, .err-table td { padding: 7px 5px; font-size: 11px; }
  .err-table th:nth-child(1), .err-table td:nth-child(1) { width: 92px; }
  .err-table th:nth-child(4), .err-table td:nth-child(4) { width: 44px; }
  .err-table th:nth-child(6), .err-table td:nth-child(6) { width: 74px; }
  .err-table .err-loc-cell { font-size: 10.5px; }
}


/* ===== 窄屏：错误表格强制固定列宽（覆盖全局 table min-width） ===== */
@media (max-width: 760px) {
  .err-table {
    min-width: 0 !important;
    width: 100% !important;
    table-layout: fixed !important;
  }
  .err-table th:nth-child(3), .err-table td:nth-child(3),
  .err-table th:nth-child(5), .err-table td:nth-child(5) { display: none !important; }
  .err-table th:nth-child(1), .err-table td:nth-child(1) { width: 82px !important; }
  .err-table th:nth-child(2), .err-table td:nth-child(2) { width: auto !important; }
  .err-table th:nth-child(4), .err-table td:nth-child(4) { width: 38px !important; }
  .err-table th:nth-child(6), .err-table td:nth-child(6) { width: 70px !important; }

  .err-table th, .err-table td { padding: 6px 4px !important; font-size: 10.5px !important; }
  .err-table th { font-size: 10px !important; }
  .err-table td.mono { white-space: normal !important; }
  .err-table .err-loc-cell {
    white-space: normal !important;
    word-break: break-all;
    font-size: 10px !important;
    line-height: 1.35;
  }
  .err-table .err-cond-cell, .err-table .err-func-cell { word-break: break-all; }
}


/* ===== 错误表格改 5 列（位置 / 原始内容 / 次数 / 首次 / 最后） ===== */
.err-table { min-width: 680px; table-layout: auto; }
.err-table .err-cond-cell {
  white-space: normal;
  word-break: normal;
  overflow-wrap: anywhere;
  color: #344054;
  line-height: 1.5;
}

@media (max-width: 760px) {
  .err-table { min-width: 0 !important; width: 100% !important; table-layout: fixed !important; }
  /* 第 3 列现在是「次数」，必须恢复显示（旧规则曾把它隐藏） */
  .err-table th:nth-child(3), .err-table td:nth-child(3) { display: table-cell !important; width: 38px !important; }
  /* 第 4 列「首次」隐藏 */
  .err-table th:nth-child(4), .err-table td:nth-child(4) { display: none !important; }
  /* 第 5 列「最后」恢复显示（旧规则曾把它隐藏） */
  .err-table th:nth-child(5), .err-table td:nth-child(5) { display: table-cell !important; width: 70px !important; }

  .err-table th:nth-child(1), .err-table td:nth-child(1) { width: 80px !important; }
  .err-table th:nth-child(2), .err-table td:nth-child(2) { width: auto !important; }

  .err-table th, .err-table td { padding: 6px 4px !important; font-size: 10.5px !important; }
  .err-table th { font-size: 10px !important; }
  .err-table td.mono { white-space: normal !important; }
  .err-table .err-loc-cell {
    white-space: normal !important;
    word-break: break-all;
    font-size: 10px !important;
    line-height: 1.35;
  }
}
