/* Stage 35: consolidate the original floating map controls into one left-side rail.
   Keep the original React/DOM nodes alive: only their visual positions are changed. */
#saj-left-tools-panel-stage35 {
  position: fixed;
  left: 10px;
  top: 12px;
  bottom: 12px;
  width: 196px;
  box-sizing: border-box;
  z-index: 9998;
  border: 1px solid rgba(157, 190, 211, .95);
  border-radius: 16px;
  background: rgba(247, 251, 255, .94);
  box-shadow: 0 8px 28px rgba(14, 45, 70, .18);
  backdrop-filter: blur(9px);
  -webkit-backdrop-filter: blur(9px);
  pointer-events: none;
  transition: width .18s ease, height .18s ease, background .18s ease;
}
#saj-left-tools-panel-stage35 .saj-left-tools-head {
  position: absolute;
  top: 8px;
  left: 8px;
  right: 8px;
  min-height: 31px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  box-sizing: border-box;
  padding: 3px 6px;
  border: 1px solid #d5e2ed;
  border-radius: 10px;
  background: rgba(255,255,255,.97);
  color: #12304a;
  font: 700 11px Tahoma, Arial, sans-serif;
  direction: rtl;
  pointer-events: auto;
}
#saj-left-tools-panel-stage35 .saj-left-tools-head button {
  flex: 0 0 27px;
  width: 27px;
  height: 27px;
  border: 1px solid #bfd0df;
  border-radius: 8px;
  background: #fff;
  color: #1d4771;
  cursor: pointer;
  font: 700 16px Tahoma, Arial, sans-serif;
}
#saj-left-tools-panel-stage35 .saj-left-tools-head span { white-space: nowrap; }

/* Administrator link: shown only when the existing app creates it for managers. */
body a[href="/admin"] {
  position: fixed !important;
  left: 22px !important;
  right: auto !important;
  top: 54px !important;
  bottom: auto !important;
  width: 164px !important;
  min-height: 34px !important;
  padding: 9px 7px !important;
  box-sizing: border-box !important;
  text-align: center !important;
  white-space: normal !important;
  z-index: 10004 !important;
  font-size: 11px !important;
  line-height: 1.35 !important;
  border-radius: 10px !important;
}

/* Preserve the existing validation button, label, icon and click handler. */
#root button[title="اعتبارسنجی بلوک"] {
  position: fixed !important;
  left: 22px !important;
  right: auto !important;
  top: 96px !important;
  bottom: auto !important;
  width: 164px !important;
  min-width: 0 !important;
  height: 36px !important;
  padding: 5px 8px !important;
  box-sizing: border-box !important;
  border-radius: 10px !important;
  z-index: 10004 !important;
  font-size: 11px !important;
  white-space: nowrap !important;
}

/* The existing React wrapper contains the base-map button, current-location button,
   and the expandable satellite/layer menu. No React node is moved or replaced. */
#root .saj-left-satellite-controls {
  position: fixed !important;
  top: 140px !important;
  bottom: 194px !important;
  left: 18px !important;
  right: auto !important;
  width: 172px !important;
  max-height: none !important;
  min-width: 0 !important;
  box-sizing: border-box !important;
  padding: 5px !important;
  overflow-y: auto !important;
  overflow-x: hidden !important;
  display: flex !important;
  flex-direction: column !important;
  gap: 6px !important;
  align-items: stretch !important;
  background: rgba(255,255,255,.96) !important;
  border: 1px solid #dbe6ef !important;
  border-radius: 12px !important;
  box-shadow: 0 3px 12px rgba(18,48,74,.08) !important;
  z-index: 10003 !important;
}
#root .saj-left-satellite-controls > button[title="نقشه پایه"] {
  order: 1 !important;
  width: 100% !important;
  height: 38px !important;
  min-height: 38px !important;
  flex: 0 0 38px !important;
  border-radius: 9px !important;
  font-size: 24px !important;
  box-sizing: border-box !important;
}
#root .saj-left-satellite-controls > div {
  order: 2 !important;
  position: relative !important;
  inset: auto !important;
  width: 100% !important;
  min-width: 0 !important;
  max-width: 100% !important;
  max-height: min(42vh, 330px) !important;
  overflow-y: auto !important;
  overflow-x: hidden !important;
  flex: 0 1 auto !important;
  box-sizing: border-box !important;
  padding: 6px !important;
  border-radius: 9px !important;
  box-shadow: inset 0 0 0 1px #e6edf4 !important;
}
#root .saj-left-satellite-controls > div > button {
  width: 100% !important;
  min-height: 34px !important;
  box-sizing: border-box !important;
  white-space: normal !important;
  line-height: 1.5 !important;
  font-size: 11px !important;
  padding: 7px 8px !important;
}
#root .saj-left-satellite-controls > button[title="نمایش موقعیت من"] {
  order: 3 !important;
  width: 100% !important;
  height: 38px !important;
  min-height: 38px !important;
  flex: 0 0 38px !important;
  border-radius: 9px !important;
  font-size: 22px !important;
  box-sizing: border-box !important;
}

/* Existing external controls remain their own real buttons and retain their listeners. */
#saj-pr-open,
#saj-archive-open {
  position: fixed !important;
  left: 22px !important;
  right: auto !important;
  width: 164px !important;
  max-width: 164px !important;
  min-height: 34px !important;
  height: auto !important;
  padding: 8px 7px !important;
  box-sizing: border-box !important;
  white-space: normal !important;
  text-align: center !important;
  line-height: 1.35 !important;
  font-size: 11px !important;
  border-radius: 10px !important;
  transform: none !important;
  z-index: 10004 !important;
}
#saj-pr-open { top: auto !important; bottom: 62px !important; }
#saj-archive-open { top: auto !important; bottom: 20px !important; }

/* The real rotating compass stays mounted in React; only its visual location changes. */
#rotation-knob {
  position: fixed !important;
  top: auto !important;
  right: auto !important;
  left: 76px !important;
  bottom: 108px !important;
  width: 52px !important;
  height: 52px !important;
  min-width: 52px !important;
  min-height: 52px !important;
  z-index: 10004 !important;
}

/* Independent show/hide state: hide tools visually without removing them or handlers. */
body.saj-left-tools-collapsed #saj-left-tools-panel-stage35 {
  width: 48px;
  height: 44px;
  bottom: auto;
  background: rgba(247,251,255,.98);
}
body.saj-left-tools-collapsed #saj-left-tools-panel-stage35 .saj-left-tools-head {
  left: 5px; right: 5px; top: 5px; padding: 2px;
}
body.saj-left-tools-collapsed #saj-left-tools-panel-stage35 .saj-left-tools-head span { display: none; }
body.saj-left-tools-collapsed a[href="/admin"],
body.saj-left-tools-collapsed #root button[title="اعتبارسنجی بلوک"],
body.saj-left-tools-collapsed #root .saj-left-satellite-controls,
body.saj-left-tools-collapsed #saj-pr-open,
body.saj-left-tools-collapsed #saj-archive-open,
body.saj-left-tools-collapsed #rotation-knob {
  visibility: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

/* Do not place the tool rail over the main drawing toolbar at very narrow widths. */
@media (max-width: 520px) {
  #saj-left-tools-panel-stage35 { width: 188px; left: 6px; top: 8px; bottom: 8px; }
  body a[href="/admin"] { left: 16px !important; width: 158px !important; top: 50px !important; }
  #root button[title="اعتبارسنجی بلوک"] { left: 16px !important; width: 158px !important; top: 91px !important; }
  #root .saj-left-satellite-controls { left: 12px !important; width: 166px !important; top: 133px !important; bottom: 190px !important; }
  #saj-pr-open, #saj-archive-open { left: 16px !important; width: 158px !important; max-width: 158px !important; }
  #rotation-knob { left: 68px !important; bottom: 106px !important; width: 48px !important; height: 48px !important; min-width: 48px !important; min-height: 48px !important; }
}
@media (max-height: 640px) {
  #root .saj-left-satellite-controls { top: 136px !important; bottom: 180px !important; }
  #root .saj-left-satellite-controls > div { max-height: 28vh !important; }
  #saj-pr-open { bottom: 58px !important; }
  #saj-archive-open { bottom: 18px !important; }
  #rotation-knob { bottom: 101px !important; width: 46px !important; height: 46px !important; min-width: 46px !important; min-height: 46px !important; }
}
body:not(.saj-authenticated) #saj-left-tools-panel-stage35 { display: none !important; }
