/* ---------------------------------------------------------------------------
   记账簿 · 网页版
   奶油 + 鼠尾草绿，圆角卡片，移动端自适应
--------------------------------------------------------------------------- */

:root {
  --page: #DCE5D2;
  --card: #FBF7EA;
  --card-soft: #F3EEDD;
  --border: #D9D2BC;
  --text: #5B5346;
  --muted: #8B8373;
  --accent: #8FAE7E;
  --accent-dark: #7B9B6B;
  --accent-soft: #E8EFDD;
  --income: #6E9961;
  --expense: #C0806F;
  --shadow: 0 10px 30px rgba(91, 83, 70, 0.08);
  --radius: 22px;
}

* { box-sizing: border-box; }

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

body {
  min-height: 100vh;
  background: var(--page);
  color: var(--text);
  font-family: "Microsoft YaHei UI", "PingFang SC", "Hiragino Sans GB",
               "Noto Sans SC", system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button, input, select {
  font: inherit;
  color: inherit;
}

.hidden { display: none !important; }

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

.app {
  max-width: 1180px;
  margin: 0 auto;
  padding: 24px 24px 36px;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding: 4px 4px 14px;
}

.brand h1 {
  margin: 0;
  font-size: 27px;
  letter-spacing: 0.5px;
}

.brand p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

/* --------------------------------------------------------------------------
   通用控件
--------------------------------------------------------------------------- */

.pill {
  border: 0;
  border-radius: 999px;
  padding: 10px 18px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
  white-space: nowrap;
}

.pill.primary { background: var(--accent); color: #fff; }
.pill.primary:hover { background: var(--accent-dark); }

.pill.ghost { background: transparent; color: var(--muted); }
.pill.ghost:hover { background: rgba(255, 255, 255, 0.45); color: var(--text); }

.pill.soft {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
}
.pill.soft:hover { background: var(--card-soft); }

.pill.danger {
  background: var(--card);
  color: var(--expense);
  border: 1px solid var(--border);
}
.pill.danger:hover { background: #F6E7E2; }

.pill.small { padding: 7px 15px; font-size: 13px; }
.pill.tiny { padding: 4px 11px; font-size: 12px; }
.pill.large { padding: 13px 30px; font-size: 16px; }

.field {
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 14px;
  padding: 10px 12px;
  min-height: 42px;
  transition: border-color 0.15s ease;
}

.field:focus, .input:focus {
  outline: none;
  border-color: var(--accent);
}

.select { cursor: pointer; }

.date-btn {
  cursor: pointer;
  min-width: 168px;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.input {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 14px;
  padding: 11px 14px;
  min-height: 44px;
}

.field-label {
  display: block;
  margin: 14px 0 6px;
  color: var(--muted);
  font-size: 12.5px;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* --------------------------------------------------------------------------
   日期栏
--------------------------------------------------------------------------- */

.datebar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 2px 4px 14px;
}

.datebar .spacer { flex: 1; }

.nav-day {
  font-size: 18px;
  line-height: 1;
  padding: 7px 13px;
}

/* --------------------------------------------------------------------------
   汇总卡片
--------------------------------------------------------------------------- */

.cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin: 4px 0 16px;
}

.card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}

.card-label {
  display: flex;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
}

.card-value {
  font-size: 26px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 7px;
  border-radius: 50%;
  background: var(--muted);
  flex: 0 0 auto;
}

.dot.income { background: var(--income); }
.dot.expense { background: var(--expense); }
.dot.neutral { background: var(--text); }

.income { color: var(--income); }
.expense { color: var(--expense); }

/* --------------------------------------------------------------------------
   工作区：明细 + 当日分类
--------------------------------------------------------------------------- */

.workspace {
  display: grid;
  grid-template-columns: 3fr 2fr;
  gap: 14px;
  align-items: stretch;
  margin-bottom: 4px;
}

.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  min-width: 0;
}

.detail-panel { display: flex; flex-direction: column; }

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 2px 10px;
}

.hint {
  margin-right: auto;
  color: var(--muted);
  font-size: 12px;
}

/* --------------------------------------------------------------------------
   明细列表
--------------------------------------------------------------------------- */

.thead,
.record {
  display: grid;
  grid-template-columns: 70px minmax(0, 1fr) 130px minmax(0, 1.3fr);
  column-gap: 18px;
  align-items: center;
}

.thead {
  padding: 10px 14px;
  background: var(--card-soft);
  border-radius: 12px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.record-list { margin-top: 6px; }

.record {
  width: 100%;
  padding: 12px 14px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  text-align: left;
  cursor: pointer;
  transition: background 0.12s ease;
}

.record:nth-child(even) { background: var(--card-soft); }
.record:hover { background: var(--accent-soft); }

.r-type { color: var(--muted); font-size: 13px; }
.r-cat { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.r-amount {
  text-align: right;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.r-note {
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty {
  margin: 0;
  padding: 34px 0;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
}

/* --------------------------------------------------------------------------
   分类区块 + 饼图
--------------------------------------------------------------------------- */

.cat-section {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.cat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-bottom: 6px;
}

.cat-title {
  display: inline-flex;
  align-items: center;
  font-size: 14px;
  font-weight: 600;
}

.cat-title.income { color: var(--income); }
.cat-title.expense { color: var(--expense); }

.cat-body { flex: 1; min-height: 0; }

.cat-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
}

.cat-row:nth-child(odd) { background: var(--card-soft); }

.cat-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cat-amount {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.cat-percent {
  width: 56px;
  color: var(--muted);
  font-size: 12px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.cat-empty {
  margin: 0;
  padding: 18px 10px;
  color: var(--muted);
  font-size: 13px;
}

.pie-layout {
  display: flex;
  gap: 14px;
  align-items: center;
  padding: 4px 0;
}

.pie {
  flex: 0 0 auto;
  width: 140px;
  height: 140px;
  border-radius: 50%;
  box-shadow: inset 0 0 0 2px var(--card);
}

.legend {
  flex: 1;
  min-width: 0;
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 0;
  font-size: 12px;
}

.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: 0 0 auto;
}

.legend-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.legend-value {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* --------------------------------------------------------------------------
   状态栏
--------------------------------------------------------------------------- */

.status {
  padding: 14px 4px 0;
  color: var(--muted);
  font-size: 12.5px;
}

/* --------------------------------------------------------------------------
   遮罩层 / 弹窗
--------------------------------------------------------------------------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  overflow-y: auto;
  background: rgba(75, 70, 60, 0.35);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}

.screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px 18px;
}

.welcome-card,
.modal-card,
.calendar-card {
  width: min(480px, 100%);
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  padding: 24px;
  background: var(--card);
  border-radius: 26px;
  box-shadow: 0 20px 60px rgba(60, 55, 45, 0.25);
}

.welcome-card { width: min(560px, 100%); }
.modal-card.stats-card { width: min(960px, 100%); }

.welcome-title {
  margin: 0;
  font-size: 24px;
}

.welcome-sub {
  margin: 6px 0 4px;
  color: var(--muted);
  font-size: 13px;
}

.manual-title,
.modal-title {
  margin: 18px 0 0;
  font-size: 15px;
}

.modal-title { margin: 0; }

.stats-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.stats-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}

.stats-cards { margin: 0 0 14px; }

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

.stats-grid .pie {
  width: 180px;
  height: 180px;
}

/* --------------------------------------------------------------------------
   说明书
--------------------------------------------------------------------------- */

.manual {
  max-height: 38vh;
  margin-top: 8px;
  padding: 16px 18px;
  overflow-y: auto;
  background: var(--card-soft);
  border-radius: 16px;
  font-size: 13.5px;
}

.manual h3 {
  margin: 18px 0 8px;
  font-size: 14px;
  color: var(--text);
}

.manual h3:first-child { margin-top: 0; }

.manual ol {
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: manual;
}

.manual li {
  position: relative;
  margin: 8px 0;
  padding-left: 34px;
  line-height: 1.6;
  counter-increment: manual;
}

.manual li::before {
  content: "● " counter(manual) ".";
  position: absolute;
  left: 0;
  color: var(--accent);
  font-weight: 700;
}

.welcome-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 18px;
}

.modal-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 20px;
}

.modal-actions .spacer { flex: 1; }

/* --------------------------------------------------------------------------
   日历
--------------------------------------------------------------------------- */

.calendar-card { width: min(360px, 100%); }

.cal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.cal-title { font-size: 16px; }

.cal-nav {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 24px;
  line-height: 1;
  padding: 4px 14px;
  border-radius: 10px;
  cursor: pointer;
}

.cal-nav:hover { background: var(--accent-soft); }

.cal-weekdays,
.cal-days {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.cal-weekdays span {
  padding: 4px 0;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.cal-days button {
  padding: 9px 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
  font-variant-numeric: tabular-nums;
}

.cal-days button:hover { background: var(--accent-soft); }
.cal-days button.today { color: var(--accent-dark); font-weight: 700; }
.cal-days button.selected { background: var(--accent); color: #fff; }

.cal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}

/* --------------------------------------------------------------------------
   移动端适配
--------------------------------------------------------------------------- */

@media (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; }
  .side-panel { flex-direction: row; }
  .cat-section { flex: 1; }
}

@media (max-width: 760px) {
  .app { padding: 16px 14px 28px; }

  .topbar { align-items: center; padding-bottom: 10px; }
  .brand h1 { font-size: 22px; }
  .brand p { font-size: 12px; }

  .datebar { gap: 6px; padding-bottom: 12px; }
  .datebar .spacer { display: none; }
  .date-btn { flex: 1; min-width: 0; }
  #statsBtn { margin-left: auto; }

  .cards { gap: 8px; }
  .card { padding: 12px 12px; border-radius: 18px; gap: 4px; }
  .card-label { font-size: 11px; }
  .card-value { font-size: 17px; }

  .panel { padding: 10px 10px 12px; border-radius: 20px; }
  .toolbar { padding-bottom: 8px; }
  .hint { display: none; }

  .thead { display: none; }

  .record {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "cat amount"
      "type amount"
      "note note";
    column-gap: 10px;
    row-gap: 3px;
    padding: 11px 8px;
    border-radius: 0;
    border-bottom: 1px solid rgba(217, 210, 188, 0.6);
  }

  .record:nth-child(even) { background: transparent; }
  .record:last-child { border-bottom: 0; }

  .r-cat { grid-area: cat; font-size: 14.5px; }
  .r-type { grid-area: type; font-size: 12px; }
  .r-amount { grid-area: amount; font-size: 16px; align-self: center; }
  .r-note { grid-area: note; font-size: 12.5px; }

  .side-panel { flex-direction: column; }

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

  .field-row { grid-template-columns: 1fr; gap: 0; }

  .overlay { padding: 10px; }
  .welcome-card, .modal-card, .calendar-card { padding: 20px; border-radius: 22px; }
  .manual { max-height: 34vh; }

  .pie { width: 110px; height: 110px; }
  .stats-grid .pie { width: 150px; height: 150px; margin: 0 auto; }
}

@media (max-width: 380px) {
  .card-value { font-size: 15px; }
  .card { padding: 10px 9px; }
  .card-label { font-size: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
