/* ==========================================================================
 * 记账助手 · 样式
 * 手机优先，支持深色模式；无任何外部字体或 CSS 依赖。
 * ========================================================================== */

/* ------------------------------------------------------------ 设计变量 */
:root {
  --brand: #123b58;
  --brand-soft: #1d5c7d;
  --accent: #1c8f7a;
  --danger: #cf4a45;
  --warn: #b57d0a;

  --bg: #eef4f6;
  --card: #ffffff;
  --text: #14303f;
  --muted: #6a8493;
  --line: #dfeaee;
  --line-soft: #edf4f6;
  --hover: #f5fafb;
  --shadow: 0 1px 2px rgba(18, 59, 88, .06), 0 6px 20px rgba(18, 59, 88, .06);
  --shadow-lg: 0 10px 40px rgba(10, 35, 52, .18);

  --radius: 14px;
  --radius-sm: 9px;
  --maxw: 720px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --brand: #4f9fc4;
    --brand-soft: #6fb6d6;
    --accent: #3fbfa3;
    --danger: #e2706b;
    --warn: #d8a63e;

    --bg: #0d161c;
    --card: #15232b;
    --text: #e4eef3;
    --muted: #8ba4b1;
    --line: #24373f;
    --line-soft: #1c2c34;
    --hover: #1a2a32;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
    --shadow-lg: 0 10px 40px rgba(0, 0, 0, .5);
  }
}

/* ------------------------------------------------------------ 基础重置 */
* { box-sizing: border-box; }

/*
 * 关键规则，务必保留：
 * 浏览器对 [hidden] 的默认样式是 display:none，但作者样式表里的
 * `.modal{display:flex}` 这类声明会把它盖掉——结果是带 hidden 的弹窗
 * 依然铺满全屏，成为一个看不见的透明遮罩，把页面上所有点击全部吃掉。
 * 这里用 !important 确保 hidden 永远意味着「真的不显示」。
 */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", "Source Han Sans SC",
               Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
}

h1, h2, h3, p { margin: 0; }
h1 { font-size: 19px; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 17px; font-weight: 650; letter-spacing: -.01em; }
h2 span { color: var(--muted); font-weight: 500; font-size: 14px; }
h3 { font-size: 15px; font-weight: 650; }

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

/* ------------------------------------------------------------ 顶部栏 */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: color-mix(in srgb, var(--card) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}

/* 不支持 color-mix 的旧浏览器回退 */
@supports not (background: color-mix(in srgb, red 50%, blue)) {
  .topbar { background: var(--card); }
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }

.brand-icon {
  width: 36px; height: 36px;
  flex: 0 0 36px;
  display: grid; place-items: center;
  border-radius: 10px;
  background: var(--brand);
  color: #fff;
}
:root:not([data-theme]) .brand-icon { color: #fff; }

.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-text strong { font-size: 15px; font-weight: 650; letter-spacing: -.01em; }
.brand-text small { font-size: 11.5px; color: var(--muted); line-height: 1.2; }

.topbar-actions { display: flex; gap: 4px; flex: 0 0 auto; }

.icon-btn {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border: 0; border-radius: 10px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn:active { transform: scale(.94); }

/* ------------------------------------------------------------ 布局 */
.content {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 14px 14px 40px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

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

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

.eyebrow {
  font-size: 11px;
  font-weight: 650;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--brand-soft);
  margin-bottom: 2px;
}

.date-chip {
  flex: 0 0 auto;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  background: var(--line-soft);
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

.hint { font-size: 12.5px; color: var(--muted); margin-bottom: 10px; }

/* ------------------------------------------------------------ 输入区 */
textarea {
  width: 100%;
  min-height: 84px;
  resize: vertical;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  line-height: 1.55;
  transition: border-color .15s, box-shadow .15s;
}
textarea::placeholder { color: var(--muted); opacity: .8; }
textarea:focus {
  outline: none;
  border-color: var(--brand-soft);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-soft) 18%, transparent);
}

.compose-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

/* ------------------------------------------------------------ 按钮 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 550;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, border-color .15s, opacity .15s, transform .08s;
  -webkit-tap-highlight-color: transparent;
}
.btn:active:not(:disabled) { transform: scale(.975); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn:focus-visible { outline: 2px solid var(--brand-soft); outline-offset: 2px; }

.btn-primary { background: var(--brand); color: #fff; flex: 1; }
.btn-primary:hover:not(:disabled) { background: var(--brand-soft); }

.btn-outline {
  background: var(--card);
  border-color: var(--line);
  color: var(--text);
}
.btn-outline:hover:not(:disabled) { background: var(--hover); border-color: var(--brand-soft); }

.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover:not(:disabled) { background: var(--hover); color: var(--text); }

.btn-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: color-mix(in srgb, var(--danger) 10%, transparent); }

.btn-sm { min-height: 33px; padding: 0 12px; font-size: 13px; }

/* -------------------------------------------------------- 截图预览 */
.thumbs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed var(--line);
}

.thumb {
  position: relative;
  width: 62px; height: 62px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--line-soft);
  flex: 0 0 auto;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb button {
  position: absolute; top: 2px; right: 2px;
  width: 19px; height: 19px;
  display: grid; place-items: center;
  border: 0; border-radius: 50%;
  background: rgba(0, 0, 0, .62);
  color: #fff; font-size: 13px; line-height: 1;
  cursor: pointer; padding: 0;
}
.thumb .thumb-name {
  position: absolute; left: 0; right: 0; bottom: 0;
  font-size: 9px; text-align: center;
  background: rgba(0, 0, 0, .55); color: #fff;
  padding: 1px 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ------------------------------------------------------------ 进度 */
.progress {
  display: flex; align-items: center; gap: 9px;
  margin-top: 12px; padding: 10px 12px;
  background: var(--line-soft);
  border-radius: var(--radius-sm);
  font-size: 13px; color: var(--muted);
}

.spinner {
  width: 15px; height: 15px;
  flex: 0 0 15px;
  border: 2px solid var(--line);
  border-top-color: var(--brand-soft);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------- 待核对卡片 */
.review-list { display: flex; flex-direction: column; gap: 10px; }

.review-item {
  border: 1px solid var(--line);
  border-left: 3px solid var(--brand-soft);
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  background: var(--hover);
}
.review-item.income { border-left-color: var(--accent); }
.review-item.lowconf { border-left-color: var(--warn); }
.review-item.error {
  border-left-color: var(--danger);
  background: color-mix(in srgb, var(--danger) 6%, transparent);
  font-size: 13px;
}

.review-top {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; margin-bottom: 9px;
}
.review-src { font-size: 11.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge {
  flex: 0 0 auto;
  font-size: 11px; font-weight: 600;
  padding: 2px 8px; border-radius: 999px;
  background: var(--line-soft); color: var(--muted);
}
.badge.warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.badge.ok { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); }
.badge.danger { background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); }

.review-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.review-grid .full { grid-column: 1 / -1; }

.mini-field { display: flex; flex-direction: column; gap: 3px; }
.mini-field label { font-size: 11px; color: var(--muted); font-weight: 550; }
.mini-field input, .mini-field select {
  width: 100%;
  min-height: 34px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--card);
  font-size: 14px;
}
.mini-field input:focus, .mini-field select:focus {
  outline: none; border-color: var(--brand-soft);
}
.mini-field input.amount { font-weight: 650; font-variant-numeric: tabular-nums; }

.review-remove {
  margin-top: 9px;
  border: 0; background: transparent;
  color: var(--muted); font-size: 12px;
  cursor: pointer; padding: 3px 0;
}
.review-remove:hover { color: var(--danger); }

.review-actions {
  display: flex; gap: 8px; margin-top: 13px;
}

/* ------------------------------------------------------------ 过滤器 */
.filters { display: flex; gap: 8px; margin-bottom: 12px; }

.filters select, .filters input {
  min-height: 38px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--text);
  font-size: 14px;
}
.filters select { flex: 0 0 auto; max-width: 46%; }
.filters input { flex: 1; min-width: 0; }
.filters select:focus, .filters input:focus { outline: none; border-color: var(--brand-soft); }

/* ------------------------------------------------------------ 汇总 */
.summary {
  display: flex; flex-wrap: wrap; gap: 8px;
  margin-bottom: 12px;
}

.sum-item {
  flex: 1 1 auto;
  min-width: 108px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  background: var(--line-soft);
}
.sum-item .sum-label { font-size: 11.5px; color: var(--muted); }
.sum-item .sum-value {
  font-size: 17px; font-weight: 680;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.015em;
}
.sum-item.income .sum-value { color: var(--accent); }
.sum-item.expense .sum-value { color: var(--text); }
.sum-item.net .sum-value { color: var(--brand-soft); }

/* 分类占比条 */
.cat-bars { display: flex; flex-direction: column; gap: 7px; margin-bottom: 14px; }
.cat-bar { display: flex; align-items: center; gap: 9px; font-size: 12.5px; }
.cat-bar .cat-name { flex: 0 0 52px; color: var(--muted); }
.cat-bar .cat-track {
  flex: 1; height: 7px; border-radius: 999px;
  background: var(--line-soft); overflow: hidden;
}
.cat-bar .cat-fill {
  height: 100%; border-radius: 999px;
  background: var(--brand-soft);
  transition: width .3s ease;
}
.cat-bar .cat-amt {
  flex: 0 0 auto; min-width: 62px; text-align: right;
  font-variant-numeric: tabular-nums; color: var(--muted);
}

/* ------------------------------------------------------------ 列表 */
.entries { display: flex; flex-direction: column; }

.day-group { margin-bottom: 6px; }
.day-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 8px;
  padding: 9px 2px 5px;
  font-size: 12px; color: var(--muted);
  border-bottom: 1px solid var(--line-soft);
}
.day-head .day-total { font-variant-numeric: tabular-nums; }

.entry {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 2px;
  border-bottom: 1px solid var(--line-soft);
}
.entry:last-child { border-bottom: 0; }

.entry-cat {
  width: 34px; height: 34px;
  flex: 0 0 34px;
  display: grid; place-items: center;
  border-radius: 9px;
  background: var(--line-soft);
  font-size: 12px; font-weight: 600;
  color: var(--brand-soft);
}
.entry-cat.income { background: color-mix(in srgb, var(--accent) 15%, transparent); color: var(--accent); }

.entry-main { flex: 1; min-width: 0; }
.entry-title {
  font-size: 14px; font-weight: 550;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.entry-sub {
  font-size: 11.5px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.entry-amt {
  flex: 0 0 auto;
  font-size: 14.5px; font-weight: 620;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.01em;
}
.entry-amt.income { color: var(--accent); }

.entry-tools { flex: 0 0 auto; display: flex; gap: 1px; }
.entry-tools button {
  width: 30px; height: 30px;
  display: grid; place-items: center;
  border: 0; border-radius: 7px;
  background: transparent; color: var(--muted);
  cursor: pointer; padding: 0;
}
.entry-tools button:hover { background: var(--line-soft); color: var(--text); }
.entry-tools button.del:hover { color: var(--danger); }

.empty {
  text-align: center;
  color: var(--muted);
  font-size: 13.5px;
  padding: 26px 10px;
}

/* ------------------------------------------------------------ 页脚 */
.foot {
  text-align: center;
  font-size: 11.5px;
  color: var(--muted);
  line-height: 1.7;
  padding: 4px 0 8px;
}
.foot-note { display: block; opacity: .8; }

/* ------------------------------------------------------------ 横幅 */
.banner {
  padding: 10px 16px;
  font-size: 13px;
  line-height: 1.5;
  border-bottom: 1px solid var(--line);
}
.banner-warn { background: color-mix(in srgb, var(--warn) 15%, var(--card)); color: var(--warn); }
.banner-info { background: color-mix(in srgb, var(--brand-soft) 12%, var(--card)); color: var(--brand-soft); }
.banner b { font-weight: 650; }

/* ------------------------------------------------------------ 弹窗 */
.modal {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(8, 24, 34, .5);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  animation: fade .15s ease;
}
@keyframes fade { from { opacity: 0; } }

.modal-box {
  position: relative;
  width: 100%;
  max-width: 480px;
  max-height: calc(100vh - 32px);
  display: flex;
  flex-direction: column;
  background: var(--card);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  animation: pop .18s cubic-bezier(.2, .8, .3, 1);
  overflow: hidden;
}
.modal-sm { max-width: 380px; }
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.98); } }

.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 15px 16px 11px;
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.modal-body {
  padding: 15px 16px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  flex: 1 1 auto;
}
.modal-foot {
  display: flex; gap: 8px; justify-content: flex-end;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  flex: 0 0 auto;
}
.modal-foot .btn { flex: 0 0 auto; min-width: 84px; }

/* ------------------------------------------------------------ 表单 */
.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 12.5px; font-weight: 600;
  margin-bottom: 5px;
}
.field input, .field select {
  width: 100%;
  min-height: 40px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
}
.field input:focus, .field select:focus { outline: none; border-color: var(--brand-soft); }
.field-hint { font-size: 11.5px; color: var(--muted); margin-top: 5px; line-height: 1.5; }
.field-row { display: grid; grid-template-columns: 1.6fr 1fr; gap: 10px; }

.switch {
  display: flex; align-items: center; gap: 9px;
  margin-bottom: 6px;
  font-size: 14px; cursor: pointer;
}
.switch input { width: 17px; height: 17px; accent-color: var(--brand); cursor: pointer; margin: 0; }

.test-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 6px; }
.test-result { font-size: 12.5px; line-height: 1.4; }
.test-result.ok { color: var(--accent); }
.test-result.err { color: var(--danger); }

.divider { border: 0; border-top: 1px solid var(--line); margin: 18px 0 14px; }
.sub-title { margin-bottom: 7px; }

.data-actions { display: flex; gap: 7px; flex-wrap: wrap; margin-bottom: 8px; }

/* ------------------------------------------------------------ 提示条 */
.toasts {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 90;
  display: flex; flex-direction: column; gap: 7px;
  align-items: center;
  pointer-events: none;
  width: calc(100% - 32px);
  max-width: 440px;
}

.toast {
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: toastIn .2s cubic-bezier(.2, .8, .3, 1);
  max-width: 100%;
  text-align: center;
}
.toast.ok { background: var(--accent); color: #fff; }
.toast.err { background: var(--danger); color: #fff; }
@keyframes toastIn { from { opacity: 0; transform: translateY(12px); } }

/* ------------------------------------------------------------ 响应式 */
@media (max-width: 420px) {
  body { font-size: 14.5px; }
  .content { padding: 12px 11px 34px; }
  .card { padding: 13px; border-radius: 12px; }
  h1 { font-size: 17.5px; }
  .review-grid { grid-template-columns: 1fr; }
  .field-row { grid-template-columns: 1fr; }
  .compose-actions { flex-direction: column; }
  .compose-actions .btn { width: 100%; }
  .sum-item { min-width: calc(50% - 4px); flex: 1 1 calc(50% - 4px); }
  .filters select { max-width: 42%; }
}

/* 减少动画偏好 */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

/* 打印：只留明细，方便存档 */
@media print {
  .topbar, .compose, .review, .filters, .foot, .banner,
  .cat-bars, .entry-tools, .modal, .toasts { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; border: 0; }
}
