﻿/* Mobile layout for the Liftgate overview */
@media screen and (max-width: 768px), screen and (max-device-width: 768px) {
  * {
    box-sizing: border-box;
  }

  html,
  body {
    width: 100%;
    min-width: 0;
    overflow-x: hidden;
  }

  body {
    padding: 0 12px 22px;
    text-align: left;
    background: #272727;
  }

  body.status-page {
    padding-bottom: calc(90px + env(safe-area-inset-bottom));
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
  }

  body.status-page.auth-locked #pwPopup input {
    -webkit-user-select: text;
    user-select: text;
    -webkit-touch-callout: default;
  }

  .site-header {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 10px 0 4px;
  }

  .site-header a {
    display: inline-flex;
    justify-content: center;
  }

  .site-header a.logo-group {
    display: flex;
    gap: 9px;
    width: 100%;
  }

  .site-header img.logo,
  .logo {
    width: min(58vw, 190px);
    max-width: 190px;
    height: auto;
    margin: 0 auto;
  }

  .site-header .logo-group img.logo-primary {
    width: auto;
    max-width: 42vw;
    max-height: 58px;
    margin: 0;
  }

  .site-header .logo-group .logo-divider {
    height: 40px;
  }

  .site-header .logo-group .customer-logo-shell {
    flex-basis: 42vw;
    min-height: 48px;
    max-width: 42vw;
    padding: 5px 8px;
    border-radius: 7px;
  }

  .site-header .logo-group .customer-logo {
    max-height: 48px;
  }

  body.status-page:not(.auth-locked) .site-header {
    width: calc(100% + 24px);
    margin-left: -12px;
    padding: 6px 12px 5px;
  }

  body.status-page:not(.auth-locked) .site-header .logo-group img.logo-primary {
    width: auto;
    max-width: min(42vw, 205px);
  }

  .site-header .logo-group.customer-logo-missing img.logo-primary,
  body.status-page:not(.auth-locked) .site-header .logo-group.customer-logo-missing img.logo-primary {
    width: min(62vw, 205px);
    max-width: 205px;
  }

  .header-bar {
    display: none;
  }

  h1 {
    margin: 8px 0 12px;
    font-size: 22px;
    line-height: 1.15;
    text-align: center;
  }

  .overview-mode-switch {
    width: 100%;
    gap: 7px;
    margin: 10px 0 4px;
  }

  .overview-mode-button {
    flex: 1 1 0;
    min-width: 0;
    padding: 10px 8px;
    font-size: 14px;
  }

  .map-selector {
    width: 100%;
    margin: 12px 0 0;
    padding: 6px;
    gap: 8px;
    border-radius: 10px;
  }

  .map-selector-button {
    flex-basis: calc((100% - 16px) / 3);
    min-width: calc((100% - 16px) / 3);
    min-height: 42px;
    padding: 8px 5px;
    gap: 5px;
    font-size: 13px;
  }

  .public-map-shell {
    display: block;
    width: 100%;
    height: auto;
    margin: 12px 0 16px;
    padding: 6px;
    border-radius: 10px;
  }

  .map-fullscreen-close {
    display: none;
  }

  body.map-fullscreen-open {
    overflow: hidden;
  }

  .public-map-shell.map-fullscreen {
    position: fixed;
    inset: 0;
    z-index: 300;
    display: flex;
    width: 100vw;
    height: 100dvh;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: #101010;
    box-shadow: none;
  }

  .public-map-shell.map-fullscreen .public-map {
    width: 100%;
    height: 100%;
    min-height: 100%;
    border-radius: 0;
  }

  .public-map-shell.map-fullscreen .public-map-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
  }

  .public-map-shell.map-fullscreen .map-fullscreen-close {
    position: absolute;
    top: calc(10px + env(safe-area-inset-top));
    right: 10px;
    z-index: 20;
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    padding: 0;
    border: 1px solid rgba(255,255,255,.38);
    border-radius: 50%;
    background: rgba(24,24,24,.88);
    color: #fff;
    font-size: 30px;
    font-weight: 300;
    line-height: 1;
  }

  body.map-fullscreen-open .overlay { z-index: 400; }
  body.map-fullscreen-open .popup { z-index: 410; }

  .public-map { width: 100%; height: auto; min-height: 260px; border-radius: 7px; }
  .public-map.has-image { height: auto; min-height: 0; }
  .public-map > .public-map-image { height: auto; }
  .map-marker { width: 42px; height: 51px; }
  .map-marker .marker-drop { width: 35px; height: 35px; border-width: 2px; }
  .map-marker .marker-label { bottom: 49px; max-width: 130px; padding: 4px 6px; font-size: 11px; }
  .map-marker .marker-label small { font-size: 9px; }

  #torContainer {
    width: 100%;
  }

  .tor-tabs {
    width: 100%;
    max-width: none;
    margin: 18px 0 18px;
    padding: 0;
    align-items: stretch;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
  }

  .overview-section-label {
    display: block;
    width: 100%;
    margin: 0 0 6px 4px;
    color: #aaa;
    font-size: 12px;
    font-weight: 400;
    line-height: 1.2;
    text-align: left;
  }

  .assets-section-label {
    margin-top: 2px;
    margin-left: 0;
    text-align: center;
  }

  .location-section-label {
    margin-left: 0;
    text-align: center;
  }

  body.auth-locked .site-header {
    top: 0;
    padding: max(12px, env(safe-area-inset-top)) 0 12px;
  }

  body.auth-locked .site-header .logo-group img.logo-primary {
    width: auto;
    max-width: 44vw;
  }

  body.auth-locked .site-header .logo-group.customer-logo-missing img.logo-primary {
    width: min(66vw, 240px);
    max-width: 240px;
  }

  body.auth-locked #pwPopup {
    top: var(--login-popup-top, 55%);
    width: calc(100% - 32px);
    padding: 22px 18px 20px;
    border-radius: 16px;
  }

  body.auth-locked #pwPopup .login-panel-heading {
    grid-template-columns: 42px minmax(0, 1fr);
    gap: 12px;
    margin-bottom: 19px;
  }

  body.auth-locked #pwPopup .login-security-mark { width: 42px; height: 42px; border-radius: 12px; }
  body.auth-locked #pwPopup .login-security-mark::before { inset: 10px; }
  body.auth-locked #pwPopup h2 { font-size: 27px; }
  body.auth-locked #pwPopup .login-fields { gap: 12px; }

  .tab-header {
    display: flex;
    flex-wrap: wrap;
    justify-content: stretch;
    gap: 8px;
    width: 100%;
    margin: 0 0 12px;
    padding: 6px;
    overflow: visible;
    border: 1px solid #454545;
    border-radius: 10px;
    background: #222;
    box-shadow: 0 6px 18px rgba(0,0,0,.24);
  }

  .tab-btn {
    flex: 1 1 calc((100% - 16px) / 3);
    min-width: calc((100% - 16px) / 3);
    max-width: 100%;
    min-height: 42px;
    padding: 8px 5px;
    border: 1px solid #555;
    border-radius: 9px;
    background: #303030;
    color: #ddd;
    font-size: 13px;
    font-weight: 700;
    line-height: 1.15;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .tab-btn:hover {
    background: #444;
  }

  .tab-btn.active {
    border-color: #3e7e3e;
    background: #3e7e3e;
    color: #fff;
  }

  .tab-content {
    width: 100%;
    max-width: none;
    min-height: 0;
    margin: 0;
    overflow: visible;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
  }

  .ort-container {
    width: 100%;
    padding: 0;
    align-items: stretch;
  }

  .ort-container.visible {
    display: flex;
    position: relative;
  }

  .ort-container.hidden {
    display: none;
  }

  .tor-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    width: 100%;
    max-width: none;
    margin: 8px 0 6px;
    padding: 0;
    justify-items: stretch;
  }

  .tor-button {
    width: 100%;
    max-width: none;
    min-height: 58px;
    padding: 12px 14px;
    border-radius: 8px;
    font-size: 18px;
    line-height: 1.15;
    background-color: #4c8043;
    color: #fff;
    box-shadow: none;
    touch-action: manipulation;
  }

  .tor-button:hover {
    transform: none;
    background-color: #4c8043;
  }

  .tor-button:not(.locked):not(.not):not(.out-of-service):active {
    transform: scale(0.985);
    background-color: #3d6c37;
  }

  .tor-button .tor-labels {
    min-width: 0;
    margin-right: 12px;
    text-align: left;
  }

  .tor-button .tor-name,
  .tor-button .tor-type {
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .status-switch {
    width: 54px;
    height: 24px;
    margin: 0;
    border-radius: 999px;
  }

  .switch-circle {
    top: 3px;
    width: 18px;
    height: 18px;
  }

  .status-open .switch-circle,
  .status-switch.status-hold-open .switch-circle {
    left: 3px;
  }

  .status-closed .switch-circle,
  .status-switch.status-hold-closed .switch-circle {
    left: 33px;
  }

  .status-unknown .switch-circle,
  .status-switch.status-error .switch-circle {
    left: 18px;
  }

  .location-image-shell {
    order: 3;
    width: 100%;
    max-width: none;
    margin: 4px 0 4px;
    padding: 6px;
    border-radius: 10px;
  }

  .ort-image {
    width: 100%;
    max-width: none;
    max-height: 34vh;
    margin: 0;
    border-radius: 7px;
    object-fit: cover;
  }

  .location-viewer-stage { padding: 52px 10px 98px; }
  .location-viewer-stage img { max-width: calc(100vw - 20px); max-height: calc(100dvh - 150px); border-radius: 9px; }
  .location-viewer-toolbar {
    bottom: max(12px, env(safe-area-inset-bottom));
    width: calc(100% - 20px);
    justify-content: center;
    gap: 6px;
    padding: 6px;
    border-radius: 10px;
  }
  .location-viewer-toolbar button { flex: 1 1 auto; min-width: 42px; min-height: 42px; padding: 7px 8px; font-size: 15px; }
  .location-viewer-toolbar .location-zoom-reset { min-width: 72px; }
  .location-viewer-toolbar .location-viewer-close { flex-grow: 1.45; }

  .ort-label {
    order: 2;
    margin: 4px 0 4px;
    font-size: 18px;
    line-height: 1.2;
    text-align: center;
    letter-spacing: 0;
  }

  .mains {
    width: 100%;
    margin: 12px 0;
    padding: 0;
  }

  .main-buttons {
    width: 100%;
    min-height: 50px;
    margin: 0;
    padding: 12px 14px;
    border-radius: 8px;
    font-size: 17px;
    line-height: 1.15;
  }

  .status-page .status-legend {
    display: grid !important;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    grid-template-rows: auto auto;
    align-items: end;
    justify-content: stretch;
    gap: 5px 8px;
    width: 100%;
    margin: 0;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    border-top: 0;
  }

  .status-page .legend-center {
    display: none !important;
    position: absolute;
    left: 8px;
    right: 8px;
    bottom: calc(100% + 8px);
    width: auto;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    padding: 12px;
    border: 1px solid #565b60;
    border-radius: 12px;
    background: linear-gradient(180deg, #2b2b2b 0%, #202020 100%);
    box-shadow: 0 -10px 28px rgba(0, 0, 0, .38);
  }

  .status-page .legend-center.expanded {
    display: grid !important;
  }

  .status-page .legend-center .legend-item {
    display: flex !important;
    justify-content: flex-start;
    font-size: 12px;
  }

  .status-page .legend-left,
  .status-page .legend-right {
    display: contents;
  }

  .status-page .app-version {
    display: block !important;
    grid-column: 1;
    grid-row: 1;
    justify-self: center;
    margin: 0;
    color: #9b9b9b;
    font-size: 10px;
    font-weight: 300;
    line-height: 1;
    letter-spacing: .2px;
    text-align: center;
  }

  .status-page .session-status:not([hidden]) {
    display: block !important;
    grid-column: 2 / 5;
    grid-row: 1;
    justify-self: end;
    margin: 0;
    padding-right: 2px;
    color: #bdbdbd;
    font-size: 10px;
    line-height: 1;
    text-align: right;
    white-space: nowrap;
  }

  .status-page .emergency-menu-item {
    grid-column: 1;
    grid-row: 2;
  }

  .status-page .legend-menu-item {
    grid-column: 2;
    grid-row: 2;
  }

  .status-page .settings-menu-item {
    grid-column: 3;
    grid-row: 2;
  }

  .status-page .logout-menu-item {
    grid-column: 4;
    grid-row: 2;
  }

  .status-page .status-legend.user-action-layout {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .status-page .status-legend.user-action-layout .session-status:not([hidden]) {
    grid-column: 2 / 4;
  }

  .status-page .status-legend.user-action-layout .logout-menu-item {
    grid-column: 3;
  }

  .status-page .status-legend .mobile-menu-item {
    min-width: 0;
    margin: 0;
  }

  .configs,
  .config_menu {
    width: 100%;
  }

  .status-page .status-legend .config_menu {
    min-height: 40px;
    padding: 8px 4px;
    border-radius: 8px;
    font-size: 13px;
    line-height: 1.15;
    white-space: nowrap;
  }

  .status-page #hold_open_all {
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    padding-inline: 6px;
    font-size: clamp(8px, 2.4vw, 11.5px);
    letter-spacing: -0.15px;
    text-align: center;
  }

  .popup {
    width: calc(100% - 24px);
    max-width: 420px;
    max-height: calc(100vh - 24px);
    overflow-y: auto;
    padding: 18px;
    border: 1px solid #555;
    border-radius: 10px;
    background: linear-gradient(180deg, #303030 0%, #292929 100%);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.025);
  }

  #popup.popup-opening,
  #clusterPopup.popup-opening,
  #diagnosticPopup.popup-opening,
  #popup.popup-opening.popup-overview-motion,
  #clusterPopup.popup-opening.popup-overview-motion,
  #diagnosticPopup.popup-opening.popup-overview-motion {
    animation: mobile-control-popup-in .24s cubic-bezier(.2,.72,.25,1) both;
  }

  #popup.popup-closing,
  #clusterPopup.popup-closing,
  #diagnosticPopup.popup-closing,
  #popup.popup-closing.popup-overview-motion,
  #clusterPopup.popup-closing.popup-overview-motion,
  #diagnosticPopup.popup-closing.popup-overview-motion {
    animation: mobile-control-popup-out .18s ease-in both;
  }

  #popup,
  #clusterPopup,
  #diagnosticPopup {
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
  }

  @keyframes mobile-control-popup-in {
    0% {
      opacity: 0;
      transform: translate3d(-50%, -50%, 0) scale(.985);
    }
    100% {
      opacity: 1;
      transform: translate3d(-50%, -50%, 0) scale(1);
    }
  }

  @keyframes mobile-control-popup-out {
    0% {
      opacity: 1;
      transform: translate3d(-50%, -50%, 0) scale(1);
    }
    100% {
      opacity: 0;
      transform: translate3d(-50%, -50%, 0) scale(.99);
    }
  }

  .cluster-popup {
    max-height: calc(100dvh - 24px);
    padding-bottom: 18px;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
  }

  .cluster-popup .cluster-close-button {
    position: sticky;
    bottom: 0;
    z-index: 6;
    width: min(170px, 70%);
    min-height: 44px;
    margin: 18px auto 0;
    box-shadow: 0 3px 7px rgba(0,0,0,.2);
  }

  #diagnosticPopup {
    width: calc(100% - 16px);
    max-width: none;
    max-height: calc(100dvh - 16px);
    padding: 16px;
    overscroll-behavior: contain;
  }

  .diagnostic-heading { align-items: flex-start; gap: 10px; margin-bottom: 12px; }
  .diagnostic-popup .diagnostic-heading h2 { font-size: 22px; }
  .diagnostic-popup .diagnostic-type { font-size: 12px; }
  .diagnostic-status { min-width: 108px; min-height: 34px; padding: 7px 9px; font-size: 11px; }
  .diagnostic-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
  .diagnostic-stat { padding: 9px 7px; }
  .diagnostic-stat strong { font-size: 18px; }
  .diagnostic-chart-card { padding: 10px; }
  .diagnostic-hourly-chart { height: 86px; }
  .diagnostic-week-chart { gap: 4px; min-height: 78px; }
  .diagnostic-week-day { grid-template-rows: 16px 50px 14px; font-size: 9px; }
  .diagnostic-week-column { width: 76%; height: 48px; }
  .diagnostic-week-error { top: -6px; right: -7px; min-width: 17px; height: 17px; font-size: 8px; }
  .diagnostic-events { grid-template-columns: 1fr; gap: 7px; }
  .diagnostic-actions { position: sticky; bottom: -16px; z-index: 6; grid-template-columns: 1fr 1fr; padding: 10px 0 16px; background: linear-gradient(180deg, transparent, #202321 20%); }
  .diagnostic-actions .diagnostic-close-button { grid-column: 1 / -1; }
  .diagnostic-popup .diagnostic-service-button,
  .diagnostic-popup .diagnostic-reset-button,
  .diagnostic-popup .diagnostic-close-button { min-height: 42px; font-size: 12px; }

  .popup h2 {
    margin: 0 0 12px;
    font-size: 20px;
    line-height: 1.2;
    color: #fff;
  }

  .popup .button-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    width: 100%;
    margin: 10px 0;
  }

  .popup .button-row.stop-row {
    grid-template-columns: 1fr;
  }

  .control-button,
  .control-button2,
  .control-button3,
  .anlagen-button {
    width: 100%;
    min-height: 48px;
    margin: 0;
    padding: 11px 10px;
    border-radius: 8px;
    font-size: 16px;
    line-height: 1.15;
  }

  #popup .control-button,
  #popup .control-button2,
  #popup .control-button3,
  .cluster-popup .control-button,
  .cluster-popup .control-button2,
  .cluster-popup .control-button3 {
    border-radius: 14px;
  }

  .anlagen-button {
    margin-bottom: 12px;
  }

  #pwInput {
    width: 100%;
    min-height: 44px;
    font-size: 18px;
  }

  .overlay.active {
    opacity: 1;
  }
}

@media screen and (max-width: 768px) and (prefers-reduced-motion: reduce),
       screen and (max-device-width: 768px) and (prefers-reduced-motion: reduce) {
  #popup.popup-opening,
  #clusterPopup.popup-opening,
  #diagnosticPopup.popup-opening,
  #popup.popup-closing,
  #clusterPopup.popup-closing,
  #diagnosticPopup.popup-closing {
    animation: none;
  }
}
