:root {
  --primary: #4A3BFF;
  --primary-hover: #3A2FDF;
  --primary-light: #EEECFF;
  --green: #00C48C;
  --green-light: #E6F9F4;
  --orange: #FF9F43;
  --orange-light: #FFF4E8;
  --red: #EF4444;
  --red-light: #FEE2E2;
  --gray-50: #F8F9FA;
  --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;
  --white: #FFFFFF;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  background: var(--gray-50);
  color: var(--gray-800);
  display: flex;
  min-height: 100vh;
}

/* ========== Sidebar ========== */
.sidebar {
  width: 240px;
  background: var(--white);
  border-right: 1px solid var(--gray-200);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform 0.25s;
}
.sidebar-header {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--gray-100);
}
.sidebar-header .logo {
  font-size: 18px;
  font-weight: 700;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 10px;
}
.sidebar-header .logo svg { width: 28px; height: 28px; }
.sidebar-nav {
  flex: 1;
  padding: 12px 12px;
  overflow-y: auto;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 14px;
  color: var(--gray-600);
  transition: all 0.15s;
  margin-bottom: 2px;
  text-decoration: none;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}
.nav-item:hover { background: var(--gray-100); color: var(--gray-800); }
.nav-item.active { background: var(--primary); color: var(--white); font-weight: 600; }
.nav-item.active svg { stroke: white; }
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav-sub-group {
  padding-left: 16px;
  margin-bottom: 4px;
}
.nav-sub {
  padding-left: 30px;
  font-size: 13px;
}
.sidebar-footer {
  position: relative;
  padding: 16px 20px;
  border-top: 1px solid var(--gray-100);
  display: flex;
  align-items: center;
  gap: 12px;
}
.avatar {
  width: 36px; height: 36px;
  background: var(--primary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 14px;
  font-weight: 600;
  flex-shrink: 0;
}
.user-info { font-size: 13px; }
.user-info .name { font-weight: 600; color: var(--gray-800); }
.user-info .role { color: var(--gray-400); font-size: 12px; margin-top: 1px; }

.logout-btn {
  background: none;
  border: none;
  color: var(--gray-400);
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}
.logout-btn:hover {
  color: var(--red);
  background: var(--red-light);
}

/* ========== Main ========== */
.main {
  flex: 1;
  margin-left: 240px;
  padding: 24px 32px;
  min-width: 0;
}
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 28px;
}
.topbar h1 { font-size: 24px; font-weight: 700; color: var(--gray-900); }
.topbar-right { display: flex; align-items: center; gap: 16px; }

/* ========== Buttons ========== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s;
  text-decoration: none;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-green { background: var(--green); color: white; }
.btn-green:hover { background: #00B07C; }
.btn-outline { background: white; color: var(--gray-600); border-color: var(--gray-300); }
.btn-outline:hover { background: var(--gray-50); border-color: var(--gray-400); }
.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-danger { background: var(--red); color: white; }
.btn-danger:hover { background: #DC2626; }

/* ========== Cards ========== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px;
  margin-bottom: 28px;
}
.stat-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 20px 24px;
  box-shadow: var(--shadow);
  position: relative;
}
.stat-card .stat-label { font-size: 13px; color: var(--gray-500); margin-bottom: 6px; }
.stat-card .stat-value { font-size: 28px; font-weight: 700; color: var(--gray-900); margin-bottom: 4px; }
.stat-card .stat-sub { font-size: 12px; display: flex; align-items: center; gap: 4px; }
.stat-sub.up { color: var(--green); }
.stat-sub.info { color: var(--gray-500); }
.stat-card .stat-icon {
  width: 42px; height: 42px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  position: absolute; top: 20px; right: 24px;
}

/* ========== Panels ========== */
.panel {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 20px;
  overflow: hidden;
}
.panel-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--gray-100);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.panel-header h3 { font-size: 15px; font-weight: 600; color: var(--gray-800); }
.panel-body { padding: 16px 20px; }

/* ========== Content Grid ========== */
.content-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

/* ========== Tables ========== */
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left;
  font-size: 12px;
  color: var(--gray-400);
  font-weight: 500;
  padding: 10px 12px;
  border-bottom: 1px solid var(--gray-200);
  white-space: nowrap;
}
td {
  font-size: 13px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--gray-50);
  color: var(--gray-700);
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--gray-50); }
.table-footer {
  padding: 12px 20px;
  background: var(--gray-50);
  border-top: 1px solid var(--gray-100);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  color: var(--gray-500);
}
.table-footer strong { color: var(--gray-800); }

/* ========== Badges ========== */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}
.badge-pending { background: var(--primary-light); color: var(--primary); }
.badge-waiting { background: var(--orange-light); color: var(--orange); }
.badge-paid { background: var(--green-light); color: var(--green); }

/* ========== Forms ========== */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--gray-700);
  margin-bottom: 6px;
}
.form-input, .form-select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--gray-800);
  background: var(--white);
  transition: border-color 0.15s;
  font-family: inherit;
}
.form-input:focus, .form-select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}
textarea.form-input { resize: vertical; min-height: 80px; }
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.form-row-4 {
  grid-template-columns: repeat(4, 1fr);
}
.form-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  margin-top: 20px;
}

/* ========== Charts ========== */
.chart-container { position: relative; height: 240px; }
.chart-container canvas { width: 100% !important; }
.chart-sm { height: 200px; }

/* ========== Filter Bar ========== */
.filter-bar {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: flex-end;
  padding: 16px 20px;
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}
.filter-bar .form-group { margin-bottom: 0; flex: 1; min-width: 150px; }

/* ========== Status Tabs ========== */
.status-tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--gray-100);
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
}
.status-tab {
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  background: transparent;
  color: var(--gray-500);
  transition: all 0.15s;
}
.status-tab:hover { color: var(--gray-700); }
.status-tab.active { background: var(--white); color: var(--gray-800); box-shadow: var(--shadow); }

/* ========== Modal ========== */
.modal-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 200;
  align-items: center; justify-content: center;
}
.modal-overlay.show { display: flex; }
.modal {
  background: var(--white);
  border-radius: var(--radius);
  width: 90%; max-width: 900px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}
.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--gray-100);
  display: flex; justify-content: space-between; align-items: center;
}
.modal-header h3 { font-size: 16px; font-weight: 600; }
.modal-close {
  width: 32px; height: 32px;
  border: none; background: var(--gray-100);
  border-radius: 50%; cursor: pointer;
  font-size: 18px; color: var(--gray-500);
  display: flex; align-items: center; justify-content: center;
}
.modal-close:hover { background: var(--gray-200); }
.modal-body { padding: 20px; }

/* ========== Upload Zone ========== */
.upload-zone {
  border: 2px dashed var(--gray-300);
  border-radius: var(--radius);
  padding: 40px 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.15s;
  background: var(--gray-50);
  margin-bottom: 16px;
}
.upload-zone:hover { border-color: var(--primary); background: var(--primary-light); }
.upload-zone svg { width: 42px; height: 42px; color: var(--gray-400); margin-bottom: 12px; }
.upload-zone p { font-size: 14px; color: var(--gray-500); }
.upload-zone .hint { font-size: 12px; color: var(--gray-400); margin-top: 6px; }

/* ========== File Preview ========== */
.file-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}
.file-preview .preview-item {
  position: relative;
  width: 80px;
  height: 80px;
  border-radius: 8px;
  overflow: hidden;
  border: 2px solid var(--gray-200);
}
.file-preview .preview-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.file-preview .preview-item .preview-name {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0,0,0,0.55);
  color: #fff;
  font-size: 10px;
  padding: 2px 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.file-preview .preview-item .preview-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  line-height: 16px;
  text-align: center;
  background: rgba(0,0,0,0.5);
  color: #fff;
  border-radius: 50%;
  font-size: 12px;
  cursor: pointer;
}

/* ========== Voice Button ========== */
.voice-btn {
  width: 100%;
  padding: 14px;
  border: 2px solid var(--gray-200);
  border-radius: var(--radius);
  background: var(--white);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.15s;
  color: var(--gray-600);
  margin-bottom: 16px;
}
.voice-btn:hover { border-color: var(--primary); color: var(--primary); }
.voice-btn.recording { border-color: var(--red); background: var(--red-light); color: var(--red); animation: pulse 1.2s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.6; } }

/* ========== Toast ========== */
.toast {
  position: fixed;
  top: 20px; right: 20px;
  padding: 12px 24px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  color: white;
  z-index: 999;
  animation: slideIn 0.3s ease;
  box-shadow: var(--shadow-md);
}
.toast-success { background: var(--green); }
.toast-error { background: var(--red); }
.toast-info { background: var(--primary); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ========== Empty State ========== */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--gray-400);
}
.empty-state svg { width: 56px; height: 56px; margin-bottom: 12px; }
.empty-state p { font-size: 14px; }

/* ========== Page sections ========== */
.page-section { display: none; }
.page-section.active { display: block; }

/* ========== Detail Card ========== */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.detail-item { padding: 12px; background: var(--gray-50); border-radius: var(--radius-sm); }
.detail-item .detail-label { font-size: 12px; color: var(--gray-400); margin-bottom: 4px; }
.detail-item .detail-value { font-size: 14px; font-weight: 500; color: var(--gray-800); }
.detail-item .detail-value.large { font-size: 20px; }

/* ========== Table inline edit ========== */
.table-input {
  width: 100%;
  padding: 4px 8px;
  border: 1px solid var(--gray-300);
  border-radius: 4px;
  font-size: 13px;
  font-family: inherit;
}
.table-input:focus { outline: none; border-color: var(--primary); }

/* ========== Export options ========== */
.export-options {
  display: flex;
  gap: 12px;
  margin-top: 20px;
  flex-wrap: wrap;
}

/* ========== Mobile ========== */
.mobile-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--white);
  border-top: 1px solid var(--gray-200);
  z-index: 100;
  padding: 6px 0 env(safe-area-inset-bottom);
}
.mobile-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 0;
  cursor: pointer;
  border: none;
  background: none;
  color: var(--gray-400);
  font-size: 11px;
}
.mobile-nav-item.active { color: var(--primary); }
.mobile-nav-item svg { width: 20px; height: 20px; }

/* ========== Mobile Components ========== */
.voice-btn {
  display: flex; align-items: center; justify-content: center;
  padding: 18px; margin: 16px 0;
  background: linear-gradient(135deg, #F0F0FF, #E8E8FF);
  border: 2px dashed #4A3BFF;
  border-radius: 12px; cursor: pointer;
  color: #4A3BFF; font-size: 14px; font-weight: 500;
  transition: all 0.2s;
}
.voice-btn:hover { background: linear-gradient(135deg, #E0E0FF, #D8D8FF); }

.status-tabs {
  display: flex; gap: 8px; margin-bottom: 16px;
}
.status-tab {
  flex: 1; padding: 10px 8px; text-align: center;
  border: none; background: var(--gray-100); border-radius: 8px;
  font-size: 13px; cursor: pointer; color: #6B7280; font-weight: 500;
  transition: all 0.2s;
}
.status-tab.active { background: #4A3BFF; color: white; }

/* ========== Responsive ========== */
@media (max-width: 1024px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); box-shadow: 4px 0 20px rgba(0,0,0,0.15); }
  .main { margin-left: 0; padding: 12px 16px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .content-grid { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
  .form-row, .form-row-4 { grid-template-columns: 1fr; }
  .mobile-nav { display: flex; }
  body { padding-bottom: 64px; }
  .topbar { margin-bottom: 12px; }
  .topbar h1 { font-size: 18px; }
  .menu-toggle {
    display: flex;
    align-items: center; justify-content: center;
    width: 36px; height: 36px;
    border: none; background: var(--gray-100);
    border-radius: var(--radius-sm);
    cursor: pointer;
  }
  .panel-header { flex-wrap: wrap; gap: 8px; }
  .panel { margin-bottom: 12px; }
  .panel-body { padding: 12px 14px; }
  .panel-header { padding: 12px 14px; }
  .modal { width: 95%; max-width: 95%; border-radius: 16px 16px 0 0; margin-top: auto; max-height: 90vh; }
  .btn { padding: 10px 16px; font-size: 14px; }
  .table-input { font-size: 14px; padding: 6px 8px; }

  /* 移动端顶部栏调整 */
  .topbar-right { display: none; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .main { padding: 10px 12px; }
}

@media (min-width: 1025px) {
  .menu-toggle { display: none; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
}

/* Utility */
.text-right { text-align: right; }
.text-center { text-align: center; }
.font-bold { font-weight: 600; }
.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mb-0 { margin-bottom: 0; }
.mb-2 { margin-bottom: 16px; }
.text-green { color: var(--green); }
.text-orange { color: var(--orange); }
.text-primary { color: var(--primary); }
.text-gray { color: var(--gray-500); }
.text-sm { font-size: 12px; }

/* 收据图片悬停放大 */
.receipt-img-cell { position: relative; }
.receipt-img-thumb { width: 48px; height: 48px; border-radius: 6px; object-fit: cover; border: 1px solid var(--gray-200); cursor: pointer; }
/* 收据列表图片不再 hover 放大，只保留点击查看原图 */
.receipt-img-none { width: 48px; height: 48px; border-radius: 6px; background: var(--gray-100); display: flex; align-items: center; justify-content: center; font-size: 11px; color: var(--gray-400); }

/* 分类图片悬停时JS浮层显示原图 */
.classify-img { cursor: pointer; }

/* 搜索选择器 */
.ss-input { width: 100%; box-sizing: border-box; }
.ss-drop { position: absolute; top: 100%; left: 0; right: 0; z-index: 300; background: white; border: 1px solid var(--gray-200); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,0.12); max-height: 200px; overflow-y: auto; margin-top: 2px; }
.ss-item { padding: 8px 12px; cursor: pointer; font-size: 13px; color: var(--gray-700); }
.ss-item:hover { background: var(--primary-light); }
.ss-item.ss-add { color: var(--primary); font-weight: 500; border-top: 1px solid var(--gray-100); }
