:root {
  --bg: #eef2ec;
  --surface: #ffffff;
  --ink: #16241b;
  --sub: #55635a;
  --line: #d9e0d8;
  --field-line: #84928a;

  --cash: #0c7f49;
  --cash-edge: #075a33;
  --cash-soft: #dff3e8;
  --paypay: #cf2f1c;
  --paypay-edge: #9c2112;
  --paypay-soft: #fde6e1;
  --cheese: #ffcb3d;
  --alert: #b3261a;
  --alert-soft: #fde9e6;

  --font-text: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", Meiryo, sans-serif;
  --font-count: "DIN Condensed", "DIN Alternate", "Roboto Condensed", "Arial Narrow", var(--font-text);

  --page-gutter: 12px;
  --radius-card: 18px;
  --radius-key: 14px;
  --radius-field: 10px;
  --radius-pill: 999px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  padding-bottom: calc(32px + env(safe-area-inset-bottom));
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-text);
  font-size: 16px;
  line-height: 1.5;
}

h1, h2, h3, p { margin: 0; }

.phrase { display: inline-block; max-width: 100%; overflow-wrap: anywhere; }

a { color: inherit; }

button, input, select {
  font: inherit;
  color: inherit;
}

button {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  cursor: pointer;
}

button:disabled { opacity: 0.5; cursor: default; }

:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 2px;
}

.note { padding: 12px 16px; color: var(--sub); font-size: 15px; }

/* 接続状態：普段は控えめに、切れたときだけ目立たせる */

.status {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 30px;
  padding: 4px 16px;
  padding-top: calc(4px + env(safe-area-inset-top));
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  color: var(--sub);
  font-size: 13px;
  font-weight: 600;
}

.status[hidden] { display: none; }

.status-text { display: flex; align-items: center; gap: 6px; }

.status-text::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--field-line);
}

.status.is-on .status-text::before { background: var(--cash); }

.status.is-off {
  background: var(--alert);
  border-color: var(--alert);
  color: #fff;
  font-weight: 700;
}

.status.is-off .status-text::before { background: #fff; }

.status-pending {
  padding: 1px 10px;
  border-radius: var(--radius-pill);
  background: var(--cheese);
  color: var(--ink);
  font-weight: 700;
  white-space: nowrap;
}

/* 送信できなかった売上 */

.failure {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin: 10px var(--page-gutter) 0;
  padding: 12px 14px;
  border: 1.5px solid var(--alert);
  border-radius: var(--radius-key);
  background: var(--alert-soft);
  font-size: 14px;
}

.failure-title { font-weight: 700; }

/* ボタン */

.btn {
  min-height: 48px;
  padding: 10px 16px;
  border: 1.5px solid var(--field-line);
  border-radius: var(--radius-field);
  background: var(--surface);
  font-weight: 700;
}

.btn-primary { border-color: var(--ink); background: var(--ink); color: #fff; }
.btn-danger { border-color: var(--alert); background: var(--alert); color: #fff; }

.btn-cash,
.btn-paypay {
  border: 0;
  border-radius: var(--radius-key);
  color: #fff;
}

.btn-cash { background: var(--cash); box-shadow: 0 4px 0 var(--cash-edge); }
.btn-paypay { background: var(--paypay); box-shadow: 0 4px 0 var(--paypay-edge); }

.btn-small {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 6px 14px;
  border: 1px solid var(--field-line);
  border-radius: var(--radius-field);
  background: var(--surface);
  font-size: 14px;
  font-weight: 700;
  line-height: 1.3;
  text-align: center;
  text-decoration: none;
}

.btn-small-danger { border-color: var(--alert); color: var(--alert); }

/* ページの見出し */

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px 10px;
}

.page-title {
  font-size: 24px;
  font-weight: 800;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.page-nav {
  display: flex;
  flex-shrink: 0;
  gap: 8px;
}

.page-nav a {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 4px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: var(--surface);
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}

/* カード */

.card,
.item,
.arrival,
.totals,
.board,
.settings-section {
  margin: 0 var(--page-gutter) 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  background: var(--surface);
}

.section-title {
  padding: 12px 16px 8px;
  font-size: 15px;
  font-weight: 800;
}

/* 画面の選択とログイン */

.choices {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0 var(--page-gutter);
  list-style: none;
}

.choice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 76px;
  padding: 14px 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  background: var(--surface);
  font-size: 19px;
  font-weight: 800;
  line-height: 1.35;
  text-decoration: none;
  overflow-wrap: anywhere;
}

.choice::after {
  content: "";
  flex-shrink: 0;
  width: 10px;
  height: 10px;
  border-top: 2.5px solid currentColor;
  border-right: 2.5px solid currentColor;
  transform: rotate(45deg);
}

.choice-site { border-color: var(--cheese); background: var(--cheese); }
.choice-sub { display: block; font-size: 13px; font-weight: 600; }
.choice:not(.choice-site) .choice-sub { color: var(--sub); }

.login {
  display: grid;
  gap: 16px;
  max-width: 380px;
  margin: 12vh auto 0;
  padding: 24px 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  background: var(--surface);
}

@media (max-width: 420px) {
  .login { margin-right: var(--page-gutter); margin-left: var(--page-gutter); }
}

.login-title { font-size: 28px; font-weight: 800; line-height: 1.2; }
.login .input { font-size: 24px; letter-spacing: 0.3em; text-align: center; }
.login .btn { min-height: 52px; }

/* 入力欄 */

.field { display: grid; gap: 4px; font-size: 14px; font-weight: 700; }

.input {
  width: 100%;
  min-height: 48px;
  padding: 8px 12px;
  border: 1.5px solid var(--field-line);
  border-radius: var(--radius-field);
  background: #fff;
  font-size: 18px;
}

.input:focus {
  outline: none;
  border-color: var(--ink);
  box-shadow: 0 0 0 2px var(--ink);
}

.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.field-row {
  display: grid;
  grid-template-columns: 1fr 96px;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.stepper { display: grid; grid-template-columns: 44px minmax(0, 1fr) 44px; }
.stepper .input { border-right: 0; border-left: 0; border-radius: 0; padding: 8px 2px; text-align: center; }
.stepper .input:focus { position: relative; z-index: 1; }
.stepper .btn { min-height: 48px; padding: 0; font-size: 22px; line-height: 1; }
.stepper .btn:first-child { border-radius: var(--radius-field) 0 0 var(--radius-field); }
.stepper .btn:last-child { border-radius: 0 var(--radius-field) var(--radius-field) 0; }

.form-error {
  padding: 8px 12px;
  border-radius: var(--radius-field);
  background: var(--alert-soft);
  color: var(--alert);
  font-size: 14px;
  font-weight: 700;
}

/* 商品（外販先） */

.item { padding: 12px 14px; }

.item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.item-name { font-size: 18px; font-weight: 800; line-height: 1.35; overflow-wrap: anywhere; }

.count-planned {
  display: inline-block;
  margin-top: 4px;
  padding: 1px 10px;
  border-radius: var(--radius-pill);
  background: var(--cheese);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.count {
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  align-items: flex-end;
}

.count-label { color: var(--sub); font-size: 12px; font-weight: 700; line-height: 1.2; }

.count-num {
  font-family: var(--font-count);
  font-size: clamp(64px, 19vw, 76px);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 0.92;
  /* 数字の字形は行の上寄りに収まるので、上を空けて下の余白を詰める */
  margin: 0.08em 0 -0.2em;
}

.is-out .count-label,
.is-out .count-num { color: var(--alert); }

.sell {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding-bottom: 4px;
}

/* レジのキーのように、押すと沈む */
.sell-btn {
  display: grid;
  place-items: center;
  min-height: 76px;
  padding: 8px;
  border: 0;
  border-radius: var(--radius-key);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.2;
  transition: transform 60ms ease-out, box-shadow 60ms ease-out;
}

.sell-btn strong {
  font-family: var(--font-count);
  font-size: 32px;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  line-height: 1;
}

.sell-cash { background: var(--cash); box-shadow: 0 4px 0 var(--cash-edge); }
.sell-paypay { background: var(--paypay); box-shadow: 0 4px 0 var(--paypay-edge); }

.sell-btn:active { transform: translateY(3px); }
.sell-cash:active { box-shadow: 0 1px 0 var(--cash-edge); }
.sell-paypay:active { box-shadow: 0 1px 0 var(--paypay-edge); }

.item-links {
  display: grid;
  grid-template-columns: 3fr 2fr;
  gap: 10px;
  margin-top: 10px;
}

/* 補充の知らせ（外販先） */

.arrival {
  padding: 12px 14px;
  border-color: var(--cheese);
  background: var(--cheese);
  animation: arrive 900ms ease-out;
}

@keyframes arrive {
  0%, 100% { box-shadow: 0 0 0 0 rgb(255 203 61 / 0); }
  35% { box-shadow: 0 0 0 7px rgb(255 203 61 / 0.55); }
}

.arrival-title { font-size: 17px; font-weight: 800; line-height: 1.35; }

.arrival-body {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1.5px dashed rgb(22 36 27 / 0.45);
}

.arrival-items { margin: 0; padding: 0; font-size: 15px; font-weight: 700; list-style: none; }

/* 売上の合計 */

.totals {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
}

.total { min-width: 0; padding: 7px 14px 8px; }
.total + .total { border-left: 1px solid var(--line); }
.total-label { font-size: 12px; font-weight: 700; line-height: 1.3; }
.total-cash .total-label { color: var(--cash); }
.total-paypay .total-label { color: var(--paypay); }

.total-value {
  font-family: var(--font-count);
  font-size: clamp(22px, 6.4vw, 28px);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  line-height: 1.1;
}

/* 売上履歴 */

.history { padding-bottom: 4px; overflow: hidden; }

.sales { margin: 0; padding: 0; list-style: none; }

.sale {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  border-top: 1px solid var(--line);
}

.sale-main { font-size: 15px; font-weight: 700; line-height: 1.4; overflow-wrap: anywhere; }

.sale-sub {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px 6px;
  margin-top: 2px;
  color: var(--sub);
  font-size: 13px;
}

.pay-chip {
  padding: 0 8px;
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 700;
}

.pay-cash { background: var(--cash-soft); color: var(--cash-edge); }
.pay-paypay { background: var(--paypay-soft); color: var(--paypay-edge); }

.sale.is-void .sale-main { color: var(--sub); }
/* inline-block には親の取り消し線が届かないので、語ごとに引く */
.sale.is-void .sale-main .phrase { text-decoration: line-through; }
.sale-tag { color: var(--sub); font-size: 13px; font-weight: 700; white-space: nowrap; }
.sale-tag-pending { color: var(--ink); }

/* 店舗の画面 */

.boards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 360px), 1fr));
  align-items: start;
  gap: 12px;
  padding: 0 var(--page-gutter);
}

.board { min-width: 0; margin: 0; overflow: hidden; }

.board-head { padding: 12px 16px 10px; }
.board-name { font-size: 22px; font-weight: 800; line-height: 1.25; overflow-wrap: anywhere; }
.board-meta { color: var(--sub); font-size: 13px; font-weight: 600; }

.board .totals {
  margin: 0;
  border-width: 1px 0;
  border-radius: 0;
}

.stock-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
}

.stock-count { display: flex; flex-direction: column; align-items: flex-end; }
.stock-label { color: var(--sub); font-size: 12px; font-weight: 700; line-height: 1.2; }

.stock-num {
  font-family: var(--font-count);
  font-size: 64px;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  line-height: 0.92;
  margin: 0.08em 0 -0.2em;
}

.stock-row.is-out .stock-label,
.stock-row.is-out .stock-num { color: var(--alert); }

.stock-name { font-size: 17px; font-weight: 800; line-height: 1.35; overflow-wrap: anywhere; }
.stock-detail { margin-bottom: 6px; color: var(--sub); font-size: 13px; font-weight: 600; }

.board-actions { padding: 12px 16px; }
.board-actions .btn { width: 100%; }

.planned { margin: 0; padding: 0; list-style: none; }

.planned-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: var(--cheese);
  font-size: 14px;
  font-weight: 700;
}

.planned-row + .planned-row { border-top: 1.5px dashed rgb(22 36 27 / 0.45); }

.history-toggle { border-top: 1px solid var(--line); }

.history-toggle > summary {
  min-height: 48px;
  padding: 12px 16px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}

/* 設定 */

.settings-section { padding-bottom: 12px; overflow: hidden; }

.settings-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  padding: 10px 16px;
  border-top: 1px solid var(--line);
}

.settings-name { font-size: 15px; font-weight: 700; overflow-wrap: anywhere; }
.settings-sub { color: var(--sub); font-size: 13px; }
.settings-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.settings-add { padding: 12px 16px 0; }

/* ダイアログ：スマホではキーボードに隠れないよう上に寄せる */

.dialog {
  width: calc(100% - 16px);
  max-width: none;
  max-height: calc(100dvh - 16px);
  margin: calc(8px + env(safe-area-inset-top)) auto auto;
  padding: 0;
  border: 0;
  border-radius: 20px;
  background: var(--surface);
  color: var(--ink);
}

.dialog[open] { animation: sheet-in 140ms ease-out; }

@keyframes sheet-in {
  from { opacity: 0; transform: translateY(-10px); }
}

.dialog::backdrop { background: rgb(22 36 27 / 0.55); }

.dialog-form { display: grid; gap: 12px; padding: 14px 16px 18px; }

.dialog-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.dialog-title { padding-top: 6px; font-size: 18px; font-weight: 800; line-height: 1.35; overflow-wrap: anywhere; }
.dialog-sub { color: var(--sub); font-size: 14px; }
.dialog-actions { display: grid; gap: 10px; }
.dialog-actions.is-split { grid-template-columns: 1fr 1fr; padding-bottom: 4px; }
.dialog-actions.is-split .btn { padding: 10px 4px; font-size: 15px; white-space: nowrap; }
.dialog-head .btn-small { flex-shrink: 0; white-space: nowrap; }
.dialog-total { font-size: 18px; font-weight: 800; }

/* 登録の確認：次のタップを邪魔しないよう、販売ボタンにかからない上側に出す */

.toast {
  position: fixed;
  top: calc(36px + env(safe-area-inset-top));
  right: var(--page-gutter);
  left: var(--page-gutter);
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 520px;
  min-height: 52px;
  margin: 0 auto;
  padding: 6px 6px 6px 14px;
  border-radius: var(--radius-key);
  background: var(--ink);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.4;
  animation: sheet-in 120ms ease-out;
}

.toast[hidden] { display: none; }
.toast span { white-space: pre-line; overflow-wrap: anywhere; }

.toast-action {
  flex-shrink: 0;
  min-height: 44px;
  padding: 6px 14px;
  border: 0;
  border-radius: var(--radius-field);
  background: var(--cheese);
  color: var(--ink);
  font-weight: 800;
}

@media (hover: hover) {
  .btn:hover:not(:disabled),
  .btn-small:hover { background: var(--bg); }
  .btn-primary:hover:not(:disabled) { background: #2a3c31; }
  .btn-danger:hover:not(:disabled) { background: #8f1d13; }
  .btn-cash:hover:not(:disabled), .sell-cash:hover { background: #0a6f40; }
  .btn-paypay:hover:not(:disabled), .sell-paypay:hover { background: #b82816; }
  .page-nav a:hover { background: var(--bg); }
}

@media (min-width: 600px) {
  .dialog { width: 460px; margin: auto; }
  .site-view, .home-view { max-width: 540px; margin: 0 auto; }
  .settings-view { max-width: 720px; margin: 0 auto; }
}

@media (prefers-reduced-motion: reduce) {
  .arrival, .dialog[open], .toast { animation: none; }
  .sell-btn { transition: none; }
  .sell-btn:active { transform: none; }
}
