:root {
  --navy: #13224a;
  --navy-2: #1f3576;
  --navy-soft: #e8ecf6;
  --green: #2bd47f;
  --green-2: #1fb86b;
  --green-ink: #0b6b40;
  --green-soft: #e3f8ec;
  --bg: #f3f5f9;
  --card: #ffffff;
  --ink: #17203a;
  --muted: #5b6480;
  --line: #dde2ec;
  --danger: #c8372f;
  --danger-soft: #fdecea;
  --warn-ink: #7a4f00;
  --warn-soft: #fff4d6;
  --radius: 14px;
  --tap: 48px;
  --tabbar-h: 62px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  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.55;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea { font-size: 16px; } /* iOS の自動拡大を防ぐ */
a { color: var(--navy-2); }
h1, h2, h3 { line-height: 1.3; margin: 0; }
h1 { font-size: 1.3rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ── 上部 ── */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 10px;
  background: var(--navy); color: #fff;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; letter-spacing: .06em; font-size: 1rem; color: #fff; text-decoration: none; }
.brand .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--green); }
.brand small { font-weight: 600; font-size: .7rem; color: var(--green); border: 1px solid var(--green); border-radius: 6px; padding: 0 5px; letter-spacing: 0; }
.save-ind { font-size: .78rem; display: flex; align-items: center; gap: 6px; color: #c9d3ee; white-space: nowrap; }
.save-ind.saving { color: #fff; }
.save-ind.saved::before { content: "✓"; color: var(--green); font-weight: 700; }
.save-ind.error { color: #ffb4ae; font-weight: 700; }

.banner { padding: 10px 16px; font-size: .9rem; display: flex; gap: 10px; align-items: center; justify-content: space-between; }
.banner.sample { background: var(--warn-soft); color: var(--warn-ink); border-bottom: 1px solid #f0d58a; }
.banner.error { background: var(--danger); color: #fff; }
.banner.info { background: var(--navy-soft); color: var(--navy); }
.banner.offline { background: #eef0f4; color: var(--muted); font-size: .8rem; padding: 4px 16px; justify-content: center; }
.banner button { flex: none; }

main { max-width: 760px; margin: 0 auto; padding: 16px 16px calc(var(--tabbar-h) + var(--safe-b) + 24px); }
main.has-cart { padding-bottom: calc(var(--tabbar-h) + var(--safe-b) + 150px); }

/* ── 下部ナビ ── */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: #fff; border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}
.tabbar a {
  min-height: var(--tabbar-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: .72rem; font-weight: 600;
}
.tabbar a svg { width: 24px; height: 24px; }
.tabbar a[aria-current="page"] { color: var(--navy); }
.tabbar a[aria-current="page"] svg { color: var(--green-2); }

/* ── 部品 ── */
.card { background: var(--card); border-radius: var(--radius); padding: 16px; box-shadow: 0 1px 2px rgba(19,34,74,.06); border: 1px solid var(--line); }
.stack > * + * { margin-top: 14px; }
.stack-sm > * + * { margin-top: 8px; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.xs { font-size: .75rem; }
.center { text-align: center; }
.num { font-variant-numeric: tabular-nums; }
.neg { color: var(--danger); }
.pos { color: var(--green-ink); }
hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: var(--tap); padding: 10px 18px; border-radius: 12px; border: 1px solid var(--line);
  background: #fff; color: var(--navy); font-weight: 700; cursor: pointer; text-decoration: none; text-align: center;
  touch-action: manipulation; user-select: none;
}
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--green); border-color: var(--green); color: var(--navy); }
.btn.primary:active { background: var(--green-2); }
.btn.navy { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.danger { background: #fff; border-color: var(--danger); color: var(--danger); }
.btn.danger.solid { background: var(--danger); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.block { width: 100%; }
.btn.big { min-height: 60px; font-size: 1.1rem; border-radius: 16px; }
.btn.sm { min-height: 44px; padding: 6px 12px; font-size: .9rem; }
.linkbtn { background: none; border: 0; padding: 10px 4px; min-height: 44px; color: var(--navy-2); text-decoration: underline; cursor: pointer; font-weight: 600; }

.field { display: block; }
.field > span.lbl { display: block; font-weight: 700; font-size: .9rem; margin-bottom: 6px; }
.field .req { color: var(--danger); font-size: .75rem; margin-left: 6px; }
.field .opt { color: var(--muted); font-size: .75rem; margin-left: 6px; font-weight: 500; }
.input, select.input, textarea.input {
  width: 100%; min-height: var(--tap); padding: 10px 12px; border-radius: 10px; border: 1.5px solid var(--line); background: #fff;
}
textarea.input { min-height: 84px; resize: vertical; }
.input:focus { outline: none; border-color: var(--navy-2); box-shadow: 0 0 0 3px rgba(31,53,118,.15); }
.input.invalid { border-color: var(--danger); }
.err { color: var(--danger); font-size: .85rem; margin-top: 4px; font-weight: 600; }
.err:empty { display: none; }
.hint { color: var(--muted); font-size: .8rem; margin-top: 4px; }
.yen-input { position: relative; }
.yen-input::before { content: "¥"; position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); font-weight: 700; }
.yen-input .input { padding-left: 28px; font-size: 1.2rem; font-weight: 700; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 44px; padding: 8px 14px; border-radius: 999px; border: 1.5px solid var(--line); background: #fff;
  font-weight: 700; cursor: pointer; touch-action: manipulation;
}
.chip[aria-pressed="true"] { background: var(--navy); border-color: var(--navy); color: #fff; }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--navy-soft); border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { min-height: 44px; border: 0; border-radius: 9px; background: transparent; font-weight: 700; color: var(--navy); cursor: pointer; }
.seg button[aria-pressed="true"] { background: #fff; box-shadow: 0 1px 3px rgba(19,34,74,.15); }

.tabs { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; border-bottom: 2px solid var(--line); }
.tabs a { min-height: 48px; display: flex; align-items: center; justify-content: center; text-decoration: none; color: var(--muted); font-weight: 700; margin-bottom: -2px; border-bottom: 3px solid transparent; }
.tabs a[aria-current="page"] { color: var(--navy); border-color: var(--green); }

.notice { background: var(--navy-soft); color: var(--navy); padding: 12px 14px; border-radius: 12px; font-size: .9rem; }
.notice.warn { background: var(--warn-soft); color: var(--warn-ink); }
.notice.danger { background: var(--danger-soft); color: var(--danger); }
.badge { display: inline-block; font-size: .72rem; font-weight: 700; padding: 1px 8px; border-radius: 999px; background: var(--navy-soft); color: var(--navy); vertical-align: middle; }
.badge.ref { background: var(--warn-soft); color: var(--warn-ink); }
.badge.green { background: var(--green-soft); color: var(--green-ink); }

/* ── 指標 ── */
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.kpi { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.kpi .k { font-size: .75rem; color: var(--muted); font-weight: 700; }
.kpi .v { font-size: 1.25rem; font-weight: 800; font-variant-numeric: tabular-nums; word-break: break-all; }
.hero { background: var(--navy); color: #fff; border-radius: var(--radius); padding: 18px; }
.hero .k { color: #c9d3ee; font-size: .8rem; font-weight: 700; }
.hero .v { font-size: 2rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.hero .neg { color: #ffb4ae; }

/* ── リスト ── */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { border-bottom: 1px solid var(--line); }
.list > li:last-child { border-bottom: 0; }
.ev-item { display: flex; gap: 12px; align-items: center; padding: 12px 4px; text-decoration: none; color: inherit; min-height: 64px; }
.ev-date { flex: none; width: 52px; text-align: center; background: var(--navy-soft); border-radius: 10px; padding: 6px 0; color: var(--navy); }
.ev-date b { display: block; font-size: 1.15rem; line-height: 1.1; }
.ev-date span { font-size: .7rem; font-weight: 700; }
.ev-title { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ev-sub { font-size: .8rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ev-money { text-align: right; flex: none; font-variant-numeric: tabular-nums; }
.ev-money b { display: block; }
.month-h { display: flex; justify-content: space-between; font-weight: 800; color: var(--navy); padding: 6px 2px; font-size: .9rem; }

/* ── 販売 ── */
.products { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 520px) { .products { grid-template-columns: repeat(3, 1fr); } }
.ptile {
  position: relative; min-height: 88px; border-radius: 14px; border: 1.5px solid var(--line); background: #fff;
  padding: 10px 12px; text-align: left; cursor: pointer; touch-action: manipulation; display: flex; flex-direction: column; justify-content: space-between;
}
.ptile:active { background: var(--green-soft); border-color: var(--green); }
.ptile .pn { font-weight: 700; line-height: 1.3; word-break: break-all; }
.ptile .pp { font-weight: 800; color: var(--navy-2); font-variant-numeric: tabular-nums; }
.ptile .cnt { position: absolute; top: -8px; right: -6px; min-width: 28px; height: 28px; border-radius: 14px; background: var(--green); color: var(--navy); font-weight: 800; display: flex; align-items: center; justify-content: center; padding: 0 6px; border: 2px solid #fff; }
.ptile.free { border-style: dashed; color: var(--navy-2); align-items: center; justify-content: center; text-align: center; font-weight: 700; }

.cart {
  position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar-h) + var(--safe-b)); z-index: 25;
  background: #fff; border-top: 2px solid var(--green); box-shadow: 0 -6px 18px rgba(19,34,74,.12);
  padding: 10px 16px 12px;
}
.cart-inner { max-width: 760px; margin: 0 auto; }
.cart-lines { max-height: 30vh; overflow: auto; }
.cart-line { display: flex; align-items: center; gap: 8px; padding: 4px 0; font-size: .9rem; }
.qty { display: flex; align-items: center; gap: 4px; }
.qty button { width: 44px; height: 44px; border-radius: 10px; border: 1.5px solid var(--line); background: #fff; font-size: 1.2rem; font-weight: 800; cursor: pointer; }
.qty b { min-width: 26px; text-align: center; }
.cart-total { font-size: 1.3rem; font-weight: 800; font-variant-numeric: tabular-nums; }

.tx { padding: 10px 2px; }
.tx.deleted { opacity: .55; }
.tx.deleted .tx-lines { text-decoration: line-through; }
.tx-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: .85rem; color: var(--muted); }
.tx-line { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.tx-line button { min-height: 40px; }

/* ── グラフ ── */
.bars { display: grid; gap: 6px; }
.bar-row { display: grid; grid-template-columns: 72px 1fr auto; gap: 8px; align-items: center; font-size: .85rem; }
.bar-row .lab { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.bar-track { height: 18px; background: var(--navy-soft); border-radius: 6px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--green); border-radius: 6px; min-width: 2px; }
.bar-fill.neg { background: #f19a93; }
.bar-row .val { font-variant-numeric: tabular-nums; font-weight: 700; text-align: right; min-width: 70px; }

table.cmp { width: 100%; border-collapse: collapse; font-size: .85rem; }
table.cmp th, table.cmp td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: right; font-variant-numeric: tabular-nums; vertical-align: top; }
table.cmp th:first-child, table.cmp td:first-child { text-align: left; }
table.cmp th { font-size: .75rem; color: var(--muted); font-weight: 700; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ── モーダル・トースト ── */
.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(10,18,40,.5); display: flex; align-items: flex-end; justify-content: center; }
@media (min-width: 640px) { .overlay { align-items: center; } }
.modal {
  background: #fff; width: 100%; max-width: 520px; max-height: 92vh; overflow: auto;
  border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + var(--safe-b));
}
@media (min-width: 640px) { .modal { border-radius: 18px; } }
.modal-actions { display: flex; gap: 10px; margin-top: 18px; }
.modal-actions .btn { flex: 1; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 60;
  bottom: calc(var(--tabbar-h) + var(--safe-b) + 14px + var(--cart-h, 0px));
  background: var(--ink); color: #fff; border-radius: 12px; padding: 8px 8px 8px 16px;
  display: flex; align-items: center; gap: 10px; max-width: calc(100% - 32px); width: max-content; box-shadow: 0 6px 20px rgba(0,0,0,.25);
}
.toast.error { background: var(--danger); }
.toast button { min-height: 44px; background: var(--green); color: var(--navy); border: 0; border-radius: 9px; font-weight: 800; padding: 0 14px; cursor: pointer; }

.empty { text-align: center; padding: 28px 12px; color: var(--muted); }
.empty .big { font-size: 2rem; }
.steps { counter-reset: s; list-style: none; padding: 0; margin: 0; text-align: left; }
.steps li { counter-increment: s; position: relative; padding: 6px 0 6px 38px; }
.steps li::before { content: counter(s); position: absolute; left: 0; top: 6px; width: 26px; height: 26px; border-radius: 50%; background: var(--green); color: var(--navy); font-weight: 800; display: flex; align-items: center; justify-content: center; font-size: .85rem; }

details.filters summary { cursor: pointer; font-weight: 700; min-height: 44px; display: flex; align-items: center; color: var(--navy-2); }
.legal h2 { margin-top: 18px; }
.legal p, .legal li { font-size: .92rem; }
.boot { padding: 40px 16px; text-align: center; color: var(--muted); }
.fatal { max-width: 560px; margin: 40px auto; }
@media (prefers-reduced-motion: no-preference) {
  .toast { animation: up .18s ease-out; }
  @keyframes up { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }
}
