/* v1.5.17 — Mobile Cards / Tables switch above every table                   */
/* ========================================================================== */

.sonic-mobile-table-view-switch {
  display: none;
}

@media (max-width: 1199.98px) {
  .sonic-mobile-table-view-switch {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
    margin: 0 0 14px;
    padding: 10px;
    border: 1px solid var(--bs-border-color);
    background: var(--bs-card-bg, #fff);
    font-family: "Tajawal", sans-serif;
    font-weight: 700;
  }

  .sonic-mobile-table-view-title {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    flex: 0 0 auto;
    color: var(--bs-heading-color);
    font-size: 13px;
    white-space: nowrap;
  }

  .sonic-mobile-table-view-title .ti {
    color: var(--bs-primary);
    font-size: 19px;
  }

  .sonic-mobile-table-view-options {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    flex: 1 1 auto;
    max-width: 240px;
    padding: 4px;
    background: var(--bs-tertiary-bg);
    border: 1px solid var(--bs-border-color);
  }

  .sonic-mobile-table-view-option {
    min-height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 7px 12px;
    border: 1px solid transparent;
    border-radius: 4px;
    background: transparent;
    color: var(--bs-heading-color);
    font-family: "Tajawal", sans-serif;
    font-size: 13px;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    transition: background-color .18s ease, color .18s ease, border-color .18s ease, box-shadow .18s ease;
  }

  .sonic-mobile-table-view-option .ti {
    font-size: 18px;
  }

  .sonic-mobile-table-view-option.active {
    border-color: var(--bs-primary);
    background: var(--bs-primary);
    color: #fff;
    box-shadow: 0 7px 16px rgba(var(--bs-primary-rgb), .2);
  }

  .sonic-mobile-table-view-option:focus-visible {
    outline: 3px solid rgba(var(--bs-primary-rgb), .22);
    outline-offset: 2px;
  }

  /* Table mode: preserve the real MatDash table and allow horizontal touch scrolling. */
  .table-responsive.sonic-mobile-view-host[data-mobile-table-view="table"] {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    -webkit-overflow-scrolling: touch;
  }

  .table-responsive.sonic-mobile-view-host[data-mobile-table-view="table"] table.sonic-default-light-table {
    display: table !important;
    width: max-content !important;
    min-width: 100% !important;
  }

  /* Card mode uses the original rows/cells, so buttons, forms and inputs remain functional. */
  .table-responsive.sonic-mobile-view-host[data-mobile-table-view="cards"] {
    overflow: visible !important;
    width: 100% !important;
    max-width: 100% !important;
    border: 0 !important;
    background: transparent !important;
  }

  .table-responsive.sonic-mobile-view-host[data-mobile-table-view="cards"] table.sonic-default-light-table,
.table-responsive.sonic-mobile-view-host[data-mobile-table-view="cards"] table.sonic-default-light-table > tbody {
    display: block !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    border: 0 !important;
    background: transparent !important;
  }

  .table-responsive.sonic-mobile-view-host[data-mobile-table-view="cards"] table.sonic-default-light-table > thead,
.table-responsive.sonic-mobile-view-host[data-mobile-table-view="cards"] table.sonic-default-light-table > tfoot {
    display: none !important;
  }

  .table-responsive.sonic-mobile-view-host[data-mobile-table-view="cards"] table.sonic-default-light-table > tbody > tr {
    display: block !important;
    width: 100% !important;
    margin: 0 0 14px !important;
    padding: 5px 14px !important;
    border: 1px solid var(--bs-border-color) !important;
    border-radius: 12px !important;
    background: var(--bs-card-bg, #fff) !important;
    box-shadow: 0 7px 22px rgba(15, 23, 42, .055) !important;
  }

  .table-responsive.sonic-mobile-view-host[data-mobile-table-view="cards"] table.sonic-default-light-table > tbody > tr:last-child {
    margin-bottom: 0 !important;
  }

  .table-responsive.sonic-mobile-view-host[data-mobile-table-view="cards"] table.sonic-default-light-table > tbody > tr > th,
.table-responsive.sonic-mobile-view-host[data-mobile-table-view="cards"] table.sonic-default-light-table > tbody > tr > td {
    display: flex !important;
    align-items: center !important;
    justify-content: flex-start !important;
    flex-wrap: wrap !important;
    gap: 8px 12px !important;
    width: 100% !important;
    min-width: 0 !important;
    min-height: 46px;
    padding: 10px 0 !important;
    border: 0 !important;
    border-bottom: 1px dashed var(--bs-border-color) !important;
    background: transparent !important;
    color: var(--bs-heading-color) !important;
    white-space: normal !important;
    text-align: start !important;
    box-shadow: none !important;
    overflow-wrap: anywhere;
  }

  .table-responsive.sonic-mobile-view-host[data-mobile-table-view="cards"] table.sonic-default-light-table > tbody > tr > :last-child {
    border-bottom: 0 !important;
  }

  .table-responsive.sonic-mobile-view-host[data-mobile-table-view="cards"] table.sonic-default-light-table > tbody > tr > th::before,
.table-responsive.sonic-mobile-view-host[data-mobile-table-view="cards"] table.sonic-default-light-table > tbody > tr > td::before {
    content: attr(data-label) !important;
    display: block !important;
    flex: 0 0 min(38%, 132px);
    max-width: 132px;
    color: var(--bs-secondary-color) !important;
    font-family: "Tajawal", sans-serif;
    font-size: 12px;
    font-weight: 700;
    line-height: 1.5;
    text-align: start;
    white-space: normal;
  }

  .table-responsive.sonic-mobile-view-host[data-mobile-table-view="cards"] .sonic-mobile-card-wide-cell::before {
    flex-basis: 100% !important;
    max-width: 100% !important;
  }

  .table-responsive.sonic-mobile-view-host[data-mobile-table-view="cards"] table.sonic-default-light-table td > .form-control,
.table-responsive.sonic-mobile-view-host[data-mobile-table-view="cards"] table.sonic-default-light-table td > .form-select,
.table-responsive.sonic-mobile-view-host[data-mobile-table-view="cards"] table.sonic-default-light-table td > .select2-container,
.table-responsive.sonic-mobile-view-host[data-mobile-table-view="cards"] table.sonic-default-light-table th > .form-control,
.table-responsive.sonic-mobile-view-host[data-mobile-table-view="cards"] table.sonic-default-light-table th > .form-select,
.table-responsive.sonic-mobile-view-host[data-mobile-table-view="cards"] table.sonic-default-light-table th > .select2-container {
    flex: 1 1 54%;
    min-width: 0;
    max-width: 100%;
  }

  .table-responsive.sonic-mobile-view-host[data-mobile-table-view="cards"] table.sonic-default-light-table td form,
.table-responsive.sonic-mobile-view-host[data-mobile-table-view="cards"] table.sonic-default-light-table th form {
    margin: 0 !important;
  }

  .table-responsive.sonic-mobile-view-host[data-mobile-table-view="cards"] table.sonic-default-light-table td .btn,
.table-responsive.sonic-mobile-view-host[data-mobile-table-view="cards"] table.sonic-default-light-table th .btn {
    margin: 2px 0 !important;
  }

  .table-responsive.sonic-mobile-view-host[data-mobile-table-view="cards"] table.sonic-default-light-table tbody tr:hover > * {
    background: transparent !important;
    box-shadow: none !important;
  }
}

@media (max-width: 399.98px) {
  .sonic-mobile-table-view-switch {
    align-items: stretch;
    flex-direction: column;
  }

  .sonic-mobile-table-view-options {
    width: 100%;
    max-width: none;
  }
}

[data-bs-theme="dark"] .sonic-mobile-table-view-switch,
[data-bs-theme="dark"] .table-responsive.sonic-mobile-view-host[data-mobile-table-view="cards"] table.sonic-default-light-table > tbody > tr {
  background: #1a2537 !important;
  border-color: #313e54 !important;
}

/* ========================================================================== */

@media (max-width:1199.98px){
  .sonic-mobile-table-view-switch { border-radius:12px; }
  .sonic-mobile-table-view-switch .sonic-mobile-table-view-option { white-space:nowrap!important; }
  .sonic-mobile-view-host[data-mobile-table-view="cards"] table.sonic-default-light-table tbody tr > td,
  .sonic-mobile-view-host[data-mobile-table-view="cards"] table.sonic-default-light-table tbody tr > th { word-break:normal!important; overflow-wrap:anywhere!important; white-space:normal!important; }
  .sonic-mobile-view-host[data-mobile-table-view="cards"] table.sonic-default-light-table tbody tr > td .btn { white-space:normal!important; overflow-wrap:normal!important; min-width:fit-content; }
  .sonic-mobile-view-host[data-mobile-table-view="cards"] table.sonic-default-light-table tbody tr > :last-child { border-bottom:0!important; }
  .sonic-mobile-view-host[data-mobile-table-view="cards"] table.sonic-default-light-table tbody tr > td:not([data-label]):before { content:''; }
}
@media (min-width:1200px){.sonic-mobile-table-view-switch{display:none!important}.sonic-mobile-view-host{overflow-x:auto!important}}

/* Sonic v157: title, company logo and branding on mobile login. */
.sonic-auth-mobile-brand { display:none; }
@media (max-width:991.98px){
 .sonic-auth-shell .sonic-auth-panel {flex-direction:column;justify-content:center;gap:22px;min-height:100dvh;padding:72px 18px 28px;}
 .sonic-auth-mobile-brand {display:flex;align-items:center;justify-content:center;flex-direction:column;gap:12px;width:min(100%,480px);margin:0 auto 6px;padding:22px 18px;border:1px solid var(--bs-border-color);border-radius:18px;background:var(--bs-card-bg,#fff);text-align:center;box-shadow:0 6px 22px rgba(25,35,55,.06)}
 .sonic-auth-mobile-brand img {width:min(275px,86%)!important;height:90px!important;max-height:90px;object-fit:contain!important;transform:none!important;scale:1!important}
 .sonic-auth-mobile-brand strong {font-size:19px;color:var(--bs-heading-color);font-weight:800;}
 .sonic-auth-mobile-brand small {font-size:12px;color:var(--bs-secondary-color);font-weight:600;}
 .sonic-auth-form-wrap {width:min(100%,480px);}
}
@media(max-width:400px){.sonic-auth-mobile-brand img{height:72px!important}.sonic-auth-mobile-brand strong{font-size:17px}}
/* Toast messages always appear above modal stacking context, never affect layout. */
#sonic-toast-bottom-left.toast-container{position:fixed!important;z-index:9999999!important;bottom:14px!important;left:14px!important;top:auto!important;right:auto!important;width:min(370px,calc(100vw - 28px))!important;direction:rtl!important;font-family:Tajawal,sans-serif!important;}
#sonic-toast-bottom-left.toast-container>div{width:100%!important;font-family:Tajawal,sans-serif!important;white-space:normal!important;word-wrap:break-word!important;}

@media(min-width:1300px) and (prefers-reduced-motion:no-preference){
 html[dir="rtl"][data-layout="vertical"] .page-wrapper {transition:margin-right .2s ease,width .2s ease!important;}
 html[dir="rtl"][data-layout="vertical"] .topbar {transition:width .2s ease!important;}
 .sonic-single-sidebar {transition:right .2s ease!important;}
}
