:root {
  --ink: #17202a;
  --muted: #617080;
  --line: #d7dee7;
  --paper: #f6f7f9;
  --panel: #ffffff;
  --chrome: #fbfcfe;
  --blue: #2458a6;
  --green: #1b7b61;
  --red: #b93b33;
  --field-vh: 100dvh;
  --floor-panel-top: 0px;
  --field-bottom-space: 76px;
}

body.spatial-page {
  overflow: hidden;
  background: #eef2f6;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  line-height: 1.5;
}

body.field-app {
  overflow-x: hidden;
}

.app-header {
  display: flex;
  justify-content: flex-start;
  gap: 14px;
  align-items: center;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: 56px;
  padding: 8px 16px;
  background: var(--chrome);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 8px rgba(23, 32, 42, 0.06);
}

.app-title {
  flex: 0 1 360px;
  min-width: 220px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  margin-left: auto;
}

.header-actions button {
  width: auto;
  white-space: nowrap;
}

.pwa-status {
  display: inline-flex;
  min-height: 32px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 10px;
  color: var(--muted);
  background: #fff;
  font-size: 12px;
  white-space: nowrap;
}

.pwa-status[data-state="ready"] {
  border-color: rgba(27, 123, 97, 0.34);
  color: var(--green);
  background: #eef9f5;
}

.pwa-status[data-state="blocked"] {
  border-color: rgba(185, 59, 51, 0.28);
  color: var(--red);
  background: #fff4f2;
}

h1, h2, h3, p { margin-top: 0; }
h1 { font-size: 16px; margin-bottom: 2px; }
h2 { font-size: 20px; }
h3 { font-size: 15px; margin: 16px 0 8px; }

.app-title p {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 0;
}

.menu-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.view-menu {
  position: relative;
}

.view-menu summary {
  width: auto;
  list-style: none;
  cursor: pointer;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 7px 10px;
  color: var(--ink);
  font-weight: 700;
}

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

.view-menu[open] summary,
.view-menu summary:hover {
  border-color: var(--line);
  background: #eef2f6;
}

.view-menu-panel {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 30;
  width: 240px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: #fff;
  box-shadow: 0 12px 28px rgba(23, 32, 42, 0.16);
}

.view-menu-panel label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  margin: 0;
  padding: 6px 8px;
  border-radius: 6px;
  color: var(--ink);
  cursor: pointer;
}

.view-menu-panel label:hover {
  background: #f1f4f8;
}

.view-menu-panel input {
  width: auto;
  padding: 0;
}

.layout {
  max-width: 1440px;
  margin: 0 auto;
  padding: 16px 20px 24px;
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 16px;
}

.span-all { grid-column: 1 / -1; }
.controls { grid-column: span 4; }
.is-hidden { display: none !important; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px 16px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

label {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin: 10px 0 4px;
}

input, select, textarea, button {
  width: 100%;
  font: inherit;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 10px;
  background: #fff;
  color: var(--ink);
}

a.button-link {
  display: inline-flex;
  width: auto;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--blue);
  border-radius: 6px;
  padding: 9px 12px;
  background: var(--blue);
  color: #fff;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}

a.button-link.secondary {
  background: #fff;
  color: var(--blue);
}

.spatial-topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 64px;
  padding: 8px 16px;
  border-bottom: 1px solid rgba(215, 222, 231, 0.92);
  background: rgba(251, 252, 254, 0.94);
  backdrop-filter: blur(12px);
}

.spatial-topbar h1 {
  margin-bottom: 2px;
}

.spatial-topbar p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 12px;
}

.spatial-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px;
}

.spatial-actions label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  padding: 7px 8px;
  color: var(--ink);
  white-space: nowrap;
}

.spatial-actions input {
  width: auto;
  padding: 0;
}

.spatial-actions button,
.spatial-actions .button-link {
  width: auto;
  min-height: 36px;
  padding: 7px 11px;
  white-space: nowrap;
}

.spatial-shell {
  position: fixed;
  inset: 64px 0 0;
  overflow: hidden;
}

.spatial-scene {
  position: absolute;
  inset: 0;
  cursor: grab;
  touch-action: none;
}

.spatial-scene:active {
  cursor: grabbing;
}

.spatial-scene canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.spatial-drawer {
  position: absolute;
  top: 18px;
  right: 18px;
  z-index: 10;
  width: min(360px, calc(100vw - 36px));
  max-height: calc(100vh - 118px);
  overflow: auto;
  border: 1px solid rgba(215, 222, 231, 0.95);
  border-radius: 8px;
  padding: 14px 16px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 12px 34px rgba(23, 32, 42, 0.15);
  backdrop-filter: blur(12px);
}

.spatial-detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 12px 0;
}

.spatial-detail-grid div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: #f8fafc;
}

.spatial-detail-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.spatial-detail-grid strong {
  display: block;
  font-size: 16px;
}

.risk-note {
  border-left: 3px solid var(--red);
  padding-left: 10px;
  color: var(--red);
}

.spatial-good-note {
  border-left: 3px solid #0ea5e9;
  padding-left: 10px;
  color: #0369a1;
  font-weight: 700;
}

.floor-link {
  margin-top: 8px;
}

.spatial-legend {
  position: absolute;
  left: 18px;
  bottom: 18px;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  max-width: calc(100vw - 36px);
  border: 1px solid rgba(215, 222, 231, 0.95);
  border-radius: 8px;
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 10px 28px rgba(23, 32, 42, 0.12);
}

.spatial-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
}

.legend-swatch {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 3px;
}

.legend-swatch.type-120 { background: #2458a6; }
.legend-swatch.type-80 { background: #1b7b61; }
.legend-swatch.top-score { background: #0ea5e9; }
.legend-swatch.depleted { background: #6b7280; }
.legend-swatch.context { background: #9aa3ad; }
.legend-swatch.risk { background: #b7791f; }
.legend-swatch.facility { background: #6f42c1; }

.floor-page {
  max-width: 1320px;
  margin: 0 auto;
  padding: 16px 20px 28px;
}

.field-page {
  padding-bottom: 108px;
}

.floor-controls {
  margin-bottom: 16px;
}

.field-toolbar {
  align-items: center;
}

.field-toolbar button {
  width: auto;
  min-width: 118px;
}

.field-toolbar button.active {
  background: var(--green);
  border-color: var(--green);
}

.selection-count {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  color: var(--muted);
  background: #f8fafc;
  font-size: 13px;
}

.floor-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}

.floor-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.floor-swatch {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 1px solid var(--line);
  border-radius: 3px;
}

.floor-board-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 8px;
  align-items: stretch;
  min-height: 520px;
}

.field-board-tools {
  display: grid;
  grid-template-columns: minmax(160px, 0.8fr) minmax(320px, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding-bottom: 2px;
}

.field-board-tools strong {
  display: block;
}

.field-board-tools span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.field-building-picker {
  display: grid;
  grid-template-columns: 36px minmax(92px, 0.7fr) minmax(128px, 1fr) minmax(120px, 0.9fr) 36px;
  gap: 6px;
  align-items: end;
  width: 100%;
  min-width: 0;
}

.field-building-picker label {
  margin: 0;
  min-width: 0;
}

.field-building-picker select {
  width: 100%;
  min-height: 36px;
  padding: 6px 8px;
}

.field-select-actions {
  display: grid;
  grid-template-columns: auto auto auto;
  gap: 8px;
  align-items: center;
  min-width: 0;
}

.field-board-tools button,
.field-select-actions button {
  width: auto;
  min-width: 112px;
}

.field-board-tools button.active {
  background: var(--green);
  border-color: var(--green);
}

.floor-board-viewport {
  position: relative;
  min-width: 0;
  overflow: auto;
  cursor: grab;
  overscroll-behavior: contain;
  touch-action: none;
}

.floor-board-viewport.is-panning {
  cursor: grabbing;
}

.floor-side-arrow {
  width: 36px;
  min-width: 36px;
  min-height: 36px;
  border-radius: 6px;
  padding: 0;
  font-size: 24px;
  line-height: 1;
  background: #fff;
  color: var(--blue);
}

.floor-side-arrow:hover:not(:disabled) {
  background: #edf4ff;
}

.floor-board {
  min-width: 760px;
}

.floor-room-menu {
  position: absolute;
  z-index: 10;
  width: 222px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
  box-shadow: 0 12px 28px rgba(23, 32, 42, 0.18);
}

.floor-room-menu strong {
  display: block;
  margin-bottom: 4px;
}

.floor-room-menu p {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
}

.floor-room-menu button {
  min-height: 34px;
  margin-top: 6px;
  padding: 6px 8px;
  font-size: 13px;
}

.floor-title {
  margin-bottom: 12px;
  text-align: center;
  font-size: 22px;
  font-weight: 800;
}

.floor-head,
.floor-row {
  display: grid;
  grid-template-columns: 86px minmax(0, 1fr);
}

.floor-row.focused {
  box-shadow: inset 0 0 0 3px rgba(36, 88, 166, 0.44);
}

.floor-head-grid,
.floor-rooms {
  display: grid;
  min-width: 0;
}

.floor-unit-head,
.floor-room-head,
.floor-label,
.floor-room {
  border: 1px solid #26323f;
  min-height: 42px;
}

.floor-unit-head,
.floor-room-head {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f7d765;
  font-weight: 800;
}

.floor-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}

.floor-label span,
.floor-room span {
  font-size: 11px;
}

.floor-room {
  display: flex;
  min-height: 48px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 0;
  color: var(--ink);
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
}

.floor-room em {
  display: inline-flex;
  min-width: 38px;
  justify-content: center;
  border-radius: 999px;
  margin-top: 2px;
  padding: 1px 6px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--blue);
  font-size: 11px;
  font-style: normal;
  font-weight: 800;
}

.floor-room small {
  color: inherit;
  font-size: 10px;
  opacity: 0.78;
}

.floor-room.active {
  position: relative;
  z-index: 1;
  outline: 3px solid var(--blue);
  outline-offset: -3px;
}

.floor-room.located {
  position: relative;
  z-index: 2;
  outline: 4px solid #0ea5e9;
  outline-offset: -4px;
  animation: located-pulse 0.42s ease-in-out infinite alternate;
}

@keyframes located-pulse {
  from {
    box-shadow: inset 0 0 0 0 rgba(14, 165, 233, 0.1);
  }

  to {
    box-shadow: inset 0 0 0 7px rgba(14, 165, 233, 0.24);
  }
}

.floor-room.best-visible em {
  background: #fff7f5;
  color: var(--red);
  box-shadow: 0 0 0 2px rgba(185, 59, 51, 0.22);
}

.floor-room.multi-selected,
.state-selected {
  position: relative;
  z-index: 2;
  outline: 4px solid var(--green);
  outline-offset: -4px;
}

.multi-select-mode .floor-room,
.floor-board.is-drag-selecting .floor-room {
  touch-action: none;
}

.multi-select-mode .floor-board-viewport {
  overscroll-behavior: contain;
}

.best-guide {
  position: absolute;
  z-index: 30;
  display: inline-flex;
  width: auto;
  min-width: 118px;
  min-height: 34px;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-color: rgba(185, 59, 51, 0.28);
  border-radius: 999px;
  padding: 7px 10px;
  background: rgba(255, 255, 255, 0.96);
  color: var(--red);
  box-shadow: 0 10px 24px rgba(23, 32, 42, 0.18);
}

.best-guide strong {
  font-size: 16px;
  line-height: 1;
}

.best-guide span {
  color: inherit;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.best-guide.is-hidden {
  display: none;
}

.tier-low,
.floor-swatch.floor-low {
  background: #fff200;
}

.tier-middle,
.floor-swatch.floor-middle {
  background: #f3b4bd;
}

.tier-high,
.floor-swatch.floor-high {
  background: #fff200;
}

.tier-mixed {
  background: repeating-linear-gradient(
    45deg,
    #fff200 0,
    #fff200 10px,
    #f3b4bd 10px,
    #f3b4bd 20px
  );
}

.state-taken,
.floor-swatch.floor-taken {
  background: #9aa3ad !important;
  color: #fff;
}

.state-supporting,
.floor-swatch.floor-supporting {
  background: #a7dcdd !important;
  color: #17202a;
}

.state-blocked {
  background: #b8b2ad !important;
  color: #17202a;
}

.state-mine {
  background: #d6e8ff !important;
  color: #163a73;
}

.state-single {
  background: #f6c3ca !important;
  color: #17202a;
}

.state-not-remaining,
.floor-swatch.floor-not-remaining {
  background: #eef1f4 !important;
  color: #617080;
}

.panel-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.rank-controls {
  display: grid;
  grid-template-columns: 160px minmax(220px, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}

.rank-list,
.mobile-list {
  display: grid;
  gap: 10px;
}

.rank-card {
  display: grid;
  grid-template-columns: 82px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
}

.rank-score {
  display: flex;
  min-height: 66px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: #eef5ff;
  color: var(--blue);
}

.rank-score strong {
  font-size: 22px;
  line-height: 1.1;
}

.rank-score span {
  color: var(--muted);
  font-size: 12px;
}

.rank-main strong,
.mobile-list-row strong {
  display: block;
}

.rank-main p,
.rank-main small,
.mobile-list-row span {
  display: block;
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.rank-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.rank-actions button,
.mobile-list-row button {
  width: auto;
  min-width: 76px;
  padding: 7px 8px;
  font-size: 12px;
}

.mobile-list-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
}

.mobile-list-row span {
  grid-column: 1;
}

.mobile-list-row button {
  grid-row: 1 / span 2;
  grid-column: 2;
}

.batch-bar {
  position: fixed;
  right: 14px;
  bottom: 78px;
  left: 14px;
  z-index: 45;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid rgba(215, 222, 231, 0.96);
  border-radius: 10px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 12px 30px rgba(23, 32, 42, 0.16);
  backdrop-filter: blur(12px);
}

.batch-bar strong {
  margin-right: auto;
}

.batch-bar button {
  width: auto;
  min-width: 104px;
  padding: 8px 10px;
}

.operation-toast {
  position: fixed;
  right: 14px;
  bottom: calc(148px + env(safe-area-inset-bottom));
  left: 14px;
  z-index: 70;
  border: 1px solid rgba(36, 88, 166, 0.24);
  border-radius: 10px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.98);
  color: var(--blue);
  box-shadow: 0 12px 30px rgba(23, 32, 42, 0.16);
  font-size: 13px;
  font-weight: 700;
  text-align: center;
}

.operation-toast[data-tone="conflict"] {
  border-color: rgba(185, 59, 51, 0.32);
  color: var(--red);
  background: #fff7f5;
}

.operation-toast.is-hidden {
  display: none;
}

.mobile-bottom-nav {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 44;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  min-height: calc(64px + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  border-top: 1px solid rgba(215, 222, 231, 0.96);
  background: rgba(251, 252, 254, 0.97);
  box-shadow: 0 -10px 24px rgba(23, 32, 42, 0.08);
  backdrop-filter: blur(12px);
}

.mobile-bottom-nav button {
  min-height: 64px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
}

.mobile-bottom-nav button.active {
  color: var(--blue);
  background: #eef5ff;
}

.offline-page {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 20px;
}

.offline-card {
  width: min(560px, 100%);
}

.offline-card h1 {
  font-size: 24px;
}

textarea {
  min-height: 128px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 13px;
}

button {
  background: var(--blue);
  color: #fff;
  border-color: var(--blue);
  font-weight: 700;
  cursor: pointer;
}

.app-header button,
.app-header .button-link {
  min-height: 36px;
  padding: 7px 11px;
}

button.secondary {
  background: #fff;
  color: var(--blue);
}

button:disabled {
  color: var(--muted);
  background: #eef1f4;
  border-color: var(--line);
  cursor: not-allowed;
}

.toolbar {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.hint {
  color: var(--muted);
  font-size: 13px;
}

.summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.metric {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.metric strong {
  display: block;
  font-size: 22px;
}

.heat-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 0.85fr);
  gap: 16px;
}

.heat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 10px;
}

.heat-card {
  min-height: 86px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  text-align: left;
}

.heat-card.active {
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(36, 88, 166, 0.14);
}

.is-user-blocked {
  color: var(--muted);
  background: #eef1f4 !important;
  border-color: #c8d0da !important;
  opacity: 0.74;
}

.is-mine {
  border-color: var(--green) !important;
  box-shadow: 0 0 0 2px rgba(27, 123, 97, 0.13);
}

.blocked-reason {
  margin: 6px 0 0;
  color: var(--red);
  font-size: 12px;
}

.heat-score {
  display: block;
  color: var(--blue);
  font-size: 22px;
  font-weight: 800;
}

.room-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
}

.room-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.room-card button,
td button {
  width: auto;
  min-width: 82px;
  padding: 7px 8px;
  font-size: 12px;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
}

.taken-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  border-top: 1px solid var(--line);
  padding: 8px 0;
}

.taken-row button {
  width: auto;
  min-width: 72px;
  padding: 6px 8px;
  font-size: 12px;
}

.score {
  color: var(--blue);
  font-weight: 800;
}

.is-user-blocked .score,
.is-user-blocked .heat-score {
  color: var(--muted);
}

.table-wrap {
  max-height: 480px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th, td {
  border-bottom: 1px solid var(--line);
  padding: 8px;
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  background: #eef2f6;
}

.trace-layout {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 16px;
  padding: 16px;
}

.review-layout {
  display: grid;
  grid-template-columns: 420px minmax(0, 1fr);
  gap: 16px;
  padding: 16px;
}

.trace-sidebar {
  position: sticky;
  top: 72px;
  align-self: start;
  max-height: calc(100vh - 88px);
  overflow: auto;
}

.review-sidebar {
  position: sticky;
  top: 72px;
  align-self: start;
  max-height: calc(100vh - 88px);
  overflow: auto;
}

.trace-sidebar textarea {
  min-height: 112px;
}

.review-sidebar textarea {
  min-height: 96px;
}

#traceOutput {
  min-height: 280px;
}

#reviewOutput {
  min-height: 260px;
}

.review-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.review-stats .metric {
  padding: 8px;
}

.review-stats .metric strong {
  font-size: 20px;
}

.role-counts {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.role-counts span {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 8px;
  color: var(--muted);
  background: #f8fafc;
  font-size: 12px;
}

.trace-stage-panel {
  overflow: auto;
  min-height: calc(100vh - 88px);
}

.review-stage-panel {
  min-height: calc(100vh - 88px);
}

.review-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 10px;
}

.review-stage {
  height: 68vh;
  min-height: 520px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.candidate-svg {
  display: block;
  width: 1800px;
  height: 1200px;
}

.candidate-box {
  cursor: pointer;
}

.candidate-box rect {
  fill-opacity: 0.12;
  stroke-width: 10;
  vector-effect: non-scaling-stroke;
}

.candidate-box text {
  fill: #17202a;
  font-size: 90px;
  font-weight: 800;
  pointer-events: none;
}

.candidate-box:hover rect,
.candidate-box.is-selected rect {
  fill-opacity: 0.28;
  stroke: var(--blue);
  stroke-width: 18;
}

.candidate-box.status-approved rect {
  fill-opacity: 0.32;
  stroke: var(--green);
}

.candidate-box.status-skipped {
  opacity: 0.32;
}

.candidate-list-wrap {
  max-height: 320px;
  overflow: auto;
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.candidate-list-wrap table {
  font-size: 12px;
}

.is-active-row td {
  background: #eef5ff;
}

.candidate-list-wrap tr {
  cursor: pointer;
}

.trace-stage {
  position: relative;
  background: #fff;
}

.trace-stage img,
.trace-stage canvas {
  position: absolute;
  inset: 0;
  display: block;
}

.trace-stage canvas {
  cursor: crosshair;
}

@media (max-width: 1000px) {
  .layout, .heat-layout { display: block; }
  .trace-layout,
  .review-layout { display: block; }
  .trace-sidebar,
  .review-sidebar { position: static; max-height: none; }
  .panel { margin-bottom: 16px; }
  .summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 1100px) {
  body.field-app {
    padding-bottom: calc(76px + env(safe-area-inset-bottom));
  }

  .field-app .app-header {
    min-height: 48px;
    padding: 7px 10px;
  }

  .field-app .header-actions a[href="spatial-board.html"] {
    display: none;
  }

  .field-app .header-actions .button-link {
    min-height: 32px;
    padding: 6px 9px;
    font-size: 12px;
  }

  .field-page {
    max-width: none;
    min-width: 0;
    padding: 8px 6px calc(88px + env(safe-area-inset-bottom));
  }

  .field-page .panel {
    max-width: 100%;
    min-width: 0;
    margin-bottom: 0;
    border-radius: 6px;
    padding: 8px;
  }

  .field-controls h2,
  .mobile-rank-panel h2,
  .mobile-list-panel h2 {
    margin-bottom: 8px;
    font-size: 18px;
  }

  .floor-board-panel {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    gap: 8px;
    height: max(340px, calc(var(--field-vh, 100dvh) - var(--floor-panel-top, 0px) - var(--field-bottom-space, 76px)));
    min-height: 0;
  }

  .field-board-tools {
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
  }

  .field-board-tools > div {
    grid-column: auto;
  }

  .field-board-title {
    display: none;
  }

  .field-building-picker {
    grid-template-columns: 32px minmax(72px, 0.72fr) minmax(120px, 1.28fr) 32px;
    gap: 5px;
  }

  .field-building-picker .building-step:first-child {
    grid-column: 1;
    grid-row: 1;
  }

  .field-building-picker .building-step:last-child {
    grid-column: 4;
    grid-row: 1;
  }

  .field-building-picker label:nth-of-type(1) {
    grid-column: 2;
    grid-row: 1;
  }

  .field-building-picker label:nth-of-type(2) {
    grid-column: 3;
    grid-row: 1;
  }

  .field-building-picker label:nth-of-type(3) {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .field-building-picker label {
    font-size: 11px;
  }

  .field-building-picker select {
    min-height: 34px;
    padding: 5px 6px;
    font-size: 12px;
  }

  .field-select-actions {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 66px;
    gap: 6px;
  }

  .field-board-tools .selection-count {
    min-height: 34px;
    padding: 0 6px;
    text-align: center;
    font-size: 12px;
  }

  .field-board-tools button {
    min-width: 0;
    padding: 7px 9px;
    font-size: 12px;
  }

  .floor-side-arrow {
    width: 32px;
    min-width: 32px;
    min-height: 34px;
    font-size: 22px;
  }

  .floor-board-viewport {
    -webkit-overflow-scrolling: touch;
    min-height: 0;
  }

  .floor-board {
    width: 100%;
    min-width: 0;
  }

  .floor-title {
    margin-bottom: 8px;
    font-size: 18px;
  }

  .floor-head,
  .floor-row {
    grid-template-columns: 48px minmax(0, 1fr);
  }

  .floor-unit-head,
  .floor-room-head,
  .floor-label,
  .floor-room {
    min-height: 40px;
    min-width: 0;
  }

  .floor-room {
    min-height: 52px;
    overflow: hidden;
    padding: 2px 1px;
  }

  .floor-room strong {
    font-size: 12px;
  }

  .floor-room span,
  .floor-label span {
    font-size: 9px;
    line-height: 1.25;
  }

  .floor-room em {
    min-width: 32px;
    padding: 0 5px;
    font-size: 10px;
  }

  .floor-room small {
    font-size: 9px;
  }

  .floor-room-menu {
    position: fixed;
    right: 8px;
    bottom: 74px;
    left: 8px !important;
    top: auto !important;
    width: auto;
    z-index: 60;
  }

  .rank-controls {
    grid-template-columns: 1fr 1.4fr;
  }

  .rank-card {
    grid-template-columns: 64px minmax(0, 1fr);
    align-items: start;
  }

  .rank-score {
    min-height: 58px;
  }

  .rank-score strong {
    font-size: 18px;
  }

  .rank-actions {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .rank-actions button {
    width: 100%;
    min-width: 0;
  }

  .batch-bar {
    bottom: calc(68px + env(safe-area-inset-bottom));
    flex-wrap: wrap;
  }

  .batch-bar strong {
    flex: 1 0 100%;
    margin-right: 0;
  }

  .batch-bar button {
    flex: 1 1 0;
    min-width: 0;
    font-size: 12px;
  }

  .operation-toast {
    bottom: calc(138px + env(safe-area-inset-bottom));
    font-size: 12px;
  }

  .app-title {
    flex-basis: auto;
  }

  .app-title p {
    display: none;
  }
}

@media (max-width: 760px) {
  .app-header { display: block; }
  .menu-bar,
  .header-actions { margin-top: 12px; }
  .view-menu-panel {
    position: static;
    width: 100%;
    margin-top: 8px;
  }
}
