:root {
  --bg: #10151b;
  --surface: #1b232d;
  --surface-2: #232e3a;
  --line: #33404f;
  --text: #eef2f6;
  --muted: #93a1b0;
  --primary: #3b82f6;
  --primary-press: #2563eb;
  --danger: #ef4444;
  --danger-press: #dc2626;
  --accent: #22c55e;
  --radius: 14px;
  --tap: 48px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic UI", "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
}

/* ===== ビュー切替 ===== */
.view { display: none; min-height: 100vh; padding-bottom: calc(96px + var(--safe-b)); }
.view.is-active { display: block; }
#view-order.is-active { display: flex; flex-direction: column; }
.hidden { display: none !important; }

/* ===== ヘッダー ===== */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  padding-top: calc(14px + env(safe-area-inset-top, 0px));
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.app-title { font-size: 18px; margin: 0; font-weight: 700; flex: 0 1 auto; }
.app-header .spacer { flex: 1; }
.header-actions { display: flex; gap: 8px; margin-left: auto; }

/* ===== ボタン共通 ===== */
.btn {
  min-height: var(--tap);
  padding: 0 16px;
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  background: var(--surface-2);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--primary); }
.btn-primary:active { background: var(--primary-press); }
.btn-danger { background: var(--danger); }
.btn-danger:active { background: var(--danger-press); }
.btn-ghost { background: transparent; border: 1px solid var(--line); padding: 0 12px; }

/* ===== 卓一覧 ===== */
.grand-total {
  padding: 14px 16px;
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.table-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 10px;
  padding: 14px;
}
.table-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 8px;
  min-height: 92px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  cursor: pointer;
  text-align: center;
}
.table-card:active { transform: scale(0.97); }
.table-card.is-open { border-color: var(--primary); background: #1d2a3d; }
.table-card .no { font-size: 20px; font-weight: 800; }
.table-card .sum { font-size: 15px; font-weight: 700; color: var(--accent); }
.table-card .count { font-size: 12px; color: var(--muted); }
.table-card.is-empty .sum { color: var(--muted); }

/* ===== 注文入力 ===== */
.order-body { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 12px; }
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
}
.panel h2 { margin: 0 0 10px; font-size: 15px; color: var(--muted); font-weight: 700; }
.panel-head { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.panel-head h2 { margin: 0; }

.cat-filter { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; }
.cat-chip {
  flex: 0 0 auto;
  min-height: 36px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.cat-chip.is-active { background: var(--primary); border-color: var(--primary); color: #fff; }

.menu-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
.menu-btn {
  min-height: 60px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  padding: 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  text-align: center;
}
.menu-btn:active { transform: scale(0.96); background: var(--primary); }
.menu-btn .m-name { font-size: 14px; font-weight: 700; }
.menu-btn .m-price { font-size: 13px; color: var(--muted); }

.manual-form { display: grid; grid-template-columns: 1fr 96px auto; gap: 8px; }
input[type="text"], input[type="number"] {
  min-height: var(--tap);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  padding: 0 12px;
  font-size: 16px;
  width: 100%;
}
input::placeholder { color: var(--muted); }

/* ===== 手入力の候補（オートコンプリート） ===== */
.suggest-list {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 260px;
  overflow-y: auto;
}
.suggest-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 46px;
  padding: 8px 12px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
}
.suggest-item:active { transform: scale(0.98); background: var(--primary); }
.suggest-item .s-name { font-weight: 700; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.suggest-item .s-price { flex: 0 0 auto; color: var(--muted); font-size: 14px; font-weight: 700; }
.suggest-item mark { background: transparent; color: var(--accent); font-weight: 800; }
.suggest-item .s-cat { color: var(--muted); font-weight: 500; font-size: 12px; margin-left: 6px; }

/* ===== 注文明細 ===== */
.order-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.order-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 10px;
  align-items: center;
  padding: 10px;
  background: var(--surface-2);
  border-radius: var(--radius);
}
.order-item .oi-name { font-weight: 700; }
.order-item .oi-unit { font-size: 13px; color: var(--muted); }
.order-item .oi-line { font-weight: 700; color: var(--accent); text-align: right; }
.qty-ctrl { display: flex; align-items: center; gap: 6px; }
.qty-btn {
  width: 40px; height: 40px;
  border: none; border-radius: 10px;
  background: var(--surface); color: var(--text);
  font-size: 20px; font-weight: 800; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.qty-btn:active { transform: scale(0.92); }
.qty-num { min-width: 28px; text-align: center; font-weight: 800; font-size: 17px; }
.oi-del {
  border: none; background: transparent; color: var(--danger);
  font-size: 14px; font-weight: 700; cursor: pointer; padding: 6px;
}

.empty-hint { color: var(--muted); font-size: 14px; margin: 6px 2px 0; }

/* ===== 注文フッター ===== */
.order-footer {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  padding-bottom: calc(12px + var(--safe-b));
  background: var(--surface);
  border-top: 1px solid var(--line);
  z-index: 20;
}
#view-order:not(.is-active) ~ .order-footer { display: none; }
.footer-total { font-size: 20px; font-weight: 800; }
.footer-total span { color: var(--accent); }

/* order-footer は #view-order 内にあるので、他ビュー表示時は隠す */
body:not(.order-active) .order-footer { display: none; }

/* ===== メニュー編集 ===== */
.menu-form { display: flex; flex-direction: column; gap: 8px; }
.menu-form-actions { display: flex; gap: 8px; }
.menu-form-actions .btn { flex: 1; }

.menu-manage-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.menu-manage-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface-2);
  border-radius: var(--radius);
}
.menu-manage-item .mm-main { flex: 1; min-width: 0; }
.menu-manage-item .mm-name { font-weight: 700; }
.menu-manage-item .mm-reading { font-weight: 500; font-size: 12px; color: var(--muted); margin-left: 4px; }
.menu-manage-item .mm-meta { font-size: 13px; color: var(--muted); }
.icon-btn {
  border: none; border-radius: 10px; min-height: 40px; padding: 0 12px;
  font-size: 14px; font-weight: 700; cursor: pointer; color: var(--text);
}
.icon-btn.edit { background: var(--surface); }
.icon-btn.del { background: transparent; color: var(--danger); }

.panel + .panel, .grand-total + .table-grid { margin-top: 0; }
.view .panel { margin: 12px; }
#view-order .order-body .panel { margin: 0; }

/* ===== 卓カードのラベル（卓メモ） ===== */
.table-card .label {
  font-size: 12px;
  font-weight: 700;
  color: var(--primary);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ===== 注文画面: 卓番号を大きく強調（誤入力に気づけるように） ===== */
.order-header .btn-ghost { flex: 0 0 auto; }
.order-table-badge {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}
.order-table-badge .ot-no {
  font-size: 24px;
  font-weight: 800;
  color: #fff;
  background: var(--primary);
  padding: 4px 16px;
  border-radius: 999px;
  line-height: 1.2;
}
.order-table-badge .ot-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 卓メモ入力 */
.table-label-field { display: flex; flex-direction: column; gap: 6px; }
.table-label-field > span { font-size: 13px; color: var(--muted); font-weight: 700; }

/* ===== 会計履歴 ===== */
.history-hint { color: var(--muted); font-size: 13px; margin: 0 0 10px; }
.history-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.history-item {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
}
.hi-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.hi-table { font-size: 16px; font-weight: 800; }
.hi-time { font-size: 12px; color: var(--muted); flex: 0 0 auto; }
.hi-items { font-size: 13px; color: var(--muted); margin: 6px 0; word-break: break-word; }
.hi-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.hi-total { font-weight: 800; color: var(--accent); }
.hi-total .hi-sub { color: var(--muted); font-weight: 600; font-size: 12px; margin-left: 4px; }
.hi-undo { min-height: 40px; padding: 0 14px; }

/* ===== 卓の移動モーダル ===== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  padding: 12px;
}
.modal-box {
  width: 100%;
  max-width: 560px;
  max-height: 82vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  padding-bottom: calc(16px + var(--safe-b));
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.modal-box h2 { margin: 0; font-size: 17px; font-weight: 800; }
.modal-hint { margin: 0; font-size: 13px; color: var(--muted); }
.move-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 8px;
}
.move-card {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 6px;
  min-height: 76px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  cursor: pointer;
  text-align: center;
  color: var(--text);
}
.move-card:active { transform: scale(0.96); }
.move-card.is-open { border-color: var(--primary); background: #1d2a3d; }
.move-card .no { font-size: 17px; font-weight: 800; }
.move-card .label { font-size: 11px; font-weight: 700; color: var(--primary); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.move-card .count { font-size: 11px; color: var(--muted); }

/* ===== トースト通知 ===== */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + var(--safe-b));
  transform: translate(-50%, 12px);
  z-index: 60;
  max-width: 88%;
  padding: 12px 18px;
  background: #0f1a12;
  border: 1px solid var(--accent);
  color: var(--text);
  border-radius: 999px;
  font-size: 14px;
  font-weight: 700;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.toast.is-show { opacity: 1; transform: translate(-50%, 0); }

/* ===== 席の区画（カウンター/テーブル） ===== */
.section-head {
  padding: 10px 16px 4px;
  font-size: 13px;
  font-weight: 800;
  color: var(--muted);
  letter-spacing: 0.04em;
  display: flex;
  align-items: center;
  gap: 8px;
}
.section-head::before {
  content: "";
  width: 10px; height: 10px;
  border-radius: 3px;
}
.section-head.counter::before { background: #f59e0b; }
.section-head.table::before { background: var(--primary); }

/* 席種で色分け（使用中の縁取り） */
.table-card.counter.is-open { border-color: #f59e0b; background: #2a2313; }
.table-card.table.is-open { border-color: var(--primary); background: #1d2a3d; }
.move-card.counter.is-open { border-color: #f59e0b; background: #2a2313; }
.move-card.table.is-open { border-color: var(--primary); background: #1d2a3d; }

/* ===== 人数入力 ===== */
.guests-field {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 10px;
  flex-wrap: wrap;
}
.guests-field > span { font-size: 13px; color: var(--muted); font-weight: 700; }
.guests-ctrl { display: flex; align-items: center; gap: 8px; }
.guests-num { min-width: 32px; text-align: center; font-weight: 800; font-size: 18px; }
.guests-charge { font-size: 13px; font-weight: 700; color: var(--accent); }
.guests-charge.hidden { display: none !important; }

/* ===== 料金内訳 ===== */
.bill-breakdown {
  margin-top: 10px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.bd-row {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  color: var(--muted);
}
.bd-row span:last-child { font-weight: 700; color: var(--text); }
.bd-row.bd-total { font-size: 17px; margin-top: 4px; }
.bd-row.bd-total span { color: var(--accent); font-weight: 800; }

/* ===== 会計モーダル ===== */
.checkout-breakdown {
  display: flex;
  flex-direction: column;
  gap: 5px;
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: 12px;
}
.pay-method { display: flex; gap: 8px; }
.pay-btn {
  flex: 1;
  min-height: var(--tap);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}
.pay-btn.is-active { background: var(--primary); border-color: var(--primary); color: #fff; }
.quick-cash { display: flex; flex-wrap: wrap; gap: 8px; }
.quick-btn {
  flex: 1 0 auto;
  min-height: 42px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}
.quick-btn:active { transform: scale(0.97); background: var(--primary); }
.change-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 16px;
  font-weight: 700;
  padding: 4px 2px;
}
.change-row span { font-size: 22px; font-weight: 800; color: var(--accent); }
.change-row span.short { color: var(--danger); }
.checkout-actions { display: flex; gap: 8px; }
.checkout-actions .btn { flex: 1; }

/* ===== 設定 ===== */
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 0;
  font-size: 15px;
  font-weight: 700;
}
.setting-row input[type="checkbox"] { width: 22px; height: 22px; }
.setting-field { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.setting-field > span { font-size: 13px; color: var(--muted); font-weight: 700; }

/* ===== レポート ===== */
.report-stats, .report-pay { display: flex; flex-direction: column; gap: 2px; }
.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
}
.stat-row:last-child { border-bottom: none; }
.stat-label { font-size: 14px; color: var(--muted); }
.stat-value { font-size: 17px; font-weight: 800; color: var(--text); }
.report-items { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.report-item {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--surface-2);
  border-radius: 10px;
}
.ri-rank {
  width: 24px; height: 24px;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface); border-radius: 50%;
  font-size: 12px; font-weight: 800; color: var(--muted);
}
.ri-name { font-weight: 700; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ri-qty { font-size: 14px; color: var(--muted); font-weight: 700; }
.ri-amount { font-size: 14px; font-weight: 800; color: var(--accent); }

.hi-guests { font-size: 12px; color: var(--muted); font-weight: 600; }
