/* つけ回し盤面 PoC。夜の店内で使うダーク基調のUtility画面。
   配色の原則:
     操作の色(--brand)＝青。状態の色＝緑・琥珀・赤。この2系統を色相で完全に分ける。
     以前は操作色が深紅で、超過アラートの赤と近く、暗い店内で瞬時に見分けられなかった。
     このシステムの存在意義は「超過に気づけること」なので、赤はアラート専用に空ける。
   背景は寒色寄りのニュートラル。暖色の黒だと赤と馴染んでアラートが沈む。 */
:root {
  --bg: #10131a;
  --surface: #181c25;
  --surface-2: #222836;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.16);
  /* 文字のコントラストを引き上げ。暗所＋斜めから見る前提 */
  --ink: #f2f4f8;
  --dim: #aab3c2;
  --faint: #7d8695;
  /* 操作・選択・指名。赤から最も遠い色相にして、アラートと競合させない */
  --brand: #4b8ef7;
  --brand-ink: #8fbaff;
  --brand-soft: rgba(75, 142, 247, 0.18);
  /* 店舗の識別色。ヘッダの印だけに使い、機能の色としては使わない */
  --accent-shop: #d8324a;
  /* 状態色。夜の暗い店内・斜めから見る前提なので、彩度と面積を強めにとる */
  --ok: #35d39a;
  --ok-soft: rgba(53, 211, 154, 0.16);
  --amber: #ffb63d;
  --amber-soft: rgba(255, 182, 61, 0.20);
  --red: #ff4d55;
  --red-soft: rgba(255, 77, 85, 0.22);
  --mono: "JetBrains Mono", ui-monospace, monospace;
  --shadow: 0 8px 24px rgba(8, 6, 10, 0.45);
  /* input[type=time] などのネイティブUIを暗色で描かせる（白いピッカーが浮くのを防ぐ） */
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
[hidden] { display: none !important; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: "Zen Kaku Gothic New", "BIZ UDPGothic", "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif;
  font-size: 15px;
  line-height: 1.7;
  padding-bottom: 132px; /* 待機バーの分 */
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; background: none; border: none; padding: 0; cursor: pointer; }

/* ---------- ヘッダ ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px calc(10px);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 9px; min-width: 0; }
/* 店舗の識別色。ここだけ赤を残す。機能の色ではないので、状態の赤とは意味が衝突しない */
.brand-mark { width: 9px; height: 22px; border-radius: 3px; background: linear-gradient(180deg, var(--accent-shop), #7d1526); flex: none; }
.brand-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.brand-text strong { font-size: 14.5px; font-weight: 700; letter-spacing: 0.01em; white-space: nowrap; }
.brand-sub { font-size: 10.5px; color: var(--faint); font-family: var(--mono); }
.floor-tabs { display: flex; gap: 4px; margin-left: 2px; }
.floor-tab {
  padding: 5px 13px; border-radius: 999px; font-weight: 700; font-size: 13.5px;
  color: var(--dim); border: 1px solid transparent; transition: background 0.18s, color 0.18s;
}
.floor-tab[aria-selected="true"] { background: var(--brand-soft); color: var(--brand-ink); border-color: color-mix(in srgb, var(--brand) 45%, transparent); }
/* 相手フロア＝見るだけ。選択中でも操作色(--brand)を与えず、押せないことを色でも示す */
.floor-tab.is-foreign[aria-selected="true"] {
  background: var(--surface-2); color: var(--ink); border-color: var(--line-strong);
}
.floor-tab .ro {
  font-size: 9.5px; font-weight: 700; margin-left: 5px; padding: 0 5px; border-radius: 999px;
  background: var(--surface-2); color: var(--faint); line-height: 1.7; vertical-align: 1px;
}
.floor-tab.is-foreign[aria-selected="true"] .ro { background: var(--bg); }
/* 見るだけのフロアは盤面全体を一段沈める。自フロアと取り違えないようにする */
.board.is-readonly { opacity: 0.72; }
.board.is-readonly .seat-chip { cursor: default; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.conn { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; color: var(--dim); }
.conn-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); transition: background 0.2s; }
.conn.is-reconnecting .conn-dot { background: var(--amber); }
.conn.is-offline .conn-dot { background: var(--red); }
.icon-btn {
  width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center;
  color: var(--dim); background: var(--surface); border: 1px solid var(--line);
}
.icon-btn:active { background: var(--surface-2); }

/* ---------- アラートバナー ---------- */
.banner {
  position: sticky; top: 55px; z-index: 25;
  margin: 8px 14px 0; padding: 9px 13px;
  background: var(--red-soft); border: 1px solid color-mix(in srgb, var(--red) 45%, transparent);
  border-radius: 11px; color: #f4b9bb; font-size: 13.5px; font-weight: 500;
  display: flex; gap: 9px; align-items: baseline; cursor: pointer;
  animation: banner-in 0.25s ease-out;
}
.banner strong { color: #ff9b9e; font-weight: 700; }
.banner .banner-note { margin-left: auto; font-size: 11px; color: var(--dim); white-space: nowrap; }
@keyframes banner-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

.save-warn {
  position: sticky; top: 55px; z-index: 26;
  margin: 8px 14px 0; padding: 9px 13px; border-radius: 11px; font-size: 13px; font-weight: 500;
  background: var(--amber-soft); border: 1px solid color-mix(in srgb, var(--amber) 50%, transparent); color: #e8bf76;
}

.boot-error {
  margin: 12px 14px; padding: 12px 14px; border-radius: 11px; font-size: 13.5px; line-height: 1.7;
  background: var(--red-soft); border: 1px solid color-mix(in srgb, var(--red) 50%, transparent); color: #f4b9bb;
}

.hint {
  margin: 8px 14px 0; padding: 8px 13px; border-radius: 11px; font-size: 13px;
  background: var(--brand-soft); border: 1px solid color-mix(in srgb, var(--brand) 40%, transparent);
  color: var(--brand-ink); display: flex; align-items: center; gap: 8px;
  animation: banner-in 0.2s ease-out;
}
.hint button { margin-left: auto; font-size: 12px; color: var(--dim); text-decoration: underline; }

/* ---------- 盤面 ---------- */
.board {
  display: grid; gap: 10px; padding: 12px 14px 8px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
@media (min-width: 700px) { .board { grid-template-columns: repeat(auto-fill, minmax(215px, 1fr)); } }
.table-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 13px;
  padding: 10px 11px 11px; min-height: 96px; display: flex; flex-direction: column; gap: 7px;
  transition: border-color 0.18s, background 0.18s, box-shadow 0.18s;
}
.table-card.is-target { border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand); cursor: pointer; }
.table-card.is-full { opacity: 0.55; }

/* 卓の状態を「カードごと」色で分ける。チップの細い線だけだと、
   歩きながら斜めに見る現場では空卓と着席卓の区別がつかない。
   左端の太いレールは、カードが小さくなる2列表示でも視認できる。 */
.table-card::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
  border-radius: 13px 0 0 13px; background: transparent; transition: background 0.2s;
}
.table-card { position: relative; overflow: hidden; }
.table-card.st-empty { background: color-mix(in srgb, var(--bg) 45%, var(--surface)); border-style: dashed; }
.table-card.st-empty .table-name { color: var(--dim); }
.table-card.st-ok      { background: linear-gradient(160deg, color-mix(in srgb, var(--ok) 10%, var(--surface)), var(--surface) 62%); border-color: color-mix(in srgb, var(--ok) 34%, transparent); }
.table-card.st-ok::before      { background: var(--ok); }
.table-card.st-caution { background: linear-gradient(160deg, color-mix(in srgb, var(--amber) 14%, var(--surface)), var(--surface) 62%); border-color: color-mix(in srgb, var(--amber) 46%, transparent); }
.table-card.st-caution::before { background: var(--amber); }
.table-card.st-over    { background: linear-gradient(160deg, color-mix(in srgb, var(--red) 17%, var(--surface)), var(--surface) 62%); border-color: color-mix(in srgb, var(--red) 60%, transparent); }
.table-card.st-over::before    { background: var(--red); animation: rail-pulse 1.6s ease-in-out infinite; }
@keyframes rail-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
.table-card.st-over .table-name { color: #ffd9da; }

/* 卓名は情報の起点なので、状態色に負けないよう常に最前面の明度を保つ */
.table-card.st-ok .table-name, .table-card.st-caution .table-name { color: var(--ink); }
.table-head { display: flex; align-items: baseline; gap: 7px; }
.table-name { font-family: var(--mono); font-weight: 700; font-size: 15px; letter-spacing: 0.02em; }
.table-cap { font-size: 10.5px; color: var(--faint); font-family: var(--mono); }
.table-body { display: flex; flex-direction: column; gap: 6px; }

.seat-chip {
  position: relative; overflow: hidden;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 9px;
  padding: 6px 9px 8px; display: flex; align-items: center; gap: 7px; width: 100%; text-align: left;
  transition: border-color 0.18s, background 0.18s;
}
.seat-chip .name { font-weight: 700; font-size: 13.5px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seat-chip .time { margin-left: auto; font-family: var(--mono); font-size: 12.5px; font-weight: 700; color: var(--dim); flex: none; }
.seat-chip .bar { position: absolute; left: 0; bottom: 0; height: 4px; background: var(--ok); transition: width 0.4s linear, background 0.3s; }
.seat-chip.s-ok { border-color: color-mix(in srgb, var(--ok) 40%, transparent); background: var(--ok-soft); }
.seat-chip.s-ok .time { color: var(--ok); }
.seat-chip.s-caution { border-color: color-mix(in srgb, var(--amber) 60%, transparent); background: var(--amber-soft); }
.seat-chip.s-caution .time { color: var(--amber); }
.seat-chip.s-caution .bar { background: var(--amber); }
.seat-chip.s-over { border-color: var(--red); background: var(--red-soft); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--red) 35%, transparent); }
.seat-chip.s-over .time { color: #ffd9da; }
.seat-chip.s-over .name { color: #fff; }
.seat-chip.s-over .bar { background: var(--red); }

/* 「いま自分が入れた卓」が分かるようにする。複数人で同時に触るため、
   自分の操作が反映されたかを目で追えないと同じ操作を二重に打つ。 */
.seat-chip.is-new { border-color: var(--brand-ink); animation: just-placed 1.1s ease-out 3; }
@keyframes just-placed {
  0%   { box-shadow: 0 0 0 0 color-mix(in srgb, var(--brand-ink) 80%, transparent); }
  70%  { box-shadow: 0 0 0 10px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}
@media (prefers-reduced-motion: reduce) {
  .seat-chip.is-new { animation: none; }
  .table-card.st-over::before { animation: none; }
}
.seat-chip.s-acked { border-color: var(--line-strong); background: var(--surface-2); }
.seat-chip.s-acked .time { color: var(--faint); }
.seat-chip.s-acked .bar { background: var(--faint); }
.badge {
  flex: none; font-size: 9.5px; font-weight: 700; letter-spacing: 0.04em;
  padding: 1px 6px; border-radius: 999px; line-height: 1.6;
  background: var(--brand-soft); color: var(--brand-ink); border: 1px solid color-mix(in srgb, var(--brand) 40%, transparent);
}
.badge.b-ack { background: transparent; color: var(--faint); border-color: var(--line-strong); }
.seat-empty {
  border: 1px dashed var(--line-strong); border-radius: 9px; padding: 6px 9px;
  color: var(--faint); font-size: 12px; text-align: left; width: 100%;
  transition: border-color 0.18s, color 0.18s, background 0.18s;
}
.seat-empty:active, .is-target .seat-empty { border-color: var(--brand); color: var(--brand-ink); }

.board-empty {
  grid-column: 1 / -1; text-align: center; padding: 44px 20px; color: var(--dim);
  background: var(--surface); border: 1px dashed var(--line-strong); border-radius: 13px;
}
.board-empty strong { display: block; font-size: 15px; color: var(--ink); margin-bottom: 4px; }
.board-empty span { font-size: 12.5px; }

/* ---------- 待機バー ---------- */
.waiting-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line-strong);
  padding: 8px 14px calc(10px + env(safe-area-inset-bottom));
}
.waiting-head { display: flex; align-items: center; gap: 8px; margin-bottom: 7px; }
.waiting-title { font-size: 11.5px; font-weight: 700; color: var(--dim); letter-spacing: 0.06em; }
.waiting-count { font-family: var(--mono); font-size: 11px; color: var(--faint); }
.preset-chips { margin-left: auto; display: none; gap: 5px; }
.preset-chips.is-visible { display: flex; }
.preset-chip {
  font-size: 11.5px; font-weight: 700; padding: 3px 10px; border-radius: 999px;
  border: 1px solid var(--line-strong); color: var(--dim); transition: all 0.15s;
}
.preset-chip[aria-pressed="true"] { background: var(--brand-soft); color: var(--brand-ink); border-color: color-mix(in srgb, var(--brand) 45%, transparent); }
.waiting-list { display: flex; gap: 7px; overflow-x: auto; scrollbar-width: none; }
.waiting-list::-webkit-scrollbar { display: none; }
.cast-pill {
  flex: none; padding: 7px 14px; border-radius: 999px; font-weight: 700; font-size: 13.5px;
  background: var(--surface-2); border: 1px solid var(--line-strong); color: var(--ink);
  transition: all 0.15s;
}
.cast-pill[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: #fff; }
/* 相手フロアを見ている間の待機リスト。押せないことを見た目でも示す */
.cast-pill:disabled { opacity: 0.5; cursor: default; }
/* 他フロアで接客中。押せないことが見た目で分かるようにする */
.cast-pill.is-elsewhere {
  background: transparent; border-style: dashed; border-color: var(--line-strong);
  color: var(--faint); cursor: default; display: inline-flex; align-items: center; gap: 6px;
}
.cast-pill.is-elsewhere .where {
  font-size: 10px; font-family: var(--mono); font-weight: 700;
  background: var(--surface-2); color: var(--dim); border-radius: 999px; padding: 1px 6px;
}
.waiting-empty { color: var(--faint); font-size: 12.5px; padding: 6px 2px; }

/* ---------- シート ---------- */
.sheet-wrap { position: fixed; inset: 0; z-index: 50; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(5, 4, 7, 0.55); animation: fade-in 0.2s; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: var(--surface); border-top: 1px solid var(--line-strong);
  border-radius: 16px 16px 0 0; padding: 14px 16px calc(18px + env(safe-area-inset-bottom));
  box-shadow: var(--shadow); animation: sheet-up 0.22s ease-out;
  max-height: 72vh; overflow-y: auto;
}
@media (min-width: 700px) { .sheet { left: 50%; right: auto; width: 420px; transform: translateX(-50%); border-radius: 16px; bottom: 24px; border: 1px solid var(--line-strong); } }
@keyframes sheet-up { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .sheet, .sheet-backdrop, .banner, .hint { animation: none; } }
.sheet h2 { margin: 0 0 2px; font-size: 15px; font-weight: 700; }
.sheet .sheet-sub { color: var(--dim); font-size: 12px; margin-bottom: 12px; }
.sheet-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.sheet-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.btn {
  display: flex; align-items: center; justify-content: center; gap: 7px;
  padding: 11px 14px; border-radius: 11px; font-weight: 700; font-size: 14px; width: 100%;
  background: var(--surface-2); border: 1px solid var(--line-strong); color: var(--ink);
  transition: background 0.15s, border-color 0.15s;
}
.btn:active { background: #2e2933; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-danger { color: #f2a0a3; border-color: color-mix(in srgb, var(--red) 45%, transparent); background: var(--red-soft); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--dim); }
.btn:disabled { opacity: 0.45; pointer-events: none; }

/* 設定 */
.settings-block { border-top: 1px solid var(--line); padding: 13px 0; }
.settings-block:first-of-type { border-top: none; }
.settings-block h3 { margin: 0 0 8px; font-size: 12px; font-weight: 700; color: var(--dim); letter-spacing: 0.05em; }
.field { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.field label { font-size: 12.5px; color: var(--dim); flex: none; width: 4.5em; }
.field input {
  flex: 1; min-width: 0; background: var(--bg); border: 1px solid var(--line-strong); border-radius: 9px;
  color: var(--ink); padding: 8px 10px; font: inherit; font-size: 13.5px;
}
.field input:focus { outline: none; border-color: var(--brand); }
.field .unit { color: var(--faint); font-size: 12px; }
.field-error { color: var(--red); font-size: 12px; margin: -3px 0 8px 4.8em; }
.cast-manage { display: flex; flex-wrap: wrap; gap: 6px; }
.cast-manage .cast-pill { display: inline-flex; align-items: center; gap: 7px; padding-right: 9px; }
.cast-manage .x { color: var(--dim); font-family: var(--mono); font-size: 12px; }
/* 手入力＝HP掲載NGのキャスト。取り込みで消えない分をひと目で分ける */
.cast-manage .cast-pill.is-manual { border-color: color-mix(in srgb, var(--brand) 50%, transparent); }
.cast-manage .src {
  font-size: 9.5px; font-weight: 700; padding: 0 5px; margin-left: 5px; border-radius: 999px;
  background: var(--brand-soft); color: var(--brand-ink); line-height: 1.7;
}

/* 名簿のまとめて入力。開いていないときは畳んでおき、普段の追加操作の邪魔をしない */
.bulk { margin-top: 10px; border-top: 1px solid var(--line); padding-top: 10px; }
.bulk > summary {
  cursor: pointer; list-style: none; font-size: 12.5px; font-weight: 700; color: var(--brand-ink);
  padding: 4px 0; user-select: none;
}
.bulk > summary::-webkit-details-marker { display: none; }
.bulk > summary::before { content: "▸ "; color: var(--faint); }
.bulk[open] > summary::before { content: "▾ "; }
.bulk textarea {
  /* 既定のままだと暗い画面に白い箱が浮く。入力欄と同じ見た目に揃える */
  width: 100%; box-sizing: border-box; resize: vertical;
  background: var(--bg); border: 1px solid var(--line-strong); border-radius: 9px;
  color: var(--ink); padding: 9px 10px; font: inherit; font-size: 13.5px; line-height: 1.7;
}
.bulk textarea:focus { outline: none; border-color: var(--brand); }
.bulk-row { display: flex; gap: 8px; margin-top: 8px; }
.bulk-row .btn { width: auto; flex: 1; }

/* トースト */
.toast {
  position: fixed; left: 50%; bottom: 140px; transform: translateX(-50%);
  background: var(--surface-2); border: 1px solid var(--line-strong); color: var(--ink);
  border-radius: 11px; padding: 9px 16px; font-size: 13px; font-weight: 500;
  box-shadow: var(--shadow); z-index: 60; animation: banner-in 0.2s;
  width: max-content; max-width: calc(100vw - 36px); text-align: center; line-height: 1.55;
}

/* 操作履歴 */
.hist-row {
  display: flex; gap: 8px; align-items: baseline;
  padding: 5px 0; border-bottom: 1px solid var(--line); font-size: 12.5px;
}
.hist-row:last-child { border-bottom: none; }
.hist-time { font-family: var(--mono); font-size: 11px; color: var(--faint); flex: none; }
.hist-text { min-width: 0; }
.hist-actor { margin-left: auto; flex: none; font-size: 11px; color: var(--faint); }
.hist-row.is-conflict .hist-text { color: var(--amber); }

/* 閲覧モード */
body.view-mode { padding-bottom: 16px; }
body.view-mode .waiting-bar, body.view-mode #settingsBtn { display: none; }
.view-note { margin: 0 14px 8px; color: var(--faint); font-size: 11.5px; }
