:root {
  --bg: #f4f6f5;
  --card: #ffffff;
  --text: #1d2422;
  --muted: #5f6b67;
  --line: #d9e0dd;
  --main: #1f6f5c;
  --main-text: #ffffff;
  --main-soft: #e3f1ec;
  --check: #fff4c2;
  --check-line: #e0b400;
  --danger: #b3261e;
  --danger-text: #ffffff;
  --warn-bg: #fde8e6;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121615;
    --card: #1c2220;
    --text: #e8eeec;
    --muted: #9aa7a2;
    --line: #34403c;
    --main: #3fa58a;
    --main-text: #0d1513;
    --main-soft: #1d3a32;
    --check: #4a3f0e;
    --check-line: #c9a227;
    --danger: #ff8a80;
    --danger-text: #2b0d0b;
    --warn-bg: #4a1f1c;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", Meiryo, sans-serif;
  font-size: 16px; line-height: 1.5;
  padding-bottom: calc(84px + env(safe-area-inset-bottom));
}
button, select, input { font: inherit; color: inherit; }
h1 { font-size: 19px; margin: 0; }
h2 { font-size: 17px; margin: 0; }
h3 { font-size: 18px; margin: 0; }
h4 { font-size: 15px; margin: 22px 0 6px; }

.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--main); color: var(--main-text);
}
.icon-btn { background: transparent; border: 1px solid currentColor; border-radius: 999px; padding: 4px 12px; font-size: 14px; color: inherit; }
.dlg .icon-btn { color: var(--muted); }

main { max-width: 640px; margin: 0 auto; padding: 14px 16px; }
section { margin-bottom: 18px; }
.note { color: var(--muted); font-size: 14px; margin: 8px 0; }
.note.small { font-size: 12px; margin-top: 20px; }

.big-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 112px; border-radius: var(--radius); background: var(--main); color: var(--main-text);
  cursor: pointer; text-align: center; padding: 14px; box-shadow: 0 2px 8px rgba(0,0,0,.12);
}
.big-btn:active { transform: scale(.99); }
.big-btn-title { font-size: 21px; font-weight: 700; }
.big-btn-sub { font-size: 14px; opacity: .9; }
.sub-btn {
  display: block; margin-top: 10px; text-align: center; padding: 12px; border-radius: var(--radius);
  border: 2px solid var(--main); color: var(--main); font-weight: 600; cursor: pointer; background: var(--card);
}

.keep-note { background: var(--check); border: 1px solid var(--check-line); border-radius: var(--radius); padding: 10px 14px; font-size: 14px; margin-bottom: 14px; }
.keep-note .link-btn { display: block; padding-bottom: 0; }
.howto { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; font-size: 14px; }
.howto summary { font-weight: 700; cursor: pointer; color: var(--main); }
.howto ol { padding-left: 1.3em; margin: 8px 0; }
.howto li { margin-bottom: 6px; }
.howto p { margin: 8px 0; }

.progress { background: var(--card); border-radius: var(--radius); padding: 14px; border: 1px solid var(--line); }
.progress-text { font-weight: 600; }
.progress-sub { color: var(--muted); font-size: 13px; margin-top: 6px; }
.bar { height: 10px; background: var(--line); border-radius: 99px; overflow: hidden; margin-top: 8px; }
.bar > div { height: 100%; width: 0; background: var(--main); transition: width .25s; }

.sec-head { display: flex; align-items: center; justify-content: space-between; gap: 8px 10px; margin-bottom: 6px; flex-wrap: wrap; }
.head-btns { display: flex; gap: 8px; align-items: center; margin-left: auto; }
.danger-ghost { border-color: var(--danger); color: var(--danger); }
.picking-here .danger-ghost { background: var(--danger); color: var(--danger-text); }
.only-picking { display: none; }
.picking-here .only-picking { display: block; }
.picking-here .only-normal, .picking-here #btn-ok-all { display: none; }
.stop-btn { margin-top: 10px; width: 100%; min-height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--danger); cursor: pointer; }
.badge { display: inline-block; background: var(--check-line); color: #000; border-radius: 99px; font-size: 13px; padding: 0 8px; vertical-align: 2px; }
.ghost { background: var(--card); border: 1px solid var(--main); color: var(--main); border-radius: 999px; padding: 6px 12px; font-size: 14px; }
select#month-filter { padding: 6px 8px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); }

.card { background: var(--card); border-radius: var(--radius); border: 1px solid var(--line); padding: 12px; margin-bottom: 14px; box-shadow: 0 1px 4px rgba(0,0,0,.05); }
.card-top { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 8px; }
.thumb { width: 84px; height: 112px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); background: var(--line); flex: none; cursor: zoom-in; }
.thumb.no-photo { display: flex; align-items: center; justify-content: center; font-size: 12px; color: var(--muted); background: var(--bg); cursor: default; }
.card-sum { flex: 1; min-width: 0; }
.x-btn { flex: none; background: transparent; color: var(--danger); border: 1px solid var(--danger); border-radius: 999px; padding: 4px 12px; font-size: 14px; min-height: 34px; cursor: pointer; }

/* 選んで消す */
.pick-box { display: none; flex: none; width: 26px; height: 26px; border-radius: 7px; border: 2px solid var(--muted); background: var(--card); align-self: center; position: relative; }
.picking-here .pick-box { display: block; }
.picked .pick-box { background: var(--danger); border-color: var(--danger); }
.picked .pick-box::after { content: ""; position: absolute; left: 7px; top: 2px; width: 7px; height: 13px; border: solid var(--danger-text); border-width: 0 3px 3px 0; transform: rotate(45deg); }
.picking-here .card { cursor: pointer; padding-bottom: 4px; }
.picking-here .card .fields, .picking-here .card .card-actions, .picking-here .card .x-btn { display: none; }
.picking-here .card .thumb { width: 60px; height: 80px; }
.card.picked, .row.picked { border-color: var(--danger); box-shadow: 0 0 0 2px var(--danger) inset; }
.picking-here .row { grid-template-columns: 26px 36px 40px minmax(0, 1fr) auto; }
.pick-bar { max-width: 608px; margin: 0 auto; }
.pick-info { display: flex; justify-content: space-between; align-items: center; font-size: 14px; gap: 8px; }
.pick-btns { display: flex; gap: 10px; margin-top: 4px; }
.pick-btns > * { flex: 1; }
body.picking { padding-bottom: calc(130px + env(safe-area-inset-bottom)); }
.card-amount { font-size: 22px; font-weight: 700; }
.card-store { color: var(--muted); font-size: 14px; overflow-wrap: anywhere; }
.warn { background: var(--warn-bg); border-radius: 8px; padding: 6px 8px; font-size: 13px; margin-top: 6px; }
.info { background: var(--main-soft); border-radius: 8px; padding: 6px 8px; font-size: 13px; margin-top: 6px; }

.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; }
.field { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.field.full { grid-column: 1 / -1; }
.field > span { font-size: 13px; color: var(--muted); }
.field input, .field select {
  width: 100%; min-height: 44px; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); font-size: 16px;
}
.field.check input, .field.check select { background: var(--check); border-color: var(--check-line); }
.field.check > span::after { content: "  たしかめて"; color: var(--check-line); font-weight: 700; }
.tax-line { grid-column: 1 / -1; font-size: 13px; color: var(--muted); margin-top: -2px; }
.card-actions { display: flex; gap: 10px; margin-top: 12px; }
.card-actions .primary { flex: 2; }
.card-actions .danger { flex: 1; }

button.primary, .primary { background: var(--main); color: var(--main-text); border: 0; border-radius: 12px; padding: 12px 16px; font-weight: 700; min-height: 48px; cursor: pointer; }
button.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); border-radius: 12px; padding: 12px 16px; min-height: 48px; cursor: pointer; }
button.danger-solid { background: var(--danger); color: var(--danger-text); border: 0; border-radius: 12px; padding: 12px 16px; min-height: 48px; font-weight: 700; cursor: pointer; }
button.danger-solid:disabled { opacity: .4; cursor: default; }
button.plain { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 16px; min-height: 48px; cursor: pointer; }
.wide { display: block; width: 100%; text-align: center; margin-top: 10px; }
button.wide:not(.primary):not(.danger):not(.danger-solid), .file-btn { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 16px; min-height: 48px; cursor: pointer; }

.total { font-size: 15px; margin: 4px 0 8px; }
.total b { font-size: 20px; }
.month-head { font-size: 14px; color: var(--muted); margin: 14px 2px 6px; display: flex; justify-content: space-between; }
.row {
  display: grid; grid-template-columns: 36px 42px minmax(0, 1fr) auto; gap: 8px; align-items: center; width: 100%;
  text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin-bottom: 6px; cursor: pointer;
}
.row-thumb { width: 36px; height: 48px; object-fit: cover; border-radius: 5px; border: 1px solid var(--line); background: var(--line); display: block; }
.row-thumb.no-photo { background: var(--bg); }
.row-date { font-size: 14px; color: var(--muted); }
.row-main { min-width: 0; }
.row-store { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { display: block; font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-amount { font-weight: 700; text-align: right; }
.row-amount small { display: block; font-weight: 400; font-size: 12px; color: var(--muted); }
.link-btn { background: none; border: 0; padding: 8px 0; color: var(--main); font-weight: 700; text-decoration: underline; cursor: pointer; }
.empty { text-align: center; color: var(--muted); padding: 24px 8px; background: var(--card); border-radius: var(--radius); border: 1px dashed var(--line); }

.bottom {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 92%, transparent); border-top: 1px solid var(--line);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.bottom .wide { max-width: 608px; margin: 0 auto; }

dialog { border: 0; border-radius: 18px; padding: 0; width: min(560px, calc(100vw - 20px)); max-height: calc(100dvh - 30px); overflow: auto; overscroll-behavior: contain; background: var(--card); color: var(--text); }
#dlg-ask { width: min(420px, calc(100vw - 32px)); }
.ask-text { margin: 0; color: var(--muted); }
.ask-btns { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.ask-btns .wide { margin-top: 0; }
.sticky-actions { position: sticky; bottom: 0; background: var(--card); padding: 10px 0 2px; margin-top: 0; box-shadow: 0 -10px 10px -10px rgba(0,0,0,.2); }
.photo-links { display: flex; justify-content: space-between; gap: 10px; margin: 2px 0 6px; }
.link-btn.danger-link { color: var(--danger); }
dialog::backdrop { background: rgba(0,0,0,.45); }
.dlg { padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.dlg-head { display: flex; justify-content: space-between; align-items: center; }
.dlg-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 6px; }
.dlg-actions > * { flex: 1; }
.photo-dlg img { width: 100%; height: auto; max-height: 75dvh; object-fit: contain; border-radius: 8px; background: #000; }
.check-row { display: flex; gap: 8px; align-items: center; font-size: 15px; }
.check-row input { width: 22px; height: 22px; }
.ok-text { font-weight: 700; color: var(--main); margin: 6px 0 0; }
.edit-photo { width: 100%; max-height: 260px; object-fit: contain; background: #000; border-radius: 10px; cursor: zoom-in; }

.toast {
  position: fixed; left: 50%; bottom: calc(88px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 20;
  background: #222; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: calc(100vw - 32px); box-shadow: 0 4px 14px rgba(0,0,0,.25);
  display: flex; align-items: center; gap: 14px; width: max-content;
}
.toast-act { background: transparent; border: 0; color: #8fe3c9; font-weight: 700; font-size: 15px; padding: 6px 2px; cursor: pointer; white-space: nowrap; }
