/* バックオフィス：iOS の作法（docs/design-ref.md） */
:root {
  --paper: #F2F2F7; --cell: #FFFFFF; --ink: #1C1C1E; --sub: #6E6E73; --line: #D1D1D6;
  --ai: #2B4C7E; --ai-soft: #E6ECF5; --shu: #C8372D; --ok: #2E7D5B; --warn: #C46A00; --red: #D92D20;
  --bar: rgba(249, 249, 251, 0.86); --dim: rgba(0, 0, 0, 0.42);
  --radius: 12px; --tab-h: 56px;
  --font: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "BIZ UDPGothic", "Yu Gothic UI", "Meiryo", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #000000; --cell: #1C1C1E; --ink: #F2F2F7; --sub: #98989F; --line: #38383A;
    --ai: #8FB0E3; --ai-soft: #1E2A3D; --shu: #E5645A; --ok: #4CC38A; --warn: #FF9F0A; --red: #FF453A;
    --bar: rgba(22, 22, 24, 0.86); --dim: rgba(0, 0, 0, 0.6); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #000000; --cell: #1C1C1E; --ink: #F2F2F7; --sub: #98989F; --line: #38383A;
  --ai: #8FB0E3; --ai-soft: #1E2A3D; --shu: #E5645A; --ok: #4CC38A; --warn: #FF9F0A; --red: #FF453A;
  --bar: rgba(22, 22, 24, 0.86); --dim: rgba(0, 0, 0, 0.6); color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--paper); color: var(--ink); font-family: var(--font); font-size: 17px; line-height: 1.45; -webkit-text-size-adjust: 100%; }
body { min-height: 100dvh; overscroll-behavior-y: none; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--ai); outline-offset: 2px; border-radius: 6px; }
.num, .yen { font-variant-numeric: tabular-nums; }

/* 画面の枠 */
#app { max-width: 640px; margin: 0 auto; min-height: 100dvh; position: relative; }
.screen { padding: 0 16px calc(var(--tab-h) + 32px + env(safe-area-inset-bottom)); animation: push .28s cubic-bezier(.2,.8,.2,1); }
.screen.root { animation: none; }
@keyframes push { from { transform: translateX(24%); opacity: .4; } to { transform: none; opacity: 1; } }

/* 上の帯：大きい見出し → 小さい見出し */
.navbar { position: sticky; top: 0; z-index: 20; margin: 0 -16px; padding: calc(env(safe-area-inset-top) + 6px) 16px 6px; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; min-height: 44px; background: transparent; transition: background .2s; }
.navbar.scrolled { background: var(--bar); backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px); box-shadow: 0 .5px 0 var(--line); }
.navbar .small-title { font-weight: 600; font-size: 17px; opacity: 0; transition: opacity .15s; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.navbar.scrolled .small-title { opacity: 1; }
.navbar .left { justify-self: start; } .navbar .right { justify-self: end; }
.back { background: none; border: 0; color: var(--ai); font-size: 17px; padding: 8px 4px; margin-left: -6px; cursor: pointer; display: flex; align-items: center; gap: 2px; }
.back::before { content: ""; width: 10px; height: 10px; border-left: 2.5px solid currentColor; border-bottom: 2.5px solid currentColor; transform: rotate(45deg); margin-right: 4px; }
.navbtn { background: none; border: 0; color: var(--ai); font-size: 17px; padding: 8px 4px; cursor: pointer; font-weight: 500; }
h1.large { font-size: 32px; line-height: 1.15; font-weight: 700; margin: 4px 0 12px; letter-spacing: .01em; }
.lead { color: var(--sub); font-size: 15px; margin: -6px 0 16px; }

/* 行のかたまり（inset grouped） */
.group { margin: 0 0 28px; }
.group > .gh { font-size: 13px; color: var(--sub); margin: 0 16px 6px; }
.group > .gf, .gf { font-size: 13px; color: var(--sub); margin: 6px 16px 0; }
.screen > .gf { margin: 0 16px 28px; }
.list { background: var(--cell); border-radius: var(--radius); overflow: hidden; }
.row { position: relative; display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 10px 16px; background: var(--cell); width: 100%; border: 0; text-align: left; cursor: default; touch-action: pan-y; }
.row + .row::before, .swipe + .swipe::before, .row + .swipe::before, .swipe + .row::before, .row + .field::before, .field + .row::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; height: .5px; background: var(--line); z-index: 2; }
button.row, a.row { cursor: pointer; color: inherit; text-decoration: none; }
button.row:active, a.row:active { background: var(--line); }
.row .main { flex: 1; min-width: 0; }
.row .title { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .sub { display: block; color: var(--sub); font-size: 13px; margin-top: 1px; }
.row .val { color: var(--sub); text-align: right; white-space: nowrap; }
.row .val.strong { color: var(--ink); font-weight: 600; }
.row.chev::after { content: ""; width: 8px; height: 8px; border-right: 2px solid #C4C4C7; border-top: 2px solid #C4C4C7; transform: rotate(45deg); margin-left: 4px; flex: none; }
.icon { width: 30px; height: 30px; border-radius: 7px; display: grid; place-items: center; color: #fff; flex: none; font-size: 16px; }
.icon svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.badge { min-width: 22px; height: 22px; padding: 0 7px; border-radius: 11px; background: var(--red); color: #fff; font-size: 13px; font-weight: 600; display: inline-grid; place-items: center; }
.pill { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--paper); color: var(--sub); white-space: nowrap; }
.pill.ok { background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok); }
.pill.warn { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); }
.pill.red { background: color-mix(in srgb, var(--red) 14%, transparent); color: var(--red); }
.pill.ai { background: var(--ai-soft); color: var(--ai); }

/* 左にスワイプ */
.swipe { position: relative; overflow: hidden; background: var(--cell); }
.swipe .row { transition: transform .25s cubic-bezier(.2,.8,.2,1); z-index: 1; }
.swipe.dragging .row { transition: none; }
.swipe .actions { position: absolute; inset: 0 0 0 auto; display: flex; }
.swipe .actions button { border: 0; color: #fff; font-size: 15px; font-weight: 600; min-width: 84px; padding: 0 12px; cursor: pointer; }
.act-ok { background: var(--ok); } .act-warn { background: var(--warn); } .act-red { background: var(--red); } .act-ai { background: var(--ai); }

/* 判子（承認・確定の瞬間だけ） */
.stamp { position: absolute; right: 18px; top: 50%; width: 58px; height: 58px; margin-top: -29px; border: 3px solid var(--shu); border-radius: 50%; color: var(--shu); display: grid; place-items: center; font-weight: 800; font-size: 15px; letter-spacing: .05em; transform: rotate(-14deg); z-index: 5; pointer-events: none; background: color-mix(in srgb, var(--cell) 70%, transparent); animation: stamp .36s cubic-bezier(.3,1.6,.5,1) both; }
.stamp.big { position: relative; right: auto; top: auto; margin: 8px auto 0; width: 96px; height: 96px; font-size: 22px; border-width: 4px; }
@keyframes stamp { 0% { transform: scale(2.2) rotate(-14deg); opacity: 0; } 60% { opacity: 1; } 100% { transform: scale(1) rotate(-14deg); opacity: .92; } }

/* 入力 */
.field { display: flex; align-items: center; gap: 12px; padding: 0 16px; min-height: 48px; background: var(--cell); position: relative; }
.field + .field::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; height: .5px; background: var(--line); }
.field label { flex: 0 0 auto; width: 34%; min-width: 92px; font-size: 16px; }
.field input, .field select, .field textarea { flex: 1; min-width: 0; border: 0; background: transparent; padding: 12px 0; font-size: 17px; text-align: right; outline: none; }
.field textarea { text-align: left; min-height: 80px; resize: vertical; }
.field.stack { flex-direction: column; align-items: stretch; gap: 2px; padding-top: 10px; }
.field.stack label { width: auto; font-size: 13px; color: var(--sub); }
.field.stack input, .field.stack textarea { text-align: left; padding: 4px 0 10px; }
.field .unit { color: var(--sub); }
.field input::placeholder { color: #A1A1A6; }
.field.toggle label { flex: 1; width: auto; }
.field.toggle input { flex: none; }
input[type="checkbox"].switch { appearance: none; width: 51px; height: 31px; border-radius: 16px; background: var(--line); position: relative; cursor: pointer; transition: background .2s; flex: none; }
input[type="checkbox"].switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff; box-shadow: 0 2px 4px rgba(0,0,0,.2); transition: transform .2s; }
input[type="checkbox"].switch:checked { background: var(--ok); }
input[type="checkbox"].switch:checked::after { transform: translateX(20px); }

.btn { display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; min-height: 50px; border: 0; border-radius: var(--radius); background: var(--ai); color: #fff; font-size: 17px; font-weight: 600; cursor: pointer; padding: 0 16px; }
:root[data-theme="dark"] .btn, .btn { color: #fff; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn:not(.plain):not(.tinted) { color: #0B1220; } }
.btn.tinted { background: var(--ai-soft); color: var(--ai); }
.btn.plain { background: var(--cell); color: var(--ai); }
.btn.danger { background: var(--cell); color: var(--red); }
.btn:disabled { opacity: .45; cursor: default; }
.btn + .btn { margin-top: 10px; }
.btns { margin: 0 0 28px; }
.seg { display: flex; background: color-mix(in srgb, var(--line) 60%, transparent); border-radius: 9px; padding: 2px; margin: 0 0 16px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 7px 4px; border-radius: 7px; font-size: 14px; font-weight: 500; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--cell); box-shadow: 0 1px 3px rgba(0,0,0,.12); font-weight: 600; }

/* お金の大きな数字 */
.hero { text-align: center; padding: 18px 16px 22px; background: var(--cell); border-radius: var(--radius); margin-bottom: 28px; }
.hero .k { color: var(--sub); font-size: 13px; }
.hero .v { font-size: 38px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.01em; line-height: 1.2; margin-top: 2px; }
.hero .v small { font-size: 18px; font-weight: 600; margin-left: 2px; }
.hero .sub { color: var(--sub); font-size: 13px; margin-top: 4px; }

/* 打刻 */
.clock { text-align: center; padding: 20px 0 8px; }
.clock .time { font-size: 64px; font-weight: 300; font-variant-numeric: tabular-nums; letter-spacing: .02em; line-height: 1; }
.clock .date { color: var(--sub); margin-top: 6px; }
.punch-state { text-align: center; margin: 10px 0 22px; }
.punch-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 28px; }
.punch-grid .btn { min-height: 84px; font-size: 20px; flex-direction: column; gap: 2px; }
.punch-grid .btn small { font-size: 12px; font-weight: 500; opacity: .85; }
.punch-grid .btn.wide { grid-column: 1 / -1; }

/* 下のタブ */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: var(--bar); backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px); box-shadow: 0 -.5px 0 var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabbar nav { max-width: 640px; margin: 0 auto; display: flex; height: var(--tab-h); }
.tabbar button { flex: 1; border: 0; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 10px; color: #8E8E93; cursor: pointer; position: relative; }
.tabbar button svg { width: 26px; height: 26px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar button[aria-current="page"] { color: var(--ai); }
.tabbar .badge { position: absolute; top: 4px; left: 52%; transform: scale(.82); }

/* シート（下から出る紙） */
.dim { position: fixed; inset: 0; background: var(--dim); z-index: 50; animation: fade .2s; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 51; max-width: 640px; margin: 0 auto; max-height: 92dvh; background: var(--paper); border-radius: 14px 14px 0 0; display: flex; flex-direction: column; animation: up .3s cubic-bezier(.2,.8,.2,1); }
.sheet .bar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 10px 16px; border-bottom: .5px solid var(--line); }
.sheet .bar .t { font-weight: 600; text-align: center; }
.sheet .bar .l { justify-self: start; } .sheet .bar .r { justify-self: end; }
.sheet .body { overflow: auto; padding: 16px 16px calc(24px + env(safe-area-inset-bottom)); -webkit-overflow-scrolling: touch; }
@keyframes up { from { transform: translateY(100%); } to { transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.toast { position: fixed; left: 50%; bottom: calc(var(--tab-h) + 20px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: color-mix(in srgb, var(--ink) 92%, transparent); color: var(--paper); padding: 10px 16px; border-radius: 20px; font-size: 15px; z-index: 80; max-width: calc(100% - 32px); animation: fade .2s; }
.empty { text-align: center; color: var(--sub); padding: 40px 16px; }
.empty b { display: block; color: var(--ink); font-size: 17px; margin-bottom: 4px; }
.note { font-size: 13px; color: var(--sub); background: var(--cell); border-radius: var(--radius); padding: 12px 16px; margin: 0 0 28px; }
.note.warn { color: var(--warn); }
.photo { width: 100%; max-height: 260px; object-fit: contain; background: var(--cell); border-radius: var(--radius); margin-bottom: 16px; }
.qrbox { background: #fff; padding: 16px; border-radius: var(--radius); display: grid; place-items: center; margin-bottom: 12px; }
.qrbox canvas { width: 220px; height: 220px; image-rendering: pixelated; }
.lines .row { align-items: flex-start; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 13px; white-space: pre-wrap; word-break: break-all; }

/* 画面ツアー */
.tour-hole { position: fixed; z-index: 90; border-radius: 12px; box-shadow: 0 0 0 9999px rgba(0,0,0,.55); transition: all .3s cubic-bezier(.2,.8,.2,1); pointer-events: none; }
.tour-hole::after { content: ""; position: absolute; inset: -4px; border: 2.5px solid #fff; border-radius: 14px; animation: ring 1.4s ease-out infinite; }
@keyframes ring { from { opacity: 1; transform: scale(1); } to { opacity: 0; transform: scale(1.06); } }
.tour-block { position: fixed; inset: 0; z-index: 89; }
.tour-bubble { position: fixed; z-index: 91; left: 16px; right: 16px; max-width: 420px; margin: 0 auto; background: var(--cell); color: var(--ink); border-radius: 14px; padding: 14px 16px 12px; box-shadow: 0 10px 30px rgba(0,0,0,.25); }
.tour-bubble .step { font-size: 12px; color: var(--sub); }
.tour-bubble p { margin: 4px 0 12px; font-size: 16px; }
.tour-bubble .tb { display: flex; gap: 8px; }
.tour-bubble .tb button { border: 0; border-radius: 9px; padding: 9px 12px; font-size: 15px; font-weight: 600; cursor: pointer; background: var(--paper); color: var(--ink); }
.tour-bubble .tb .next { margin-left: auto; background: var(--ai); color: #fff; }
.tour-bubble .tb .stop { color: var(--sub); background: none; padding-left: 0; }

/* 請求書・明細の印刷（A4） */
.paper { margin-bottom: 24px; overflow: hidden; border-radius: 8px; }
.paper .doc { width: 680px; transform-origin: 0 0; }
.doc { background: #fff; color: #111; padding: 28px; border-radius: 8px; font-size: 13px; line-height: 1.6; }
.doc h2 { font-size: 22px; letter-spacing: .3em; text-align: center; margin: 0 0 18px; font-weight: 700; }
.doc .head { display: flex; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.doc .to { font-size: 16px; border-bottom: 1px solid #111; padding-bottom: 2px; }
.doc .from { text-align: right; font-size: 12px; }
.doc .total { font-size: 20px; font-weight: 700; border-bottom: 2px solid #111; display: inline-block; padding: 0 8px 2px; margin: 6px 0 14px; }
.doc table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.doc th, .doc td { border: 1px solid #999; padding: 5px 7px; }
.doc th { background: #F2F2F2; font-weight: 600; }
.doc td.n { text-align: right; white-space: nowrap; }
.doc .sum { margin-left: auto; width: 60%; margin-top: 10px; }
.doc .foot { margin-top: 16px; font-size: 12px; }
@media print {
  @page { size: A4; margin: 14mm; }
  body { background: #fff; }
  body > *:not(#print) { display: none !important; }
  #print { display: block !important; }
  #print .doc { padding: 0; border-radius: 0; font-size: 11pt; width: auto !important; transform: none !important; }
}
#print { display: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
@media (min-width: 700px) {
  .screen { padding-top: 12px; }
}
