/*
 * Insurensa responsive layer.
 *
 * Loaded last, after the theme and the table styles, so it can correct the
 * theme's desktop-first assumptions without fighting specificity.
 *
 * Breakpoints follow the theme's own Bootstrap 4 scale:
 *   < 992px  the sidebar becomes an off-canvas drawer
 *   < 768px  data tables restack as labelled rows; header collapses to essentials
 *   < 576px  tighter gutters, full-width actions
 */

/* --- Brand mark -----------------------------------------------------------
 *
 * The theme sizes `.logo-src` as a background image and swaps in narrow
 * variants when the sidebar collapses. Both shells render a real <img>
 * instead, so the image itself must be constrained — otherwise the collapsed
 * state drops the width rule and the wordmark renders at its natural size,
 * spilling out of the header and over the page.
 */
.app-header__logo .logo-src,
.app-sidebar .logo-src {
  height: 60px;
  width: auto;
  max-width: 200px;
  background: none !important;
  display: flex;
  align-items: center;
  overflow: hidden;
}

.logo_img {
  height: 38px;
  width: auto;
  max-width: 100%;
  object-fit: contain;
}

/* Collapsed rail: show only the shield, cropped from the wordmark. */
.closed-sidebar .app-header__logo .logo-src {
  max-width: 46px;
}
.closed-sidebar .logo_img {
  height: 32px;
  max-width: none;
  object-position: left center;
}

/* --- Off-canvas drawer ----------------------------------------------------
 * Below 992px the sidebar sits off screen until the header's hamburger opens
 * it. Before this, the drawer had no trigger at all and phones were left with
 * no navigation.
 */
.sidebar-backdrop {
  display: none;
}

@media (max-width: 991.98px) {
  .app-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    z-index: 1040;
    background: #fff;
    padding-top: 60px;
  }

  .sidebar-mobile-open .app-sidebar {
    transform: translateX(0);
  }

  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(24, 28, 38, 0.45);
    z-index: 1035;
  }
  .sidebar-backdrop[hidden] {
    display: none;
  }

  /* Content spans the full width; the drawer floats above it. */
  .app-main__outer {
    padding-left: 0;
  }

  /* The desktop collapse control is meaningless here. */
  .app-header__logo .header__pane {
    display: none;
  }
  .app-header__mobile-menu {
    display: flex;
    align-items: center;
  }
}

@media (prefers-reduced-motion: reduce) {
  .app-sidebar {
    transition: none;
  }
}

/* --- Header ---------------------------------------------------------------
 * The right-hand cluster (rating, company, sign-out) does not fit beside the
 * logo on a phone. Drop the decorative parts and keep the actions.
 */
@media (max-width: 991.98px) {
  /* The theme hides the header logo below its desktop breakpoint, which leaves
     the bar unbranded on phones and tablets. Show a compact mark instead. */
  .app-header__logo,
  .app-header__logo .logo-src {
    display: flex !important;
    align-items: center;
  }
  .app-header__logo {
    width: auto;
    min-width: 0;
    padding-left: 12px;
  }
  .app-header__logo .logo-src {
    height: 44px;
    max-width: 150px;
    padding-left: 0;
  }
  .logo_img {
    height: 30px;
  }
}

@media (max-width: 767.98px) {
  .app-header {
    padding-right: 8px;
  }
  .app-header__logo {
    width: auto;
    min-width: 0;
    padding-left: 10px;
  }
  .app-header-right .header-user-info,
  .app-header-right .centered-reviews {
    display: none;
  }
  .app-header-right .btn {
    padding: 6px 10px;
    font-size: 13px;
  }
  .app-header-right {
    gap: 6px;
  }
}

/* --- Page title -----------------------------------------------------------*/
@media (max-width: 767.98px) {
  .app-page-title {
    padding: 16px 14px;
  }
  .app-page-title .page-title-icon {
    display: none;
  }
  .page-title-heading {
    font-size: 20px;
  }
  .page-title-subheading {
    font-size: 12.5px;
  }
  /* Header actions wrap under the title rather than squeezing beside it. */
  .page-title-actions {
    margin-left: 0 !important;
    margin-top: 10px;
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
  }
}

/* --- Data tables as stacked rows ------------------------------------------
 *
 * A seven-column grid is unusable at 375px. Below the tablet breakpoint each
 * row becomes its own block, with the column name from `data-label` shown
 * beside the value. Horizontal scrolling a wide table on a phone is
 * technically "responsive" but nobody reads it that way.
 */
@media (max-width: 767.98px) {
  table.dataTable thead {
    /* Removed outright rather than visually hidden: an off-screen header row
       still lays its cells out at full table width and pushes the page wider
       than the viewport. Each cell carries its own label via data-label, so
       nothing is lost. */
    display: none;
  }

  table.dataTable,
  table.dataTable tbody,
  table.dataTable tr,
  table.dataTable td {
    display: block;
    width: 100%;
    /* DataTables ships `box-sizing: content-box` on cells, so a `width: 100%`
       stacked cell came out 100% *plus* its 24px of horizontal padding and
       overflowed the row by exactly that much — the values on the right of
       every card ended up clipped by the scroll container. */
    box-sizing: border-box;
  }

  table.dataTable tr {
    border: 1px solid #e9ecef;
    border-radius: 8px;
    margin-bottom: 10px;
    padding: 4px 0;
    background: #fff;
  }

  table.dataTable td {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    border: 0;
    padding: 7px 12px;
    text-align: left !important;
  }

  table.dataTable td::before {
    content: attr(data-label);
    flex: 0 0 40%;
    font-size: 11.5px;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    color: #6c757d;
  }

  /* A cell with no label (the actions column) spans the full width. */
  table.dataTable td:not([data-label])::before,
  table.dataTable td[data-label='']::before {
    content: none;
  }
  table.dataTable td:not([data-label]),
  table.dataTable td[data-label=''] {
    justify-content: flex-start;
    padding-top: 10px;
  }
  table.dataTable td:not([data-label]) .btn {
    width: 100%;
  }

  /* The empty-state row must not be split into label/value. */
  table.dataTable td.dataTables_empty {
    display: block;
    text-align: center !important;
  }
  table.dataTable td.dataTables_empty::before {
    content: none;
  }

  /* Restacked cells own their line, so the desktop nowrap is unnecessary. */
  table.dataTable td.nowrap {
    white-space: normal;
  }
}

/* --- Table toolbar --------------------------------------------------------*/
@media (max-width: 767.98px) {
  .dataTables_wrapper .row > [class*='col-'] {
    flex: 0 0 100%;
    max-width: 100%;
  }
  .dt-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
  }
  .dt-buttons .btn {
    flex: 1 1 auto;
    min-height: 40px;
    margin-right: 0;
  }
  .dataTables_filter {
    text-align: left;
  }
  .dataTables_filter label,
  .dataTables_length label {
    width: 100%;
  }
  .dataTables_filter input {
    width: 100%;
    min-width: 0;
    min-height: 42px;
  }
  .dataTables_paginate {
    text-align: center;
  }
  .dataTables_paginate .pagination {
    justify-content: center;
    flex-wrap: wrap;
  }
  .dataTables_info {
    display: block;
    text-align: center;
  }
}

/* --- Cards, forms and touch targets --------------------------------------*/
@media (max-width: 767.98px) {
  .app-main__inner {
    padding: 14px 12px;
  }
  .card-body {
    padding: 14px 12px;
  }
  .main-card {
    margin-bottom: 14px;
  }

  /* 16px prevents iOS zooming the viewport on focus; 44px is a comfortable
     touch target. */
  .form-control,
  .custom-select,
  select.form-control {
    font-size: 16px;
    min-height: 44px;
  }
  .btn {
    min-height: 42px;
  }
  .btn-sm {
    min-height: 36px;
  }

  /* Stat tiles go one per row rather than four across. */
  .card.widget-content {
    height: auto;
  }

  /* Property lists: label above value. */
  .property-list th,
  .property-list td {
    display: block;
    width: 100% !important;
    border-top: 0;
    padding: 4px 12px;
  }
  .property-list th {
    padding-top: 10px;
    font-size: 11.5px;
    text-transform: uppercase;
    color: #6c757d;
  }
  .property-list tr {
    display: block;
    border-top: 1px solid #f0f1f3;
  }
  .property-list tr:first-child {
    border-top: 0;
  }
}

@media (max-width: 575.98px) {
  .app-main__inner {
    padding: 12px 10px;
  }
  /* Footer actions stack and go full width. */
  .modal-footer .btn,
  .card-body > form > .btn {
    width: 100%;
  }
}

/* --- Tablet: keep wide tables inside their card ---------------------------
 *
 * Between the stacking breakpoint and the desktop layout a seven-column table
 * is still wider than the viewport. It stays a table there — that width is
 * readable on a tablet — but it must scroll within its own card rather than
 * widening the page.
 */
@media (min-width: 768px) and (max-width: 991.98px) {
  .dataTables_wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .dataTables_wrapper table.dataTable {
    min-width: 720px;
  }
}

/* --- Touch targets --------------------------------------------------------
 * Pagination and sort controls are comfortably tappable on touch screens.
 */
@media (max-width: 991.98px) {
  .dataTables_paginate .page-link {
    min-width: 40px;
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  .dataTables_length select {
    min-height: 40px;
  }
}

/* --- Header actions below the desktop breakpoint --------------------------
 *
 * The theme parks `.app-header__content` off to one side under 992px —
 * `position: absolute; visibility: hidden; opacity: 0`, styled as a floating
 * white pill — and reveals it by adding `header-mobile-open`, a class its own
 * jQuery plugin toggles from a second hamburger. Both shells here are React and
 * render no such control, so on every phone and tablet the header collapsed to
 * a bare logo: no sign-out, no language toggle, no rating widget. The controls
 * still occupied layout boxes, which is why they looked present to a DOM probe
 * while painting nothing at all.
 *
 * Rather than reintroduce a hamburger for three controls, lay the content out
 * inline. It fits: the account name and the rating widget are already hidden at
 * these widths, leaving the language toggle and the sign-out button.
 *
 * The selectors below carry the theme's own `.app-header` prefix deliberately —
 * a bare `.app-header__content` loses to it on specificity no matter how late
 * this stylesheet loads.
 */
@media (max-width: 991.98px) {
  .app-header .app-header__content {
    position: static;
    visibility: visible;
    opacity: 1;
    overflow: visible;
    order: 3;
    flex: 1 1 auto;
    min-width: 0;
    width: auto;
    left: auto;
    top: auto;
    padding: 0;
    background: transparent;
    border-radius: 0;
    box-shadow: none;
    justify-content: flex-end;
  }

  /* The left-hand nav slot is empty in both shells. */
  .app-header .app-header__content .app-header-left {
    display: none;
  }

  .app-header .app-header__content .app-header-right {
    margin-left: auto;
    padding-right: 8px;
    flex-wrap: nowrap;
    align-items: center;
  }

  /* The theme's reveal button would now toggle something already visible. */
  .app-header .app-header__menu {
    display: none;
  }
}

/* --- Small-screen header budget -------------------------------------------
 *
 * With the header actions restored above, 375px has to carry the drawer
 * toggle, the wordmark, the language toggle, the portal's "My reviews" call to
 * action and sign-out. That does not fit, and the overflow widened the page
 * enough to clip the stacked table rows beside it.
 *
 * Sign-out is the one control with no other route to it, so it stays. The
 * "My reviews" button goes: it is the same destination as the sidebar entry
 * one tap away in the drawer.
 */
@media (max-width: 767.98px) {
  .app-header .header-dots .btn {
    display: none;
  }

  .app-header .app-header__logo {
    padding-left: 6px;
  }
  .app-header .app-header__logo .logo-src {
    max-width: 110px;
  }
}

@media (max-width: 575.98px) {
  /* Below this the wordmark is the first thing worth trading away: the drawer
     toggle and the page title already say where the user is. */
  .app-header .app-header__logo {
    display: none !important;
  }
}
