:root {
  --bg: #f6f7f9; --card: #ffffff; --text: #111827; --muted: #6b7280;
  --line: #e5e7eb; --brand: #0f766e; --in: #15803d; --out: #b91c1c;
  --in-bg: #ecfdf3; --out-bg: #fef2f2; --net-bg: #f0f9ff;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115; --card: #1a1d23; --text: #f3f4f6; --muted: #9ca3af;
    --line: #2a2e36; --brand: #2dd4bf; --in: #4ade80; --out: #f87171;
    --in-bg: #12261a; --out-bg: #2a1515; --net-bg: #12222c;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font-family: "Noto Sans Thai", "Sarabun", system-ui, -apple-system, sans-serif; font-size: 16px; }
button { font: inherit; color: inherit; cursor: pointer; }

.top { position: sticky; top: 0; z-index: 5; background: var(--bg);
  padding: calc(env(safe-area-inset-top) + 10px) 14px 8px; border-bottom: 1px solid var(--line); }
.daynav { display: flex; align-items: center; gap: 8px; position: relative; }
.daynav button { background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  height: 44px; min-width: 44px; font-size: 22px; }
.daynav .daylabel { flex: 1; font-size: 17px; font-weight: 600; }
.hidden-date { position: absolute; inset: 0; opacity: 0; pointer-events: none; }
.tabs { display: flex; gap: 6px; margin-top: 8px; }
.tabs button { flex: 1; height: 38px; border: 0; border-radius: 10px; background: transparent;
  color: var(--muted); font-weight: 600; }
.tabs button.on { background: var(--card); color: var(--brand); border: 1px solid var(--line); }

main { padding: 12px 14px 110px; max-width: 640px; margin: 0 auto; }
.summary { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.card { border-radius: 16px; padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; }
.card span { font-size: 13px; color: var(--muted); }
.card b { font-size: 22px; font-variant-numeric: tabular-nums; }
.card.in { background: var(--in-bg); } .card.in b { color: var(--in); }
.card.out { background: var(--out-bg); } .card.out b { color: var(--out); }
.card.net { background: var(--net-bg); grid-column: 1 / -1; flex-direction: row;
  justify-content: space-between; align-items: baseline; }

.list { list-style: none; margin: 14px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.row { background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 10px 12px; display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; }
.row .thumb { width: 48px; height: 48px; border-radius: 10px; object-fit: cover; flex: none;
  background: var(--line); border: 0; padding: 0; }
.row .ph { width: 48px; height: 48px; border-radius: 10px; flex: none; display: grid;
  place-items: center; background: var(--line); color: var(--muted); font-size: 12px; }
.row .mid { flex: 1; min-width: 0; }
.row .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .sub { font-size: 13px; color: var(--muted); }
.row .amt { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.row .amt.in { color: var(--in); } .row .amt.out { color: var(--out); }
.dayrow .sub { display: flex; gap: 10px; flex-wrap: wrap; }
.empty { text-align: center; color: var(--muted); margin-top: 40px; line-height: 1.7; }
.tools { margin-top: 18px; display: flex; justify-content: center; }

.fab { position: fixed; right: 18px; bottom: calc(env(safe-area-inset-bottom) + 20px);
  width: 62px; height: 62px; border-radius: 50%; border: 0; background: var(--brand);
  color: #fff; font-size: 34px; line-height: 1; box-shadow: 0 6px 18px rgba(0,0,0,.25); z-index: 6; }

.sheet { position: fixed; inset: 0; z-index: 10; display: flex; align-items: flex-end; }
.sheet-bg { position: absolute; inset: 0; background: rgba(0,0,0,.45); }
.sheet-body { position: relative; width: 100%; max-height: 92vh; overflow: auto; background: var(--card);
  border-radius: 22px 22px 0 0; padding: 18px 16px calc(env(safe-area-inset-bottom) + 18px);
  display: flex; flex-direction: column; gap: 12px; }
.sheet-body h2 { margin: 0; font-size: 18px; }
.sheet-body label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
.sheet-body input:not([type=file]), .sheet-body select { height: 48px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); padding: 0 12px; font: inherit; font-size: 16px; }
#amount { font-size: 24px; font-weight: 700; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; background: var(--bg);
  border-radius: 12px; padding: 4px; }
.seg button { height: 42px; border: 0; border-radius: 9px; background: transparent; font-weight: 700; color: var(--muted); }
.seg button.on#typeOut { background: var(--out); color: #fff; }
.seg button.on#typeIn { background: var(--in); color: #fff; }
.slip-row { display: flex; gap: 12px; align-items: center; }
.slip-pick { flex: 1; height: 48px; border: 1.5px dashed var(--line); border-radius: 12px;
  display: grid !important; place-items: center; color: var(--brand) !important; font-weight: 600; cursor: pointer; }
.slip-preview { position: relative; width: 72px; height: 72px; flex: none; }
.slip-preview img { width: 100%; height: 100%; object-fit: cover; border-radius: 12px; }
.slip-preview button { position: absolute; top: -8px; right: -8px; width: 26px; height: 26px; border-radius: 50%;
  border: 0; background: #111827; color: #fff; font-size: 16px; line-height: 1; }
.actions { display: flex; gap: 8px; margin-top: 4px; }
.actions button { height: 48px; border-radius: 12px; border: 0; font-weight: 700; padding: 0 18px; }
.actions .primary { flex: 1; background: var(--brand); color: #fff; }
.ghost { background: var(--bg); border: 1px solid var(--line) !important; border-radius: 12px; height: 44px; padding: 0 16px; }
.danger { background: var(--out-bg); color: var(--out); }
.error { color: var(--out); margin: 0; font-size: 14px; }

.lightbox { position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,.9); display: grid; place-items: center; }
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; }

.tools { flex-direction: column; gap: 10px; align-items: stretch; }
.ai { margin: 0; font-size: 14px; color: var(--brand); background: var(--net-bg); border-radius: 10px; padding: 8px 10px; line-height: 1.5; }
.ai.warn { color: var(--muted); }
.hint { margin: 0; font-size: 13px; color: var(--muted); }

.copybar { display: flex; gap: 10px; align-items: flex-end; margin: 12px 0 4px; }
.copybar .open { flex: 1; display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.copybar input { height: 44px; border: 1px solid var(--line); border-radius: 12px; padding: 0 12px; font-size: 16px; background: var(--bg); color: inherit; font-variant-numeric: tabular-nums; }
