/* 好运365 后台管理系统样式
   设计取向：深色主题与小程序端保持一致，表格信息密度优先，操作区固定在上方。 */

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

:root {
  --bg: #120c1f;
  --panel: #1b1230;
  --panel-2: rgba(255, 255, 255, 0.04);
  --gold: #f4c96b;
  --gold-light: #f7d98c;
  --text: #f5f1e8;
  --muted: #9a93a8;
  --muted-2: #6f6880;
  --line: rgba(255, 255, 255, 0.07);
  --danger: #e58c8c;
  --ok: #86d6ae;
  --warn: #e5b76b;
}

body {
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  line-height: 1.6;
}

button, input, select, textarea { font-family: inherit; font-size: 13px; }

/* ---------- 登录页 ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 70% 15%, rgba(244, 201, 107, 0.14), transparent 55%), var(--bg);
}

.login-box {
  width: 360px;
  padding: 36px 32px;
  border-radius: 16px;
  background: var(--panel);
  border: 1px solid rgba(244, 201, 107, 0.22);
}

.login-box h1 { font-size: 20px; color: var(--gold); letter-spacing: 1px; }
.login-box .sub { color: var(--muted); font-size: 12px; margin: 6px 0 24px; }

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }

input[type="text"], input[type="password"], input[type="number"], input[type="date"],
input[type="datetime-local"], select, textarea {
  width: 100%;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
  outline: none;
}

input:focus, select:focus, textarea:focus { border-color: rgba(244, 201, 107, 0.6); }
textarea { min-height: 80px; resize: vertical; }
select option { background: var(--panel); }

button {
  padding: 9px 20px;
  border-radius: 999px;
  border: none;
  font-weight: 600;
  color: #1b1230;
  background: linear-gradient(90deg, var(--gold-light), var(--gold));
  cursor: pointer;
}
button:hover { filter: brightness(1.06); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.ghost {
  color: var(--text);
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.16);
}
button.danger-outline {
  color: var(--danger);
  background: transparent;
  border: 1px solid rgba(229, 140, 140, 0.4);
}
button.mini { padding: 4px 12px; font-size: 12px; border-radius: 6px; }

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

.sidebar {
  width: 210px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
}

.brand {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--line);
}
.brand-title { font-size: 17px; font-weight: 700; color: var(--gold); letter-spacing: 1px; }
.brand-sub { font-size: 11px; color: var(--muted-2); margin-top: 2px; }

.nav { flex: 1; padding: 12px 10px; overflow-y: auto; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--muted);
  cursor: pointer;
  margin-bottom: 2px;
  user-select: none;
}
.nav-item:hover { background: rgba(255, 255, 255, 0.05); color: var(--text); }
.nav-item.active {
  background: rgba(244, 201, 107, 0.14);
  color: var(--gold);
  font-weight: 600;
}
.nav-group { font-size: 11px; color: var(--muted-2); padding: 14px 12px 6px; letter-spacing: 1px; }

.sidebar-foot {
  padding: 14px 16px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
}
.sidebar-foot .who { color: var(--text); margin-bottom: 8px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(27, 18, 48, 0.6);
}
.topbar h2 { font-size: 15px; font-weight: 600; }
.topbar .right { display: flex; align-items: center; gap: 12px; font-size: 12px; color: var(--muted); }

.content { padding: 20px 22px 40px; flex: 1; overflow-x: auto; }

/* ---------- 卡片与指标 ---------- */
.card {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
}
.card-title { font-size: 13px; font-weight: 600; color: var(--gold); margin-bottom: 12px; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.stat {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
}
.stat-label { font-size: 12px; color: var(--muted); }
.stat-value { font-size: 24px; font-weight: 700; color: var(--gold); margin-top: 4px; }
.stat-extra { font-size: 11px; color: var(--muted-2); margin-top: 2px; }

.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
  gap: 16px;
}
.chart { width: 100%; height: 300px; }
.chart-tall { height: 340px; }

/* ---------- 筛选栏 ---------- */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px;
  margin-bottom: 14px;
  padding: 14px;
  border-radius: 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
}
.filter-item { display: flex; flex-direction: column; min-width: 130px; }
.filter-item label { font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.filter-item input, .filter-item select { padding: 7px 10px; }
.filter-actions { display: flex; gap: 8px; margin-left: auto; }

/* ---------- 表格 ---------- */
.table-wrap { overflow-x: auto; border-radius: 12px; border: 1px solid var(--line); }
table { width: 100%; border-collapse: collapse; font-size: 12.5px; white-space: nowrap; }
thead th {
  text-align: left;
  padding: 11px 12px;
  color: var(--muted);
  font-weight: 500;
  background: rgba(0, 0, 0, 0.22);
  border-bottom: 1px solid var(--line);
}
tbody td { padding: 10px 12px; border-bottom: 1px solid var(--line); }
tbody tr:hover { background: rgba(255, 255, 255, 0.03); }
tbody tr:last-child td { border-bottom: none; }
.cell-actions { display: flex; gap: 6px; flex-wrap: nowrap; }
.cell-muted { color: var(--muted-2); }
.cell-mono { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.cell-wrap { white-space: normal; max-width: 260px; }

.tag {
  display: inline-block;
  padding: 1px 9px;
  border-radius: 999px;
  font-size: 11px;
}
.tag.gold { background: rgba(244, 201, 107, 0.16); color: var(--gold); }
.tag.ok { background: rgba(134, 214, 174, 0.16); color: var(--ok); }
.tag.warn { background: rgba(229, 183, 107, 0.16); color: var(--warn); }
.tag.danger { background: rgba(229, 140, 140, 0.16); color: var(--danger); }
.tag.muted { background: rgba(154, 147, 168, 0.16); color: var(--muted); }

/* ---------- 分页 ---------- */
.pager {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 14px;
  font-size: 12px;
  color: var(--muted);
}
.pager select { width: auto; padding: 5px 8px; }
.pager button { padding: 5px 14px; font-size: 12px; }

/* ---------- 弹窗 ---------- */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal {
  width: 100%;
  max-width: 520px;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid rgba(244, 201, 107, 0.24);
  border-radius: 14px;
  padding: 22px;
}
.modal.wide { max-width: 760px; }
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.modal-head h3 { font-size: 15px; color: var(--gold); }
.modal-close { cursor: pointer; color: var(--muted); font-size: 20px; line-height: 1; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* ---------- 权限勾选 ---------- */
.perm-group { margin-bottom: 14px; }
.perm-group-title { font-size: 12px; color: var(--gold); margin-bottom: 6px; }
.perm-items { display: flex; flex-wrap: wrap; gap: 8px 16px; }
.perm-item { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text); }
.perm-item input { width: auto; }

/* ---------- 提示 ---------- */
.toast {
  position: fixed;
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 20px;
  border-radius: 999px;
  font-size: 12.5px;
  background: rgba(27, 18, 48, 0.96);
  border: 1px solid rgba(244, 201, 107, 0.4);
  color: var(--text);
  z-index: 200;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}
.toast.show { opacity: 1; }
.toast.err { border-color: rgba(229, 140, 140, 0.5); color: var(--danger); }

.empty { padding: 40px 0; text-align: center; color: var(--muted-2); font-size: 12.5px; }
.hidden { display: none !important; }
.mt8 { margin-top: 8px; }
.mb8 { margin-bottom: 8px; }
.flex { display: flex; }
.gap8 { gap: 8px; }
.grow { flex: 1; }
.nowrap { white-space: nowrap; }

/* ---------- 移动端适配 ----------
   后台主要面向 PC，但运营偶尔会用手机查看，这里保证小屏可用：
   表单可点击、字号可读、表格可横向滚动、侧边栏改为顶部横向菜单。 */

@media (max-width: 820px) {
  body { font-size: 14px; }

  /* 登录页：铺满可用宽度，加大触控区域 */
  .login-wrap { padding: 20px 16px; align-items: center; }
  .login-box {
    width: 100%;
    max-width: 420px;
    padding: 28px 22px;
    border-radius: 14px;
  }
  .login-box h1 { font-size: 22px; }
  .login-box .sub { font-size: 13px; margin: 6px 0 22px; }

  .field { margin-bottom: 18px; }
  .field label { font-size: 13px; margin-bottom: 8px; }

  /* 16px 是 iOS Safari 的临界值，低于它会自动放大页面 */
  input[type="text"], input[type="password"], input[type="number"], input[type="date"],
  input[type="datetime-local"], select, textarea { font-size: 16px; padding: 12px 14px; }

  button { padding: 12px 22px; font-size: 15px; border-radius: 10px; }
  button.mini { padding: 8px 14px; font-size: 13px; }
  #loginBtn { padding: 14px; font-size: 16px; }

  /* 布局：侧边栏变成顶部横向菜单，内容区占满宽度 */
  .layout { flex-direction: column; min-height: 100vh; }
  .sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--line);
    flex-direction: column;
  }
  .brand { padding: 14px 16px 12px; }
  .brand-title { font-size: 16px; }

  .nav {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 10px 12px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .nav::-webkit-scrollbar { display: none; }
  .nav-item {
    flex: 0 0 auto;
    padding: 8px 14px;
    margin-bottom: 0;
    white-space: nowrap;
    border: 1px solid var(--line);
  }
  .nav-item.active { border-color: rgba(244, 201, 107, 0.45); }

  /* 侧边栏底部（用户名 + 退出）改为同行排列，节省纵向空间 */
  .sidebar-foot {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    border-top: 1px solid var(--line);
  }
  .sidebar-foot .who { margin-bottom: 0; flex: 1; }
  .sidebar-foot button { width: auto !important; padding: 8px 18px; font-size: 13px; }

  .topbar { height: 48px; padding: 0 16px; }
  .topbar h2 { font-size: 15px; }
  .content { padding: 14px 12px 32px; }

  /* 指标卡两列布局 */
  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat { padding: 12px; }
  .stat-label { font-size: 12px; }
  .stat-value { font-size: 20px; }
  .stat-extra { font-size: 11px; }

  /* 图表占满整行，高度适中 */
  .chart-grid { grid-template-columns: 1fr; gap: 12px; }
  .chart { height: 240px; }
  .chart-tall { height: 280px; }

  /* 筛选栏：每项占一半宽度，按钮在末尾 */
  .filter-bar { padding: 12px; gap: 10px; }
  .filter-item { flex: 1 1 calc(50% - 5px); min-width: 0; }
  .filter-actions { margin-left: 0; width: 100%; }
  .filter-actions button { flex: 1; }

  /* 表格保持横向滚动，不压缩列宽导致文字换行错乱 */
  .table-wrap { -webkit-overflow-scrolling: touch; }
  table { font-size: 13px; }
  thead th, tbody td { padding: 10px 12px; }

  /* 分页栏允许换行 */
  .pager { flex-wrap: wrap; justify-content: center; gap: 8px; row-gap: 10px; }
  .pager button { padding: 8px 16px; }

  /* 弹窗接近全屏，避免内部滚动区域过小 */
  .modal-mask { padding: 12px; align-items: flex-end; }
  .modal {
    max-width: 100%;
    max-height: 88vh;
    padding: 18px;
    border-radius: 16px 16px 0 0;
  }
  .modal-head h3 { font-size: 16px; }
  .modal-foot { gap: 10px; }
  .modal-foot button { flex: 1; }

  /* 权限勾选项改为两列，便于点按 */
  .perm-items { gap: 10px 0; }
  .perm-item { flex: 1 1 50%; }
  .perm-item input { width: 18px; height: 18px; }

  .toast {
    left: 16px;
    right: 16px;
    transform: none;
    text-align: center;
    font-size: 13.5px;
  }
}

/* 更窄的屏幕（如 iPhone SE 竖屏）进一步压缩 */
@media (max-width: 380px) {
  .stat-grid { grid-template-columns: 1fr; }
  .filter-item { flex: 1 1 100%; }
  .tab { font-size: 13px; }
}
/* ---------- 咨询管理 ---------- */
.consult-layout {
  display: flex;
  gap: 14px;
  height: calc(100vh - 170px);
  min-height: 480px;
}

/* 左侧会话列表 */
.consult-side {
  width: 300px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-2);
  overflow: hidden;
}

.consult-filter {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.consult-filter input, .consult-filter select { padding: 7px 10px; font-size: 12.5px; }
.consult-filter button { padding: 8px; font-size: 12.5px; }
.consult-unread {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--muted);
  cursor: pointer;
}
.consult-unread input { width: auto; }

.consult-sessions { flex: 1; overflow-y: auto; }

.consult-item {
  padding: 11px 13px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.consult-item:hover { background: rgba(255, 255, 255, 0.04); }
.consult-item.active {
  background: rgba(244, 201, 107, 0.12);
  border-left: 3px solid var(--gold);
  padding-left: 10px;
}
.consult-item-top {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 3px;
}
.consult-item-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.consult-item-time { font-size: 11px; color: var(--muted-2); }
.consult-item-mid {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  margin-bottom: 3px;
}
.consult-item-msg {
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.consult-pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
}

/* 右侧聊天区 */
.consult-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-2);
  overflow: hidden;
}

.consult-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 13px;
  min-height: 48px;
}

.consult-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.consult-msg { display: flex; }
.consult-msg.left { justify-content: flex-start; }
.consult-msg.right { justify-content: flex-end; }

.consult-bubble {
  max-width: 72%;
  padding: 9px 13px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--line);
}
.consult-msg.right .consult-bubble {
  background: rgba(244, 201, 107, 0.14);
  border-color: rgba(244, 201, 107, 0.28);
}

.consult-msg-meta {
  font-size: 10.5px;
  color: var(--muted-2);
  margin-bottom: 3px;
}
.consult-msg-text {
  font-size: 13px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
}

.consult-reply {
  border-top: 1px solid var(--line);
  padding: 12px 16px;
  display: flex;
  gap: 10px;
  align-items: flex-end;
}
.consult-reply textarea {
  flex: 1;
  min-height: 62px;
  max-height: 140px;
  resize: vertical;
  font-size: 13px;
}
.consult-reply-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.consult-reply-actions button { white-space: nowrap; padding: 9px 18px; }

/* 移动端：上下堆叠 */
@media (max-width: 820px) {
  .consult-layout {
    flex-direction: column;
    height: auto;
    min-height: 0;
  }
  .consult-side {
    width: 100%;
    max-height: 340px;
  }
  .consult-main {
    height: 60vh;
    min-height: 380px;
  }
  .consult-bubble { max-width: 86%; }
  .consult-reply { flex-direction: column; align-items: stretch; }
  .consult-reply-actions { flex-direction: row; }
  .consult-reply-actions button { flex: 1; }
}