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

:root {
  --primary: #4CAF7C;
  --primary-light: #81C784;
  --expense: #EF5350;
  --income: #4CAF7C;
  --background: #F5F7FA;
  --card-bg: #FFFFFF;
  --text-primary: #1A1A1A;
  --text-secondary: #666666;
  --text-hint: #999999;
  --border: #E8E8E8;
  --shadow: 0 2px 20px rgba(0, 0, 0, 0.06);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--background);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
}

/* 页面容器 - 默认移动端 */
.page {
  max-width: 480px;
  margin: 0 auto;
  padding: 24px 20px;
}

/* ===== 认证页面 ===== */
.auth-container {
  background: var(--card-bg);
  border-radius: 24px;
  padding: 40px 36px;
  box-shadow: var(--shadow);
  margin-top: 60px;
}

.auth-container h1 {
  text-align: center;
  margin-bottom: 32px;
  font-size: 26px;
  font-weight: 600;
}

.auth-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 28px;
  background: var(--background);
  padding: 6px;
  border-radius: 14px;
}

.tab-btn {
  flex: 1;
  padding: 12px 20px;
  border: none;
  background: transparent;
  border-radius: 10px;
  cursor: pointer;
  font-size: 15px;
  font-weight: 500;
  color: var(--text-secondary);
  transition: all 0.25s ease;
}

.tab-btn.active {
  background: var(--card-bg);
  color: var(--text-primary);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.auth-form input {
  width: 100%;
  padding: 16px 18px;
  margin-bottom: 14px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  font-size: 15px;
  transition: border-color 0.2s;
}

.auth-form input:focus {
  outline: none;
  border-color: var(--primary);
}

.auth-form button {
  width: 100%;
  padding: 16px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 8px;
  transition: all 0.2s;
}

.auth-form button:hover {
  background: var(--primary-light);
}

.error {
  color: var(--expense);
  text-align: center;
  margin-top: 16px;
  font-size: 14px;
}

/* ===== 主页面头部 ===== */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 0 28px;
}

header h1 {
  font-size: 22px;
  font-weight: 600;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 16px;
}

#user-email {
  font-size: 14px;
  color: var(--text-secondary);
}

#logout-btn {
  padding: 10px 20px;
  background: transparent;
  color: var(--expense);
  border: 1.5px solid var(--expense);
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s;
}

#logout-btn:hover {
  background: var(--expense);
  color: white;
}

/* ===== 主内容区域 - 移动端竖向 ===== */
main {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* ===== 利润计算器 ===== */
.calculator {
  background: var(--card-bg);
  border-radius: 20px;
  padding: 28px 24px;
  box-shadow: var(--shadow);
}

.calculator h2 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 20px;
}

.rate-display {
  text-align: center;
  padding: 14px 16px;
  background: var(--background);
  border-radius: 12px;
  margin-bottom: 20px;
  font-size: 14px;
  color: var(--text-secondary);
}

#exchange-rate {
  width: 90px;
  padding: 8px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  text-align: center;
  font-size: 15px;
  font-weight: 500;
}

.profit-preview {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
  color: white;
  padding: 28px 24px;
  border-radius: 18px;
  text-align: center;
  margin-bottom: 24px;
}

.profit-preview.loss {
  background: linear-gradient(135deg, var(--expense) 0%, #FF8A80 100%);
}

.profit-preview span:first-child {
  display: block;
  font-size: 14px;
  opacity: 0.9;
  margin-bottom: 8px;
}

.profit-value {
  font-size: 36px;
  font-weight: 700;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 24px;
}

.input-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.input-row label {
  width: 72px;
  font-size: 14px;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.input-row input[type="number"],
.input-row input[type="text"] {
  flex: 1;
  padding: 14px 16px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 15px;
  transition: border-color 0.2s;
}

.input-row input:focus {
  outline: none;
  border-color: var(--primary);
}

.input-row select {
  padding: 14px 12px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  background: white;
  cursor: pointer;
}

.save-btn {
  width: 100%;
  padding: 16px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

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

/* ===== 日历 ===== */
.calendar-section {
  background: var(--card-bg);
  border-radius: 20px;
  padding: 24px;
  box-shadow: var(--shadow);
}

.calendar-section h2 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 20px;
}

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

.calendar-header button {
  padding: 10px 18px;
  border: 1.5px solid var(--border);
  background: white;
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s;
}

.calendar-header button:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.calendar-header span {
  font-weight: 600;
  font-size: 16px;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  margin-bottom: 20px;
}

.calendar-day-header {
  text-align: center;
  font-size: 12px;
  color: var(--text-hint);
  padding: 8px 0;
  font-weight: 500;
}

.calendar-day {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.2s;
}

.calendar-day.empty {
  cursor: default;
}

.calendar-day:not(.empty):hover {
  background: var(--background);
}

.calendar-day.has-profit {
  background: rgba(76, 175, 124, 0.12);
  color: var(--income);
  font-weight: 600;
}

.calendar-day.has-loss {
  background: rgba(239, 83, 80, 0.12);
  color: var(--expense);
  font-weight: 600;
}

.calendar-day.today {
  background: rgba(76, 175, 124, 0.08);
  border-radius: 10px;
}

.calendar-day.selected {
  background: rgba(76, 175, 124, 0.15);
  color: var(--primary);
  font-weight: 600;
  border-radius: 10px;
}

.month-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.stat-item {
  padding: 18px 16px;
  background: var(--background);
  border-radius: 14px;
  text-align: center;
}

.stat-item span:first-child {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.stat-item span:last-child {
  font-size: 22px;
  font-weight: 700;
  color: var(--income);
}

/* ===== 历史记录 ===== */
.history-section {
  background: var(--card-bg);
  border-radius: 20px;
  padding: 24px;
  box-shadow: var(--shadow);
}

.history-section h2 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 20px;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 18px;
  background: var(--background);
  border-radius: 14px;
  transition: all 0.2s;
}

.history-item:hover {
  transform: translateX(4px);
}

.history-item .info {
  flex: 1;
}

.history-item .date {
  font-size: 13px;
  color: var(--text-hint);
}

.history-item .note {
  font-size: 14px;
  margin-top: 4px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 280px;
}

.history-item .amount {
  font-size: 18px;
  font-weight: 700;
  flex-shrink: 0;
  margin-left: 16px;
}

.history-item .amount.profit {
  color: var(--income);
}

.history-item .amount.loss {
  color: var(--expense);
}

.history-item .actions {
  display: flex;
  gap: 8px;
  margin-left: 12px;
}

.history-item .edit-btn,
.history-item .delete-btn {
  padding: 6px 12px;
  border: none;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
}

.history-item .edit-btn {
  background: var(--background);
  color: var(--text-secondary);
}

.history-item .edit-btn:hover {
  background: var(--primary);
  color: white;
}

.history-item .delete-btn {
  background: var(--background);
  color: var(--expense);
}

.history-item .delete-btn:hover {
  background: var(--expense);
  color: white;
}

/* 日历每天底部的金额 */
.calendar-day {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}

.calendar-day .day-amount {
  font-size: 10px;
  font-weight: 500;
  line-height: 1;
}

.calendar-day.has-profit .day-amount {
  color: var(--income);
}

.calendar-day.has-loss .day-amount {
  color: var(--expense);
}

/* ===== 弹窗样式 ===== */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}

.modal-content {
  background: white;
  border-radius: 20px;
  width: 90%;
  max-width: 360px;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  font-size: 17px;
  font-weight: 600;
  color: var(--text-primary);
}

.modal-close {
  width: 32px;
  height: 32px;
  border: none;
  background: var(--background);
  border-radius: 50%;
  font-size: 20px;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.modal-close:hover {
  background: var(--expense);
  color: white;
}

.modal-body {
  padding: 24px;
}

.modal-amount {
  margin-bottom: 20px;
}

.modal-amount label,
.modal-note label {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.modal-amount input {
  width: 100%;
  padding: 14px 16px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  transition: border-color 0.2s;
}

.modal-amount input:focus {
  outline: none;
  border-color: var(--primary);
}

.modal-note textarea {
  width: 100%;
  padding: 14px 16px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  font-size: 14px;
  resize: none;
  font-family: inherit;
  transition: border-color 0.2s;
}

.modal-note textarea:focus {
  outline: none;
  border-color: var(--primary);
}

.modal-footer {
  display: flex;
  gap: 12px;
  padding: 16px 24px 24px;
}

.modal-cancel,
.modal-save {
  flex: 1;
  padding: 14px;
  border: none;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.modal-cancel {
  background: var(--background);
  color: var(--text-secondary);
}

.modal-cancel:hover {
  background: var(--border);
}

.modal-save {
  background: var(--primary);
  color: white;
}

.modal-save:hover {
  background: var(--primary-light);
}

.loading {
  text-align: center;
  padding: 40px;
  color: var(--text-hint);
  font-size: 14px;
}

/* ========================================
   PC端适配 - 屏幕宽度 >= 1024px
   ======================================== */
@media (min-width: 1024px) {
  .page {
    max-width: 1200px;
    padding: 48px 40px;
  }
  
  /* PC端主内容三栏布局 */
  main {
    display: grid;
    grid-template-columns: 480px 1fr 1fr;
    gap: 28px;
    align-items: start;
  }
  
  .calculator {
    grid-column: 1;
    grid-row: 1;
    border-radius: 24px;
    padding: 32px;
  }
  
  .calendar-section {
    grid-column: 2 / 4;
    grid-row: 1;
    border-radius: 24px;
    padding: 28px;
  }
  
  .history-section {
    grid-column: 1 / 4;
    grid-row: 2;
    border-radius: 24px;
    padding: 28px;
  }
  
  header {
    padding: 24px 0 32px;
  }
  
  header h1 {
    font-size: 26px;
  }
  
  .profit-value {
    font-size: 44px;
  }
  
  .history-item .note {
    max-width: none;
  }
}

/* ========================================
   平板适配 - 屏幕宽度 768px - 1023px
   ======================================== */
@media (min-width: 768px) and (max-width: 1023px) {
  .page {
    max-width: 720px;
    padding: 36px 32px;
  }
  
  main {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
  }
  
  .calculator {
    grid-column: 1 / 3;
    grid-row: 1;
    border-radius: 22px;
    padding: 30px;
  }
  
  .calendar-section {
    grid-column: 1;
    grid-row: 2;
    border-radius: 20px;
    padding: 26px;
  }
  
  .history-section {
    grid-column: 2;
    grid-row: 2;
    border-radius: 20px;
    padding: 26px;
  }
  
  header h1 {
    font-size: 24px;
  }
  
  .profit-value {
    font-size: 40px;
  }
  
  .history-item .note {
    max-width: none;
  }
}
