/* ============ 全局重置 ============ */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', sans-serif;
  font-size: 14px;
  color: #1f2937;
  background: #f3f4f6;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: contain;
}
button { font-family: inherit; }
a { color: inherit; text-decoration: none; }
input, textarea, select, button { font-family: inherit; font-size: inherit; }
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* ============ 颜色变量 ============ */
:root {
  --primary: #1e40af;
  --primary-light: #3b82f6;
  --primary-bg: #eff6ff;
  --success: #10b981;
  --success-bg: #ecfdf5;
  --warning: #f59e0b;
  --warning-bg: #fffbeb;
  --danger: #ef4444;
  --danger-bg: #fef2f2;
  --info: #6366f1;
  --info-bg: #eef2ff;
  --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;
  --bg: #f3f4f6;
  --card-bg: #ffffff;
  --border: #e5e7eb;
}

/* ============ 顶栏 ============ */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--card-bg);
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top));
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--border);
  min-height: 48px;
}
.header-back {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  margin-right: 4px;
  cursor: pointer;
  border-radius: 8px;
}
.header-back:active { background: var(--gray-100); }
.header-title {
  flex: 1;
  font-size: 17px;
  font-weight: 600;
  color: var(--gray-900);
  text-align: center;
}
.header-right {
  min-width: 32px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.header-action {
  font-size: 13px;
  color: var(--primary);
  padding: 6px 10px;
  cursor: pointer;
  border-radius: 8px;
}
.header-action:active { background: var(--gray-100); }

/* ============ 主内容 ============ */
.main-content {
  padding: 16px;
  padding-bottom: calc(80px + env(safe-area-inset-bottom));
  min-height: calc(100vh - 60px);
}

/* ============ 卡片 ============ */
.card {
  background: var(--card-bg);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
}
.card-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--gray-900);
  margin: 0 0 12px;
  display: flex; align-items: center; justify-content: space-between;
}
.card-section-bar {
  width: 3px; height: 14px;
  background: var(--primary);
  border-radius: 2px;
  margin-right: 8px;
  display: inline-block;
  vertical-align: middle;
}

/* ============ 列表项 ============ */
.list-item {
  background: var(--card-bg);
  padding: 14px 16px;
  margin-bottom: 8px;
  border-radius: 12px;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: transform .1s;
}
.list-item:active { transform: scale(0.98); }
.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
.list-row:last-child { margin-bottom: 0; }
.list-meta {
  font-size: 12px;
  color: var(--gray-500);
}

/* ============ 表单 ============ */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: 13px;
  color: var(--gray-700);
  margin-bottom: 6px;
  font-weight: 500;
}
.form-label.required::after {
  content: '*';
  color: var(--danger);
  margin-left: 3px;
}
.form-control {
  width: 100%;
  padding: 11px 14px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  color: var(--gray-900);
  transition: border-color .15s;
  box-sizing: border-box;
}
.form-control:focus {
  outline: none;
  border-color: var(--primary);
}
textarea.form-control {
  min-height: 80px;
  resize: vertical;
  font-family: inherit;
}
select.form-control {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path fill='%236b7280' d='M6 8L0 0h12z'/></svg>");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}

/* ============ 按钮 ============ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 11px 18px;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
  background: var(--gray-100);
  color: var(--gray-700);
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:active { background: var(--primary-light); }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--gray-700);
}
.btn-block { width: 100%; }
.btn-sm { padding: 7px 12px; font-size: 13px; border-radius: 8px; }
.btn-lg { padding: 14px 20px; font-size: 15px; border-radius: 12px; }

/* ============ 状态徽章 ============ */
.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  background: var(--gray-100);
  color: var(--gray-700);
}
.badge-primary { background: var(--primary-bg); color: var(--primary); }
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-info { background: var(--info-bg); color: var(--info); }

/* 状态颜色映射 */
.status-pending { background: var(--info-bg); color: var(--info); }
.status-processing { background: var(--warning-bg); color: var(--warning); }
.status-approved { background: var(--success-bg); color: var(--success); }
.status-rejected { background: var(--danger-bg); color: var(--danger); }
.status-cancelled { background: var(--gray-100); color: var(--gray-600); }

/* ============ 底部导航 ============ */
.tab-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--card-bg);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 99;
}
.tab-item {
  padding: 8px 0 6px;
  text-align: center;
  cursor: pointer;
  color: var(--gray-500);
  position: relative;
}
.tab-item.active { color: var(--primary); }
.tab-icon {
  width: 24px; height: 24px;
  margin: 0 auto 2px;
  display: block;
}
.tab-label { font-size: 11px; }
.tab-badge {
  position: absolute;
  top: 4px;
  right: 50%;
  margin-right: -22px;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 999px;
  min-width: 16px;
  text-align: center;
}

/* ============ 空状态 ============ */
.empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--gray-400);
  font-size: 14px;
}
.empty-icon {
  width: 80px; height: 80px;
  margin: 0 auto 16px;
  opacity: 0.3;
}

/* ============ 加载 ============ */
.loading {
  text-align: center;
  padding: 30px;
  color: var(--gray-500);
  font-size: 13px;
}
.spinner {
  width: 24px; height: 24px;
  border: 2px solid var(--gray-200);
  border-top-color: var(--primary);
  border-radius: 50%;
  margin: 0 auto 8px;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============ Toast ============ */
.toast {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0,0,0,0.82);
  color: #fff;
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 14px;
  z-index: 9999;
  max-width: 80%;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity .2s;
}
.toast.show { opacity: 1; }

/* ============ 弹窗 ============ */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 1000;
  display: flex;
  align-items: flex-end;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}
.modal-mask.show { opacity: 1; pointer-events: auto; }
.modal {
  background: var(--card-bg);
  width: 100%;
  border-radius: 18px 18px 0 0;
  padding: 20px 16px;
  padding-bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateY(100%);
  transition: transform .25s ease-out;
  max-height: 85vh;
  overflow-y: auto;
}
.modal-mask.show .modal { transform: translateY(0); }
.modal-title {
  font-size: 16px;
  font-weight: 600;
  text-align: center;
  margin: 0 0 16px;
}
.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 16px;
}

/* ============ 通用工具 ============ */
.flex { display: flex; }
.flex-1 { flex: 1; min-width: 0; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.flex-col { display: flex; flex-direction: column; }
.gap-4 { gap: 4px; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.text-sm { font-size: 12px; }
.text-base { font-size: 14px; }
.text-lg { font-size: 16px; }
.text-xl { font-size: 18px; }
.text-2xl { font-size: 22px; }
.font-medium { font-weight: 500; }
.font-bold { font-weight: 600; }
.text-gray { color: var(--gray-500); }
.text-gray-dark { color: var(--gray-700); }
.text-primary { color: var(--primary); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-danger { color: var(--danger); }
.mb-4 { margin-bottom: 4px; }
.mb-8 { margin-bottom: 8px; }
.mb-12 { margin-bottom: 12px; }
.mb-16 { margin-bottom: 16px; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ellipsis-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ============ 头像 ============ */
.avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 500;
  flex-shrink: 0;
}
.avatar-lg { width: 48px; height: 48px; font-size: 16px; }
.avatar-sm { width: 28px; height: 28px; font-size: 12px; }

/* ============ 时间线 ============ */
.timeline {
  position: relative;
  padding-left: 22px;
}
.timeline-item {
  position: relative;
  padding-bottom: 16px;
}
.timeline-item:last-child { padding-bottom: 0; }
.timeline-item::before {
  content: '';
  position: absolute;
  left: -16px;
  top: 4px;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--gray-300);
  border: 2px solid var(--card-bg);
  z-index: 1;
}
.timeline-item.active::before { background: var(--primary); }
.timeline-item.success::before { background: var(--success); }
.timeline-item.danger::before { background: var(--danger); }
.timeline-item:not(:last-child)::after {
  content: '';
  position: absolute;
  left: -12px;
  top: 12px;
  bottom: -2px;
  width: 2px;
  background: var(--gray-200);
}

/* ============ 输入与开关 ============ */
.switch {
  position: relative;
  display: inline-block;
  width: 42px;
  height: 24px;
}
.switch input { opacity: 0; width: 0; height: 0; }
.switch-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--gray-300);
  border-radius: 999px;
  transition: .2s;
}
.switch-slider::before {
  content: '';
  position: absolute;
  height: 18px; width: 18px;
  left: 3px; bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: .2s;
}
.switch input:checked + .switch-slider { background: var(--primary); }
.switch input:checked + .switch-slider::before { transform: translateX(18px); }

/* ============ 文件附件 ============ */
.file-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--gray-50);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 6px;
  font-size: 13px;
}
.file-chip-icon {
  width: 24px; height: 24px;
  background: var(--primary-bg);
  color: var(--primary);
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 600;
}
.file-chip-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-chip-action { font-size: 12px; color: var(--primary); cursor: pointer; }
.file-chip-remove { color: var(--danger); cursor: pointer; padding: 0 4px; }

/* ============ Tab 切换 ============ */
.seg-tabs {
  display: flex;
  background: var(--gray-100);
  padding: 3px;
  border-radius: 10px;
  margin-bottom: 12px;
}
.seg-tab {
  flex: 1;
  text-align: center;
  padding: 8px;
  font-size: 13px;
  color: var(--gray-600);
  border-radius: 8px;
  cursor: pointer;
  transition: all .15s;
  font-weight: 500;
}
.seg-tab.active {
  background: var(--card-bg);
  color: var(--primary);
}

/* 统计卡 */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.stat-card {
  background: var(--card-bg);
  padding: 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
}
.stat-num {
  font-size: 24px;
  font-weight: 600;
  color: var(--gray-900);
  line-height: 1.2;
}
.stat-label {
  font-size: 12px;
  color: var(--gray-500);
  margin-top: 4px;
}

/* ============ 加急标记 ============ */
.urgent-tag {
  display: inline-block;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 4px;
  margin-right: 6px;
  font-weight: 600;
}
