/* ========================================
   金库 - 个人理财 PWA
   色卡：
   夜晚 #2C3735 #8E3A2A #557B78 #D5C09C
   白日 #00624E #FFDA64 #C38556 #FF8888
   ======================================== */

/* ---------- 重置 ---------- */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Noto Sans CJK SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  min-height: 100dvh;
  overflow-x: hidden;
  position: relative;
}

/* ---------- 夜晚模式（默认） ---------- */
:root {
  --bg-base: #2C3735;
  --bg-surface: rgba(85, 123, 120, 0.12);
  --bg-surface-hover: rgba(85, 123, 120, 0.2);
  --text-primary: #D5C09C;
  --text-secondary: #557B78;
  --text-muted: rgba(85, 123, 120, 0.6);
  --accent: #8E3A2A;
  --accent-soft: rgba(142, 58, 42, 0.15);
  --btn-bg: #557B78;
  --btn-text: #D5C09C;
  --btn-secondary-bg: rgba(213, 192, 156, 0.1);
  --btn-secondary-text: #D5C09C;
  --border: rgba(85, 123, 120, 0.25);
  --overlay-bg: rgba(44, 55, 53, 0.85);
  --panel-bg: #2C3735;
  --danger: #8E3A2A;
  --danger-text: #D5C09C;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
  --bg-opacity: 0.85;
}

/* ---------- 白日模式 ---------- */
@media (prefers-color-scheme: light) {
  :root {
    --bg-base: #FFDA64;
    --bg-surface: rgba(0, 98, 78, 0.08);
    --bg-surface-hover: rgba(0, 98, 78, 0.14);
    --text-primary: #00624E;
    --text-secondary: rgba(0, 98, 78, 0.7);
    --text-muted: rgba(0, 98, 78, 0.45);
    --accent: #C38556;
    --accent-soft: rgba(195, 133, 86, 0.15);
    --btn-bg: #00624E;
    --btn-text: #FFDA64;
    --btn-secondary-bg: rgba(0, 98, 78, 0.1);
    --btn-secondary-text: #00624E;
    --border: rgba(0, 98, 78, 0.2);
    --overlay-bg: rgba(255, 218, 100, 0.85);
    --panel-bg: #FFDA64;
    --danger: #C38556;
    --danger-text: #FFDA64;
    --shadow: 0 4px 24px rgba(0, 98, 78, 0.15);
    --bg-opacity: 0.15;
  }
}

/* ---------- 背景层 ---------- */
.bg-layer {
  position: fixed;
  inset: 0;
  z-index: -2;
  background-image: url("assets/mountain.jpg");
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

.bg-overlay {
  position: fixed;
  inset: 0;
  z-index: -1;
  background: var(--bg-base);
  opacity: var(--bg-opacity);
  transition: opacity 0.4s ease;
}

/* ---------- Screen 切换 ---------- */
.screen {
  display: none;
  min-height: 100dvh;
  flex-direction: column;
}

.screen.active {
  display: flex;
}

/* ---------- 首次使用引导 ---------- */
#setup-screen {
  align-items: center;
  justify-content: center;
  padding: 2rem 1.5rem;
}

.setup-card {
  text-align: center;
  max-width: 360px;
  width: 100%;
}

.setup-bear-img {
  width: 100px;
  height: 100px;
  object-fit: cover;
  border-radius: 50%;
  margin-bottom: 1.5rem;
  opacity: 0.85;
}

.setup-title {
  font-size: 2.5rem;
  font-weight: 800;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
  letter-spacing: -0.02em;
}

.setup-subtitle {
  font-size: 1rem;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 2rem;
}

.setup-input-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.currency-prefix {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
}

#setup-balance {
  width: 200px;
  padding: 0.75rem 1rem;
  font-size: 1.5rem;
  text-align: center;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text-primary);
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

#setup-balance:focus {
  border-color: var(--btn-bg);
}

#setup-balance::placeholder {
  color: var(--text-muted);
}

/* ---------- 主屏 ---------- */
#home-screen {
  padding: 1.5rem 1.25rem;
  padding-top: calc(1.5rem + env(safe-area-inset-top));
  padding-bottom: calc(4rem + env(safe-area-inset-bottom));
}

.home-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  max-width: 480px;
  margin: 0 auto;
  width: 100%;
}

.balance-section {
  text-align: center;
  margin-top: 2rem;
  margin-bottom: 1.5rem;
}

.balance-label {
  font-size: 0.875rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 0.5rem;
}

.balance-amount {
  font-size: 3.5rem;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -0.03em;
  line-height: 1.1;
}

/* ---------- 状态区（窟窿 / 水位线 / 安全区） ---------- */
.status-section {
  text-align: center;
  margin-bottom: 1.5rem;
}

.debt-display {
  margin-bottom: 0.5rem;
}

.debt-display .debt-label {
  font-size: 0.8rem;
  color: var(--accent);
  margin-right: 0.5rem;
}

.debt-display .debt-amount {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent);
}

.waterline-display {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.waterline-display .waterline-label {
  margin-right: 0.5rem;
}

.waterline-display .waterline-amount {
  font-weight: 600;
  color: var(--text-secondary);
}

.safe-section {
  text-align: center;
  margin-bottom: 2rem;
}

.safe-section .safe-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.safe-section .safe-amount {
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--text-secondary);
}

/* 隐藏控制 */
.hidden {
  display: none !important;
}

/* ---------- 落笔按钮 ---------- */
.btn-add {
  margin-bottom: 2rem;
  font-size: 1.1rem;
}

/* ---------- 最近流水 ---------- */
.recent-section {
  flex: 1;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.section-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.link-text {
  font-size: 0.85rem;
  color: var(--text-muted);
  cursor: pointer;
}

.recent-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.transaction-row {
  display: flex;
  align-items: center;
  padding: 0.75rem;
  background: var(--bg-surface);
  border-radius: 10px;
  border: 1px solid transparent;
  transition: border-color 0.2s;
}

.transaction-row .tx-date {
  font-size: 0.75rem;
  color: var(--text-muted);
  width: 48px;
  flex-shrink: 0;
}

.transaction-row .tx-note {
  flex: 1;
  font-size: 0.9rem;
  color: var(--text-primary);
  margin: 0 0.5rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.transaction-row .tx-amount {
  font-size: 0.95rem;
  font-weight: 700;
  flex-shrink: 0;
}

.tx-amount.positive {
  color: var(--text-secondary);
}

.tx-amount.negative {
  color: var(--accent);
}

/* ---------- 底部设置按钮 ---------- */
.home-footer {
  position: fixed;
  bottom: env(safe-area-inset-bottom);
  right: 1rem;
  z-index: 10;
}

.btn-settings {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: transparent;
  border: none;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0.5;
  transition: opacity 0.2s;
}

.btn-settings:hover,
.btn-settings:active {
  opacity: 0.8;
}

/* ---------- 明细页 ---------- */
.detail-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1.5rem 1.25rem 1rem;
  padding-top: calc(1.5rem + env(safe-area-inset-top));
}

.btn-back {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 0.95rem;
  cursor: pointer;
  padding: 0;
}

.detail-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
}

.detail-summary {
  display: flex;
  justify-content: space-around;
  padding: 0 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  margin: 0 1.25rem;
}

.detail-summary-item {
  text-align: center;
}

.detail-summary-label {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.detail-summary-value {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
}

.detail-list {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: 480px;
  margin: 0 auto;
  width: 100%;
}

.detail-list .transaction-row {
  position: relative;
}

/* 明细页每条的编辑/删除入口（灰色三点） */
.tx-more {
  width: 28px;
  height: 28px;
  border: none;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.4;
  flex-shrink: 0;
  border-radius: 6px;
  transition: opacity 0.2s;
}

.tx-more:hover {
  opacity: 0.7;
}

.tx-more-menu {
  position: absolute;
  right: 0;
  top: 100%;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: none;
  z-index: 20;
  overflow: hidden;
}

.tx-more-menu.show {
  display: block;
}

.tx-more-menu button {
  display: block;
  width: 100%;
  padding: 0.5rem 1rem;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 0.85rem;
  text-align: left;
  cursor: pointer;
}

.tx-more-menu button:hover {
  background: var(--bg-surface-hover);
}

.tx-more-menu button.danger {
  color: var(--accent);
}

.detail-empty {
  text-align: center;
  padding: 3rem 1rem;
}

.empty-bear-img {
  width: 80px;
  height: 80px;
  object-fit: cover;
  border-radius: 50%;
  margin-bottom: 1rem;
  opacity: 0.6;
}

.detail-empty p {
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* ---------- 设置页 ---------- */
.settings-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1.5rem 1.25rem 1rem;
  padding-top: calc(1.5rem + env(safe-area-inset-top));
}

.settings-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
}

.settings-content {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.25rem;
  max-width: 480px;
  margin: 0 auto;
  width: 100%;
}

.settings-group {
  margin-bottom: 1.5rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

.settings-danger {
  border-color: var(--accent-soft);
}

.settings-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.875rem 1rem;
  border-bottom: 1px solid var(--border);
  gap: 0.5rem;
}

.settings-item:last-child {
  border-bottom: none;
}

.settings-item-label {
  font-size: 0.9rem;
  color: var(--text-primary);
  flex-shrink: 0;
}

.settings-item-value {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.btn-edit-small {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.75rem;
  padding: 0.25rem 0.6rem;
  border-radius: 6px;
  cursor: pointer;
}

.btn-action {
  background: var(--btn-secondary-bg);
  border: 1px solid var(--border);
  color: var(--btn-secondary-text);
  font-size: 0.8rem;
  padding: 0.4rem 0.8rem;
  border-radius: 8px;
  cursor: pointer;
}

.btn-action:hover {
  background: var(--bg-surface-hover);
}

.btn-danger {
  color: var(--accent);
  border-color: var(--accent-soft);
}

.settings-about {
  text-align: center;
  padding: 2rem 1rem;
}

.settings-about p {
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.6;
}

/* ---------- 通用按钮 ---------- */
.btn-primary {
  background: var(--btn-bg);
  color: var(--btn-text);
  border: none;
  border-radius: 12px;
  padding: 0.875rem 1.5rem;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  transition: transform 0.1s, opacity 0.2s;
  -webkit-appearance: none;
  appearance: none;
}

.btn-primary:active {
  transform: scale(0.98);
  opacity: 0.9;
}

.btn-secondary {
  background: var(--btn-secondary-bg);
  color: var(--btn-secondary-text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.875rem 1.5rem;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.2s;
  -webkit-appearance: none;
  appearance: none;
}

.btn-secondary:active {
  transform: scale(0.98);
  opacity: 0.9;
}

.btn-small {
  padding: 0.5rem 0.875rem;
  font-size: 0.85rem;
}

/* ---------- Overlay 弹层 ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay-bg);
  display: none;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
  padding-bottom: calc(1rem + env(safe-area-inset-bottom));
}

.overlay.show {
  display: flex;
}

.add-panel {
  background: var(--panel-bg);
  border-radius: 16px 16px 0 0;
  padding: 1.5rem;
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow);
  animation: slideUp 0.25s ease;
}

@keyframes slideUp {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0);
  }
}

@media (min-width: 481px) {
  .add-panel {
    border-radius: 16px;
  }
  .overlay {
    align-items: center;
  }
}

.add-type-toggle {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.type-btn {
  flex: 1;
  padding: 0.6rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
}

.type-btn.active {
  background: var(--btn-bg);
  color: var(--btn-text);
  border-color: var(--btn-bg);
}

.add-input-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
  padding: 0.5rem 1rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}

#add-amount,
#edit-amount,
#initial-amount {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 1.5rem;
  font-weight: 700;
  -webkit-appearance: none;
  appearance: none;
}

#add-amount::placeholder,
#edit-amount::placeholder,
#initial-amount::placeholder {
  color: var(--text-muted);
}

.add-note-input {
  width: 100%;
  padding: 0.75rem 1rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text-primary);
  font-size: 0.95rem;
  outline: none;
  margin-bottom: 1rem;
  -webkit-appearance: none;
  appearance: none;
}

.add-note-input::placeholder {
  color: var(--text-muted);
}

.add-actions {
  display: flex;
  gap: 0.75rem;
}

.add-actions .btn-primary,
.add-actions .btn-secondary,
.add-actions .btn-danger {
  flex: 1;
}

.edit-header {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  text-align: center;
  margin-bottom: 0.5rem;
}

.edit-warning {
  font-size: 0.8rem;
  color: var(--accent);
  text-align: center;
  margin-bottom: 1rem;
}

.confirm-panel {
  background: var(--panel-bg);
  border-radius: 16px;
  padding: 2rem 1.5rem;
  width: 100%;
  max-width: 320px;
  text-align: center;
  box-shadow: var(--shadow);
}

.confirm-text {
  font-size: 1rem;
  color: var(--text-primary);
  margin-bottom: 1.5rem;
  line-height: 1.5;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: calc(5rem + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel-bg);
  color: var(--text-primary);
  padding: 0.75rem 1.5rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  font-size: 0.85rem;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
  white-space: nowrap;
}

.toast.show {
  opacity: 1;
}

/* ---------- 响应式 ---------- */
@media (min-width: 481px) {
  .balance-amount {
    font-size: 4rem;
  }
  .home-content {
    max-width: 520px;
  }
}

@media (max-width: 360px) {
  .balance-amount {
    font-size: 2.8rem;
  }
  .detail-summary {
    flex-wrap: wrap;
    gap: 0.5rem;
  }
}

/* ---------- reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
  .add-panel {
    animation: none;
  }
}
