/**
 * Mobile-friendly responsive styles
 * Centralized file - no logic changes, CSS/UI only
 * Breakpoints: 768px (tablet), 576px (mobile)
 */

/* ========== Hamburger menu toggle button ========== */
.btn-menu-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  margin-right: 8px;
  background: transparent;
  border: none;
  cursor: pointer;
  border-radius: 4px;
}

.btn-menu-toggle:hover {
  background: rgba(0, 0, 0, 0.05);
}

.btn-menu-toggle:focus {
  outline: none;
}

.menu-toggle-icon {
  display: block;
  width: 24px;
  height: 24px;
  object-fit: contain;
}

/* Show only hamburger when menu is closed */
.menu-toggle-close {
  display: none !important;
}

body.mobile-menu-open .menu-toggle-hamburger {
  display: none !important;
}

body.mobile-menu-open .menu-toggle-close {
  display: block !important;
}

/* Prevent body scroll when menu is open */
body.mobile-menu-open {
  overflow: hidden;
}

/* Menu overlay - when menu is open */
.menu-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 998;
  opacity: 0;
  transition: opacity 0.3s ease;
}

body.mobile-menu-open .menu-overlay {
  display: block;
  opacity: 1;
}

/* ========== Auth pages (Login/Signup/Welcome) - stack top-bottom at 992px ========== */
@media (max-width: 992px) {
  .auth-split-layout,
  .main-container .d-flex:has(.logo-section) {
    flex-direction: column !important;
  }

  .auth-split-layout > .w-50,
  .main-container .d-flex:has(.logo-section) > .w-50 {
    width: 100% !important;
    float: none !important;
    max-width: 100% !important;
  }

  .auth-split-layout > .logo-section,
  .main-container .d-flex:has(.logo-section) > .logo-section {
    min-height: auto !important;
    padding: 24px 16px !important;
    order: 1;
  }

  .auth-split-layout > .form-section,
  .auth-split-layout > .w-50:not(.logo-section),
  .main-container .d-flex:has(.logo-section) > .form-section,
  .main-container .d-flex:has(.logo-section) > .w-50:not(.logo-section) {
    order: 2;
    padding: 24px 16px !important;
    flex: 1 1 auto;
    min-height: min-content;
    overflow: visible;
  }

  /* Allow auth layout to grow so bottom content (Submit, Already registered?) is visible */
  body.login-layout .auth-split-layout,
  body.login-layout form .auth-split-layout {
    min-height: auto;
    height: auto !important;
  }
  body.login-layout form.h-100,
  body.login-layout .auth-pages-wrapper {
    min-height: auto;
    height: auto !important;
  }

  .auth-split-layout .logo-section,
  .main-container .d-flex:has(.logo-section) .logo-section {
    overflow-x: hidden;
    min-height: 0 !important;
  }

  .auth-split-layout .logo-section img,
  .main-container .d-flex:has(.logo-section) .logo-section img {
    max-width: 200px;
  }

  .auth-split-layout .form-section h1,
  .auth-split-layout .form-section > div h1,
  .main-container .d-flex:has(.logo-section) .form-section h1,
  .main-container .d-flex:has(.logo-section) .w-50:not(.logo-section) h1 {
    font-size: 32px;
  }
}

/* ========== Tablet and below (768px) ========== */
@media (max-width: 768px) {
  .btn-menu-toggle.d-inline-flex {
    display: inline-flex !important;
  }

  .header-center-div > div {
    margin-bottom: 4px;
    text-align: center;
  }

  /* Hide vertical nav by default on mobile - show only when menu-open */
  #prospect-tab.custom-tabs.ui-tabs.ui-tabs-vertical .ui-tabs-nav {
    position: absolute !important;
  }

  .custom-tabs.ui-tabs.ui-tabs-vertical > .ui-tabs-nav {
    display: none !important;
  }

  body.mobile-menu-open .custom-tabs.ui-tabs.ui-tabs-vertical > .ui-tabs-nav {
    display: flex !important;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    max-width: 85vw;
    z-index: 999;
    flex-direction: column;
    flex-wrap: nowrap;
    align-items: stretch;
    margin: 0;
    padding: 12px;
    padding-bottom: max(12px, env(safe-area-inset-bottom, 0px));
    background: #fff;
    box-shadow: 4px 0 12px rgba(0, 0, 0, 0.15);
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    min-height: 0;
  }

  /* prospect-screen sets overflow:unset (note submenu) and max-height on #prospect-tab nav — restore slide-out scroll */
  body.mobile-menu-open #prospect-tab.custom-tabs.ui-tabs.ui-tabs-vertical > .ui-tabs-nav {
    overflow-y: auto !important;
    overflow-x: hidden;
    max-height: none !important;
  }

  body.mobile-menu-open .custom-tabs.ui-tabs.ui-tabs-vertical {
    flex-direction: column;
  }

  body.mobile-menu-open .custom-tabs.ui-tabs.ui-tabs-vertical > .ui-tabs-nav li {
    flex: none;
    flex-shrink: 0;
    margin: 0 0 4px 0;
    width: 100%;
  }

  /* Back tab menu in slide-out */
  body.mobile-menu-open .custom-tabs.ui-tabs.ui-tabs-vertical .back-tab-menu {
    margin: 0 0 8px 0;
    width: 100%;
  }

  /* Forms submenu - ensure expand/collapse and submenu items work in slide-out */
  body.mobile-menu-open #prospect-tab .ui-tabs-nav > li.forms-submenu-item {
    display: none;
  }
  body.mobile-menu-open #prospect-tab .ui-tabs-nav > li#FormsMenu.open ~ li.forms-submenu-item {
    display: flex !important;
    padding-left: 20px;
    margin-left: 0;
  }
  body.mobile-menu-open #prospect-tab .ui-tabs-nav > li.forms-submenu-item > a {
    width: 100%;
    white-space: normal;
    word-wrap: break-word;
    overflow-wrap: break-word;
  }

  /* Header - compact layout */
  header {
    padding-left: 8px !important;
    padding-right: 8px !important;
  }

  header > div {
    flex-wrap: wrap;
    min-height: 50px;
    height: auto !important;
    padding: 6px 0 !important;
  }

  /* Menu toggle - align with logo, ensure it's first */
  .menu-section {
    display: flex;
    align-items: center;
  }
  .menu-section .btn-menu-toggle {
    flex-shrink: 0;
    order: -1;
  }

  .header-center-div {
    order: 3;
    width: 100%;
    flex-wrap: wrap;
    height: auto !important;
    padding: 4px 0;
    justify-content: flex-start;
  }

  .header-center-div > div {
    margin-bottom: 4px;
  }


  .menu-section {
    flex-shrink: 0;
  }

  .left-menu .menu-img-icon {
    height: 40px;
    max-width: 120px;
    object-fit: contain;
  }

  .left-menu .menu-img-icon-admin {
    height: 32px;
    max-width: 100px;
    object-fit: contain;
  }

  .profile-wrapper span {
    font-size: 11px;
    max-width: 80px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .profile-wrapper img {
    width: 26px;
    height: 26px;
  }

  .profile-dropdown .drop-menu {
    min-width: 120px;
    right: 0;
    left: auto;
  }

  /* Main container - skip for login/signup pages (no header) */
  body:not(.login-layout) .main-container {
    padding: 8px;
    min-height: calc(100vh - 120px);
  }

  /* Theme form header */
  .theme-form-header {
    flex-wrap: wrap;
    height: auto !important;
    padding: 8px;
  }

  .theme-form-header .form-control {
    min-width: 100%;
    max-width: 100%;
    margin-top: 6px;
  }

  /* Custom tabs - vertical layout on mobile (nav hidden by default, shown via hamburger) */
  .custom-tabs.ui-tabs.ui-tabs-vertical {
    flex-direction: column;
  }

  /* Do not override display - nav is hidden above, shown only when body.mobile-menu-open */
  .custom-tabs.ui-tabs.ui-tabs-vertical > .ui-tabs-nav {
    float: none;
    width: 100%;
    margin-right: 0;
    margin-bottom: 8px;
    padding: 4px;
    flex-wrap: wrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .custom-tabs.ui-tabs.ui-tabs-vertical > .ui-tabs-nav li {
    flex: 1 1 auto;
    min-width: fit-content;
    margin: 0 4px 4px 0;
  }

  .custom-tabs.ui-tabs.ui-tabs-vertical > .ui-tabs-panel {
    width: 100%;
  }

  /* Dialog/Modal sizing */
  .ui-dialog.ui-widget.ui-widget-content.dialog-size-lg,
  .ui-dialog.ui-widget.ui-widget-content.dialog-size-md,
  .ui-dialog.ui-widget.ui-widget-content.dialog-size-sm {
    width: 95vw !important;
    max-width: 95vw !important;
    left: 2.5vw !important;
  }

  /* DataTables */
  .dataTables_wrapper .bottom {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .dataTables_wrapper .dataTables_length,
  .dataTables_wrapper .dataTables_info {
    margin-right: 0;
  }

  /* Formio components - reduce padding on mobile */
  .formio-component-table {
    width: 100% !important;
    max-width: 100% !important;
    margin-left: 0 !important;
  }

  .formio-component-content[data-key*="primary"],
  .formio-component-content[data-key*="Primary"],
  .formio-component-content[data-key*="secondary"],
  .formio-component-content[data-key*="Secondary"],
  .formio-component-checkbox[data-key*="notApplicable"],
  .formio-component-checkbox[data-key*="NotApplicable"] {
    padding-left: 16px !important;
  }

  .formio-component-checkbox .form-check.checkbox {
    padding-left: 16px !important;
  }

  .sign-date-field {
    width: 100% !important;
  }

  .sign-date-field input {
    width: 100% !important;
  }

  /* Documents tab - Next button (full-width flex row; no float) */
  #documents .document-tab-next {
    margin-top: 8px;
  }

  #documents #lnkdocumentNxt {
    min-width: 120px;
    width: auto;
  }

  /* Search area */
  .search-menu .sub-menu .form-control {
    width: 100%;
    max-width: 200px;
  }

  /* Logo/form section - refined at 768px */
  .logo-section img {
    max-width: 200px;
  }

  .form-section > div {
    max-width: 100%;
    padding: 12px;
  }

  .auth-split-layout .form-section h1,
  .auth-split-layout .form-section > div h1,
  .auth-split-layout .w-50:not(.logo-section) h1 {
    font-size: 32px;
  }
}

/* ========== Mobile (576px and below) ========== */
@media (max-width: 576px) {
  /* Header - logo left, profile right, center content full width below */
  header > div {
    flex-wrap: wrap;
  }

  .menu-section {
    flex: 1 1 auto;
    min-width: 0;
  }

  .left-menu {
    justify-content: flex-start;
  }

  .left-menu .menu-img-icon {
    height: 36px;
    max-width: 100px;
  }

  .header-center-div {
    flex: 1 1 100%;
    order: 3;
    padding: 4px 0;
  }

  .profile-dropdown {
    flex: 0 0 auto;
  }

  .profile-wrapper span.profile-name-class,
  .profile-wrapper span {
    font-size: 10px;
    max-width: 60px;
  }

  /* Main content - full width, comfortable padding (skip for login layout) */
  body:not(.login-layout) .main-container {
    padding: 12px 8px;
    height: calc(100vh - 100px) !important;
  }

  body:not(.login-layout) .main-container.no-header-footer {
    padding: 12px 8px;
  }

  /* Buttons - full width on small screens for better touch */
  .btn-group,
  .form-inline .btn {
    width: 100%;
  }

  .btn-group .btn {
    flex: 1;
  }

  /* Tables - allow horizontal scroll */
  .table-responsive {
    -webkit-overflow-scrolling: touch;
    overflow-x: auto;
  }

  .theme-table table,
  .theme-table.flex-table table {
    min-width: 500px;
  }

  /* Reduce font sizes slightly for readability on small screens */
  body {
    font-size: 13px;
  }

  h1, .h1 { font-size: 20px; }
  h2, .h2 { font-size: 18px; }
  h3, .h3 { font-size: 16px; }
  h4, .h4 { font-size: 15px; }

  /* Form controls - larger touch targets */
  .form-control {
    min-height: 38px;
    font-size: 16px; /* Prevents zoom on iOS */
  }

  .custom-checkbox label,
  .custom-radio label {
    font-size: 14px;
  }

  /* Footer */
  footer {
    font-size: 11px;
    padding: 6px 8px;
    height: auto;
  }

  .branding-text {
    flex-wrap: wrap;
    justify-content: center;
    text-align: center;
  }

  /* Error page */
  .error-page-block > div {
    width: 95vw;
    padding: 16px;
  }

  /* Back tab menu - full width */
  a.back-tab-menu {
    width: 100%;
    margin: 0 0 8px 0;
    padding: 10px 12px;
  }

  a.back-tab-menu i {
    margin-right: 10px;
    font-size: 14px;
  }

  /* Switch box */
  .switch-box {
    flex-wrap: wrap;
  }

  .switch-box .switch-text {
    width: 100%;
    margin-bottom: 4px;
  }

  /* Dropdown - ensure it doesn't overflow */
  .dropdown .drop-menu {
    max-width: calc(100vw - 24px);
  }

  /* Spinner - scale down on mobile */
  .spinner-div img {
    max-width: 120px;
  }

  /* Login/Signup - full width on small screens */
  .logo-section img {
    max-width: 160px;
  }

  .form-section {
    padding: 12px 8px;
  }

  .form-section h1 {
    font-size: 26px;
  }
}

/* ========== Very small screens (400px and below) ========== */
@media (max-width: 400px) {
  .left-menu .menu-img-icon {
    height: 32px;
    max-width: 80px;
  }

  .main-container {
    padding: 8px 6px;
  }

  .theme-form-header {
    padding: 6px;
  }
}


