/* ============================================================
   企微答答 — 统一设计系统 (Design Tokens + Components)
   ============================================================ */

/* --- 设计 Token --- */
:root {
  /* 颜色 */
  --bg:        #f8fafc;
  --surface:   #ffffff;
  --border:    #e2e8f0;
  --border-in: #d1d5db;

  --primary:   #2563eb;
  --primary-h: #1d4ed8;
  --primary-l: #eff6ff;
  --danger:    #dc2626;
  --danger-h:  #b91c1c;
  --success:   #16a34a;
  --warn:      #d97706;

  --text:      #0f172a;
  --text-m:    #64748b;
  --text-l:    #94a3b8;

  /* 侧边栏 */
  --sb-bg:     #0f172a;
  --sb-hover:  #1e293b;
  --sb-active: #2563eb;
  --sb-text:   #94a3b8;
  --sb-w:      220px;

  /* 间距 & 圆角 */
  --r-sm: 6px;
  --r:    8px;
  --r-lg: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

/* --- Reset --- */
*, *::before, *::after { box-sizing: border-box; }
html { font-size: 14px; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
}

/* ============================================================
   侧边栏
   ============================================================ */
.sidebar {
  width: var(--sb-w);
  background: var(--sb-bg);
  color: var(--sb-text);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  overflow-y: auto;
  transition: transform .25s ease;
}
.sidebar-logo {
  padding: 20px 16px 12px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-logo h2 {
  margin: 0;
  font-size: 16px;
  color: #fff;
  font-weight: 700;
}
.sidebar-logo span {
  font-size: 11px;
  color: var(--sb-text);
  margin-top: 2px;
  display: block;
}
.sidebar-nav {
  flex: 1;
  padding: 8px 8px 16px;
}
.nav-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: rgba(255,255,255,.3);
  padding: 14px 10px 4px;
}
.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  color: var(--sb-text);
  text-decoration: none;
  font-size: 13px;
  border-radius: var(--r);
  transition: background .15s, color .15s;
  margin-bottom: 1px;
}
.sidebar-nav a i {
  font-style: normal;
  font-size: 15px;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}
.sidebar-nav a:hover {
  background: var(--sb-hover);
  color: #e2e8f0;
}
.sidebar-nav a.active {
  background: var(--sb-active);
  color: #fff;
  font-weight: 600;
}
.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid rgba(255,255,255,.08);
}
.sidebar-footer a {
  color: var(--sb-text);
  text-decoration: none;
  font-size: 12px;
}
.sidebar-footer a:hover { color: #fff; }

/* --- 移动端汉堡 --- */
.mobile-header {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 48px;
  background: var(--sb-bg);
  z-index: 99;
  align-items: center;
  padding: 0 12px;
  gap: 10px;
}
.mobile-header h2 { margin: 0; font-size: 15px; color: #fff; font-weight: 600; }
.hamburger {
  background: none;
  border: none;
  color: #fff;
  font-size: 22px;
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
}
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 99;
}

/* ============================================================
   主内容区
   ============================================================ */
.main-content {
  flex: 1;
  margin-left: var(--sb-w);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.page-pad {
  padding: 24px;
  flex: 1;
}

/* --- 页头 --- */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  gap: 12px;
  flex-wrap: wrap;
}
.page-header h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
}
.page-header .subtitle {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--text-m);
}

/* ============================================================
   通用组件
   ============================================================ */

/* --- 按钮 --- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid var(--border-in);
  border-radius: var(--r);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: all .15s;
  font-family: var(--font);
}
.btn:hover { background: #f1f5f9; }
.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.btn-primary:hover { background: var(--primary-h); }
.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}
.btn-danger:hover { background: var(--danger-h); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-ghost {
  background: none;
  border: none;
  color: var(--primary);
  padding: 4px 8px;
}
.btn-ghost:hover { background: var(--primary-l); }
.btn-ghost.danger { color: var(--danger); }
.btn-ghost.danger:hover { background: #fef2f2; }

/* --- 卡片 --- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.card-header h3 { margin: 0; font-size: 15px; font-weight: 600; }
.card-body { padding: 18px; }

/* --- 表格 --- */
.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
}
th, td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid #f1f5f9;
  font-size: 13px;
}
th {
  background: #f8fafc;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}
tr:hover td { background: #fafbff; }

/* --- 表单 --- */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}
.form-grid .full { grid-column: 1 / -1; }
.field label {
  display: block;
  margin-bottom: 4px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-m);
}
.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border-in);
  border-radius: var(--r);
  font-size: 13px;
  font-family: var(--font);
  transition: border-color .15s;
}
.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}
.field .hint {
  margin-top: 3px;
  font-size: 11px;
  color: var(--text-l);
}

/* --- 模态框 --- */
.modal-mask {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(15,23,42,.45);
  z-index: 200;
  padding: 16px;
}
.modal-mask.active { display: flex; }
.modal-card {
  width: min(640px, 96vw);
  max-height: 90vh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: var(--r-lg);
  box-shadow: 0 12px 40px rgba(15,23,42,.18);
}
.modal-card.wide { width: min(900px, 96vw); }
.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; font-weight: 600; }
.modal-close {
  background: none;
  border: none;
  font-size: 20px;
  color: var(--text-l);
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}
.modal-close:hover { color: var(--text); }
.modal-body { padding: 20px; }
.modal-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* --- Tag / Badge --- */
.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}
.tag-blue   { background: #dbeafe; color: #1d4ed8; }
.tag-green  { background: #dcfce7; color: #166534; }
.tag-red    { background: #fee2e2; color: #991b1b; }
.tag-yellow { background: #fef3c7; color: #92400e; }
.tag-gray   { background: #f1f5f9; color: #475569; }

/* --- 统计卡片 --- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.stat-card h3 {
  margin: 0 0 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-m);
}
.stat-card .value {
  margin: 0;
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
}

/* --- Toast 通知 --- */
.toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  padding: 10px 16px;
  border-radius: var(--r);
  font-size: 13px;
  color: #fff;
  box-shadow: 0 4px 12px rgba(0,0,0,.15);
  animation: toastIn .25s ease;
  max-width: 360px;
}
.toast.success { background: var(--success); }
.toast.error   { background: var(--danger); }
.toast.warn    { background: var(--warn); }
.toast.info    { background: var(--primary); }
@keyframes toastIn {
  from { opacity: 0; transform: translateY(-12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* --- 搜索栏 --- */
.search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
}
.search-bar input {
  padding: 7px 12px;
  border: 1px solid var(--border-in);
  border-radius: var(--r);
  font-size: 13px;
  width: 240px;
  max-width: 100%;
}

/* --- 空状态 --- */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-l);
  font-size: 13px;
}
.empty-state svg { margin-bottom: 8px; opacity: .5; }

/* --- 加载状态 --- */
.loading {
  text-align: center;
  padding: 30px;
  color: var(--text-l);
  font-size: 13px;
}

/* --- 引导组件 --- */
.guide-box {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: var(--r);
  padding: 14px 18px;
  margin-bottom: 16px;
  font-size: 13px;
  color: #1e40af;
  line-height: 1.6;
}
.guide-box strong { display: block; margin-bottom: 4px; }
.guide-box p { margin: 2px 0; }

.field-hint {
  margin-top: 3px;
  font-size: 11px;
  color: var(--text-l);
  line-height: 1.4;
}

.collapse-toggle {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  font-size: 13px;
  padding: 4px 0;
  font-family: var(--font);
}
.collapse-toggle:hover { text-decoration: underline; }

/* ============================================================
   响应式 (移动端)
   ============================================================ */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .sidebar-overlay.open {
    display: block;
  }
  .mobile-header {
    display: flex;
  }
  .main-content {
    margin-left: 0;
    padding-top: 48px;
  }
  .page-pad {
    padding: 14px;
  }
  .page-header {
    flex-direction: column;
    align-items: flex-start;
  }
  .page-header h1 {
    font-size: 18px;
  }
  .form-grid {
    grid-template-columns: 1fr;
  }
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .modal-card {
    width: 100%;
    max-height: 96vh;
    border-radius: var(--r);
  }
  .search-bar input { width: 100%; }
}
