/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f0f2f5;
  --card-bg: #ffffff;
  --primary: #4f6df5;
  --primary-light: #e8ecff;
  --primary-dark: #3b56d4;
  --success: #52c41a;
  --success-light: #f0fae6;
  --warning: #faad14;
  --warning-light: #fffbe6;
  --danger: #ff4d4f;
  --danger-light: #fff1f0;
  --text: #1a1a2e;
  --text-secondary: #6c757d;
  --text-tertiary: #adb5bd;
  --border: #e8e8e8;
  --shadow: 0 2px 8px rgba(0,0,0,0.06);
  --shadow-lg: 0 4px 16px rgba(0,0,0,0.1);
  --radius: 12px;
  --radius-sm: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* ===== Header ===== */
.header {
  background: linear-gradient(135deg, #4f6df5 0%, #6a5acd 100%);
  color: #fff;
  padding: 0 32px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 12px rgba(79, 109, 245, 0.3);
}

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 20px;
  font-weight: 700;
}

.logo-icon {
  width: 36px;
  height: 36px;
  background: rgba(255,255,255,0.2);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}

.nav-tabs {
  display: flex;
  gap: 4px;
}

.tab-btn {
  background: transparent;
  border: none;
  color: rgba(255,255,255,0.7);
  padding: 8px 20px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 15px;
  font-weight: 500;
  transition: all 0.2s;
  font-family: var(--font);
}

.tab-btn:hover {
  background: rgba(255,255,255,0.1);
  color: #fff;
}

.tab-btn.active {
  background: rgba(255,255,255,0.2);
  color: #fff;
}

/* ===== Main Content ===== */
.main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px 32px;
}

.module { display: none; }
.module.active { display: block; }

/* ===== Cards ===== */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 20px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.card-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-title::before {
  content: '';
  width: 4px;
  height: 20px;
  background: var(--primary);
  border-radius: 2px;
}

/* ===== Summary Cards ===== */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

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

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

.stat-card.success::before { background: var(--success); }
.stat-card.warning::before { background: var(--warning); }
.stat-card.danger::before { background: var(--danger); }

.stat-label {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}

.stat-value .unit {
  font-size: 14px;
  font-weight: 400;
  color: var(--text-secondary);
  margin-left: 4px;
}

.stat-change {
  font-size: 13px;
  margin-top: 6px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.stat-change.up { color: var(--success); }
.stat-change.down { color: var(--danger); }

/* ===== Charts ===== */
.chart-container {
  position: relative;
  height: 320px;
  width: 100%;
}

.chart-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

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

/* ===== Table ===== */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-sm);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th {
  background: #f5f7fa;
  padding: 12px 16px;
  text-align: left;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
  border-bottom: 2px solid var(--border);
}

td {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tr:hover td {
  background: #f9faff;
}

.text-right { text-align: right; }
.text-center { text-align: center; }

.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
}

.badge-primary { background: var(--primary-light); color: var(--primary-dark); }
.badge-success { background: var(--success-light); color: var(--success); }
.badge-warning { background: var(--warning-light); color: #d48806; }
.badge-danger { background: var(--danger-light); color: var(--danger); }

/* ===== Forms ===== */
.form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-group label {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
}

input, select {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.2s;
  background: #fff;
  color: var(--text);
}

input:focus, select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 109, 245, 0.1);
}

input[type="number"] { width: 120px; }

.btn {
  padding: 8px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  font-family: var(--font);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

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

.btn-primary:hover { background: var(--primary-dark); }

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

.btn-outline:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 4px 12px; font-size: 13px; }

/* ===== Year Selector ===== */
.year-selector {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.year-pills {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.year-pill {
  padding: 6px 16px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  transition: all 0.2s;
  font-family: var(--font);
}

.year-pill:hover { border-color: var(--primary); color: var(--primary); }
.year-pill.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* ===== Progress Bar ===== */
.progress-wrap {
  margin: 16px 0;
}

.progress-bar {
  height: 24px;
  background: #f0f2f5;
  border-radius: 12px;
  overflow: hidden;
  position: relative;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #4f6df5, #6a5acd);
  border-radius: 12px;
  transition: width 0.5s ease;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 12px;
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  min-width: 40px;
}

.progress-info {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
  font-size: 14px;
  color: var(--text-secondary);
}

/* ===== Savings Items ===== */
.savings-section {
  margin-bottom: 16px;
}

.savings-section-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  padding: 8px 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.savings-section-title .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary);
}

.savings-section-title.expected .dot { background: var(--warning); }

.editable-cell {
  cursor: pointer;
  position: relative;
}

.editable-cell:hover {
  background: var(--primary-light);
  border-radius: 4px;
}

.editable-cell input {
  width: 100%;
  padding: 4px 8px;
  border: 1px solid var(--primary);
  border-radius: 4px;
  font-size: 14px;
}

/* ===== Modal ===== */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.4);
  z-index: 200;
  justify-content: center;
  align-items: center;
}

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

.modal {
  background: #fff;
  border-radius: var(--radius);
  padding: 28px;
  width: 90%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}

.modal-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 20px;
}

.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  margin-top: 20px;
}

/* ===== Misc ===== */
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }
.text-secondary { color: var(--text-secondary); }
.text-primary { color: var(--primary); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.font-bold { font-weight: 600; }
.font-large { font-size: 18px; }
.text-sm { font-size: 13px; }

.highlight-row {
  background: #f0f5ff !important;
}

.highlight-row:hover td {
  background: #e6f0ff !important;
}

.empty-state {
  text-align: center;
  padding: 40px;
  color: var(--text-tertiary);
}

/* ===== Sync Bar ===== */
.sync-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255,255,255,0.15);
  padding: 4px 12px;
  border-radius: 8px;
  font-size: 13px;
}
.sync-status { color: rgba(255,255,255,0.9); }
.sync-status.synced { color: #b7eb8f; }
.sync-status.syncing { color: #ffe58f; }
.sync-status.error { color: #ffa39e; }
.sync-btn-mini {
  background: rgba(255,255,255,0.2);
  border: none;
  color: #fff;
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  white-space: nowrap;
}
.sync-btn-mini:hover { background: rgba(255,255,255,0.3); }

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .header { padding: 0 12px; }
  .header-inner {
    flex-wrap: wrap;
    height: auto;
    padding: 8px 0;
    gap: 8px;
  }
  .logo { font-size: 17px; gap: 6px; }
  .logo-icon { width: 30px; height: 30px; font-size: 17px; }
  .nav-tabs { width: 100%; gap: 0; }
  .tab-btn { padding: 6px 10px; font-size: 13px; flex: 1; text-align: center; }
  .main { padding: 12px; }
  .card { padding: 14px; margin-bottom: 14px; }
  .card-title { font-size: 15px; }
  .card-header { margin-bottom: 14px; flex-wrap: wrap; gap: 8px; }
  .chart-grid { grid-template-columns: 1fr; gap: 14px; }
  .chart-container { height: 260px; }
  .summary-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: 14px;
  }
  .stat-card { padding: 14px; }
  .stat-value { font-size: 20px; }
  .stat-label { font-size: 12px; }
  .sub-tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .sub-tab-btn { padding: 8px 16px; font-size: 14px; white-space: nowrap; }
  table { font-size: 12px; }
  th { padding: 8px 10px; }
  td { padding: 7px 10px; }
  .year-pills { gap: 4px; }
  .year-pill { padding: 5px 12px; font-size: 13px; }
  .modal {
    width: 95%;
    padding: 16px;
    max-height: 85vh;
  }
  .modal-title { font-size: 16px; margin-bottom: 14px; }
  .form-row { flex-direction: column; gap: 10px; }
  .form-group { width: 100%; }
  input, select { width: 100%; }
  input[type="number"] { width: 100%; }
  .btn { padding: 10px 16px; font-size: 14px; }
  .btn-sm { padding: 6px 12px; font-size: 12px; }
  .progress-bar { height: 20px; }
  .progress-fill { font-size: 11px; }
  .toast { right: 12px; bottom: 12px; left: 12px; text-align: center; }
  .sync-bar { font-size: 12px; padding: 3px 8px; }
}

@media (max-width: 480px) {
  .summary-grid { grid-template-columns: 1fr; }
  .logo { font-size: 15px; }
  .logo-icon { width: 28px; height: 28px; font-size: 15px; }
  .card { padding: 12px; }
  .stat-value { font-size: 18px; }
  .chart-container { height: 220px; }
  .tab-btn { padding: 6px 8px; font-size: 12px; }
  .sub-tab-btn { padding: 8px 12px; font-size: 13px; }
  table { font-size: 11px; }
  th { padding: 6px 8px; }
  td { padding: 6px 8px; }
}

/* ===== Mobile table sticky first column ===== */
@media (max-width: 768px) {
  .table-wrap table td:first-child,
  .table-wrap table th:first-child {
    position: sticky;
    left: 0;
    background: #fff;
    z-index: 1;
    box-shadow: 2px 0 4px rgba(0,0,0,0.06);
  }
  .table-wrap table thead th:first-child {
    background: #f5f7fa;
  }
  .table-wrap table tbody tr:hover td:first-child {
    background: #f9faff;
  }
}

/* ===== Sub Tabs ===== */
.sub-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  border-bottom: 2px solid var(--border);
  padding-bottom: 0;
}

.sub-tab-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  padding: 10px 24px;
  cursor: pointer;
  font-size: 15px;
  font-weight: 500;
  transition: all 0.2s;
  font-family: var(--font);
  position: relative;
  bottom: -2px;
  border-bottom: 3px solid transparent;
  border-radius: 0;
}

.sub-tab-btn:hover {
  color: var(--primary);
}

.sub-tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 600;
}

.sub-module { display: none; }
.sub-module.active { display: block; animation: fadeIn 0.3s ease; }

/* ===== Tooltip ===== */
.tooltip {
  position: relative;
  cursor: help;
}

.tooltip:hover::after {
  content: attr(data-tip);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: #333;
  color: #fff;
  padding: 4px 12px;
  border-radius: 4px;
  font-size: 12px;
  white-space: nowrap;
  z-index: 10;
}

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

.module.active {
  animation: fadeIn 0.3s ease;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #333;
  color: #fff;
  padding: 12px 24px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  z-index: 300;
  opacity: 0;
  transform: translateY(20px);
  transition: all 0.3s;
}

.toast.show { opacity: 1; transform: translateY(0); }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
