:root {
  --blue: #1f5fa8; --blue-d: #174a84; --blue-l: #e8f0fa;
  --bg: #f4f6f9; --card: #fff; --text: #1d2430; --muted: #6b7686; --line: #dde3ea;
  --red: #c62828; --green: #2e7d32;
  --radius: 12px;
  font-family: "Noto Sans JP", "Hiragino Sans", "Yu Gothic UI", Meiryo, system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-size: 16px; -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; }
input, textarea, select { font: inherit; }
.boot { padding: 40px; text-align: center; color: var(--muted); }
.muted { color: var(--muted); } .small { font-size: 13px; } .center { text-align: center; }
.hint { color: var(--muted); font-size: 13px; margin: 6px 4px; }

/* ---- 共通部品 ---- */
.btn { border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 10px 16px; min-height: 44px; cursor: pointer; font-size: 15px; }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; font-weight: 600; }
.btn.danger { color: var(--red); border-color: #f0c6c6; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--blue); padding: 10px 8px; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 14px; }
.btn.big { width: 100%; min-height: 54px; font-size: 17px; border-radius: 14px; }
.btn.pulse { box-shadow: 0 0 0 3px rgba(31,95,168,.3); }
.btn:disabled, .icon-btn:disabled { opacity: .35; }
.icon-btn { border: none; background: transparent; min-width: 40px; min-height: 40px; border-radius: 10px; cursor: pointer; font-size: 20px; }
.icon-btn.big { font-size: 24px; }
.icon-btn:active { background: rgba(0,0,0,.06); }
.input { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; min-height: 44px; background: #fff; font-size: 16px; }
.input:focus { outline: 2px solid rgba(31,95,168,.35); border-color: var(--blue); }
textarea.input { resize: vertical; line-height: 1.5; }
.seg { display: flex; background: #e7ebf0; border-radius: 10px; padding: 3px; gap: 3px; }
.seg-btn { flex: 1; border: none; background: transparent; border-radius: 8px; padding: 8px 6px; min-height: 38px; cursor: pointer; font-size: 14px; white-space: nowrap; }
.seg-btn.on { background: #fff; color: var(--blue); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.type-badge { display: inline-block; background: var(--blue-l); color: var(--blue); border-radius: 6px; padding: 2px 8px; font-size: 13px; white-space: nowrap; }
.type-badge.small { font-size: 11px; margin-left: 8px; vertical-align: 2px; }
.plain-list { padding-left: 1.2em; margin: 8px 0; line-height: 1.7; }
.plain-list.num { list-style: decimal; }
.price { font-weight: 700; color: var(--blue); font-size: 18px; text-align: center; }

/* ---- モーダル ---- */
.modal-wrap { position: fixed; inset: 0; background: rgba(15,23,35,.45); display: flex; align-items: flex-end; justify-content: center; z-index: 100; padding: 12px; }
@media (min-width: 600px) { .modal-wrap { align-items: center; } }
.modal { background: #fff; border-radius: 16px; width: 100%; max-width: 440px; max-height: 88vh; overflow: auto; padding: 18px; box-shadow: 0 10px 40px rgba(0,0,0,.25); animation: up .18s ease-out; }
.modal.wide { max-width: 560px; }
@keyframes up { from { transform: translateY(20px); opacity: 0; } }
.modal h3 { margin: 0 0 12px; font-size: 18px; }
.modal p { line-height: 1.6; margin: 6px 0; }
.modal-buttons { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
.modal-buttons .btn { flex: 1; min-width: 90px; }
.sheet-list { display: flex; flex-direction: column; gap: 6px; }
.sheet-item { text-align: left; border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 14px; font-size: 16px; cursor: pointer; }
.sheet-item.danger { color: var(--red); }
.toast { position: fixed; left: 50%; bottom: 90px; transform: translate(-50%, 20px); background: rgba(25,32,45,.92); color: #fff; padding: 10px 18px; border-radius: 22px; font-size: 14px; opacity: 0; transition: .25s; z-index: 200; max-width: 90vw; text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.busy { position: fixed; inset: 0; background: rgba(255,255,255,.8); z-index: 300; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; color: var(--text); }
.spinner { width: 40px; height: 40px; border: 4px solid var(--blue-l); border-top-color: var(--blue); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- 画面の枠組み ---- */
.page { max-width: 760px; margin: 0 auto; padding-bottom: 100px; min-height: 100vh; }
.app-head { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 8px; background: #fff; border-bottom: 1px solid var(--line); padding: 6px 8px; padding-top: max(6px, env(safe-area-inset-top)); min-height: 56px; }
.head-title { flex: 1; font-weight: 700; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-head.home { justify-content: space-between; padding: 10px 12px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand img { width: 40px; height: 40px; border-radius: 10px; }
.brand-name { font-weight: 800; font-size: 17px; }
.brand-sub { font-size: 12px; color: var(--muted); }
.bottom-action { position: fixed; left: 0; right: 0; bottom: 0; padding: 12px 16px; padding-bottom: max(12px, env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--bg) 30%); z-index: 5; }
.bottom-action .btn { max-width: 728px; margin: 0 auto; display: block; box-shadow: 0 4px 14px rgba(31,95,168,.3); }

.welcome { margin: 24px 16px; background: #fff; border-radius: var(--radius); padding: 22px; border: 1px solid var(--line); }
.welcome h2 { margin: 0 0 14px; font-size: 20px; color: var(--blue-d); }
.steps { padding-left: 1.3em; line-height: 1.8; }
.tlist { display: grid; grid-template-columns: 1fr; gap: 12px; padding: 14px; }
@media (min-width: 600px) { .tlist { grid-template-columns: 1fr 1fr; } }
.tcard { display: flex; gap: 12px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; cursor: pointer; }
.tcard-thumb { width: 84px; height: 112px; object-fit: contain; background: #f0f2f5; border: 1px solid var(--line); border-radius: 6px; flex: none; }
.tcard-body { display: flex; flex-direction: column; gap: 6px; min-width: 0; flex: 1; }
.tcard-body .btn { align-self: flex-start; margin-top: auto; }
.tcard-name { font-weight: 700; font-size: 17px; word-break: break-all; }

.notice { margin: 14px; padding: 14px; background: #fff8e1; border: 1px solid #f3dc9a; border-radius: var(--radius); }
.notice p { margin: 0 0 10px; }
.toolbar-row { display: flex; gap: 8px; padding: 12px 14px 4px; }
.toolbar-row .search { flex: 1; }
.rlist { padding: 8px 14px; display: flex; flex-direction: column; gap: 8px; }
.ritem { display: flex; align-items: center; gap: 4px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 6px 10px 14px; cursor: pointer; }
.ritem-main { flex: 1; min-width: 0; }
.ritem-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.empty { text-align: center; color: var(--muted); padding: 30px 16px; line-height: 1.7; }

/* ---- 設定 ---- */
.set-group { margin: 16px 14px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.set-title { font-weight: 700; padding: 12px 14px 6px; color: var(--blue-d); }
.set-note { padding: 4px 14px 12px; font-size: 14px; color: var(--muted); line-height: 1.6; }
.set-note.ok { color: var(--green); font-weight: 600; }
.set-item { width: 100%; display: flex; justify-content: space-between; align-items: center; text-align: left; background: #fff; border: none; border-top: 1px solid var(--line); padding: 14px; cursor: pointer; font-size: 16px; }
.chev { color: var(--muted); font-size: 22px; }
.help h4 { margin: 14px 0 4px; color: var(--blue-d); }
.help p { margin: 4px 0; line-height: 1.7; }

/* ---- 取り込み（全画面） ---- */
.fullscreen { position: fixed; inset: 0; background: #111; z-index: 90; display: flex; flex-direction: column; color: #fff; }
.fs-head { display: flex; align-items: center; justify-content: space-between; padding: 8px; padding-top: max(8px, env(safe-area-inset-top)); background: #000; }
.fs-head .btn.ghost { color: #9cc3ff; }
.fs-title { font-weight: 700; }
.fs-hint { margin: 6px 12px; font-size: 13px; color: #bbb; text-align: center; }
.fs-foot { display: flex; gap: 10px; justify-content: center; padding: 10px; padding-bottom: max(10px, env(safe-area-inset-bottom)); background: #000; }
.fs-foot .btn { background: #2a2f38; color: #fff; border-color: #444; }
.crop-stage { position: relative; flex: 1; margin: 8px; touch-action: none; }
.crop-img { position: absolute; }
.crop-svg { position: absolute; inset: 0; pointer-events: none; }
.crop-poly { fill: rgba(31,95,168,.18); stroke: #4da3ff; stroke-width: 2; }
.crop-handle { position: absolute; width: 44px; height: 44px; margin: -22px 0 0 -22px; border-radius: 50%; background: rgba(77,163,255,.35); border: 3px solid #4da3ff; touch-action: none; }
.magnifier { position: absolute; display: none; width: 120px; height: 120px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 4px 16px rgba(0,0,0,.5); pointer-events: none; }
.adjust-stage { flex: 1; display: flex; align-items: center; justify-content: center; padding: 10px; min-height: 0; }
.adjust-preview { max-width: 100%; max-height: 100%; background: #fff; box-shadow: 0 4px 20px rgba(0,0,0,.6); }
.adjust-controls { background: #fff; color: var(--text); padding: 12px; display: flex; flex-direction: column; gap: 10px; padding-bottom: max(12px, env(safe-area-inset-bottom)); }
.slider { display: flex; align-items: center; gap: 12px; font-size: 14px; }
.slider span { width: 90px; flex: none; }
.slider input { flex: 1; }

/* ---- 枠エディタ ---- */
.editor { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
.editor-toolbar { display: flex; align-items: center; gap: 2px; background: #fff; border-bottom: 1px solid var(--line); padding: 2px 6px; }
.editor-toolbar .spacer { flex: 1; }
.zoom-label { font-size: 12px; color: var(--muted); width: 42px; text-align: center; }
.page-tabs { display: flex; gap: 4px; overflow-x: auto; }
.page-tab { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 4px 10px; font-size: 13px; white-space: nowrap; cursor: pointer; }
.page-tab.on { background: var(--blue); color: #fff; border-color: var(--blue); }
.stage-scroll { flex: 1; overflow: auto; background: #c9d0d9; touch-action: none; padding: 12px; }
.stage { position: relative; margin: 0 auto; background: #fff; box-shadow: 0 2px 12px rgba(0,0,0,.2); user-select: none; -webkit-user-select: none; }
.stage-bg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.box-layer { position: absolute; inset: 0; }
.fbox { position: absolute; border: 1.5px solid rgba(31,95,168,.85); background: rgba(31,95,168,.10); border-radius: 2px; cursor: move; touch-action: none; }
.fbox.t-photo { border-color: rgba(46,125,50,.9); background: rgba(46,125,50,.10); }
.fbox.t-check { border-color: rgba(123,31,162,.9); background: rgba(123,31,162,.10); }
.fbox.t-choice { border-color: rgba(239,108,0,.9); background: rgba(239,108,0,.10); border-radius: 50%; }
.fbox.t-date { border-color: rgba(0,131,143,.9); background: rgba(0,131,143,.10); }
.fbox.group { box-shadow: 0 0 0 2px rgba(229,57,53,.35); }
.fbox.sel { border: 2px solid #e53935; background: rgba(229,57,53,.12); z-index: 2; }
.fbox-label { position: absolute; left: 0; top: -15px; font-size: 10px; line-height: 14px; background: rgba(31,95,168,.85); color: #fff; padding: 0 4px; border-radius: 3px; white-space: nowrap; max-width: 160px; overflow: hidden; text-overflow: ellipsis; pointer-events: none; }
.fbox.sel .fbox-label { background: #e53935; }
.hd { position: absolute; width: 22px; height: 22px; background: #fff; border: 2px solid #e53935; border-radius: 50%; touch-action: none; }
.hd::after { content: ''; position: absolute; inset: -10px; }
.hd-nw { left: -12px; top: -12px; cursor: nwse-resize; } .hd-ne { right: -12px; top: -12px; cursor: nesw-resize; }
.hd-sw { left: -12px; bottom: -12px; cursor: nesw-resize; } .hd-se { right: -12px; bottom: -12px; cursor: nwse-resize; }
.draw-preview { position: absolute; display: none; border: 2px dashed #e53935; background: rgba(229,57,53,.1); pointer-events: none; }
.editor-panel { background: #fff; border-top: 1px solid var(--line); padding: 10px 12px; padding-bottom: max(10px, env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 8px; }
.type-chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 20px; padding: 6px 12px; white-space: nowrap; cursor: pointer; font-size: 14px; display: flex; align-items: center; gap: 4px; }
.chip.on { background: var(--blue); color: #fff; border-color: var(--blue); }
.chip-icon { font-size: 13px; }
.sel-row { display: flex; align-items: center; gap: 8px; }
.choice-row { display: flex; align-items: center; gap: 10px; }
.btn-row { display: flex; gap: 6px; flex-wrap: wrap; }
.settings { display: flex; flex-direction: column; gap: 10px; }
.form-row { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--muted); }
.check-row { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.check-row input { width: 20px; height: 20px; }
.option-list { display: flex; flex-direction: column; gap: 6px; }
.option-item { display: flex; gap: 6px; align-items: center; }

/* ---- 記入画面 ---- */
.fill { max-width: 760px; margin: 0 auto; padding-bottom: 100px; min-height: 100vh; }
.fill-tabs { padding: 10px 14px 0; position: sticky; top: 56px; z-index: 9; background: var(--bg); padding-bottom: 6px; }
.fill-form { padding: 6px 14px; display: flex; flex-direction: column; gap: 10px; }
.form-item { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; transition: box-shadow .3s; }
.form-item.flash { box-shadow: 0 0 0 3px rgba(229,57,53,.5); }
.form-label { font-weight: 600; margin-bottom: 8px; font-size: 15px; }
.ctl-inline { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ctl-inline .input { flex: 1; min-width: 150px; }
.unit { color: var(--muted); }
.page-sep { font-size: 13px; color: var(--muted); margin-top: 8px; font-weight: 700; }
.switch { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.switch input { display: none; }
.switch-track { width: 52px; height: 30px; background: #cfd6de; border-radius: 15px; position: relative; transition: .2s; flex: none; }
.switch-track::after { content: ''; position: absolute; left: 3px; top: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.switch input:checked + .switch-track { background: var(--blue); }
.switch input:checked + .switch-track::after { left: 25px; }
.choice-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.choice-btn { border: 1.5px solid var(--line); background: #fff; border-radius: 22px; padding: 8px 18px; min-height: 42px; cursor: pointer; font-size: 15px; }
.choice-btn.on { border-color: #ef6c00; background: #fff3e0; color: #e65100; font-weight: 700; }
.photo-ctl { display: flex; gap: 12px; align-items: flex-start; }
.photo-thumb, .photo-empty { width: 120px; height: 90px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); background: #f0f2f5; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 13px; flex: none; }
.btn-col { display: flex; flex-direction: column; gap: 6px; }
.fill-preview { padding: 6px 14px; display: flex; flex-direction: column; gap: 12px; align-items: center; }
.preview-page { width: 100%; height: auto; background: #fff; box-shadow: 0 2px 10px rgba(0,0,0,.15); cursor: pointer; }
.fill-foot { position: fixed; left: 0; right: 0; bottom: 0; padding: 10px 16px; padding-bottom: max(10px, env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--bg) 30%); z-index: 5; }
.fill-foot .btn { max-width: 728px; margin: 0 auto; display: block; box-shadow: 0 4px 14px rgba(31,95,168,.3); }
.type-badge.alt { background: #fff3e0; color: #e65100; }
