:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #16181d;
  --muted: #7c8494;
  --line: #e8eaee;
  --primary: #d92b2b;
  --primary-soft: #fdeceb;
  --primary-dark: #b31f1f;
  --gold: #f0a020;
  --green: #0f9960;
  --blue: #2563eb;
  --radius: 16px;
  --shadow: 0 2px 10px rgba(20, 26, 40, 0.06);
  --tabbar-h: 62px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  overscroll-behavior-y: none;
}

button,
input,
select,
textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
}

.app {
  max-width: 680px;
  margin: 0 auto;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 16px);
  min-height: 100vh;
}

/* ---------- 顶部 ---------- */
.topbar {
  padding: 18px 18px 10px;
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.3px;
}

.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--primary), #f4653c);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 15px;
  font-weight: 800;
}

.date-chip {
  font-size: 12.5px;
  color: var(--muted);
  background: #fff;
  border: 1px solid var(--line);
  padding: 5px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

/* ---------- 通用卡片 ---------- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}

.page {
  display: none;
  padding: 4px 14px 8px;
  animation: fade 0.18s ease;
}

.page.active {
  display: block;
}

@keyframes fade {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 18px 4px 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.4px;
}

.section-title .link {
  color: var(--primary);
  font-weight: 600;
  font-size: 13px;
}

/* ---------- 录入表单 ---------- */
.entry-card {
  padding: 18px 16px 16px;
}

.amount-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  border-bottom: 2px solid var(--primary);
  padding-bottom: 8px;
}

.amount-row .currency {
  font-size: 22px;
  font-weight: 700;
  color: var(--primary);
}

.amount-input {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
  font-size: 40px;
  font-weight: 700;
  letter-spacing: 0.5px;
  background: transparent;
  padding: 0;
}

.amount-input::placeholder {
  color: #d3d7de;
  font-weight: 600;
}

.quick-amounts {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 12px 0 2px;
  scrollbar-width: none;
}

.quick-amounts::-webkit-scrollbar {
  display: none;
}

.chip-amount {
  flex: 0 0 auto;
  padding: 6px 13px;
  border-radius: 999px;
  background: #f4f5f7;
  color: #4b5563;
  font-size: 13.5px;
  font-weight: 600;
  border: 1px solid transparent;
}

.chip-amount:active {
  background: var(--primary-soft);
  color: var(--primary);
}

.field-label {
  font-size: 12.5px;
  color: var(--muted);
  font-weight: 600;
  margin: 16px 2px 8px;
  display: block;
}

.type-grid {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
}

.type-grid::-webkit-scrollbar {
  display: none;
}

.type-chip {
  flex: 0 0 auto;
  padding: 8px 14px;
  border-radius: 11px;
  background: #f4f5f7;
  font-size: 14px;
  font-weight: 600;
  color: #4b5563;
  border: 1.5px solid transparent;
  transition: all 0.15s;
  white-space: nowrap;
}

.type-chip.on {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary);
}

.picker-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-radius: 12px;
  background: #f7f8fa;
  border: 1px solid var(--line);
  font-size: 14.5px;
  text-align: left;
}

.picker-btn .val {
  font-weight: 600;
}

.picker-btn .val.empty {
  color: var(--muted);
  font-weight: 500;
}

.picker-btn .hint {
  font-size: 12px;
  color: var(--muted);
  margin-left: 6px;
  font-weight: 400;
}

.note-input {
  width: 100%;
  padding: 11px 14px;
  border-radius: 12px;
  background: #f7f8fa;
  border: 1px solid var(--line);
  outline: none;
  resize: none;
  font-size: 14px;
  min-height: 44px;
}

.note-input:focus,
.picker-btn:focus {
  border-color: #cfd4dc;
  background: #fff;
}

.submit-btn {
  width: 100%;
  margin-top: 18px;
  padding: 15px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--primary), #ec5a35);
  color: #fff;
  font-size: 16.5px;
  font-weight: 700;
  letter-spacing: 1px;
  box-shadow: 0 6px 16px rgba(217, 43, 43, 0.25);
  transition: transform 0.1s, box-shadow 0.15s;
}

.submit-btn:active {
  transform: scale(0.985);
  box-shadow: 0 3px 10px rgba(217, 43, 43, 0.2);
}

.submit-btn:disabled {
  opacity: 0.6;
}

/* ---------- 统计 ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.stat {
  background: var(--card);
  border-radius: 14px;
  padding: 13px 10px;
  box-shadow: var(--shadow);
  text-align: center;
}

.stat .num {
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.stat .num small {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin-left: 1px;
}

.stat .lbl {
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 3px;
}

.stat.hero {
  grid-column: span 3;
  background: linear-gradient(135deg, #2b2f36, #16181d);
  color: #fff;
  text-align: left;
  padding: 16px 18px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
}

.stat.hero .num {
  font-size: 32px;
  color: #fff;
}

.stat.hero .num small {
  color: rgba(255, 255, 255, 0.6);
}

.stat.hero .lbl {
  color: rgba(255, 255, 255, 0.65);
  margin: 0;
  font-size: 12px;
}

.hero-right {
  text-align: right;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.6);
  line-height: 1.6;
}

.hero-right b {
  color: #ffd06a;
  font-size: 14px;
}

/* ---------- 记录列表 ---------- */
.list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ticket-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border-radius: 13px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  border: 1px solid transparent;
}

.ticket-row:active {
  border-color: #e5e7eb;
}

.ticket-dot {
  width: 4px;
  align-self: stretch;
  border-radius: 4px;
  background: var(--primary);
  flex: 0 0 4px;
}

.ticket-main {
  flex: 1;
  min-width: 0;
}

.ticket-title {
  font-size: 14.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ticket-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ticket-amount {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.2px;
  white-space: nowrap;
}

.ticket-amount small {
  font-size: 11px;
  color: var(--muted);
  font-weight: 600;
}

.empty {
  text-align: center;
  color: var(--muted);
  font-size: 13.5px;
  padding: 30px 10px;
}

.empty-icon {
  font-size: 30px;
  opacity: 0.35;
  margin-bottom: 6px;
}

/* ---------- 客户 ---------- */
.customer-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border-radius: 13px;
  padding: 13px 14px;
  box-shadow: var(--shadow);
}

.avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 16px;
  color: #fff;
  background: linear-gradient(135deg, #6b7280, #4b5563);
  flex: 0 0 42px;
}

.customer-main {
  flex: 1;
  min-width: 0;
}

.customer-name {
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}

.tag {
  font-size: 10.5px;
  padding: 1px 6px;
  border-radius: 5px;
  background: #f1f3f5;
  color: var(--muted);
  font-weight: 600;
}

.customer-meta {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.customer-total {
  text-align: right;
}

.customer-total b {
  font-size: 15px;
  font-weight: 700;
}

.customer-total span {
  display: block;
  font-size: 11px;
  color: var(--muted);
}

.search-box {
  width: 100%;
  padding: 11px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  outline: none;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}

.search-box:focus {
  border-color: #d0d4db;
}

/* ---------- 历史 ---------- */
.seg {
  display: flex;
  gap: 6px;
  background: #eceef1;
  padding: 4px;
  border-radius: 12px;
  margin-bottom: 14px;
}

.seg button {
  flex: 1;
  padding: 8px 4px;
  border-radius: 9px;
  font-size: 13.5px;
  font-weight: 600;
  color: #5b6373;
}

.seg button.on {
  background: #fff;
  color: var(--text);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.range-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.range-row input[type="date"] {
  flex: 1;
  min-width: 0;
  padding: 9px 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 13.5px;
}

.day-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border-radius: 13px;
  padding: 13px 15px;
  box-shadow: var(--shadow);
}

.day-date {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.2px;
}

.day-week {
  font-size: 11.5px;
  color: var(--muted);
  font-weight: 500;
  margin-left: 6px;
}

.day-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

/* ---------- 管理 ---------- */
.manage-row {
  display: flex;
  align-items: center;
  gap: 11px;
  background: var(--card);
  border-radius: 13px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
}

.color-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: 0 0 10px;
}

.row-actions {
  display: flex;
  gap: 6px;
  flex: 0 0 auto;
}

.mini-btn {
  padding: 6px 11px;
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 600;
  background: #f2f4f7;
  color: #4b5563;
}

.mini-btn.danger {
  background: #fdeceb;
  color: var(--primary);
}

.mini-btn.primary {
  background: var(--primary-soft);
  color: var(--primary);
}

.ghost-btn {
  width: 100%;
  padding: 13px;
  border-radius: 12px;
  border: 1.5px dashed #d5d9e0;
  color: #5b6373;
  font-weight: 600;
  font-size: 14px;
  background: transparent;
}

.ghost-btn:active {
  background: #fff;
}

.note-text {
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.7;
  padding: 0 4px;
}

.note-text code {
  background: #eceef1;
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 11.5px;
}

/* ---------- tabbar ---------- */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  display: flex;
  z-index: 40;
}

.tabbar .tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: #9aa1ad;
  font-size: 10.5px;
  font-weight: 600;
  transition: color 0.15s;
}

.tabbar .tab .ico {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
}

.tabbar .tab .ico svg {
  width: 21px;
  height: 21px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tabbar .tab.on {
  color: var(--primary);
}

/* ---------- 弹层 ---------- */
.mask {
  position: fixed;
  inset: 0;
  background: rgba(15, 18, 25, 0.42);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 50;
}

.mask.show {
  opacity: 1;
  pointer-events: auto;
}

.sheet {
  position: fixed;
  left: 50%;
  transform: translate(-50%, 105%);
  bottom: 0;
  width: 100%;
  max-width: 680px;
  background: #fff;
  border-radius: 20px 20px 0 0;
  padding: 8px 18px calc(20px + env(safe-area-inset-bottom, 0px));
  z-index: 60;
  transition: transform 0.26s cubic-bezier(0.22, 0.61, 0.36, 1);
  max-height: 88vh;
  display: flex;
  flex-direction: column;
}

.sheet.show {
  transform: translate(-50%, 0);
}

.sheet-handle {
  width: 38px;
  height: 4px;
  border-radius: 4px;
  background: #dfe2e7;
  margin: 4px auto 10px;
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.sheet-title {
  font-size: 16.5px;
  font-weight: 700;
}

.sheet-close {
  font-size: 20px;
  color: #a0a7b3;
  padding: 0 4px;
  line-height: 1;
}

.sheet-body {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.sheet-body .type-grid {
  flex-wrap: wrap;
  overflow: visible;
}

.field {
  margin-bottom: 14px;
}

.field > label {
  display: block;
  font-size: 12.5px;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 6px;
}

.field input[type="text"],
.field input[type="tel"],
.field input[type="number"],
.field textarea {
  width: 100%;
  padding: 11px 13px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: #f7f8fa;
  outline: none;
  font-size: 14.5px;
}

.field input:focus,
.field textarea:focus {
  background: #fff;
  border-color: #cfd4dc;
}

.money-field {
  position: relative;
}

.money-field .prefix {
  position: absolute;
  left: 13px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-weight: 600;
}

.money-field input {
  padding-left: 30px !important;
  font-size: 18px !important;
  font-weight: 700;
}

.sheet-actions {
  display: flex;
  gap: 10px;
  margin-top: 6px;
}

.btn {
  flex: 1;
  padding: 13px;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 700;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-ghost {
  background: #f2f4f7;
  color: #4b5563;
}

.btn-danger {
  background: #fdeceb;
  color: var(--primary);
  flex: 0 0 auto;
  padding: 13px 20px;
}

.pick-list {
  max-height: 52vh;
  overflow-y: auto;
  margin: 0 -6px;
}

.pick-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 13px 12px;
  border-radius: 11px;
  font-size: 15px;
}

.pick-item:active {
  background: #f5f6f8;
}

.pick-item.on {
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 600;
}

.pick-item .sub {
  font-size: 12px;
  color: var(--muted);
  font-weight: 400;
}

.pick-item.on .sub {
  color: var(--primary);
  opacity: 0.75;
}

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + 26px);
  transform: translate(-50%, 16px);
  background: rgba(22, 24, 29, 0.92);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: all 0.22s;
  z-index: 90;
  white-space: nowrap;
  max-width: 88vw;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast.err {
  background: rgba(190, 30, 30, 0.95);
}

@media (min-width: 700px) {
  .app {
    padding-top: 10px;
  }
  .sheet {
    border-radius: 20px;
    bottom: 24px;
    max-width: 560px;
  }
}

/* ---------- 补充：色彩选择 / 开关 / 明细 ---------- */
.color-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 2px 0;
}

.color-opt {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid transparent;
  position: relative;
}

.color-opt.on {
  border-color: #16181d;
  transform: scale(1.06);
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 13px;
  border-radius: 11px;
  background: #f7f8fa;
  border: 1px solid var(--line);
  margin-bottom: 14px;
}

.switch-row .txt {
  font-size: 14px;
  font-weight: 600;
}

.switch-row .sub {
  font-size: 12px;
  color: var(--muted);
  font-weight: 400;
  margin-top: 1px;
}

.switch {
  width: 46px;
  height: 27px;
  border-radius: 999px;
  background: #d7dbe2;
  position: relative;
  transition: background 0.18s;
  flex: 0 0 46px;
}

.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 21px;
  height: 21px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  transition: transform 0.18s;
}

.switch.on {
  background: var(--primary);
}

.switch.on::after {
  transform: translateX(19px);
}

.badge {
  font-size: 10.5px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 5px;
  background: #f1f3f5;
  color: var(--muted);
}

.badge.warn {
  background: #fff4e5;
  color: #b06a00;
}

.detail-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 4px 2px 12px;
  border-bottom: 1px dashed var(--line);
  margin-bottom: 12px;
}

.detail-head .big {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.detail-head .sub {
  font-size: 12px;
  color: var(--muted);
  text-align: right;
  line-height: 1.6;
}

.spacer {
  flex: 1;
}

.row-title {
  flex: 1;
  min-width: 0;
}

.row-title .t1 {
  font-size: 14.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row-title .t2 {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.loading {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  padding: 24px 0;
}

.text-strong {
  font-weight: 700;
}

.mt8 {
  margin-top: 8px;
}

.mt14 {
  margin-top: 14px;
}
