/* RESPONSIVE STYLES (Media Queries) */
html, body {
    max-width: 100%;
    overflow-x: hidden !important; 
    position: relative;
}

.app-container, .main-wrapper {
    max-width: 100vw; 
    overflow-x: hidden;
}

/* [ui-view] is split out of the rule above and uses `clip` instead of
   `hidden` DELIBERATELY. `overflow-x: hidden` with an unset overflow-y forces
   the other axis to compute as `auto` (CSS Overflow 3), which quietly turned
   the routed-view wrapper into a VERTICAL clipping box. Because [ui-view]
   hugs its content height exactly, any absolutely-positioned popover near the
   bottom of a page got cut off at the last element - e.g. the mm-date-picker
   popover on the lower "Gültig ab" row of Übersicht > Kernkonditionen lost its
   last ~25px even after the card's own overflow was fixed.
   `overflow-x: clip` still blocks horizontal overflow (the reason this rule
   exists) but leaves overflow-y as `visible`, so nothing is clipped vertically.
   Kept off .app-container/.main-wrapper on purpose: .main-wrapper contains the
   `position: sticky` .header, and turning it from a scroll container into a
   non-scrolling one would change whether that header sticks - a behaviour
   change unrelated to this fix. */
[ui-view] {
    max-width: 100vw;
    overflow-x: clip;
}
/* Large screens / Tablets (up to 1200px) */
@media (max-width: 1200px) {
  .quick-actions-grid-simple {
    grid-template-columns: repeat(3, 1fr) !important;
  }
}

/* Tablets (up to 1371px) */
@media (max-width: 1371px) {
  .mobile-menu-btn {
    display: block;
  }

  .grid-cols-3, .grid-cols-4 {
      grid-template-columns: repeat(2, 1fr) !important;
  }

  .activity-chart-area,
  .system-status-area {
    grid-template-columns: 1fr !important;
  }

  /* Data Center 1024px Adjustments (iPad Landscape) */
  .max-w-7xl {
    max-width: 100% !important;
    width: 100% !important;
    overflow-x: hidden;
  }

  .max-w-7xl .grid-cols-2 {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 16px !important;
  }

  /* Use auto-fit for Data Center grids: adapts 2 or 3 columns based on available space */
  .max-w-7xl .grid-cols-3,
  .insights-grid {
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)) !important;
    gap: 16px !important;
  }

  .datacenter-filters {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    gap: 16px;
  }

  .datacenter-filters .segmented-control {
    width: auto;
    max-width: 100%;
    overflow-x: auto;
  }

  .datacenter-filters .flex.space-x-2 {
    width: auto;
    justify-content: flex-end;
  }

  .card-header {
    flex-wrap: wrap;
    gap: 12px;
  }

  .ae-unit-list {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }

  /* Academy View Responsive */
  .academy-stats-grid {
    grid-template-columns: repeat(2, 1fr);
    width: calc(100% + 48px);
    margin-left: -24px;
    padding: 24px;
  }

  .academy-hero {
    padding: 32px 24px 0 24px;
  }

 
  
  /* iPad Landscape specific grid for Mission Control */
  @media (min-width: 769px) and (max-width: 1024px) {
    .camera-section {
       grid-column: span 2;
       order: -1;
    }
    .joystick-section {
       grid-column: 1;
    }
    .quick-actions-section {
       grid-column: 2;
    }
  }

  .camera-section-header {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .camera-controls {
    flex-wrap: wrap;
    justify-content: center;
  }

  .camera-switcher {
    margin-right: 0;
    flex-wrap: wrap;
    justify-content: center;
  }

  .component-status-grid {
    grid-template-columns: 1fr;
  }

  .mission-grid {
    grid-template-columns: 1fr;
  }
    
  .positions-list {
    flex-direction: row;
    flex-wrap: wrap;
  }
    
  .position-btn {
    flex: 1;
    min-width: 150px;
  }

  /* Mission Detail Responsive */
  .mission-screen-layout {
    flex-direction: column;
  }

  .mission-screen-layout .screen-column,
  .mission-screen-layout .controls-column {
    flex: 0 0 100%;
    max-width: 100%;
  }

  .info-cards-row {
    grid-template-columns: 1fr;
  }

  .subscription-plan-grid {
    grid-template-columns: 1fr !important;
  }

  /*.status-panel {
    flex-direction: column;
    align-items: stretch;
  }*/

  .hidden-mobile {
    display: none !important;
  }

  .about-hero-title {
    font-size: 1.75rem !important;
  }

  .about-hero-version {
    font-size: 1.1rem !important;
  }

  .about-hero-description {
    font-size: 1rem !important;
  }

  .modal-overlay {
    padding: 16px;
  }

  .form-row {
    grid-template-columns: 1fr !important;
  }

  .settings-row {
    flex-direction: column;
    align-items: flex-start !important;
    gap: 12px;
  }

  .settings-row select {
    width: 100% !important;
  }
}

/* Small Tablets / Large Phones (up to 768px) */
@media (max-width: 768px) {
  .grid-cols-2,
  .grid-cols-3,
  .grid-cols-4,
  .max-w-7xl .grid-cols-2,
  .max-w-7xl .grid-cols-3,
  .insights-grid {
    grid-template-columns: 1fr !important;
    width: 100% !important;
  }

  .quick-actions-grid-simple {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  .header-btn .btn-text {
    display: none;
  }

  .welcome-banner-title {
    font-size: 24px;
  }

  .welcome-banner-text {
    font-size: 14px;
  }

  .card {
    padding: 16px;
  }

  .main-content {
    padding: 16px;
  }
  .login-page {
    flex-direction: column;
  }
  /* Data Center Mobile */
  .max-w-7xl {
    max-width: 100% !important;
    width: 100% !important;
    padding: 0;
    overflow-x: hidden;
  }

  /* Academy Mobile */
  .academy-stats-grid {
    grid-template-columns: 1fr;
    width: calc(100% + 32px);
    margin-left: -16px;
    padding: 16px;
  }

  .welcome-banner {
    padding: 16px;
    margin-bottom: 16px;
  }

  /* Mission Control Mobile */
  .status-panel {
    padding: 12px;
    justify-content: center;
  }

  .status-item {
    width: 100%;
    justify-content: space-between;
    border-bottom: 1px solid rgba(0,0,0,0.05);
    padding: 8px 0;
  }

  .status-item:last-child {
    border-bottom: none;
    justify-content: center;
  }

  .status-item .stop-btn {
    width: 100%;
    padding: 12px;
    font-size: 16px;
    font-weight: bold;
    justify-content: center;
  }

  .joystick-info {
    justify-content: center !important;
  }

  body.dark .status-item {
    border-bottom-color: rgba(255,255,255,0.05);
  }

  .camera-grid-layout {
    grid-template-columns: 1fr !important;
    grid-template-rows: auto !important;
  }

  .camera-grid-cell {
    aspect-ratio: 16/9;
  }

  .camera-live-container {
    min-height: 300px;
  }

  .camera-live-iframe {
    min-height: 300px;
  }

  .lift-buttons {
    flex-direction: column;
  }

  .robot-selector {
    flex-direction: column;
  }

  /* Profile View Mobile */
  .profile-grid {
    display: flex;
    flex-direction: column;
  }

  .profile-sidebar,
  .profile-main-content {
    flex: 0 0 100%;
    max-width: 100%;
  }

  .mission-grid-4col {
    grid-template-columns: 1fr;
  }
  .p-4 {
      padding: 1rem !important;
  }
  .table-container {
      width: 100%;
      overflow-x: auto; 
      -webkit-overflow-scrolling: touch;
      display: block;
      padding-bottom: 10px; 
  }
  table {
      min-width: 600px;
      width: 100%;
  }
  
  th, td {
      white-space: nowrap;
      padding: 12px 15px;
  }
}

/* Mobile Phones (up to 480px) */
@media (max-width: 480px) {
  .ae-unit-list {
    grid-template-columns: 1fr;
  }

  .quick-actions-grid-simple {
    grid-template-columns: 1fr !important;
  }

  .lift-position-input {
    flex-direction: column;
    align-items: stretch;
  }

  .lift-position-input .form-input,
  .lift-position-input .btn {
    width: 100%;
  }

  .position-selector-controls {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .position-selector-controls .btn,
  .position-selector-controls select {
    width: 100%;
  }

  .toast-container {
    top: 10px;
    right: 10px;
    left: 10px;
  }
    
  .toast {
    min-width: auto;
    max-width: none;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  .joystick-info {
    flex-direction: column;
    gap: 15px;
    padding: 15px;
  }

  .joystick-info .btn-group {
    width: 100%;
    display: flex;
  }

  .joystick-info .btn-group .btn {
    flex: 1;
    padding: 12px;
    font-size: 14px;
  }

  .webrtc-status-badge {
    margin-left: 0;
    width: 100%;
    justify-content: center;
  }

  .status-item .status-badge {
    font-size: 13px;
    padding: 6px 12px;
  }

  .arrow-key {
    width: 70px;
    height: 60px;
  }

  .joystick-zone-container {
    width: 180px;
    height: 180px;
  }

  .segmented-control {
    overflow-x: auto;
    white-space: nowrap;
    justify-content: flex-start !important;
  }

  .segmented-item {
    flex: 0 0 auto;
  }
}

/* Landscape / Special cases */
@media (max-width: 1400px) {
  .mission-grid-4col {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Desktop-only elements */
@media (min-width: 769px) {
  .login-branding {
    display: flex;
  }

  .login-form-container {
    width: 50%;
  }

  .mobile-logo {
    display: none;
  }
}
@media (max-width: 1570px) {
  .mission-control-grid {
    display: grid;
    grid-template-columns: 3fr 7fr;
    gap: 20px;
    margin-bottom: 20px;
  }
}
@media (max-width: 1024px) {
  .mission-control-grid {
    grid-template-columns: repeat(2, 1fr); 
    gap: 16px;
  }
  
  .camera-section {
    grid-column: span 2;
    order: -1; 
  }
  
  .joystick-section {
    grid-column: 1;
  }
  .quick-actions-section {
    grid-column: 2;
  }
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 9999;
    transform: translateX(-100%); 
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  }

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

  .main-wrapper {
    margin-left: 0 !important;
    width: 100% !important;
    transition: none; 
  }

  .mobile-menu-btn, 
  .sidebar-toggle {
    display: block;
  }
}
@media (max-width: 768px) {
  .mission-control-grid {
    grid-template-columns: 1fr !important;
  }
  
  .camera-section,
  .joystick-section,
  .quick-actions-section {
    grid-column: span 2;
    order: 0; 
  }
}

/* Adjustments for Positions Section on small screens */
@media (max-width: 480px) {
    .pos-action-bar {
        flex-wrap: wrap;
    }
    .pos-dropdown-select {
        flex: 0 0 100%;
        margin-bottom: 4px;
    }
    .btn-nav-go, .btn-nav-edit, .btn-nav-del, .btn-nav-cancel {
        flex: 1;
        font-size: 10px !important;
        padding: 4px !important;
    }
    .charging-item-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 5px;
    }
    .charging-item-row .btn {
        width: 100%;
    }
}

/* Ensure positions are not hidden on ultra-wide screens */
@media (min-width: 1571px) {
    .mission-control-grid {
        grid-template-columns: 350px 1fr 350px !important;
        gap: 30px !important;
    }
    .pos-dropdown-select {
        font-size: 14px;
        min-width: 120px;
    }
    .btn-nav-go, .btn-nav-edit, .btn-nav-del, .btn-nav-cancel {
        padding: 8px 12px !important;
    }
}