/* dsh-relay 面板样式：深色侧边栏 + 浅色内容，系统字体栈，零外部依赖 */

:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --ink: #0f172a;
  --ink-2: #475569;
  --ink-3: #94a3b8;
  --line: #e6eaf2;
  --line-2: #d8deea;
  --brand: #2563eb;
  --brand-ink: #1d4ed8;
  --green: #16a34a;
  --green-bg: #e8f7ee;
  --gray: #64748b;
  --gray-bg: #eef2f7;
  --amber: #b45309;
  --amber-bg: #fdf3e2;
  --red: #dc2626;
  --red-bg: #fdecec;
  --side: #0f172a;
  --side-2: #131f38;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 8px 24px rgba(15, 23, 42, .06);
  --font: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
          "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; }
input { font-family: inherit; }
.hidden { display: none !important; }
.muted { color: var(--ink-2); }
.small { font-size: 12px; }
.error { color: var(--red); font-size: 13px; margin: 10px 0 0; }

/* ---------- 登录 ---------- */
.login-wrap {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(900px 420px at 75% -8%, #dbe7ff 0%, transparent 60%),
    radial-gradient(700px 380px at 10% 110%, #e4ecff 0%, transparent 55%),
    var(--bg);
}
.login-card {
  width: min(380px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: 0 24px 60px rgba(15, 23, 42, .12);
  padding: 38px 34px 30px;
  text-align: center;
}
.brand-mark {
  width: 54px; height: 54px; margin: 0 auto 16px;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; font-weight: 700; color: #fff;
  background: linear-gradient(135deg, #2563eb, #4f8cff);
  border-radius: 16px;
  box-shadow: 0 10px 22px rgba(37, 99, 235, .35);
}
.login-card h1 { font-size: 22px; margin: 0 0 6px; letter-spacing: .4px; }
.login-card > p { margin: 0 0 24px; font-size: 13px; }
.login-card form { text-align: left; }
.login-card label { display: block; font-size: 12px; color: var(--ink-2); margin-bottom: 7px; }
.login-card input {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--line-2);
  border-radius: 10px;
  font-size: 14px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  background: #fbfcfe;
}
.login-card input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(37, 99, 235, .12); }
.login-card .btn { margin-top: 16px; }
.hint { margin-top: 20px !important; font-size: 12px; color: var(--ink-3); }

/* ---------- 布局 ---------- */
.app { display: flex; min-height: 100%; }
.sidebar {
  width: 208px;
  flex: 0 0 208px;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, var(--side) 0%, var(--side-2) 100%);
  color: #cbd5e1;
  position: sticky;
  top: 0;
  height: 100vh;
}
.side-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 22px 20px 18px;
  font-weight: 700; font-size: 16px; color: #fff; letter-spacing: .5px;
}
.side-brand .dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: #22d3ee;
  box-shadow: 0 0 0 4px rgba(34, 211, 238, .15), 0 0 14px rgba(34, 211, 238, .7);
}
.side-nav { padding: 8px 12px; display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  text-align: left;
  padding: 10px 12px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: #94a3b8;
  font-size: 14px;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: rgba(148, 163, 184, .1); color: #e2e8f0; }
.nav-item.active { background: rgba(59, 130, 246, .16); color: #dbeafe; font-weight: 600; }
.side-foot {
  margin-top: auto;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  border-top: 1px solid rgba(148, 163, 184, .12);
}
.side-foot .muted { color: #64748b; }
.link {
  background: none; border: 0; padding: 0; text-align: left;
  color: #93c5fd; font-size: 13px;
}
.link:hover { color: #bfdbfe; text-decoration: underline; }

.content { flex: 1; min-width: 0; padding: 30px 34px 60px; }
.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}
.page-head h2 { margin: 0 0 4px; font-size: 21px; letter-spacing: .3px; }
.page-head p { margin: 0; }
.actions { display: flex; gap: 10px; }

/* ---------- 按钮 ---------- */
.btn {
  border: 1px solid transparent;
  border-radius: 9px;
  padding: 9px 15px;
  font-size: 13.5px;
  font-weight: 600;
  transition: transform .05s, box-shadow .15s, background .15s, border-color .15s;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: var(--brand); color: #fff;
  box-shadow: 0 6px 16px rgba(37, 99, 235, .28);
}
.btn.primary:hover { background: var(--brand-ink); }
.btn.ghost { background: #fff; border-color: var(--line-2); color: var(--ink-2); }
.btn.ghost:hover { border-color: var(--brand); color: var(--brand); }
.btn.danger { background: var(--red); color: #fff; }
.btn.danger:hover { background: #b91c1c; }
.btn.block { width: 100%; padding: 11px; }
.btn.sm { padding: 5px 10px; font-size: 12.5px; border-radius: 7px; font-weight: 500; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.icon-btn {
  width: 32px; height: 32px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  font-size: 18px;
  line-height: 1;
  color: var(--ink-2);
}
.icon-btn:hover { border-color: var(--red); color: var(--red); }

/* ---------- 通道表格 ---------- */
.table-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.channels-table { width: 100%; border-collapse: collapse; }
.channels-table th {
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-3);
  padding: 13px 16px;
  background: #fafbfe;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.channels-table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
.channels-table tr:last-child td { border-bottom: 0; }
.channels-table tbody tr { transition: background .12s; cursor: pointer; }
.channels-table tbody tr:hover { background: #f7f9fd; }
.channels-table .num { text-align: right; }
.channels-table .ops { text-align: right; }
.channels-table .ops .btn { margin-left: 6px; }
.empty { padding: 46px 20px; text-align: center; }
.empty p { margin: 0 0 6px; }

.name-cell { display: flex; flex-direction: column; gap: 3px; }
.name-cell strong { font-size: 14px; }
.name-cell .mono { font-size: 12px; }
.mono { font-family: var(--mono); color: var(--ink-2); }

.chips { display: flex; flex-wrap: wrap; gap: 5px; max-width: 300px; }
.chip {
  display: inline-block;
  padding: 2px 8px;
  font-size: 11.5px;
  border-radius: 999px;
  background: #eef3ff;
  color: #3b5bdb;
  border: 1px solid #dbe6ff;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 状态徽章 */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 999px;
  white-space: nowrap;
}
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.online { color: var(--green); background: var(--green-bg); }
.badge.offline { color: var(--gray); background: var(--gray-bg); }
.badge.paused { color: var(--amber); background: var(--amber-bg); }
.badge.stopped { color: var(--red); background: var(--red-bg); }
.badge.online .dot { box-shadow: 0 0 0 3px rgba(22, 163, 74, .16); }

.traffic-cell { font-size: 12.5px; color: var(--ink-2); line-height: 1.5; }
.traffic-cell .up { color: #0e7490; }
.traffic-cell .down { color: #6d28d9; }

.rate-cell { display: flex; align-items: center; justify-content: flex-end; gap: 10px; }
.rate-num { font-family: var(--mono); font-size: 12.5px; line-height: 1.5; text-align: right; }
.rate-num .down { color: #6d28d9; }
.rate-num .up { color: #0e7490; }
.spark { width: 74px; height: 26px; flex: 0 0 74px; }

/* ---------- 系统页 ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
}
.stat-card .label { font-size: 12px; color: var(--ink-3); margin-bottom: 8px; }
.stat-card .value { font-size: 24px; font-weight: 700; letter-spacing: .3px; }
.stat-card .value .unit { font-size: 13px; font-weight: 500; color: var(--ink-3); margin-left: 4px; }

/* ---------- 抽屉 ---------- */
.drawer { position: fixed; inset: 0; z-index: 40; }
.drawer-backdrop { position: absolute; inset: 0; background: rgba(15, 23, 42, .35); backdrop-filter: blur(2px); }
.drawer-panel {
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: min(620px, 94vw);
  background: #fbfcfe;
  box-shadow: -24px 0 60px rgba(15, 23, 42, .18);
  display: flex;
  flex-direction: column;
  animation: slide-in .18s ease-out;
}
@keyframes slide-in { from { transform: translateX(30px); opacity: .4; } to { transform: none; opacity: 1; } }
.drawer-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}
.drawer-head h3 { margin: 0 0 4px; font-size: 17px; }
.drawer-head p { margin: 0; }
.drawer-body { overflow-y: auto; padding: 20px 24px 40px; display: flex; flex-direction: column; gap: 20px; }

.panel-block {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px 18px;
}
.panel-block h4 {
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--ink-2);
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.panel-block h4 .sub { font-weight: 400; color: var(--ink-3); font-size: 12px; }

.chart-svg { width: 100%; height: auto; display: block; }
.chart-empty { color: var(--ink-3); font-size: 12.5px; padding: 20px 0; text-align: center; }

.conn-table, .event-list { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.conn-table th { text-align: left; color: var(--ink-3); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.conn-table td { padding: 7px 8px; border-bottom: 1px solid #f1f4f9; font-family: var(--mono); }
.conn-table td.name { font-family: var(--font); }
.conn-table tr:last-child td { border-bottom: 0; }
.event-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 9px; }
.event-list li { display: flex; gap: 10px; font-size: 12.5px; color: var(--ink-2); }
.event-list .ts { color: var(--ink-3); font-family: var(--mono); flex: 0 0 118px; }
.event-list .kind { color: var(--brand); font-weight: 600; flex: 0 0 auto; }

.code-block {
  position: relative;
  background: #0f172a;
  color: #e2e8f0;
  border-radius: 10px;
  padding: 14px 16px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.7;
  overflow-x: auto;
  white-space: pre;
}
.code-block .copy-btn {
  position: absolute;
  top: 8px; right: 8px;
  border: 1px solid rgba(148, 163, 184, .3);
  background: rgba(148, 163, 184, .12);
  color: #cbd5e1;
  border-radius: 6px;
  padding: 3px 9px;
  font-size: 11.5px;
  font-family: var(--font);
}
.code-block .copy-btn:hover { background: rgba(148, 163, 184, .22); }

/* ---------- 弹窗 ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(15, 23, 42, .42); backdrop-filter: blur(2px); }
.modal-panel {
  position: relative;
  width: min(500px, 92vw);
  max-height: 88vh;
  overflow-y: auto;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 30px 80px rgba(15, 23, 42, .3);
  padding: 24px 26px 22px;
  animation: pop .16s ease-out;
}
@keyframes pop { from { transform: scale(.97); opacity: .5; } to { transform: none; opacity: 1; } }
.modal-panel h3 { margin: 0 0 6px; font-size: 17px; }
.modal-panel .desc { margin: 0 0 18px; color: var(--ink-2); font-size: 13px; line-height: 1.6; }
.form-row { margin-bottom: 14px; }
.form-row label { display: block; font-size: 12.5px; color: var(--ink-2); margin-bottom: 6px; }
.form-row label .req { color: var(--red); }
.form-row input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line-2);
  border-radius: 9px;
  font-size: 13.5px;
  outline: none;
  background: #fbfcfe;
}
.form-row input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(37, 99, 235, .12); }
.form-row .help { margin: 6px 0 0; font-size: 11.5px; color: var(--ink-3); }
.form-row .field-error { margin: 6px 0 0; font-size: 12px; color: var(--red); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

.token-box {
  background: #f0f7ff;
  border: 1px dashed #bfdbfe;
  border-radius: 10px;
  padding: 12px 14px;
  font-family: var(--mono);
  font-size: 12.5px;
  word-break: break-all;
  color: #1e3a8a;
  margin: 10px 0 4px;
}
.warn-box {
  background: var(--amber-bg);
  border: 1px solid #f5d9a8;
  color: #92400e;
  border-radius: 9px;
  padding: 10px 12px;
  font-size: 12.5px;
  line-height: 1.6;
  margin: 12px 0;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 34px;
  transform: translateX(-50%);
  z-index: 60;
  padding: 10px 18px;
  border-radius: 10px;
  background: rgba(15, 23, 42, .92);
  color: #f1f5f9;
  font-size: 13px;
  box-shadow: 0 12px 30px rgba(15, 23, 42, .3);
  animation: toast-in .18s ease-out;
}
.toast.error { background: rgba(153, 27, 27, .95); }
.toast.success { background: rgba(6, 78, 59, .95); }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- 响应式 ---------- */
@media (max-width: 900px) {
  .sidebar { width: 64px; flex: 0 0 64px; }
  .side-brand span:last-child, .side-foot .muted { display: none; }
  .side-brand { justify-content: center; padding: 20px 0 16px; }
  .nav-item { text-align: center; padding: 11px 0; font-size: 12px; }
  .side-foot { align-items: center; padding: 14px 6px; }
  .content { padding: 22px 16px 50px; }
  .channels-table { min-width: 860px; }
  .table-card { overflow-x: auto; }
  .page-head { flex-direction: column; align-items: flex-start; }
}
