/* ============================================================
   MDC Mobile Responsive Stylesheet
   Keeps the authentic desktop MDC look — just makes it usable
   on a phone by fullscreening the window and allowing scroll.
   Only activates at max-width: 768px — desktop/NUI unchanged.
   ============================================================ */

/* Sidebar parts exist in the page on every screen size; only phones show them */
.mdc-sidebar-toggle,
.mdc-sidebar-backdrop {
  display: none;
}

/* 1. Hide desktop chrome that doesn't work on a phone */
@media (max-width: 768px) {
  .desktop-icon,
  .desktop-icons-container {
    display: none !important;
  }

  html, body {
    overflow: hidden;
    overscroll-behavior: none;
    -webkit-overflow-scrolling: touch;
  }
}

/* 2. MDC / CADS / File Manager windows — fullscreen with internal scroll */
@media (max-width: 768px) {
  .mdc-window,
  .dispatcher-window,
  .file-manager-window {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    height: 100% !important;
    max-width: none !important;
    max-height: none !important;
    transform: none !important;
    border: none !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    z-index: 5000;
    overflow: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  /* The grid is shorter than a tall phone screen: fill the rest with the MDC's own
     black frame instead of showing the desktop wallpaper through the window. */
  .mdc-window {
    background: #000;
  }

  /* The MDC grid is 800px wide — let it stay that way so the
     layout looks identical to desktop. User scrolls horizontally. */
  #mdc-container {
    min-width: 800px;
  }

  /* Title bar sticks to top while scrolling. Taller, with room on the left for the
     sidebar button (a 44px touch target). */
  .mdc-window > .windows-title-bar,
  .dispatcher-window > .windows-title-bar,
  .file-manager-window > .windows-title-bar {
    position: sticky;
    top: 0;
    z-index: 100;
    height: 44px;
    padding-left: 48px;
    cursor: default !important; /* no dragging on mobile */
  }

  /* Hide minimize/maximize — already fullscreen */
  .title-buttons .minimize-btn,
  .title-buttons .fullscreen-btn {
    display: none;
  }
}

/* Taps on buttons never double-tap-zoom the page (replaces the old mobile.js behaviour) */
@media (max-width: 768px) {
  button,
  .blue-btn,
  .footer-btn {
    touch-action: manipulation;
  }

}

/* Sidebar: the taskbar slides in from the left (Start, open apps, Quick Settings, sound,
   network, profile/Sign Out, clock). Same markup and behaviour as on desktop. */
@media (max-width: 768px) {
  body.logged-in .mdc-sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    top: 0;
    left: 0;
    width: 44px;
    height: 44px;
    padding: 0;
    background: transparent;
    border: none;
    font-size: 22px;
    line-height: 1;
    color: #202020;
    /* Above every window (the window manager caps them at 9900), below the drawer (10010) */
    z-index: 9950;
    touch-action: manipulation;
  }

  .mdc-sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 10009;
  }
  body.mdc-sidebar-open .mdc-sidebar-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  .win11-taskbar {
    position: fixed !important;
    top: 0 !important;
    bottom: 0 !important;
    left: 0 !important;
    right: auto !important;
    width: min(300px, 84vw);
    height: auto !important;
    flex-direction: column;
    align-items: stretch !important;
    justify-content: flex-start !important;
    gap: 16px;
    padding: calc(12px + env(safe-area-inset-top, 0px)) 12px calc(12px + env(safe-area-inset-bottom, 0px));
    border-top: none;
    border-right: 1px solid #c7c7c7;
    box-shadow: 4px 0 16px rgba(0, 0, 0, 0.3);
    overflow-y: auto;
    transform: translateX(-110%);
    visibility: hidden;
    transition: transform 0.2s ease, visibility 0s linear 0.2s;
    z-index: 10010;
  }
  body.mdc-sidebar-open .win11-taskbar {
    transform: none;
    visibility: visible;
    transition: transform 0.2s ease, visibility 0s;
  }

  .win11-taskbar__left,
  .win11-taskbar__center,
  .win11-taskbar__right {
    flex: none !important;
    width: 100%;
    flex-wrap: wrap;
    justify-content: flex-start !important;
    gap: 8px;
    margin: 0 !important;
    overflow: visible;
  }

  .win11-start,
  .win11-tray-icon,
  .win11-taskbar__app-btn,
  .win11-profile-btn {
    min-width: 44px;
    min-height: 44px;
  }

  /* In a sidebar the icons need names (two apps share the same star icon): one full-width
     row each, labelled from the button's own title. */
  .win11-start,
  .win11-taskbar__app-btn {
    width: 100%;
    justify-content: flex-start;
    gap: 12px;
    padding: 0 12px;
  }
  .win11-start::after,
  .win11-taskbar__app-btn::after {
    content: attr(title);
    font-size: 15px;
    color: #202020;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* Sign Out pop-up drops down from the profile button (it opened upward over the app list) */
  .win11-profile-menu {
    bottom: auto;
    top: calc(100% + 6px);
  }
  .win11-profile-menu__item {
    min-height: 44px;
  }

  /* The footer line sits above everything; hide while the menu is open */
  body.mdc-sidebar-open #mdc-copyright {
    display: none;
  }
}

/* 3. Login inputs — prevent iOS auto-zoom on focus */
@media (max-width: 768px) {
  .mdc-login__input {
    font-size: 16px !important;
  }
}

/* 4. Sub-windows (call log, status, other functions, inquiries)
      — slide up from bottom, capped at 70vh */
@media (max-width: 768px) {
  .call-log-window,
  .status-window,
  .other-functions-window,
  .inquiries-window {
    position: fixed !important;
    top: auto !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    max-height: 70vh !important;
    transform: none !important;
    border-radius: 12px 12px 0 0 !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    z-index: 6000;
  }
}

/* 5. Toast notifications — above the bottom of the screen */
@media (max-width: 768px) {
  .toast-notification {
    bottom: 12px !important;
    right: 8px !important;
    left: 8px !important;
    width: auto !important;
    max-width: none !important;
  }
}

/* 6. Auto-open MDC on mobile is handled by a <script> block
      in dist/index.html — no mobile.js dependency needed. */

/* MDCS on a phone: a rounded window with a small gap around it, like PremierOne Mobile.
 * It is still the same full-size scrolling window (the 800px grid scrolls sideways inside it); only
 * the frame changes: 6px gap, 12px corners, flat title bar, flat close button (a 44px touch target,
 * red while pressed). Dispatch Console and File Manager keep their edge-to-edge frame. */
@media (max-width: 768px) {
  .mdc-window {
    top: max(6px, env(safe-area-inset-top, 0px)) !important;
    left: 6px !important;
    right: 6px !important;
    bottom: max(6px, env(safe-area-inset-bottom, 0px)) !important;
    width: auto !important;
    height: auto !important;
    border-radius: var(--win11-radius-lg, 12px) !important;
    box-shadow: var(--win11-shadow-window-light, 0 8px 24px rgba(0, 0, 0, 0.35), 0 0 0 1px rgba(0, 0, 0, 0.06)) !important;
  }

  .mdc-window > #title-bar {
    border: none !important;
    border-bottom: 1px solid currentColor !important;
    border-radius: var(--win11-radius-lg, 12px) var(--win11-radius-lg, 12px) 0 0;
    box-shadow: none !important;
  }

  .mdc-window > #title-bar .title-buttons {
    gap: 0;
    height: 100%;
    align-items: stretch;
  }

  .mdc-window > #title-bar .close-btn {
    width: 44px;
    height: 44px;
    background: transparent !important;
    border: none !important;
    border-radius: 0 var(--win11-radius-lg, 12px) 0 0;
    box-shadow: none !important;
    color: #1B1B1B !important;
    font-size: 16px;
    font-weight: normal;
    line-height: 1;
  }
  .mdc-window > #title-bar .close-btn:active {
    background: #e81123 !important;
    color: #fff !important;
  }
  body.mdc-night-mode .mdc-window > #title-bar .close-btn {
    color: #f3f3f3 !important;
  }
}
