/* Plan view «Расстановка» — TurApps dark theme
   tokens: --bg #0e1116, --panel #171d27, --line #2a3342,
           --text #e8edf5, --muted #8b97a8, --accent #d4a017, --accent-2 #3d8bfd */

#layout-panel.layout-plan-panel {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  width: 100%;
  max-width: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg, #0e1116);
  color: var(--text, #e8edf5);
}

#layout-panel.layout-plan-panel.is-hidden {
  display: none;
}

/* Toolbar: room mm + grid + tools + hall button */
#layout-panel .layout-plan-toolbar {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--line, #2a3342);
  background: var(--panel, #171d27);
}

#layout-panel .layout-plan-toolbar label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 0;
  font-size: 12px;
  color: var(--muted, #8b97a8);
}

/* Hidden fallback inputs / controls inside toolbar */
#layout-panel .layout-plan-toolbar .is-hidden {
  display: none;
}

#layout-room-w,
#layout-room-d,
#layout-grid,
#layout-panel .layout-plan-toolbar input[type="number"],
#layout-panel .layout-plan-toolbar select {
  width: 112px;
  max-width: 100%;
  margin: 0;
  padding: 6px 8px;
  background: #10151c;
  border: 1px solid var(--line, #2a3342);
  border-radius: 6px;
  color: var(--text, #e8edf5);
}

#layout-room-w:focus,
#layout-room-d:focus,
#layout-grid:focus,
#layout-panel .layout-plan-toolbar input[type="number"]:focus,
#layout-panel .layout-plan-toolbar select:focus {
  outline: 2px solid var(--accent-2, #3d8bfd);
  outline-offset: 1px;
}

/* Alias if markup uses longer ids (same toolbar fields) */
#layout-panel #layout-room-width,
#layout-panel #layout-room-depth {
  width: 112px;
  max-width: 100%;
  margin: 0;
  padding: 6px 8px;
  background: #10151c;
  border: 1px solid var(--line, #2a3342);
  border-radius: 6px;
  color: var(--text, #e8edf5);
}

/* Grid as chips (buttons) when present beside / instead of select */
#layout-panel .layout-grid-chips,
#layout-panel [data-layout-grid-chips] {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

#layout-panel .layout-grid-chips button,
#layout-panel [data-layout-grid-chips] button {
  padding: 6px 10px;
  border: 1px solid var(--line, #2a3342);
  border-radius: 6px;
  background: #10151c;
  color: var(--text, #e8edf5);
  cursor: pointer;
  font-size: 12px;
  line-height: 1.2;
}

#layout-panel .layout-grid-chips button:hover,
#layout-panel [data-layout-grid-chips] button:hover {
  border-color: var(--accent, #d4a017);
}

#layout-panel .layout-grid-chips button.is-on,
#layout-panel .layout-grid-chips button.is-active,
#layout-panel [data-layout-grid-chips] button.is-on,
#layout-panel [data-layout-grid-chips] button.is-active {
  border-color: var(--accent, #d4a017);
  color: var(--accent, #d4a017);
}

/* Tool rail: one vertical column at the left of the plan */
#layout-panel .layout-tools {
  flex: 0 0 76px;
  width: 76px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  padding: 12px 8px;
  border-right: 1px solid var(--line, #2a3342);
  background: var(--panel, #171d27);
  box-sizing: border-box;
}

#layout-panel .layout-tool {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  margin: 0;
  padding: 8px 4px;
  min-height: 56px;
  border: 1px solid var(--line, #2a3342);
  border-radius: 10px;
  background: #10151c;
  color: var(--text, #e8edf5);
  cursor: pointer;
  font-size: 10px;
  line-height: 1.15;
  white-space: nowrap;
}

#layout-panel .layout-tool svg {
  width: 20px;
  height: 20px;
  display: block;
}

#layout-panel .layout-tool:hover {
  border-color: #f97316;
  box-shadow: 0 0 0 2px rgba(249, 115, 22, 0.35);
}

#layout-panel .layout-tool.is-on {
  border-color: #f97316;
  color: #c2410c;
  background: rgba(249, 115, 22, 0.14);
  box-shadow: 0 0 0 2px #f97316;
}

#layout-panel #btn-layout-hall {
  margin-left: 0;
  min-height: 36px;
  padding: 8px 14px;
  border-radius: 8px;
}

/* Body: canvas + selection sidebar */
#layout-panel .layout-plan-workspace {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: row;
  overflow: hidden;
}

#layout-plan-home {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
#layout-panel .layout-plan-canvas-wrap {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  position: relative;
  overflow: hidden;
}

#layout-panel .layout-plan-canvas-wrap > #layout-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* Canvas fills the growing column (direct child of workspace) */
#layout-panel .layout-plan-workspace > #layout-canvas {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
}

#layout-canvas {
  width: 100%;
  height: 100%;
  display: block;
  background: var(--bg-2, #151a22);
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#layout-canvas:active,
#layout-canvas.is-panning {
  cursor: grabbing;
}

/* Tool cursors (hover highlight is drawn on canvas, not CSS) */
#layout-canvas.layout-tool-wall,
#layout-canvas[data-layout-tool="wall"],
#layout-canvas.is-draw,
#layout-canvas[data-layout-mode="draw"] {
  cursor: crosshair;
}

#layout-canvas.is-place,
#layout-canvas[data-layout-mode="place"],
#layout-canvas[data-layout-tool="place"] {
  cursor: crosshair;
}

/* Rotation chips overlay: absolute over canvas, no hit area except chips */
#layout-overlays.layout-overlays {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 2;
}

#layout-overlays.layout-overlays .layout-rot-chip {
  pointer-events: auto;
}

.layout-rot-chip {
  position: absolute;
  display: inline-flex;
  gap: 2px;
  padding: 2px;
  border: 1px solid var(--line, #2a3342);
  border-radius: 6px;
  background: var(--panel, #171d27);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  /* left/top set by JS */
}

.layout-rot-chip button {
  margin: 0;
  width: 28px;
  height: 28px;
  padding: 0;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--text, #e8edf5);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.layout-rot-chip button svg {
  width: 16px;
  height: 16px;
}

.layout-rot-chip button:hover {
  color: var(--accent, #d4a017);
  background: rgba(212, 160, 23, 0.12);
}

/* Selection sidebar ~260px */
#layout-selection {
  flex: 0 0 260px;
  width: 260px;
  max-width: 100%;
  min-height: 0;
  overflow: auto;
  padding: 14px 16px;
  border-left: 1px solid var(--line, #2a3342);
  background: var(--panel, #171d27);
  color: var(--text, #e8edf5);
  box-sizing: border-box;
}

#layout-selection h2 {
  margin: 0 0 10px;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.3;
  color: var(--text, #e8edf5);
}

#layout-selection p {
  margin: 0 0 8px;
  font-size: 13px;
  line-height: 1.45;
}

#layout-selection .field-hint,
#layout-selection .muted,
#layout-selection .note {
  color: var(--muted, #8b97a8);
  font-size: 12px;
}

#layout-selection #btn-layout-detach,
#layout-selection #btn-layout-delete {
  display: block;
  width: 100%;
  box-sizing: border-box;
  margin-top: 8px;
}

.layout-rack-edit {
  margin: 0 0 8px;
}

.layout-rack-edit.is-hidden {
  display: none;
}

.layout-rack-name-label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 0 0 8px;
  font-size: 12px;
  color: var(--muted, #8b97a8);
}

#layout-rack-name {
  width: 100%;
  box-sizing: border-box;
}

.layout-rack-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 0 0 8px;
}

.layout-rack-actions .file-btn {
  width: 100%;
  box-sizing: border-box;
  margin: 0;
}

.layout-rack-actions #btn-layout-dup {
  grid-column: 1 / -1;
}

.layout-building {
  margin: 0 0 16px;
  padding: 0 0 14px;
  border-bottom: 1px solid var(--line, #2a3342);
}

.layout-building.is-hidden {
  display: none;
}

.layout-building-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 8px;
}

.layout-building-row input {
  flex: 1 1 auto;
  min-width: 0;
}

.layout-building-vis {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line, #2a3342);
  border-radius: 6px;
  background: #10151c;
  color: #64748b;
  cursor: pointer;
}

.layout-building-vis.is-on {
  color: var(--accent, #d4a017);
  border-color: var(--accent, #d4a017);
  background: rgba(212, 160, 23, 0.12);
}

.layout-building-vis-ico {
  width: 16px;
  height: 16px;
  display: block;
}
  margin-top: 8px;
}

/* Tab uses existing .tab.module-btn look; only hide when flagged */
.app-header #tab-layout.is-hidden {
  display: none;
}

/* Hall / edit modals: reuse .modal-back / .modal; layout-specific field grid only */
#layout-hall-modal .modal {
  max-width: 620px;
}

#layout-hall-modal .layout-hall-span {
  grid-column: 1 / -1;
}

#layout-hall-modal .layout-hall-hint {
  margin: 10px 0 0;
}

#layout-hall-modal #layout-hall-error:empty {
  display: none;
}

#layout-hall-col-custom.layout-hall-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 12px;
  margin: 0;
}
#layout-hall-col-custom.layout-hall-grid.is-hidden {
  display: none;
}

#layout-join-modal .modal {
  max-width: 420px;
}

#layout-hall-modal .layout-hall-grid,
#layout-edit-modal .layout-hall-grid,
#layout-edit-modal .layout-edit-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 12px;
}

#layout-hall-modal .layout-hall-grid label,
#layout-edit-modal .layout-hall-grid label,
#layout-edit-modal .layout-edit-grid label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 0;
  font-size: 12px;
  color: var(--muted, #8b97a8);
}

#layout-hall-modal .layout-hall-grid input,
#layout-hall-modal .layout-hall-grid select,
#layout-edit-modal .layout-hall-grid input,
#layout-edit-modal .layout-hall-grid select,
#layout-edit-modal .layout-edit-grid input,
#layout-edit-modal .layout-edit-grid select {
  width: 100%;
  margin: 0;
  padding: 6px 8px;
  box-sizing: border-box;
  background: #10151c;
  border: 1px solid var(--line, #2a3342);
  border-radius: 6px;
  color: var(--text, #e8edf5);
}

#layout-hall-modal .layout-hall-grid input:focus,
#layout-hall-modal .layout-hall-grid select:focus,
#layout-edit-modal .layout-hall-grid input:focus,
#layout-edit-modal .layout-hall-grid select:focus,
#layout-edit-modal .layout-edit-grid input:focus,
#layout-edit-modal .layout-edit-grid select:focus {
  outline: 2px solid var(--accent-2, #3d8bfd);
  outline-offset: 1px;
}

#layout-edit-modal .layout-edit-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 0 0 10px;
  font-size: 12px;
  color: var(--muted, #8b97a8);
}

#layout-edit-modal .layout-edit-row input {
  width: 100%;
  margin: 0;
  padding: 6px 8px;
  box-sizing: border-box;
  background: #10151c;
  border: 1px solid var(--line, #2a3342);
  border-radius: 6px;
  color: var(--text, #e8edf5);
}

.layout-dim-actions {
  position: absolute;
  display: inline-flex;
  gap: 2px;
  padding: 2px;
  border: 1px solid var(--line, #2a3342);
  border-radius: 6px;
  background: var(--panel, #171d27);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  pointer-events: auto;
}

.layout-dim-actions button {
  width: 26px;
  height: 26px;
  padding: 0;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--text, #e8edf5);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.layout-dim-actions button:hover {
  color: var(--accent, #d4a017);
  background: rgba(212, 160, 23, 0.12);
}

.layout-dim-actions button.is-danger:hover {
  color: #f87171;
}

.layout-col-grid-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 12px;
}

.layout-col-preset {
  margin: 0;
  padding: 6px 10px;
  border: 1px solid var(--line, #2a3342);
  border-radius: 6px;
  background: #10151c;
  color: var(--text, #e8edf5);
  cursor: pointer;
  font-size: 12px;
}

.layout-col-preset:hover {
  border-color: var(--accent, #d4a017);
}

.layout-col-preset.is-on {
  border-color: var(--accent, #d4a017);
  color: var(--accent, #d4a017);
  background: rgba(212, 160, 23, 0.12);
}

#layout-col-grid-custom.layout-hall-grid {
  margin-bottom: 12px;
}

#layout-col-grid-modal .layout-hall-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 14px;
  margin: 0 0 12px;
}

#layout-canvas.layout-tool-ruler,
#layout-canvas[data-layout-tool="ruler"],
#layout-canvas[data-layout-tool="route"] {
  cursor: crosshair;
}

/* Mobile: tools wrap; overlays stay absolute; sidebar under canvas */
@media (max-width: 720px) {
  #layout-panel .layout-plan-workspace {
    flex-direction: column;
  }

  #layout-panel .layout-plan-canvas-wrap {
    flex: 1 1 auto;
    min-height: 220px;
  }

  #layout-panel .layout-plan-workspace > #layout-canvas {
    flex: 1 1 auto;
    min-height: 0;
    height: auto;
  }

  #layout-selection {
    flex: 0 0 auto;
    width: 100%;
    max-height: 42%;
    border-left: none;
    border-top: 1px solid var(--line, #2a3342);
  }

  #layout-room-w,
  #layout-room-d,
  #layout-grid,
  #layout-panel .layout-plan-toolbar input[type="number"],
  #layout-panel .layout-plan-toolbar select {
    width: 96px;
  }

  #layout-panel .layout-tools {
    flex: 0 0 64px;
    width: 64px;
    flex-direction: column;
  }

  #layout-panel #btn-layout-hall {
    margin-left: 0;
  }

  #layout-overlays.layout-overlays {
    position: absolute;
    inset: 0;
  }

  #layout-hall-modal .layout-hall-grid,
  #layout-edit-modal .layout-hall-grid,
  #layout-edit-modal .layout-edit-grid {
    grid-template-columns: 1fr;
  }
}
