/* 网站数据统计与营销分析平台 - 全站样式（纯手写，无 UI 框架） */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #2563eb;
  --primary-d: #1d4ed8;
  --primary-l: #eff6ff;
  --bg: #f4f6fa;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --up: #e11d48;
  --down: #0d9488;
  --radius: 10px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
h1, h2, h3, h4 { font-weight: 600; }

/* ---------------- 布局 ---------------- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 196px;
  flex: 0 0 196px;
  background: #fff;
  border-right: 1px solid var(--border);
  position: fixed;
  top: 0; bottom: 0; left: 0;
  display: flex;
  flex-direction: column;
  z-index: 20;
}

.logo {
  padding: 17px 20px;
  font-size: 16px;
  font-weight: 700;
  color: var(--primary);
  border-bottom: 1px solid var(--border);
  letter-spacing: .5px;
}
.logo small { display: block; font-size: 11px; color: var(--muted); font-weight: 400; letter-spacing: 0; }

.nav { flex: 1; padding: 8px 0; overflow-y: auto; }
.nav a {
  display: block;
  padding: 10px 20px;
  color: #374151;
  border-left: 3px solid transparent;
  transition: background .15s;
}
.nav a:hover { background: #f8fafc; }
.nav a.active {
  background: var(--primary-l);
  color: var(--primary);
  border-left-color: var(--primary);
  font-weight: 600;
}

.side-foot {
  border-top: 1px solid var(--border);
  padding: 12px 20px;
  font-size: 13px;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.side-foot a { color: var(--primary); }
.side-foot a:hover { text-decoration: underline; }

.main { flex: 1; margin-left: 196px; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: 58px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 20px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.tb-label { color: var(--muted); font-size: 13px; }
.tb-select, .tb-input, .form-inline input, .form-inline select {
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0 10px;
  font-size: 13px;
  color: var(--text);
  background: #fff;
  outline: none;
}
.tb-select:focus, .tb-input:focus { border-color: var(--primary); }
.tb-select { min-width: 170px; }
.tb-right { margin-left: auto; display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }

.content { padding: 18px 20px 48px; }

/* ---------------- 通用组件 ---------------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 16px;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.card-head h3 { font-size: 15px; }
.card-head .sub { color: var(--muted); font-size: 12px; }

.btn {
  height: 32px;
  padding: 0 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}
.btn:hover { border-color: #cbd5e1; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-d); }
.btn-danger { color: var(--up); border-color: #fecdd3; }
.btn-sm { height: 26px; padding: 0 10px; font-size: 12px; }

.tabs { display: flex; gap: 6px; }
.tab {
  height: 28px; padding: 0 12px; border-radius: 6px;
  border: 1px solid var(--border); background: #fff; cursor: pointer;
  font-size: 13px; color: var(--muted);
}
.tab.active { background: var(--primary-l); border-color: #bfdbfe; color: var(--primary); font-weight: 600; }

.grid-2 { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }

.chart { width: 100%; height: 300px; }
.chart-sm { width: 100%; height: 240px; }

.empty { color: var(--muted); text-align: center; padding: 26px 0; font-size: 13px; }

/* ---------------- 指标卡 ---------------- */
.metrics { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 14px; margin-bottom: 16px; }
.metric {
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px;
}
.metric .m-label { color: var(--muted); font-size: 12px; }
.metric .m-value { font-size: 24px; font-weight: 700; margin: 4px 0 2px; letter-spacing: -.4px; }
.metric .m-sub { font-size: 12px; color: var(--muted); }
.cmp-up { color: var(--up); font-weight: 600; }
.cmp-down { color: var(--down); font-weight: 600; }
.cmp-flat { color: var(--muted); }
.cmp-yest { color: var(--muted); }

/* ---------------- 表格 ---------------- */
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--border); }
.table th { color: var(--muted); font-weight: 500; background: #fafbfc; white-space: nowrap; }
.table tbody tr:hover { background: #fafbfc; }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table .path { max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table-wrap { overflow-x: auto; }

/* ---------------- 列表 TOP ---------------- */
.toplist { list-style: none; }
.toplist li {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 0; border-bottom: 1px dashed #f1f3f7;
}
.toplist li:last-child { border-bottom: none; }
.toplist .rank {
  width: 18px; height: 18px; flex: 0 0 18px; border-radius: 4px;
  background: #f1f5f9; color: var(--muted);
  font-size: 11px; display: flex; align-items: center; justify-content: center;
}
.toplist .rank.top3 { background: var(--primary-l); color: var(--primary); font-weight: 700; }
.toplist .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toplist .val { color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------------- 新老访客 ---------------- */
.newold .no-row { display: flex; justify-content: space-between; font-size: 13px; margin-top: 10px; }
.newold .no-row b { font-size: 15px; }
.bar { height: 7px; border-radius: 4px; background: #f1f5f9; margin-top: 6px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--primary); border-radius: 4px; }
.bar-alt i { background: #93c5fd; }

/* ---------------- 实时 ---------------- */
.realtime-card { display: flex; align-items: center; gap: 24px; }
.rt-num { display: flex; align-items: baseline; gap: 10px; }
.rt-num span { font-size: 46px; font-weight: 700; color: var(--primary); line-height: 1; letter-spacing: -1px; }
.rt-num small { color: var(--muted); font-size: 13px; }
.rt-tip { color: var(--muted); font-size: 12px; }

/* ---------------- 分页 / 工具条 ---------------- */
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar .spacer { margin-left: auto; }
/* 明细筛选栏（参考 51.la 访问明细） */
.filters { border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; margin-bottom: 14px; background: #f8fafc; }
.filters .f-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.filters .f-row + .f-row { margin-top: 10px; }
.filters .tb-label { min-width: 68px; text-align: right; }
.filters .tb-input { height: 30px; border: 1px solid var(--border); border-radius: 6px; padding: 0 10px; font-size: 13px; background: #fff; }
.filters .tb-input:focus { border-color: var(--primary); outline: none; }
.pager { display: flex; align-items: center; gap: 10px; justify-content: flex-end; margin-top: 14px; font-size: 13px; color: var(--muted); }

/* ---------------- 表单 ---------------- */
.form-inline { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.form-inline input { min-width: 220px; }

.code-box { position: relative; }
.code-box textarea {
  width: 100%; height: 62px; resize: vertical;
  font-family: Consolas, Monaco, "Courier New", monospace;
  font-size: 12.5px; line-height: 1.6;
  border: 1px solid var(--border); border-radius: 6px;
  padding: 10px 12px; background: #f8fafc; color: #334155;
  outline: none;
}

.badge { display: inline-block; padding: 1px 8px; border-radius: 20px; font-size: 12px; }
.badge-on { background: #ecfdf5; color: #047857; }
.badge-off { background: #f3f4f6; color: var(--muted); }

.hint { color: var(--muted); font-size: 12px; margin-top: 8px; line-height: 1.7; }
.hint code { background: #f1f5f9; padding: 1px 5px; border-radius: 4px; font-size: 12px; }

/* ---------------- 登录页 ---------------- */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(150deg, #eff6ff 0%, #f4f6fa 55%, #eef2ff 100%);
  padding: 20px;
}
.login-card {
  width: 100%; max-width: 380px; background: #fff;
  border: 1px solid var(--border); border-radius: 14px;
  padding: 32px 30px; box-shadow: 0 12px 32px rgba(15, 23, 42, .07);
}
.login-card h1 { font-size: 20px; margin-bottom: 4px; }
.login-card .login-sub { color: var(--muted); font-size: 13px; margin-bottom: 22px; }
.login-field { margin-bottom: 14px; }
.login-field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.login-field input {
  width: 100%; height: 40px; border: 1px solid var(--border); border-radius: 8px;
  padding: 0 12px; font-size: 14px; outline: none;
}
.login-field input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .1); }
.login-btn {
  width: 100%; height: 42px; margin-top: 8px;
  background: var(--primary); color: #fff; border: none; border-radius: 8px;
  font-size: 15px; cursor: pointer;
}
.login-btn:hover { background: var(--primary-d); }
.login-btn:disabled { opacity: .65; cursor: default; }
.login-err { color: var(--up); font-size: 13px; min-height: 20px; margin-top: 10px; }

/* ---------------- 轻提示 ---------------- */
.toast {
  position: fixed; left: 50%; top: 74px; transform: translateX(-50%);
  background: #1f2937; color: #fff; padding: 9px 18px; border-radius: 8px;
  font-size: 13px; z-index: 999; opacity: 0; transition: opacity .2s, top .2s;
  pointer-events: none; max-width: 80vw;
}
.toast.show { opacity: .95; top: 82px; }

@media (max-width: 1280px) {
  .metrics { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 1080px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
  .sidebar { width: 62px; flex: 0 0 62px; }
  .sidebar .logo { padding: 16px 8px; font-size: 12px; text-align: center; }
  .sidebar .logo small, .side-foot span { display: none; }
  .nav a { padding: 11px 6px; text-align: center; font-size: 12px; }
  .main { margin-left: 62px; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ---------- 访客详细信息弹窗 ---------- */
.vicon { cursor: pointer; font-size: 14px; opacity: .65; }
.vicon:hover { opacity: 1; transform: scale(1.15); }
.modal-mask { position: fixed; inset: 0; background: rgba(15,23,42,.45); z-index: 100; display: flex; align-items: flex-start; justify-content: center; padding: 48px 16px; overflow: auto; }
.modal-box { background: var(--bg, #fff); border-radius: 10px; box-shadow: 0 12px 40px rgba(0,0,0,.22); width: 860px; max-width: 100%; padding: 18px 22px 22px; }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 14px; }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-head .sub { color: var(--muted, #64748b); font-size: 12px; }
.modal-close { border: 0; background: transparent; font-size: 16px; cursor: pointer; color: var(--muted, #64748b); padding: 4px 8px; }
.modal-close:hover { color: var(--text, #0f172a); }
.modal-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 16px; }
@media (max-width: 720px) { .modal-grid { grid-template-columns: 1fr; } }
.modal-sec { border: 1px solid var(--border, #e2e8f0); border-radius: 8px; padding: 10px 12px; }
.modal-sec h4 { margin: 0 0 8px; font-size: 13px; }
.modal-sec .kv { display: flex; gap: 8px; font-size: 12px; line-height: 1.9; }
.modal-sec .kv span { color: var(--muted, #64748b); white-space: nowrap; min-width: 96px; }
.modal-sec .kv b { font-weight: 500; word-break: break-all; }
.modal-sec.trail { margin-top: 4px; }
.modal-sec.trail .table-wrap { max-height: 320px; overflow: auto; }
.modal-mask[hidden] { display: none; }
