/*
 * Clickwise responsive contract.
 *
 * This layer is loaded after both the legacy and modern dashboards so the
 * shared React shell behaves consistently on every route. Keep desktop
 * layout rules in base.css/modern.css; this file owns narrow-screen safety,
 * touch targets and scroll containment.
 */

:root {
  --cw-mobile-topbar-height: 58px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

.dashboard-shell,
.dashboard-body,
.dashboard-body > div,
.topBarContainer,
.topBarLeftContainer {
  min-width: 0;
}

.mobile-navigation-backdrop {
  border: 0;
  margin: 0;
  padding: 0;
}

.control-panel-button,
.topBarUserChip,
.tipBoxButton {
  font: inherit;
}

.control-panel-button,
.tipBoxButton {
  background: transparent;
  border-left: 0;
  border-right: 0;
  border-top: 0;
}

.topBarUserChip {
  cursor: pointer;
  margin: 0;
}

.tipBoxButton {
  text-align: left;
  width: calc(100% - 16px);
}

.topBarActionsScroller {
  display: contents;
}

.responsiveDataTable,
.legacy-responsive-table,
.table-responsive,
.table-container {
  max-width: 100%;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
  -webkit-overflow-scrolling: touch;
}

.responsiveDataTable:focus-visible,
.legacy-responsive-table:focus-visible,
.table-responsive:focus-visible,
.table-container:focus-visible {
  outline: 2px solid #0f766e;
  outline-offset: 2px;
}

.responsiveFilterExtra {
  align-items: center;
  display: flex;
  gap: 8px;
}

.responsiveTabList {
  max-width: 100%;
  overscroll-behavior-inline: contain;
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
}

.ai-chat-composer {
  grid-template-columns: minmax(0, 1fr) auto;
}

.chat-launcher-button {
  bottom: max(20px, env(safe-area-inset-bottom));
  right: max(20px, env(safe-area-inset-right));
}

.reactModalBackground {
  border: 0;
  margin: 0;
  padding: 0;
}

.reactModalButton {
  align-items: center;
  appearance: none;
  background: transparent;
  border: 0;
  cursor: pointer;
  display: inline-flex;
  justify-content: center;
  min-height: 44px;
  min-width: 44px;
}

@media (max-width: 639px) {
  html,
  body,
  #app,
  .dashboard-shell {
    margin: 0;
    max-width: 100%;
    min-width: 0;
    width: 100%;
  }

  html,
  body {
    overflow-x: clip;
  }

  @supports not (overflow: clip) {
    html,
    body {
      overflow-x: hidden;
    }
  }

  .top-bar {
    height: calc(var(--cw-mobile-topbar-height) + env(safe-area-inset-top));
    max-height: none;
    padding-top: env(safe-area-inset-top);
    width: 100%;
  }

  .topBarContainer,
  .topBarContainer-open,
  .topBarContainer-close,
  .dashboard-body-open,
  .dashboard-body-close {
    margin-left: 0 !important;
    max-width: 100%;
    width: 100%;
  }

  .topBarLeftContainer {
    gap: 6px;
    min-height: var(--cw-mobile-topbar-height);
    overflow: visible;
    padding: 6px 8px;
    width: 100%;
  }

  .mobile-navigation-toggle {
    min-height: 44px;
    min-width: 44px;
  }

  .topBarUserChip {
    flex: 0 1 132px;
    max-width: 132px;
    min-height: 44px;
    min-width: 0;
    overflow: hidden;
  }

  .topBarTitle {
    max-width: 76px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .topBarGroup {
    display: none;
  }

  .topBarActionsScroller {
    align-items: center;
    display: flex;
    flex: 1 1 auto;
    gap: 6px;
    min-width: 0;
    overflow-x: auto;
    overflow-y: visible;
    overscroll-behavior-inline: contain;
    padding: 2px 1px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .topBarActionsScroller::-webkit-scrollbar {
    display: none;
  }

  .currencySelector,
  .languageSelector,
  .topBar .languageSelector {
    flex: 0 0 auto;
    position: static !important;
    right: auto !important;
    top: auto !important;
  }

  .currencySelectorCover,
  .languageSelectorCover {
    align-items: center;
    display: inline-flex;
    min-height: 40px;
  }

  .languageSelectorTipContainer,
  .currencySelectorTipContainer {
    bottom: auto;
    max-height: calc(100dvh - var(--cw-mobile-topbar-height) - 16px);
    overflow-y: auto;
    position: fixed !important;
    right: 8px !important;
    top: calc(var(--cw-mobile-topbar-height) + env(safe-area-inset-top) + 2px) !important;
    z-index: 140;
  }

  .currencySelectorCoverTitle,
  .topBarActionsScroller button[title="Open command palette"] {
    display: none;
  }

  .topBarActionsScroller > span,
  .topBarActionsScroller > button {
    flex: 0 0 auto;
    margin-left: 0 !important;
  }

  .tipContainer {
    bottom: auto;
    left: 8px !important;
    max-height: calc(100dvh - var(--cw-mobile-topbar-height) - 16px);
    overflow-y: auto;
    position: fixed !important;
    right: 8px;
    top: calc(var(--cw-mobile-topbar-height) + env(safe-area-inset-top) + 2px) !important;
    width: auto !important;
    z-index: 130;
  }

  .tipBoxButton {
    min-height: 44px;
  }

  .main-sidebar-open {
    max-width: 288px;
    padding-bottom: env(safe-area-inset-bottom);
    padding-top: env(safe-area-inset-top);
    width: min(86vw, 288px) !important;
    z-index: 120 !important;
  }

  .main-sidebar-close {
    display: none !important;
  }

  .main-sidebar-open .control-panel-button,
  .main-sidebar-open .sideBar_a {
    min-height: 44px;
  }

  .main-sidebar-open .control-panel-button {
    align-items: center;
    display: flex;
    justify-content: flex-end;
  }

  .mobile-navigation-backdrop {
    z-index: 115 !important;
  }

  .dashboard-body {
    min-height: calc(100vh - var(--cw-mobile-topbar-height) - env(safe-area-inset-top));
    min-height: calc(100dvh - var(--cw-mobile-topbar-height) - env(safe-area-inset-top));
    overflow-x: clip;
    top: calc(var(--cw-mobile-topbar-height) + env(safe-area-inset-top)) !important;
  }

  .dashboard-body > .tw-px-4,
  .dashboard-body > .tw-px-6,
  .dashboard-body .tw-p-4,
  .dashboard-body .tw-p-5,
  .dashboard-body .tw-p-6 {
    padding-left: 12px;
    padding-right: 12px;
  }

  .dashboard-body img,
  .dashboard-body svg,
  .dashboard-body canvas,
  .dashboard-body video,
  .dashboard-body iframe {
    max-width: 100%;
  }

  .dashboard-body input:not([type="checkbox"]):not([type="radio"]):not([type="range"]),
  .dashboard-body select,
  .dashboard-body textarea,
  .reactModal input:not([type="checkbox"]):not([type="radio"]):not([type="range"]),
  .reactModal select,
  .reactModal textarea {
    font-size: 16px !important;
    min-height: 44px;
    max-width: 100%;
  }

  .dashboard-body button,
  .dashboard-body a.btn,
  .reactModal button,
  .reactModal a.btn {
    min-height: 42px;
  }

  .dashboard-body table.table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
  }

  .responsiveFilterBarControls {
    align-items: stretch;
  }

  .responsiveFilterSearch,
  .responsiveFilterSelect,
  .responsiveFilterExtra,
  .responsiveFilterExtra > * {
    max-width: none !important;
    min-width: 0 !important;
    width: 100%;
  }

  .filterBarDateRange {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    width: 100%;
  }

  .filterBarDateRange input {
    min-width: 0;
    width: 100%;
  }

  .responsiveFilterCount {
    margin-left: 0 !important;
    width: 100%;
  }

  .reactModal {
    height: 100vh;
    height: 100dvh;
  }

  .reactModalContainer {
    border-radius: 10px;
    height: auto;
    left: max(8px, env(safe-area-inset-left));
    max-height: calc(100dvh - max(8px, env(safe-area-inset-top)) - max(8px, env(safe-area-inset-bottom)));
    max-width: none;
    right: max(8px, env(safe-area-inset-right));
    top: max(8px, env(safe-area-inset-top));
    transform: none;
    width: auto;
  }

  .reactModalHeader {
    min-height: 52px;
  }

  .reactModalButton {
    right: 4px;
    top: 4px;
  }

  .reactModalContent {
    max-height: calc(100dvh - 150px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    overflow: auto;
    padding: 14px;
    -webkit-overflow-scrolling: touch;
  }

  .reactModalFooter {
    flex-wrap: wrap;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }

  .chat-launcher-button {
    bottom: max(12px, env(safe-area-inset-bottom));
    right: max(12px, env(safe-area-inset-right));
  }

  .impersonation-banner {
    align-items: stretch;
    bottom: 0;
    flex-direction: column;
    max-height: min(42dvh, 180px);
    overflow-y: auto;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    top: auto !important;
  }

  .cw-impersonating .dashboard-body {
    padding-bottom: 150px;
  }

  .cw-impersonating .chat-launcher-button {
    bottom: calc(150px + env(safe-area-inset-bottom));
  }

  .auth-reset-shell {
    min-height: 100vh;
    min-height: 100dvh;
    padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  }

  .auth-reset-shell .login-box {
    margin: clamp(24px, 9dvh, 72px) auto 24px;
    max-width: 390px;
    width: 100%;
  }

  .auth-reset-shell .topBar {
    min-width: 0;
    width: 100%;
  }

  .auth-reset-shell .topBar .logo {
    height: auto;
    max-width: min(220px, 72vw);
  }

  .ai-chat-drawer {
    bottom: calc(76px + env(safe-area-inset-bottom)) !important;
    height: min(560px, calc(100dvh - 96px - env(safe-area-inset-top) - env(safe-area-inset-bottom))) !important;
    left: max(8px, env(safe-area-inset-left));
    right: max(8px, env(safe-area-inset-right)) !important;
    width: auto !important;
  }

  .ai-chat-composer {
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }

  .reactModalImgContainer {
    bottom: max(8px, env(safe-area-inset-bottom));
    left: max(8px, env(safe-area-inset-left));
    max-height: calc(100dvh - 16px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    max-width: none;
    overflow: auto;
    right: max(8px, env(safe-area-inset-right));
    top: max(8px, env(safe-area-inset-top));
    transform: none;
  }

  .reactModalImgContainer img {
    height: auto;
    max-height: calc(100dvh - 16px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    object-fit: contain;
    width: auto;
  }
}

@media (max-width: 359px) {
  .topBarUserChip {
    flex-basis: 108px;
    max-width: 108px;
  }

  .topBarTitle {
    max-width: 54px;
  }

  .filterBarDateRange {
    grid-template-columns: 1fr;
  }

  .filterBarDateRange > span {
    display: none;
  }

  .reactModalFooter .btn,
  .reactModalFooter button {
    width: 100%;
  }
}

@media (min-width: 640px) and (max-width: 820px) {
  .main-sidebar-open {
    width: 190px;
  }

  .dashboard-body-open,
  .topBarContainer-open {
    margin-left: 190px;
  }
}
