/* ============================================================
   良耳记账本 · 手机端样式
   设计基调：小清新、克制留白、柔和阴影、低饱和配色
   约定：不使用纯黑纯白、不使用炫光渐变，色彩来源于品牌茶绿
   ============================================================ */

:root {
  --bg:        #F7F5F0;
  --surface:   #FFFDFA;
  --surface-2: #F1EEE7;
  --line:      #E9E4DA;
  --text:      #3B3A36;
  --text-2:    #7C796F;
  --text-3:    #A9A69B;

  --brand:     #6B9E86;
  --brand-ink: #4E8069;
  --expense:   #D98E7A;
  --income:    #6B9E86;

  --shadow-sm: 0 1px 2px rgba(59, 58, 54, .05);
  --shadow-md: 0 6px 20px -8px rgba(59, 58, 54, .18);
  --shadow-lg: 0 -10px 40px -12px rgba(59, 58, 54, .22);

  --radius:    18px;
  --radius-sm: 12px;
  --tap:       44px;

  --ease: cubic-bezier(.22, .61, .36, 1);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "PingFang SC", "Hiragino Sans GB",
               "Microsoft YaHei", "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }

/* ------------------------------ 布局 ------------------------------ */

.app {
  max-width: 520px;
  margin: 0 auto;
  padding: 12px 16px calc(112px + env(safe-area-inset-bottom));
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 16px 0;
}

.card-title {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: .02em;
  color: var(--text);
}

.card-hint, .legend { font-size: 12px; color: var(--text-3); }
.legend { display: flex; gap: 12px; }
.legend-item { display: inline-flex; align-items: center; gap: 5px; }
.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.dot.expense { background: var(--expense); }
.dot.income  { background: var(--income); }

/* ----------------------------- 顶部栏 ----------------------------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  height: 52px;
  margin-bottom: 8px;
}

.month-title {
  min-width: 132px;
  height: var(--tap);
  padding: 0 12px;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: .02em;
  border-radius: var(--radius-sm);
}

.month-nav {
  width: var(--tap);
  height: var(--tap);
  font-size: 22px;
  line-height: 1;
  color: var(--text-3);
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.month-nav:active { background: var(--surface-2); }

/* ------------------------------ 概览 ------------------------------ */

.hero {
  padding: 20px 18px 18px;
  margin-bottom: 12px;
}

.hero-label {
  margin: 0 0 6px;
  font-size: 13px;
  color: var(--text-3);
}

.hero-value {
  margin: 0;
  font-size: 34px;
  font-weight: 650;
  letter-spacing: -.01em;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.hero-split {
  display: flex;
  align-items: center;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.hero-item { flex: 1; display: flex; flex-direction: column; gap: 3px; }
.hero-item:last-child { align-items: flex-end; }
.hero-item-label { font-size: 12px; color: var(--text-3); }
.hero-item-value {
  font-size: 17px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.hero-item-value.expense { color: var(--expense); }
.hero-item-value.income  { color: var(--income); }
.hero-divider { width: 1px; height: 26px; background: var(--line); }

/* ------------------------------ 趋势 ------------------------------ */

.trend { padding-bottom: 14px; margin-bottom: 12px; }

.trend-chart {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 92px;
  padding: 12px 16px 0;
}

.trend-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  height: 100%;
  justify-content: flex-end;
}

.trend-bars {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 3px;
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
}

.trend-bar {
  width: 8px;
  min-height: 3px;
  border-radius: 4px 4px 2px 2px;
  transition: height .3s var(--ease);
}
.trend-bar.expense { background: color-mix(in srgb, var(--expense) 75%, #fff); }
.trend-bar.income  { background: color-mix(in srgb, var(--income) 75%, #fff); }

.trend-label {
  font-size: 11px;
  color: var(--text-3);
  white-space: nowrap;
}
.trend-col.is-current .trend-label { color: var(--brand-ink); font-weight: 600; }

/* ------------------------------ 明细 ------------------------------ */

.records { padding-bottom: 6px; background: transparent; }

.record-list { padding: 8px 0 4px; }

.day-group { margin-bottom: 6px; }

.day-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 10px 16px 6px;
}

.day-date { font-size: 12.5px; color: var(--text-2); font-weight: 600; }
.day-total { font-size: 12px; color: var(--text-3); font-variant-numeric: tabular-nums; }

.record-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 56px;
  padding: 8px 16px;
  text-align: left;
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.day-group .record-item:last-child { border-radius: 0 0 var(--radius) var(--radius); }
.day-group .record-item:first-of-type { border-top: none; }
.record-item:active { background: var(--surface-2); }

.cat-badge {
  flex: none;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 600;
  color: #FFFFFF;
  background: var(--text-3);
}

.record-main { flex: 1; min-width: 0; }
.record-name {
  font-size: 15px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.record-note {
  font-size: 12px;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}
.record-amount {
  flex: none;
  font-size: 16px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.01em;
}
.record-amount.expense { color: var(--expense); }
.record-amount.income  { color: var(--income); }

/* 骨架屏（不用 spinner） */
.skeleton-item {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 56px;
  padding: 8px 16px;
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.skeleton-item:first-child { border-top: none; border-radius: var(--radius) var(--radius) 0 0; }
.skeleton-item:last-child { border-radius: 0 0 var(--radius) var(--radius); }
.sk {
  background: linear-gradient(90deg, #EFEBE3 25%, #F6F3EC 37%, #EFEBE3 63%);
  background-size: 400% 100%;
  animation: sk 1.4s ease infinite;
  border-radius: 8px;
}
.sk-badge { width: 38px; height: 38px; border-radius: 12px; flex: none; }
.sk-line { height: 11px; }
.sk-main { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.sk-w60 { width: 60%; }
.sk-w35 { width: 35%; }
.sk-amount { width: 54px; height: 14px; flex: none; }

@keyframes sk { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* 空状态 */
.empty-state {
  padding: 44px 24px 48px;
  text-align: left;
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}
.empty-title { margin: 0 0 6px; font-size: 15px; font-weight: 600; }
.empty-desc { margin: 0; font-size: 13px; color: var(--text-3); line-height: 1.7; }

/* 重新加载提示 */
.list-error {
  padding: 24px 16px;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--text-2);
}
.retry-btn {
  display: block;
  margin: 12px auto 0;
  min-height: 40px;
  padding: 0 20px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  font-size: 13px;
  color: var(--text);
}

/* ------------------------------ 悬浮按钮 ------------------------------ */

.fab {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(20px + env(safe-area-inset-bottom));
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 52px;
  padding: 0 26px;
  border-radius: 999px;
  background: var(--brand);
  color: #FFFFFF;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: .02em;
  box-shadow: 0 10px 24px -10px rgba(78, 128, 105, .75);
  transition: transform .16s var(--ease), box-shadow .16s var(--ease);
  z-index: 20;
}
.fab:active { transform: translateX(-50%) scale(.96); }
.fab-plus { font-size: 20px; line-height: 1; margin-top: -1px; }

/* ------------------------------ 记账面板 ------------------------------ */

.sheet-mask {
  position: fixed;
  inset: 0;
  background: rgba(59, 58, 54, .32);
  opacity: 0;
  transition: opacity .22s var(--ease);
  z-index: 40;
}
.sheet-mask.is-open { opacity: 1; }

.sheet {
  position: fixed;
  left: 50%;
  bottom: 0;
  width: min(520px, 100%);
  transform: translate(-50%, 100%);
  background: var(--surface);
  border-radius: 22px 22px 0 0;
  box-shadow: var(--shadow-lg);
  padding: 8px 18px calc(18px + env(safe-area-inset-bottom));
  transition: transform .26s var(--ease);
  z-index: 50;
  max-height: 92vh;
  overflow-y: auto;
}
.sheet.is-open { transform: translate(-50%, 0); }

.sheet-grip {
  width: 38px;
  height: 4px;
  border-radius: 2px;
  background: var(--line);
  margin: 4px auto 8px;
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: var(--tap);
}

.link-btn {
  min-height: 40px;
  padding: 0 8px;
  font-size: 14px;
  color: var(--text-2);
  border-radius: var(--radius-sm);
}
.link-btn.danger { color: var(--expense); }

/* 分段控件 */
.seg {
  position: relative;
  display: flex;
  padding: 3px;
  background: var(--surface-2);
  border-radius: 999px;
}
.seg-btn {
  position: relative;
  z-index: 1;
  min-width: 68px;
  height: 34px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-3);
  border-radius: 999px;
  transition: color .18s var(--ease);
}
.seg-btn.is-active { color: var(--brand-ink); }
.seg-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 68px;
  height: 34px;
  background: var(--surface);
  border-radius: 999px;
  box-shadow: var(--shadow-sm);
  transition: transform .22s var(--ease);
}
.seg[data-kind="income"] .seg-thumb { transform: translateX(68px); }

/* 金额 */
.amount-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 12px 4px 14px;
  border-bottom: 1px solid var(--line);
}
.amount-symbol { font-size: 22px; color: var(--text-3); }
.amount-input {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
  background: transparent;
  font-size: 34px;
  font-weight: 650;
  letter-spacing: -.01em;
  font-variant-numeric: tabular-nums;
  padding: 0;
}
.amount-input::placeholder { color: #D5D1C7; }

/* 分类网格 */
.cat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 16px 0 6px;
}
.cat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-height: 74px;
  padding: 8px 2px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  transition: background .15s var(--ease), border-color .15s var(--ease);
}
.cat-item:active { background: var(--surface-2); }
.cat-item.is-active { background: var(--surface-2); border-color: var(--line); }
.cat-item .cat-badge { width: 40px; height: 40px; }
.cat-name { font-size: 12px; color: var(--text-2); }
.cat-item.is-active .cat-name { color: var(--text); font-weight: 600; }

/* 表单行 */
.field-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 50px;
  border-top: 1px solid var(--line);
}
.field-label {
  flex: none;
  width: 44px;
  font-size: 14px;
  color: var(--text-3);
}
.field-input {
  flex: 1;
  min-width: 0;
  height: var(--tap);
  border: none;
  outline: none;
  background: transparent;
  font-size: 15px;
}
.field-input::placeholder { color: #CFCBC1; }

.form-error {
  margin: 10px 0 0;
  font-size: 13px;
  color: var(--expense);
}

.primary-btn {
  width: 100%;
  height: 50px;
  margin-top: 16px;
  border-radius: 14px;
  background: var(--brand);
  color: #FFFFFF;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: .02em;
  transition: transform .14s var(--ease), opacity .14s var(--ease);
}
.primary-btn:active { transform: scale(.985); }
.primary-btn[disabled] { opacity: .55; cursor: default; }

/* ------------------------------ Toast ------------------------------ */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(92px + env(safe-area-inset-bottom));
  transform: translate(-50%, 8px);
  max-width: 76vw;
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(59, 58, 54, .9);
  color: #FBF9F5;
  font-size: 13.5px;
  opacity: 0;
  transition: opacity .2s var(--ease), transform .2s var(--ease);
  z-index: 60;
  pointer-events: none;
}
.toast.is-open { opacity: 1; transform: translate(-50%, 0); }

/* --------------------------- 登录 / 注册 --------------------------- */

/* .auth-view 自带 display:flex，会盖掉 hidden 的 display:none，
   这里用更高优先级的选择器保证隐藏生效（不影响其它元素的 transition 行为）。 */
.auth-view[hidden] { display: none; }

.auth-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 20px calc(24px + env(safe-area-inset-bottom));
}

.auth-card {
  width: 100%;
  max-width: 420px;
  padding: 28px 22px 22px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
}

.auth-brand { margin-bottom: 22px; text-align: center; }

.auth-mark {
  width: 52px;
  height: 52px;
  margin: 0 auto 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 16px;
  background: var(--brand);
  color: #FFFFFF;
  font-size: 22px;
  font-weight: 600;
}

.auth-brand h1 {
  margin: 0;
  font-size: 19px;
  font-weight: 650;
  letter-spacing: .01em;
}

.auth-sub {
  margin: 6px 0 0;
  font-size: 12.5px;
  color: var(--text-3);
}

.auth-card .field-label {
  display: block;
  width: auto;
  margin: 0 0 6px;
  font-size: 12.5px;
}

.auth-card .field-input {
  display: block;
  width: 100%;
  height: var(--tap);
  padding: 0 14px;
  margin-bottom: 14px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 15px;
}
.auth-card .field-input:focus { border-color: var(--brand); background: var(--surface); }

.auth-card .form-error { margin: 0 0 10px; }

.auth-switch { display: block; margin: 14px auto 0; text-align: center; }

/* 底部账号栏 */
.auth-foot {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 18px 0 0;
  font-size: 12.5px;
  color: var(--text-3);
}
.auth-foot .link-btn { font-size: 12.5px; }

/* --------------------------- 交互状态 --------------------------- */

button:focus-visible,
input:focus-visible,
.cat-item:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

/* --------------------------- 减少动效 --------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
  .sheet { transform: translate(-50%, 0); }
}

/* --------------------------- 窄屏适配 --------------------------- */
@media (max-width: 340px) {
  .cat-grid { grid-template-columns: repeat(3, 1fr); }
  .hero-value { font-size: 30px; }
}

/* 账单右侧：消费时刻（哪天几点几分） */
.record-title {
  display: flex;
  align-items: baseline;
  gap: 6px;
  min-width: 0;
}
.record-time {
  flex: none;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--surface-2);
}

/* 备注智能归类提示 */
.cat-hint {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--text-3);
}
.cat-hint.is-auto {
  color: var(--brand-ink);
  font-weight: 600;
}
