/* Stage 127 / Task 80 — compact, collision-free map controls.
   Preserve original React controls and handlers; only normalize visual size/placement. */
:root {
  --saj-ui-rail-width: 188px;
  --saj-ui-action-height: min(24vh, 200px);
  --saj-ui-left: 8px;
}

/* The left rail is a backing surface. Functional controls stay above it. */
#saj-left-tools-panel-stage35 {
  left: var(--saj-ui-left) !important;
  top: 8px !important;
  bottom: 8px !important;
  width: var(--saj-ui-rail-width) !important;
  z-index: 9998 !important;
  pointer-events: none !important;
  overflow: visible !important;
}
#saj-left-tools-panel-stage35 .saj-left-tools-head {
  top: 6px !important;
  left: 6px !important;
  right: 6px !important;
  min-height: 29px !important;
  padding: 2px 4px !important;
  gap: 4px !important;
  border-radius: 9px !important;
  pointer-events: auto !important;
  z-index: 10030 !important;
}
#saj-left-tools-panel-stage35 .saj-left-tools-head > span {
  flex: 1 1 auto !important;
  max-width: 58px !important;
  min-width: 0 !important;
  font-size: 9px !important;
  line-height: 1.2 !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
}
#saj-left-tools-panel-stage35 .saj-left-tools-head #saj-global-gis-search-open {
  position: relative !important;
  inset: auto !important;
  display: inline-flex !important;
  flex: 0 0 36px !important;
  width: 36px !important;
  min-width: 36px !important;
  max-width: 36px !important;
  height: 26px !important;
  min-height: 26px !important;
  margin: 0 !important;
  padding: 0 3px !important;
  font: 700 8px/1.1 Tahoma,Arial,sans-serif !important;
  border-radius: 7px !important;
  box-shadow: none !important;
  z-index: auto !important;
}
#saj-left-tools-panel-stage35 .saj-left-tools-head button#saj-left-tools-toggle-stage35 {
  flex: 0 0 24px !important;
  width: 24px !important;
  height: 24px !important;
  min-height: 24px !important;
  border-radius: 7px !important;
  font-size: 14px !important;
}

/* Admin and block-validation shortcuts use the same compact left-rail alignment. */
body a[href="/admin"] {
  left: 17px !important;
  top: 46px !important;
  width: 162px !important;
  max-width: 162px !important;
  min-height: 29px !important;
  padding: 4px 6px !important;
  border-radius: 8px !important;
  font-size: 8.5px !important;
  line-height: 1.25 !important;
  z-index: 10016 !important;
}
#root button[title="اعتبارسنجی بلوک"] {
  left: 17px !important;
  top: 80px !important;
  width: 162px !important;
  min-width: 0 !important;
  height: 30px !important;
  min-height: 30px !important;
  padding: 3px 6px !important;
  border-radius: 8px !important;
  font-size: 8.5px !important;
  line-height: 1.25 !important;
  z-index: 10016 !important;
}

/* Satellite/base-map controls occupy only the reserved middle area.
   They scroll internally instead of slipping beneath the lower tools card. */
#root .saj-left-satellite-controls {
  position: fixed !important;
  left: 14px !important;
  right: auto !important;
  top: 116px !important;
  bottom: calc(142px + var(--saj-ui-action-height) + 12px) !important;
  width: 164px !important;
  min-width: 0 !important;
  max-height: none !important;
  box-sizing: border-box !important;
  padding: 4px !important;
  gap: 4px !important;
  overflow-x: hidden !important;
  overflow-y: auto !important;
  overscroll-behavior: contain !important;
  -webkit-overflow-scrolling: touch !important;
  align-items: stretch !important;
  z-index: 10018 !important;
  pointer-events: auto !important;
}
#root .saj-left-satellite-controls > button[title="نقشه پایه"],
#root .saj-left-satellite-controls > button[title="نمایش موقعیت من"] {
  flex: 0 0 33px !important;
  width: 100% !important;
  height: 33px !important;
  min-height: 33px !important;
  font-size: 16px !important;
  border-radius: 8px !important;
}
#root .saj-left-satellite-controls > div {
  position: relative !important;
  inset: auto !important;
  flex: 0 1 auto !important;
  width: 100% !important;
  min-width: 0 !important;
  max-width: 100% !important;
  max-height: min(20vh, 168px) !important;
  padding: 4px !important;
  overflow-x: hidden !important;
  overflow-y: auto !important;
  border-radius: 8px !important;
  box-sizing: border-box !important;
}
#root .saj-left-satellite-controls > div > button {
  width: 100% !important;
  min-width: 0 !important;
  min-height: 28px !important;
  height: auto !important;
  padding: 4px 6px !important;
  font-size: 8.5px !important;
  line-height: 1.25 !important;
  border-radius: 7px !important;
  white-space: normal !important;
}

/* Export-path and GIS-history actions are docked at the bottom of the same rail.
   Their scroll area is bounded, and the satellite control area ends above it. */
#saj-map-tool-actions-stage74 {
  position: absolute !important;
  left: 8px !important;
  right: auto !important;
  top: auto !important;
  bottom: 142px !important;
  width: 164px !important;
  max-width: calc(100% - 16px) !important;
  height: var(--saj-ui-action-height) !important;
  max-height: var(--saj-ui-action-height) !important;
  min-height: 0 !important;
  padding: 0 !important;
  gap: 4px !important;
  display: flex !important;
  flex-direction: column !important;
  align-items: stretch !important;
  justify-content: flex-end !important;
  overflow-x: hidden !important;
  overflow-y: auto !important;
  overscroll-behavior: contain !important;
  -webkit-overflow-scrolling: touch !important;
  box-sizing: border-box !important;
  border: 0 !important;
  border-radius: 0 !important;
  background: transparent !important;
  z-index: 10020 !important;
  pointer-events: none !important;
}
#saj-project-device-export {
  pointer-events: auto !important;
  padding: 5px !important;
  gap: 3px !important;
  border-radius: 8px !important;
  font-size: 8px !important;
}
#saj-project-device-export .saj-device-export-head strong { font-size: 8.5px !important; }
#saj-project-device-export button,
#saj-project-device-export #saj-device-export-project {
  min-height: 28px !important;
  padding: 4px 5px !important;
  font-size: 8px !important;
  line-height: 1.25 !important;
}
#saj-project-device-export .saj-device-export-folder-label,
#saj-project-device-export .saj-device-export-description,
#saj-project-device-export .saj-device-export-hint,
#saj-project-device-export .saj-device-export-status { font-size: 8px !important; }
#saj-history-widget { gap: 4px !important; pointer-events: auto !important; }
#saj-history-trigger {
  min-height: 29px !important;
  padding: 5px 7px !important;
  border-radius: 8px !important;
  font-size: 8.5px !important;
  line-height: 1.3 !important;
}

/* Rotation control is given a distinct lower slot, below the new search button
   (which is docked into the rail header) and clear of the action card. */
#rotation-knob {
  left: 70px !important;
  right: auto !important;
  top: auto !important;
  bottom: 96px !important;
  width: 40px !important;
  height: 40px !important;
  min-width: 40px !important;
  min-height: 40px !important;
  z-index: 10022 !important;
}
#rotation-knob svg { width: 18px !important; height: 18px !important; }
#saj-pr-open,
#saj-archive-open {
  left: 17px !important;
  right: auto !important;
  width: 162px !important;
  max-width: 162px !important;
  min-height: 30px !important;
  height: auto !important;
  padding: 5px 6px !important;
  border-radius: 8px !important;
  font-size: 8.5px !important;
  line-height: 1.25 !important;
  z-index: 10022 !important;
}
#saj-pr-open { bottom: 54px !important; }
#saj-archive-open { bottom: 18px !important; }

/* The main pencil/editing palette: scale down icons, text and spacing while
   preserving a >=36px activation area for touch. */
#root #jnaf-editing-toolbar-stage13,
#root div[style*="z-index: 10003"][style*="width: 100%"] {
  gap: 4px !important;
  padding: 4px !important;
  border-radius: 10px !important;
  scrollbar-width: thin !important;
}
#root #jnaf-editing-toolbar-stage13 > div,
#root div[style*="z-index: 10003"][style*="width: 100%"] > div { gap: 3px !important; padding: 1px !important; }
#root #jnaf-editing-toolbar-stage13 > div > div,
#root div[style*="z-index: 10003"][style*="width: 100%"] > div > div { gap: 3px !important; }
#root #jnaf-editing-toolbar-stage13 button,
#root div[style*="z-index: 10003"][style*="width: 100%"] button {
  box-sizing: border-box !important;
  min-width: 36px !important;
  min-height: 36px !important;
  padding: 4px 6px !important;
  border-radius: 8px !important;
  font-size: 8.5px !important;
  line-height: 1.2 !important;
  gap: 3px !important;
}
#root #jnaf-editing-toolbar-stage13 button svg,
#root div[style*="z-index: 10003"][style*="width: 100%"] button svg {
  width: 11px !important;
  height: 11px !important;
  flex: 0 0 11px !important;
}
#root #jnaf-editing-toolbar-stage13 select,
#root div[style*="z-index: 10003"][style*="width: 100%"] select {
  min-height: 32px !important;
  height: 32px !important;
  padding: 3px 5px !important;
  font-size: 8.5px !important;
  border-radius: 7px !important;
}
#root #jnaf-editor-split-toolbar-button-stage13 { min-height: 36px !important; min-width: 40px !important; padding: 4px 7px !important; }
#root #jnaf-editor-split-toolbar-button-stage13 svg { width: 11px !important; height: 11px !important; }

/* Layer drawer and its controls are compact without shrinking touch hit areas. */
#root #jnaf-tools-layers-drawer-stage13,
#root #jnaf-tools-layers-drawer-stage13[data-stage13-open="true"] {
  width: min(236px, 26vw) !important;
  max-width: calc(100vw - 16px) !important;
  border-radius: 15px !important;
}
#root #jnaf-tools-layers-drawer-stage13 > div:first-child { min-height: 66px !important; padding-top: 8px !important; padding-bottom: 7px !important; }
#root #jnaf-tools-layers-drawer-stage13 > div:first-child h2 { font-size: 13px !important; line-height: 1.3 !important; }
#root #jnaf-tools-layers-drawer-stage13 > div:not(:first-child) { gap: 5px !important; padding: 6px !important; }
#root #jnaf-tools-layers-drawer-stage13 button {
  min-height: 33px !important;
  padding: 4px 6px !important;
  border-radius: 8px !important;
  font-size: 8.5px !important;
  line-height: 1.25 !important;
}
#root #jnaf-tools-layers-drawer-stage13 button svg { width: 12px !important; height: 12px !important; }
#root button#jnaf-layers-drawer-collapse-stage13 { width: 32px !important; min-width: 32px !important; height: 32px !important; min-height: 32px !important; }
#root button[title="منوی ابزارها و مدیریت لایه‌ها"],
#root button[title="نوار ابزار ویرایش و ترسیم"] {
  width: 40px !important;
  min-width: 40px !important;
  height: 40px !important;
  min-height: 40px !important;
}
#root button[title="منوی ابزارها و مدیریت لایه‌ها"] svg,
#root button[title="نوار ابزار ویرایش و ترسیم"] svg { width: 17px !important; height: 17px !important; }

/* Stable stacking: the backing rail is never allowed to cover a functional control. */
#saj-left-tools-panel-stage35 { isolation: auto !important; }
#saj-left-tools-panel-stage35 .saj-left-tools-head,
#root .saj-left-satellite-controls,
#saj-map-tool-actions-stage74,
#rotation-knob,
#saj-pr-open,
#saj-archive-open { pointer-events: auto !important; }
body.saj-left-tools-collapsed #saj-global-gis-search-open { display: none !important; }

@media (max-width: 520px) {
  :root { --saj-ui-rail-width: 184px; --saj-ui-action-height: min(24vh, 176px); --saj-ui-left: 6px; }
  #saj-left-tools-panel-stage35 { left: 6px !important; width: 184px !important; top: 6px !important; bottom: 6px !important; }
  #saj-left-tools-panel-stage35 .saj-left-tools-head { left: 5px !important; right: 5px !important; }
  body a[href="/admin"] { left: 13px !important; top: 44px !important; width: 160px !important; max-width: 160px !important; }
  #root button[title="اعتبارسنجی بلوک"] { left: 13px !important; top: 76px !important; width: 160px !important; }
  #root .saj-left-satellite-controls {
    left: 11px !important;
    top: 111px !important;
    bottom: calc(142px + var(--saj-ui-action-height) + 10px) !important;
    width: 160px !important;
  }
  #root .saj-left-satellite-controls > div { max-height: min(20vh, 148px) !important; }
  #saj-map-tool-actions-stage74 { left: 7px !important; width: 160px !important; bottom: 142px !important; }
  #rotation-knob { left: 66px !important; bottom: 96px !important; width: 40px !important; height: 40px !important; min-width: 40px !important; min-height: 40px !important; }
  #saj-pr-open, #saj-archive-open { left: 13px !important; width: 160px !important; max-width: 160px !important; }
  #root #jnaf-editing-toolbar-stage13,
  #root div[style*="z-index: 10003"][style*="width: 100%"] {
    max-height: min(24dvh, 190px) !important;
    padding: 4px !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
  }
  #root #jnaf-editing-toolbar-stage13 button,
  #root div[style*="z-index: 10003"][style*="width: 100%"] button { min-width: 36px !important; min-height: 36px !important; font-size: 8px !important; padding: 4px 5px !important; }
  #root #jnaf-tools-layers-drawer-stage13,
  #root #jnaf-tools-layers-drawer-stage13[data-stage13-open="true"] {
    width: auto !important;
    max-width: calc(100vw - 12px) !important;
  }
}

@media (max-height: 640px) {
  :root { --saj-ui-action-height: min(23vh, 142px); }
  #root .saj-left-satellite-controls {
    top: 108px !important;
    bottom: calc(142px + var(--saj-ui-action-height) + 10px) !important;
  }
  #root .saj-left-satellite-controls > div { max-height: min(18vh, 112px) !important; }
  #saj-map-tool-actions-stage74 { max-height: var(--saj-ui-action-height) !important; }
}

@media (max-width: 380px) {
  #saj-left-tools-panel-stage35 { width: 178px !important; }
  #saj-left-tools-panel-stage35 .saj-left-tools-head > span { font-size: 8px !important; }
  #root .saj-left-satellite-controls { width: 154px !important; }
  #saj-map-tool-actions-stage74 { width: 154px !important; }
  #root #jnaf-editing-toolbar-stage13 button,
  #root div[style*="z-index: 10003"][style*="width: 100%"] button { min-width: 34px !important; min-height: 36px !important; font-size: 7.5px !important; }
}

@media (prefers-reduced-motion: reduce) {
  #saj-left-tools-panel-stage35,
  #saj-map-tool-actions-stage74 { transition: none !important; }
}

body:not(.saj-authenticated) #saj-global-gis-search-open { display: none !important; }

/* Stage 129 / Task 82 — keep every supplementary map option inside the
   existing basemap/location panel. This removes the old lower floating tray
   and prevents controls from being painted underneath one another. */
#root .saj-left-satellite-controls {
  top: 116px !important;
  bottom: 8px !important;
  height: auto !important;
  max-height: none !important;
  overflow-x: hidden !important;
  overflow-y: auto !important;
  overscroll-behavior: contain !important;
  -webkit-overflow-scrolling: touch !important;
  scrollbar-width: thin !important;
  align-items: stretch !important;
}
#root .saj-left-satellite-controls > div#saj-map-tool-actions-stage74 {
  position: relative !important;
  inset: auto !important;
  top: auto !important;
  right: auto !important;
  bottom: auto !important;
  left: auto !important;
  order: 4 !important;
  flex: 0 0 auto !important;
  max-height: none !important;
  overflow: visible !important;
  padding: 0 !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  width: 100% !important;
  min-width: 0 !important;
  max-width: 100% !important;
  height: auto !important;
  min-height: 0 !important;
  max-height: none !important;
  margin: 5px 0 2px !important;
  padding: 0 !important;
  gap: 5px !important;
  display: flex !important;
  flex-direction: column !important;
  align-items: stretch !important;
  justify-content: flex-start !important;
  overflow: visible !important;
  box-sizing: border-box !important;
  border: 0 !important;
  border-radius: 0 !important;
  background: transparent !important;
  z-index: auto !important;
  pointer-events: auto !important;
}
#saj-project-device-export,
#saj-history-widget,
#saj-gis-undo-redo {
  position: relative !important;
  inset: auto !important;
  width: 100% !important;
  min-width: 0 !important;
  max-width: 100% !important;
  box-sizing: border-box !important;
  pointer-events: auto !important;
}
@media (max-width: 520px) {
  #root .saj-left-satellite-controls {
    top: 111px !important;
    bottom: 8px !important;
    width: 160px !important;
  }
}
@media (max-height: 640px) {
  #root .saj-left-satellite-controls {
    top: 108px !important;
    bottom: 8px !important;
  }
}
@media (max-width: 380px) {
  #root .saj-left-satellite-controls { width: 154px !important; }
}

