/* ============================================================
   七匹狼技术 · 群发中台  样式
   默认亮色，可切暗色（右上角按钮，localStorage 记忆）
   ============================================================ */

:root,
[data-theme="light"] {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #eef2f8;
  --surface-3: #e4eaf3;
  --border: #dbe3ee;
  --text: #1b2536;
  --muted: #6b7a90;
  --primary: #2563eb;
  --primary-dim: #1d4ed8;
  --primary-soft: #e8f0ff;
  --success: #15803d;
  --success-soft: #e6f7ec;
  --warn: #b45309;
  --warn-soft: #fdf3e3;
  --danger: #c81e1e;
  --danger-soft: #fdecec;
  --info-soft: #e8f1fe;
  --shadow: 0 4px 18px rgba(20, 40, 80, .08);
  --shadow-lg: 0 16px 48px rgba(20, 40, 80, .16);
  --radius: 12px;
  --hover-row: #f7faff;
}

[data-theme="dark"] {
  --bg: #0b0f14;
  --surface: #121821;
  --surface-2: #1a2230;
  --surface-3: #222c3c;
  --border: #243040;
  --text: #e6edf3;
  --muted: #8b98a8;
  --primary: #3b82f6;
  --primary-dim: #1d4ed8;
  --primary-soft: #14233c;
  --success: #4ade80;
  --success-soft: #12261b;
  --warn: #fbbf24;
  --warn-soft: #2a2110;
  --danger: #f87171;
  --danger-soft: #2b1414;
  --info-soft: #13233c;
  --shadow: 0 8px 28px rgba(0, 0, 0, .35);
  --shadow-lg: 0 20px 56px rgba(0, 0, 0, .5);
  --hover-row: rgba(26, 34, 48, .55);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

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

button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
a { color: var(--primary); text-decoration: none; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- 布局 ---------- */
.shell { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
  width: 214px; flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 16px 10px;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 6px 10px 18px; }
.brand-logo {
  width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(135deg, #3b82f6, #8b5cf6);
  display: grid; place-items: center; font-weight: 700; font-size: 15px; color: #fff;
  box-shadow: 0 4px 12px rgba(59, 130, 246, .3);
}
.brand-title { font-size: 14px; font-weight: 600; }
.brand-sub { font-size: 11px; color: var(--muted); }

.nav { display: flex; flex-direction: column; gap: 3px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 9px;
  color: var(--muted); cursor: pointer; border: none; background: none;
  text-align: left; width: 100%; transition: .15s;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--primary-soft); color: var(--primary); font-weight: 500; }
.nav-item .ico { width: 18px; text-align: center; font-size: 15px; }
.nav-badge {
  margin-left: auto; background: var(--danger); color: #fff;
  font-size: 10px; padding: 1px 6px; border-radius: 9px; font-weight: 600;
}

.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

.topbar {
  height: 58px; flex-shrink: 0;
  display: flex; align-items: center; gap: 12px;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.topbar h1 { font-size: 16px; font-weight: 600; }
.topbar .spacer { flex: 1; }
.topbar .clock { color: var(--muted); font-size: 12px; }

.theme-btn {
  width: 32px; height: 32px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface-2);
  cursor: pointer; font-size: 15px; line-height: 1;
  display: grid; place-items: center; transition: .15s;
}
.theme-btn:hover { background: var(--surface-3); }

.content { flex: 1; overflow-y: auto; padding: 20px; }

/* ---------- 卡片 ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 14px; }
.card-title {
  font-size: 12px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .06em; margin-bottom: 12px;
}

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

.kpi { display: flex; flex-direction: column; gap: 3px; }
.kpi-value { font-size: 27px; font-weight: 700; letter-spacing: -.02em; }
.kpi-label { font-size: 12px; color: var(--muted); }
.kpi-sub { font-size: 11px; color: var(--muted); }

/* ---------- 表格 ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left; color: var(--muted); font-weight: 600; font-size: 12px;
  padding: 9px 10px; border-bottom: 1px solid var(--border); white-space: nowrap;
  background: var(--surface-2);
}
th:first-child { border-radius: 8px 0 0 0; }
th:last-child { border-radius: 0 8px 0 0; }
td { padding: 11px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:hover td { background: var(--hover-row); }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text); cursor: pointer; transition: .15s; white-space: nowrap;
  font-weight: 500;
}
.btn:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dim); border-color: var(--primary-dim); color: #fff; }
.btn-danger { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-ghost { background: transparent; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- 表单 ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field label { font-size: 12px; color: var(--muted); font-weight: 500; }
.input, .select, .textarea {
  width: 100%; padding: 9px 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  outline: none; transition: .15s;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft);
}
.textarea { min-height: 110px; resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; line-height: 1.7; }

/* ---------- 标签 ---------- */
.tag {
  display: inline-block; padding: 2px 9px; border-radius: 6px;
  font-size: 11px; font-weight: 600; white-space: nowrap;
}
.tag-green { background: var(--success-soft); color: var(--success); }
.tag-blue { background: var(--info-soft); color: var(--primary); }
.tag-amber { background: var(--warn-soft); color: var(--warn); }
.tag-red { background: var(--danger-soft); color: var(--danger); }
.tag-gray { background: var(--surface-2); color: var(--muted); }

.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.nowrap { white-space: nowrap; }
.row { display: flex; align-items: center; gap: 10px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.mt { margin-top: 14px; }

/* ---------- 模态 ---------- */
.mask {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .45);
  display: grid; place-items: center; z-index: 50; padding: 20px;
  backdrop-filter: blur(3px);
}
.modal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; box-shadow: var(--shadow-lg);
  width: min(680px, 100%); max-height: 88vh; overflow-y: auto; padding: 22px;
}
.modal h3 { font-size: 16px; margin-bottom: 16px; font-weight: 600; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

/* ---------- 登录 ---------- */
.login-wrap {
  height: 100vh; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(circle at 20% 20%, var(--primary-soft), var(--bg) 55%);
}
.login-box {
  width: min(390px, 100%); background: var(--surface);
  border: 1px solid var(--border); border-radius: 20px; padding: 34px 28px;
  box-shadow: var(--shadow-lg);
}
.login-box h2 { font-size: 20px; margin-bottom: 6px; font-weight: 700; }
.login-box p { color: var(--muted); font-size: 12px; margin-bottom: 22px; }

/* ---------- 私聊 ---------- */
.dm-layout { display: grid; grid-template-columns: 330px 1fr; gap: 14px; height: calc(100vh - 130px); }
.dm-list { overflow-y: auto; border-right: none; padding: 0; }
.dm-item {
  padding: 12px; border-bottom: 1px solid var(--border);
  cursor: pointer; transition: .12s;
}
.dm-item:hover { background: var(--hover-row); }
.dm-item.active { background: var(--primary-soft); border-left: 3px solid var(--primary); }
.dm-name { font-size: 13px; font-weight: 600; }
.dm-preview { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dm-thread { display: flex; flex-direction: column; overflow: hidden; padding: 0; }
.dm-messages { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 9px; background: var(--bg); }
.msg { max-width: 74%; padding: 9px 13px; border-radius: 14px; font-size: 13px; white-space: pre-wrap; word-break: break-word; line-height: 1.6; }
.msg-in { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg-out { align-self: flex-end; background: var(--primary); color: #fff; border-bottom-right-radius: 4px; }
.msg-time { font-size: 10px; color: var(--muted); margin-top: 3px; }
.dm-input { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--border); background: var(--surface); }

/* ---------- 空状态 ---------- */
.empty { text-align: center; color: var(--muted); padding: 46px 20px; font-size: 13px; }

.mobile-tabs { display: none; }

/* ---------- 手机适配 ---------- */
@media (max-width: 860px) {
  .sidebar { display: none; }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
  .content { padding: 12px; padding-bottom: 76px; }
  .dm-layout { grid-template-columns: 1fr; height: calc(100vh - 150px); }
  .dm-list { border-right: none; }
  .topbar { padding: 0 12px; }
  .topbar h1 { font-size: 15px; }
  .kpi-value { font-size: 22px; }
  .card { padding: 13px; }

  .mobile-tabs {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0;
    background: var(--surface); border-top: 1px solid var(--border);
    z-index: 40; padding-bottom: env(safe-area-inset-bottom);
    box-shadow: 0 -4px 16px rgba(0, 0, 0, .06);
  }
  .mobile-tabs .nav-item {
    flex: 1; flex-direction: column; gap: 2px; padding: 8px 4px;
    font-size: 10px; border-radius: 0; align-items: center;
  }
  .mobile-tabs .nav-item .ico { font-size: 18px; }
  .mobile-tabs .nav-item.active { background: transparent; color: var(--primary); }
}
