/* ==========================================================================
   Superset 6.0 Explore RTL & Persian Layout Polish (v4)
   Targets: Tooltips (<CSSMotion>), Datasource Panel Folders, and Control Panels
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. GLOBAL EXPLORE TOOLTIPS & POPOVERS (including rc-motion / <CSSMotion>)
   -------------------------------------------------------------------------- */
body .ant-tooltip,
body .ant-tooltip-inner,
body .ant-tooltip-content,
body .ant-tooltip-inner *,
body .ant-tooltip div,
body .ant-tooltip span,
body .ant-tooltip p,
body .ant-popover,
body .ant-popover-inner,
body .ant-popover-inner-content,
body .ant-popover-inner-content * {
  direction: rtl !important;
  text-align: right !important;
  font-family: 'Vazirmatn FD', Vazirmatn, sans-serif !important;
  line-height: 1.65 !important;
}

body .ant-tooltip-inner {
  max-width: 380px !important;
  padding: 8px 12px !important;
}

/* Force override any hardcoded inline text-align in tooltips (e.g. ExploreViewContainer.jsx) */
body .ant-tooltip [style*="text-align"],
body .ant-tooltip-inner [style*="text-align"],
body .ant-tooltip-inner div[style],
body .ant-tooltip div[style],
body .ant-tooltip [style*="textAlign"],
body .ant-tooltip-inner [style*="textAlign"] {
  text-align: right !important;
  direction: rtl !important;
}

/* Ensure inline elements in tooltips preserve proper Persian bidi reading order */
body .ant-tooltip-inner strong,
body .ant-tooltip-inner span {
  display: inline !important;
  direction: rtl !important;
  unicode-bidi: isolate !important;
}

/* --------------------------------------------------------------------------
   2. DATASOURCE PANEL (Left Sidebar: Metrics, Columns, and Folders)
   -------------------------------------------------------------------------- */
#explore-container .data-source-selection,
#explore-container .data-source-selection .field-selections,
#explore-container .data-source-selection .title-container,
#explore-container .data-source-selection button {
  direction: rtl !important;
  text-align: right !important;
}

/* 2.1 Title container: 'Chart Source' on Right, Collapse button on Left */
#explore-container .data-source-selection .title-container {
  display: flex !important;
  flex-direction: row !important;
  direction: rtl !important;
  justify-content: space-between !important;
  align-items: center !important;
  padding: 0 16px !important;
}
#explore-container .data-source-selection .title-container .horizontal-text {
  order: 1 !important;
  text-align: right !important;
  font-family: 'Vazirmatn FD', Vazirmatn, sans-serif !important;
  font-weight: 600 !important;
}
#explore-container .data-source-selection .title-container .action-button {
  order: 2 !important;
  margin-inline-start: auto !important;
  margin-inline-end: 0 !important;
}
#explore-container .data-source-selection .title-container .collapse-icon {
  transform: rotate(90deg) !important; /* points right to indicate collapsing to right in RTL */
}

/* 2.2 Search input */
#explore-container .data-source-selection input {
  direction: rtl !important;
  text-align: right !important;
  font-family: 'Vazirmatn FD', Vazirmatn, sans-serif !important;
}

/* 2.3 Datasource Folder Header Rows (e.g. "متریک‌ها", "ستون‌ها") */
#explore-container .data-source-selection button,
#explore-container .data-source-selection [class*="SectionHeaderButton"] {
  border: none !important;
  background: transparent !important;
  width: 100% !important;
  padding: 0 !important;
  cursor: pointer !important;
}

/* The flex row holding Title and Arrow */
[class*="pe6vce"],
[class*="SectionHeaderTextContainer"],
#explore-container .data-source-selection button > div,
#explore-container .data-source-selection button div:has(> .anticon),
#explore-container .data-source-selection div:has(> .ant-typography):has(> .anticon) {
  display: flex !important;
  flex-direction: row !important;
  direction: rtl !important;
  justify-content: space-between !important;
  align-items: center !important;
  text-align: right !important;
  width: 100% !important;
}

/* FOLDER LABEL: "متریک‌ها", "ستون‌ها" ALWAYS ON THE RIGHT (order: 1) */
[class*="pe6vce"] > :first-child,
[class*="pe6vce"] .ant-typography,
[class*="SectionHeaderTextContainer"] > :first-child,
[class*="SectionHeaderTextContainer"] .ant-typography,
#explore-container .data-source-selection button span.ant-typography,
#explore-container .data-source-selection button .ant-typography,
#explore-container .data-source-selection button [class*="SectionHeader"] {
  order: 1 !important;
  text-align: right !important;
  direction: rtl !important;
  float: right !important;
  margin-inline-end: auto !important;
  margin-inline-start: 0 !important;
  flex: 1 1 auto !important;
  font-family: 'Vazirmatn FD', Vazirmatn, sans-serif !important;
  font-weight: 600 !important;
}

/* FOLDER ARROW / CHEVRON: ALWAYS ON THE LEFT (order: 2) */
[class*="pe6vce"] > :last-child,
[class*="pe6vce"] .anticon,
[class*="pe6vce"] svg,
[class*="SectionHeaderTextContainer"] > :last-child,
[class*="SectionHeaderTextContainer"] .anticon,
#explore-container .data-source-selection button .anticon,
#explore-container .data-source-selection button span[role="img"],
#explore-container .data-source-selection button svg {
  order: 2 !important;
  margin-inline-start: auto !important;
  margin-inline-end: 0 !important;
  float: left !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  flex-shrink: 0 !important;
}

/* 2.4 Subtitle: Showing X of Y items */
#explore-container .data-source-selection .field-length,
#explore-container .data-source-selection [class*="field-length"] {
  direction: rtl !important;
  text-align: right !important;
  font-family: 'Vazirmatn FD', Vazirmatn, sans-serif !important;
}

/* 2.5 Draggable items in datasource selection */
#explore-container .data-source-selection [draggable='true'],
#explore-container .data-source-selection span:has(> .option-label) {
  direction: rtl !important;
}
#explore-container .data-source-selection .option-label {
  direction: ltr !important;
  unicode-bidi: isolate !important;
  text-align: right !important;
}
#explore-container .data-container .datasource-svg {
  margin-right: 0 !important;
  margin-left: 8px !important;
  flex-shrink: 0 !important;
}
#explore-container .data-container .title-select {
  direction: ltr !important;
  unicode-bidi: isolate !important;
  text-align: right !important;
}

/* --------------------------------------------------------------------------
   3. CONTROLS PANEL (Middle Sidebar: Sections, Headers, Option Pills)
   -------------------------------------------------------------------------- */
#explore-container .explore-column,
#explore-container .ant-select-selection-item,
#explore-container .ant-select-selection-placeholder,
#explore-container .ant-select-selection-search-input {
  text-align: right !important;
}

/* 3.1 Collapsible Panel Headers in Ant Design Collapse */
#explore-container .ant-collapse > .ant-collapse-item > .ant-collapse-header,
.ant-collapse > .ant-collapse-item > .ant-collapse-header {
  display: flex !important;
  flex-direction: row !important;
  direction: rtl !important;
  justify-content: space-between !important;
  align-items: center !important;
  text-align: right !important;
  width: 100% !important;
}

#explore-container .ant-collapse-header-text,
.ant-collapse-header-text,
[data-test="collapsible-control-panel-header"] {
  order: 1 !important;
  text-align: right !important;
  float: right !important;
  margin-inline-end: auto !important;
  margin-inline-start: 0 !important;
  flex: 1 1 auto !important;
}

#explore-container .ant-collapse-expand-icon,
.ant-collapse-expand-icon,
.ant-collapse-arrow {
  order: 2 !important;
  margin-inline-start: auto !important;
  margin-inline-end: 0 !important;
  float: left !important;
  padding-inline-start: 8px !important;
  padding-inline-end: 0 !important;
  display: flex !important;
  align-items: center !important;
}

/* Horizontal chevrons mirrored in RTL */
.ant-collapse-arrow:not([style*="rotate(90deg)"]):not([style*="rotate(-90deg)"]):not([style*="rotate(180deg)"]) {
  transform: scaleX(-1) !important;
}

/* 3.2 Individual Control Headers (Bootstrap .pull-left / .pull-right) */
.ControlHeader,
[data-test$="-header"] {
  display: flex !important;
  flex-direction: row !important;
  direction: rtl !important;
  justify-content: space-between !important;
  align-items: center !important;
  width: 100% !important;
}

.ControlHeader .pull-left,
[data-test$="-header"] .pull-left,
.ControlHeader label {
  order: 1 !important;
  float: right !important;
  text-align: right !important;
  margin-inline-end: auto !important;
  margin-inline-start: 0 !important;
  flex: 1 1 auto !important;
}

.ControlHeader .pull-right,
[data-test$="-header"] .pull-right {
  order: 2 !important;
  float: left !important;
  text-align: left !important;
  margin-inline-start: auto !important;
  margin-inline-end: 0 !important;
}

.ControlHeader label > span:has(> .anticon-exclamation-circle) {
  margin-right: 4px !important;
  margin-left: 0 !important;
}

/* Fix hover info icon / bolt positioning in ControlHeader */
.ControlHeader label > span:has(> .anticon-info-circle),
.ControlHeader label > span:has(> [data-test="description-tooltip"]),
.ControlHeader span[style*="transform: translate(100%"] {
  right: auto !important;
  left: 0 !important;
  transform: translate(-100%, -50%) !important;
  padding-left: 0 !important;
  padding-right: 4px !important;
}

/* 3.3 Option Pills (Metrics, Columns, Filters dropzones) */
[data-test="option-label"] {
  display: flex !important;
  flex-direction: row !important;
  direction: rtl !important;
  align-items: center !important;
  width: 100% !important;
}

[data-test="control-label"] {
  order: 1 !important;
  text-align: right !important;
  padding-inline-start: 8px !important;
  padding-inline-end: 8px !important;
  display: flex !important;
  align-items: center !important;
  flex: 1 1 auto !important;
}

[data-test="remove-control-button"] {
  order: 2 !important;
  margin-inline-start: auto !important;
  border-left: 1px solid var(--ant-color-split, rgba(0, 0, 0, 0.06)) !important;
  border-right: none !important;
}

.CaretContainer,
div:has(> .anticon-right) {
  order: 3 !important;
  border-right: 1px solid var(--ant-color-split, rgba(0, 0, 0, 0.06)) !important;
  border-left: none !important;
}
.CaretContainer .anticon-right,
div:has(> .anticon-right) .anticon-right {
  transform: scaleX(-1) !important;
}

div:has(> .anticon-plus) {
  gap: 8px !important;
}
div > .anticon-plus {
  flex-shrink: 0 !important;
  margin-right: 0 !important;
  margin-left: 0 !important;
}

/* Header button panel gap */
.header-with-actions .right-button-panel:has(.anticon-save):has(.anticon-ellipsis) {
  gap: 8px !important;
}
