/* ═══ 全局变量 & Reset ═══ */
:root {
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-light: #eef2ff;
  --success: #16a34a;
  --success-light: #dcfce7;
  --warning: #ea580c;
  --warning-light: #fff7ed;
  --danger: #dc2626;
  --danger-light: #fef2f2;
  --info: #0891b2;
  --info-light: #ecfeff;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;
  --sidebar-width: 240px;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
  --shadow-lg: 0 10px 15px rgba(0,0,0,.1), 0 4px 6px rgba(0,0,0,.05);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans SC", sans-serif;
  font-size: 14px;
  color: var(--gray-800);
  background: var(--gray-50);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ═══ 通用组件 ═══ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  padding: 8px 16px; border: none; border-radius: var(--radius);
  font-size: 14px; font-weight: 500; cursor: pointer; transition: all .2s;
  white-space: nowrap;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-default { background: var(--gray-100); color: var(--gray-700); border: 1px solid var(--gray-300); }
.btn-default:hover { background: var(--gray-200); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: .9; }
.btn-sm { padding: 5px 12px; font-size: 13px; }
.btn-block { width: 100%; }

.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 6px; font-weight: 500; font-size: 13px; color: var(--gray-600); }
.form-group input, .form-group select, .form-group textarea {
  width: 100%; padding: 8px 12px; border: 1px solid var(--gray-300);
  border-radius: var(--radius); font-size: 14px; outline: none; transition: border-color .2s;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,.1);
}
.form-group textarea { resize: vertical; }

.error-msg {
  background: var(--danger-light); color: var(--danger);
  padding: 8px 12px; border-radius: var(--radius); font-size: 13px; margin-bottom: 12px;
}

.text-muted { color: var(--gray-400); font-size: 14px; }

/* ═══ 登录页 ═══ */
.login-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 20px;
}
.login-card {
  background: #fff; border-radius: 16px; box-shadow: var(--shadow-lg);
  width: 100%; max-width: 400px; padding: 40px;
}
.login-header { text-align: center; margin-bottom: 30px; }
.login-logo { font-size: 48px; margin-bottom: 12px; }
.login-header h1 { font-size: 24px; color: var(--gray-900); margin-bottom: 4px; }
.login-header p { color: var(--gray-500); font-size: 13px; }
.login-form button { margin-top: 8px; }
.login-footer { text-align: center; margin-top: 20px; font-size: 13px; }

/* ═══ Modal ═══ */
.modal { position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 1000; }
.modal-overlay { position: absolute; width: 100%; height: 100%; background: rgba(0,0,0,.5); }
.modal-card {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  background: #fff; border-radius: 12px; box-shadow: var(--shadow-lg);
  width: 90%; max-width: 500px; max-height: 85vh; display: flex; flex-direction: column;
}
.modal-lg { max-width: 700px; }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--gray-200);
}
.modal-header h2 { font-size: 18px; }
.modal-close {
  background: none; border: none; font-size: 24px; cursor: pointer;
  color: var(--gray-400); line-height: 1;
}
.modal-close:hover { color: var(--gray-600); }
.modal-body { padding: 20px; overflow-y: auto; flex: 1; }
.modal-footer {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 12px 20px; border-top: 1px solid var(--gray-200);
}

/* ═══ 主界面布局 ═══ */
.app-page { display: flex; min-height: 100vh; }

/* 侧边栏 */
.sidebar {
  width: var(--sidebar-width); background: var(--gray-900); color: #fff;
  display: flex; flex-direction: column; position: fixed; top: 0; left: 0;
  height: 100vh; z-index: 100;
}
.sidebar-logo {
  display: flex; align-items: center; gap: 8px;
  padding: 20px; font-size: 18px; font-weight: 600;
  border-bottom: 1px solid rgba(255,255,255,.1);
}
.logo-icon { font-size: 24px; }
.sidebar-nav { flex: 1; padding: 12px 0; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 20px; color: rgba(255,255,255,.6);
  transition: all .2s; cursor: pointer; text-decoration: none;
}
.nav-item:hover { color: #fff; background: rgba(255,255,255,.05); text-decoration: none; }
.nav-item.active { color: #fff; background: rgba(79,70,229,.3); border-right: 3px solid var(--primary); }
.nav-icon { font-size: 18px; width: 24px; text-align: center; }
.sidebar-footer {
  padding: 16px 20px; border-top: 1px solid rgba(255,255,255,.1);
}
.user-info { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.user-avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--primary);
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 14px; text-transform: uppercase;
}
.user-name { font-size: 14px; }
.btn-logout {
  width: 100%; padding: 6px; background: rgba(255,255,255,.1); border: none;
  color: rgba(255,255,255,.7); border-radius: var(--radius); cursor: pointer;
  font-size: 13px; transition: all .2s;
}
.btn-logout:hover { background: var(--danger); color: #fff; }

/* 主内容区 */
.main-content {
  flex: 1; margin-left: var(--sidebar-width); padding: 24px;
  min-height: 100vh;
}

/* 视图切换 */
.view { display: none; }
.view.active { display: block; }

/* 页面头部 */
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px;
}
.page-header h1 { font-size: 22px; }
.page-actions { display: flex; gap: 8px; }

/* ═══ 仪表盘 ═══ */
.stats-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px; margin-bottom: 20px;
}
.stat-card {
  background: #fff; border-radius: 12px; padding: 20px;
  display: flex; align-items: center; gap: 16px; box-shadow: var(--shadow);
  border-left: 4px solid var(--gray-300);
}
.stat-card.stat-blue { border-left-color: var(--info); }
.stat-card.stat-green { border-left-color: var(--success); }
.stat-card.stat-orange { border-left-color: var(--warning); }
.stat-card.stat-purple { border-left-color: #7c3aed; }
.stat-icon { font-size: 32px; }
.stat-value { font-size: 28px; font-weight: 700; }
.stat-label { color: var(--gray-500); font-size: 13px; }

.dashboard-row {
  display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px;
}
@media (max-width: 768px) { .dashboard-row { grid-template-columns: 1fr; } }

.card {
  background: #fff; border-radius: 12px; box-shadow: var(--shadow);
  margin-bottom: 16px; overflow: hidden;
}
.card-header {
  padding: 14px 20px; border-bottom: 1px solid var(--gray-200);
}
.card-header h3 { font-size: 15px; }
.card-body { padding: 20px; }

/* 状态条 */
.status-bar-item {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}
.status-bar-label { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.status-dot { width: 10px; height: 10px; border-radius: 50%; }
.status-bar-track {
  flex: 1; height: 8px; background: var(--gray-100);
  border-radius: 4px; margin: 0 12px; overflow: hidden;
}
.status-bar-fill { height: 100%; border-radius: 4px; transition: width .5s; }

/* 柱状图 */
.bar-chart { display: flex; align-items: flex-end; gap: 8px; height: 120px; padding-top: 10px; }
.bar-item { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.bar {
  width: 100%; max-width: 40px; background: var(--primary); border-radius: 4px 4px 0 0;
  transition: height .5s; min-height: 2px; position: relative;
}
.bar:hover { opacity: .8; }
.bar-label { font-size: 11px; color: var(--gray-500); }
.bar-value { font-size: 11px; font-weight: 600; }

/* 排行榜 */
.rank-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid var(--gray-100);
}
.rank-item:last-child { border-bottom: none; }
.rank-num {
  width: 24px; height: 24px; border-radius: 50%; background: var(--gray-200);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: var(--gray-600);
}
.rank-num.top-1 { background: #fbbf24; color: #fff; }
.rank-num.top-2 { background: #9ca3af; color: #fff; }
.rank-num.top-3 { background: #d97706; color: #fff; }
.rank-title { flex: 1; font-weight: 500; }
.rank-count { font-weight: 700; color: var(--primary); }

/* ═══ 表单列表 ═══ */
.forms-list { display: flex; flex-direction: column; gap: 12px; }
.form-card {
  background: #fff; border-radius: 12px; box-shadow: var(--shadow);
  padding: 16px 20px; display: flex; align-items: center; gap: 16px;
  transition: box-shadow .2s;
}
.form-card:hover { box-shadow: var(--shadow-md); }
.form-card-info { flex: 1; }
.form-card-title { font-size: 16px; font-weight: 600; margin-bottom: 4px; }
.form-card-meta { display: flex; gap: 16px; font-size: 12px; color: var(--gray-500); }
.form-card-actions { display: flex; gap: 6px; align-items: center; }
.form-token-box {
  background: var(--gray-100); padding: 2px 8px; border-radius: 4px;
  font-family: monospace; font-size: 12px; color: var(--gray-600);
  cursor: pointer; max-width: 120px; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap;
}
.form-token-box:hover { background: var(--gray-200); }

/* 状态标签 */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 12px; font-size: 12px; font-weight: 500;
}
.badge-active { background: var(--success-light); color: var(--success); }
.badge-inactive { background: var(--gray-100); color: var(--gray-500); }
.badge-new { background: var(--info-light); color: var(--info); }
.badge-read { background: var(--gray-100); color: var(--gray-500); }
.badge-replied { background: var(--success-light); color: var(--success); }
.badge-archived { background: var(--gray-100); color: var(--gray-400); }

/* ═══ 表单字段编辑器 ═══ */
.form-section {
  margin-bottom: 24px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--gray-100);
}
.form-section:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }

.form-section-title {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 15px; font-weight: 600; color: var(--gray-700);
  margin-bottom: 16px; padding-bottom: 8px;
  border-bottom: 2px solid var(--primary-light);
}
.section-icon { margin-right: 6px; }

.form-hint { font-weight: 400; color: var(--gray-400); font-size: 12px; }
.required-mark { color: var(--danger); }

/* 字段表头 */
.field-header {
  display: flex; align-items: center; gap: 8px;
  padding: 0 12px 6px 12px;
  font-size: 12px; font-weight: 600; color: var(--gray-500);
  text-transform: uppercase; letter-spacing: .3px;
}
.field-header-key { width: 130px; }
.field-header-label { flex: 1; }
.field-header-type { width: 110px; }
.field-header-required { width: 60px; text-align: center; }
.field-header-action { width: 36px; text-align: center; }

/* 字段行 */
.form-fields { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.field-row {
  display: flex; gap: 8px; align-items: center;
  padding: 10px 12px; background: var(--gray-50);
  border-radius: var(--radius); border: 1px solid var(--gray-200);
  transition: all .2s;
}
.field-row:hover { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,.06); }
.field-row input, .field-row select {
  padding: 7px 10px; border: 1px solid var(--gray-300);
  border-radius: 6px; font-size: 13px; outline: none; transition: border-color .2s;
  background: #fff;
}
.field-row input:focus, .field-row select:focus {
  border-color: var(--primary); box-shadow: 0 0 0 2px rgba(79,70,229,.1);
}
.field-key { width: 130px; font-family: 'SF Mono', 'Consolas', monospace; }
.field-label { flex: 1; }
.field-type { width: 110px; cursor: pointer; }

.field-required {
  width: 60px; display: flex; align-items: center; justify-content: center; gap: 4px;
  font-size: 12px; color: var(--gray-500); cursor: pointer; user-select: none;
}
.field-required input { width: 15px; height: 15px; cursor: pointer; accent-color: var(--primary); }

.field-remove {
  width: 36px; height: 32px; background: none; border: 1px solid transparent;
  color: var(--gray-400); cursor: pointer; font-size: 18px;
  border-radius: 6px; display: flex; align-items: center; justify-content: center;
  transition: all .2s;
}
.field-remove:hover { background: var(--danger-light); color: var(--danger); border-color: var(--danger); }

/* ═══ 询盘列表 ═══ */
.filter-bar {
  display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap;
}
.filter-bar select, .filter-bar input {
  padding: 6px 10px; border: 1px solid var(--gray-300);
  border-radius: var(--radius); font-size: 13px; outline: none;
}
.filter-bar input { flex: 1; min-width: 150px; }

.batch-bar {
  display: flex; align-items: center; gap: 8px;
  background: var(--primary-light); padding: 8px 16px;
  border-radius: var(--radius); margin-bottom: 12px; font-size: 13px;
}
.batch-bar select {
  padding: 4px 8px; border: 1px solid var(--gray-300); border-radius: 4px;
}

.inquiries-list { display: flex; flex-direction: column; gap: 8px; }
.inquiry-card {
  background: #fff; border-radius: 10px; box-shadow: var(--shadow);
  padding: 14px 16px; display: flex; align-items: center; gap: 12px;
  cursor: pointer; transition: all .2s;
}
.inquiry-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.inquiry-check { flex-shrink: 0; }
.inquiry-check input { width: 16px; height: 16px; cursor: pointer; }
.inquiry-star { font-size: 18px; cursor: pointer; user-select: none; }
.inquiry-star.starred { color: #fbbf24; }
.inquiry-star:not(.starred) { color: var(--gray-300); }
.inquiry-info { flex: 1; min-width: 0; }
.inquiry-title { font-weight: 500; margin-bottom: 2px; }
.inquiry-preview {
  font-size: 12px; color: var(--gray-500);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.inquiry-meta { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.inquiry-time { font-size: 12px; color: var(--gray-400); }

/* 分页 */
.pagination {
  display: flex; justify-content: center; align-items: center; gap: 4px;
  margin-top: 20px;
}
.pagination button {
  padding: 6px 12px; border: 1px solid var(--gray-300); border-radius: var(--radius);
  background: #fff; cursor: pointer; font-size: 13px;
}
.pagination button:hover { background: var(--gray-100); }
.pagination button.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.pagination button:disabled { opacity: .4; cursor: not-allowed; }
.pagination-info { font-size: 13px; color: var(--gray-500); margin: 0 8px; }

/* ═══ 询盘详情 ═══ */
.detail-section { margin-bottom: 20px; }
.detail-section h4 {
  font-size: 13px; color: var(--gray-500); text-transform: uppercase;
  margin-bottom: 8px; letter-spacing: .5px;
}
.detail-row {
  display: flex; padding: 8px 0; border-bottom: 1px solid var(--gray-100);
}
.detail-label { width: 120px; color: var(--gray-500); font-size: 13px; flex-shrink: 0; }
.detail-value { flex: 1; font-size: 14px; word-break: break-all; }

/* ═══ Toast ═══ */
.toast {
  position: fixed; top: 20px; right: 20px; z-index: 2000;
  padding: 12px 20px; border-radius: var(--radius); font-size: 14px;
  box-shadow: var(--shadow-lg); animation: slideIn .3s ease;
  max-width: 360px;
}
.toast.success { background: var(--success); color: #fff; }
.toast.error { background: var(--danger); color: #fff; }
.toast.info { background: var(--info); color: #fff; }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ═══ 获取JS弹窗 ═══ */
.embed-info {
  background: var(--primary-light); border-radius: var(--radius);
  padding: 12px 16px; margin-bottom: 16px; font-size: 13px; color: var(--gray-600);
  line-height: 1.8;
}
.embed-info p { margin: 0; }
.embed-info code {
  background: #fff; padding: 1px 6px; border-radius: 4px;
  font-family: 'SF Mono', 'Consolas', monospace; font-size: 12px;
  color: var(--primary); border: 1px solid var(--gray-200);
}
.embed-code-wrapper {
  border: 1px solid var(--gray-200); border-radius: var(--radius); overflow: hidden;
}
.embed-code-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 16px; background: var(--gray-100);
  border-bottom: 1px solid var(--gray-200);
  font-size: 13px; font-weight: 500; color: var(--gray-600);
}
.embed-code {
  margin: 0; padding: 16px; background: var(--gray-900); color: #a5b4fc;
  font-family: 'SF Mono', 'Consolas', 'Monaco', monospace; font-size: 13px;
  line-height: 1.7; overflow-x: auto; max-height: 320px; overflow-y: auto;
  white-space: pre-wrap; word-break: break-all;
}
.embed-preview-hint {
  display: flex; align-items: flex-start; gap: 6px;
  margin-top: 16px; padding: 10px 14px;
  background: var(--warning-light); border-radius: var(--radius);
  font-size: 13px; color: var(--gray-600); line-height: 1.6;
}

/* ═══ 用户管理 ═══ */
.user-stats-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px; margin-bottom: 20px;
}

.users-list { display: flex; flex-direction: column; gap: 12px; }
.user-card {
  background: #fff; border-radius: 12px; box-shadow: var(--shadow);
  padding: 16px 20px; display: flex; align-items: center; gap: 16px;
  transition: box-shadow .2s;
}
.user-card:hover { box-shadow: var(--shadow-md); }
.user-card-info { flex: 1; }
.user-card-name { font-size: 16px; font-weight: 600; margin-bottom: 4px; display: flex; align-items: center; gap: 8px; }
.user-card-meta { display: flex; gap: 16px; font-size: 12px; color: var(--gray-500); }
.user-card-actions { display: flex; gap: 6px; align-items: center; }

/* 用户状态标签 */
.badge-super { background: var(--primary-light); color: var(--primary); }
.badge-pending { background: var(--warning-light); color: var(--warning); }
.badge-vip { background: #fef3c7; color: #b45309; }

/* VIP 等级选择器 */
.user-vip-selector { display: inline-flex; align-items: center; gap: 4px; }
.vip-selector {
  padding: 3px 8px; border: 1px solid var(--gray-300);
  border-radius: 4px; font-size: 12px; cursor: pointer; outline: none;
  background: #fff; transition: border-color .2s;
}
.vip-selector:hover { border-color: var(--primary); }
.vip-selector:focus { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(79,70,229,.1); }

/* 表单配额信息 */
.form-quota-info { display: flex; align-items: center; gap: 8px; }

/* ═══ 超管侧边栏差异化 ═══ */
.sidebar-admin { background: linear-gradient(180deg, #1e1b4b 0%, #312e81 100%); }
.user-avatar-admin { background: #f59e0b !important; }

/* 侧边栏底部按钮组 */
.sidebar-footer-actions { display: flex; flex-direction: column; gap: 6px; }
.sidebar-footer-actions .btn-logout { width: 100%; }

/* ═══ 系统配置 ═══ */
.toggle-row {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 0;
}
.toggle-row input[type="checkbox"] {
  width: 18px; height: 18px; cursor: pointer; accent-color: var(--primary);
}
.toggle-row span { font-size: 14px; color: var(--gray-600); }

.config-hint {
  font-size: 12px; color: var(--gray-400); margin-top: 4px;
}

/* ═══ 响应式 ═══ */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); transition: transform .3s; }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .filter-bar { flex-direction: column; }
  .form-card { flex-direction: column; align-items: flex-start; }
  .form-card-actions { flex-wrap: wrap; }

  /* 表单编辑器移动端适配 */
  .modal-card { width: 95%; max-height: 90vh; }
  .field-header { display: none; }
  .field-row { flex-wrap: wrap; }
  .field-key { width: 100%; }
  .field-label { width: calc(100% - 118px); }
  .field-type { width: 110px; }
  .field-required { width: auto; }
}
