:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --fg: #1f2328;
  --muted: #6b7280;
  --border: #e5e7eb;
  --accent: #4f46e5;
  --accent-strong: #4338ca;
  --danger: #dc2626;
  --ok: #16a34a;
  --warn: #d97706;
}

* { box-sizing: border-box; }
/* 保证 hidden 属性不被下面各元素的 display 规则覆盖 */
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--fg);
  font-size: 14px;
  line-height: 1.6;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* login */
.login-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 2rem;
  width: 100%;
  max-width: 20rem;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}
.login-card h1 { margin: 0 0 0.5rem; font-size: 1.3rem; }
.err { color: var(--danger); font-size: 0.85rem; margin: 0; min-height: 1.2em; }

/* layout */
.admin-body { height: 100vh; overflow: hidden; }
.app { display: flex; height: 100vh; }
.side {
  width: 13rem;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.side-brand { padding: 1rem 1.25rem; font-weight: 700; font-size: 1.05rem; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.nav-toggle { display: none; }
.side-nav { display: flex; flex-direction: column; padding: 0.5rem 0; flex: 1; }
.side-nav a {
  padding: 0.55rem 1.25rem;
  color: var(--muted);
  cursor: pointer;
  border-right: 2px solid transparent;
}
.side-nav a:hover { color: var(--fg); text-decoration: none; background: #f3f4f6; }
.side-nav a.active { color: var(--accent); border-right-color: var(--accent); font-weight: 600; }
.side-foot { padding: 1rem 1.25rem; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 0.6rem; }

.main { flex: 1; min-width: 0; overflow-y: auto; padding: 1.5rem; }
.view { width: 100%; }

.toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.toolbar h2 { margin: 0; font-size: 1.2rem; }

/* cards (stats) */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr)); gap: 0.75rem; margin-bottom: 1.25rem; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 1rem; }
.card-num { font-size: 1.6rem; font-weight: 700; }
.card-label { color: var(--muted); font-size: 0.85rem; }

/* table */
.table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.table th, .table td { text-align: left; padding: 0.6rem 0.85rem; border-bottom: 1px solid var(--border); }
.table th { background: #f9fafb; color: var(--muted); font-weight: 600; font-size: 0.85rem; }
.table tr:last-child td { border-bottom: none; }
.badge { display: inline-block; padding: 0 0.45rem; border-radius: 4px; background: #e5e7eb; color: var(--muted); font-size: 0.75rem; margin-left: 0.5rem; }
.badge.ok { background: #dcfce7; color: var(--ok); }
.badge.warn { background: #fef3c7; color: var(--warn); }
.badge.danger { background: #fee2e2; color: var(--danger); }

/* buttons */
.btn {
  font: inherit;
  font-size: 0.85rem;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--fg);
  border-radius: 6px;
  padding: 0.4rem 0.85rem;
  cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-strong); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { border-color: var(--danger); }
.btn-ghost { color: var(--muted); }
.btn-sm { padding: 0.2rem 0.55rem; font-size: 0.78rem; }

/* inputs */
input, textarea, select {
  font: inherit;
  color: var(--fg);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem 0.65rem;
  width: 100%;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); }
label { display: block; color: var(--muted); font-size: 0.82rem; margin-bottom: 0.25rem; }
.field { margin-bottom: 0.85rem; }
.field-row { display: flex; gap: 0.85rem; }
.field-row > div { flex: 1; }
.check { display: flex; align-items: center; gap: 0.5rem; }
.check input { width: auto; }

/* post editor */
.editor { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 1.25rem; margin-top: 1rem; }
.editor-panes { display: flex; gap: 1rem; margin: 0.85rem 0; }
.editor-panes textarea, .editor-panes .preview {
  flex: 1;
  min-width: 0;
  height: 22rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.8rem 1rem;
  overflow-y: auto;
}
.editor-panes textarea { resize: vertical; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 0.88rem; }
.preview { background: #fff; }
.preview img { max-width: 100%; }
.preview pre { background: #f6f8fa; padding: 0.8rem; border-radius: 6px; overflow-x: auto; }
.preview code { background: #f6f8fa; padding: 0.1em 0.35em; border-radius: 4px; }
.preview blockquote { margin: 0.6rem 0; padding-left: 0.9rem; border-left: 3px solid #d1d5db; color: #6b7280; }
.editor-foot { display: flex; gap: 0.6rem; align-items: center; justify-content: flex-end; }
.editor-status { margin-right: auto; color: var(--muted); }

/* comments */
.comment-row { border-bottom: 1px solid var(--border); padding: 0.6rem 0.85rem; display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start; }
.comment-row:last-child { border-bottom: none; }
.comment-meta { color: var(--muted); font-size: 0.78rem; margin-top: 0.2rem; }
.comment-actions { display: flex; gap: 0.4rem; flex-shrink: 0; }

/* settings form */
.form-card { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 1.25rem; max-width: 34rem; }

@media (max-width: 720px) {
  .app { flex-direction: column; height: auto; }
  .side { width: 100%; flex-direction: column; border-right: none; border-bottom: 1px solid var(--border); }
  .side-brand { padding: 0.7rem 1rem; }
  .nav-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    width: 2.1rem; height: 2.1rem; font-size: 1.05rem; line-height: 1;
    border: 1px solid var(--border); border-radius: 6px;
    background: var(--panel); color: var(--fg); cursor: pointer;
  }
  /* 折叠：默认隐藏；展开后纵向整行，文字不再逐字换行 */
  .side-nav { display: none; flex-direction: column; padding: 0.3rem 0; }
  .side-nav.open { display: flex; }
  .side-nav a {
    padding: 0.65rem 1rem; border-right: none; border-left: 3px solid transparent;
    white-space: nowrap; font-size: 0.95rem;
  }
  .side-nav a.active { border-left-color: var(--accent); border-right-color: transparent; }
  /* 移动端也能退出登录 / 查看站点 */
  .side-foot {
    display: flex; flex-direction: row; align-items: center;
    justify-content: space-between; padding: 0.6rem 1rem;
    border-top: 1px solid var(--border);
  }
  .main { padding: 1rem 0.9rem; }
  .editor-panes { flex-direction: column; }
  .editor-panes textarea { height: 16rem; }
  /* 窄屏下表单与工具栏更易用 */
  .field-row { flex-direction: column; gap: 0; }
  .nav-row { flex-wrap: wrap; }
  .nav-row .nv-label, .nav-row .nv-url { flex: 1 1 100%; }
  .toolbar { flex-wrap: wrap; }
  .raw-filters { grid-template-columns: repeat(2, 1fr); gap: 0.6rem 0.7rem; }
  .raw-filters .rw-ip-label, .raw-filters .raw-actions { grid-column: 1 / -1; }
  .raw-actions .btn { flex: 1; }
  .table-wrap .table { min-width: 30rem; }
}

/* pager */
.pager { display: flex; align-items: center; gap: 0.75rem; margin: 1rem 0; justify-content: flex-end; }
.pager .btn:disabled { opacity: 0.45; cursor: not-allowed; }
.pager-info { color: var(--muted); font-size: 0.85rem; }

/* analytics */
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 1rem 1.1rem; margin-bottom: 1.25rem; }
.panel h3 { margin: 0 0 0.9rem; font-size: 0.95rem; }
.panel-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr)); gap: 1.25rem; margin-bottom: 1.25rem; }
.panel-row:last-child { margin-bottom: 0; }
.panel-row .panel { margin-bottom: 0; }
.bars { display: flex; flex-direction: column; gap: 0.45rem; }
.bar-row { display: flex; align-items: center; gap: 0.6rem; font-size: 0.82rem; }
.bar-label { width: 6.5rem; text-align: right; color: var(--muted); flex-shrink: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { flex: 1; background: #f0f1f3; border-radius: 4px; height: 0.9rem; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.bar-fill.alt { background: #10b981; }
.bar-val { width: 3rem; font-variant-numeric: tabular-nums; color: var(--fg); flex-shrink: 0; }

/* segmented view toggle + toolbar-right */
.toolbar { flex-wrap: wrap; gap: 0.6rem; }
.toolbar-right { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
/* flex-shrink:0 + nowrap 防止被挤压时中文逐字换行（按钮变竖条） */
.seg { display: inline-flex; flex-direction: row; flex-shrink: 0; white-space: nowrap; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.seg-btn { display: inline-flex; align-items: center; justify-content: center; font: inherit; font-size: 0.82rem; white-space: nowrap; border: none; background: var(--panel); color: var(--muted); padding: 0.35rem 0.8rem; cursor: pointer; }
.seg-btn + .seg-btn { border-left: 1px solid var(--border); }
.seg-btn.active { background: var(--accent); color: #fff; }
.toolbar-right select { width: auto; min-width: 7rem; }

/* 关于我：社交链接动态行 */
.link-row { display: flex; gap: 0.5rem; margin-bottom: 0.5rem; align-items: center; }
.link-row .lk-label { flex: 0 0 9rem; }
.link-row .lk-url { flex: 1; min-width: 0; }
.link-row .lk-icon { flex: 0 0 6rem; }
.link-row .lk-del { flex-shrink: 0; }

/* ===== EasyMDE 编辑器 ===== */
.EasyMDEContainer .CodeMirror {
  border-color: var(--border);
  border-radius: 0 0 6px 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--fg);
  background: var(--panel);
}
.EasyMDEContainer .CodeMirror-focused { border-color: var(--accent); }
.editor-toolbar {
  border-color: var(--border);
  border-radius: 6px 6px 0 0;
  background: #fafbfc;
  opacity: 1;
}
.editor-toolbar button { color: var(--fg) !important; }
.editor-toolbar button:hover,
.editor-toolbar button.active { background: #eef0f3; border-color: var(--border); }
.editor-toolbar i.separator { border-left-color: var(--border); border-right-color: transparent; }
.editor-statusbar { color: var(--muted); font-size: 0.75rem; }

/* 工具栏图标：不依赖 FontAwesome，用字符代替 */
.editor-toolbar .fa::before { font-family: inherit; font-style: normal; font-weight: 600; }
.editor-toolbar .fa-bold::before { content: "B"; }
.editor-toolbar .fa-italic::before { content: "I"; font-style: italic; }
.editor-toolbar .fa-strikethrough::before { content: "S"; text-decoration: line-through; }
.editor-toolbar .fa-header-1::before { content: "H1"; font-size: 0.8em; }
.editor-toolbar .fa-header-2::before { content: "H2"; font-size: 0.8em; }
.editor-toolbar .fa-header-3::before { content: "H3"; font-size: 0.8em; }
.editor-toolbar .fa-quote-left::before { content: "\201C"; font-size: 1.1em; }
.editor-toolbar .fa-list-ul::before { content: "\2022\2261"; font-size: 0.75em; }
.editor-toolbar .fa-list-ol::before { content: "1\2261"; font-size: 0.75em; }
.editor-toolbar .fa-code::before { content: "</>"; font-size: 0.72em; }
.editor-toolbar .fa-table::before { content: "\25A6"; }
.editor-toolbar .fa-minus::before { content: "\2014"; }
.editor-toolbar .fa-link::before { content: "\1F517"; }
.editor-toolbar .fa-image::before { content: "\1F5BC"; }
.editor-toolbar .fa-eye::before { content: "\1F441"; }
.editor-toolbar .fa-columns::before { content: "\25A5"; }
.editor-toolbar .fa-arrows-alt::before { content: "\26F6"; }
.editor-toolbar .fa-undo::before { content: "\21B6"; }
.editor-toolbar .fa-repeat::before { content: "\21B7"; }
.editor-toolbar .fa-question-circle::before { content: "?"; }

/* 预览区（服务端 goldmark 渲染结果） */
.editor-preview, .editor-preview-side { background: var(--panel); }
.editor-preview pre, .editor-preview-side pre { background: #f6f8fa; padding: 0.8rem; border-radius: 6px; overflow-x: auto; }
.editor-preview code, .editor-preview-side code { background: #f6f8fa; padding: 0.1em 0.35em; border-radius: 4px; }
.editor-preview img, .editor-preview-side img { max-width: 100%; }
.editor-preview blockquote, .editor-preview-side blockquote { border-left: 3px solid var(--border); padding-left: 0.9rem; color: var(--muted); }

/* 导航菜单编辑器 */
.hint { color: var(--muted); font-size: 0.85rem; margin: 0 0 1rem; }
.nav-row { display: flex; gap: 0.5rem; align-items: center; margin-bottom: 0.5rem; }
.nav-row .nv-label { flex: 0 0 10rem; }
.nav-row .nv-url { flex: 1; min-width: 0; }
.nav-row .nv-type { flex: 0 0 4.5rem; color: var(--faint); font-size: 0.76rem; }
.nav-add { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; margin-top: 1rem; }
.nav-add select { width: auto; min-width: 8rem; }

/* 原始数据筛选栏 */
/* 筛选栏：用 grid 保证同一行控件底部严格对齐 */
.raw-filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(8.5rem, 1fr));
  align-items: end; /* 每个单元格底部对齐：标签、下拉、按钮同一条基线 */
  --ctl-h: 2.35rem; /* 筛选控件统一高度 */
  gap: 0.7rem 0.85rem;
  margin-bottom: 1.1rem;
}
.raw-filters > label {
  display: flex; flex-direction: column; justify-content: flex-end;
  gap: 0.25rem; min-width: 0;
  margin-bottom: 0; /* 覆盖全局 label 的 0.25rem 外边距，否则与按钮组差 4px */
  font-size: 0.78rem; color: var(--muted);
}
/* 统一控件高度，保证同一行底部严格对齐 */
.raw-filters select,
.raw-filters input:not([type="checkbox"]),
.raw-filters .btn {
  width: 100%; min-width: 0;
  height: var(--ctl-h);
  padding-top: 0; padding-bottom: 0;
}
.raw-filters .check { flex-direction: row; align-items: center; gap: 0.4rem; height: var(--ctl-h); }
.raw-filters .check input { width: auto; height: auto; }
.raw-actions { display: flex; gap: 0.5rem; align-items: flex-end; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-wrap .table { min-width: 34rem; }
.ua-cell { max-width: 22rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.78rem; color: var(--muted); }
.ip-link { font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }

/* IP 地理位置 */
.geo-credit { margin-top: 1rem; color: var(--faint); font-size: 0.76rem; }
.geo-credit a { color: var(--muted); }
.faint { color: var(--faint); }
.geo-link { border-bottom: 1px dotted var(--border); }

/* App 内置浏览器标记（微信/QQ/支付宝…）
   注意：类名不能用 .app —— 后台布局主容器就是 .app（display:flex;height:100vh），
   会被那条规则污染成 900px 高的竖条。 */
.badge.inapp { background: #07c160; color: #fff; border-color: #07c160; white-space: nowrap; }

/* 聚合视图提示条 */
.agg-hint {
  margin: 0 0 1rem; padding: 0.6rem 0.85rem;
  background: #fffbeb; border: 1px solid #fde68a; border-radius: 6px;
  color: #92400e; font-size: 0.83rem; line-height: 1.5;
}
