:root {
  --bg: #fff6f9;
  --surface: #ffffff;
  --surface-2: #ffe7f0;
  --text: #5b4a56;
  --muted: #ab8ea1;
  --accent: #ff9eb7;
  --accent-2: #7bd8ae;
  --danger: #ff7a92;
  --border: #ffd9e6;
  --shadow: 0 2px 12px rgba(255, 158, 183, 0.16);
}

:root[data-theme="dark"] {
  --bg: #241d2b;
  --surface: #322838;
  --surface-2: #3f3244;
  --text: #f7e9f2;
  --muted: #c4a3bb;
  --accent: #ff9eb7;
  --accent-2: #79e0b4;
  --danger: #ff7d94;
  --border: #4f3d55;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", "PingFang TC", "Microsoft JhengHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background 0.2s, color 0.2s;
}

a {
  color: var(--accent);
}

/* ---- 登入頁 ---- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 32px 28px;
  width: 100%;
  max-width: 340px;
  text-align: center;
}

.login-card h1 {
  font-size: 20px;
  margin: 0 0 20px;
}

.login-card input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  margin-bottom: 12px;
}

.login-card button {
  width: 100%;
  padding: 12px;
  border-radius: 10px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  cursor: pointer;
}

.login-error {
  color: var(--danger);
  font-size: 13px;
  min-height: 18px;
  margin-top: 8px;
}

/* ---- 主頁面 ---- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar h1 {
  font-size: 18px;
  margin: 0;
}

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

.icon-btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 14px;
}

/* ---- 色系選擇器 ---- */
.palette-picker-wrap {
  position: relative;
}

.palette-dropdown {
  display: none;
  position: absolute;
  top: 120%;
  right: 0;
  flex-direction: column;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 8px;
  box-shadow: var(--shadow);
  min-width: 170px;
  z-index: 50;
}

.palette-dropdown.active {
  display: flex;
}

.palette-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--text);
  font-size: 13px;
  text-align: left;
}

.palette-option:hover {
  background: var(--surface-2);
}

.palette-option.active {
  font-weight: 700;
  background: var(--surface-2);
}

.palette-dot {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1px solid rgba(0, 0, 0, 0.1);
}

.accent-label {
  font-size: 11px;
  color: var(--muted);
  padding: 8px 10px 2px;
  border-top: 1px solid var(--border);
  margin-top: 4px;
}

.accent-swatches {
  display: flex;
  gap: 8px;
  padding: 4px 10px 6px;
}

.accent-swatch {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
}

.accent-swatch.active {
  border-color: var(--text);
}

main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px;
  padding-bottom: 90px;
}

.content-narrow {
  max-width: 640px;
  margin: 0 auto;
}

.tabs {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 10;
}

.tab-btn {
  flex: 1;
  padding: 12px 0;
  text-align: center;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
}

.tab-btn.active {
  color: var(--accent);
  font-weight: 600;
}

.panel {
  display: none;
}

.panel.active {
  display: block;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}

.card h2 {
  font-size: 15px;
  margin: 0 0 12px;
  color: var(--muted);
}

/* ---- 記帳頁工具列 ---- */
.tx-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.tx-toolbar h2 {
  font-size: 18px;
  margin: 0;
  color: var(--text);
}

.add-btn {
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: var(--shadow);
}

/* ---- 新增一筆彈出視窗 ---- */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(91, 74, 86, 0.35);
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

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

.modal-box {
  background: var(--surface);
  border-radius: 20px;
  padding: 20px;
  width: 100%;
  max-width: 420px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 8px 30px rgba(91, 74, 86, 0.25);
}

.modal-box-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.modal-box-header h2 {
  margin: 0;
  font-size: 16px;
  color: var(--text);
}

.modal-close-btn {
  border: none;
  background: var(--surface-2);
  color: var(--muted);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 15px;
}

/* ---- 記帳表單 ---- */
.type-switch {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.type-switch button {
  flex: 1;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
}

.type-switch button.active[data-type="expense"] {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

.type-switch button.active[data-type="income"] {
  background: var(--accent-2);
  color: #fff;
  border-color: var(--accent-2);
}

.form-row {
  margin-bottom: 10px;
}

.form-row label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
}

.form-row input,
.form-row select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
}

.primary-btn {
  width: 100%;
  padding: 12px;
  border-radius: 10px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  cursor: pointer;
  margin-top: 4px;
}

.more-fields {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 2px 12px;
  margin-bottom: 12px;
}

.more-fields summary {
  padding: 8px 0;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
}

.more-fields .form-row {
  margin-bottom: 10px;
}

.table-card {
  padding: 20px;
}

.table-scroll {
  overflow-x: auto;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.tx-table {
  border-collapse: collapse;
  width: 100%;
  min-width: 720px;
  font-size: 14px;
}

.tx-table th,
.tx-table td {
  border: 1px solid var(--border);
  padding: 10px 12px;
  text-align: center;
  white-space: nowrap;
}

.tx-table tbody tr:nth-child(even) {
  background: var(--surface-2);
}

.tx-table thead th {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  position: sticky;
  top: 0;
}

.tx-table td.col-note {
  color: var(--muted);
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tx-table td.col-amount {
  font-weight: 700;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.tx-table td.col-amount.expense {
  color: var(--danger);
}

.tx-table td.col-amount.income {
  color: var(--accent-2);
}

.cat-chip {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  color: var(--text);
  font-size: 12px;
}

.del-btn {
  border: none;
  background: none;
  color: var(--muted);
  font-size: 16px;
  cursor: pointer;
  padding: 4px 8px;
}

.empty-hint {
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  padding: 12px 0;
}

/* ---- 月報表 ---- */
.month-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 14px;
}

.month-nav button {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 8px;
  width: 32px;
  height: 32px;
  cursor: pointer;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}

.summary-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  text-align: center;
}

.summary-tile .label {
  font-size: 12px;
  color: var(--muted);
}

.summary-tile .value {
  font-size: 16px;
  font-weight: 700;
  margin-top: 4px;
}

.summary-tile.income .value {
  color: var(--accent-2);
}

.summary-tile.expense .value {
  color: var(--danger);
}

.chart-wrap {
  position: relative;
  height: 240px;
}

/* ---- 預算 ---- */
.budget-item {
  margin-bottom: 14px;
}

.budget-item .row {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  margin-bottom: 6px;
}

.budget-item .cat {
  font-weight: 600;
}

.progress-bar {
  height: 8px;
  border-radius: 4px;
  background: var(--surface-2);
  overflow: hidden;
}

.progress-bar > div {
  height: 100%;
  background: var(--accent-2);
}

.progress-bar > div.over {
  background: var(--danger);
}

.budget-del {
  border: none;
  background: none;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
}

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