/**
 * Portal-wide Arabic (RTL) fixes — loaded from partials/layout.blade.php on every page.
 * Complements html[dir=rtl] + logical CSS. Do not rely on per-module Blade @if(ar) forks.
 */

/* -------------------------------------------------------------------------- */
/* Base: beat Bootstrap body { text-align: left }                             */
/* -------------------------------------------------------------------------- */

html[dir='rtl'] body {
  text-align: start;
}

html[dir='rtl'] .content-wrapper,
html[dir='rtl'] .page-content,
html[dir='rtl'] .container-fluid,
html[dir='rtl'] .card,
html[dir='rtl'] .card-body,
html[dir='rtl'] .modal-content,
html[dir='rtl'] .modal-header,
html[dir='rtl'] .modal-body,
html[dir='rtl'] .modal-footer,
html[dir='rtl'] .dropdown-menu,
html[dir='rtl'] .list-group-item,
html[dir='rtl'] .alert {
  text-align: start;
}

/* -------------------------------------------------------------------------- */
/* Page heroes / titles + descriptions (enterprise + devices + legacy)        */
/* -------------------------------------------------------------------------- */

html[dir='rtl'] .bw-ent-hero-main,
html[dir='rtl'] .bw-ent-title,
html[dir='rtl'] .bw-ent-description,
html[dir='rtl'] .bw-add-hero-title,
html[dir='rtl'] .bw-add-card-sub,
html[dir='rtl'] .bw-bulk-title,
html[dir='rtl'] .bw-device-shell-title,
html[dir='rtl'] .page-title-row,
html[dir='rtl'] .page-title-row h1,
html[dir='rtl'] .page-title-row h2,
html[dir='rtl'] .page-title-row p {
  text-align: start;
}

/* -------------------------------------------------------------------------- */
/* Forms & labels                                                             */
/* -------------------------------------------------------------------------- */

html[dir='rtl'] .form-label,
html[dir='rtl'] label:not(.form-check-label):not(.btn):not(.custom-control-label):not(.btn-check) {
  text-align: start;
}

html[dir='rtl'] .form-control,
html[dir='rtl'] .form-select,
html[dir='rtl'] select.form-control,
html[dir='rtl'] textarea.form-control,
html[dir='rtl'] .input-group-text {
  text-align: start;
}

/* -------------------------------------------------------------------------- */
/* Tables — titles and cell values share the same edge                        */
/* -------------------------------------------------------------------------- */

html[dir='rtl'] .table thead th,
html[dir='rtl'] .table tbody td,
html[dir='rtl'] .bw-ent-table thead th,
html[dir='rtl'] .bw-ent-table tbody td,
html[dir='rtl'] table.dataTable thead th,
html[dir='rtl'] table.dataTable tbody td {
  text-align: start;
}

html[dir='rtl'] .table thead th.org-row-actions-cell,
html[dir='rtl'] .table tbody td.org-row-actions-cell,
html[dir='rtl'] .table:has(td.org-row-actions-cell) thead th:last-child,
html[dir='rtl'] .bw-ent-table thead th.org-row-actions-cell,
html[dir='rtl'] .bw-ent-table tbody td.org-row-actions-cell,
html[dir='rtl'] .bw-ent-table:has(td.org-row-actions-cell) thead th:last-child {
  text-align: end;
}

html[dir='rtl'] .table thead th,
html[dir='rtl'] .table tbody td {
  padding-inline: 14px !important;
}

html[dir='rtl'] .bw-ent-table thead th,
html[dir='rtl'] .bw-ent-table tbody td {
  padding-inline: 0.85rem !important;
}

/* Beat hardcoded text-align:left in module CSS (Devices, Access Control, etc.) */
html[dir='rtl'] [style*='text-align: left'],
html[dir='rtl'] [style*='text-align:left'] {
  text-align: start !important;
}

html[dir='rtl'] .text-left {
  text-align: start !important;
}

html[dir='rtl'] .ac-live-door-open,
html[dir='rtl'] .ac-live-door-name,
html[dir='rtl'] .ac-live-door-meta {
  text-align: start;
}

/* -------------------------------------------------------------------------- */
/* DataTables chrome                                                          */
/* -------------------------------------------------------------------------- */

html[dir='rtl'] .dataTables_wrapper .dataTables_length,
html[dir='rtl'] .dataTables_wrapper .dataTables_filter,
html[dir='rtl'] table.dataTable thead th,
html[dir='rtl'] table.dataTable tbody td {
  text-align: start !important;
}

html[dir='rtl'] div.dataTables_wrapper div.dataTables_length label {
  text-align: start !important;
}

html[dir='rtl'] div.dataTables_wrapper div.dataTables_filter {
  text-align: end !important;
}

html[dir='rtl'] div.dataTables_wrapper div.dataTables_filter label {
  text-align: start !important;
}

/*
 * Sortable headers (RTL): title stays on the start edge (right);
 * ↑↓ arrows move to the end edge (left) with reserved padding so they
 * never sit on top of the label (DataTables default uses physical right:).
 */
html[dir='rtl'] table.dataTable thead > tr > th.sorting,
html[dir='rtl'] table.dataTable thead > tr > th.sorting_asc,
html[dir='rtl'] table.dataTable thead > tr > th.sorting_desc,
html[dir='rtl'] table.dataTable thead > tr > th.sorting_asc_disabled,
html[dir='rtl'] table.dataTable thead > tr > th.sorting_desc_disabled,
html[dir='rtl'] table.dataTable thead > tr > td.sorting,
html[dir='rtl'] table.dataTable thead > tr > td.sorting_asc,
html[dir='rtl'] table.dataTable thead > tr > td.sorting_desc,
html[dir='rtl'] table.dataTable thead > tr > td.sorting_asc_disabled,
html[dir='rtl'] table.dataTable thead > tr > td.sorting_desc_disabled {
  padding-left: 30px !important;
  padding-right: 12px !important;
}

html[dir='rtl'] table.dataTable thead .sorting:before,
html[dir='rtl'] table.dataTable thead .sorting_asc:before,
html[dir='rtl'] table.dataTable thead .sorting_desc:before,
html[dir='rtl'] table.dataTable thead .sorting_asc_disabled:before,
html[dir='rtl'] table.dataTable thead .sorting_desc_disabled:before {
  right: auto !important;
  left: 1em !important;
}

html[dir='rtl'] table.dataTable thead .sorting:after,
html[dir='rtl'] table.dataTable thead .sorting_asc:after,
html[dir='rtl'] table.dataTable thead .sorting_desc:after,
html[dir='rtl'] table.dataTable thead .sorting_asc_disabled:after,
html[dir='rtl'] table.dataTable thead .sorting_desc_disabled:after {
  right: auto !important;
  left: 0.5em !important;
}

html[dir='rtl'] table.dataTable.table-sm thead > tr > th.sorting,
html[dir='rtl'] table.dataTable.table-sm thead > tr > th.sorting_asc,
html[dir='rtl'] table.dataTable.table-sm thead > tr > th.sorting_desc,
html[dir='rtl'] table.dataTable.table-sm thead > tr > th.sorting_asc_disabled,
html[dir='rtl'] table.dataTable.table-sm thead > tr > th.sorting_desc_disabled {
  padding-left: 20px !important;
}

html[dir='rtl'] table.dataTable.table-sm thead .sorting:before,
html[dir='rtl'] table.dataTable.table-sm thead .sorting_asc:before,
html[dir='rtl'] table.dataTable.table-sm thead .sorting_desc:before,
html[dir='rtl'] table.dataTable.table-sm thead .sorting_asc_disabled:before,
html[dir='rtl'] table.dataTable.table-sm thead .sorting_desc_disabled:before {
  right: auto !important;
  left: 0.85em !important;
}

html[dir='rtl'] table.dataTable.table-sm thead .sorting:after,
html[dir='rtl'] table.dataTable.table-sm thead .sorting_asc:after,
html[dir='rtl'] table.dataTable.table-sm thead .sorting_desc:after,
html[dir='rtl'] table.dataTable.table-sm thead .sorting_asc_disabled:after,
html[dir='rtl'] table.dataTable.table-sm thead .sorting_desc_disabled:after {
  right: auto !important;
  left: 0.5em !important;
}

/* Empty / actions / checkbox headers should never show ↑↓ */
table.dataTable thead th.sorting:empty::before,
table.dataTable thead th.sorting:empty::after,
table.dataTable thead th.sorting_asc:empty::before,
table.dataTable thead th.sorting_asc:empty::after,
table.dataTable thead th.sorting_desc:empty::before,
table.dataTable thead th.sorting_desc:empty::after,
table.dataTable thead th.sorting_disabled:empty::before,
table.dataTable thead th.sorting_disabled:empty::after,
table.dataTable thead th.sorting:has(> input[type='checkbox']):before,
table.dataTable thead th.sorting:has(> input[type='checkbox']):after,
table.dataTable thead th.sorting_asc:has(input[type='checkbox']):before,
table.dataTable thead th.sorting_asc:has(input[type='checkbox']):after,
table.dataTable thead th.sorting_desc:has(input[type='checkbox']):before,
table.dataTable thead th.sorting_desc:has(input[type='checkbox']):after,
table.dataTable thead th.ac-col-actions.sorting:before,
table.dataTable thead th.ac-col-actions.sorting:after,
table.dataTable thead th.ac-col-actions.sorting_asc:before,
table.dataTable thead th.ac-col-actions.sorting_asc:after,
table.dataTable thead th.ac-col-actions.sorting_desc:before,
table.dataTable thead th.ac-col-actions.sorting_desc:after {
  display: none !important;
  content: none !important;
}

table.dataTable thead th.sorting:empty,
table.dataTable thead th.sorting_asc:empty,
table.dataTable thead th.sorting_desc:empty,
table.dataTable thead th.sorting:has(input[type='checkbox']),
table.dataTable thead th.sorting_asc:has(input[type='checkbox']),
table.dataTable thead th.sorting_desc:has(input[type='checkbox']),
table.dataTable thead th.ac-col-actions.sorting,
table.dataTable thead th.ac-col-actions.sorting_asc,
table.dataTable thead th.ac-col-actions.sorting_desc {
  padding-left: 12px !important;
  padding-right: 12px !important;
  cursor: default;
  background-image: none !important;
}

/* -------------------------------------------------------------------------- */
/* Dropdowns                                                                  */
/* -------------------------------------------------------------------------- */

html[dir='rtl'] .dropdown-menu {
  text-align: start;
  direction: rtl;
}

html[dir='rtl'] .dropdown-item {
  text-align: start;
}

html[dir='rtl'] .ac-row-actions-menu.ac-row-actions-menu--portaled {
  text-align: right;
  direction: rtl;
}

html[dir='rtl'] .ac-row-actions-menu.ac-row-actions-menu--portaled .dropdown-item,
html[dir='rtl'] .ac-row-actions-menu.ac-row-actions-menu--portaled .ac-row-actions-item {
  text-align: right;
  flex-direction: row;
}

/* -------------------------------------------------------------------------- */
/* Toastr — card on left; check / status icon on the right                    */
/* -------------------------------------------------------------------------- */

html[dir='rtl'] #toast-container.toast-top-left,
html[dir='rtl'] #toast-container.toast-bottom-left {
  left: 12px !important;
  right: auto !important;
}

html[dir='rtl'] #toast-container > div {
  background-position: right 15px center !important;
  padding: 15px 50px 15px 15px !important;
  text-align: right !important;
  direction: rtl !important;
}

html[dir='rtl'] #toast-container > .toast-success,
html[dir='rtl'] #toast-container > .toast-error,
html[dir='rtl'] #toast-container > .toast-info,
html[dir='rtl'] #toast-container > .toast-warning {
  background-position: right 15px center !important;
}

html[dir='rtl'] #toast-container .toast-close-button {
  left: 0.3em !important;
  right: auto !important;
  float: left !important;
}

/* -------------------------------------------------------------------------- */
/* SweetAlert attendance toast cards                                          */
/* -------------------------------------------------------------------------- */

html[dir='rtl'] .swal2-container.swal2-bottom-left,
html[dir='rtl'] .swal2-container.swal2-top-left {
  inset-inline-start: 0 !important;
  inset-inline-end: auto !important;
  left: 0 !important;
  right: auto !important;
}

html[dir='rtl'] .attendance-notification-card {
  direction: rtl;
  text-align: right;
}

html[dir='rtl'] .attendance-notification-body {
  flex-direction: row;
}

html[dir='rtl'] .attendance-notification-body > span {
  flex: 1 1 auto;
  text-align: right;
}

html[dir='rtl'] .attendance-notification-user-row,
html[dir='rtl'] .attendance-notification-meta-row {
  flex-direction: row-reverse;
}

html[dir='rtl'] .attendance-notification-close {
  inset-inline-end: 8px !important;
}

/* -------------------------------------------------------------------------- */
/* Select2                                                                    */
/* -------------------------------------------------------------------------- */

html[dir='rtl'] .select2-container--default .select2-selection--single .select2-selection__rendered,
html[dir='rtl'] .select2-results__option {
  text-align: start;
}

html[dir='rtl'] .select2-container--default .select2-selection--single {
  text-align: start;
}

html[dir='rtl'] .bw-add-discovery-table thead th,
html[dir='rtl'] .bw-add-discovery-table tbody td,
html[dir='rtl'] .bw-add-hero-title,
html[dir='rtl'] .bw-bulk-title,
html[dir='rtl'] .bw-device-shell-title {
  text-align: start;
}

html[dir='rtl'] .bw-bulk-page .bw-bulk-grid-row .bw-bulk-col-actions {
  text-align: end;
}

/* -------------------------------------------------------------------------- */
/* Side menu — icon + label gaps (Devices / Access Control / all modules)     */
/* -------------------------------------------------------------------------- */

html[dir='rtl'] #mainNav .navbar-sidenav > .nav-item > .nav-link,
html[dir='rtl'] #mainNav .navbar-sidenav .sidenav-second-level > li > a,
html[dir='rtl'] #mainNav .navbar-sidenav .sidenav-third-level > li > a {
  display: flex !important;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: flex-start;
  gap: 0.5rem;
  text-align: start;
}

html[dir='rtl'] #mainNav .navbar-sidenav .nav-link > .d-flex {
  display: inline-flex !important;
  flex: 0 1 auto !important;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: flex-start;
  gap: 0.5rem;
  width: auto;
  max-width: 100%;
  min-width: 0;
}

html[dir='rtl'] #mainNav .navbar-sidenav .nav-link > .d-flex > div {
  flex: 0 0 auto;
  margin: 0 !important;
  padding: 0;
  width: auto;
}

html[dir='rtl'] #mainNav .navbar-sidenav .nav-link > .d-flex > div:first-child {
  flex: 0 0 1.25rem;
  width: 1.25rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

html[dir='rtl'] #mainNav .navbar-sidenav .googleIconSideBar {
  margin: 0 !important;
  margin-inline-end: 0 !important;
}

html[dir='rtl'] #mainNav .navbar-sidenav .nav-link > img,
html[dir='rtl'] #mainNav .navbar-sidenav .sidenav-second-level > li > a > img,
html[dir='rtl'] #mainNav .navbar-sidenav .sidenav-third-level > li > a > img {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  margin: 0 !important;
}

html[dir='rtl'] #mainNav .navbar-sidenav .nav-link-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (min-width: 992px) {
  html[dir='rtl'] #mainNav .navbar-collapse .navbar-sidenav > .nav-item .sidenav-second-level > li > a {
    padding-top: 1em !important;
    padding-bottom: 1em !important;
    padding-right: 2.25em !important;
    padding-left: 0.75em !important;
  }

  html[dir='rtl'] #mainNav .navbar-collapse .navbar-sidenav > .nav-item .sidenav-third-level > li > a {
    padding-top: 1em !important;
    padding-bottom: 1em !important;
    padding-right: 3.75em !important;
    padding-left: 0.75em !important;
  }
}
