/* ========== 全局重置与变量 ========== */
:root {
  --primary: #1F4E79;
  --primary-light: #2E75B6;
  --primary-lighter: #DDEBF7;
  --accent: #FF6B35;
  --success: #27AE60;
  --warning: #F39C12;
  --danger: #E74C3C;
  --bg: #F0F4F8;
  --card-bg: #FFFFFF;
  --text: #2C3E50;
  --text-light: #7F8C8D;
  --text-lighter: #BDC3C7;
  --border: #E1E8ED;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 4px 20px rgba(0,0,0,0.12);
  --tab-height: 60px;
  --header-height: 80px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* ========== 顶部标题栏 ========== */
.app-header {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
  color: #fff;
  padding: 16px 20px 14px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 10px rgba(31,78,121,0.3);
}

.header-content {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-icon {
  font-size: 24px;
}

.app-header h1 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 1px;
}

.header-subtitle {
  font-size: 12px;
  opacity: 0.85;
  margin-top: 2px;
}

/* ========== Tab 导航 ========== */
.tab-bar {
  display: flex;
  background: var(--card-bg);
  height: var(--tab-height);
  position: sticky;
  top: var(--header-height);
  z-index: 99;
  box-shadow: 0 -1px 8px rgba(0,0,0,0.06);
}

.tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--text-light);
  font-size: 12px;
  transition: all 0.25s;
  position: relative;
}

.tab-item .tab-icon {
  font-size: 20px;
}

.tab-item.active {
  color: var(--primary);
  font-weight: 600;
}

.tab-item.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 40px;
  height: 3px;
  background: var(--primary);
  border-radius: 3px 3px 0 0;
}

/* ========== 主内容 ========== */
.content {
  padding-bottom: calc(var(--tab-height) + 20px);
}

.page {
  display: none;
  animation: fadeIn 0.3s ease;
}

.page.active {
  display: block;
}

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

/* ========== 筛选区 ========== */
.filter-section {
  background: var(--card-bg);
  margin: 12px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.filter-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  cursor: pointer;
  font-weight: 600;
  font-size: 15px;
  user-select: none;
}

.filter-arrow {
  font-size: 10px;
  transition: transform 0.3s;
  color: var(--text-light);
}

.filter-header.expanded .filter-arrow {
  transform: rotate(180deg);
}

.filter-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.35s ease;
  padding: 0 16px;
}

.filter-body.expanded {
  max-height: 400px;
  padding-bottom: 16px;
}

.filter-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.filter-row label {
  width: 70px;
  flex-shrink: 0;
  font-size: 13px;
  color: var(--text-light);
}

.filter-row select,
.filter-row input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  background: #FAFBFC;
  color: var(--text);
}

.filter-actions {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}

/* ========== 按钮 ========== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:active {
  background: #163a5c;
  transform: scale(0.97);
}

.btn-secondary {
  background: #ECF0F1;
  color: var(--text);
}

.btn-secondary:active {
  background: #D5DBDB;
  transform: scale(0.97);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.filter-actions .btn {
  flex: 1;
}

/* ========== 数据管理 ========== */
.data-management {
  display: flex;
  gap: 10px;
  padding: 8px 12px;
}

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

/* ========== 汇总小卡 ========== */
.summary-cards {
  display: flex;
  gap: 10px;
  padding: 0 12px;
  margin-bottom: 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.summary-cards::-webkit-scrollbar { display: none; }

.mini-card {
  flex-shrink: 0;
  min-width: 110px;
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 12px 16px;
  box-shadow: var(--shadow);
}

.mini-card .mc-label {
  font-size: 11px;
  color: var(--text-light);
  margin-bottom: 4px;
}

.mini-card .mc-value {
  font-size: 17px;
  font-weight: 700;
  color: var(--primary);
}

/* ========== 记录列表 ========== */
.record-list {
  padding: 0 12px;
}

.record-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 12px;
  overflow: hidden;
  transition: transform 0.2s;
}

.record-card:active {
  transform: scale(0.98);
}

.rc-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px 8px;
}

.rc-header-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.rc-city {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.rc-province {
  font-size: 12px;
  color: var(--text-light);
}

.rc-category {
  font-size: 11px;
  padding: 2px 10px;
  border-radius: 20px;
  font-weight: 600;
  white-space: nowrap;
}

.cat-假期游 { background: #E8F5E9; color: #2E7D32; }
.cat-周末游 { background: #E3F2FD; color: #1565C0; }
.cat-gap游  { background: #FFF3E0; color: #E65100; }

.rc-date {
  font-size: 12px;
  color: var(--text-lighter);
  padding: 0 16px;
}

.rc-costs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  padding: 10px 16px;
  font-size: 12px;
  color: var(--text-light);
}

.rc-cost-item {
  display: flex;
  align-items: center;
  gap: 3px;
}

.rc-cost-item .cost-label {
  color: var(--text-lighter);
}

.rc-cost-item .cost-value {
  color: var(--text);
  font-weight: 500;
}

.rc-transport {
  padding: 0 16px 8px;
  font-size: 12px;
  color: var(--text-light);
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.transport-tag {
  background: var(--primary-lighter);
  color: var(--primary);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
}

.rc-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  background: #FAFBFC;
}

.rc-total {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
}

.rc-total-label {
  font-size: 12px;
  color: var(--text-light);
  font-weight: 400;
}

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

.rc-actions button {
  border: none;
  background: none;
  cursor: pointer;
  font-size: 18px;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background 0.2s;
}

.rc-actions button:active {
  background: #ECEFF1;
}

.rc-notes {
  padding: 0 16px 10px;
  font-size: 12px;
  color: var(--text-light);
  line-height: 1.5;
}

/* ========== 空状态 ========== */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-light);
}

.empty-icon {
  font-size: 60px;
  display: block;
  margin-bottom: 16px;
}

.empty-state p {
  margin-bottom: 20px;
  font-size: 15px;
}

/* ========== 表单 ========== */
.expense-form {
  padding: 12px;
}

.form-section {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 12px;
}

.form-section-title {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 14px;
  color: var(--primary);
}

.form-section-title small {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-light);
}

.form-row {
  display: flex;
  gap: 12px;
}

.form-row .form-group {
  flex: 1;
}

.form-group {
  margin-bottom: 14px;
}

.form-group:last-child {
  margin-bottom: 0;
}

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

.form-group label small {
  font-weight: 400;
  color: var(--text-light);
  font-size: 11px;
}

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

.form-group input[type="text"],
.form-group input[type="date"],
.form-group input[type="number"],
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  background: #FAFBFC;
  color: var(--text);
  font-family: inherit;
  transition: border-color 0.2s;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--primary-light);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(46,117,182,0.1);
}

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

/* 单选 */
.radio-group {
  display: flex;
  gap: 8px;
}

.radio-item {
  flex: 1;
  position: relative;
}

.radio-item input[type="radio"] {
  position: absolute;
  opacity: 0;
}

.radio-item span {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 4px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
  background: #FAFBFC;
}

.radio-item input[type="radio"]:checked + span {
  border-color: var(--primary);
  background: var(--primary-lighter);
  color: var(--primary);
  font-weight: 600;
}

/* 多选 */
.checkbox-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.check-item {
  position: relative;
}

.check-item input[type="checkbox"] {
  position: absolute;
  opacity: 0;
}

.check-item span {
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  border: 2px solid var(--border);
  border-radius: 20px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
  background: #FAFBFC;
}

.check-item input[type="checkbox"]:checked + span {
  border-color: var(--primary);
  background: var(--primary-lighter);
  color: var(--primary);
  font-weight: 600;
}

/* 总花费显示 */
.total-display .total-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--accent);
  padding: 6px 0;
}

/* ========== 多选标签输入 ========== */
.multi-input-wrapper {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #FAFBFC;
  min-height: 42px;
  transition: border-color 0.2s, background 0.2s;
  cursor: text;
}

.multi-input-wrapper:focus-within {
  border-color: var(--primary-light);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(46,117,182,0.1);
}

.multi-input-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.multi-input-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  background: var(--primary-lighter);
  color: var(--primary);
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  animation: tagIn 0.2s ease;
}

@keyframes tagIn {
  from { transform: scale(0.7); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.multi-input-tag .tag-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: rgba(31,78,121,0.15);
  color: var(--primary);
  font-size: 12px;
  cursor: pointer;
  transition: background 0.2s;
  line-height: 1;
}

.multi-input-tag .tag-remove:hover {
  background: var(--danger);
  color: #fff;
}

.multi-input-wrapper input {
  flex: 1;
  min-width: 80px;
  border: none;
  background: transparent;
  outline: none;
  font-size: 14px;
  color: var(--text);
  padding: 0;
  font-family: inherit;
}

.multi-input-wrapper input::placeholder {
  color: var(--text-lighter);
}

.form-actions {
  display: flex;
  gap: 12px;
  padding: 4px 0 8px;
}

.form-actions .btn {
  flex: 1;
  padding: 14px;
  font-size: 15px;
}

/* ========== 浮动按钮 ========== */
.fab {
  position: fixed;
  bottom: calc(var(--tab-height) + 16px);
  right: 20px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: none;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(255,107,53,0.4);
  z-index: 50;
  transition: transform 0.2s;
}

.fab:active {
  transform: scale(0.9);
}

/* ========== 统计页 ========== */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  padding: 12px;
}

.kpi-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}

.kpi-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
  background: var(--primary);
}

.kpi-card.kpi-accent::before { background: var(--accent); }
.kpi-card.kpi-success::before { background: var(--success); }
.kpi-card.kpi-warning::before { background: var(--warning); }

.kpi-label {
  font-size: 12px;
  color: var(--text-light);
  margin-bottom: 4px;
}

.kpi-value {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
}

.kpi-unit {
  font-size: 12px;
  font-weight: 400;
  color: var(--text-light);
  margin-left: 2px;
}

.chart-section,
.table-section {
  background: var(--card-bg);
  margin: 0 12px 12px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}

.section-title {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--primary);
}

.chart-wrapper {
  position: relative;
  height: 220px;
}

/* 表格 */
.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  min-width: 500px;
}

.data-table th {
  background: var(--primary-lighter);
  color: var(--primary);
  font-weight: 600;
  padding: 8px 10px;
  text-align: center;
  white-space: nowrap;
}

.data-table td {
  padding: 8px 10px;
  text-align: center;
  border-bottom: 1px solid var(--border);
}

.data-table tr:last-child td {
  border-bottom: none;
  font-weight: 700;
  background: #FFF8E1;
  color: var(--primary);
}

.data-table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ========== 地图页 ========== */
.map-stats {
  display: flex;
  gap: 10px;
  padding: 12px;
  overflow-x: auto;
  scrollbar-width: none;
}
.map-stats::-webkit-scrollbar { display: none; }

.map-toggle {
  display: flex;
  gap: 0;
  margin: 0 12px 12px;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.map-toggle-btn {
  flex: 1;
  padding: 12px;
  border: none;
  background: var(--card-bg);
  color: var(--text-light);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.25s;
}

.map-toggle-btn.active {
  background: var(--primary);
  color: #fff;
}

.map-container {
  background: var(--card-bg);
  margin: 0 12px 12px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  overflow: hidden;
}

.map-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  flex-wrap: wrap;
  gap: 4px;
}

.map-header .section-title {
  margin-bottom: 0;
}

.map-hint {
  font-size: 12px;
  color: var(--text-light);
}

.map-hint strong {
  color: var(--accent);
  font-size: 16px;
}

.map-svg-wrapper {
  width: 100%;
  overflow: hidden;
  border-radius: var(--radius-sm);
  background: #EAF2F8;
  position: relative;
}

.map-svg-wrapper svg {
  width: 100%;
  height: auto;
  display: block;
  max-height: 500px;
}

/* 地图区域样式 */
.map-region {
  fill: #C8D6E5;
  stroke: #fff;
  stroke-width: 0.5;
  transition: fill 0.3s, opacity 0.3s;
  cursor: pointer;
}

.map-region.lit {
  fill: var(--accent);
  opacity: 0.85;
  animation: lightUp 0.6s ease;
}

.map-region.lit:hover {
  opacity: 1;
  filter: brightness(1.15);
}

.map-region:not(.lit):hover {
  fill: #A4B8CA;
}

@keyframes lightUp {
  0% { fill: #FFD700; opacity: 1; transform: scale(1.05); }
  50% { fill: #FF6B35; }
  100% { fill: var(--accent); opacity: 0.85; }
}

.map-legend {
  display: flex;
  gap: 16px;
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-light);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 3px;
}

.legend-dot.lit { background: var(--accent); }
.legend-dot.unlit { background: #C8D6E5; }

/* 已点亮地区列表 */
.lit-regions-section {
  background: var(--card-bg);
  margin: 0 12px 12px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}

.lit-regions-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.lit-region-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  background: linear-gradient(135deg, #FFF3E0, #FFE0B2);
  color: #E65100;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
}

.lit-region-tag .tag-count {
  background: var(--accent);
  color: #fff;
  padding: 1px 6px;
  border-radius: 10px;
  font-size: 11px;
}

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

.toast.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

/* ========== 响应式 ========== */
@media (min-width: 768px) {
  .content {
    max-width: 640px;
    margin: 0 auto;
  }
  .app-header {
    text-align: center;
  }
  .header-content {
    justify-content: center;
  }
  .kpi-grid {
    grid-template-columns: repeat(4, 1fr);
  }
  .fab {
    display: none;
  }
  .map-svg-wrapper svg {
    max-height: 600px;
  }
}
