/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #0e1117;
  color: #e0e0e0;
  height: 100%;
  overflow: hidden;
  touch-action: none; /* ブラウザデフォルトのスクロールを抑止 */
}
body { display: flex; flex-direction: column; height: 100dvh; }

/* ── Topbar ── */
#topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: #161b27;
  border-bottom: 1px solid #2a2f40;
  flex-shrink: 0;
  min-height: 42px;
}
#topbar h1 {
  font-size: 13px;
  font-weight: 600;
  color: #c8d8ff;
  letter-spacing: 0.04em;
  display: flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}
#topbar h1 i { font-size: 15px; }
#topbar h1 span { color: #5a7fff; }
.tb-sep { width: 1px; height: 18px; background: #2a2f40; flex-shrink: 0; }
.tb-btn {
  padding: 4px 8px;
  border-radius: 5px;
  border: 1px solid #2a2f40;
  background: transparent;
  color: #99a0b0;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
  flex-shrink: 0;
}
.tb-btn i { font-size: 14px; }
.tb-btn:hover:not(:disabled) { background: #1e2436; color: #e0e0e0; }
.tb-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.tb-btn:active:not(:disabled) { transform: scale(0.96); }
#topbar-right { margin-left: auto; display: flex; align-items: center; gap: 5px; }
.zoom-btn {
  width: 26px; height: 26px;
  border-radius: 4px;
  border: 1px solid #2a2f40;
  background: #0e1117;
  color: #6a7080;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  flex-shrink: 0;
}
.zoom-btn:hover { background: #1a2030; color: #c0c8d8; }
.zoom-btn:active { transform: scale(0.94); }

/* ── Layer Tabs ── */
#layer-tabs {
  display: flex;
  align-items: stretch;
  padding: 0 0 0 10px;
  background: #0e1117;
  border-bottom: 1px solid #2a2f40;
  flex-shrink: 0;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
#layer-tabs::-webkit-scrollbar { display: none; }
.layer-tab {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  font-size: 11px;
  color: #505870;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  transition: color 0.1s;
  user-select: none;
  flex-shrink: 0;
}
.layer-tab:hover { color: #8090a8; }
.layer-tab.active { color: var(--layer-color); border-bottom-color: var(--layer-color); }
.tab-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--layer-color); opacity: 0.5; }
.layer-tab.active .tab-dot { opacity: 1; }
.tab-count {
  font-size: 9px;
  background: #1a2030;
  padding: 1px 3px;
  border-radius: 3px;
  color: #505870;
}
.layer-tab.active .tab-count {
  background: color-mix(in srgb, var(--layer-color) 15%, transparent);
  color: var(--layer-color);
}
#layer-tabs-right { margin-left: auto; display: flex; align-items: center; gap: 3px; padding: 0 8px; flex-shrink: 0; }
.vis-label { font-size: 10px; color: #404858; margin-right: 2px; }
.vis-btn {
  width: 22px; height: 22px;
  border-radius: 3px;
  border: 1px solid #2a2f40;
  background: #131720;
  color: #6a7080;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
}
.vis-btn:hover { color: #c0c8d8; }
.vis-btn.on { background: #1a2a50; color: #8aafff; border-color: #2a3f7a; }

/* ── App layout ── */
#app {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

/* ── Sidebar (デスクトップ) ── */
#sidebar {
  width: 200px;
  min-width: 200px;
  border-right: 1px solid #2a2f40;
  display: flex;
  flex-direction: column;
  background: #131720;
  flex-shrink: 0;
}
#sidebar-header { padding: 8px 10px; border-bottom: 1px solid #2a2f40; }
#sidebar-header h2 {
  font-size: 10px;
  font-weight: 500;
  color: #6a7080;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 5px;
}
#search-box {
  width: 100%;
  padding: 5px 7px;
  font-size: 12px;
  border-radius: 4px;
  border: 1px solid #2a2f40;
  background: #0e1117;
  color: #c0c8d8;
}
#search-box::placeholder { color: #404858; }
#search-box:focus { outline: none; border-color: #3a4fff; }
#categories {
  flex: 1;
  overflow-y: auto;
  padding: 3px;
  scrollbar-width: thin;
  scrollbar-color: #2a2f40 transparent;
}
.cat-label {
  font-size: 9px;
  font-weight: 600;
  color: #404858;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 6px 5px 2px;
}
.building-group {
  width: 100%;
  min-width: 0;
}
.building-group-header {
  display: flex;
  align-items: center;
  gap: 5px;
  width: 100%;
  min-width: 0;
  min-height: 30px;
  padding: 5px 6px;
  border: none;
  border-radius: 4px;
  background: none;
  color: #68758c;
  cursor: pointer;
  font: inherit;
  font-size: 10px;
  font-weight: 600;
  text-align: left;
  touch-action: manipulation;
}
.building-group-header:hover { background: #1a2030; color: #aab4c8; }
.building-group-header:focus-visible { outline: 1px solid #3a4fff; outline-offset: -1px; }
.building-group-chevron::before { content: "▾"; display: block; width: 10px; }
.building-group.collapsed .building-group-chevron::before { content: "▸"; }
.building-group-title {
  min-width: 0;
  overflow-wrap: anywhere;
}
.building-group.collapsed .building-group-items { display: none; }
.building-group.collapsed.search-match .building-group-items { display: block; }
.building-group-items { min-width: 0; }
.building-group-items .building-btn { padding-left: 12px; }
.building-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 4px 6px;
  border-radius: 4px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 11px;
  color: #8090a8;
  text-align: left;
  transition: background 0.1s;
  touch-action: manipulation;
}
.building-btn:hover { background: #1a2030; color: #c0c8d8; }
.building-btn.selected { background: #1a2a50; color: #8aafff; border: 1px solid #2a3f7a; }
.b-icon { width: 20px; height: 20px; border-radius: 3px; display: flex; align-items: center; justify-content: center; font-size: 10px; flex-shrink: 0; }
.b-size { font-size: 9px; color: #404858; margin-left: auto; }
.b-layer-dot { width: 4px; height: 4px; border-radius: 50%; flex-shrink: 0; }

#tools {
  padding: 6px;
  border-top: 1px solid #2a2f40;
  display: flex;
  gap: 4px;
}
.tool-btn {
  flex: 1;
  padding: 5px 4px;
  font-size: 10px;
  border-radius: 4px;
  border: 1px solid #2a2f40;
  background: #0e1117;
  color: #6a7080;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  touch-action: manipulation;
}
.tool-btn i { font-size: 14px; }
.tool-btn:hover { background: #1a2030; color: #c0c8d8; }
.tool-btn.active { background: #1a2a50; color: #8aafff; border-color: #2a3f7a; }
.tool-btn:active { transform: scale(0.96); }

#sidebar-hint {
  padding: 5px 8px 6px;
  border-top: 1px solid #2a2f40;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
#sidebar-hint span {
  font-size: 9px;
  color: #404858;
}
#sidebar-hint kbd {
  background: #1a2030;
  border: 1px solid #2a2f40;
  border-radius: 2px;
  padding: 0 3px;
  font-size: 9px;
  color: #6a7080;
  font-family: monospace;
}

/* ── Canvas area ── */
#canvas-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}
#grid-canvas {
  flex: 1;
  overflow: hidden;
  position: relative;
  touch-action: none;
}
canvas#main-canvas { display: block; touch-action: none; }

/* ── ミニマップ ── */
#minimap-wrap {
  position: absolute;
  bottom: 8px;
  right: 8px;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid #2a2f40;
  box-shadow: 0 2px 8px rgba(0,0,0,0.6);
  cursor: crosshair;
  opacity: 0.85;
  transition: opacity 0.2s;
}
#minimap-wrap:hover { opacity: 1; }
#minimap-canvas { display: block; }

/* ── Status bar ── */
#info-bar {
  padding: 3px 10px;
  border-top: 1px solid #2a2f40;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 10px;
  color: #404858;
  background: #131720;
  flex-shrink: 0;
  overflow: hidden;
}
.info-item { display: flex; align-items: center; gap: 3px; white-space: nowrap; }
.info-item i { font-size: 11px; }
.info-layer { color: #6a7080; }
.info-selected { color: #5a6a80; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0; }
.info-hint { margin-left: auto; white-space: nowrap; flex-shrink: 0; }

/* ── Right panel ── */
#right-panel {
  width: 175px;
  min-width: 175px;
  border-left: 1px solid #2a2f40;
  background: #131720;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
}
#right-tabs { display: flex; border-bottom: 1px solid #2a2f40; }
.right-tab {
  flex: 1;
  padding: 6px 4px;
  font-size: 10px;
  color: #505870;
  cursor: pointer;
  text-align: center;
  border-bottom: 2px solid transparent;
}
.right-tab.active { color: #8aafff; border-bottom-color: #5a7fff; }
#right-content { flex: 1; overflow-y: auto; }
#panel-stats { padding: 7px; }
#panel-rooms { padding: 5px; }
.stat-card { background: #0e1117; border: 1px solid #2a2f40; border-radius: 5px; padding: 7px 9px; margin-bottom: 5px; }
.stat-name { font-size: 9px; color: #404858; margin-bottom: 1px; }
.stat-val  { font-size: 14px; font-weight: 600; color: #c8d8ff; }
.stat-sub  { font-size: 9px; color: #5a6a80; margin-top: 1px; }
.stat-ok   { color: #4aaa70; }
.stat-warn { color: #d08030; }

/* Room cards */
.room-card { border-radius: 4px; padding: 5px 7px; margin-bottom: 4px; border: 1px solid; cursor: pointer; }
.room-card:hover { opacity: 0.85; }
.room-card-header { display: flex; align-items: center; justify-content: space-between; }
.room-type-name { font-size: 10px; font-weight: 600; }
.room-size      { font-size: 9px; opacity: 0.7; }
.room-status    { font-size: 8px; padding: 1px 4px; border-radius: 3px; margin-top: 2px; display: inline-block; }
.room-ok      { background: rgba(74,170,112,0.15); color: #4aaa70; border-color: rgba(74,170,112,0.3); }
.room-warn    { background: rgba(208,128,48,0.15); color: #d08030; border-color: rgba(208,128,48,0.3); }
.room-invalid { background: rgba(80,80,100,0.2);  color: #6a7080; border-color: rgba(100,100,120,0.3); }
.room-detail  { font-size: 8px; color: #6a7080; margin-top: 2px; line-height: 1.4; }
#no-rooms { font-size: 10px; color: #404858; padding: 10px 6px; text-align: center; }

#legend { padding: 7px; border-top: 1px solid #2a2f40; }
.legend-title { font-size: 9px; font-weight: 600; color: #404858; text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 4px; }
.legend-item { display: flex; align-items: center; gap: 4px; font-size: 9px; color: #6a7080; margin-bottom: 2px; }
.legend-dot  { width: 7px; height: 7px; border-radius: 2px; flex-shrink: 0; }

/* ── Context menu ── */
#context-menu {
  position: absolute;
  background: #1a2030;
  border: 1px solid #2a3f7a;
  border-radius: 6px;
  padding: 4px;
  z-index: 200;
  display: none;
  min-width: 120px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
}
.ctx-item {
  padding: 7px 12px;
  font-size: 12px;
  color: #8090a8;
  cursor: pointer;
  border-radius: 3px;
  display: flex;
  align-items: center;
  gap: 7px;
  touch-action: manipulation;
}
.ctx-item i { font-size: 13px; }
.ctx-item:hover { background: #1a2a50; color: #c0c8d8; }
.ctx-item:active { background: #243060; }

/* ── Toast ── */
#toast {
  position: fixed;
  bottom: 70px;
  left: 50%;
  transform: translateX(-50%);
  background: #1a2a50;
  border: 1px solid #3a4fff;
  color: #8aafff;
  padding: 7px 16px;
  border-radius: 6px;
  font-size: 12px;
  display: none;
  z-index: 300;
  pointer-events: none;
}

/* ── Bottom bar (スマホ専用) ── */
#bottom-bar {
  display: none;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  background: #161b27;
  border-top: 1px solid #2a2f40;
  flex-shrink: 0;
  safe-area-inset-bottom: env(safe-area-inset-bottom);
  padding-bottom: max(6px, env(safe-area-inset-bottom));
}
#bottom-bar .tool-btn { flex: 1; min-width: 48px; padding: 6px 4px; font-size: 10px; flex-direction: column; }
#bottom-bar .tb-btn  { flex: 0 0 auto; padding: 6px 10px; }

/* ── Palette Drawer (スマホ専用) ── */
#palette-drawer {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 60vh;
  background: #131720;
  border-top: 1px solid #2a3f7a;
  border-radius: 12px 12px 0 0;
  z-index: 250;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.25s cubic-bezier(0.32, 0.72, 0, 1);
}
#palette-drawer.open { transform: translateY(0); }
#palette-drawer-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid #2a2f40;
}
#palette-drawer-header input {
  flex: 1;
  padding: 5px 8px;
  font-size: 13px;
  border-radius: 5px;
  border: 1px solid #2a2f40;
  background: #0e1117;
  color: #c0c8d8;
}
#palette-close {
  border: none;
  background: none;
  color: #6a7080;
  cursor: pointer;
  font-size: 18px;
  padding: 4px;
}
#categories-m {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 4px;
  -webkit-overflow-scrolling: touch;
}

/* ────────────────────────────────────────────
   レスポンシブ
──────────────────────────────────────────── */

/* タブレット (768px〜1024px) */
@media (max-width: 1024px) {
  #sidebar { width: 170px; min-width: 170px; }
  #right-panel { width: 150px; min-width: 150px; }
  .tb-label { display: none; }
  #topbar h1 span.subtitle { display: none; }
}

/* スマホ (〜767px) */
@media (max-width: 767px) {
  /* サイドバー・右パネルを非表示 */
  #sidebar      { display: none; }
  #right-panel  { display: none; }
  #layer-tabs   { font-size: 10px; }
  .layer-tab    { padding: 5px 8px; font-size: 10px; }
  .tab-count    { display: none; }
  .vis-label    { display: none; }
  #layer-tabs-right { gap: 2px; }

  /* ボトムバー表示 */
  #bottom-bar { display: flex; }

  /* パレットドロワー表示 */
  #palette-drawer { display: flex; }
  #categories-m .building-group-header { min-height: 44px; padding: 8px 10px; font-size: 12px; }
  #categories-m .building-group-items .building-btn { min-height: 40px; padding-left: 18px; }

  /* トースト位置調整 */
  #toast { bottom: 80px; }

  /* ミニマップを小さく */
  #minimap-wrap { opacity: 0.7; }

  /* ステータスバー簡略化 */
  .info-hint { display: none; }
  #active-layer-label { display: none; }
}

/* 横向きスマホ */
@media (max-width: 767px) and (orientation: landscape) {
  #bottom-bar { display: none; }
  #sidebar { display: flex; width: 160px; min-width: 160px; }
  #sidebar-hint { display: none; }
  #palette-drawer { display: none; }
}
