:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #e5e7eb;
  --text: #1f2328;
  --text-2: #6b7280;
  --text-3: #9ca3af;
  --primary: #2563eb;
  --primary-weak: #eff6ff;
  --teal: #0f9d76;
  --teal-weak: #e6f7f1;
  --amber: #b45309;
  --amber-weak: #fef3c7;
  --red: #dc2626;
  --red-weak: #fee2e2;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 4px 16px rgba(16, 24, 40, 0.06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}
a { color: var(--primary); text-decoration: none; }

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  padding: 8px 14px;
  transition: background 0.15s, opacity 0.15s;
}
button:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: #1d4fd8; }
.btn-ghost { background: transparent; color: var(--text-2); border: 1px solid var(--border); }
.btn-ghost:hover { background: #f3f4f6; }
.btn-teal { background: var(--teal); color: #fff; }
.btn-danger { background: var(--red-weak); color: var(--red); }

input, textarea, select {
  font-family: inherit;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  background: var(--surface);
  color: var(--text);
  width: 100%;
  outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12); }
textarea { resize: vertical; }

.badge {
  display: inline-block;
  font-size: 12px;
  padding: 2px 10px;
  border-radius: 999px;
  font-weight: 500;
}
.badge-open { background: var(--amber-weak); color: var(--amber); }
.badge-pending { background: #e0e7ff; color: #3730a3; }
.badge-resolved { background: var(--teal-weak); color: var(--teal); }
.badge-closed { background: #f3f4f6; color: var(--text-2); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.hidden { display: none !important; }

/* 头部 */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 16px; font-weight: 600; }
.logo {
  width: 30px; height: 30px; border-radius: 8px;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
}

/* 客户门户布局 */
.portal { max-width: 1080px; margin: 0 auto; padding: 24px; }
.portal-grid { display: grid; grid-template-columns: 360px 1fr; gap: 20px; align-items: start; }
@media (max-width: 860px) { .portal-grid { grid-template-columns: 1fr; } }

.chat-panel { height: 560px; display: flex; flex-direction: column; overflow: hidden; }
.chat-head { padding: 14px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
.chat-head .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--teal); }
.chat-body { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; background: #fafbfc; }
.msg { max-width: 82%; padding: 10px 14px; border-radius: 14px; font-size: 14px; white-space: pre-wrap; word-break: break-word; }
.msg.user { align-self: flex-end; background: var(--primary); color: #fff; border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg .src { display: block; font-size: 11px; margin-top: 4px; opacity: 0.7; }
.chat-input { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--border); }
.chat-input input { flex: 1; }

/* FAQ */
.faq-list { max-height: 300px; overflow-y: auto; }
.faq-item { padding: 12px 14px; border-bottom: 1px solid var(--border); cursor: pointer; }
.faq-item:hover { background: #f9fafb; }
.faq-q { font-weight: 500; }
.faq-a { color: var(--text-2); font-size: 13px; margin-top: 4px; display: none; }
.faq-item.open .faq-a { display: block; }

/* 工单 */
.ticket-form { display: flex; flex-direction: column; gap: 10px; }
.field label { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 4px; }
.ticket-track-result { margin-top: 12px; }

/* 后台 */
.admin-wrap { max-width: 1200px; margin: 0 auto; padding: 24px; }
.stat-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px; margin-bottom: 20px; }
@media (max-width: 860px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }
.stat { padding: 16px; }
.stat .num { font-size: 26px; font-weight: 600; }
.stat .label { color: var(--text-2); font-size: 13px; }

.admin-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
@media (max-width: 900px) { .admin-cols { grid-template-columns: 1fr; } }

.panel-head { padding: 14px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.panel-body { padding: 16px; }

.ticket-row { padding: 14px 16px; border-bottom: 1px solid var(--border); }
.ticket-row:hover { background: #f9fafb; }
.ticket-row .top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.ticket-row .subject { font-weight: 500; }
.ticket-row .meta { color: var(--text-3); font-size: 12px; margin-top: 2px; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); }
.tab { padding: 10px 16px; background: transparent; color: var(--text-2); border-radius: 0; }
.tab.active { color: var(--primary); border-bottom: 2px solid var(--primary); font-weight: 500; }

.empty { text-align: center; color: var(--text-3); padding: 40px 16px; }

.toast {
  position: fixed; top: 20px; left: 50%; transform: translateX(-50%);
  background: #111827; color: #fff; padding: 10px 18px; border-radius: 8px;
  font-size: 13px; z-index: 999; opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
.toast.show { opacity: 1; }

.login-card { max-width: 360px; margin: 80px auto; padding: 28px; }
.login-card h2 { margin-bottom: 16px; font-weight: 600; }

/* 详情弹窗 */
.modal-mask { position: fixed; inset: 0; background: rgba(17,24,39,0.45); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal { background: var(--surface); border-radius: var(--radius); width: 560px; max-width: 92vw; max-height: 84vh; display: flex; flex-direction: column; }
.modal-head { padding: 16px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-body { padding: 16px; overflow-y: auto; }
.msgs { display: flex; flex-direction: column; gap: 8px; }

/* ============ 微信 H5 适配 ============ */
#wechatTip {
  position: fixed; inset: 0; background: rgba(0,0,0,0.55);
  display: none; align-items: flex-end; justify-content: center;
  z-index: 998; padding: 20px;
}
.wx-tip-card {
  background: #fff; border-radius: 14px; padding: 22px 20px 18px;
  width: 100%; max-width: 360px; text-align: center;
  box-shadow: 0 12px 40px rgba(0,0,0,0.18);
}
.wx-tip-title { font-size: 17px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.wx-tip-desc  { font-size: 13px; color: var(--text-2); line-height: 1.6; margin-bottom: 16px; }
.wx-tip-btn   {
  background: var(--teal); color: #fff; border: 0; border-radius: 22px;
  padding: 10px 28px; font-size: 14px; font-weight: 500;
}
.wx-tip-share { font-size: 12px; color: var(--text-3); margin-top: 12px; }

/* 移动端 / 微信内的紧凑布局 */
.is-mobile .topbar { padding: 8px 14px; }
.is-mobile .topbar .btn-ghost { display: none; }     /* 微信内隐藏后台入口，避免泄露 */
.is-mobile .portal { padding: 12px; }
.is-mobile .portal-grid { grid-template-columns: 1fr; gap: 14px; }
.is-mobile .chat-input { padding: 8px; }
.is-mobile .chat-input input { font-size: 16px; }    /* 避免 iOS 缩放 */
.is-mobile .card { border-radius: 12px; }
.is-mobile .topbar .brand { font-size: 15px; }
.is-mobile .topbar .logo { width: 28px; height: 28px; font-size: 13px; }

/* 微信内：去掉顶部 admin 链接已经在 .is-mobile 处理；再加顶部安全距离 */
.in-wechat .topbar { padding-top: calc(8px + env(safe-area-inset-top)); }
.in-wechat .portal { padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
.in-wechat .chat-body { -webkit-overflow-scrolling: touch; }

/* 微信浏览器：让点击不出现默认蓝底 */
.in-wechat a, .in-wechat button { -webkit-tap-highlight-color: rgba(0,0,0,0.06); }

/* 分享按钮 */
.btn-share {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--teal-weak); color: var(--teal);
  border: 1px solid var(--teal); border-radius: 14px;
  padding: 4px 12px; font-size: 13px; cursor: pointer;
  font-weight: 500; transition: all 0.15s;
}
.btn-share:hover { background: var(--teal); color: #fff; }
.btn-share:active { transform: scale(0.96); }

/* ===== 页脚：备案信息（工信部要求网站底部展示备案号并链接工信部） ===== */
.site-footer {
  max-width: 1080px; margin: 0 auto;
  padding: 18px 24px 28px;
  text-align: center; font-size: 12px; line-height: 1.9;
  color: var(--text-3);
}
.site-footer .ft-copy { display: block; }
.site-footer .ft-line { display: block; margin-top: 2px; }
.site-footer a { color: var(--text-3); text-decoration: none; border-bottom: 1px dotted var(--border); }
.site-footer a:hover { color: var(--primary); border-bottom-color: var(--primary); }
.site-footer .ft-sep { color: var(--border); margin: 0 8px; }
/* 公安备案图标（公安联网备案通过后，平台会给出图标，需与备案编号一起展示） */
.site-footer .ft-icon {
  width: 12px; height: 13px;
  vertical-align: -2px; margin-right: 4px;
  border: 0; display: inline-block;
}
.is-mobile .site-footer { padding: 14px 12px 22px; }
