/* =========================================================
   Apex Panel — 糖果色主题（实色，无渐变）
   浅色为主，[data-theme="dark"] 切换深色。无外部依赖。
   ========================================================= */

:root {
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Code",
    "Menlo", "Consolas", monospace;

  /* 糖果色（实色） */
  --accent: #ff4d7d;          /* 草莓粉 — 主操作 */
  --accent-press: #ec3c6b;
  --accent-soft: #ffe2ec;
  --ok: #10c4a0;              /* 薄荷绿 — 可达 */
  --ok-soft: #d3f6ee;
  --down: #ff5a72;           /* 珊瑚红 — 不可达 / 危险 */
  --down-soft: #ffe0e4;
  --probe: #ff9e21;          /* 糖果橙 — 探测中 */
  --sky: #25c0f4;            /* 天空蓝 */
  --sky-soft: #d8f2fd;

  /* 浅色主题 */
  --bg-0: #fbf3f8;
  --card: #ffffff;
  --text: #2c2436;
  --text-dim: #6c6480;
  --text-faint: #a39bb2;

  --border: #efe5f0;
  --divider: #f1eaf4;
  --chip: #f3eef7;

  --field-bg: #faf6fc;
  --field-border: #e8dded;
  --field-border-focus: var(--accent);

  --row-bg: #fbf7fd;
  --row-bg-hover: #ffffff;

  --shadow-card: 0 14px 34px -18px rgba(120, 70, 130, .34);
  --shadow-soft: 0 10px 24px -16px rgba(120, 70, 130, .3);
  --shadow-row: 0 12px 26px -16px rgba(120, 70, 130, .38);

  --radius: 18px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --ring: 0 0 0 3px var(--accent-soft);
}

[data-theme="dark"] {
  --accent: #ff6b96;
  --accent-press: #ff5285;
  --accent-soft: rgba(255, 107, 150, .18);
  --ok: #22d9b2;
  --ok-soft: rgba(34, 217, 178, .18);
  --down: #ff6b81;
  --down-soft: rgba(255, 107, 129, .18);
  --probe: #ffb03b;
  --sky: #44cdf7;
  --sky-soft: rgba(68, 205, 247, .18);

  --bg-0: #181426;
  --card: #231d33;
  --text: #f2ecf8;
  --text-dim: #b4abc4;
  --text-faint: #837a97;

  --border: #342c47;
  --divider: #2e2740;
  --chip: #2c2540;

  --field-bg: #1d1830;
  --field-border: #3a3250;
  --field-border-focus: var(--accent);

  --row-bg: #211b31;
  --row-bg-hover: #2a2340;

  --shadow-card: 0 20px 44px -22px rgba(0, 0, 0, .62);
  --shadow-soft: 0 14px 30px -20px rgba(0, 0, 0, .55);
  --shadow-row: 0 16px 34px -20px rgba(0, 0, 0, .6);
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font-ui);
  color: var(--text);
  background: var(--bg-0);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
  overflow-x: hidden;
}

.hidden { display: none !important; }
.mono { font-family: var(--font-mono); font-variant-ligatures: none; }

/* ---------- 卡片 ---------- */
.glass {
  background: var(--card);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-card);
}

/* ---------- 品牌标识 ---------- */
.brand { display: flex; align-items: center; gap: 11px; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 11px;
  color: #fff;
  background: var(--accent);
  box-shadow: 0 6px 16px -7px var(--accent);
}
.brand-mark svg { width: 22px; height: 22px; }
.brand-name {
  font-weight: 700;
  font-size: 17px;
  letter-spacing: .2px;
  color: var(--accent);
}
.brand-lg { gap: 14px; margin-bottom: 6px; }
.brand-lg .brand-name { font-size: 22px; }
.brand-sub { font-size: 12.5px; color: var(--text-faint); margin-top: 2px; }

/* ---------- 登录 ---------- */
.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 360px;
  border-radius: var(--radius);
  padding: 32px 30px;
  animation: rise .5s cubic-bezier(.2, .8, .2, 1) both;
}
.login-card .field { margin-top: 22px; }
.login-card .btn-block { margin-top: 20px; }
.login-card .err { margin: 12px 0 0; text-align: center; }

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky;
  top: 14px;
  z-index: 20;
  margin: 14px auto 0;
  max-width: 1040px;
  width: calc(100% - 28px);
  border-radius: var(--radius);
  padding: 12px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.topbar-actions { display: flex; align-items: center; gap: 10px; }

/* ---------- 布局 ---------- */
.container {
  max-width: 1040px;
  margin: 0 auto;
  padding: 22px 14px 60px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}
.card {
  border-radius: var(--radius);
  padding: 24px 24px 22px;
  animation: rise .55s cubic-bezier(.2, .8, .2, 1) both;
}
.container .card:nth-child(2) { animation-delay: .06s; }
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}
.card-head h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: .2px;
  display: flex;
  align-items: center;
  gap: 9px;
}
.card-foot { margin-top: 18px; }
h2 { color: var(--text); }

@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---------- 全局设置 ---------- */
.settings { display: flex; flex-direction: column; }
.setting-row {
  display: grid;
  grid-template-columns: 96px 1fr auto;
  align-items: center;
  gap: 14px;
  padding: 13px 0;
  border-bottom: 1px solid var(--divider);
}
.setting-row:last-child { border-bottom: none; }
.setting-label { font-size: 13px; color: var(--text-faint); font-weight: 600; }
.value { font-size: 13.5px; color: var(--text); word-break: break-all; }
.apikey-value { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.setting-actions { display: flex; gap: 7px; justify-content: flex-end; flex-wrap: wrap; }

.hint {
  margin: 16px 0 0;
  font-size: 12px;
  line-height: 1.7;
  color: var(--text-faint);
  padding: 12px 14px;
  background: var(--sky-soft);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.hint code { background: transparent; padding: 0; color: var(--text-dim); }

code {
  font-family: var(--font-mono);
  background: var(--chip);
  padding: 2px 7px;
  border-radius: 6px;
  font-size: .92em;
}

/* ---------- 徽章 / 胶囊 ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  font-size: 11.5px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  letter-spacing: .2px;
  white-space: nowrap;
}
.badge-muted { background: var(--chip); color: var(--text-faint); }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge.port { font-family: var(--font-mono); background: var(--sky-soft); color: var(--sky); }
.badge.transport { background: var(--chip); color: var(--text-dim); text-transform: lowercase; }
.badge.disabled { background: var(--down-soft); color: var(--down); }

.count-badge {
  font-size: 12px;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--accent);
  background: var(--accent-soft);
  padding: 1px 9px;
  border-radius: 999px;
}

/* ---------- 通道列表 ---------- */
.ch-list { display: flex; flex-direction: column; gap: 11px; }
.ch-row {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) auto auto auto;
  align-items: center;
  gap: 16px;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  background: var(--row-bg);
  border: 1px solid var(--border);
  transition: transform .18s ease, background .18s ease, box-shadow .18s ease, border-color .18s ease;
}
.ch-row:hover {
  background: var(--row-bg-hover);
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: var(--shadow-row);
}
.ch-row.is-disabled { opacity: .55; }

.ch-main { display: flex; align-items: center; gap: 13px; min-width: 0; }
.ch-name { min-width: 0; }
.ch-name .name { font-weight: 650; font-size: 14.5px; display: flex; align-items: center; gap: 8px; }
.ch-sub {
  font-size: 12px;
  color: var(--text-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 3px;
}
.ch-meta { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; justify-content: flex-end; }
.ch-status { display: flex; align-items: center; gap: 8px; min-width: 96px; }
.ch-actions { display: flex; gap: 5px; }

/* 状态点 + 胶囊 */
.status-dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; background: var(--text-faint); }
.status-dot.ok   { background: var(--ok);   animation: pulse-ok 2s infinite; }
.status-dot.down { background: var(--down); box-shadow: 0 0 8px rgba(255, 90, 114, .6); }
.status-dot.probe { background: var(--probe); animation: blink 1s infinite; }
@keyframes pulse-ok {
  0%   { box-shadow: 0 0 0 0 rgba(16, 196, 160, .5); }
  70%  { box-shadow: 0 0 0 7px rgba(16, 196, 160, 0); }
  100% { box-shadow: 0 0 0 0 rgba(16, 196, 160, 0); }
}
@keyframes blink { 50% { opacity: .35; } }

.status-pill { font-size: 12px; font-weight: 600; color: var(--text-faint); }
.status-pill.ok   { color: var(--ok); }
.status-pill.down { color: var(--down); }
.status-pill.probe { color: var(--probe); }

.lat { font-size: 12.5px; color: var(--text-faint); min-width: 58px; text-align: right; }
.lat[data-tier="fast"] { color: var(--ok); }
.lat[data-tier="mid"]  { color: var(--probe); }
.lat[data-tier="slow"] { color: var(--down); }

/* 骨架屏（实色脉冲，无渐变） */
.skeleton {
  height: 60px;
  border-radius: var(--radius-md);
  background: var(--row-bg);
  border: 1px solid var(--border);
  animation: pulse 1.3s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .45; } }

/* 空状态 */
.empty { text-align: center; padding: 42px 20px 36px; color: var(--text-faint); }
.empty svg { width: 56px; height: 56px; color: var(--accent); }
.empty .empty-title { margin: 14px 0 4px; font-size: 15px; font-weight: 600; color: var(--text-dim); }
.empty .empty-sub { font-size: 13px; margin: 0 0 18px; }

/* ---------- 按钮 ---------- */
.btn {
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 9px 16px;
  color: var(--text);
  background: transparent;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  justify-content: center;
  transition: transform .12s ease, box-shadow .18s ease, background .18s ease, border-color .18s ease, opacity .18s;
  white-space: nowrap;
  -webkit-user-select: none;
  user-select: none;
}
.btn:active { transform: translateY(1px) scale(.99); }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }

.btn-primary { color: #fff; background: var(--accent); box-shadow: 0 8px 18px -10px var(--accent); }
.btn-primary:hover { background: var(--accent-press); transform: translateY(-1px); box-shadow: 0 12px 22px -10px var(--accent); }
.btn-plus { font-size: 16px; line-height: 1; margin-top: -1px; }

.btn-ghost { background: var(--field-bg); border-color: var(--field-border); color: var(--text-dim); }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }

.btn-danger { color: var(--down); }
.btn-danger.btn-ghost:hover { border-color: var(--down); color: var(--down); background: var(--down-soft); }
.btn-primary.btn-danger { background: var(--down); box-shadow: 0 8px 18px -10px var(--down); }
.btn-primary.btn-danger:hover { background: #f0485f; box-shadow: 0 12px 22px -10px var(--down); }

.btn-sm { padding: 6px 11px; font-size: 12px; border-radius: 8px; }
.btn-block { width: 100%; padding: 11px; }

/* 行内图标按钮 */
.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 9px;
  color: var(--text-faint);
  background: transparent;
  border: 1px solid transparent;
}
.btn-icon:hover { background: var(--field-bg); border-color: var(--field-border); color: var(--accent); }
.btn-icon.btn-danger:hover { color: var(--down); border-color: var(--down); background: var(--down-soft); }
.btn-icon svg { width: 16px; height: 16px; }

/* 主题切换图标按钮 */
.icon-btn {
  cursor: pointer;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 11px;
  background: var(--field-bg);
  border: 1px solid var(--field-border);
  color: var(--text-dim);
  transition: transform .2s ease, color .18s, border-color .18s;
}
.icon-btn:hover { color: var(--accent); border-color: var(--accent); transform: rotate(-12deg); }
.icon-btn svg { width: 19px; height: 19px; }

/* 按钮 loading */
.btn.is-loading { color: transparent !important; pointer-events: none; position: relative; }
.btn.is-loading::after {
  content: "";
  position: absolute;
  width: 15px; height: 15px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .5);
  border-top-color: #fff;
  animation: spin .6s linear infinite;
}
.btn-ghost.is-loading::after { border-color: var(--field-border); border-top-color: var(--accent); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 表单 ---------- */
.field { display: flex; flex-direction: column; gap: 7px; }
.field-label { font-size: 12.5px; color: var(--text-dim); font-weight: 600; }
input, select {
  width: 100%;
  font-family: inherit;
  font-size: 13.5px;
  color: var(--text);
  padding: 10px 12px;
  background: var(--field-bg);
  border: 1px solid var(--field-border);
  border-radius: var(--radius-sm);
  transition: border-color .16s, box-shadow .16s, background .16s;
  -webkit-appearance: none;
  appearance: none;
}
input::placeholder { color: var(--text-faint); opacity: .7; }
input:focus, select:focus {
  outline: none;
  border-color: var(--field-border-focus);
  box-shadow: var(--ring);
  background: var(--card);
}
select {
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%236c6480' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 34px;
}
[data-theme="dark"] select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23b4abc4' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
}

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-section-label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--text-faint);
  margin: 22px 0 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.form-section-label::after { content: ""; flex: 1; height: 1px; background: var(--divider); }

/* 开关 */
.switch { display: flex; align-items: center; gap: 11px; margin-top: 20px; cursor: pointer; user-select: none; }
.switch input { display: none; }
.switch-track {
  width: 42px; height: 24px;
  border-radius: 999px;
  background: var(--chip);
  position: relative;
  transition: background .2s;
  flex: 0 0 auto;
}
.switch-thumb {
  position: absolute;
  top: 3px; left: 3px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 5px rgba(0, 0, 0, .25);
  transition: transform .2s cubic-bezier(.4, 1.4, .5, 1);
}
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track .switch-thumb { transform: translateX(18px); }
.switch-label { font-size: 13.5px; color: var(--text-dim); font-weight: 500; }

/* ---------- 弹窗 ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(44, 36, 54, .42);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  animation: fade .2s ease both;
}
.modal-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 460px;
  max-height: 90vh;
  overflow: auto;
  border-radius: var(--radius);
  padding: 26px;
  animation: pop .32s cubic-bezier(.2, .9, .25, 1.1) both;
}
.modal-card h2 { margin: 0 0 18px; font-size: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }
.confirm-card { max-width: 400px; }
.confirm-msg { margin: 0 0 6px; color: var(--text-dim); font-size: 14px; line-height: 1.6; }
.confirm-card .confirm-msg + input:not(.hidden) { margin-top: 12px; }

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop {
  from { opacity: 0; transform: translateY(16px) scale(.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ---------- 链接 / 二维码 ---------- */
.link-card { max-width: 380px; text-align: center; }
.qr-frame {
  width: 224px;
  margin: 4px auto 16px;
  padding: 12px;
  background: #fff;
  border-radius: var(--radius-md);
  box-shadow: 0 8px 24px -12px rgba(44, 36, 54, .3);
}
.qr-frame img { width: 100%; height: auto; display: block; border-radius: 6px; }
.link-text {
  display: block;
  text-align: left;
  word-break: break-all;
  font-size: 11.5px;
  line-height: 1.6;
  padding: 12px;
  background: var(--field-bg);
  border: 1px solid var(--field-border);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
}

/* ---------- Toast ---------- */
.toast-wrap {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}
.toast {
  position: relative;
  pointer-events: auto;
  min-width: 220px;
  max-width: 340px;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 13px 16px;
  border-radius: var(--radius-md);
  background: var(--card);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-card);
  font-size: 13.5px;
  color: var(--text);
  overflow: hidden;
  animation: toast-in .35s cubic-bezier(.2, .9, .25, 1.1) both;
}
.toast.out { animation: toast-out .3s ease forwards; }
.toast-icon {
  width: 22px; height: 22px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  font-size: 13px;
  font-weight: 700;
}
.toast.success .toast-icon { background: var(--ok); }
.toast.error .toast-icon   { background: var(--down); }
.toast.info .toast-icon    { background: var(--accent); }
.toast-bar {
  position: absolute;
  left: 0; bottom: 0;
  height: 3px;
  width: 100%;
  transform-origin: left;
}
.toast.success .toast-bar { background: var(--ok); }
.toast.error .toast-bar   { background: var(--down); }
.toast.info .toast-bar    { background: var(--accent); }
@keyframes toast-in  { from { opacity: 0; transform: translateX(120%); } to { opacity: 1; transform: translateX(0); } }
@keyframes toast-out { to { opacity: 0; transform: translateX(120%); } }
@keyframes toast-progress { from { transform: scaleX(1); } to { transform: scaleX(0); } }

.err { color: var(--down); font-size: 13px; min-height: 1.2em; margin: 8px 0 0; }

/* ---------- 响应式 ---------- */
@media (max-width: 720px) {
  .topbar { top: 0; margin-top: 0; width: 100%; border-radius: 0 0 var(--radius) var(--radius); }
  .card { padding: 20px 16px; }
  .setting-row { grid-template-columns: 1fr; gap: 8px; padding: 14px 0; }
  .setting-actions { justify-content: flex-start; }
  .ch-row { grid-template-columns: 1fr; gap: 12px; }
  .ch-meta { justify-content: flex-start; }
  .ch-actions { justify-content: flex-start; width: 100%; }
  .form-grid { grid-template-columns: 1fr; }
  .toast-wrap { left: 14px; right: 14px; top: 14px; }
  .toast { max-width: none; }
}

/* ---------- 无障碍：尊重减弱动效 ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
