/**
 * eCAD Bridge — Universal Responsive Design System
 * Ensures seamless, responsive layouts across:
 * - Mobile Phones (320px - 480px)
 * - Large Phones / Small Tablets (481px - 767px)
 * - Tablets (768px - 1023px, iPad portrait & landscape)
 * - Laptops (1024px - 1439px)
 * - Desktops & High-Res Displays (1440px+)
 */

/* ========================================================
   1. GLOBAL VIEWPORT & OVERFLOW CONTROL
   ======================================================== */
html, body {
  max-width: 100vw;
  overflow-x: hidden;
  box-sizing: border-box;
}

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

img, video, canvas, svg {
  max-width: 100%;
  height: auto;
}

/* Touch targets: minimum 40px for comfortable touch interactions on phones */
@media (max-width: 768px) {
  button, a.button, input[type="button"], input[type="submit"], .tab-btn, .category-pill, .article-tab, .video-tab {
    min-height: 38px;
  }
}

/* ========================================================
   2. HORIZONTAL SCROLLBAR ELIMINATION FOR TOUCH FILTER BARS
   ======================================================== */
.no-scrollbar::-webkit-scrollbar,
.scrollbar-none::-webkit-scrollbar,
#articleCategoryTabs::-webkit-scrollbar,
#videoCategoryTabs::-webkit-scrollbar,
#videoDockTabs::-webkit-scrollbar,
#topCategoryPills::-webkit-scrollbar,
#category-tabs::-webkit-scrollbar {
  display: none !important;
  width: 0 !important;
  height: 0 !important;
}

.no-scrollbar,
.scrollbar-none,
#articleCategoryTabs,
#videoCategoryTabs,
#videoDockTabs,
#topCategoryPills,
#category-tabs {
  -ms-overflow-style: none !important;
  scrollbar-width: none !important;
  -webkit-overflow-scrolling: touch;
}

/* ========================================================
   3. UNIVERSAL RESPONSIVE NAVIGATION & MOBILE DRAWER
   ======================================================== */
.ec-mobile-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  min-width: 40px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: #FFFFFF;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  padding: 0;
  z-index: 60;
}

.ec-mobile-toggle:hover,
.ec-mobile-toggle:focus-visible {
  background: rgba(249, 115, 22, 0.15);
  border-color: rgba(249, 115, 22, 0.5);
  color: #F97316;
  outline: none;
}

.ec-mobile-toggle .material-symbols-outlined {
  font-size: 24px;
  line-height: 1;
}

@media (max-width: 1023px) {
  .ec-mobile-toggle {
    display: inline-flex !important;
  }
}

/* Mobile Drawer Overlay & Panel */
.ec-mobile-drawer {
  position: fixed;
  top: 80px;
  left: 0;
  right: 0;
  bottom: auto;
  max-height: calc(100vh - 80px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: rgba(8, 13, 20, 0.98);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  padding: 18px 20px 28px;
  display: none !important;
  flex-direction: column;
  gap: 8px;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.85);
  z-index: 99;
  animation: ecDrawerAnim 0.28s cubic-bezier(0.16, 1, 0.3, 1);
}

.ec-mobile-drawer.open {
  display: flex !important;
}

@keyframes ecDrawerAnim {
  from {
    opacity: 0;
    transform: translateY(-12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.ec-mobile-drawer a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-radius: 10px;
  color: #94A3B8;
  font-family: 'Inter', sans-serif;
  font-weight: 500;
  font-size: 14px;
  text-decoration: none;
  transition: all 0.2s ease;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.ec-mobile-drawer a:hover,
.ec-mobile-drawer a.active {
  color: #F97316;
  background: rgba(249, 115, 22, 0.10);
  font-weight: 600;
  padding-left: 20px;
  border-bottom-color: rgba(249, 115, 22, 0.25);
}

.ec-mobile-drawer a .arr {
  font-size: 18px;
  opacity: 0.55;
  transition: transform 0.2s ease;
}

.ec-mobile-drawer a:hover .arr {
  opacity: 1;
  transform: translateX(3px);
  color: #F97316;
}

.ec-mobile-drawer-btn {
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 14px !important;
  border-radius: 10px;
  background: #101927;
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #FFFFFF !important;
  font-family: 'Inter', sans-serif;
  font-size: 13px !important;
  font-weight: 600;
  text-decoration: none;
  transition: all 0.2s ease;
}

.ec-mobile-drawer-btn:hover {
  background: #18243A;
  border-color: rgba(249, 115, 22, 0.4);
  color: #F97316 !important;
}

.ec-mobile-drawer-btn.primary {
  background: linear-gradient(135deg, #F97316 0%, #EA580C 100%);
  border: none;
  color: #FFFFFF !important;
  box-shadow: 0 4px 14px rgba(249, 115, 22, 0.35);
}

/* ========================================================
   4. HEADER RESPONSIVENESS ON SMALL DEVICES
   ======================================================== */
@media (max-width: 640px) {
  header .h-20 {
    height: 68px !important;
  }
  .ec-mobile-drawer {
    top: 68px !important;
    max-height: calc(100vh - 68px) !important;
  }
  main.pt-20 {
    padding-top: 68px !important;
  }
  body.pt-20 {
    padding-top: 68px !important;
  }
}

/* Hide non-essential header labels on very small mobile (< 400px) */
@media (max-width: 400px) {
  header .flex.items-center.gap-3.pl-3.border-l {
    gap: 0.5rem !important;
    padding-left: 0.5rem !important;
  }
  header a[href*="LoginPage"] span:last-child {
    display: none;
  }
  header a[href*="LoginPage"] {
    padding-left: 0.5rem !important;
    padding-right: 0.5rem !important;
  }
}

/* ========================================================
   5. SKILL LABS FULL RESPONSIVE OVERHAUL
   ======================================================== */
@media (max-width: 1080px) {
  .shell-head {
    padding: 0 14px !important;
    gap: 8px !important;
  }
  .modeswitch button {
    padding: 6px 10px !important;
    font-size: 11.5px !important;
  }
}

@media (max-width: 768px) {
  .shell-head {
    height: 58px !important;
    padding: 0 10px !important;
    gap: 6px !important;
  }
  .shell-head-left {
    gap: 6px !important;
  }
  .back-home-btn span {
    display: none !important;
  }
  .back-home-btn {
    padding: 6px 8px !important;
  }
  .logo-divider {
    display: none !important;
  }
  .logo-text .product-subtitle {
    display: none !important;
  }
  .logo-text .product-title {
    font-size: 13px !important;
  }
  .logo-img {
    height: 28px !important;
  }
  .modeswitch {
    padding: 2px !important;
    gap: 2px !important;
  }
  .modeswitch button {
    padding: 5px 8px !important;
  }
  .modeswitch button span:not(.mode-icon) {
    display: none !important;
  }
  .progress-pill-text {
    display: none !important;
  }
  .progress-pill {
    padding: 4px 8px !important;
    font-size: 11px !important;
  }
  .demo-btn span:last-child {
    display: none !important;
  }
  .demo-btn {
    padding: 6px 8px !important;
    margin-right: 0 !important;
  }
  
  /* Mobile 3-Pane Switcher in Learn View */
  .mtabs {
    display: flex !important;
    position: sticky !important;
    top: 58px !important;
    z-index: 40 !important;
    background: #080D14 !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1) !important;
  }
  .learn-workspace {
    display: block !important;
    height: calc(100vh - 100px) !important;
    overflow-y: auto !important;
  }
  .content-col, .play-col {
    width: 100% !important;
  }
}

@media (max-width: 480px) {
  .shell-head-center {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .shell-head-center::-webkit-scrollbar {
    display: none;
  }
  .logo-text {
    display: none !important;
  }
}

/* ========================================================
   6. FPGEN & SYM CRAFT CAD WORKBENCH RESPONSIVENESS
   ======================================================== */
@media (max-width: 1023px) {
  /* Allow CAD Viewport to adapt height nicely on mobile and tablets */
  #cad-viewport,
  #schematic-canvas-card {
    min-height: 380px !important;
    max-height: 520px !important;
    height: 52vh !important;
  }
  
  /* Top Category dock horizontally scrollable with touch momentum */
  #topCategoryPills {
    display: flex !important;
    overflow-x: auto !important;
    white-space: nowrap !important;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px !important;
    scrollbar-width: none;
  }
  #topCategoryPills::-webkit-scrollbar {
    display: none;
  }
}

@media (max-width: 640px) {
  #cad-viewport,
  #schematic-canvas-card {
    min-height: 320px !important;
    height: 44vh !important;
  }
  .category-pill {
    padding: 0.3rem 0.75rem !important;
    font-size: 0.7rem !important;
  }
}

/* ========================================================
   7. ENGINEERING CALCULATORS RESPONSIVENESS
   ======================================================== */
@media (max-width: 768px) {
  #category-tabs {
    border-radius: 1rem !important;
    overflow-x: auto !important;
    justify-content: flex-start !important;
    padding: 0.5rem !important;
    width: 100% !important;
    max-width: 100% !important;
    -webkit-overflow-scrolling: touch;
  }
  #category-tabs .tab-btn {
    white-space: nowrap !important;
    flex-shrink: 0 !important;
    padding: 0.5rem 0.85rem !important;
    font-size: 11px !important;
  }
}

/* ========================================================
   8. CODE SNIPPETS & PRE BLOCKS OVERFLOW GUARD
   ======================================================== */
pre, code {
  max-width: 100%;
}

pre {
  overflow-x: auto !important;
  -webkit-overflow-scrolling: touch;
  word-break: normal;
  word-wrap: normal;
}

/* ========================================================
   9. TABLE & DATA GRIDS RESPONSIVENESS
   ======================================================== */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* ========================================================
   10. MODALS & DIALOGS FULL RESPONSIVENESS
   ======================================================== */
.modal-bg > div,
.modal-backdrop > div {
  max-width: min(92vw, 680px) !important;
  max-height: 90vh !important;
  overflow-y: auto !important;
  margin: auto !important;
}

/* ========================================================
   11. TOUCH-FRIENDLY UTILITIES
   ======================================================== */
@media (hover: none) and (pointer: coarse) {
  /* Enhance hit areas for touch devices */
  .category-pill, .article-tab, .video-tab, .filter-tab {
    padding-top: 0.45rem !important;
    padding-bottom: 0.45rem !important;
  }
}


/* ========================================================
   GLOBAL HIGH-CONTRAST DARK SELECT & OPTION STYLING
   ======================================================== */
select, option, optgroup {
  color-scheme: dark !important;
  background-color: #101927 !important;
  color: #F4F6FB !important;
}

select option:checked,
select option:hover {
  background-color: #1E293B !important;
  color: #F97316 !important;
}
