/* Plan mode — site workbook grid (replaces map canvas) */
body[data-app-mode="plan"] .object-rail,
body[data-app-mode="plan"] .map-viewport,
body[data-app-mode="plan"] .zoom-ctl,
body[data-app-mode="plan"] #btnFloor,
body[data-app-mode="plan"] #btnSheetImport,
body[data-app-mode="plan"] #btnMapDownload,
body[data-app-mode="plan"] #mapSelect,
body[data-app-mode="plan"] .compliance-panel,
body[data-app-mode="plan"] .compliance-rail {
  display: none !important;
}

body[data-app-mode="plan"] .map-body {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.plan-panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 0.75rem 1rem 1rem;
  gap: 0.35rem;
  overflow: hidden;
}

body[data-app-mode="plan"] .plan-panel {
  margin-left: 56px;
  padding: 0.35rem;
  padding-top: calc(10px + 38px + 8px);
  height: calc(100vh - 8px);
  max-height: calc(100vh - 8px);
  background: #f3f4f6;
}

.plan-panel[hidden] {
  display: none !important;
}

.plan-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  flex-shrink: 0;
}

.plan-tab-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  flex: 1;
  min-width: 0;
}

.plan-tab-btn {
  font: inherit;
  font-size: 0.78rem;
  padding: 0.25rem 0.55rem;
  border-radius: 4px;
  border: 1px solid #cbd5e1;
  background: #ffffff;
  color: #334155;
  cursor: pointer;
  white-space: nowrap;
}

.plan-tab-btn.is-active {
  background: #dbeafe;
  border-color: #60a5fa;
  color: #1e3a8a;
}

.plan-tab-btn.is-computed {
  opacity: 0.85;
  font-style: italic;
}

.plan-status-msg {
  font-size: 0.78rem;
  color: #64748b;
  min-width: 6rem;
}

.plan-toolbar-btn,
.plan-import-label {
  font: inherit;
  font-size: 0.78rem;
  padding: 0.25rem 0.55rem;
  border-radius: 4px;
  border: 1px solid #cbd5e1;
  background: #ffffff;
  color: #334155;
  cursor: pointer;
}

.plan-toolbar-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.plan-toolbar-icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
}

.plan-toolbar-icon-btn.is-active {
  background: #dbeafe;
  border-color: #60a5fa;
  color: #1e40af;
}

.plan-toolbar-icon {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.plan-format-bar {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
  padding: 0.2rem 0.35rem;
  background: #ffffff;
  border: 1px solid #dadce0;
  border-radius: 4px;
}

.plan-format-bar[hidden] {
  display: none !important;
}

.plan-format-bar:not(.plan-format-editable) .plan-format-edit-only {
  display: none !important;
}

.plan-format-freeze-wrap {
  position: relative;
}

.plan-freeze-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 90;
  min-width: 11rem;
  padding: 4px 0;
  background: #ffffff;
  border: 1px solid #dadce0;
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.plan-freeze-menu[hidden] {
  display: none !important;
}

.plan-freeze-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  font: inherit;
  font-size: 13px;
  padding: 6px 14px;
  border: none;
  background: transparent;
  color: #202124;
  cursor: pointer;
}

.plan-freeze-menu-item:hover {
  background: #f1f3f4;
}

.plan-freeze-menu-sep {
  height: 1px;
  margin: 4px 0;
  background: #dadce0;
}

.plan-format-group {
  display: flex;
  align-items: center;
  gap: 1px;
}

.plan-format-sep {
  width: 1px;
  height: 24px;
  background: #dadce0;
  margin: 0 0.15rem;
}

.plan-format-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: none;
  border-radius: 2px;
  background: transparent;
  color: #3c4043;
  cursor: pointer;
}

.plan-format-btn:hover {
  background: #f1f3f4;
}

.plan-format-btn.is-active {
  background: #e8f0fe;
  color: #1a73e8;
}

.plan-format-icon {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.plan-format-color-wrap {
  display: flex;
  align-items: center;
  gap: 1px;
}

.plan-format-color-btn {
  position: relative;
  flex-direction: column;
  height: 28px;
  padding-bottom: 2px;
}

.plan-format-color-bar {
  display: block;
  width: 16px;
  height: 3px;
  border-radius: 1px;
  margin-top: 1px;
}

.plan-format-color-bar-text {
  background: #000000;
}

.plan-format-color-bar-fill {
  background: #ffff00;
  border: 1px solid #dadce0;
}

.plan-format-color-input {
  position: absolute;
  width: 0;
  height: 0;
  opacity: 0;
  pointer-events: none;
}

.plan-format-clear-fill {
  width: 24px;
  height: 28px;
  color: #5f6368;
}

/* Dropdown cells: honor alignment from format toolbar */
.plan-grid-host .ag-cell.plan-align-center,
.plan-grid-host .ag-cell.plan-align-center .ag-cell-value {
  text-align: center;
}

.plan-grid-host .ag-cell.plan-align-right,
.plan-grid-host .ag-cell.plan-align-right .ag-cell-value {
  text-align: right;
}

.plan-grid-host .ag-cell.plan-align-left,
.plan-grid-host .ag-cell.plan-align-left .ag-cell-value {
  text-align: left;
}

.plan-grid-host .ag-cell.plan-align-center .plan-dropdown-cell {
  justify-content: center;
}

.plan-grid-host .ag-cell.plan-align-right .plan-dropdown-cell {
  justify-content: flex-end;
}

.plan-grid-host .ag-cell.plan-align-left .plan-dropdown-cell {
  justify-content: flex-start;
}

.plan-grid-scroll {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  background: #ffffff;
  border: 1px solid #b8b8b8;
  border-radius: 4px;
}

.plan-add-rows {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 6px 10px 12px;
  font-size: 13px;
  color: #374151;
  border-top: 1px solid #e5e7eb;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.06);
}

.plan-add-rows[hidden] {
  display: none !important;
}

.plan-add-rows-link {
  font: inherit;
  font-size: 13px;
  color: #1a73e8;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
}

.plan-add-rows-link:hover {
  text-decoration: underline;
}

.plan-add-rows-input {
  width: 3rem;
  padding: 2px 6px;
  font: inherit;
  font-size: 13px;
  color: #111827;
  border: 1px solid #dadce0;
  border-radius: 4px;
  text-align: center;
  background: #ffffff;
}

.plan-add-rows-label {
  color: #374151;
}

/* Grid fills the scroll area; ag-Grid owns vertical + horizontal scrolling internally. */
.plan-grid-scroll .plan-grid-host {
  flex: 1;
  min-height: 0;
  height: 100%;
  width: 100%;
  border: none;
}

.plan-grid-scroll .plan-grid-host .ag-root-wrapper {
  border: none;
  border-radius: 0;
}

/* Light spreadsheet grid (fallback when not in scroll wrapper) */
.plan-grid-host {
  flex: 1;
  min-height: 320px;
  height: 100%;
  width: 100%;
  background: #ffffff;
  --ag-background-color: #ffffff;
  --ag-foreground-color: #111827;
  --ag-secondary-foreground-color: #111827;
  --ag-disabled-foreground-color: #374151;
  --ag-header-background-color: #f9fafb;
  --ag-header-foreground-color: #111827;
  --ag-border-color: #cfcfcf;
  --ag-row-hover-color: #eef2ff;
  --ag-selected-row-background-color: #e0e7ff;
  --ag-input-focus-border-color: #3b82f6;
  --ag-font-size: 13px;
  color: #111827;
}

/* Default cell text colour comes from cellStyle (supports per-cell font colour). */
.plan-grid-host .ag-cell,
.plan-grid-host .ag-cell-value {
  color: inherit;
}

/* Black on white for inline editors (body is dark-themed globally). */
.plan-grid-host .ag-cell-editor,
.plan-grid-host .ag-input-field-input,
.plan-grid-host select {
  color: #111827 !important;
}

.plan-grid-host select,
.plan-grid-host .ag-input-field-input,
.plan-grid-host .ag-cell-editor {
  background-color: #ffffff !important;
}

.plan-grid-host select option {
  color: #111827;
  background-color: #ffffff;
}

/* Dropdown popups are rendered on document.body, outside the grid host. */
body[data-app-mode="plan"] .ag-popup,
body[data-app-mode="plan"] .ag-popup-child,
body[data-app-mode="plan"] .ag-select-list,
body[data-app-mode="plan"] .ag-list-item,
body[data-app-mode="plan"] .ag-select-list-item,
body[data-app-mode="plan"] .ag-select-list-item span,
body[data-app-mode="plan"] .ag-rich-select-list,
body[data-app-mode="plan"] .ag-rich-select-row,
body[data-app-mode="plan"] .ag-picker-field-display {
  color: #111827 !important;
  background-color: #ffffff;
}

body[data-app-mode="plan"] .ag-list-item.ag-active-item,
body[data-app-mode="plan"] .ag-select-list-item:hover,
body[data-app-mode="plan"] .ag-rich-select-row:hover {
  background-color: #eef2ff !important;
  color: #111827 !important;
}

/* Custom plan dropdown editor (Community edition). */
body[data-app-mode="plan"] .plan-dropdown-editor,
.plan-grid-host .plan-dropdown-editor {
  background: #ffffff;
  border: 1px solid #b0b0b0;
  border-radius: 4px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  min-width: 160px;
  max-width: 360px;
  padding: 4px;
  color: #111827;
}

.plan-dropdown-editor-filter {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid #d4d4d4;
  border-radius: 3px;
  padding: 4px 6px;
  font: inherit;
  font-size: 13px;
  color: #111827;
  background: #ffffff;
  margin-bottom: 4px;
}

.plan-dropdown-editor-list {
  max-height: 240px;
  overflow-y: auto;
}

.plan-dropdown-editor-item {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  color: #111827;
  font: inherit;
  font-size: 13px;
  line-height: 1.35;
  padding: 5px 8px;
  cursor: pointer;
  border-radius: 2px;
}

.plan-dropdown-editor-item:hover,
.plan-dropdown-editor-item.is-current,
.plan-dropdown-editor-item.is-keyboard-active {
  background: #eef2ff;
}

.plan-dropdown-editor-item.is-keyboard-active {
  outline: 1px solid #1a73e8;
  outline-offset: -1px;
}

.plan-grid-host .ag-root-wrapper {
  border-radius: 4px;
  border: 1px solid #b8b8b8;
  height: 100%;
  background: #ffffff;
}

.plan-grid-host .ag-header {
  border-bottom: 1px solid #b0b0b0;
}

.plan-grid-host .ag-header-cell {
  border-right: 1px solid #b0b0b0 !important;
  padding-left: 4px;
  padding-right: 4px;
}

.plan-grid-host .ag-header-cell-label {
  font-weight: 600;
  font-size: 12px;
  justify-content: center;
  width: 100%;
}

.plan-grid-host .ag-header-cell-text {
  text-align: center;
}

.plan-grid-host .ag-header-cell.plan-drop-col-header,
.plan-grid-host .ag-header-cell[col-id="plan-drop-col"] {
  background-color: #f3f4f6 !important;
  color: #6b7280 !important;
}

.plan-grid-host .ag-row.plan-title-row .ag-cell {
  font-weight: 600;
  background-color: #f9fafb;
}

.plan-grid-host .ag-row.plan-title-row .ag-cell.plan-drop-col-cell {
  background-color: #ffff00 !important;
}

.plan-grid-host .ag-header-cell.plan-drop-col-header .ag-header-cell-text,
.plan-grid-host .ag-header-cell[col-id="plan-drop-col"] .ag-header-cell-text {
  color: #111827 !important;
}

.plan-grid-host .ag-header-cell.plan-drop-col-header,
.plan-grid-host .ag-header-cell.plan-drop-col-header .ag-header-cell-label {
  justify-content: center;
}

.plan-grid-host .ag-cell.plan-drop-col-cell {
  text-align: center;
  justify-content: center;
}

.plan-grid-host .ag-cell.plan-drop-col-cell .ag-cell-value {
  text-align: center;
  width: 100%;
}

.plan-grid-host .ag-cell {
  border-right: 1px solid #d4d4d4 !important;
  border-bottom: 1px solid #d4d4d4 !important;
  line-height: 24px;
  padding-left: 4px;
  padding-right: 4px;
}

.plan-grid-host .ag-row {
  border: none;
}

.plan-grid-host .ag-center-cols-container .ag-row:last-child .ag-cell {
  border-bottom: 1px solid #d4d4d4 !important;
}

body[data-app-mode="plan"] .ag-rich-select-row.plan-dropdown-clear-option,
body[data-app-mode="plan"] .ag-list-item.plan-dropdown-clear-option {
  color: #6b7280 !important;
  font-style: italic;
}

/* Dropdown cells: subtle Sheets-like arrow (hover / focus only). */
.plan-grid-host .ag-cell .plan-dropdown-cell {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  min-height: 22px;
  margin: 0;
  padding: 0;
}

.plan-dropdown-cell-value {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 22px;
  padding-right: 12px;
  color: inherit;
}

.plan-dropdown-cell.plan-drop-centered .plan-dropdown-cell-value {
  text-align: center;
  padding-left: 12px;
}

.plan-dropdown-cell-btn {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 12px;
  height: 12px;
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 0;
  opacity: 1;
}

.plan-dropdown-cell-btn::before {
  content: "";
  display: block;
  width: 0;
  height: 0;
  margin: 4px auto 0;
  border-left: 3px solid transparent;
  border-right: 3px solid transparent;
  border-top: 4px solid #9ca3af;
}

.plan-dropdown-cell-btn:hover::before {
  border-top-color: #6b7280;
}

/* Cell range selection (Sheets-like drag select). Tint via inset shadow so cell fill colours show through. */
.plan-grid-host .ag-cell.plan-cell-range-selected:not(.ag-cell-focus) {
  box-shadow: inset 0 0 0 9999px rgba(59, 130, 246, 0.18);
}

.plan-grid-host .ag-body-viewport:not(.ag-has-focus) .ag-cell.plan-cell-range-selected {
  box-shadow: inset 0 0 0 9999px rgba(59, 130, 246, 0.18);
}

.plan-grid-host .ag-cell-range-selected:not(.ag-cell-focus),
.plan-grid-host .ag-body-viewport:not(.ag-has-focus) .ag-cell-range-selected {
  box-shadow: inset 0 0 0 9999px rgba(59, 130, 246, 0.18);
}

.plan-grid-host .ag-cell-focus {
  border: 2px solid #2563eb !important;
  /* Active cell keeps its fill; add a light tint like Google Sheets. */
  box-shadow: inset 0 0 0 9999px rgba(59, 130, 246, 0.12);
}

.plan-fill-handle {
  position: absolute;
  width: 8px;
  height: 8px;
  margin: 0;
  padding: 0;
  background: #2563eb;
  border: 1px solid #ffffff;
  box-sizing: border-box;
  cursor: crosshair;
  z-index: 6;
  pointer-events: auto;
  box-shadow: 0 0 0 1px rgba(37, 99, 235, 0.35);
}

.plan-grid-host .ag-cell.plan-cell-fill-preview:not(.ag-cell-focus) {
  box-shadow: inset 0 0 0 9999px rgba(34, 197, 94, 0.16);
}

.plan-grid-host .ag-body-viewport:not(.ag-has-focus) .ag-cell.plan-cell-fill-preview {
  box-shadow: inset 0 0 0 9999px rgba(34, 197, 94, 0.16);
}

/* Row selector column (Sheets-style grey gutter). */
.plan-grid-host .ag-header-cell.plan-row-select-header,
.plan-grid-host .ag-cell.plan-row-select-cell {
  background-color: #f3f4f6 !important;
  color: #6b7280 !important;
  border-right: 1px solid #d1d5db !important;
  text-align: center;
  cursor: pointer;
  user-select: none;
}

.plan-grid-host .ag-cell.plan-row-select-cell:hover {
  background-color: #e5e7eb !important;
}

.plan-grid-host .ag-row.plan-row-selected .ag-cell:not(.plan-row-select-cell) {
  box-shadow: inset 0 0 0 9999px rgba(59, 130, 246, 0.14);
}

.plan-grid-host .ag-row.plan-row-selected .ag-cell.plan-row-select-cell {
  background-color: #dbeafe !important;
  color: #1e40af !important;
}

.plan-row-menu {
  position: fixed;
  z-index: 80;
  min-width: 10rem;
  padding: 4px 0;
  background: #ffffff;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
}

.plan-row-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  font: inherit;
  font-size: 13px;
  padding: 6px 12px;
  border: none;
  background: transparent;
  color: #111827;
  cursor: pointer;
}

.plan-row-menu-item:hover:not(:disabled) {
  background: #eef2ff;
}

.plan-row-menu-item:disabled,
.plan-row-menu-item[hidden] {
  display: none;
}

.plan-grid-host .ag-header-cell {
  cursor: pointer;
}

.plan-grid-host .ag-header-cell.plan-row-select-header {
  cursor: default;
}

.plan-grid-host .ag-header-cell:not(.plan-row-select-header) {
  cursor: pointer;
  user-select: none;
}

.plan-grid-host .ag-header-cell.plan-col-header-selected {
  background-color: #d3e3fd !important;
  box-shadow: inset 0 -2px 0 #1a73e8;
}

/* Frozen (pinned left) columns and pinned top rows. */
.plan-grid-host .ag-pinned-left-header,
.plan-grid-host .ag-pinned-left-cols-container {
  z-index: 2;
}

.plan-grid-host .ag-pinned-left-header .ag-header-cell:last-child,
.plan-grid-host .ag-pinned-left-cols-container .ag-cell.ag-cell-last-left-pinned {
  box-shadow: 2px 0 5px rgba(0, 0, 0, 0.1);
}

.plan-grid-host .ag-floating-top,
.plan-grid-host .ag-pinned-left-floating-top {
  border-bottom: 1px solid #b0b0b0;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
  z-index: 3;
}

.plan-grid-host:focus {
  outline: none;
}
