/* ============================================================
   短链管理系统 - 全局样式
   ============================================================ */
:root {
  --primary: #2b6cb0;
  --primary-dark: #1e4e7b;
  --primary-light: #eaf2fb;
  --success: #2e9e5b;
  --danger: #d64545;
  --warning: #d9822b;
  --text: #1a1b1c;
  --text-sub: #6b7280;
  --bg: #f4f3ee;
  --card: #ffffff;
  --border: #e4e3dd;
  --radius: 12px;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'PingFang SC', 'Microsoft YaHei', 'Segoe UI', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}

/* ================= 认证页（登录/安装） ================= */
.auth-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(160deg, #eef4fb 0%, #f4f3ee 60%);
}
.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--card);
  border-radius: 16px;
  padding: 32px 28px;
  box-shadow: var(--shadow);
}
.auth-logo {
  width: 56px; height: 56px;
  margin: 0 auto 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 30px;
  background: var(--primary-light);
  border-radius: 14px;
}
.auth-title { font-size: 26px; font-weight: 700; text-align: center; margin: 0 0 18px; color: var(--primary-dark); }
.auth-sub { font-size: 13px; color: var(--text-sub); text-align: center; margin: 0 0 20px; }
.auth-ok { text-align: center; padding: 24px 0; font-size: 15px; color: var(--success); }

/* 记住密码 */
.remember-row { margin-bottom: 14px; }
.remember-label {
  display: inline-flex !important;
  align-items: center;
  gap: 6px;
  font-size: 13.5px !important;
  color: var(--text) !important;
  cursor: pointer;
  margin-bottom: 0 !important;
}
.remember-label input[type="checkbox"] {
  width: 15px; height: 15px;
  accent-color: var(--primary);
  cursor: pointer;
}

.form-item { margin-bottom: 14px; }
.form-item label { display: block; font-size: 13px; color: var(--text-sub); margin-bottom: 5px; }
.form-item input[type="text"],
.form-item input[type="password"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  background: #fafaf8;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.form-item input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(43, 108, 176, 0.12);
  background: #fff;
}

.captcha-row { display: flex; gap: 10px; }
.captcha-row input { flex: 1; }
.captcha-img {
  width: 170px; height: 52px;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 9px 18px;
  font-size: 14px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  background: #e8e8e4;
  color: var(--text);
  transition: opacity .15s, background .15s;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { opacity: .88; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; border-radius: 6px; }
.btn-block { width: 100%; padding: 11px; font-size: 15px; margin-top: 4px; }
.btn-ghost { background: transparent; color: var(--primary); }
.btn-ghost:hover { background: var(--primary-light); }

/* ================= 后台布局（左菜单 + 右内容） ================= */
.layout {
  display: flex;
  min-height: 100vh;
}
.sidebar {
  width: 216px;
  background: #fff;
  border-right: 1px solid var(--border);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  transition: width .2s ease, transform .2s ease;
  overflow: hidden;
  z-index: 90;
}
.sidebar.collapsed { width: 60px; }
.sidebar-head {
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 17px;
  font-weight: 700;
  color: var(--primary-dark);
  text-decoration: none;
  letter-spacing: .5px;
  white-space: nowrap;
  cursor: default;
}
.brand .logo {
  width: 34px; height: 34px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  border-radius: 9px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 18px;
  box-shadow: 0 2px 6px rgba(43, 108, 176, 0.3);
  flex-shrink: 0;
}
.hamburger {
  border: none;
  background: none;
  font-size: 19px;
  cursor: pointer;
  color: var(--text-sub);
  width: 36px; height: 36px;
  border-radius: 8px;
  flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
}
.hamburger:hover { background: #f0efea; color: var(--text); }
.sidebar-nav {
  flex: 1;
  padding: 10px 8px;
  overflow-y: auto;
  overflow-x: hidden;
}
.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--text-sub);
  font-size: 14px;
  white-space: nowrap;
  margin-bottom: 3px;
  transition: background .12s;
}
.sidebar-nav a .nav-icon { font-size: 16px; flex-shrink: 0; width: 22px; text-align: center; }
.sidebar-nav a:hover { background: #f5f7fa; color: var(--text); }
.sidebar-nav a.active { background: var(--primary-light); color: var(--primary); font-weight: 600; }
/* 折叠态：只显示图标 */
.sidebar.collapsed .sidebar-nav a { justify-content: center; padding: 10px 0; }
.sidebar.collapsed .sidebar-nav a .nav-text { display: none; }
.sidebar.collapsed .sidebar-head .brand-text { display: none; }
.sidebar.collapsed .sidebar-head { justify-content: center; padding: 0; }

/* 移动端遮罩 */
.sidebar-mask {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 85;
}
.sidebar-mask.show { display: block; }

.main-wrap {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.topbar {
  background: #fff;
  border-bottom: 1px solid var(--border);
  height: 54px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  flex-shrink: 0;
}
.topbar-title { font-size: 15px; font-weight: 600; flex: 1; min-width: 0; }
.topbar-user {
  display: flex; align-items: center; gap: 10px;
  flex-shrink: 0;
  margin-left: auto;
}
.user-name { font-size: 13.5px; color: var(--text); font-weight: 600; }

/* 右上角用户下拉菜单 */
.user-menu { position: relative; }
.user-btn {
  display: flex; align-items: center; gap: 8px;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 10px;
  padding: 6px 12px 6px 6px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.user-btn:hover { border-color: var(--primary); background: var(--primary-light); }
.user-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}
.caret { font-size: 11px; color: var(--text-sub); }
.user-dropdown {
  display: none;
  position: absolute;
  right: 0; top: calc(100% + 6px);
  min-width: 158px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  padding: 5px;
  z-index: 1200;
}
.user-dropdown.open { display: block; }
.ud-item {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 12px;
  font-size: 13.5px;
  color: var(--text);
  text-decoration: none;
  border-radius: 7px;
  white-space: nowrap;
}
.ud-item:hover { background: var(--primary-light); color: var(--primary); }
.ud-item .ud-icon { font-size: 14px; }

.main {
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 18px 16px 60px;
  box-sizing: border-box;
}
.view { display: none; }
.view.active { display: block; }

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}
.page-title { font-size: 19px; font-weight: 600; margin: 0; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

/* 工具栏（搜索 + 添加按钮） */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 14px;
}
.search-box {
  display: flex;
  flex: 1;
  min-width: 220px;
  max-width: 380px;
}
.search-box input {
  flex: 1;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px 0 0 8px;
  font-size: 14px;
  outline: none;
  background: #fafaf8;
}
.search-box input:focus { border-color: var(--primary); background: #fff; }
.search-box .btn { border-radius: 0 8px 8px 0; }

/* ================= 统计卡片 ================= */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}
.stat-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  border-left: 4px solid var(--primary);
}
.stat-card .label { font-size: 13px; color: var(--text-sub); }
.stat-card .value {
  font-size: 30px;
  font-weight: 700;
  margin-top: 4px;
  color: var(--text);
}
.stat-card .sub { font-size: 12px; color: var(--text-sub); margin-top: 2px; }

.dash-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 14px;
}
.chart-card { padding: 14px 16px; }
.chart-card .chart-title { font-size: 15px; font-weight: 600; margin-bottom: 8px; }
.chart-box { width: 100%; height: 260px; }
.rank-list { margin: 0; padding: 0; list-style: none; }
.rank-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 4px;
  border-bottom: 1px solid #f0efea;
}
.rank-list li:last-child { border-bottom: none; }
.rank-no {
  width: 22px; height: 22px;
  border-radius: 6px;
  background: #eceef2;
  color: var(--text-sub);
  font-size: 12px;
  font-weight: 600;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.rank-no.top { background: #f7d98a; color: #7a5200; }
.rank-info { flex: 1; min-width: 0; }
.rank-name {
  font-size: 13.5px;
  font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.rank-meta { font-size: 12px; color: var(--text-sub); }
.rank-cnt { font-size: 14px; font-weight: 700; color: var(--primary); flex-shrink: 0; }

/* ================= 表格 ================= */
.table-wrap {
  overflow-x: auto;
  margin-bottom: 12px;
  -webkit-overflow-scrolling: touch;
}
table.tbl {
  width: 100%;
  border-collapse: collapse;
  /* min-width 由 JS 按列设置动态计算，避免窄列被撑宽 */
}
.tbl th, .tbl td {
  padding: 9px 10px;
  text-align: left;
  border-bottom: 1px solid #f0efea;
  font-size: 13.5px;
  vertical-align: middle;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tbl th {
  color: var(--text-sub);
  font-weight: 600;
  font-size: 12.5px;
  background: #fafaf8;
  white-space: nowrap;
}
.tbl tbody tr { transition: background .12s; }
.tbl tbody tr:hover { background: #f7f9fc; }
.tbl tbody tr.clickable { cursor: pointer; }
.cell-ellipsis {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.alias-tag {
  font-family: 'Consolas', 'Menlo', monospace;
  background: var(--primary-light);
  color: var(--primary-dark);
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 1px;
  white-space: nowrap;
}
.qr-link {
  color: var(--primary);
  text-decoration: underline;
  cursor: pointer;
  font-size: 13px;
  white-space: nowrap;
}
.qr-link:hover { color: var(--primary-dark); }
.op-cell { white-space: nowrap; }
.op-cell .btn { margin-right: 8px; margin-bottom: 3px; }
.op-cell .btn:last-child { margin-right: 0; }
.op-cell .btn .bi { font-size: 13px; margin-right: 3px; }

/* 列设置 */
.col-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 10px;
}
.col-chk {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13.5px;
  cursor: pointer;
  user-select: none;
}
.col-chk:hover { border-color: var(--primary); background: var(--primary-light); }
.col-chk input { accent-color: var(--primary); cursor: pointer; }

/* ================= 移动端适配 ================= */
@media (max-width: 767px) {
  /* 侧边栏改为抽屉式 */
  .sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    width: 216px;
    transform: translateX(-100%);
    box-shadow: 4px 0 20px rgba(0,0,0,.12);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar.collapsed { width: 216px; }
  .sidebar.collapsed .sidebar-nav a { justify-content: flex-start; padding: 10px 12px; }
  .sidebar.collapsed .sidebar-nav a .nav-text { display: inline; }
  .sidebar.collapsed .sidebar-head .brand-text { display: inline; }
  .sidebar.collapsed .sidebar-head { justify-content: space-between; padding: 0 12px; }
  .main-wrap { width: 100%; }
  .hide-sm { display: none; }
  /* 操作按钮移动端只显示图标 */
  .op-cell .btn .bt { display: none; }
  .op-cell .btn { padding: 5px 8px; }
  .op-cell .btn .bi { margin-right: 0; font-size: 14px; }
  .topbar { padding: 0 10px; }
}

/* ================= 分页 ================= */
.pager {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
  color: var(--text-sub);
}
.pager-info { white-space: nowrap; }
.pager-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pager-right select {
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  background: #fff;
  cursor: pointer;
}
.pager .btn {
  padding: 6px 12px;
  font-size: 13px;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 6px;
}
.pager .btn:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); background: var(--primary-light); }

/* ================= 弹窗（统一居中） ================= */
.modal-mask {
  position: fixed;
  left: 0; top: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-mask.show {
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
}
.modal {
  position: relative;
  left: auto;
  top: auto;
  right: auto;
  bottom: auto;
  transform: none;
  background: #fff;
  border-radius: 14px;
  width: 100%;
  max-width: 560px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  margin: auto; /* 双保险：flex 未生效时仍水平居中 */
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.18);
  animation: modalIn .18s ease-out;
}
.modal-lg { max-width: 720px; }
.modal-sm { max-width: 420px; }
@keyframes modalIn {
  from { opacity: 0; transform: translateY(14px) scale(.98); }
  to { opacity: 1; transform: none; }
}
.modal-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-head .mt { font-size: 16px; font-weight: 600; }
.modal-close {
  border: none; background: none;
  font-size: 22px; line-height: 1;
  color: var(--text-sub);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
}
.modal-close:hover { background: #f0efea; color: var(--text); }
.modal-body {
  padding: 16px 18px;
  overflow-y: auto;
  font-size: 14px;
}
.modal-foot {
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* 详情键值 */
.detail-list { margin: 0; padding: 0; list-style: none; }
.detail-list li {
  display: flex;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid #f2f1ec;
  align-items: flex-start;
}
.detail-list li:last-child { border-bottom: none; }
.detail-list .k {
  flex-shrink: 0;
  width: 92px;
  color: var(--text-sub);
  font-size: 13px;
}
.detail-list .v {
  flex: 1;
  min-width: 0;
  font-size: 13.5px;
  word-break: break-all;
}
.short-url-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--primary-light);
  border-radius: 8px;
  padding: 8px 10px;
  margin: 10px 0;
}
.short-url-box code {
  flex: 1;
  min-width: 0;
  word-break: break-all;
  color: var(--primary-dark);
  font-size: 13.5px;
}

/* ================= 二维码分享弹窗 ================= */
.qr-wrap {
  text-align: center;
  padding: 8px 0 2px;
}
.qr-box {
  display: inline-block;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  box-shadow: var(--shadow);
}
.qr-box canvas, .qr-box img { display: block; width: 200px; height: 200px; }
.qr-hint { font-size: 13px; color: var(--text-sub); margin: 10px 0 4px; }
.qr-title { font-size: 15px; font-weight: 600; margin: 12px 0 2px; }
.qr-foot {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 14px;
}

/* ================= Toast（页面中央提示） ================= */
.toast {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 3000;
  background: rgba(20, 22, 26, 0.92);
  color: #fff;
  padding: 14px 26px;
  border-radius: 12px;
  font-size: 14.5px;
  max-width: 86vw;
  text-align: center;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s;
  word-break: break-all;
}
.toast.show { opacity: 1; }
.toast.ok { background: rgba(46, 158, 91, 0.95); }
.toast.err { background: rgba(214, 69, 69, 0.95); }

/* 居中确认框 */
.confirm-box { text-align: center; padding: 8px 4px; }
.confirm-box .icon { font-size: 40px; margin-bottom: 8px; }
.confirm-box .msg { font-size: 15px; margin-bottom: 18px; line-height: 1.6; word-break: break-all; }

/* ================= 空状态 ================= */
.empty {
  text-align: center;
  padding: 36px 16px;
  color: var(--text-sub);
  font-size: 13.5px;
}
.empty .icon { font-size: 34px; margin-bottom: 8px; }

/* 页脚 */
.foot {
  text-align: center;
  color: var(--text-sub);
  font-size: 12px;
  padding: 20px 0 30px;
}

/* 加载中 */
.loading {
  text-align: center;
  padding: 30px;
  color: var(--text-sub);
  font-size: 13.5px;
}
.loading::before {
  content: '';
  display: inline-block;
  width: 18px; height: 18px;
  margin-right: 8px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  vertical-align: -3px;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
