:root {
  --bg:        #F5F6F8;
  --surface:   #FFFFFF;
  --surface2:  #F0F1F4;
  --primary:   #00008B;
  --accent:    #FF0099;
  --accent-dim:rgba(255,0,153,0.08); /* アイコン背景色 */
  --accent-rim:rgba(255,0,153,0.25); /* アイコン枠色 */
  --primary-dim:rgba(0,0,139,0.10);  /* 自席背景色 (薄い青) */
  --primary-rim:rgba(0,0,139,0.25);  /* 自席枠色 */
  --fav:       #F5B700; /* ★アイコン色 / fav 卓の枠線 */
  --fav-dim:   #FFF4C2; /* fav 卓の塗り */
  --fav-active:#FFE98A; /* fav 卓のタップ時塗り */
  --fav-text:  #9A6B00; /* fav 卓の番号文字色 */
  --text:      #313131;
  --muted:     #6B7280;
  --border:    rgba(0,0,0,0.06);
  --border2:   rgba(0,0,0,0.10);
  --tab-h:     56px;
  --hdr-h:     44px;
}
/* -webkit-touch-callout(iOS Safari 長押しメニュー)の禁止*/
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; -webkit-touch-callout: none; }
html, body { height: 100%; overflow: hidden; background: var(--bg); }
body {
  font-family: 'Poppins', 'Hiragino Sans', 'Hiragino Kaku Gothic ProN', 'Noto Sans JP', Meiryo, sans-serif;
  color: var(--text);
  user-select: none; -webkit-user-select: none; /* テキスト選択不可 */
}

/* ── APP SHELL ── */
#app { height: 100vh; height: 100dvh; display: flex; flex-direction: column; }

/* ── HEADER ── */
header {
  height: var(--hdr-h); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; padding: 0 18px;
  background: var(--surface); border-bottom: none;
}
.hdr-award { height: 18px; width: auto; max-width: 100%; object-fit: contain; display: block; }

/* ── MAIN ── */
main { flex: 1; overflow: hidden; position: relative; }

/* ── NAV ── */
nav {
  height: var(--tab-h); flex-shrink: 0; display: flex;
  background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 3px;
  background: none; border: none; color: var(--muted);
  font-family: inherit; font-size: 10px; letter-spacing: 0.05em;
  cursor: pointer; transition: color 0.15s; padding-top: 4px;
}
.tab-ico { font-size: 20px; }
.tab.active { color: var(--accent); }
.tab.active .tab-lbl { font-weight: 700; } 

/* ── VIEWS ── */
/* 3 ビュー (search / map / favs) を横並びにし、data-active で transform 切替 */
.views-slider {
  display: flex; width: 300%; height: 100%;
  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
}
/* 1/3 の循環小数を割算式で渡し、ブラウザに正確計算させる (-66.6666% 等の丸めで favs 表示時に左端へマップが数px見切れる現象を回避) */
.views-slider[data-active="map"]  { transform: translateX(calc(-100% / 3)); }
.views-slider[data-active="favs"] { transform: translateX(calc(-200% / 3)); }
.view {
  width: calc(100% / 3); flex-shrink: 0; height: 100%;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
}
/* アクセシビリティ: 視差効果オフ時はスライドを瞬時に切替 */
@media (prefers-reduced-motion: reduce) {
  .views-slider { transition: none; }
}

/* ═══════════════════ SEARCH VIEW ═══════════════════ */
.search-bar {
  position: sticky; top: 0; z-index: 10;
  background: var(--surface); padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.search-inner { position: relative; }
.search-ico { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); font-size: 15px; pointer-events: none; color: var(--muted); }
#q {
  width: 100%; padding: 13px 44px 13px 44px;
  background: var(--surface2); border: 2px solid var(--border2);
  border-radius: 14px; color: var(--text); font-size: 14px;
  font-family: inherit; outline: none; appearance: none; -webkit-appearance: none; transition: border-color 0.15s;
  user-select: text; -webkit-user-select: text; /* 検索語のみ選択コピー可 */
}
#q:focus { border: 2px solid var(--primary); }
#q::placeholder { color: var(--muted); }
.search-clear { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); width: 28px; height: 28px; border-radius: 50%; border: none; background: var(--border2); color: var(--muted); font-size: 14px; cursor: pointer; display: none; align-items: center; justify-content: center; }
.search-clear.on { display: flex; }

/* 検索結果一括★ボタン: 検索バー内の入力下に配置、fav-btn と同じトグル挙動 (☆/★ 切替) */
.bulk-fav-btn {
  margin-top: 8px;
  width: 100%;
  padding: 8px 12px;
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: 10px;
  color: var(--muted);
  font-family: inherit;
  font-size: 12px;
  text-align: center;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.bulk-fav-btn[hidden] { display: none; }
.bulk-fav-btn::before { content: '☆ '; font-size: 16px; vertical-align: -1px; }
.bulk-fav-btn.on { color: var(--text); border-color: var(--border); }
.bulk-fav-btn.on::before { content: '★ '; color: var(--fav); }
.bulk-fav-btn:active { background: var(--border); }

.hint { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 48px 24px; gap: 10px; text-align: center; }
.hint-txt { font-size: 14px; color: var(--muted); line-height: 1.9; margin-bottom: 10px;}

/* 検索結果行: 行全体がマップ遷移ボタン（背景は .r-item のまま、.r-goto 独自背景は廃止） */
.r-item { display: flex; align-items: center; padding: 10px 5px; gap: 5px; border-bottom: 1px solid var(--border); cursor: pointer; transition: background 0.1s; }
.r-item:active { background: var(--surface2); }
.r-item:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.r-av { width: 36px; height: 36px; border-radius: 50%; background: var(--accent-dim); border: 1px solid var(--accent-rim); display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 600; color: var(--accent); flex-shrink: 0; letter-spacing: -0.05em; white-space: nowrap; }
.r-info { flex: 1; min-width: 0; }
.r-name { font-size: 14px; font-weight: 600; margin-bottom: 2px; display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.r-nick { font-size: 12px; color: var(--muted); font-weight: 400; }
.r-dept { font-size: 12px; color: var(--muted); }

/* テーブル番号表示コンテナ */
.r-goto { display: flex; align-items: baseline; justify-content: flex-end; gap: 6px; color: var(--primary); min-width: 90px; }
.r-tbl-label { font-size: 10px; font-weight: 500; }
/* テーブル番号の幅を揃える */
.r-tblnum { text-align: right; font-family: ui-monospace, 'SF Mono', Menlo, Consolas, 'DejaVu Sans Mono', monospace; font-size: 45px; font-weight: 600; line-height: 1; letter-spacing: -0.02em; }
.r-arrow { font-size: 18px; font-weight: 600; line-height: 1; opacity: 0.7; align-self: center; }
.empty { text-align: center; padding: 48px 20px; color: var(--muted); font-size: 13px; }

/* ★リスト用: r-item を左右反転表示 (children の HTML 順を逆にし、寄せ方向も反転) */
.r-item-rev .r-info { text-align: right; }
.r-item-rev .r-name { justify-content: flex-end; }
.r-item-rev .r-goto { justify-content: flex-start; }

/* 共通: 横スクロール pill フィルタバー — ★リスト / 会場マップで共有 */
.favs-filter, .map-filter {
  flex-shrink: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; gap: 6px;
  padding: 8px 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none; /* Firefox */
}
.favs-filter::-webkit-scrollbar, .map-filter::-webkit-scrollbar { display: none; }
/* 候補ゼロ時はバー自体を非表示 */
.favs-filter:empty, .map-filter:empty { display: none; }
/* favs 側だけ .view 内 sticky を残す (.map-filter は #v-map の flex column に乗せる) */
.favs-filter { position: sticky; top: 0; z-index: 10; }

/* 会場マップ側は左 padding を 0 に: ::before のグラデーション背景を左端まで延ばすため */
.map-filter { padding-left: 0; }

/* 左端の黄色★: 横スクロールでボタンが左に潜るほど surface 背景が濃くなり、滑らかにフェードアウト */
.map-filter::before {
  content: '★';
  position: sticky; left: 0;
  flex-shrink: 0;
  align-self: stretch;            /* バー高さ全体を覆い、上下余白も埋める */
  display: flex; align-items: center;
  padding: 0 28px 0 12px;         /* 左:★視覚余白 / 右:フェード幅 */
  color: var(--fav);
  font-size: 18px; line-height: 1;
  /* 左 60% は不透明 (ボタンを隠す) → 右 40% で transparent へグラデ */
  background: linear-gradient(to right, var(--surface) 60%, transparent);
  z-index: 1;
}

/* ub-goto と同じ pill 形 (padding/border-radius)、色はトグル状態で切替 */
.ff-btn {
  flex-shrink: 0;
  padding: 2px 10px;
  border-radius: 8px;
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  /* 非選択 */
  background: var(--surface);
  color: var(--muted);
  border: 1px solid var(--border2);
}
.ff-btn.on {
  /* 選択時: 枠線なし — レイアウトずれ防止に transparent border で寸法維持 */
  background: var(--primary);
  color: var(--surface);
  border: 1px solid transparent;
}

/* ═══════════════════ FAV BUTTON ═══════════════════ */
/* Common to all fav button */
.fav-btn {
  width: 32px; height: 32px; border-radius: 50%;
  background: none; border: none; cursor: pointer;
  font-family: inherit; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); transition: color 0.15s, transform 0.1s;
  padding: 0;
}
.fav-btn::before { content: '☆'; font-size: 20px; line-height: 1; }
.fav-btn.on { color: var(--fav); }
/* fav-btn 非表示時 (自分自身) に縦の並びを保つための同サイズ透明プレースホルダ */
.fav-btn-placeholder { width: 32px; height: 32px; flex-shrink: 0; }
.fav-btn.on::before { content: '★'; }
.fav-btn:active { transform: scale(1.2); }

/* ═══════════════════ MAP VIEW ═══════════════════ */
/* 常時レンダリングされるのでflex-column レイアウトで固定 */
#v-map { background: var(--bg); display: flex; flex-direction: column; }
.map-toolbar {
  flex-shrink: 0; padding: 10px 16px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}
.map-toolbar-title { font-size: 13px; color: var(--muted); flex: 1; }
.pdf-open-btn {
  font-size: 12px; padding: 7px 14px;
  background: var(--surface); color: var(--primary);
  border: 2px solid var(--primary); border-radius: 8px;
  font-family: inherit; cursor: pointer; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 5px;
}
.pdf-open-btn .ext-ico { width: 13px; height: 13px; display: inline-flex; }

/* .map-area: .map-wrap を内包する positioning context（.stage-pointer 配置用） */
.map-area { flex: 1; position: relative; display: flex; flex-direction: column; min-height: 0; }
/* native scroll */
.map-wrap {
  flex: 1; overflow: auto; position: relative;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x pan-y;
}
/* ステージ方向表示 */
.stage-pointer {
  position: absolute; top: 10px; z-index: 5;
  padding: 6px 16px; background: var(--primary); color: var(--surface);
  font-size: 12px; font-weight: 700; border-radius: 100px;
  font-family: inherit; border: none; cursor: pointer; white-space: nowrap;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.203);
  opacity: 1; transition: opacity 0.4s ease;
}
/* [hidden] のデフォルト display:none を打ち消してフェード */
.stage-pointer[hidden] { display: revert; opacity: 0; pointer-events: none; }
.stage-pointer.at-left { left: 10px; }
.stage-pointer.at-right { right: 10px; }
.stage-pointer.at-left::before,
.stage-pointer.at-right::after {
  display: inline-block; 
}
.stage-pointer.at-left::before {
  content: '◀︎'; margin-right: 4px;
  animation: stage-pointer-sway-left 1.2s ease-in-out infinite;
}
.stage-pointer.at-right::after {
  content: '▶︎'; margin-left: 4px;
  animation: stage-pointer-sway-right 1.2s ease-in-out infinite;
}
/* 左右矢印を振動 */
@keyframes stage-pointer-sway-left {
  0%, 100% { transform: translateX(0); }
  50%      { transform: translateX(-3px); }
}
@keyframes stage-pointer-sway-right {
  0%, 100% { transform: translateX(0); }
  50%      { transform: translateX(3px); }
}
/* 不可視時は揺らさない */
@media (prefers-reduced-motion: reduce) {
  .stage-pointer.at-left::before,
  .stage-pointer.at-right::after { animation: none; }
}
.map-inner {
  height: 100%; padding: 12px 8px 24px; box-sizing: border-box;
  width: max-content; margin-inline: auto; /* 横画面対応 */
}
.map-wrap svg { height: 100%; width: auto; display: block; }
.map-tbl { fill: #FFFFFF; stroke: var(--border2); stroke-width: 1; cursor: pointer; transition: fill 0.2s, stroke 0.2s; rx: 6; ry: 6; }
.map-tbl:active { fill: var(--surface2); }
.map-tbl.hl { fill: rgba(255,0,153,0.15); stroke: var(--accent); stroke-width: 2; }

.map-tbl.fav { fill: var(--fav-dim); stroke: var(--fav); stroke-width: 1.5; }
.map-tbl.fav:active { fill: var(--fav-active); }

.map-tbl.hl.fav { fill: var(--fav-dim); stroke: var(--accent); stroke-width: 2; }

/* 自席 (ログインユーザー): 常時 primary 色 */
/* fav/hl と重複時は背景のみ相手の色を採用、枠線・番号は primary を維持 */
.map-tbl.me { fill: var(--primary-dim); stroke: var(--primary); stroke-width: 2; }
.map-tbl.me.fav { fill: var(--fav-dim); stroke: var(--primary); stroke-width: 2; }
.map-tbl.me.hl { fill: rgba(255,0,153,0.15); stroke: var(--primary); stroke-width: 2; }
.map-tbl.me.hl.fav { fill: rgba(255,0,153,0.15); stroke: var(--primary); stroke-width: 2; }

.map-tbl-num { fill: var(--muted); font-size: 18px; font-weight: 700; text-anchor: middle; pointer-events: none; }
.map-tbl-num.hl { fill: var(--accent); }
.map-tbl-num.fav { fill: var(--fav-text); }
.map-tbl-num.hl.fav { fill: var(--accent); }
.map-tbl-num.me { fill: var(--primary); }
.map-tbl-num.me.fav { fill: var(--primary); }
.map-tbl-num.me.hl { fill: var(--primary); }
.map-tbl-num.me.hl.fav { fill: var(--primary); }
.map-label { fill: var(--muted); font-size: 10px; text-anchor: middle; pointer-events: none; }
.map-stage { fill: rgba(0,0,139,0.06); stroke: rgba(0,0,139,0.2); stroke-width: 1; rx: 6; ry: 6; }
.map-stage-label { fill: var(--primary); font-size: 13px; font-weight: 700; text-anchor: middle; letter-spacing: 0.15em; }

/* ═══════════════════ DETAIL OVERLAY ═══════════════════ */
#ov { position: fixed; inset: 0; z-index: 200; display: flex; flex-direction: column; justify-content: flex-end; opacity: 0; pointer-events: none; transition: opacity 0.2s; }
#ov.on { opacity: 1; pointer-events: all; }
.ov-bg { position: absolute; inset: 0; background: rgba(0,0,50,0.5); }
#panel {
  position: relative; background: var(--surface);
  border-radius: 22px 22px 0 0; max-height: 82vh;
  display: flex; flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
  transform: translateY(40px); transition: transform 0.25s cubic-bezier(0.32,0.72,0,1);
}
#ov.on #panel { transform: translateY(0); }
.panel-hdr { padding: 16px 20px 14px; border-bottom: 1px solid var(--border2); flex-shrink: 0; }
.panel-tbl-badge { display: flex; align-items: baseline; gap: 6px; margin-bottom: 4px; }
.panel-tbl-label { font-size: 13px; color: var(--muted); }
.panel-tbl-num   { font-size: 36px; font-weight: 700; color: var(--primary); line-height: 1; }
.panel-close { position: absolute; top: 14px; right: 14px; width: 40px; height: 40px; border-radius: 50%; background: var(--surface2); border: none; color: var(--muted); font-size: 14px; cursor: pointer; display: flex; align-items: center; justify-content: center; }

.members { overflow-y: auto; flex: 1; padding: 4px 0 12px; }
.m-item { display: flex; align-items: center; gap: 5px; border-bottom: 1px solid var(--border); padding: 11px 10px; }
.m-av { width: 40px; height: 40px; border-radius: 50%; background: var(--surface2); display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 600; color: var(--muted); flex-shrink: 0; letter-spacing: -0.05em; white-space: nowrap; }
.m-av.me    { background: var(--primary-dim); color: var(--primary); border: 1px solid var(--primary-rim); }
.m-av.focus { background: var(--accent-dim);  color: var(--accent);  border: 1px solid var(--accent-rim);  }
.m-body { margin-left: 10px; margin-right: 10px;}
.m-name { font-size: 14px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.m-nick { font-size: 12px; color: var(--muted); margin-top: 1px; }
.me-badge { font-size: 9px; font-weight: 700; background: var(--accent-dim); color: var(--accent); padding: 2px 6px; border-radius: 4px; border: 1px solid var(--accent-rim); white-space: nowrap; }
.m-dept { font-size: 10px; padding: 3px 7px; border-radius: 20px; background: var(--surface2); color: var(--muted); white-space: nowrap; flex-shrink: 0; margin-left: auto; }

/* ═══════════════════ USER BAR (header 直下に固定) ═══════════════════ */
/* #app の縦 flex 内で flex-shrink:0 にして header と main の間に常時固定 */
#user-bar {
  flex-shrink: 0;
  display: flex; align-items: center; gap: 10px;
  padding: 8px 14px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border2);
}
#user-bar[hidden] { display: none; }
.ub-info { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.ub-name { font-size: 13px; font-weight: 700; color: var(--text); }
.ub-nick { font-size: 11px; color: var(--muted); }
/* 自席ジャンプボタン: 検索結果の Table 表示を縮小したスタイル */
.ub-goto { display: inline-flex; align-items: baseline; gap: 4px; padding: 2px 10px;
  border: 1px solid var(--primary); border-radius: 8px;
  background: var(--surface); color: var(--primary);
  font-family: inherit; cursor: pointer; }
.ub-goto[hidden] { display: none; }
.ub-tbl-label { font-size: 9px; font-weight: 600; }
.ub-tblnum { font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: 18px; font-weight: 700; line-height: 1; letter-spacing: -0.02em; }
.ub-change { background: none; border: 1px solid var(--border2); color: var(--muted);
  font-family: inherit; font-size: 11px; padding: 4px 8px; border-radius: 6px; cursor: pointer; }

/* ═══════════════════ LOGIN MODAL ═══════════════════ */
/* 既存 #ov と同じ .on クラスで表示制御。bottom sheet ではなくセンターモーダル */
#login-ov { position: fixed; inset: 0; z-index: 300; display: flex;
  align-items: center; justify-content: center; padding: 20px;
  opacity: 0; pointer-events: none; transition: opacity 0.2s; }
#login-ov.on { opacity: 1; pointer-events: all; }
.login-bg { position: absolute; inset: 0; background: rgba(0,0,50,0.55); }
.login-modal {
  position: relative; background: var(--surface);
  width: 100%; max-width: 360px;
  border-radius: 16px; padding: 22px 20px 18px;
  display: flex; flex-direction: column; gap: 10px;
  max-height: calc(100dvh - 40px - env(safe-area-inset-bottom));
  transform: translateY(20px); transition: transform 0.25s cubic-bezier(0.32,0.72,0,1);
}
#login-ov.on .login-modal { transform: translateY(0); }
.login-title { font-size: 15px; font-weight: 700; color: var(--primary); }
.login-sub { font-size: 12px; color: var(--muted); }
#login-q {
  width: 100%; padding: 12px 14px;
  background: var(--surface2); border: 2px solid var(--border2);
  border-radius: 12px; color: var(--text); font-size: 14px;
  font-family: inherit; outline: none; appearance: none;
  user-select: text; -webkit-user-select: text;
}
#login-q:focus { border-color: var(--primary); }
.login-msg { font-size: 12px; color: var(--accent); min-height: 1em; }
/* モーダル右上の閉じるボタン */
.login-close {
  position: absolute; top: 8px; right: 8px;
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--surface2); border: none; color: var(--muted);
  font-size: 12px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}

/* 候補リスト本体: r-item をそのまま流用するためスクロール枠だけ用意 */
.login-results { max-height: 50vh; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.login-results:empty { display: none; }