/* ==================== 全局样式 ==================== */
:root {
  --primary: #07c160;
  --primary-dark: #059648;
  --primary-light: #d4f5e4;
  --danger: #f43e3e;
  --danger-dark: #dc2626;
  --danger-light: #fee2e2;
  --warning: #f59e0b;
  --warning-dark: #d97706;
  --warning-light: #fef3c7;
  --info: #3b82f6;
  --info-dark: #1d4ed8;
  --info-light: #dbeafe;
  --bg: #edf0f5;
  --bg-secondary: #fafbfc;
  --card-bg: #ffffff;
  --text: #0f172a;
  --text-secondary: #334155;
  --text-muted: #94a3b8;
  --border: #e2e8f0;
  --border-light: #f1f5f9;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.08);
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 8px 30px rgba(0, 0, 0, 0.12);
  --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.18);
  --radius: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}

/* ==================== 头部 ==================== */
.app-header {
  background: linear-gradient(135deg, #05a049 0%, #07c160 40%, #00e06b 100%);
  color: #fff;
  padding: 20px 28px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 6px 24px rgba(7, 193, 96, 0.35);
  position: sticky;
  top: 0;
  z-index: 100;
}

.app-title {
  font-size: 24px;
  font-weight: 900;
  letter-spacing: -0.5px;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
  display: flex;
  align-items: center;
  gap: 6px;
}

.app-logo {
  width: 32px;
  height: 32px;
  object-fit: contain;
  border-radius: 6px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

.app-subtitle {
  font-size: 13px;
  opacity: 0.9;
  margin-left: 8px;
  font-weight: 500;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  background: rgba(0, 0, 0, 0.15);
  padding: 7px 16px;
  border-radius: 22px;
  border: 1px solid rgba(255,255,255,0.2);
}

.status-sep { opacity: 0.3; font-size: 11px; }

.header-user {
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 4px;
  background: rgba(0,0,0,0.1);
}

.user-dropdown {
  display: none;
  position: fixed;
  top: 56px;
  right: 16px;
  background: var(--card-bg);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
  z-index: 300;
  min-width: 140px;
  overflow: hidden;
}

.user-dropdown-item {
  padding: 12px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition);
  color: var(--text);
}

.user-dropdown-item:hover { background: var(--bg); color: var(--primary); }

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 8px rgba(255,255,255,0.6);
  animation: pulse 2s infinite;
}

.status-dot.connected { background: #fff; }
.status-dot.disconnected { background: #ff4444; animation: none; box-shadow: 0 0 8px rgba(255,68,68,0.6); }

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(1.4); }
}

/* ==================== Tab导航 ==================== */
.tab-nav {
  display: flex;
  background: var(--card-bg);
  border-bottom: 2px solid var(--border);
  position: sticky;
  top: 64px;
  z-index: 99;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding: 6px 16px;
  gap: 6px;
  box-shadow: var(--shadow-sm);
}

.tab-btn {
  flex: 1;
  padding: 11px 20px;
  border: none;
  background: none;
  font-size: 15px;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  position: relative;
  transition: all var(--transition);
  font-weight: 600;
  border-radius: 10px;
  margin: 2px 0;
}

.tab-btn:hover {
  color: var(--text);
  background: var(--bg);
}

.tab-btn.active {
  color: #fff;
  font-weight: 700;
  background: linear-gradient(135deg, #05a049, #07c160);
  box-shadow: 0 3px 12px rgba(7, 193, 96, 0.4);
}

.tab-btn.active::after { display: none; }

/* ==================== 主内容 ==================== */
.main-content {
  max-width: 820px;
  margin: 0 auto;
  padding: 24px 20px;
}

.tab-content { display: none; }
.tab-content.active { display: block; animation: fadeIn 0.35s ease; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ==================== 统计卡片 ==================== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
  margin-bottom: 24px;
}

@media (min-width: 480px) {
  .stats-grid { grid-template-columns: repeat(5, 1fr); }
}

.stat-card {
  background: var(--card-bg);
  border-radius: var(--radius-md);
  padding: 22px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow);
  transition: all var(--transition);
  cursor: default;
  border: 2px solid transparent;
}

.stat-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
  border-color: var(--border);
}

.stat-icon {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.complaint-icon { background: linear-gradient(135deg, #dbeafe, #bfdbfe); color: #1d4ed8; }
.pending-icon { background: linear-gradient(135deg, #fef3c7, #fde68a); color: #b45309; }
.auto-icon { background: linear-gradient(135deg, #d1fae5, #a7f3d0); color: #047857; }
.escalated-icon { background: linear-gradient(135deg, #fee2e2, #fecaca); color: #dc2626; }
.refund-icon { background: linear-gradient(135deg, #fce7f3, #fbcfe8); color: #be185d; }

.stat-info { display: flex; flex-direction: column; }

.stat-value {
  font-size: 30px;
  font-weight: 900;
  line-height: 1.1;
  color: var(--text);
}

.stat-label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* ==================== 卡片 ==================== */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 24px;
  overflow: hidden;
  border: 1px solid var(--border-light);
  transition: box-shadow var(--transition);
}

.card:hover { box-shadow: var(--shadow-md); }

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 22px;
  border-bottom: 2px solid var(--border-light);
  background: var(--bg-secondary);
}

.card-header h3 {
  font-size: 17px;
  font-weight: 800;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 10px;
}

.card-header h3::before {
  content: '';
  width: 5px;
  height: 22px;
  background: var(--primary);
  border-radius: 3px;
}

.card-body { padding: 22px; }

.header-actions { display: flex; gap: 8px; }

/* ==================== 按钮 ==================== */
.btn, .btn-sm {
  border: none;
  border-radius: 10px;
  padding: 11px 22px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg);
  color: var(--text-secondary);
  border: 2px solid var(--border);
}

.btn-sm { padding: 7px 16px; font-size: 13px; border-radius: 8px; }

.btn:hover, .btn-sm:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: #cbd5e1; }
.btn:active, .btn-sm:active { transform: translateY(0); }

.btn.primary, .btn-sm.primary {
  background: linear-gradient(135deg, #06b354, #059648);
  color: #fff;
  border: none;
  box-shadow: 0 3px 12px rgba(7, 193, 96, 0.35);
}
.btn.primary:hover, .btn-sm.primary:hover {
  box-shadow: 0 5px 18px rgba(7, 193, 96, 0.45);
}

.btn.danger, .btn-sm.danger {
  background: linear-gradient(135deg, #f43e3e, #dc2626);
  color: #fff;
  border: none;
  box-shadow: 0 3px 12px rgba(244, 62, 62, 0.35);
}

.btn.warning, .btn-sm.warning {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #fff;
  border: none;
  box-shadow: 0 3px 12px rgba(245, 158, 11, 0.35);
}

.btn.info, .btn-sm.info {
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
  color: #fff;
  border: none;
  box-shadow: 0 3px 12px rgba(59, 130, 246, 0.35);
}

.btn:disabled, .btn-sm:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

/* ==================== 表单 ==================== */
.input {
  width: 100%;
  padding: 11px 16px;
  border: 2px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  color: var(--text);
  background: var(--bg-secondary);
  transition: all var(--transition);
  -webkit-appearance: none;
}

.input:focus {
  outline: none;
  border-color: var(--primary);
  background: #fff;
  box-shadow: 0 0 0 4px rgba(7, 193, 96, 0.12);
}

.textarea { resize: vertical; min-height: 60px; }
.form-group { margin-bottom: 18px; }

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-tip {
  background: var(--info-light);
  border-radius: var(--radius-md);
  padding: 14px 18px;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.7;
  border-left: 5px solid var(--info);
}

.required { color: var(--danger); }

/* ==================== 筛选栏 ==================== */
.filter-bar { margin-bottom: 18px; }

.filter-row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.filter-item { display: flex; flex-direction: column; gap: 4px; }
.filter-item label { font-size: 12px; color: var(--text-muted); font-weight: 700; }
.filter-item .input { width: 160px; }

/* ==================== 投诉列表 ==================== */
.complaint-item {
  border: 2px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 18px;
  margin-bottom: 14px;
  cursor: pointer;
  transition: all var(--transition);
  background: var(--card-bg);
  border-left: 4px solid transparent;
}

.complaint-item:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-md);
  transform: translateX(3px);
  border-left-color: var(--primary);
}

.complaint-item.escalated {
  border-left: 5px solid #dc2626;
  background: linear-gradient(90deg, #fef2f2 0%, #fff 15%);
}

.complaint-item.escalated:hover {
  border-color: #dc2626;
  box-shadow: 0 6px 24px rgba(220, 38, 38, 0.15);
}

.complaint-item-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 10px;
}

.complaint-id {
  font-size: 12px;
  color: var(--text-muted);
  font-family: 'SF Mono', 'Menlo', 'Consolas', monospace;
  background: var(--bg);
  padding: 3px 10px;
  border-radius: 6px;
  font-weight: 600;
}

.complaint-state {
  font-size: 12px;
  padding: 4px 14px;
  border-radius: 20px;
  font-weight: 700;
  flex-shrink: 0;
  letter-spacing: 0.5px;
}

.state-PENDING { background: #fef3c7; color: #92400e; border: 1px solid #fcd34d; }
.state-PROCESSING { background: #dbeafe; color: #1e40af; border: 1px solid #93c5fd; }
.state-PROCESSED { background: #d1fae5; color: #065f46; border: 1px solid #6ee7b7; }

.complaint-reason {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--text);
}

.complaint-meta {
  font-size: 13px;
  color: var(--text-muted);
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  font-weight: 500;
}

.complaint-meta span {
  background: var(--bg);
  padding: 3px 10px;
  border-radius: 6px;
}

.complaint-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  flex-wrap: wrap;
  padding-top: 14px;
  border-top: 2px solid var(--border-light);
}

/* ==================== 详情弹窗 ==================== */
.detail-section {
  margin-bottom: 20px;
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  padding: 18px;
  border: 1px solid var(--border-light);
}

.detail-section h4 {
  font-size: 13px;
  font-weight: 800;
  color: var(--primary-dark);
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--primary-light);
  text-transform: uppercase;
  letter-spacing: 1.5px;
}

.detail-row {
  display: flex;
  padding: 9px 0;
  font-size: 14px;
  border-bottom: 1px solid var(--border-light);
  align-items: baseline;
}

.detail-row:last-child { border-bottom: none; }

.detail-label {
  width: 95px;
  color: var(--text-muted);
  flex-shrink: 0;
  font-size: 12px;
  font-weight: 700;
}

.detail-value {
  flex: 1;
  word-break: break-all;
  font-weight: 600;
}

.btn-copy {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  padding: 1px 4px;
  opacity: 0.6;
  transition: opacity var(--transition);
  line-height: 1;
}

.btn-copy:hover { opacity: 1; background: var(--bg); }

/* ==================== 快捷操作 ==================== */
.quick-actions { display: flex; gap: 14px; flex-wrap: wrap; }

.action-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 30px;
  border: none;
  border-radius: var(--radius-md);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  border: 2px solid var(--border);
}

.action-btn:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }
.action-btn.primary {
  background: linear-gradient(135deg, #d1fae5, #a7f3d0);
  color: #047857;
  border-color: #6ee7b7;
}
.action-btn.warning {
  background: linear-gradient(135deg, #fef3c7, #fde68a);
  color: #92400e;
  border-color: #fcd34d;
}
.action-btn.danger {
  background: linear-gradient(135deg, #fee2e2, #fecaca);
  color: #dc2626;
  border-color: #fca5a5;
}
.btn-icon { font-size: 24px; }

/* ==================== 调度器面板 ==================== */
.scheduler-panel {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}

.scheduler-info {
  flex: 1;
  min-width: 200px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 14px 20px;
  border: 2px solid var(--border-light);
}

.scheduler-row {
  display: flex;
  justify-content: space-between;
  padding: 9px 0;
  font-size: 14px;
  border-bottom: 1px solid var(--border-light);
}

.scheduler-row:last-child { border-bottom: none; }
.scheduler-label { color: var(--text-muted); font-weight: 600; }
.scheduler-value { font-weight: 800; color: var(--text); font-size: 14px; }

.scheduler-actions {
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: flex-end;
}

.scheduler-badge {
  font-size: 12px;
  padding: 5px 16px;
  border-radius: 20px;
  font-weight: 800;
  letter-spacing: 0.5px;
}

.scheduler-badge.on {
  background: linear-gradient(135deg, #d1fae5, #a7f3d0);
  color: #047857;
  box-shadow: 0 2px 8px rgba(7, 193, 96, 0.3);
  border: 1px solid #6ee7b7;
}

.scheduler-badge.off {
  background: var(--bg);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

@media (max-width: 480px) {
  .scheduler-panel { flex-direction: column; align-items: stretch; }
  .scheduler-actions { flex-direction: row; justify-content: space-between; align-items: center; }
}

/* ==================== 规则列表 ==================== */
.rules-info {
  background: linear-gradient(135deg, #dbeafe, #bfdbfe);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  margin-bottom: 22px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  line-height: 1.9;
  border-left: 5px solid var(--info);
}

.rule-item {
  border: 2px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 18px;
  margin-bottom: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: all var(--transition);
  background: var(--card-bg);
}

.rule-item:hover { box-shadow: var(--shadow); border-color: var(--border); }
.rule-item.disabled { opacity: 0.45; background: var(--bg); }
.rule-info { flex: 1; }
.rule-name { font-size: 16px; font-weight: 800; margin-bottom: 6px; }
.rule-desc { font-size: 12px; color: var(--text-muted); font-weight: 500; }

.rule-tag {
  display: inline-block;
  font-size: 11px;
  padding: 3px 12px;
  border-radius: 10px;
  margin-right: 6px;
  margin-bottom: 4px;
  font-weight: 700;
  background: var(--primary-light);
  color: var(--primary-dark);
}

.rule-actions { display: flex; gap: 6px; flex-shrink: 0; }
.rule-actions .btn-sm { padding: 5px 12px; font-size: 12px; }

/* ==================== 日志列表 ==================== */
.log-filter { display: flex; gap: 12px; align-items: flex-end; margin-bottom: 18px; }

.log-item {
  padding: 13px 18px;
  border-bottom: 1px solid var(--border-light);
  font-size: 14px;
  transition: background var(--transition);
}

.log-item:hover { background: var(--bg-secondary); }
.log-item:last-child { border-bottom: none; }

.log-time {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 4px;
  font-family: 'SF Mono', 'Menlo', monospace;
  font-weight: 600;
}

.log-action {
  font-weight: 800;
  margin-right: 8px;
  font-size: 13px;
}

.log-action.RESPONSE { color: var(--info); }
.log-action.COMPLETE { color: var(--primary); }
.log-action.REFUND_APPROVE { color: var(--primary); }
.log-action.REFUND_EXECUTE { color: var(--primary); }
.log-action.AUTO_HANDLED { color: var(--primary); }
.log-action.AUTO_NO_MATCH { color: var(--text-muted); }
.log-action.AUTO_FAILED { color: var(--danger); }
.log-detail { color: var(--text-secondary); font-weight: 500; }

/* ==================== 模态框 ==================== */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(6px);
  z-index: 500;
  justify-content: center;
  align-items: center;
  padding: 20px;
  overflow-y: auto;
}

.modal-overlay.active { display: flex; }

.modal {
  background: var(--card-bg);
  border-radius: var(--radius);
  width: 100%;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.25);
  animation: slideUp 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(40px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 22px;
  border-bottom: 2px solid var(--border-light);
  flex-shrink: 0;
  background: var(--bg-secondary);
}

.modal-header h3 { font-size: 18px; font-weight: 800; }

.modal-close {
  width: 38px; height: 38px;
  border: 2px solid var(--border);
  background: var(--bg);
  font-size: 22px;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}

.modal-close:hover { background: var(--danger-light); color: var(--danger); border-color: var(--danger); }
.modal-body { padding: 22px; overflow-y: auto; flex: 1; }

.modal-footer {
  padding: 16px 22px;
  border-top: 2px solid var(--border-light);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-shrink: 0;
  background: var(--bg-secondary);
}

/* ==================== Switch开关 ==================== */
.switch-label {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-weight: 700;
  font-size: 14px;
  white-space: nowrap;
}

.switch-label input,
.toggle-card-switch input { display: none; }

.switch-track {
  width: 46px; height: 26px;
  background: #cbd5e1;
  border-radius: 13px;
  position: relative;
  transition: all var(--transition);
  flex-shrink: 0;
}

.switch-label input:checked + .switch-track,
.toggle-card-switch input:checked + .switch-track {
  background: var(--primary);
}

.switch-thumb {
  position: absolute;
  top: 2px; left: 2px;
  width: 22px; height: 22px;
  background: #fff;
  border-radius: 50%;
  transition: transform var(--transition);
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}

.switch-label input:checked + .switch-track .switch-thumb,
.toggle-card-switch input:checked + .switch-track .switch-thumb {
  transform: translateX(20px);
}

/* ==================== 开关卡片（规则编辑弹窗） ==================== */
.toggle-card-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toggle-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--bg);
  border: 2px solid var(--border-light);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  gap: 14px;
}

.toggle-card:hover {
  border-color: var(--border);
  background: var(--bg-secondary);
  box-shadow: var(--shadow-sm);
}

.toggle-card:has(input:checked) {
  border-color: var(--primary);
  background: linear-gradient(135deg, #f0faf4, #e6f7ed);
  box-shadow: 0 0 0 1px rgba(7, 193, 96, 0.15);
}

.toggle-card-info {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.toggle-card-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
}

.toggle-card:has(input:checked) .toggle-card-title {
  color: var(--primary-dark);
}

.toggle-card-desc {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
  line-height: 1.4;
}

.toggle-card-switch {
  flex-shrink: 0;
  display: flex;
  align-items: center;
}

/* ==================== Toast ==================== */
.toast {
  position: fixed;
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  padding: 14px 32px;
  border-radius: 14px;
  font-size: 15px;
  font-weight: 700;
  z-index: 600;
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s ease;
  box-shadow: 0 10px 40px rgba(0,0,0,0.3);
  max-width: 90vw;
  text-align: center;
}

.toast.show { opacity: 1; transform: translateX(-50%) translateY(4px); }
.toast.success { background: linear-gradient(135deg, #059648, #07c160); }
.toast.error { background: linear-gradient(135deg, #dc2626, #f43e3e); }

/* ==================== 空状态/加载 ==================== */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
  font-size: 15px;
  font-weight: 600;
}

.empty-state::before {
  content: '📭';
  display: block;
  font-size: 56px;
  margin-bottom: 18px;
  opacity: 0.35;
}

.loading { text-align: center; padding: 48px 20px; color: var(--text-muted); font-weight: 600; font-size: 15px; }

.loading::after {
  content: '';
  display: inline-block;
  width: 22px; height: 22px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-left: 10px;
  vertical-align: middle;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ==================== 分页 ==================== */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 14px;
  padding: 24px 0;
}

.page-info {
  font-size: 14px;
  color: var(--text-secondary);
  font-weight: 700;
  background: var(--bg);
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
}

/* ==================== 新投诉闪动提醒 ==================== */
@keyframes headerFlash {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.app-header.flash-alert {
  animation: headerFlash 1s ease-in-out infinite;
}

/* ==================== 投诉统计 ==================== */
.stats-section-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
  margin-bottom: 20px;
}

.stat-table-wrap {
  max-height: 360px;
  overflow-y: auto;
}

.mini-stat-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
}

.mini-stat-table thead {
  position: sticky;
  top: 0;
  z-index: 1;
}

.mini-stat-table th {
  background: var(--bg);
  padding: 10px 12px;
  text-align: left;
  font-weight: 700;
  font-size: 12px;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 1;
}

.mini-stat-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-light);
  background: var(--card-bg);
}

.mini-stat-table tbody tr:hover td {
  background: var(--bg-secondary);
}

.stat-total-row {
  background: var(--bg) !important;
  font-weight: 800;
  border-top: 2px solid var(--border);
}

.stat-total-row td {
  padding: 10px 12px;
}

.stats-table tfoot .stat-total-row td {
  background: var(--bg);
  font-weight: 800;
  font-size: 14px;
  border-top: 2px solid var(--border);
}

/* 全屏按钮 */
.btn-fs {
  width: 32px;
  height: 32px;
  border: 1.5px solid var(--border);
  background: var(--bg);
  border-radius: 8px;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: all var(--transition);
}
.btn-fs:hover {
  background: var(--primary-light);
  color: var(--primary);
  border-color: var(--primary);
}

/* 全屏模式 */
.stat-card-full.fs-mode {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 250;
  border-radius: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  background: var(--card-bg);
}
.stat-card-full.fs-mode .card-body {
  flex: 1;
  overflow: hidden;
}
.stat-card-full.fs-mode .stat-table-wrap {
  max-height: calc(100vh - 60px);
}
.stat-card-full.fs-mode .btn-fs {
  background: var(--danger-light);
  color: var(--danger);
  border-color: var(--danger);
}

.stat-count {
  font-weight: 800;
  color: var(--primary);
  font-size: 14px;
}

.stat-bar-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  position: relative;
}

.stat-bar {
  height: 6px;
  background: linear-gradient(90deg, var(--primary-light), var(--primary));
  border-radius: 3px;
  min-width: 2px;
  transition: width 0.5s ease;
}

.stat-bar-text {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}

.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  min-width: 700px;
}

.stats-table thead {
  position: sticky;
  top: 0;
}

.stats-table th.sortable {
  cursor: pointer;
  user-select: none;
}
.stats-table th.sortable:hover {
  background: var(--border-light);
}
.sort-arrow { font-size: 10px; }

.stats-table th {
  background: var(--bg);
  padding: 12px 10px;
  text-align: left;
  font-weight: 700;
  font-size: 12px;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

.stats-table td {
  padding: 10px;
  border-bottom: 1px solid var(--border-light);
  font-size: 13px;
}

.stats-table tbody tr:hover {
  background: var(--bg-secondary);
}

@media (max-width: 768px) {
  .stats-section-grid {
    grid-template-columns: 1fr;
  }
  .stats-table {
    min-width: 600px;
  }
}

.detail-filter-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: flex-start;
}

.multi-select-wrap {
  position: relative;
  min-width: 160px;
  max-width: 220px;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: var(--bg-secondary);
  padding: 4px 6px;
  cursor: text;
  transition: border-color var(--transition);
}

.multi-select-wrap:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(7,193,96,0.1);
  background: #fff;
}

.ms-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  min-height: 24px;
}

.ms-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--primary-light);
  color: var(--primary-dark);
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 6px;
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ms-tag-remove {
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  opacity: 0.6;
}

.ms-tag-remove:hover { opacity: 1; }

.ms-input {
  border: none;
  outline: none;
  background: transparent;
  font-size: 13px;
  width: 100%;
  min-width: 80px;
  padding: 2px 0;
  color: var(--text);
}

.ms-input::placeholder { color: var(--text-muted); }

.ms-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  max-height: 200px;
  overflow-y: auto;
  background: var(--card-bg);
  border: 2px solid var(--primary);
  border-radius: 0 0 10px 10px;
  box-shadow: var(--shadow-md);
  z-index: 10;
  margin-top: -1px;
}

.ms-dropdown.open { display: block; }

.ms-option {
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
  transition: background var(--transition);
}

.ms-option:hover { background: var(--primary-light); }
.ms-option.selected { font-weight: 700; color: var(--primary); }

/* ==================== 登录界面 ==================== */
.login-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: linear-gradient(135deg, #05a049 0%, #07c160 50%, #00e06b 100%);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-overlay.hidden { display: none; }

.login-box {
  background: #fff;
  border-radius: 20px;
  padding: 48px 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.3);
  animation: slideUp 0.4s ease;
}

.login-logo {
  text-align: center;
  margin-bottom: 32px;
}

.login-logo-img {
  width: 64px;
  height: 64px;
  border-radius: 14px;
  margin-bottom: 12px;
  background: linear-gradient(135deg, #05a049, #07c160);
  padding: 8px;
}

.login-logo h2 {
  font-size: 22px;
  font-weight: 800;
  color: var(--primary-dark);
  margin-bottom: 4px;
}

.login-logo p {
  font-size: 13px;
  color: var(--text-muted);
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.login-btn {
  width: 100%;
  justify-content: center;
  padding: 14px;
  font-size: 16px;
  border-radius: 12px;
  font-weight: 800;
}

.login-error {
  text-align: center;
  font-size: 13px;
  color: var(--danger);
  font-weight: 600;
  min-height: 20px;
}

@media (max-width: 480px) {
  .login-box {
    margin: 20px;
    padding: 32px 24px;
  }
}

/* ==================== 质量指标 ==================== */
.quality-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
.quality-item {
  text-align: center;
  padding: 16px 12px;
  background: var(--bg);
  border-radius: 12px;
  border: 1px solid var(--border-light);
}
.quality-value {
  font-size: 24px;
  font-weight: 800;
  color: var(--primary);
}
.quality-value.warn { color: var(--warning); }
.quality-value.danger { color: var(--danger); }
.quality-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  line-height: 1.4;
}
@media (max-width: 480px) {
  .quality-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ==================== 响应式 ==================== */
@media (max-width: 768px) {
  .app-header { padding: 14px 16px; }
  .app-title { font-size: 19px; }
  .app-subtitle { display: none; }
  .main-content { max-width: 100%; padding: 14px; }
  .tab-nav { top: 52px; padding: 4px 8px; }
  .tab-btn { padding: 11px 12px; font-size: 13px; border-radius: 8px; }
  .stats-grid { grid-template-columns: repeat(3, 1fr); gap: 10px; }
  .stat-card { padding: 16px 12px; gap: 10px; }
  .stat-icon { width: 44px; height: 44px; font-size: 20px; border-radius: 12px; }
  .stat-value { font-size: 26px; }
  .stat-label { font-size: 10px; }
  .card-header { padding: 14px; }
  .card-header h3 { font-size: 16px; }
  .card-body { padding: 14px; }
  .filter-row { flex-wrap: nowrap; overflow-x: auto; align-items: flex-end; gap: 6px; }
  .filter-item { flex: 0 0 auto; }
  .filter-item .input { width: 130px; min-width: 0; font-size: 12px; padding-left: 8px; padding-right: 8px; }
  .filter-item label { white-space: nowrap; font-size: 11px; }
  .filter-search-btn { flex-shrink: 0; white-space: nowrap; padding: 8px 12px; font-size: 12px; }
  .complaint-item { padding: 14px; }
  .complaint-item-header { flex-direction: column; gap: 6px; }
  .complaint-meta { flex-direction: column; gap: 4px; }
  .complaint-actions { flex-direction: column; }
  .complaint-actions .btn-sm { width: 100%; justify-content: center; }
  .detail-row { flex-direction: column; gap: 2px; padding: 8px 0; }
  .detail-label { width: 100%; font-size: 12px; }
  .detail-value { font-size: 14px; }
  .rule-item { flex-direction: column; gap: 10px; }
  .rule-actions { width: 100%; justify-content: flex-start; flex-wrap: wrap; }
  .log-filter { flex-direction: column; }
  .log-filter .input { width: 100% !important; }
  .quick-actions { flex-direction: column; }
  .action-btn { width: 100%; justify-content: center; }
  .pagination { flex-wrap: wrap; gap: 8px; }
}

@media (max-width: 480px) {
  .toggle-card { padding: 12px 14px; gap: 10px; }
  .toggle-card-title { font-size: 13px; }
  .toggle-card-desc { font-size: 11px; }
  .app-header { padding: 12px 14px; }
  .app-title { font-size: 17px; }
  .header-right { font-size: 12px; padding: 5px 12px; }
  .main-content { padding: 10px; }
  .tab-btn { padding: 9px 10px; font-size: 12px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .stat-card { padding: 14px 10px; }
  .stat-icon { width: 38px; height: 38px; font-size: 18px; }
  .stat-value { font-size: 24px; }
  .scheduler-panel { flex-direction: column; align-items: stretch; }
  .scheduler-actions { flex-direction: row; justify-content: space-between; align-items: center; }
  .btn, .btn-sm { padding: 9px 16px; font-size: 13px; }
  .modal-overlay { padding: 0; overflow-y: hidden; }
  .modal { max-height: -webkit-fill-available; display: flex; flex-direction: column; border-radius: 0; max-width: 100%; }
  .modal-body { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
  .modal-header { padding: 14px; }
  .modal-body { padding: 14px; }
  .modal-footer { padding: 12px 14px; flex-wrap: wrap; }
  .modal-footer .btn { flex: 1; justify-content: center; min-width: 0; }
  .scheduler-row { flex-direction: column; gap: 2px; padding: 4px 0; }
  .header-actions { flex-wrap: wrap; gap: 4px; }
  .header-actions .btn-sm { font-size: 12px; padding: 5px 12px; }
  .page-info { font-size: 13px; }
  .toast { left: 12px; right: 12px; transform: none; text-align: center; white-space: normal; font-size: 14px; }
}

@media (min-width: 769px) and (max-width: 1024px) {
  .stats-grid { grid-template-columns: repeat(5, 1fr); }
  .main-content { max-width: 95%; }
}

@media (min-width: 1200px) {
  .main-content { max-width: 960px; }
  .stats-grid { grid-template-columns: repeat(5, 1fr); }
  .stat-card { padding: 24px 20px; }
  .stat-icon { width: 56px; height: 56px; font-size: 26px; }
  .stat-value { font-size: 34px; }
}
