/**
 * NetShow Mobile Responsive Styles
 * Mobile-first responsive design for 90%+ mobile traffic.
 * 
 * Breakpoints:
 * - xs: < 576px  (phones portrait)
 * - sm: 576-767px (phones landscape, small tablets)
 * - md: 768-991px (tablets)
 * - lg: 992px+    (desktop — recommended experience)
 * 
 * Uses dvh (dynamic viewport height) for mobile address bar handling.
 */

/* ========================================
 * GLOBAL MOBILE FIXES
 * ======================================== */

/* Use dvh where supported for mobile address bar */
@supports (height: 100dvh) {
  .app-lay {
    min-height: 100dvh;
  }
  .chat-messages-container,
  .slider-container,
  .simli-container,
  #minimalActVersion {
    height: calc(100dvh - 220px) !important;
  }
}

/* Prevent horizontal overflow on mobile */
html, body {
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

/* Tap targets: 44px minimum */
a, button, .btn, .nav-link, .dropdown-item {
  min-height: 44px;
  min-width: 44px;
}

/* Smooth scrolling and momentum */
.offcanvas-body,
.chat-messages-container,
.chat-messages,
.scroll-box,
.sidebar-sections {
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* ========================================
 * PHONES (< 576px)
 * ======================================== */
@media (max-width: 575.98px) {
  /* Typography scaling */
  body {
    font-size: 15px;
  }
  
  h1, .ns-page-title { font-size: 1.5rem !important; }
  h2 { font-size: 1.25rem !important; }
  h3 { font-size: 1.1rem !important; }

  /* Navbar compact */
  #navbar {
    padding: 4px 8px !important;
  }
  
  #navbar .navbar-brand img {
    height: 28px !important;
  }
  
  .sidebarTitle {
    font-size: 13px;
  }

  /* Chat area */
  .chat-messages-container {
    height: calc(100vh - 180px) !important;
    height: calc(100dvh - 180px) !important;
  }
  
  .chat-messages {
    padding: 8px !important;
    max-width: 100% !important;
  }
  
  /* Chat input */
  .search-container-chat {
    max-width: 100% !important;
    padding: 0 8px !important;
  }
  
  .search-input-section {
    gap: 4px !important;
  }
  
  .search-input-section input,
  .search-input-section textarea {
    font-size: 16px !important; /* Prevents iOS zoom */
    padding: 10px 12px !important;
  }

  /* Agent slider */
  .slider-container {
    height: calc(100vh - 180px) !important;
    height: calc(100dvh - 180px) !important;
  }
  
  .slide {
    width: 200px !important;
    height: 200px !important;
  }
  
  .slide img {
    width: 200px !important;
    height: 200px !important;
  }

  /* Controls section */
  .controls-section {
    flex-wrap: wrap;
    gap: 4px !important;
  }
  
  .controls-section .btn {
    padding: 6px 10px !important;
    font-size: 12px !important;
  }

  /* Right sidebar — full overlay on mobile */
  .sidebar-right {
    width: 100% !important;
    min-width: 100% !important;
    position: fixed !important;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 1050;
  }

  /* Left sidebar sessions */
  .app-container .sidebar-sections {
    width: 100% !important;
  }

  /* Agent cards in grid */
  .profile-card-link-div {
    margin: 4px !important;
    border-radius: 12px !important;
  }
  
  /* Modal fullscreen on mobile */
  .modal-dialog {
    margin: 0 !important;
    max-width: 100% !important;
    height: 100% !important;
  }
  
  .modal-content {
    border-radius: 0 !important;
    height: 100% !important;
    border: none !important;
  }

  /* Footer compact */
  .netshow-footer {
    padding: 32px 16px !important;
  }
  
  .footer-links-section {
    grid-template-columns: 1fr !important;
    gap: 24px !important;
  }

  /* Page header */
  .ns-page-header-content {
    flex-direction: column;
    align-items: flex-start !important;
  }
  
  .ns-page-header-actions {
    width: 100%;
  }
  
  .ns-page-header-actions .ns-btn {
    flex: 1;
  }

  /* Cards stack */
  .ns-card {
    border-radius: var(--ns-radius-md) !important;
  }

  /* Table horizontal scroll */
  table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Hide elements not needed on mobile */
  .d-mobile-none,
  #expand_edit_container_btn,
  #right-resizer {
    display: none !important;
  }

  /* Container padding */
  .container-fluid {
    padding-left: 8px !important;
    padding-right: 8px !important;
  }

  /* ACT minimal version */
  #minimalActVersion {
    max-width: 100% !important;
    aspect-ratio: auto !important;
    height: calc(100vh - 180px) !important;
    height: calc(100dvh - 180px) !important;
  }

  /* Simli container */
  .simli-container {
    max-width: 100% !important;
    height: calc(100vh - 180px) !important;
    height: calc(100dvh - 180px) !important;
  }

  /* Desktop iframe panel — hide on phone, use full width */
  .desktop-child1 {
    width: 100% !important;
    min-width: 100% !important;
    position: fixed !important;
    top: 56px;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1040;
  }
  
  .desktop-child2 {
    width: 100% !important;
  }

  /* Breadcrumbs scroll */
  .ns-breadcrumbs {
    overflow-x: auto;
    white-space: nowrap;
    padding-bottom: 4px;
  }
}

/* ========================================
 * SMALL TABLETS / LANDSCAPE (576-767px)
 * ======================================== */
@media (min-width: 576px) and (max-width: 767.98px) {
  .chat-messages-container {
    height: calc(100vh - 200px) !important;
    height: calc(100dvh - 200px) !important;
  }
  
  .slide {
    width: 250px !important;
    height: 250px !important;
  }
  
  .sidebar-right {
    width: 320px !important;
    min-width: 320px !important;
  }
  
  .modal-dialog {
    max-width: 90% !important;
  }
}

/* ========================================
 * TABLETS (768-991px)
 * ======================================== */
@media (min-width: 768px) and (max-width: 991.98px) {
  .sidebar-right {
    width: 350px !important;
    min-width: 350px !important;
  }
  
  .desktop-child1 {
    min-width: 40% !important;
  }
}

/* ========================================
 * DESKTOP ENHANCEMENTS (992px+)
 * ======================================== */
@media (min-width: 992px) {
  /* Show desktop-only elements */
  .d-desktop-none {
    display: none !important;
  }
}

/* ========================================
 * TOUCH INTERACTIONS
 * ======================================== */
@media (hover: none) and (pointer: coarse) {
  /* Remove hover effects on touch — use active state */
  .btn:hover,
  .ns-btn:hover,
  .nav-link:hover,
  .dropdown-item:hover {
    background-color: inherit;
  }
  
  .btn:active,
  .ns-btn:active {
    transform: scale(0.97);
    transition: transform 0.1s;
  }
  
  /* Larger touch targets */
  .dropdown-item {
    padding: 10px 16px !important;
  }
  
  .nav-link {
    padding: 10px 12px !important;
  }

  /* Disable tooltips on touch */
  [data-bs-toggle="tooltip"] {
    pointer-events: auto;
  }
}

/* ========================================
 * SAFE AREA INSETS (notch/home indicator)
 * ======================================== */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .search-container-chat,
  .controls-section {
    padding-bottom: env(safe-area-inset-bottom) !important;
  }
  
  .netshow-footer {
    padding-bottom: calc(32px + env(safe-area-inset-bottom)) !important;
  }
}

/* ========================================
 * ORIENTATION
 * ======================================== */
@media (orientation: landscape) and (max-height: 500px) {
  /* Landscape phones — very limited vertical space */
  #navbar {
    padding: 2px 8px !important;
  }
  
  .chat-messages-container {
    height: calc(100vh - 120px) !important;
    height: calc(100dvh - 120px) !important;
  }
  
  .slider-container {
    height: calc(100vh - 120px) !important;
    height: calc(100dvh - 120px) !important;
  }
  
  .slide {
    width: 150px !important;
    height: 150px !important;
  }
}

/* ========================================
 * ACT CHAT / ACT CHAT LOGGED-OUT (mobile-first)
 * Scoped to ACT chat layout classes only.
 * ======================================== */
@media (max-width: 991.98px) {
  html body .desktop-container,
  html body .desktop-container .desktop-child2,
  html body .desktop-container .container-lyman {
    width: 100% !important;
    max-width: 100vw !important;
    overflow-x: hidden !important;
    overflow-x: clip !important;
  }

  html body .desktop-container {
    height: auto !important;
    min-height: 100vh !important;
    min-height: 100dvh !important;
  }

  html body .desktop-container .desktop-child2 {
    height: auto !important;
    min-height: 100vh !important;
    min-height: 100dvh !important;
  }

  html body .desktop-container .desktop-child1 {
    position: relative !important;
    top: auto !important;
    left: auto !important;
    right: auto !important;
    bottom: auto !important;
  }

  html body .desktop-container .container-lyman {
    margin: 0 !important;
    max-width: 100% !important;
    min-height: 100vh !important;
    min-height: 100dvh !important;
    border-radius: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    padding-bottom: 0 !important;
  }

  html body .desktop-container .chatbot {
    display: flex !important;
    flex-direction: column !important;
    flex: 1 1 auto !important;
    min-height: 0 !important;
    overflow: hidden !important;
  }

  html body .desktop-container #video-wrapper {
    height: clamp(180px, 38dvh, 360px) !important;
    max-height: 42dvh !important;
    overflow: hidden !important;
  }

  html body .desktop-container .video-wrapper-child1 {
    height: 100% !important;
    max-height: 100% !important;
  }

  html body .desktop-container #talk-video,
  html body .desktop-container #talk-img {
    width: 100% !important;
    height: 100% !important;
    min-height: 180px !important;
    max-height: 42dvh !important;
    object-fit: cover !important;
  }

  html body .desktop-container #video-with-canvas,
  html body .desktop-container #video-with-canvas #talk-video1,
  html body .desktop-container #video-with-canvas #shared-video {
    width: 100% !important;
    max-width: 100% !important;
    object-fit: cover !important;
  }

  html body .desktop-container .didagent__main__input {
    position: sticky !important;
    left: 0;
    right: 0;
    bottom: 0 !important;
    margin-top: auto !important;
    margin-bottom: 0 !important;
    height: auto !important;
    min-height: 64px !important;
    z-index: 1200 !important;
    background: linear-gradient(to top, rgba(8, 8, 8, 0.94), rgba(8, 8, 8, 0.72), rgba(8, 8, 8, 0)) !important;
    backdrop-filter: blur(8px);
    padding: 6px 6px calc(8px + env(safe-area-inset-bottom)) !important;
  }

  html body .desktop-container #input-2 {
    min-height: 48px !important;
    width: 100% !important;
  }

  html body .desktop-container #txtMsg,
  html body .desktop-container #txtResponse {
    font-size: 16px !important;
    min-height: 44px !important;
    line-height: 1.35 !important;
  }

  html body .desktop-container .didagent__main__input .didagaent__send__button,
  html body .desktop-container .didagent__main__input .camera-btn,
  html body .desktop-container .didagent__main__input .upload-documents-btn,
  html body .desktop-container #input-0,
  html body .desktop-container #input-last,
  html body .desktop-container .b-res-width {
    min-width: 44px !important;
    min-height: 44px !important;
  }

  html body .desktop-container .input-dialog,
  html body .desktop-container .didagent__message,
  html body .desktop-container .chat-messages,
  html body .desktop-container .chat-content,
  html body .desktop-container .chat-container {
    max-width: 100% !important;
    overflow-x: hidden !important;
  }

  html body .desktop-container .message,
  html body .desktop-container [id^="model-response-"],
  html body .desktop-container .break-words-users,
  html body .desktop-container .didagent__message {
    max-width: min(92%, 34rem) !important;
    overflow-wrap: anywhere !important;
    word-break: break-word !important;
  }

  html body .desktop-container .chat-messages .message {
    max-width: min(88%, 32rem) !important;
  }

  html body .desktop-container .message-wrapper,
  html body .desktop-container .bot-wrapper {
    width: 100% !important;
  }

  html body .desktop-container .bot-wrapper > img {
    width: clamp(30px, 8vw, 40px) !important;
    height: clamp(30px, 8vw, 40px) !important;
    margin-right: 8px !important;
    flex: 0 0 auto;
  }

  /* Sidebar / history drawers become off-canvas panels on mobile */
  html body .desktop-container #toggleSidebar1212,
  html body .desktop-container .custom-arrow {
    width: 44px !important;
    height: 44px !important;
    min-width: 44px !important;
    min-height: 44px !important;
    border-radius: 999px !important;
    background: rgba(0, 0, 0, 0.62) !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    position: fixed !important;
    left: 8px !important;
    top: calc(50% - 22px) !important;
    z-index: 1301 !important;
    touch-action: manipulation;
  }

  html body .desktop-container .custom-sidebar {
    position: fixed !important;
    left: 0 !important;
    top: 0 !important;
    bottom: 0 !important;
    width: min(86vw, 320px) !important;
    max-width: 320px !important;
    height: 100vh !important;
    height: 100dvh !important;
    transform: translateX(-105%) !important;
    transition: transform 0.25s ease !important;
    z-index: 1300 !important;
    padding-bottom: calc(16px + env(safe-area-inset-bottom)) !important;
    overflow-y: auto !important;
    opacity: 0.96 !important;
  }

  html body .desktop-container .custom-sidebar.open {
    transform: translateX(0) !important;
  }

  html body .desktop-container .sidebar-sections {
    height: auto !important;
    min-height: 0 !important;
    max-height: calc(100dvh - 96px) !important;
  }

  html body .desktop-container .chat-container {
    position: relative !important;
    width: 100% !important;
  }

  html body .desktop-container #chatSidebar.expand-sidebar {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    bottom: 0 !important;
    width: min(86vw, 320px) !important;
    transform: translateX(0) !important;
    z-index: 1250 !important;
    padding-bottom: calc(12px + env(safe-area-inset-bottom)) !important;
  }

  html body .desktop-container #chatSidebar.expand-sidebar.closed {
    transform: translateX(-105%) !important;
    width: min(86vw, 320px) !important;
  }

  html body .desktop-container #openSidebar,
  html body .desktop-container #close-chat-messages,
  html body .desktop-container #chat-hamburger-btn,
  html body .desktop-container #chat-hamburger-full-screen-btn,
  html body .desktop-container .expandchat-flex {
    min-width: 44px !important;
    min-height: 44px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
  }

  html body .desktop-container .toolbar-item > button,
  html body .desktop-container .toolbar-item > img,
  html body .desktop-container .toolbar-item > i,
  html body .desktop-container #eye-top-img,
  html body .desktop-container #eye-top-img_repl,
  html body .desktop-container .didagent__header .hamburger-i {
    min-width: 44px !important;
    min-height: 44px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
  }

  html body .desktop-container .toolbar {
    min-height: 44px !important;
    padding-inline: 4px !important;
  }

  html body .desktop-container .hamburger-modal-content {
    width: min(96vw, 640px) !important;
    margin: 4vh auto !important;
    margin: 4dvh auto !important;
    max-height: 92vh !important;
    max-height: 92dvh !important;
  }

  html body .desktop-container #videoCanvasContainerRepl {
    max-width: 100% !important;
    overflow-x: hidden !important;
  }
}

@media (max-width: 575.98px) {
  html body .desktop-container #video-wrapper {
    height: clamp(160px, 34dvh, 300px) !important;
    max-height: 36dvh !important;
  }

  html body .desktop-container .didagent__main__input {
    gap: 4px !important;
    padding-inline: 4px !important;
  }

  html body .desktop-container .chat-messages .message,
  html body .desktop-container .message {
    max-width: 94% !important;
    font-size: 0.9rem !important;
  }

  html body .desktop-container .message-wrapper {
    margin-bottom: 6px !important;
  }

  html body .desktop-container .custom-sidebar,
  html body .desktop-container #chatSidebar.expand-sidebar,
  html body .desktop-container #chatSidebar.expand-sidebar.closed {
    width: min(90vw, 300px) !important;
  }

  html body .desktop-container .dropup-content {
    left: auto !important;
    right: 0 !important;
    top: auto !important;
    bottom: 100% !important;
    max-width: min(92vw, 280px) !important;
  }
}

@media (max-width: 399.98px) {
  html body .desktop-container .b-res-width,
  html body .desktop-container #input-0,
  html body .desktop-container #input-last {
    min-width: 44px !important;
    width: 44px !important;
  }

  html body .desktop-container #txtMsg {
    padding-inline: 10px !important;
  }
}

/* ========================================
 * PRINT (hide nav/sidebar)
 * ======================================== */
@media print {
  .offcanvas,
  #navbar,
  .sidebar-right,
  .controls-section,
  .netshow-footer {
    display: none !important;
  }
  
  .app-lay,
  .main-wrapper {
    width: 100% !important;
    margin: 0 !important;
  }
}
