:root {
  --bg: #f3f9f4;
  --card: #ffffff;
  --g1: #e3f2e7;
  --g2: #c6e6cf;
  --g3: #8fcca2;
  --g4: #4f9f6c;
  --g5: #2f6b45;
  --text: #253a2d;
  --muted: #6f8577;
  --line: #dcebe0;
  --warn: #d99a1e;
  --danger: #d4544f;
  --radius: 14px;
  --tabh: 64px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", "Yu Gothic", sans-serif;
  font-size: 15px; line-height: 1.5;
  padding-bottom: calc(var(--tabh) + env(safe-area-inset-bottom) + 12px);
}
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: var(--g1); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--g5); }
.brand img { width: 28px; height: 28px; border-radius: 7px; }
.icon-btn { border: 0; background: transparent; font-size: 20px; color: var(--g5); padding: 4px 8px; border-radius: 8px; }

main { max-width: 640px; margin: 0 auto; padding: 12px 14px; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabh) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: #fff; border-top: 1px solid var(--line);
}
.tabbar button {
  border: 0; background: transparent; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 10.5px;
}
.tabbar .ti { font-size: 20px; line-height: 1; }
.tabbar button.active { color: var(--g5); font-weight: 700; }
.tabbar button[data-tab="input"] .ti {
  background: var(--g4); color: #fff; width: 34px; height: 34px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; font-size: 22px;
}

.card { background: var(--card); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; border: 1px solid var(--line); }
.card h3 { margin: 0 0 10px; font-size: 15px; color: var(--g5); display: flex; justify-content: space-between; align-items: center; }
.card h3 small { font-weight: 400; color: var(--muted); font-size: 12px; }
.muted { color: var(--muted); font-size: 13px; }
.row { display: flex; align-items: center; gap: 8px; }
.between { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.grow { flex: 1; min-width: 0; }

/* 切り替え */
.seg { display: flex; background: var(--g1); border-radius: 10px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 7px 4px; border-radius: 8px; color: var(--muted); font-size: 13.5px; white-space: nowrap; }
.seg button.on { background: #fff; color: var(--g5); font-weight: 700; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.seg button:disabled { opacity: .4; }
.controls { display: grid; gap: 8px; margin-bottom: 12px; }
.period { display: flex; align-items: center; justify-content: space-between; }
.period button { border: 0; background: var(--g1); color: var(--g5); width: 36px; height: 32px; border-radius: 8px; font-size: 18px; }
.period .label { font-weight: 700; }

/* 合計 */
.totals { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.totals div { background: var(--g1); border-radius: 10px; padding: 8px; text-align: center; }
.totals small { display: block; color: var(--muted); font-size: 12px; }
.totals b { font-size: 16px; }
.neg { color: var(--danger); }

/* アラート */
.alert { border-radius: 10px; padding: 8px 10px; margin-bottom: 6px; font-size: 13.5px; display: flex; justify-content: space-between; gap: 8px; }
.alert.warn { background: #fff6e2; color: #8a5d00; }
.alert.over { background: #fde7e6; color: #a32622; font-weight: 700; }

/* バー */
.bar { height: 8px; border-radius: 6px; background: var(--g1); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--g4); border-radius: 6px; }
.bar.warn > i { background: var(--warn); }
.bar.over > i { background: var(--danger); }
.brk { margin-bottom: 10px; }
.brk .between { font-size: 14px; margin-bottom: 4px; }
.brk .pct { color: var(--muted); font-size: 12px; margin-left: 4px; }
.total-line { border-top: 1px dashed var(--line); padding-top: 8px; font-weight: 700; }

/* 円グラフ */
.pie-wrap { display: flex; gap: 14px; align-items: center; }
.pie-wrap svg { width: 140px; height: 140px; flex-shrink: 0; }
.legend { flex: 1; min-width: 0; font-size: 13px; }
.legend div { display: flex; align-items: center; gap: 6px; padding: 2px 0; }
.legend i { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.legend span:first-of-type { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chart6 svg { width: 100%; height: auto; display: block; }
.chart-legend { display: flex; gap: 14px; justify-content: center; font-size: 12px; color: var(--muted); margin-top: 4px; }
.chart-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }

/* フォーム */
label.f { display: block; margin-bottom: 12px; }
label.f > span { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=number], input[type=date], input[type=tel], select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; font-size: 16px;
}
textarea { min-height: 64px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--g3); border-color: transparent; }
.amount-input { font-size: 26px !important; font-weight: 700; text-align: right; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 6px 11px; font-size: 13px; }
.chips button.on { background: var(--g4); border-color: var(--g4); color: #fff; }

.btn { border: 0; border-radius: 12px; padding: 12px 16px; font-weight: 700; background: var(--g4); color: #fff; width: 100%; font-size: 15px; }
.btn.sub { background: var(--g1); color: var(--g5); }
.btn.line { background: #fff; color: var(--g5); border: 1px solid var(--g3); }
.btn.danger { background: #fff; color: var(--danger); border: 1px solid #f0c4c2; }
.btn.small { width: auto; padding: 7px 12px; font-size: 13px; border-radius: 9px; }
.btn:disabled { opacity: .5; }
.btns { display: grid; gap: 8px; }
.hint { background: var(--g1); border-radius: 10px; padding: 8px 10px; font-size: 13px; color: var(--g5); margin-bottom: 12px; }

.photo-box { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.photo-box img { width: 72px; height: 72px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); }

/* 一覧 */
.day-head { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); padding: 10px 2px 4px; }
.rec { display: flex; align-items: center; gap: 10px; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin-bottom: 6px; }
.rec .cat { width: 36px; height: 36px; border-radius: 10px; background: var(--g1); color: var(--g5); display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; flex-shrink: 0; }
.rec .main { flex: 1; min-width: 0; }
.rec .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rec .s { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rec .amt { font-weight: 700; white-space: nowrap; }
.rec .amt.inc { color: var(--g4); }
.tag { display: inline-block; font-size: 10.5px; padding: 0 6px; border-radius: 6px; background: var(--g1); color: var(--g5); margin-right: 4px; }
.tag.sh { background: var(--g4); color: #fff; }
.empty { text-align: center; color: var(--muted); padding: 24px 0; font-size: 14px; }

/* カレンダー */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.cal .wd { text-align: center; font-size: 11px; color: var(--muted); padding: 2px 0; }
.cal .d { min-height: 54px; border-radius: 8px; background: #fff; border: 1px solid var(--line); padding: 3px; font-size: 11px; display: flex; flex-direction: column; }
.cal .d.out { visibility: hidden; }
.cal .d.today { border-color: var(--g4); }
.cal .d.sel { background: var(--g1); border-color: var(--g4); }
.cal .d .n { font-weight: 700; color: var(--muted); }
.cal .d .e { margin-top: auto; text-align: right; font-weight: 700; font-size: 10.5px; color: var(--text); }
.cal .d .i { text-align: right; font-size: 10px; color: var(--g4); }
.cal .wd:first-child, .cal .sun .n { color: var(--danger); }

/* 予算・固定費 */
.bud { padding: 10px 0; border-bottom: 1px solid var(--line); }
.bud:last-child { border-bottom: 0; }
.fx { padding: 10px 0; border-bottom: 1px solid var(--line); }
.fx:last-child { border-bottom: 0; }
.done { color: var(--g4); font-size: 13px; font-weight: 700; }

/* 共用 */
.code { font-size: 28px; letter-spacing: 4px; font-weight: 800; text-align: center; color: var(--g5); background: var(--g1); border-radius: 12px; padding: 10px; }
.qr { display: flex; justify-content: center; padding: 10px 0; }
.qr img, .qr canvas, .qr svg { width: 180px; height: 180px; }
video.scan { width: 100%; border-radius: 12px; background: #000; }

/* モーダル */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(20, 40, 28, .35); display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--bg); width: 100%; max-width: 640px; max-height: 92vh; overflow: auto; border-radius: 18px 18px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); }
.sheet h2 { margin: 0 0 12px; font-size: 17px; color: var(--g5); display: flex; justify-content: space-between; align-items: center; }
.sheet h2 button { border: 0; background: var(--g1); width: 32px; height: 32px; border-radius: 50%; color: var(--g5); font-size: 16px; }

.draft-row { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 8px; margin-bottom: 8px; display: grid; grid-template-columns: 1fr 110px 32px; gap: 6px; align-items: center; }
.draft-row select { grid-column: 1 / 3; font-size: 14px; padding: 7px 10px; }
.draft-row input { font-size: 15px; padding: 8px 10px; }
.draft-row .x { border: 0; background: #fde7e6; color: var(--danger); border-radius: 8px; height: 32px; }
.ocr-text { white-space: pre-wrap; font-size: 11px; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 8px; max-height: 140px; overflow: auto; color: var(--muted); }
.progress { height: 10px; background: var(--g1); border-radius: 6px; overflow: hidden; margin: 12px 0; }
.progress i { display: block; height: 100%; background: var(--g4); width: 0; transition: width .2s; }

.toast { position: fixed; left: 50%; bottom: calc(var(--tabh) + 20px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--g5); color: #fff; padding: 10px 16px; border-radius: 12px; z-index: 60; font-size: 14px; max-width: 90vw; }
.toast.err { background: var(--danger); }

.welcome { max-width: 420px; margin: 40px auto; text-align: center; }
.welcome img { width: 96px; border-radius: 22px; }
.welcome h1 { color: var(--g5); font-size: 22px; }
.welcome .card { text-align: left; }
