:root {
  color-scheme: light;
  --bg: #f6f1ea;
  --card: #fffdfb;
  --text: #2a211d;
  --muted: #8a7568;
  --accent: #b25b2e;
  --accent-2: #f5e6da;
  --border: #e7dccf;
  --danger: #b3413a;
  --ok: #2f7d4f;
  --ribbon-bg: #3a2620;
  --ribbon-accent: #e0a34f;
  --user-bubble: #3a2620;
  --assistant-bubble: #ffffff;
}

* { box-sizing: border-box; }
html, body {
  height: 100%;
  height: 100dvh;
  overflow: hidden;
}
body {
  margin: 0;
  font-family: "Noto Sans JP", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}
button { font: inherit; }
input, select { font: inherit; }

.app-shell {
  max-width: 860px;
  margin: 0 auto;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ---------- ヘッダー ---------- */
.topbar {
  flex-shrink: 0;
  padding: 14px 16px 10px;
  padding-top: calc(14px + env(safe-area-inset-top, 0px));
  background: linear-gradient(135deg, #1b120f, #2a1c16);
  color: white;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.topbar > div:first-child { min-width: 0; flex: 1 1 auto; }
.topbar h1 {
  margin: 0;
  font-size: 0.95rem;
  letter-spacing: 0.08em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-actions { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }
.pill {
  padding: 7px 10px;
  border-radius: 999px;
  background: rgba(255,255,255,0.16);
  font-size: 0.74rem;
  white-space: nowrap;
  color: white;
  border: none;
}
.pill-btn { cursor: pointer; }
.pill-btn:hover { background: rgba(255,255,255,0.26); }

/* ---------- 画面切替 ---------- */
.screen {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 24px 16px;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}
.login-card {
  width: min(100%, 420px);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px;
  margin-top: 6vh;
}

main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.panel { display: none; }
.panel.active {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}
#orders-view.active, #admin-view.active {
  overflow-y: auto;
  padding: 12px 12px 24px;
  -webkit-overflow-scrolling: touch;
}
#order-view.active { overflow: hidden; }

.section-head { margin-bottom: 10px; }
.section-head h2 { margin: 0 0 4px; font-size: 1.05rem; }
.section-head p { margin: 0; color: var(--muted); font-size: 0.85rem; }
.section-subhead { font-weight: 700; margin: 14px 0 6px; }
.small { color: var(--muted); font-size: 0.82rem; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.hidden { display: none !important; }

/* ---------- 卓チップ ---------- */
.table-bar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--ribbon-bg);
  color: white;
}
.table-bar-label { font-size: 0.78rem; opacity: 0.8; flex-shrink: 0; }
.table-chips {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.table-chips::-webkit-scrollbar { display: none; }
.table-chip {
  flex-shrink: 0;
  border: 1px solid rgba(255,255,255,0.3);
  background: transparent;
  color: rgba(255,255,255,0.85);
  border-radius: 999px;
  padding: 5px 11px;
  font-size: 0.82rem;
  cursor: pointer;
}
.table-chip.active {
  background: var(--ribbon-accent);
  border-color: var(--ribbon-accent);
  color: #2a1c16;
  font-weight: 700;
}

/* ---------- チャット ---------- */
.chat-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  -webkit-overflow-scrolling: touch;
}
.chat-list.admin {
  flex: 0 0 auto;
  height: 42dvh;
  min-height: 220px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px;
}
.chat-empty {
  margin: auto;
  text-align: center;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.6;
  white-space: pre-line;
}
.chat-row { display: flex; flex-direction: column; max-width: 88%; }
.chat-row.user { align-self: flex-end; align-items: flex-end; }
.chat-row.assistant { align-self: flex-start; align-items: flex-start; }
.chat-bubble {
  padding: 9px 12px;
  border-radius: 14px;
  font-size: 0.9rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}
.chat-row.user .chat-bubble { background: var(--user-bubble); color: white; border-bottom-right-radius: 4px; }
.chat-row.assistant .chat-bubble { background: var(--assistant-bubble); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.chat-bubble.typing { color: var(--muted); }
.chat-time { font-size: 0.68rem; color: var(--muted); margin: 3px 4px 0; }
.chat-system {
  align-self: center;
  font-size: 0.76rem;
  color: var(--muted);
  background: rgba(58,38,32,0.06);
  padding: 4px 10px;
  border-radius: 999px;
  text-align: center;
}
.chat-tag {
  display: inline-block;
  font-size: 0.66rem;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(255,255,255,0.2);
  margin-right: 6px;
  vertical-align: middle;
}
.chat-row.assistant .chat-tag { background: var(--accent-2); color: var(--accent); }
.chat-tag.ok { background: #dcfce7; color: #166534; }
.chat-tag.danger { background: #fee2e2; color: #991b1b; }
.pending-card {
  margin-top: 8px;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--accent-2);
  border: 1px dashed var(--accent);
}
.pending-summary { font-size: 0.85rem; margin-bottom: 6px; }
.pending-actions { display: flex; gap: 6px; align-items: center; }

/* ---------- 注文ドラフト ---------- */
.draft-card {
  flex-shrink: 0;
  margin: 0 12px 8px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 12px;
  box-shadow: 0 -2px 10px rgba(0,0,0,0.04);
}
.draft-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 6px; }
.draft-head strong { font-size: 0.9rem; }
.draft-list { max-height: 26dvh; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; }
.draft-line {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
  align-items: center;
  padding: 5px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.86rem;
}
.draft-line:last-child { border-bottom: none; }
.draft-line .name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.draft-line .price { color: var(--muted); font-size: 0.78rem; }

/* ---------- ドリンクの宛先（ゲスト / キャスト） ---------- */
.cast-pick { position: relative; display: inline-flex; align-items: center; margin-top: 3px; cursor: pointer; }
.cast-badge {
  font-size: 0.7rem;
  line-height: 1;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  background: #fff;
}
.cast-badge::after { content: ' ▾'; font-size: 0.6rem; }
.cast-pick.is-cast .cast-badge { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }
.cast-select { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.cast-tag {
  display: inline-block;
  font-size: 0.68rem;
  line-height: 1;
  padding: 2px 6px;
  margin-left: 4px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  vertical-align: middle;
}
.cast-chips-wrap { flex-shrink: 0; display: flex; align-items: center; gap: 8px; padding: 8px 12px 0; background: #fff; }
.cast-chips-label { font-size: 0.74rem; color: var(--muted); flex-shrink: 0; }
.cast-chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 8px; }
.cast-chips::-webkit-scrollbar { display: none; }
.cast-chips.wrap { flex-wrap: wrap; overflow: visible; margin: 8px 0; }
.cast-chip {
  flex-shrink: 0;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: 999px;
  padding: 5px 11px;
  font-size: 0.8rem;
  cursor: pointer;
}
.cast-chip.active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }
.cast-chip.inactive { color: var(--muted); text-decoration: line-through; background: #f3f4f6; }
.product-select-btn.is-cast { width: auto; min-width: 56px; flex-basis: auto; padding: 7px 8px; white-space: nowrap; }
.inline-form { display: flex; gap: 8px; align-items: center; margin-top: 4px; }
.inline-form input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 9px 12px;
  font-size: 0.9rem;
  background: white;
}
#cast-admin > .small { color: var(--muted); margin: 0 0 4px; }
.qty-ctl { display: flex; align-items: center; gap: 4px; }
.qty-ctl span { min-width: 22px; text-align: center; font-weight: 700; }
.qty-ctl .icon-btn { width: 30px; height: 30px; font-size: 1rem; }
.draft-empty { color: var(--muted); font-size: 0.82rem; padding: 6px 0; }

/* ---------- 入力バー ---------- */
.input-bar {
  flex-shrink: 0;
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 6px 12px 4px;
}
.chat-form {
  flex: 1;
  display: flex;
  gap: 6px;
  background: white;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 4px 4px 14px;
  min-width: 0;
}
.chat-form input {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
  background: transparent;
  font-size: 0.9rem;
}
.send-btn { width: 36px; height: 36px; border-radius: 999px; font-size: 1rem; }
.mic-btn {
  flex-shrink: 0;
  width: 56px;
  height: 56px;
  border-radius: 999px;
  border: none;
  background: var(--accent);
  color: white;
  font-size: 1.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
  transition: transform 0.08s ease, box-shadow 0.08s ease, background 0.2s;
  box-shadow: 0 4px 12px rgba(178,91,46,0.35);
}
.mic-btn.listening {
  background: var(--danger);
  transform: scale(1.08);
  box-shadow: 0 0 0 8px rgba(179,65,58,0.18);
}
.mic-btn.connecting { background: var(--muted); }
.mic-btn:disabled { background: var(--border); color: var(--muted); box-shadow: none; cursor: not-allowed; }
.voice-status {
  flex-shrink: 0;
  min-height: 18px;
  padding: 0 14px 8px;
  font-size: 0.72rem;
  color: var(--muted);
  text-align: right;
}
.voice-status .partial { color: var(--text); float: left; max-width: 65%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- ボタン ---------- */
.primary-btn, .ghost-btn, .icon-btn, .nav-btn {
  border: none;
  border-radius: 12px;
  cursor: pointer;
}
.primary-btn {
  background: var(--accent);
  color: white;
  width: 100%;
  padding: 10px 12px;
  font-size: 0.88rem;
  font-weight: 600;
}
.primary-btn:disabled { background: var(--border); color: var(--muted); cursor: not-allowed; }
.ghost-btn {
  background: var(--accent-2);
  color: var(--accent);
  padding: 8px 10px;
  white-space: nowrap;
}
.small-btn { width: auto; padding: 6px 10px; font-size: 0.78rem; border-radius: 10px; }
.icon-btn {
  width: 40px;
  height: 40px;
  font-size: 1.2rem;
  background: var(--accent-2);
  color: var(--accent);
}
.product-select-btn {
  width: 56px;
  min-width: 56px;
  flex: 0 0 56px;
  padding: 7px 0;
  font-size: 0.76rem;
  text-align: center;
}
.product-select-btn:disabled { background: var(--border); color: var(--muted); cursor: not-allowed; }

/* ---------- 下部ナビ ---------- */
.bottom-nav {
  flex-shrink: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 8px 12px calc(12px + env(safe-area-inset-bottom, 0px));
  background: white;
  border-top: 1px solid var(--border);
}
.nav-btn { padding: 10px 8px; background: #f3f4f6; color: var(--muted); }
.nav-btn.active { background: var(--accent-2); color: var(--accent); font-weight: 700; }

/* ---------- 一覧カード ---------- */
.product-list, .stack-list { display: grid; gap: 10px; }
.product-list { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
.product-card, .stack-item {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}
.product-card { display: flex; flex-direction: column; justify-content: space-between; gap: 8px; padding: 12px; }
.product-card-body { min-width: 0; }
.product-title { font-size: 0.86rem; line-height: 1.3; font-weight: 700; margin-bottom: 4px; }
.product-meta { color: var(--muted); font-size: 0.74rem; line-height: 1.35; }
.price { font-weight: 700; font-size: 0.86rem; }
.product-card-footer { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.status-pill {
  display: inline-flex;
  padding: 5px 8px;
  border-radius: 999px;
  font-size: 0.8rem;
  background: var(--accent-2);
  color: var(--accent);
}
.status-pill.preparing { background: #fef3c7; color: #92400e; }
.status-pill.served { background: #dcfce7; color: #166534; }
.status-pill.cancelled { background: #f1f1ef; color: #6b6b68; }
.source-tag { font-size: 0.68rem; color: var(--muted); border: 1px solid var(--border); border-radius: 999px; padding: 1px 6px; margin-left: 6px; }

/* ---------- フォーム ---------- */
.login-form { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.login-form input, .login-form select {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 0.9rem;
  background: white;
}

/* ---------- トースト ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 110px;
  transform: translateX(-50%);
  background: #2a1c16;
  color: white;
  padding: 10px 14px;
  border-radius: 999px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
  z-index: 60;
  max-width: 90vw;
  text-align: center;
  font-size: 0.85rem;
}

/* ---------- メニューシート ---------- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(30, 20, 16, 0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
}
.sheet {
  width: min(100%, 860px);
  height: 82dvh;
  background: var(--bg);
  border-radius: 20px 20px 0 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sheet-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}
.sheet .product-list { flex: 1; min-height: 0; overflow-y: auto; padding: 12px; align-content: start; }

.category-tabs-wrap { flex-shrink: 0; background: var(--ribbon-bg); position: relative; }
.category-tabs {
  display: flex;
  gap: 20px;
  overflow-x: auto;
  padding: 12px 16px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x;
  cursor: grab;
}
.category-tabs.dragging { cursor: grabbing; user-select: none; }
.category-tabs::-webkit-scrollbar { display: none; }
.category-btn {
  border: none;
  border-bottom: 2px solid transparent;
  background: transparent;
  padding: 2px 2px 8px;
  white-space: nowrap;
  flex-shrink: 0;
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.68);
  cursor: pointer;
}
.category-btn.active { color: #fff; border-bottom-color: var(--ribbon-accent); font-weight: 700; }

@media (max-width: 420px) {
  .topbar { padding-left: 12px; padding-right: 12px; }
  .product-list { gap: 8px; }
  .product-card { padding: 10px; gap: 6px; }
  .chat-row { max-width: 92%; }
}
