:root {
  --bg: #f4fbf5;
  --card: #ffffff;
  --primary: #2e7d32;
  --primary-light: #e8f5e9;
  --accent: #43a047;
  --text: #1b281c;
  --muted: #6b7a6c;
  --border: #c8e6c9;
  --danger: #c62828;
  --shadow: 0 2px 8px rgba(0,0,0,0.06);
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
}

.hidden { display: none !important; }

/* 认证 */
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.auth-card {
  background: var(--card);
  width: 100%;
  max-width: 380px;
  padding: 28px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.auth-card h1 { margin: 0 0 6px; font-size: 22px; }
.auth-sub { margin: 0 0 18px; color: var(--muted); font-size: 14px; }
.auth-tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.auth-tab {
  flex: 1;
  padding: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 6px;
  cursor: pointer;
}
.auth-tab.on { background: var(--primary); color: #fff; border-color: var(--primary); }
.auth-title { margin: 0 0 14px; font-size: 18px; }

.text-input, .date-input, select.text-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 15px;
  background: #fff;
  color: var(--text);
  margin-bottom: 12px;
}
.text-input:focus, .date-input:focus { outline: none; border-color: var(--accent); }

.primary-btn {
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: 6px;
  background: var(--primary);
  color: #fff;
  font-size: 16px;
  cursor: pointer;
}
.primary-btn:active { background: var(--accent); }

.sub-btn {
  padding: 8px 14px;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
}
.sub-btn.main { background: var(--primary); color: #fff; border-color: var(--primary); }
.link-btn {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  font-size: 14px;
}
.text-btn {
  width: 100%;
  margin-top: 12px;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
}
.form-error { color: var(--danger); font-size: 13px; margin: 8px 0 0; min-height: 18px; }

/* 应用布局 */
.app { min-height: 100vh; display: flex; flex-direction: column; }
.app-header {
  background: var(--card);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow);
  position: sticky; top: 0; z-index: 10;
}
.app-header h1 { margin: 0; font-size: 18px; }
.user-bar { display: flex; align-items: center; gap: 12px; font-size: 14px; color: var(--muted); }

.nav-tabs {
  display: flex;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.nav-tab {
  flex: 1;
  min-width: 80px;
  padding: 12px;
  border: none;
  background: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  white-space: nowrap;
}
.nav-tab.on { color: var(--primary); border-bottom: 2px solid var(--primary); }

.app-main { flex: 1; padding: 12px; overflow: auto; }
.page { max-width: 1200px; margin: 0 auto; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.row-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  font-weight: 600;
  font-size: 14px;
}
.row-label .muted { color: var(--muted); font-weight: 400; font-size: 13px; }

.rmb-line { font-size: 14px; color: var(--text); margin-top: 4px; }
.rmb-line strong { color: var(--primary); font-size: 16px; }

.record-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.record-row:last-child { border-bottom: none; }
.record-row .rec-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.record-row .rec-sub { color: var(--muted); font-size: 12px; }
.record-row .rec-amount { font-weight: 600; }
.record-row .rec-actions { display: flex; gap: 8px; flex-shrink: 0; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 6px 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 16px;
  cursor: pointer;
  font-size: 14px;
}
.chip.on { background: var(--primary-light); border-color: var(--accent); color: var(--primary); }

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}
.toolbar-left, .toolbar-right { display: flex; align-items: center; gap: 8px; }
.summary-text { color: var(--muted); font-size: 14px; }

/* 表格 */
.table-wrap {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: auto;
}
.sheet-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  min-width: 0;
  font-size: 14px;
}
.sheet-table th, .sheet-table td {
  border: 1px solid var(--border);
  padding: 8px 10px;
  text-align: right;
  white-space: nowrap;
}
.sheet-table th:first-child, .sheet-table td:first-child { text-align: left; }
.sheet-table th:nth-child(2), .sheet-table td:nth-child(2) { text-align: left; }
.sheet-table th {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
  position: sticky; top: 0;
}
.sheet-table .category-row td { background: #dcedc8; font-weight: 600; text-align: left; }
.sheet-table .total-row td { background: #c8e6c9; font-weight: 600; }
.sheet-table .cell-amount {
  cursor: pointer;
  min-width: 70px;
}
.sheet-table .cell-amount:hover { background: #f1f8e9; }
.sheet-table .cell-empty { color: #bbb; }

.cell-input {
  width: 100%;
  min-width: 48px;
  max-width: 96px;
  box-sizing: border-box;
  padding: 4px;
  border: 1px solid var(--accent);
  border-radius: 4px;
  text-align: right;
}

/* 趋势图 */
.range-row { display: flex; align-items: center; gap: 8px; }
.range-row .date-input { flex: 1; margin-bottom: 0; }
.subject-list { display: flex; flex-wrap: wrap; gap: 8px; }
.subject-item {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
}
.subject-item input { margin: 0; }
.subject-item.on { background: var(--primary-light); border-color: var(--accent); }
.chart-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  position: relative;
  height: 360px;
}

/* 设置列表 */
.list-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.list-row:last-child { border-bottom: none; }
.list-row .actions { display: flex; gap: 8px; }

/* 弹窗 */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}
.modal-card {
  background: var(--card);
  width: 100%;
  max-width: 420px;
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.modal-card h3 { margin: 0 0 14px; }
.form-btns { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }

/* 科目表响应式紧凑布局：列宽与内边距随屏幕宽度自适应 */
@media (max-width: 640px) {
  .app-header h1 { font-size: 16px; }
  .chart-card { height: 280px; }
}
@media (max-width: 480px) {
  .sheet-table { font-size: 12px; }
  .sheet-table th, .sheet-table td { padding: 4px 4px; line-height: 1.25; }
}
@media (max-width: 380px) {
  .sheet-table { font-size: 11px; }
  .sheet-table th, .sheet-table td { padding: 3px 2px; line-height: 1.2; }
}
