/* ============================================================
   main.css —— 全局布局 + 通用组件
   ============================================================ */

/* ---------- 基础重置 ---------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font-stack);
  font-size: var(--font-size);
  line-height: var(--line-height);
  color: var(--text);
  background: var(--bg);
  transition: background-color .18s ease, color .18s ease;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: none; cursor: pointer; }
svg.ic { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
img { max-width: 100%; }
::selection { background: var(--primary-soft); }
/* 滚动条 */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: var(--text-3); border: 2px solid transparent; background-clip: content-box; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 4px; }

/* ---------- 整体栅格 ---------- */
#app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--topbar-h) 1fr;
  min-height: 100vh;
}

/* ---------- 侧边导航 ---------- */
.sidebar {
  grid-column: 1;
  grid-row: 1 / span 2;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 0 18px; height: var(--topbar-h);
  font-weight: 700; font-size: 17px; color: var(--primary);
  white-space: nowrap;
}
.brand .ic { width: 24px; height: 24px; }
.nav-list { flex: 1; padding: 8px 10px; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  position: relative;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-size: 15.5px;
  min-height: 44px;
  transition: background-color .15s ease, color .15s ease;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--primary-soft); color: var(--primary-strong); font-weight: 600; }
.nav-item .ic { width: 21px; height: 21px; }
.nav-badge {
  margin-left: auto;
  font-style: normal;
  font-size: 12px; font-weight: 600;
  min-width: 20px; height: 20px; padding: 0 6px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent); color: #fff; border-radius: 10px;
}
.nav-badge[hidden] { display: none; }
.sidebar-foot { padding: 12px 18px; font-size: 12px; color: var(--text-3); }

/* ---------- 顶栏 ---------- */
.topbar {
  grid-column: 2;
  grid-row: 1;
  display: flex; align-items: center; gap: 14px;
  padding: 0 22px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.search-box {
  flex: 1; max-width: 520px;
  display: flex; align-items: center; gap: 8px;
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 7px 12px;
  color: var(--text-3);
}
.search-box:focus-within { border-color: var(--primary); background: var(--surface); }
.search-box input { flex: 1; border: none; background: none; outline: none; font-size: 15px; min-width: 0; }
.search-box .ic { width: 18px; height: 18px; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.icon-btn {
  width: 42px; height: 42px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm); color: var(--text-2);
  transition: background-color .15s ease;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* ---------- 主内容 ---------- */
.main { grid-column: 2; grid-row: 2; min-width: 0; }
.page { padding: 26px 28px 48px; max-width: 1120px; margin: 0 auto; }
.page-head { margin-bottom: 22px; }
.page-title { font-size: 24px; font-weight: 700; letter-spacing: .01em; }
.page-desc { color: var(--text-2); font-size: 15px; margin-top: 4px; }
.section-title { font-size: 16px; font-weight: 700; margin: 26px 0 12px; display: flex; align-items: center; gap: 8px; }

/* ---------- 卡片 / 栅格 ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}
.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.stat { display: flex; flex-direction: column; gap: 4px; }
.stat .num { font-size: 28px; font-weight: 700; color: var(--primary); line-height: 1.2; }
.stat .lbl { font-size: 13.5px; color: var(--text-2); }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 42px; padding: 0 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 15px; font-weight: 500;
  transition: all .15s ease;
  white-space: nowrap;
}
.btn:hover { border-color: var(--text-3); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-strong); border-color: var(--primary-strong); }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.danger:hover { background: var(--danger); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { min-height: 34px; padding: 0 12px; font-size: 13.5px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .5; pointer-events: none; }

/* ---------- 标签 ---------- */
.tag {
  display: inline-flex; align-items: center;
  font-size: 12px; line-height: 1;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-2);
  white-space: nowrap;
}
.tag.primary { background: var(--primary-soft); color: var(--primary-strong); }
.tag.accent { background: var(--accent-soft); color: var(--accent); }
.tag.success { background: rgba(58,157,99,.14); color: var(--success); }
.tag.danger { background: rgba(214,69,69,.12); color: var(--danger); }

/* ---------- 表单 ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 14px; font-weight: 600; color: var(--text-2); }
.input, select.input, textarea.input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 15px;
  outline: none;
  transition: border-color .15s ease;
}
.input:focus { border-color: var(--primary); }
textarea.input { resize: vertical; min-height: 90px; line-height: 1.6; }
.help { font-size: 12.5px; color: var(--text-3); }

/* ---------- 空状态 ---------- */
.empty {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-2);
}
.empty .ic { width: 44px; height: 44px; color: var(--text-3); margin-bottom: 12px; }
.empty h3 { font-size: 17px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.empty p { font-size: 14px; margin-bottom: 16px; }

/* ---------- 弹窗 ---------- */
.modal-root { position: fixed; inset: 0; z-index: 100; pointer-events: none; }
.modal-mask {
  position: fixed; inset: 0;
  background: rgba(15, 20, 25, .45);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  pointer-events: auto;
  animation: fade .15s ease;
}
.modal {
  width: 100%; max-width: 480px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-pop);
  border: 1px solid var(--border);
  max-height: 90vh; display: flex; flex-direction: column;
  animation: pop .16s ease;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-title { font-size: 16.5px; font-weight: 700; }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }

/* ---------- Toast ---------- */
.toast-root { position: fixed; top: 72px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast {
  background: var(--text); color: var(--bg);
  padding: 10px 18px; border-radius: 999px;
  font-size: 14px; box-shadow: var(--shadow-pop);
  animation: toast-in .18s ease;
}
.toast.success { background: var(--success); color: #fff; }
.toast.error { background: var(--danger); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } }

/* ---------- 列表行 ---------- */
.row-list { display: flex; flex-direction: column; }
.row {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 14px;
  border-bottom: 1px solid var(--border);
  transition: background-color .12s ease;
}
.row:last-child { border-bottom: none; }
.row:hover { background: var(--surface-2); }
.row .grow { flex: 1; min-width: 0; }
.row .t { font-size: 15px; font-weight: 500; }
.row .s { font-size: 12.5px; color: var(--text-3); }

/* ---------- 工具模块子导航 ---------- */
.subnav { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 20px; }
.subnav button {
  padding: 8px 16px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface);
  font-size: 14px; min-height: 40px; color: var(--text-2);
}
.subnav button.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ---------- 开发中占位 ---------- */
.placeholder {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 70px 20px; color: var(--text-2);
}
.placeholder .big { width: 56px; height: 56px; color: var(--primary); opacity: .85; margin-bottom: 16px; display: inline-flex; }
.placeholder .big svg { width: 54px; height: 54px; }
.placeholder h2 { font-size: 20px; margin-bottom: 8px; color: var(--text); }
.placeholder p { font-size: 14.5px; max-width: 420px; }

/* ---------- 移动端底部 Tab（默认隐藏） ---------- */
.tabbar { display: none; }

/* ============================================================
   响应式：≤ 820px 切换为移动端布局
   ============================================================ */
@media (max-width: 820px) {
  #app { grid-template-columns: 1fr; grid-template-rows: var(--topbar-h) 1fr; }
  .sidebar { display: none; }
  .topbar { grid-column: 1; padding: 0 14px; }
  .search-box { max-width: none; }
  .main { grid-column: 1; }
  .page { padding: 18px 14px calc(var(--tabbar-h) + 30px); }

  .tabbar {
    display: flex;
    position: fixed; left: 0; right: 0; bottom: 0;
    height: calc(var(--tabbar-h) + env(viewport-inset-bottom, 0px));
    padding-bottom: env(viewport-inset-bottom, 0px);
    background: var(--surface);
    border-top: 1px solid var(--border);
    z-index: 50;
  }
  .tab-item {
    flex: 1;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 2px;
    font-size: 11px; color: var(--text-3);
    min-height: var(--tabbar-h);
  }
  .tab-item .ic { width: 22px; height: 22px; }
  .tab-item.active { color: var(--primary); }
  .grid-3, .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
}

@media (max-width: 420px) {
  .page-title { font-size: 21px; }
  .stat .num { font-size: 24px; }
}
