/* 报销台账 · 移动优先 · 大触控目标 */
:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --text: #1a1f1c;
  --muted: #6b756f;
  --border: #e2e8e4;
  --primary: #1a6b4a;
  --primary-dark: #145239;
  --primary-soft: #e8f5ef;
  --self: #1a6b4a;
  --self-bg: #e8f5ef;
  --other: #2b5a9e;
  --other-bg: #e8effa;
  --electronic: #0f6e56;
  --electronic-bg: #e6f4ef;
  --cash: #8a5a00;
  --cash-bg: #fff3d6;
  --warn: #b86a00;
  --warn-bg: #fff4e0;
  --danger: #c0392b;
  --danger-bg: #fdecea;
  --radius: 14px;
  --tap: 48px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Noto Sans SC", sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  min-height: 100dvh;
  overscroll-behavior: none;
}
button, input, select, textarea {
  font: inherit;
  color: inherit;
}
button { cursor: pointer; border: none; background: none; }
a { color: var(--primary); }

.hidden { display: none !important; }

#app {
  max-width: 720px;
  margin: 0 auto;
  min-height: 100dvh;
  padding-bottom: calc(120px + var(--safe-b));
  display: flex;
  flex-direction: column;
}

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(10px + var(--safe-t)) 16px 10px;
  background: rgba(244, 246, 245, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.logo {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.topbar-actions { display: flex; gap: 4px; }
.icon-btn {
  width: var(--tap);
  height: var(--tap);
  border-radius: 12px;
  font-size: 1.2rem;
  display: grid;
  place-items: center;
}
.icon-btn:active { background: var(--border); }

/* Search */
.search-bar {
  display: flex;
  gap: 8px;
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.search-bar input {
  flex: 1;
  height: var(--tap);
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
}
.btn-text {
  padding: 0 12px;
  color: var(--primary);
  font-weight: 600;
  white-space: nowrap;
}
.btn-text.danger { color: var(--danger); }

/* Summary */
.summary {
  display: grid;
  grid-template-columns: 1fr 1fr 0.7fr;
  gap: 8px;
  padding: 12px 16px 4px;
}
.summary-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 12px;
  border: 1px solid var(--border);
}
.summary-card .label {
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 4px;
}
.summary-card .amount {
  font-size: 1.05rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.summary-card.self .amount { color: var(--self); }
.summary-card.other .amount { color: var(--other); }
.summary-card.pending .amount { color: var(--warn); }

/* Filters */
.filters {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 10px 16px;
}
.filters #filter-month {
  grid-column: 1 / -1;
}
.filters select,
.filters input[type="month"] {
  height: 40px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  font-size: 0.9rem;
}

/* List */
.list-wrap { flex: 1; padding: 0 12px 12px; }
.expense-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.expense-item {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 14px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 12px;
  min-height: var(--tap);
  -webkit-tap-highlight-color: transparent;
}
.expense-item:active { background: #f0f3f1; }
.expense-item .row1 {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.expense-item .type {
  font-weight: 700;
  font-size: 1.05rem;
}
.badge {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
}
.badge-self { background: var(--self-bg); color: var(--self); }
.badge-other { background: var(--other-bg); color: var(--other); }
.badge-electronic { background: var(--electronic-bg); color: var(--electronic); }
.badge-cash { background: var(--cash-bg); color: var(--cash); }
.badge-method-unknown { background: #eee; color: var(--muted); }
.badge-invoice {
  background: var(--warn-bg);
  color: var(--warn);
}
.badge-invoice.ok { background: var(--primary-soft); color: var(--primary); }
.badge-invoice.none { background: #eee; color: var(--muted); }
.expense-item .amount {
  font-size: 1.15rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.expense-item .meta {
  grid-column: 1 / -1;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.82rem;
  color: var(--muted);
  gap: 8px;
}
.expense-item .meta .notes {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 60%;
}
.thumb {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid var(--border);
}

.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--muted);
}
.empty-state .hint { font-size: 0.9rem; }

/* Bottom nav */
.bottom-nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  max-width: 720px;
  margin: 0 auto;
  padding: 10px 16px calc(12px + var(--safe-b));
  background: linear-gradient(to top, var(--bg) 70%, transparent);
  pointer-events: none;
}
.bottom-nav > * { pointer-events: auto; }
.fab {
  width: 100%;
  height: 56px;
  border-radius: 16px;
  background: var(--primary);
  color: #fff;
  font-size: 1.15rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 8px 24px rgba(26, 107, 74, 0.35);
}
.fab:active { background: var(--primary-dark); }
.fab-plus { font-size: 1.5rem; line-height: 1; }
.nav-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
}
.nav-btn {
  height: 40px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-weight: 600;
  color: var(--primary);
}

/* Sheets */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.4);
}
.sheet-panel {
  position: relative;
  width: 100%;
  max-width: 720px;
  max-height: min(92dvh, 900px);
  overflow: auto;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 8px 16px calc(20px + var(--safe-b));
  animation: slideUp 0.22s ease-out;
}
.sheet-sm { max-height: 60dvh; }
.sheet-handle {
  width: 40px;
  height: 4px;
  border-radius: 2px;
  background: #ccc;
  margin: 4px auto 8px;
}
.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.sheet-header h2 {
  margin: 0;
  font-size: 1.15rem;
}
@keyframes slideUp {
  from { transform: translateY(40px); opacity: 0.6; }
  to { transform: none; opacity: 1; }
}

/* Form */
.form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span, .field legend {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}
.field em { color: var(--danger); font-style: normal; }
.field input[type="date"],
.field input[type="number"],
.field input[type="text"],
.field input[type="url"],
.field input[type="password"],
.field select,
.field textarea {
  height: var(--tap);
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
}
.field textarea {
  height: auto;
  padding: 12px 14px;
  resize: vertical;
}
.field fieldset {
  border: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.seg-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.seg {
  position: relative;
  height: var(--tap);
  border-radius: 12px;
  border: 2px solid var(--border);
  display: grid;
  place-items: center;
  font-weight: 700;
  cursor: pointer;
  transition: 0.15s;
}
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg-self:has(input:checked) {
  border-color: var(--self);
  background: var(--self-bg);
  color: var(--self);
}
.seg-other:has(input:checked) {
  border-color: var(--other);
  background: var(--other-bg);
  color: var(--other);
}
.seg-electronic:has(input:checked) {
  border-color: var(--electronic);
  background: var(--electronic-bg);
  color: var(--electronic);
}
.seg-cash:has(input:checked) {
  border-color: var(--cash);
  background: var(--cash-bg);
  color: var(--cash);
}

.chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.chip {
  position: relative;
  height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  border: 2px solid var(--border);
  display: inline-flex;
  align-items: center;
  font-weight: 600;
  cursor: pointer;
}
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip:has(input:checked) {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
}
.chip.wrap { margin-bottom: 4px; }

.attach-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.btn-attach {
  display: inline-flex;
  align-items: center;
  height: var(--tap);
  padding: 0 16px;
  border-radius: 12px;
  background: var(--bg);
  border: 1px dashed var(--border);
  font-weight: 600;
  cursor: pointer;
}
.btn-attach-primary {
  border-style: solid;
  background: var(--card, #fff);
  border-color: var(--accent, #2563eb);
  color: var(--accent, #2563eb);
}
.btn-attach-camera {
  opacity: 0.92;
  font-weight: 500;
}
.attach-preview {
  margin-top: 8px;
}
.attach-preview img {
  max-width: 100%;
  max-height: 200px;
  border-radius: 12px;
  border: 1px solid var(--border);
  object-fit: contain;
  background: #000;
}

.form-actions {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 10px;
  margin-top: 8px;
}
.btn-primary, .btn-secondary, .btn-danger, .btn-block {
  height: var(--tap);
  border-radius: 12px;
  font-weight: 700;
  font-size: 1rem;
}
.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:active { background: var(--primary-dark); }
.btn-secondary {
  background: var(--bg);
  border: 1px solid var(--border);
}
.btn-danger {
  background: var(--danger-bg);
  color: var(--danger);
}
.btn-block {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-file { cursor: pointer; }

/* Detail */
.detail { padding: 8px 0 16px; }
.detail-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.95rem;
}
.detail-row .k { color: var(--muted); flex-shrink: 0; }
.detail-row .v { font-weight: 600; text-align: right; word-break: break-all; }
.detail-img {
  margin-top: 12px;
  max-width: 100%;
  border-radius: 12px;
  border: 1px solid var(--border);
}
.invoice-quick {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.invoice-quick .hint {
  margin: 0 0 8px;
  font-size: 0.85rem;
  color: var(--muted);
}

/* Settings */
.settings { padding-bottom: 8px; }
.settings-block {
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.settings-block h3 {
  margin: 0 0 8px;
  font-size: 1rem;
}
.hint {
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0 0 12px;
  line-height: 1.5;
}
.sync-status {
  font-size: 0.85rem;
  color: var(--muted);
  min-height: 1.2em;
  margin-top: 8px;
}
.sync-status.ok { color: var(--primary); }
.sync-status.err { color: var(--danger); }

.export-options { padding: 8px 0 16px; }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(140px + var(--safe-b));
  transform: translateX(-50%);
  z-index: 200;
  background: rgba(26, 31, 28, 0.92);
  color: #fff;
  padding: 12px 20px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
  max-width: 90vw;
  text-align: center;
  pointer-events: none;
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to { opacity: 1; transform: translateX(-50%); }
}

/* Desktop tweaks */
@media (min-width: 720px) {
  .sheet { align-items: center; }
  .sheet-panel {
    border-radius: 20px;
    max-height: 85vh;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
  }
  .bottom-nav { padding-bottom: 16px; }
}

/* Print (when viewing ledger in-app — mainly for export HTML) */
@media print {
  .topbar, .filters, .search-bar, .bottom-nav, .summary { display: none !important; }
}


/* Access unlock gate · 属马图案 */
#unlock-gate {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  background: linear-gradient(160deg, #0f3d2c 0%, #1a6b4a 45%, #0d2a1f 100%);
}
#unlock-gate.hidden { display: none !important; }
.unlock-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border-radius: 18px;
  padding: 26px 20px 20px;
  box-shadow: 0 18px 50px rgba(0,0,0,0.28);
  text-align: center;
}
.unlock-card h1 {
  margin: 0 0 6px;
  font-size: 1.35rem;
  color: var(--text);
}
.unlock-card .unlock-sub {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 0.9rem;
}
.pattern-progress {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-bottom: 16px;
}
.pattern-progress .dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--border);
  transition: 0.15s;
}
.pattern-progress .dot.filled {
  background: var(--primary);
  transform: scale(1.15);
}
.pattern-progress .dot.shake {
  animation: unlock-shake 0.4s ease;
  background: var(--danger);
}
@keyframes unlock-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}
.pattern-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 0 auto 12px;
  max-width: 280px;
}
.pattern-cell {
  aspect-ratio: 1;
  border-radius: 16px;
  border: 2px solid var(--border);
  background: #f7faf8;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: 0.12s;
  -webkit-tap-highlight-color: transparent;
  padding: 0;
}
.pattern-cell:active { transform: scale(0.96); }
.pattern-cell.picked {
  border-color: var(--primary);
  background: var(--primary-soft);
  box-shadow: 0 0 0 2px rgba(26, 107, 74, 0.2);
}
.pattern-cell.wrong {
  border-color: var(--danger);
  background: var(--danger-bg);
}
.pattern-emoji {
  font-size: 2rem;
  line-height: 1;
  user-select: none;
}
.unlock-error {
  min-height: 1.2em;
  margin: 0 0 10px;
  color: var(--danger);
  font-size: 0.88rem;
}
.unlock-reset {
  width: 100%;
  height: 44px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #fff;
  font-weight: 600;
  margin-bottom: 8px;
}
.unlock-hint {
  margin: 8px 0 0;
  font-size: 0.72rem;
  color: var(--muted);
  line-height: 1.4;
  text-align: left;
}
#app.locked { visibility: hidden; pointer-events: none; }
