/* ============================================
   短网址系统 - 全站样式
   前台 / 用户中心 / 后台 共用
   ============================================ */

:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #d97706;
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
  --radius: 12px;
  --shadow: 0 2px 10px rgba(15, 23, 42, .06);
  --sidebar-w: 240px;
  --sidebar-w-collapsed: 64px;
  --topbar-h: 56px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { margin: 0 0 12px; line-height: 1.3; }

/* ---------- 前台公共 ---------- */
.site-header {
  background: linear-gradient(135deg, #2563eb, #4f46e5);
  color: #fff;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.site-header .logo { font-size: 20px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.site-header .logo a { color: #fff; }
.site-header .nav { display: flex; gap: 6px; align-items: center; }
.site-header .nav a {
  color: #e0e7ff; padding: 7px 14px; border-radius: 8px; font-size: 14px;
}
.site-header .nav a:hover { background: rgba(255,255,255,.16); color: #fff; text-decoration: none; }
.site-header .nav .btn-outline-light {
  border: 1px solid rgba(255,255,255,.55); padding: 6px 14px; border-radius: 8px;
}

.container { max-width: 980px; margin: 0 auto; padding: 28px 20px 60px; }

/* ---------- 卡片 / 表单 / 按钮 ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 20px;
}
.card h2 { font-size: 17px; display: flex; align-items: center; gap: 8px; }

.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.form-row { display: flex; gap: 12px; flex-wrap: wrap; }
.form-row .form-group { flex: 1; min-width: 150px; }

input[type=text], input[type=url], input[type=password], input[type=number],
textarea, select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
textarea { resize: vertical; min-height: 90px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 18px;
  border: 1px solid transparent;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  transition: background .15s, opacity .15s;
  background: var(--primary); color: #fff;
}
.btn:hover { background: var(--primary-dark); text-decoration: none; }
.btn:disabled { opacity: .6; cursor: not-allowed; }
.btn-block { width: 100%; }
.btn-sm { padding: 5px 12px; font-size: 13px; border-radius: 6px; }
.btn-ghost { background: transparent; color: var(--primary); border-color: #bfdbfe; }
.btn-ghost:hover { background: #eff6ff; }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #b91c1c; }
.btn-success { background: var(--success); }
.btn-success:hover { background: #15803d; }
.btn-outline { background: transparent; color: var(--text); border-color: #cbd5e1; }
.btn-outline:hover { background: #f8fafc; }

/* ---------- 表格 ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; background: #f8fafc; white-space: nowrap; }
tr:hover td { background: #f8fafc; }
td .ellipsis { max-width: 260px; display: inline-block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }

/* ---------- 徽章 ---------- */
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: 12px; line-height: 1.7;
}
.badge-gray { background: #f1f5f9; color: #475569; }
.badge-green { background: #dcfce7; color: #15803d; }
.badge-red { background: #fee2e2; color: #b91c1c; }
.badge-blue { background: #dbeafe; color: #1d4ed8; }
.badge-orange { background: #ffedd5; color: #c2410c; }
.badge-gold { background: #fef3c7; color: #b45309; }

/* ---------- Flash / Toast ---------- */
.flash {
  padding: 11px 16px; border-radius: 10px; margin-bottom: 16px;
  font-size: 14px; display: flex; justify-content: space-between; align-items: center;
}
.flash-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.flash-error { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.flash .close { cursor: pointer; font-weight: 700; padding: 0 4px; }

/* ---------- 弹窗 ---------- */
.modal-mask {
  display: none; position: fixed; inset: 0; z-index: 999;
  background: rgba(15,23,42,.45); align-items: center; justify-content: center; padding: 20px;
}
.modal-mask.show { display: flex; }
.modal {
  background: #fff; border-radius: 14px; max-width: 480px; width: 100%;
  box-shadow: 0 20px 50px rgba(15,23,42,.25); animation: modalIn .18s ease;
}
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 20px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }
@keyframes modalIn { from { transform: translateY(14px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- 结果卡片（新生成） ---------- */
.result-box { display: none; margin-top: 6px; }
.result-box.show { display: block; }
.result-item {
  border: 1px dashed #93c5fd; background: #eff6ff; border-radius: 10px;
  padding: 14px 16px; margin-bottom: 10px;
}
.result-item .link-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.result-item .short-url { font-size: 16px; font-weight: 600; color: var(--primary); word-break: break-all; }
.result-item .meta { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* ---------- 侧边栏布局（用户中心 / 后台 汉堡菜单） ---------- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: #fff;
  border-right: 1px solid var(--border);
  position: fixed; top: 0; bottom: 0; left: 0; z-index: 100;
  transition: width .22s ease, transform .22s ease;
  overflow: hidden;
  display: flex; flex-direction: column;
}
.sidebar-dark { background: #0f172a; border-right: none; }
.sidebar-head {
  height: var(--topbar-h); display: flex; align-items: center;
  padding: 0 18px; gap: 10px; white-space: nowrap;
  border-bottom: 1px solid rgba(148,163,184,.18);
  font-size: 16px; font-weight: 700; color: var(--text);
  flex-shrink: 0;
}
.sidebar-dark .sidebar-head { color: #e2e8f0; border-color: rgba(148,163,184,.14); }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 10px 0; }
.sidebar-nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 18px; color: var(--text); white-space: nowrap;
  font-size: 14px; border-left: 3px solid transparent;
}
.sidebar-nav a:hover { background: #f1f5f9; text-decoration: none; }
.sidebar-dark .sidebar-nav a { color: #cbd5e1; }
.sidebar-dark .sidebar-nav a:hover { background: rgba(148,163,184,.12); color: #fff; }
.sidebar-nav a.active { background: #eff6ff; border-left-color: var(--primary); color: var(--primary); font-weight: 600; }
.sidebar-dark .sidebar-nav a.active { background: rgba(37,99,235,.25); color: #93c5fd; }
.sidebar-nav .nav-icon {
  width: 20px; height: 20px; flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center;
}
.sidebar-nav .nav-icon svg { width: 18px; height: 18px; }
.sidebar-nav .nav-text { overflow: hidden; text-overflow: ellipsis; }

.sidebar-foot { padding: 8px 0; border-top: 1px solid var(--border); flex-shrink: 0; }
.sidebar-dark .sidebar-foot { border-color: rgba(148,163,184,.14); }

.main-wrap { flex: 1; margin-left: var(--sidebar-w); min-width: 0; transition: margin-left .22s ease; }

.topbar {
  height: var(--topbar-h); background: #fff; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px; padding: 0 18px;
  position: sticky; top: 0; z-index: 90;
}
.sidebar-dark .topbar { background: #fff; }
.topbar .burger {
  background: none; border: 1px solid var(--border); border-radius: 8px;
  width: 38px; height: 34px; cursor: pointer; font-size: 16px;
  display: inline-flex; align-items: center; justify-content: center; color: var(--text);
}
.topbar .burger:hover { background: #f1f5f9; }
.topbar .crumb { font-size: 15px; font-weight: 600; }
.topbar .spacer { flex: 1; }
.topbar .user-chip { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }

.content { padding: 22px; }

/* 折叠态（桌面）：只显示图标 */
body.sidebar-collapsed .sidebar { width: var(--sidebar-w-collapsed); }
body.sidebar-collapsed .sidebar-head { padding: 0; justify-content: center; }
body.sidebar-collapsed .sidebar-nav a { padding: 11px 0; justify-content: center; }
body.sidebar-collapsed .sidebar-nav .nav-text,
body.sidebar-collapsed .sidebar-head .head-text,
body.sidebar-collapsed .sidebar-foot .nav-text,
body.sidebar-collapsed .sidebar-foot a span:not(.nav-icon) { display: none; }
body.sidebar-collapsed .sidebar-nav a:hover .nav-text { display: inline; position: absolute; left: 68px; background: #0f172a; color: #fff; padding: 4px 10px; border-radius: 6px; font-size: 12px; z-index: 20; white-space: nowrap; box-shadow: 0 4px 12px rgba(0,0,0,.25); }
body.sidebar-collapsed .main-wrap { margin-left: var(--sidebar-w-collapsed); }

/* 移动端：默认隐藏，汉堡滑出 */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); box-shadow: 4px 0 20px rgba(0,0,0,.1); }
  body.sidebar-open .sidebar { transform: translateX(0); }
  .main-wrap { margin-left: 0; }
  body.sidebar-collapsed .main-wrap { margin-left: 0; }
  body.sidebar-collapsed .sidebar { width: var(--sidebar-w); }
  body.sidebar-collapsed .sidebar-head { padding: 0 18px; justify-content: flex-start; }
  body.sidebar-collapsed .sidebar-nav a { padding: 11px 18px; justify-content: flex-start; }
  body.sidebar-collapsed .sidebar-nav .nav-text { display: inline; }
  body.sidebar-collapsed .sidebar-foot .nav-text { display: inline; }
  .content { padding: 16px; }
  .form-row .form-group { min-width: 100%; }
}

/* 后台看板统计卡 */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat-card {
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow);
}
.stat-card .num { font-size: 26px; font-weight: 700; color: var(--primary); margin-top: 2px; }
.stat-card .label { font-size: 13px; color: var(--muted); }
.stat-card .icon { float: right; font-size: 26px; opacity: .55; }
.stat-card .label-link { font-size: 13px; color: var(--muted); text-decoration: none; }
.stat-card .label-link:hover { color: var(--primary); text-decoration: underline; }
.stat-card .num-warn { color: #dc2626; }

/* 二维码容器 */
.qr-box { text-align: center; padding: 8px 0; }
.qr-box canvas { border-radius: 8px; border: 1px solid var(--border); }

.mt-2 { margin-top: 8px; } .mt-3 { margin-top: 16px; }
.text-muted { color: var(--muted); } .text-right { text-align: right; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.flex { display: flex; gap: 8px; align-items: center; }
/* ---------- 开关（系统设置） ---------- */
.switch-label { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.switch-label input { display: none; }
.switch-label .switch { width: 44px; height: 24px; border-radius: 12px; background: #cbd5e1; position: relative; transition: background .2s; flex: none; }
.switch-label .switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: left .2s; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.switch-label input:checked + .switch { background: #4f46e5; }
.switch-label input:checked + .switch::after { left: 23px; }

/* ---------- 表单提示 ---------- */
.form-tip { font-size: 12px; color: var(--muted, #94a3b8); margin-top: 6px; }
.form-tip code { background: #f1f5f9; padding: 1px 5px; border-radius: 4px; font-size: 12px; }

/* ============================================
   v2.0 新增：暗黑模式 / 套餐卡片 / 设置分组 / 通用组件
   ============================================ */
[data-theme="dark"] {
  --bg: #0f172a;
  --card: #1e293b;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --border: #334155;
  --shadow: 0 2px 12px rgba(0,0,0,.35);
}
[data-theme="dark"] input[type=text], [data-theme="dark"] input[type=url],
[data-theme="dark"] input[type=password], [data-theme="dark"] input[type=number],
[data-theme="dark"] input[type=email], [data-theme="dark"] input[type=date],
[data-theme="dark"] textarea, [data-theme="dark"] select {
  background: #0f172a; color: #e2e8f0; border-color: #475569;
}
[data-theme="dark"] th, [data-theme="dark"] tr:hover td, [data-theme="dark"] .btn-outline:hover,
[data-theme="dark"] .btn-ghost:hover { background: #1e293b; }
[data-theme="dark"] .topbar, [data-theme="dark"] .sidebar { background: #1e293b; }
[data-theme="dark"] .sidebar-dark { background: #0b1120; }
[data-theme="dark"] .auth-card, [data-theme="dark"] .modal, [data-theme="dark"] .stat-card { background: #1e293b; }
[data-theme="dark"] .result-item { background: #172554; border-color: #1d4ed8; }
[data-theme="dark"] .flash { background: #1e293b; }
[data-theme="dark"] .empty-box { background: #1e293b; }
[data-theme="dark"] .plan-card { background: #1e293b; }
[data-theme="dark"] .plan-card .plan-price { color: #93c5fd; }
[data-theme="dark"] .site-header { background: linear-gradient(135deg, #1e3a8a, #312e81); }
[data-theme="dark"] .switch-label .switch { background: #475569; }
[data-theme="dark"] .form-tip code, [data-theme="dark"] .sidebar-nav a:hover { background: #334155; }

/* ---------- 导航徽标 ---------- */
.nav-badge {
  display: inline-block; min-width: 18px; height: 18px; line-height: 18px;
  border-radius: 999px; background: #ef4444; color: #fff;
  font-size: 11px; font-weight: 700; text-align: center; padding: 0 5px;
  margin-left: 6px; font-style: normal;
}

/* ---------- 设置分组 ---------- */
.setting-group {
  border: 1px solid var(--border); border-radius: 12px;
  padding: 16px 18px 18px; margin-bottom: 20px;
}
.setting-group legend {
  font-size: 13px; font-weight: 700; color: var(--primary);
  padding: 0 8px;
}
.opt-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 0; border-bottom: 1px dashed var(--border);
}
.opt-row:last-child { border-bottom: none; }
.opt-row strong { font-size: 14px; }
.opt-row .form-tip { margin-top: 2px; }

/* ---------- 套餐卡片 ---------- */
.plans-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 16px; margin-bottom: 20px;
}
.plan-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 14px; padding: 22px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 12px;
  transition: transform .15s, box-shadow .15s;
}
.plan-card:hover { transform: translateY(-3px); box-shadow: 0 8px 24px rgba(15,23,42,.12); }
.plan-card.is-mine { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
.plan-name { font-size: 16px; font-weight: 700; }
.plan-price { font-size: 26px; font-weight: 800; color: var(--primary); }
.plan-price .per { font-size: 13px; font-weight: 400; color: var(--muted); }
.plan-feats { list-style: none; margin: 0; padding: 0; flex: 1; }
.plan-feats li { padding: 5px 0; font-size: 13px; color: var(--muted); }
.plan-feats li::before { content: '✓ '; color: var(--success); font-weight: 700; }
.plan-action .btn { width: 100%; }

/* ---------- 订单合计 ---------- */
.order-sum { border: 1px dashed var(--border); border-radius: 10px; padding: 12px 14px; margin-top: 10px; }
.order-sum .row { display: flex; justify-content: space-between; font-size: 13px; padding: 3px 0; color: var(--muted); }
.order-sum .row.strong { font-size: 15px; font-weight: 700; color: var(--text); border-top: 1px solid var(--border); padding-top: 8px; margin-top: 4px; }

/* ---------- 空状态 ---------- */
.empty-box {
  background: var(--card); border: 1px dashed var(--border);
  border-radius: 14px; padding: 46px 20px; text-align: center;
  color: var(--muted); margin-bottom: 20px;
}
.empty-box .btn { margin-top: 14px; }

/* ---------- 页面标题 ---------- */
.page-head { margin-bottom: 18px; }
.page-head h2 { margin-bottom: 4px; }

/* ---------- 套餐信息（个人设置） ---------- */
.plan-mine { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
