/* ===== 全体レイアウト ===== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: "Hiragino Sans", "Noto Sans JP", sans-serif;
  overflow: hidden;
  background: #1a1d24;
  color: #e8eaed;
}

#canvas-container {
  position: fixed;
  inset: 0;
}

/* パネル共通のガラス風スタイル */
#app-title,
#list-panel,
#info-panel,
#add-form,
#room-form,
#help-bar {
  background: rgba(20, 24, 32, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(8px);
}

/* ===== 左上タイトル ===== */
#app-title {
  position: fixed;
  top: 16px;
  left: 16px;
  width: 250px;
  padding: 12px 16px;
  border-radius: 10px;
  pointer-events: none;
}

#app-title h1 {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

#app-title p {
  font-size: 10.5px;
  color: #9aa0a6;
  margin-top: 2px;
}

/* ===== 左側 一覧パネル ===== */
#list-panel {
  position: fixed;
  top: 92px;
  left: 16px;
  bottom: 64px;
  width: 250px;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ===== Space Overview (MVP-17: 空間全体の俯瞰) =====
 * details/summary/chevronは既存 .card-integrations パターンを踏襲するが、
 * 一覧パネル最上部専用のため別クラスとして定義する。
 */
.overview {
  flex-shrink: 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.overview-summary {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  list-style: none;
  padding: 12px 12px 10px;
  font-size: 12.5px;
  font-weight: 700;
  color: #e8eaed;
}

.overview-summary::-webkit-details-marker {
  display: none;
}

.overview-chevron {
  margin-left: auto;
  font-size: 11px;
  display: inline-block;
  transform: rotate(-90deg);
  transition: transform 0.18s;
}

.overview[open] .overview-chevron {
  transform: rotate(0deg);
}

.overview-body {
  padding: 0 12px 12px;
}

.overview-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.overview-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.05);
  color: #e8eaed;
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.overview-chip:hover {
  background: rgba(255, 255, 255, 0.1);
}

.overview-chip[aria-expanded="true"] {
  background: rgba(61, 90, 254, 0.22);
  border-color: #3d5afe;
}

.overview-chip-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

.overview-chip-label {
  font-weight: 600;
  white-space: nowrap;
}

.overview-chip-count {
  font-size: 11px;
  color: #9aa0a6;
}

.overview-empty {
  font-size: 12px;
  color: #9aa0a6;
  padding: 8px 2px 0;
}

.overview-empty[hidden] {
  display: none;
}

.overview-items {
  list-style: none;
  margin-top: 10px;
  max-height: 35vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.overview-items[hidden] {
  display: none;
}

.overview-item {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 7px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.12s;
}

.overview-item:hover {
  background: rgba(255, 255, 255, 0.06);
}

.overview-item-name {
  flex: 1;
  min-width: 0;
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.overview-item-detail {
  flex-shrink: 0;
  font-size: 10.5px;
  color: #9aa0a6;
}

/* 部屋切り替えバー */
#room-bar {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 12px 12px 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

#room-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex: 1;
  min-width: 0;
}

#room-manage {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

#room-manage button {
  width: 26px;
  height: 26px;
  font-size: 12px;
  line-height: 1;
  border-radius: 7px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.07);
  color: #bdc1c6;
  cursor: pointer;
  transition: background 0.15s;
}

#room-manage button:hover {
  background: rgba(255, 255, 255, 0.15);
}

#btn-room-delete:hover {
  background: rgba(244, 67, 54, 0.25);
  border-color: rgba(244, 67, 54, 0.5);
}

.room-chip {
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: transparent;
  color: #bdc1c6;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.room-chip:hover {
  background: rgba(255, 255, 255, 0.08);
}

.room-chip.active {
  background: #26a69a;
  border-color: #26a69a;
  color: #fff;
}

#filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 12px 12px 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.filter-chip {
  font-family: inherit;
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: transparent;
  color: #bdc1c6;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.filter-chip:hover {
  background: rgba(255, 255, 255, 0.08);
}

.filter-chip.active {
  background: #3d5afe;
  border-color: #3d5afe;
  color: #fff;
  font-weight: 600;
}

/* ===== Finder (MVP-14: 検索・絞り込み) ===== */
#finder-bar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

#finder-search {
  display: block;
  width: 100%;
  min-width: 0;
  padding: 7px 10px;
  font-family: inherit;
  font-size: 12px;
  color: #e8eaed;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 7px;
}

#finder-search::placeholder {
  color: #6b7075;
}

#finder-selects {
  display: flex;
  gap: 6px;
}

#finder-selects select {
  flex: 1;
  min-width: 0;
  padding: 6px 8px;
  font-family: inherit;
  font-size: 11px;
  color: #e8eaed;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 7px;
}

#finder-selects select option {
  background: #1f242e;
}

#finder-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

#finder-count {
  min-width: 0;
  font-size: 11px;
  color: #9aa0a6;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#btn-finder-clear {
  flex-shrink: 0;
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: transparent;
  color: #bdc1c6;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

#btn-finder-clear:hover {
  background: rgba(255, 255, 255, 0.08);
}

#btn-finder-clear[hidden] {
  display: none;
}

#object-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
  padding: 6px;
}

.obj-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background 0.12s;
}

.obj-item:hover {
  background: rgba(255, 255, 255, 0.06);
}

.obj-item.selected {
  background: rgba(61, 90, 254, 0.22);
  border-left-color: #3d5afe;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

.obj-item .obj-meta {
  min-width: 0;
}

.obj-name-row {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.obj-item .obj-name {
  min-width: 0;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 全部屋検索時、現在の部屋以外のObjectに表示する部屋名バッジ (MVP-14) */
.obj-room-badge {
  flex-shrink: 0;
  font-size: 9px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(61, 90, 254, 0.25);
  color: #aab4ff;
  white-space: nowrap;
}

/* warrantyFilter有効時だけ表示する保証バッジ (MVP-15)。色は main.js が --warranty-color で注入 */
.obj-warranty-badge {
  flex-shrink: 0;
  font-size: 9px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 999px;
  color: var(--warranty-color, #9e9e9e);
  background: color-mix(in srgb, var(--warranty-color, #9e9e9e) 22%, transparent);
  white-space: nowrap;
}

.obj-item .obj-sub {
  font-size: 10px;
  color: #9aa0a6;
  margin-top: 1px;
}

#object-list .list-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 24px 12px;
  text-align: center;
  font-size: 12px;
  color: #9aa0a6;
}

#object-list .list-empty-clear {
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: transparent;
  color: #bdc1c6;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

#object-list .list-empty-clear:hover {
  background: rgba(255, 255, 255, 0.08);
}

/* ===== アクションバー (追加 / エクスポート) ===== */
#action-bar {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

#action-bar button {
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 8px 10px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  transition: filter 0.15s;
}

#action-bar button:hover {
  filter: brightness(1.15);
}

#btn-add {
  flex: 1;
  background: #3d5afe;
  color: #fff;
}

#btn-export {
  background: rgba(255, 255, 255, 0.12);
  color: #e8eaed;
}

/* ===== 追加/編集フォーム (オブジェクト・部屋 共通) ===== */
#add-form,
#room-form {
  position: fixed;
  top: 92px;
  left: 282px;
  width: 260px;
  max-height: calc(100vh - 160px);
  overflow-y: auto;
  border-radius: 12px;
  padding: 16px;
}

#add-form h3,
#room-form h3 {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 12px;
}

/* 壁の方角チェックボックス */
.walls-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 8px;
  margin-bottom: 12px;
}

.walls-grid label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #e8eaed;
  cursor: pointer;
}

/* 編集時に変更不可のフィールド */
.form-field input:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.form-field {
  display: block;
  font-size: 11px;
  color: #9aa0a6;
  margin-bottom: 10px;
}

.form-field input,
.form-field select,
.form-field textarea {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 7px 9px;
  font-family: inherit;
  font-size: 13px;
  color: #e8eaed;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 7px;
  resize: vertical;
}

.form-field select option {
  background: #1f242e;
}

.form-group-label {
  font-size: 11px;
  color: #9aa0a6;
  margin: 4px 0 6px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 8px;
  margin-bottom: 10px;
}

.form-grid label {
  font-size: 10px;
  color: #9aa0a6;
}

.form-grid input {
  display: block;
  width: 100%;
  margin-top: 3px;
  padding: 6px 8px;
  font-family: inherit;
  font-size: 13px;
  color: #e8eaed;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 7px;
}

.form-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

.form-actions button {
  flex: 1;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 8px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
}

.form-actions button[type="submit"] {
  background: #3d5afe;
  color: #fff;
}

.form-actions button[type="button"] {
  background: rgba(255, 255, 255, 0.12);
  color: #e8eaed;
}

/* ===== 右側 情報パネル ===== */
#info-panel {
  position: fixed;
  top: 16px;
  right: 16px;
  width: 310px;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  border-radius: 12px;
}

#info-placeholder {
  padding: 32px 20px;
  text-align: center;
  color: #9aa0a6;
  font-size: 13px;
}

#info-card .card-header {
  padding: 18px 20px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.category-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  background: #2d4a76;
  color: #aecbfa;
}

/* status バッジ。色は main.js が --status-color で注入する */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--status-color, #9e9e9e);
  color: var(--status-color, #9e9e9e);
}

.status-badge::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--status-color, #9e9e9e);
}

/* Lifecycle バッジ (MVP-13)。status バッジ(丸ドット付き枠線)と区別するため
 * 塗りつぶし+角の小さい形にする。色は main.js が --lifecycle-color で注入。 */
.lifecycle-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 5px;
  color: var(--lifecycle-color, #9e9e9e);
  background: color-mix(in srgb, var(--lifecycle-color, #9e9e9e) 18%, transparent);
}

/* labels チップ */
.label-chips {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.label-chips li {
  font-size: 11px;
  padding: 2px 9px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  color: #c8ccd2;
  overflow-wrap: anywhere;
}

.lifecycle-badge[hidden],
.label-chips[hidden] {
  display: none;
}

#card-name {
  font-size: 18px;
  font-weight: 700;
}

/* ===== 情報カードの操作ボタン ===== */
.card-actions {
  display: flex;
  gap: 6px;
  padding: 10px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.card-actions button {
  flex: 1;
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  padding: 7px 4px;
  border-radius: 7px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.07);
  color: #e8eaed;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}

.card-actions button:hover {
  background: rgba(255, 255, 255, 0.14);
}

#btn-delete:hover {
  background: rgba(244, 67, 54, 0.25);
  border-color: rgba(244, 67, 54, 0.5);
}

/* 配置/移動モードのトグルボタン (有効時) */
.mode-toggle.active {
  background: #26a69a !important;
  border-color: #26a69a !important;
  color: #fff !important;
}

.object-id {
  font-size: 11px;
  color: #9aa0a6;
  font-family: "SF Mono", Menlo, monospace;
  margin-top: 4px;
}

.card-body {
  padding: 14px 20px;
}

.card-body dt {
  font-size: 11px;
  color: #9aa0a6;
  margin-top: 12px;
}

.card-body dt:first-child {
  margin-top: 0;
}

.card-body dd {
  font-size: 14px;
  margin-top: 2px;
  line-height: 1.5;
}

/* ===== 外部連携セクション (INTEGRATIONS レジストリから描画) =====
 * 連携先ごとの色は --accent で注入するため、連携を増やしても
 * このファイルへの追記は不要。
 */
.card-integrations {
  padding: 12px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.integrations-summary {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  list-style: none;
  font-size: 12px;
  color: #9aa0a6;
}

/* native の三角マーカーを消してシェブロンに置き換える */
.integrations-summary::-webkit-details-marker {
  display: none;
}

.integrations-title {
  font-weight: 600;
}

.integrations-count {
  font-size: 11px;
  color: #6b7280;
}

.integrations-chevron {
  margin-left: auto;
  font-size: 11px;
  /* inline 要素には transform が効かないため inline-block にする */
  display: inline-block;
  transform: rotate(-90deg);
  transition: transform 0.18s;
}

#card-integrations[open] .integrations-chevron {
  transform: rotate(0deg);
}

.integrations-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 10px;
}

.integration-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  border-left: 3px solid var(--accent, #9e9e9e);
  background: rgba(255, 255, 255, 0.06);
  color: #e8eaed;
  text-decoration: none;
  transition: background 0.15s;
}

.integration-link:hover {
  background: rgba(255, 255, 255, 0.12);
}

/* ラベルが余白を吸収するので、detail の有無に関わらず矢印が右端に来る */
.integration-label {
  flex: 1;
  font-size: 13px;
  font-weight: 600;
}

.integration-detail {
  min-width: 0;
  font-size: 11px;
  color: #9aa0a6;
  font-family: "SF Mono", Menlo, monospace;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.integration-arrow {
  color: var(--accent, #9e9e9e);
  font-weight: 700;
}

.integrations-summary:focus-visible,
.integration-link:focus-visible {
  outline: 2px solid #8ab4f8;
  outline-offset: 2px;
  border-radius: 6px;
}

/* ===== 管理情報 (購入時期 / 保証期限) ===== */
.card-profile {
  padding: 14px 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.card-profile h3 {
  font-size: 11px;
  font-weight: 600;
  color: #9aa0a6;
  margin-bottom: 8px;
}

.card-profile dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 14px;
  align-items: baseline;
}

.card-profile dt {
  font-size: 11px;
  color: #9aa0a6;
}

.card-profile dd {
  font-size: 14px;
}

/* 保証期限の派生chip (MVP-15)。expiring/expiredのみ表示。色は main.js が --warranty-color で注入 */
.warranty-chip {
  display: inline-block;
  margin-left: 8px;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  color: var(--warranty-color, #9e9e9e);
  background: color-mix(in srgb, var(--warranty-color, #9e9e9e) 18%, transparent);
}

.warranty-chip[hidden] {
  display: none;
}

/* 次回点検の派生chip (MVP-16)。expiring/expiredのみ表示。色は main.js が --maintenance-color で注入 */
.maintenance-chip {
  display: inline-block;
  margin-left: 8px;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  color: var(--maintenance-color, #9e9e9e);
  background: color-mix(in srgb, var(--maintenance-color, #9e9e9e) 18%, transparent);
}

.maintenance-chip[hidden] {
  display: none;
}

.form-hint {
  font-size: 10px;
  color: #7d838b;
  margin: -4px 0 10px;
}

/* ===== 紐づけレコード ===== */
.card-records {
  padding: 14px 20px 18px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.card-records h3 {
  font-size: 11px;
  font-weight: 600;
  color: #9aa0a6;
  margin-bottom: 10px;
}

#records-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.record-item {
  padding: 9px 11px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.record-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

.record-type {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 4px;
  background: rgba(61, 90, 254, 0.25);
  color: #aecbfa;
  flex-shrink: 0;
}

/* Workspace 種別は紫系で他と区別 */
.record-type[data-type="workspace"] {
  background: rgba(124, 77, 255, 0.28);
  color: #d0bcff;
}

.record-label {
  font-size: 12px;
  font-weight: 600;
  min-width: 0;
}

.record-target {
  font-size: 10px;
  color: #9aa0a6;
  font-family: "SF Mono", Menlo, monospace;
  margin-top: 4px;
}

.record-memo {
  font-size: 11px;
  color: #bdc1c6;
  margin-top: 2px;
  line-height: 1.45;
}

#records-empty {
  font-size: 12px;
  color: #6b7280;
}

/* ===== 配置/移動モードの案内バナー ===== */
#mode-banner {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  padding: 9px 20px;
  border-radius: 999px;
  background: #26a69a;
  color: #fff;
  font-size: 12.5px;
  font-weight: 600;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  pointer-events: none;
  white-space: nowrap;
}

/* フォーム内の配置モードトグル */
#btn-place-mode {
  display: block;
  width: 100%;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 8px;
  margin-bottom: 12px;
  border-radius: 8px;
  border: 1px dashed rgba(255, 255, 255, 0.3);
  background: rgba(255, 255, 255, 0.05);
  color: #bdc1c6;
  cursor: pointer;
  transition: background 0.15s;
}

#btn-place-mode:hover {
  background: rgba(255, 255, 255, 0.12);
}

/* ===== インポートダイアログ ===== */
#import-dialog {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
}

/* display: flex が hidden 属性に勝ってしまうのを防ぐ */
#import-dialog[hidden] {
  display: none;
}

.dialog-box {
  width: min(340px, calc(100vw - 32px));
  padding: 20px 22px;
  border-radius: 14px;
  background: #1f242e;
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}

.dialog-box h3 {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 10px;
}

#import-summary {
  font-size: 13px;
  line-height: 1.5;
  margin-bottom: 10px;
}

.dialog-note {
  font-size: 11px;
  color: #9aa0a6;
  line-height: 1.6;
  margin-bottom: 14px;
}

.dialog-actions {
  display: flex;
  gap: 8px;
}

.dialog-actions button {
  flex: 1;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 9px 4px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  transition: filter 0.15s;
}

.dialog-actions button:hover {
  filter: brightness(1.15);
}

#btn-import-overwrite {
  background: #e05252;
  color: #fff;
}

#btn-import-merge {
  background: #3d5afe;
  color: #fff;
}

#btn-import-cancel {
  background: rgba(255, 255, 255, 0.12);
  color: #e8eaed;
}

/* ===== 画面下 操作説明 ===== */
#help-bar {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 20px;
  padding: 10px 22px;
  border-radius: 999px;
  font-size: 12px;
  color: #bdc1c6;
  white-space: nowrap;
  pointer-events: none;
}

/* ===== モバイル専用要素 (デスクトップでは非表示) ===== */

#btn-drawer {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 15;
  width: 44px;
  height: 44px;
  font-size: 18px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(20, 24, 32, 0.88);
  color: #e8eaed;
  cursor: pointer;
  backdrop-filter: blur(8px);
}

#drawer-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 14;
  background: rgba(0, 0, 0, 0.45);
}

#drawer-backdrop.show {
  display: block;
}

#mini-card {
  display: none; /* モバイルのメディアクエリ内でのみ表示 */
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 12;
  align-items: center;
  gap: 10px;
  padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
  background: rgba(20, 24, 32, 0.94);
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(8px);
}

.mini-meta {
  flex: 1;
  min-width: 0;
}

#mini-name {
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#mini-sub {
  font-size: 11px;
  color: #9aa0a6;
  margin-top: 1px;
}

#btn-mini-detail {
  flex-shrink: 0;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 11px 18px;
  border-radius: 10px;
  border: none;
  background: #3d5afe;
  color: #fff;
  cursor: pointer;
}

#toast {
  position: fixed;
  bottom: 96px;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  z-index: 30;
  padding: 11px 20px;
  border-radius: 999px;
  background: #3d5afe;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
  white-space: nowrap;
}

#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ===== オフライン状態バナー ===== */
#offline-banner {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 25;
  padding: 8px 18px;
  border-radius: 999px;
  background: #b26a00;
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
}

/* シートのつまみ・閉じるボタン (モバイルのみ表示) */
.sheet-header {
  display: none;
  position: relative;
  padding: 10px 0 4px;
  justify-content: center;
}

.sheet-grabber {
  width: 38px;
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.25);
}

#btn-sheet-close {
  position: absolute;
  top: 6px;
  right: 10px;
  width: 36px;
  height: 36px;
  font-size: 15px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.1);
  color: #e8eaed;
  cursor: pointer;
}

/* ===== モバイルレイアウト ===== */
@media (max-width: 850px) {
  /* --- ヘッダー: ドロワーボタンの右に小さく --- */
  #btn-drawer {
    display: block;
  }

  #app-title {
    top: 12px;
    left: 64px;
    width: auto;
    max-width: calc(100vw - 80px);
    padding: 9px 14px;
  }

  #app-title h1 {
    font-size: 14px;
  }

  #app-title p {
    display: none;
  }

  #help-bar {
    display: none; /* タッチ操作はOrbitControls標準 (1本指回転/2本指ズーム移動) */
  }

  /* --- 左パネル: ドロワー化 --- */
  #list-panel {
    top: 0;
    left: 0;
    bottom: 0;
    width: min(80vw, 320px);
    border-radius: 0 14px 14px 0;
    z-index: 16;
    transform: translateX(-105%);
    transition: transform 0.25s ease;
  }

  #list-panel.open {
    transform: translateX(0);
  }

  /* タップしやすいサイズに拡大 */
  .obj-item {
    padding: 13px 10px;
  }

  .overview-summary {
    min-height: 44px;
    padding: 12px;
  }

  .overview-chip {
    padding: 8px 13px;
    font-size: 12.5px;
  }

  .room-chip {
    padding: 10px 14px;
  }

  .filter-chip {
    padding: 8px 13px;
    font-size: 12px;
  }

  /* Finder入力/セレクトのみ16px/44px (iOS自動ズーム防止・タップ域確保)。
     既存 .form-field の15pxはMVP-14のScope外として据え置く */
  #finder-search,
  #finder-selects select {
    font-size: 16px;
    min-height: 44px;
  }

  /* 保証select追加(MVP-15)で3個になったため、2+1で折り返して横スクロールを防ぐ */
  #finder-selects {
    flex-wrap: wrap;
  }

  #finder-selects select {
    flex: 1 1 calc(50% - 3px);
  }

  #btn-finder-clear {
    min-height: 44px;
    padding: 4px 14px;
  }

  #room-manage button {
    width: 38px;
    height: 38px;
    font-size: 15px;
  }

  #action-bar button {
    padding: 13px 10px;
    font-size: 13px;
  }

  /* --- 情報カード: 下部シート化 --- */
  #info-panel {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    max-height: 80vh;
    border-radius: 16px 16px 0 0;
    z-index: 18;
    transform: translateY(105%);
    transition: transform 0.28s ease;
    padding-bottom: env(safe-area-inset-bottom);
  }

  #info-panel.open {
    transform: translateY(0);
  }

  #info-placeholder {
    display: none; /* モバイルでは未選択時にシート自体を出さない */
  }

  .sheet-header {
    display: flex;
  }

  /* 操作ボタンをタップしやすく */
  .card-actions {
    gap: 8px;
    padding: 12px 16px;
  }

  .card-actions button {
    min-height: 46px;
    font-size: 13px;
  }

  /* 連携リンク・summary もタップしやすいサイズを確保 */
  .integrations-summary {
    min-height: 44px;
  }

  .integration-link {
    min-height: 44px;
  }

  /* --- 簡易カード --- */
  #mini-card:not([hidden]) {
    display: flex;
  }

  /* --- フォーム: 画面幅いっぱいに --- */
  #add-form,
  #room-form {
    top: 64px;
    left: 12px;
    right: 12px;
    width: auto;
    max-height: calc(100vh - 130px);
    z-index: 17;
  }

  /* フォーム入力もタップしやすく */
  .form-field input,
  .form-field select,
  .form-field textarea,
  .form-grid input {
    padding: 10px;
    font-size: 15px; /* iOSの自動ズームを防ぐため16px近く */
  }

  .form-actions button {
    padding: 13px;
    font-size: 13px;
  }

  /* --- オフラインバナー: 簡易カードと重ならない位置へ --- */
  #offline-banner {
    bottom: calc(96px + env(safe-area-inset-bottom));
  }

  /* --- モードバナー: ヘッダー下に折り返し表示 --- */
  #mode-banner {
    top: 64px;
    left: 12px;
    right: 12px;
    transform: none;
    white-space: normal;
    text-align: center;
    font-size: 11.5px;
    border-radius: 12px;
  }
}
