/* M4 Task 6：管理后台 SPA 样式——暗色主题 + 移动端自适应。
   色板（任务约定）：背景 #1a1a2e / 卡片 #16213e / 强调 #0f3460 / 危险 #e94560。
   布局：顶栏 Flex + 页签 Flex（≤768px 纵向堆叠）+ 统计卡 auto-fit Grid + 表格横向滚动容器。 */

:root {
  --bg: #1a1a2e;
  --card: #16213e;
  --accent: #0f3460;
  --accent-2: #16477e;
  --danger: #e94560;
  --text: #e8eaf2;
  --muted: #8a91b4;
  --line: #263052;
  --ok: #2ecc8f;
  --warn: #f5a623;
  --input-bg: #0d1130;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.6 "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.muted { color: var(--muted); font-weight: 400; font-size: 12px; }

/* ---------------- 登录页 ---------------- */

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(ellipse at top, #1c2750 0%, var(--bg) 60%);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 32px 28px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .45);
}

.login-card h1 {
  margin: 12px 0 2px;
  font-size: 20px;
  text-align: center;
  letter-spacing: .5px;
}

.login-sub {
  margin: 0 0 22px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

.login-logo {
  width: 56px;
  height: 56px;
  margin: 0 auto;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 1px;
  color: #fff;
}

.login-error {
  margin: 0 0 12px;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(233, 69, 96, .12);
  border: 1px solid rgba(233, 69, 96, .4);
  color: #ff8fa3;
  font-size: 13px;
}

/* ---------------- 表单控件 ---------------- */

.field { margin-bottom: 14px; }

.field label {
  display: block;
  margin-bottom: 5px;
  font-size: 13px;
  color: var(--muted);
}

input[type="text"], input[type="password"], input[type="number"], select {
  width: 100%;
  padding: 9px 11px;
  background: var(--input-bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font: inherit;
  outline: none;
  transition: border-color .15s;
}

input:focus, select:focus { border-color: var(--accent-2); }

.checkbox-row { display: flex; align-items: center; gap: 8px; margin: 4px 0; }
.checkbox-row input { width: auto; }
.checkbox-row span { font-size: 13px; }

/* ---------------- 按钮 ---------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, border-color .15s, opacity .15s;
}

.btn:hover { background: var(--accent); border-color: var(--accent-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent-2);
  color: #fff;
  font-weight: 600;
}
.btn-primary:hover { background: var(--accent-2); }

.btn-danger {
  background: transparent;
  border-color: var(--danger);
  color: #ff8fa3;
}
.btn-danger:hover { background: var(--danger); color: #fff; }

.btn-sm { padding: 4px 10px; font-size: 12px; border-radius: 6px; }
.btn-block { width: 100%; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--text); background: rgba(255, 255, 255, .04); border-color: transparent; }

/* ---------------- 顶栏与页签 ---------------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-brand { display: flex; align-items: center; gap: 10px; min-width: 0; }

.brand-badge {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  flex: none;
}

.brand-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.topbar-user { display: flex; align-items: center; gap: 12px; flex: none; }
.username { color: var(--muted); font-size: 13px; white-space: nowrap; }

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 10px 16px 0;
  max-width: 1220px;
  margin: 0 auto;
  width: 100%;
}

.tab {
  padding: 8px 16px;
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: 9px 9px 0 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  cursor: pointer;
}

.tab:hover { color: var(--text); background: rgba(255, 255, 255, .04); }

.tab.active {
  background: var(--card);
  border-color: var(--line);
  color: var(--text);
  font-weight: 600;
  position: relative;
}

.tab.active::after {
  content: "";
  position: absolute;
  left: 12px;
  right: 12px;
  top: 0;
  height: 2px;
  border-radius: 2px;
  background: var(--accent-2);
}

/* ---------------- 内容区 ---------------- */

.content {
  max-width: 1220px;
  margin: 0 auto;
  padding: 18px 16px 48px;
  width: 100%;
}

.page-title {
  margin: 0 0 14px;
  font-size: 18px;
  font-weight: 600;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}

.toolbar .spacer { flex: 1; }

.toolbar input, .toolbar select { width: auto; min-width: 180px; }

.search-input { flex: 1; min-width: 160px; max-width: 360px; }

/* 统计卡：自适应网格（窄屏自动换列） */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
}

.stat-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px 16px;
}

.stat-card .stat-label { color: var(--muted); font-size: 13px; }

.stat-card .stat-value {
  font-size: 30px;
  font-weight: 700;
  margin-top: 6px;
  line-height: 1.2;
}

.stat-card.danger .stat-value { color: var(--danger); }
.stat-card.accent { border-color: var(--accent-2); }

.stat-foot { margin-top: 10px; color: var(--muted); font-size: 12px; }

/* ---------------- 卡片/面板与表格 ---------------- */

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
}

.panel h3 { margin: 0 0 12px; font-size: 15px; font-weight: 600; }

.table-wrap { overflow-x: auto; border-radius: 10px; border: 1px solid var(--line); }

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 640px;   /* 窄屏改为横向滚动而非挤压 */
}

th, td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  background: rgba(255, 255, 255, .02);
  position: sticky;
  top: 0;
}

tr:last-child td { border-bottom: none; }
tbody tr:hover { background: rgba(255, 255, 255, .03); }

td.wrap { white-space: normal; word-break: break-all; min-width: 140px; }

.row-actions { display: flex; gap: 6px; }

.empty-tip { padding: 32px 16px; text-align: center; color: var(--muted); }

.card-key { font-family: Consolas, "Courier New", monospace; font-size: 13px; }

/* ---------------- IP 并列单元格（迁移 20）----------------
   业主口径：客户端自报 IP 与服务器观测 IP **并列显示**——只有并排看才看得出
   "这个号在挂代理/改路由"。两列各是一个 .ip-cell：上排 IP、下排归属地。
   ⚠ 表示两侧不一致（代理/VPN 嫌疑），语义上挂在「客户端 IP」那一列。 */

.ip-cell { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.45; }

.ip-addr {
  font-family: Consolas, "Courier New", monospace;
  font-size: 12px;
  white-space: nowrap;
}

/* 归属地比 IP 更次要：小一号 + 淡色；查不到时用更淡的斜体，与"有地区"区分开 */
.ip-reg { font-size: 12px; color: var(--fg, #333); white-space: nowrap; }
.ip-reg-none { color: var(--muted); font-style: italic; }

.ip-warn {
  margin-left: 4px;
  color: #d97706;              /* 与 .badge-warn 同色系（琥珀） */
  cursor: help;
  font-size: 12px;
}

/* 卡详情头部的两个 IP 并排（宽弹窗里用横向并列，比表格里的上下两行更好读） */
.ip-pair-row { display: flex; flex-wrap: wrap; gap: 20px; margin: 8px 0 12px; }
.ip-pair-item { display: flex; align-items: baseline; gap: 8px; }
.ip-pair-label { font-size: 12px; color: var(--muted); }

/* ---------------- 徽章 ---------------- */

.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  line-height: 1.6;
  border: 1px solid transparent;
}

.badge-ok     { background: rgba(46, 204, 143, .12); color: var(--ok);     border-color: rgba(46, 204, 143, .35); }
.badge-danger { background: rgba(233, 69, 96, .14);  color: #ff8fa3;      border-color: rgba(233, 69, 96, .4); }
.badge-warn   { background: rgba(245, 166, 35, .12); color: var(--warn);  border-color: rgba(245, 166, 35, .35); }
.badge-muted  { background: rgba(138, 145, 180, .14); color: var(--muted); border-color: rgba(138, 145, 180, .35); }

/* ---------------- 分页 ---------------- */

.pager {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 13px;
}

/* ---------------- Toast（右下角，3s 自动消失） ---------------- */

.toast-box {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
  max-width: min(360px, calc(100vw - 32px));
}

.toast {
  padding: 11px 14px;
  border-radius: 10px;
  background: var(--card);
  border: 1px solid var(--line);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .5);
  font-size: 13px;
  animation: toast-in .18s ease-out;
  word-break: break-all;
}

.toast.err   { border-color: rgba(233, 69, 96, .55);  color: #ff8fa3; }
.toast.ok    { border-color: rgba(46, 204, 143, .5);  color: var(--ok); }

.toast.fade { opacity: 0; transition: opacity .3s; }

@keyframes toast-in {
  from { transform: translateY(8px); opacity: 0; }
  to   { transform: translateY(0);  opacity: 1; }
}

/* ---------------- 模态框（确认/表单共用） ---------------- */

.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(8, 10, 24, .66);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 90;
}

.modal {
  width: 100%;
  max-width: 440px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, .55);
  max-height: 86vh;
  overflow-y: auto;
}

.modal h3 { margin: 0 0 10px; font-size: 16px; }

.modal .modal-msg { color: var(--muted); margin: 0 0 16px; white-space: pre-wrap; word-break: break-all; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

.gen-result {
  background: var(--input-bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  max-height: 220px;
  overflow-y: auto;
  font-family: Consolas, "Courier New", monospace;
  font-size: 12px;
  line-height: 1.7;
  word-break: break-all;
}

/* 生成结果弹窗放宽宽度上限 */
.modal.wide { max-width: 560px; }

/* ---------------- 加载与骨架 ---------------- */

.loading-tip { padding: 40px 0; text-align: center; color: var(--muted); }

/* ---------------- 移动端（≤768px）：页签纵向堆叠、顶栏紧凑 ---------------- */

@media (max-width: 768px) {
  .tabs {
    flex-direction: column;
    gap: 2px;
    padding: 8px 10px 0;
  }

  .tab, .tab.active {
    border: 1px solid transparent;
    border-radius: 8px;
    text-align: left;
    width: 100%;
  }

  .tab.active {
    border-color: var(--line);
    background: var(--accent);
  }

  .tab.active::after { display: none; }

  .brand-title { font-size: 13px; }
  .topbar { padding: 10px 12px; }
  .content { padding: 12px 10px 40px; }

  .toolbar input, .toolbar select { min-width: 0; width: 100%; }
  .toolbar .btn { width: 100%; }
  .toolbar { display: grid; grid-template-columns: 1fr; }
  .toolbar .spacer { display: none; }

  .stat-card .stat-value { font-size: 24px; }
  .login-card { padding: 26px 20px; }
}
