/*
  デザインの考え方
  - 紙の「お会計票」の置き換え。伝票の罫線(緑)と、赤インクの伝票番号・「会計済」のハンコを引き継ぐ
  - 目立たせるのは赤い番号とハンコだけ。それ以外は静かに
  - 薄暗い店内で片手操作する前提: 押せる場所は大きく、ダークモードは端末の設定に従う
  - 店舗ごとのテーマは :root の変数を差し替える(src/theme.js)
*/

:root {
  --paper: #f6f8f4;
  --surface: #ffffff;
  --ink: #1f2a37;
  --muted: #667383;
  --rule: #cfe0d4;
  --rule-strong: #9db8a8;
  --shu: #c8323a; /* 赤インク: 伝票番号とハンコ */
  --primary: #2f6e5b;
  --on-primary: #ffffff;
  --warn: #b7791f;
  --warn-bg: #fdf3dc;
  --danger: #b42318;
  --ok: #2f7d4f;
  --radius: 10px;
  --font: "Zen Kaku Gothic New", "Hiragino Sans", "Noto Sans JP", "Meiryo", sans-serif;
  --shadow: 0 1px 0 var(--rule);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #14181d;
    --surface: #1c2229;
    --ink: #e7ecef;
    --muted: #93a1ae;
    --rule: #2b3640;
    --rule-strong: #3d4c57;
    --shu: #ec5c63;
    --primary: #4fa384;
    --warn: #e0b04a;
    --warn-bg: #3a2f17;
    --danger: #f0605a;
    --ok: #5cc287;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #14181d;
  --surface: #1c2229;
  --ink: #e7ecef;
  --muted: #93a1ae;
  --rule: #2b3640;
  --rule-strong: #3d4c57;
  --shu: #ec5c63;
  --primary: #4fa384;
  --warn: #e0b04a;
  --warn-bg: #3a2f17;
  --danger: #f0605a;
  --ok: #5cc287;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--paper);
  font-variant-numeric: tabular-nums;
  -webkit-tap-highlight-color: transparent;
}

a {
  color: var(--primary);
}

h1,
h2,
h3 {
  line-height: 1.3;
  margin: 0;
}
h1 {
  font-size: 1.25rem;
}
h2 {
  font-size: 1.1rem;
}
h3 {
  font-size: 1rem;
}

p {
  margin: 0 0 0.75em;
}

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

[hidden] {
  display: none !important;
}

.muted {
  color: var(--muted);
}
.small {
  font-size: 0.85rem;
}
.num {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.right {
  text-align: right;
}
.row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.row.wrap {
  flex-wrap: wrap;
}
.spread {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.grow {
  flex: 1;
  min-width: 0;
}
.stack > * + * {
  margin-top: 12px;
}

/* ---------- ページの骨組み ---------- */

.page {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px 16px 120px;
}
.page.wide {
  max-width: 1080px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--rule);
}
.topbar .title,
#event-sub {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.topbar .title {
  font-weight: 700;
  font-size: 1rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.topbar .logo {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  object-fit: cover;
}

.conn {
  font-size: 0.8rem;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}
.conn::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ok);
}
.conn.off::before {
  background: var(--danger);
}
.conn.off {
  color: var(--danger);
}

.bottombar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  gap: 8px;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--rule);
}
.bottombar > * {
  flex: 1;
}

/* ---------- 部品 ---------- */

button,
.btn {
  font: inherit;
  font-weight: 700;
  min-height: 44px;
  padding: 8px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--rule-strong);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  touch-action: manipulation;
}
button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
button.primary,
.btn.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--on-primary);
}
button.danger {
  color: var(--danger);
  border-color: var(--danger);
}
button.ghost {
  border-color: transparent;
  background: transparent;
}
button.small {
  min-height: 34px;
  padding: 4px 10px;
  font-size: 0.85rem;
}
button.block {
  width: 100%;
}
button.big {
  min-height: 56px;
  font-size: 1.05rem;
}

input,
select,
textarea {
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--rule-strong);
  border-radius: calc(var(--radius) - 2px);
  padding: 10px 12px;
  min-height: 44px;
  width: 100%;
}
input[type="checkbox"],
input[type="radio"] {
  width: 22px;
  height: 22px;
  min-height: 0;
  accent-color: var(--primary);
}
input[type="color"] {
  padding: 2px;
  width: 56px;
}
textarea {
  min-height: 80px;
}

label.field {
  display: block;
}
label.field > span {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 4px;
}
.fields {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
.check {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 14px;
}
.section {
  margin-top: 24px;
}
.section > h2 {
  margin-bottom: 10px;
}

.notice {
  border-radius: var(--radius);
  padding: 10px 12px;
  background: var(--warn-bg);
  color: var(--ink);
  border-left: 4px solid var(--warn);
}
.notice.error {
  border-left-color: var(--danger);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 10px;
  border-radius: 999px;
  border: 1px solid var(--rule-strong);
  font-size: 0.8rem;
  white-space: nowrap;
}
.chip.warn {
  border-color: var(--warn);
  color: var(--warn);
}
.chip.ok {
  border-color: var(--ok, #2e7d32);
  color: var(--ok, #2e7d32);
}
.chip.danger {
  border-color: var(--danger);
  color: var(--danger);
}

.tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  border-bottom: 1px solid var(--rule);
  margin: 0 -16px 16px;
  padding: 0 16px;
  scrollbar-width: none;
}
.tabs button {
  border: none;
  border-radius: 0;
  background: none;
  border-bottom: 3px solid transparent;
  color: var(--muted);
  white-space: nowrap;
  padding: 8px 12px;
}
.tabs button[aria-selected="true"] {
  color: var(--ink);
  border-bottom-color: var(--primary);
}

table.list {
  /* width:100%だと狭い画面で列が無理やり縮み、「スタッフ」のような短い語でも
     1文字ずつ改行されて読みにくくなる。最小幅を確保して、はみ出た分は
     .table-wrap の横スクロールに任せる(説明文の列は引き続き折り返す)。 */
  width: 100%;
  min-width: 560px;
  border-collapse: collapse;
}
table.list th,
table.list td {
  text-align: left;
  padding: 8px 6px;
  border-bottom: 1px solid var(--rule);
  vertical-align: middle;
}
table.list th {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 500;
}
/* 1列目(種類・画面名などの短いラベル)は改行させない */
table.list td:first-child,
table.list th:first-child {
  white-space: nowrap;
}
.table-wrap {
  overflow-x: auto;
}

/* ---------- 伝票番号とハンコ(このシステムの顔) ---------- */

.tno {
  display: inline-flex;
  align-items: baseline;
  color: var(--shu);
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.tno::before {
  content: "No.";
  font-size: 0.7em;
  margin-right: 1px;
}

.stamp {
  display: inline-grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border: 2px solid var(--shu);
  border-radius: 50%;
  color: var(--shu);
  font-weight: 700;
  font-size: 0.72rem;
  line-height: 1.05;
  text-align: center;
  transform: rotate(-12deg);
  flex: none;
}
.stamp.big {
  width: 92px;
  height: 92px;
  font-size: 1.3rem;
  border-width: 3px;
}

/* 伝票の罫線: 明細の行 */
.slip {
  background: var(--surface);
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  overflow: hidden;
}
.slip-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 2px solid var(--rule-strong);
}
.slip-line {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--rule);
}
.slip-line:last-child {
  border-bottom: none;
}
.slip-line .label {
  flex: 1;
  min-width: 0;
}
.slip-line .qty {
  color: var(--muted);
  min-width: 2.5em;
  text-align: right;
}
.slip-line .amount {
  min-width: 5.5em;
  text-align: right;
}
.slip-line.sub {
  padding-left: 28px;
  color: var(--muted);
  font-size: 0.9rem;
}
.slip-line.canceled .label,
.slip-line.canceled .amount {
  text-decoration: line-through;
  color: var(--muted);
}
.slip-total {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 12px;
  border-top: 2px solid var(--rule-strong);
  font-weight: 700;
  font-size: 1.15rem;
}
.slip-total .amount {
  font-size: 1.5rem;
}

/* ---------- 当日の席一覧 ---------- */

.board {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
}
.group-card {
  text-align: left;
  display: block;
  width: 100%;
  padding: 0;
  font-weight: 400;
  background: var(--surface);
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  overflow: hidden;
}
.group-card .gc-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--rule-strong);
}
.group-card .seat {
  font-weight: 700;
  font-size: 1.1rem;
}
.group-card .gc-total {
  margin-left: auto;
  font-weight: 700;
  font-size: 1.1rem;
}
.group-card .gc-tickets {
  padding: 4px 12px 8px;
}
.gc-ticket {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
  border-bottom: 1px dashed var(--rule);
  font-size: 0.92rem;
}
.gc-ticket {
  flex-wrap: wrap;
  row-gap: 4px;
}
.gc-ticket > * {
  white-space: nowrap;
}
.gc-ticket > :last-child {
  margin-left: auto;
}
.nick {
  display: inline-block;
  max-width: 9em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
}
.gc-ticket:last-child {
  border-bottom: none;
}
.gc-ticket.paid {
  color: var(--muted);
}

.alert-strip {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
}
.alert-strip .notice {
  display: flex;
  align-items: center;
  gap: 8px;
}

.empty {
  text-align: center;
  padding: 48px 16px;
  color: var(--muted);
}

/* ---------- 全画面のシート(グループの詳細・注文・会計) ---------- */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: var(--paper);
  display: flex;
  flex-direction: column;
}
.sheet-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--rule);
}
.sheet-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  -webkit-overflow-scrolling: touch;
}
.sheet-body > .inner {
  max-width: 720px;
  margin: 0 auto;
}
.sheet-foot {
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--rule);
}
.sheet-foot > .inner {
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  gap: 8px;
}
.sheet-foot > .inner > * {
  flex: 1;
}

/* ダイアログ(確認・入力) */
.dialog-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(10, 14, 18, 0.55);
  display: grid;
  place-items: end center;
  padding: 16px;
}
@media (min-width: 640px) {
  .dialog-backdrop {
    place-items: center;
  }
}
.dialog {
  width: 100%;
  max-width: 460px;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  background: var(--surface);
  border-radius: calc(var(--radius) + 4px);
  padding: 18px;
}
.dialog h2 {
  margin-bottom: 10px;
}
.dialog .actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}
.dialog .actions > * {
  flex: 1;
}

/* 選択肢(宛先・客票など) */
.picks {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
}
.picks.wrap {
  flex-wrap: wrap;
}
.pick {
  font-weight: 500;
  min-height: 40px;
  padding: 4px 12px;
  border-radius: 999px;
  white-space: nowrap;
}
.pick[aria-pressed="true"] {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--on-primary);
}
.pick[aria-pressed="true"] .tno {
  color: inherit;
}

/* 商品ボタン */
.products {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
}
.product {
  position: relative;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  text-align: left;
  font-weight: 500;
  padding: 0;
  overflow: hidden;
  min-height: 76px;
}
.product img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  display: block;
  background: var(--rule);
}
.product .p-body {
  padding: 6px 8px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.product .p-name {
  font-size: 0.9rem;
  line-height: 1.3;
}
.product .p-price {
  font-size: 0.85rem;
  color: var(--muted);
}
.product .p-price.free {
  color: var(--primary);
  font-weight: 700;
}
.product .p-count {
  position: absolute;
  top: 6px;
  right: 6px;
  min-width: 28px;
  height: 28px;
  border-radius: 14px;
  padding: 0 6px;
  background: var(--shu);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
}
.product .p-stock {
  font-size: 0.75rem;
  color: var(--warn);
}
.product.soldout {
  opacity: 0.4;
}

.stepper {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.stepper button {
  min-width: 44px;
  padding: 0;
}
.stepper output {
  min-width: 2.5em;
  text-align: center;
  font-weight: 700;
}

/* トースト */
/* 上に出す(下のボタンやダイアログの操作をふさがないように) */
.toasts {
  position: fixed;
  left: 50%;
  top: calc(60px + env(safe-area-inset-top));
  transform: translateX(-50%);
  z-index: 80;
  display: grid;
  gap: 6px;
  width: min(92vw, 420px);
  pointer-events: none;
}
.toast {
  background: var(--ink);
  color: var(--paper);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 0.95rem;
}
.toast.error {
  background: var(--danger);
  color: #fff;
}

/* ログインなどの小さい画面 */
.narrow {
  max-width: 420px;
  margin: 0 auto;
  padding: 32px 16px 64px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 24px;
}
.brand .stamp {
  width: 40px;
  height: 40px;
  font-size: 0.7rem;
}

.foot-links {
  margin-top: 40px;
  font-size: 0.8rem;
  color: var(--muted);
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}
.foot-links a {
  color: var(--muted);
}

/* 画像の小さな表示 */
.thumb {
  width: 44px;
  height: 44px;
  border-radius: 6px;
  object-fit: cover;
  background: var(--rule);
  flex: none;
}

@media (prefers-reduced-motion: no-preference) {
  .stamp.animate {
    animation: stamp 0.35s ease-out;
  }
  @keyframes stamp {
    from {
      transform: rotate(-12deg) scale(1.8);
      opacity: 0;
    }
    to {
      transform: rotate(-12deg) scale(1);
      opacity: 1;
    }
  }
}

@media print {
  .topbar,
  .bottombar,
  .no-print {
    display: none !important;
  }
}

/* ---------- 提供画面 ---------- */

.serve-controls {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}
.serve-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  align-items: start;
}
.serve-card {
  background: var(--surface);
  border: 1px solid var(--rule-strong);
  border-left: 6px solid var(--rule-strong);
  border-radius: var(--radius);
  overflow: hidden;
}
.serve-card.late {
  border-left-color: var(--warn);
}
.serve-card.very-late {
  border-left-color: var(--danger);
}
.serve-card.very-late .serve-wait {
  color: var(--danger);
}
.serve-card.late .serve-wait {
  color: var(--warn);
}
.serve-card.fresh {
  box-shadow: 0 0 0 3px var(--primary);
}
.serve-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 10px 12px 0;
}
.serve-seat {
  font-weight: 700;
  font-size: 1.25rem;
}
.serve-wait {
  font-weight: 700;
  font-size: 1.1rem;
}
.serve-meta {
  padding: 0 12px 8px;
  border-bottom: 1px solid var(--rule-strong);
}
.serve-items {
  display: grid;
}
.serve-item {
  border: none;
  border-bottom: 1px solid var(--rule);
  border-radius: 0;
  justify-content: flex-start;
  text-align: left;
  font-weight: 500;
  min-height: 56px;
  padding: 8px 12px;
  gap: 10px;
  background: transparent;
}
.serve-item:last-child {
  border-bottom: none;
}
.serve-name {
  font-size: 1.05rem;
}
.serve-qty {
  font-size: 1.15rem;
  font-weight: 700;
}
.serve-pill {
  flex: none;
  min-width: 4.6em;
  text-align: center;
  font-size: 0.78rem;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--rule-strong);
  color: var(--muted);
}
.serve-item.st-making .serve-pill {
  border-color: var(--warn);
  color: var(--warn);
  background: var(--warn-bg);
}
.serve-item.st-served {
  color: var(--muted);
}
.serve-item.st-served .serve-name {
  text-decoration: line-through;
}
.serve-item.st-served .serve-pill {
  border-color: var(--ok);
  color: var(--ok);
}
.serve-actions {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--rule-strong);
}
.serve-actions > * {
  flex: 1;
}

/* ホール画面: 提供状態の小さな印 */
.serve-mark {
  font-size: 0.72rem;
  padding: 1px 6px;
  border-radius: 999px;
  border: 1px solid var(--rule-strong);
  color: var(--muted);
  white-space: nowrap;
  margin-left: 4px;
  vertical-align: 1px;
}
.serve-mark.making {
  border-color: var(--warn);
  color: var(--warn);
}

/* テンキー(当日の数字入力はすべてこれ) */
.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.keypad button {
  min-height: 56px;
  font-size: 1.35rem;
}
.keypad-display {
  text-align: center;
  font-size: 1.8rem;
  font-weight: 700;
  min-height: 2.2em;
  letter-spacing: 0.04em;
  border-bottom: 2px solid var(--rule-strong);
  margin-bottom: 8px;
}
.keypad-display.empty {
  color: var(--muted);
  font-weight: 400;
  font-size: 1rem;
  line-height: 2.2;
}


/* ---------- 携帯端末(iPhone・iPad・Android)向け ---------- */

/* ボタンは長押しでメニューや文字選択が出ないように。ダブルタップでの拡大もしない */
button,
.btn,
.pick,
.keypad button {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
/* シートやダイアログの中でスクロールしきっても、後ろの画面が動かない */
.sheet-body,
.dialog {
  overscroll-behavior: contain;
}
.dialog {
  max-height: calc(100dvh - 32px);
}
/* ノッチ・ホームバー・横向きの角を避ける */
.topbar,
.sheet-head {
  padding-top: max(8px, env(safe-area-inset-top));
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
}
.page {
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
}

/* iPad の横向きなど広い画面: 席の一覧を見たまま、右側にグループの伝票を出す */
@media (min-width: 960px) {
  :root {
    --panel-w: min(560px, 48vw);
  }
  .sheet {
    left: auto;
    width: var(--panel-w);
    border-left: 1px solid var(--rule-strong);
    box-shadow: -10px 0 30px rgba(0, 0, 0, 0.12);
  }
  body.has-sheet {
    overflow: auto !important;
  }
  body.has-sheet .topbar,
  body.has-sheet .page {
    margin-right: var(--panel-w);
  }
  body.has-sheet .bottombar {
    right: var(--panel-w);
  }
  body.has-sheet .dialog-backdrop {
    z-index: 60;
  }
  [data-open-group].is-open {
    outline: 3px solid var(--primary);
    outline-offset: 2px;
  }
}
