/*
 * Desktop console mobile compatibility layer.
 * Loaded last so desktop behavior remains unchanged above 920px.
 */

.desktop-mobile-bar,
.desktop-mobile-sidebar-backdrop,
.desktop-mobile-sidebar-head {
  display: none;
}

@media (max-width: 920px) {
  html,
  body.desktop-cockpit {
    width: 100%;
    min-width: 0;
    overflow-x: hidden;
  }

  body.desktop-cockpit.mobile-sidebar-open {
    overflow: hidden;
    touch-action: none;
  }

  .desktop-cockpit .shell {
    display: block;
    width: 100%;
    min-width: 0;
    min-height: 100dvh;
    overflow-x: clip;
  }

  .desktop-cockpit .shell,
  .desktop-cockpit .workspace,
  .desktop-cockpit main,
  .desktop-cockpit section,
  .desktop-cockpit .panel,
  .desktop-cockpit .overview-card,
  .desktop-cockpit .work-order-list-panel {
    min-width: 0;
  }

  .desktop-cockpit .desktop-mobile-bar {
    position: sticky;
    top: 0;
    z-index: 700;
    display: flex;
    width: 100%;
    min-height: 58px;
    align-items: center;
    gap: 11px;
    padding: calc(8px + env(safe-area-inset-top)) 14px 8px;
    border-bottom: 1px solid rgba(94, 126, 151, 0.2);
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 6px 18px rgba(30, 48, 70, 0.08);
    backdrop-filter: blur(14px);
  }

  .desktop-cockpit .desktop-mobile-menu-button,
  .desktop-cockpit .desktop-mobile-sidebar-head button {
    display: inline-grid;
    flex: 0 0 40px;
    width: 40px;
    height: 40px;
    min-height: 40px;
    place-items: center;
    padding: 0;
    border: 1px solid rgba(14, 116, 144, 0.22);
    border-radius: 8px;
    background: #edf8f6;
    color: #0f5f72;
    font-size: 23px;
    line-height: 1;
    box-shadow: none;
  }

  .desktop-cockpit .desktop-mobile-bar-copy {
    display: grid;
    min-width: 0;
    gap: 2px;
  }

  .desktop-cockpit .desktop-mobile-bar-copy strong,
  .desktop-cockpit .desktop-mobile-bar-copy span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .desktop-cockpit .desktop-mobile-bar-copy strong {
    color: #153f57;
    font-size: 17px;
    line-height: 1.25;
  }

  .desktop-cockpit .desktop-mobile-bar-copy span {
    color: #668196;
    font-size: 12px;
    font-weight: 700;
  }

  .desktop-cockpit .desktop-mobile-sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 850;
    display: block;
    visibility: hidden;
    background: rgba(6, 22, 38, 0.42);
    opacity: 0;
    transition: opacity 0.2s ease, visibility 0s linear 0.2s;
  }

  .desktop-cockpit .shell.mobile-sidebar-open .desktop-mobile-sidebar-backdrop {
    visibility: visible;
    opacity: 1;
    transition-delay: 0s;
  }

  .desktop-cockpit .shell > .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 900;
    display: flex;
    width: min(86vw, 320px);
    height: 100dvh;
    max-height: 100dvh;
    gap: 12px;
    padding: calc(14px + env(safe-area-inset-top)) 14px calc(14px + env(safe-area-inset-bottom));
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    background: #f8fbfd;
    box-shadow: 18px 0 42px rgba(6, 22, 38, 0.2);
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    -webkit-overflow-scrolling: touch;
  }

  .desktop-cockpit .shell.mobile-sidebar-open > .sidebar {
    transform: translateX(0);
  }

  .desktop-cockpit .desktop-mobile-sidebar-head {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
  }

  .desktop-cockpit .desktop-mobile-sidebar-head strong {
    color: #153f57;
    font-size: 17px;
  }

  .desktop-cockpit .desktop-mobile-sidebar-head button {
    flex-basis: 36px;
    width: 36px;
    height: 36px;
    min-height: 36px;
    background: #fff;
    font-size: 25px;
  }

  .desktop-cockpit .shell > .sidebar .side-brand,
  .desktop-cockpit .shell > .sidebar .user-box {
    display: grid;
    flex: 0 0 auto;
    min-width: 0;
  }

  .desktop-cockpit .shell > .sidebar .side-brand {
    padding: 12px;
  }

  .desktop-cockpit .shell > .sidebar .side-brand strong {
    font-size: 15px;
    white-space: nowrap;
    overflow-wrap: normal;
    word-break: keep-all;
    letter-spacing: 0;
  }

  .desktop-cockpit .shell > .sidebar .user-box {
    position: relative;
    z-index: 2;
    padding: 12px;
  }

  .desktop-cockpit .shell > .sidebar .user-box > strong {
    font-size: 18px;
  }

  .desktop-cockpit .shell > .sidebar .side-note {
    display: none;
  }

  .desktop-cockpit .shell > .sidebar .project-context-dropdown {
    position: relative;
    min-width: 0;
  }

  .desktop-cockpit .shell > .sidebar .user-box .project-context-trigger {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 30px;
    align-items: center;
    width: 100%;
    min-width: 0;
    min-height: 48px;
    margin-top: 5px;
    padding: 8px 9px;
    border: 1px solid rgba(10, 61, 98, 0.16);
    border-radius: 8px;
    background: rgba(248, 251, 253, 0.92);
  }

  .desktop-cockpit .shell > .sidebar .user-box .project-context-value {
    grid-column: 1;
    display: block;
    min-width: 0;
    padding: 0;
  }

  .desktop-cockpit .shell > .sidebar .user-box .project-context-value strong {
    display: block;
    min-width: 0;
    color: #173f59;
    font-size: 15px;
    line-height: 1.35;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .desktop-cockpit .shell > .sidebar .user-box .project-context-arrow {
    grid-column: 2;
    display: grid;
    width: 30px;
    height: 30px;
    min-height: 30px;
    place-items: center;
    padding: 0;
    border: 0;
    background: #e8f3fb;
    color: #347b98;
    font-size: 19px;
    transition: transform 0.18s ease;
  }

  .desktop-cockpit .shell > .sidebar .project-context-trigger[aria-expanded="true"] .project-context-arrow {
    transform: rotate(180deg);
  }

  .desktop-cockpit .shell > .sidebar .project-context-menu {
    position: absolute;
    top: calc(100% + 7px);
    right: 0;
    left: 0;
    z-index: 30;
    display: grid;
    max-height: 240px;
    overflow-y: auto;
    border: 1px solid rgba(10, 61, 98, 0.16);
    border-radius: 9px;
    background: #fff;
    box-shadow: 0 14px 32px rgba(42, 78, 105, 0.18);
  }

  .desktop-cockpit .shell > .sidebar .project-context-menu[hidden] {
    display: none;
  }

  .desktop-cockpit .shell > .sidebar .project-context-option {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 20px;
    align-items: center;
    gap: 8px;
    width: 100%;
    min-width: 0;
    min-height: 46px;
    padding: 9px 10px;
    border: 0;
    border-bottom: 1px solid rgba(10, 61, 98, 0.1);
    border-radius: 0;
    background: #fff;
    color: #173f59;
    text-align: left;
    box-shadow: none;
  }

  .desktop-cockpit .shell > .sidebar .project-context-option:last-of-type {
    border-bottom: 0;
  }

  .desktop-cockpit .shell > .sidebar .project-context-option.active {
    background: #eaf5fb;
    box-shadow: inset 3px 0 0 #0f766e;
  }

  .desktop-cockpit .shell > .sidebar .project-context-option-copy,
  .desktop-cockpit .shell > .sidebar .project-context-option-copy strong {
    min-width: 0;
  }

  .desktop-cockpit .shell > .sidebar .project-context-option-copy strong {
    display: block;
    font-size: 14px;
    line-height: 1.3;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .desktop-cockpit .shell > .sidebar .side-nav {
    display: flex;
    flex: 1 0 auto;
    flex-direction: column;
    gap: 9px;
    width: 100%;
    min-height: auto;
    padding: 0;
    overflow: visible;
  }

  .desktop-cockpit .shell > .sidebar .side-nav-group {
    position: static;
    display: block;
    flex: 0 0 auto;
    width: 100%;
    min-width: 0;
  }

  .desktop-cockpit .shell > .sidebar .side-nav-group::after {
    display: none;
  }

  .desktop-cockpit .shell > .sidebar .side-nav-group > button,
  .desktop-cockpit .shell > .sidebar .side-subnav .sub-nav-button {
    box-sizing: border-box;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    min-height: 46px;
    padding: 8px 12px 8px 15px;
    text-align: left;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .desktop-cockpit .shell > .sidebar .side-nav-group.has-children > button::after {
    content: "⌄";
    transition: transform 0.18s ease;
  }

  .desktop-cockpit .shell > .sidebar .side-nav-group.has-children.mobile-expanded > button::after,
  .desktop-cockpit .shell > .sidebar .side-nav-group.has-children.active > button::after {
    transform: rotate(180deg);
  }

  .desktop-cockpit .shell > .sidebar .side-nav .side-subnav {
    position: static;
    display: grid;
    width: auto;
    min-width: 0;
    max-width: none;
    max-height: 0;
    gap: 0;
    margin: 0 7px;
    padding: 0;
    overflow: hidden;
    border: 0;
    border-radius: 10px;
    background: #fff;
    box-shadow: none;
    opacity: 0;
    pointer-events: none;
    transform: none;
    transition: max-height 0.2s ease, margin 0.2s ease, padding 0.2s ease, opacity 0.18s ease;
  }

  .desktop-cockpit .shell > .sidebar .side-nav-group.mobile-expanded .side-subnav,
  .desktop-cockpit .shell > .sidebar .side-nav-group.active:not(.mobile-collapsed) .side-subnav {
    max-height: 420px;
    gap: 7px;
    margin: 7px 7px 2px;
    padding: 8px;
    overflow: visible;
    border: 1px solid rgba(0, 168, 216, 0.18);
    opacity: 1;
    pointer-events: auto;
  }

  .desktop-cockpit .shell > .sidebar .side-nav .side-subnav .sub-nav-button {
    min-height: 40px;
    border-left-width: 1px;
    border-radius: 8px;
    background: #f7fbfd;
    box-shadow: none;
    font-size: 14px;
  }

  .desktop-cockpit .shell > .sidebar .side-nav .side-subnav .sub-nav-button::after {
    display: none;
  }

  .desktop-cockpit .shell > .sidebar #changePassword,
  .desktop-cockpit .shell > .sidebar #logout {
    display: inline-flex;
    flex: 0 0 auto;
    width: 100%;
    min-height: 42px;
    margin: 0;
    justify-content: center;
  }

  .desktop-cockpit .workspace {
    width: 100%;
    min-width: 0;
    padding: 16px;
  }

  .desktop-cockpit #workspacePage {
    min-width: 0;
  }

  .desktop-cockpit .topbar,
  .desktop-cockpit .panel-head,
  .desktop-cockpit .config-title,
  .desktop-cockpit .account-browser-head {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .desktop-cockpit .topbar {
    gap: 12px;
  }

  .desktop-cockpit .topbar h1 {
    font-size: 24px;
    line-height: 1.25;
  }

  .desktop-cockpit .project-switch,
  .desktop-cockpit .project-switch.inline,
  .desktop-cockpit .record-filter-bar,
  .desktop-cockpit .work-order-toolbar,
  .desktop-cockpit .config-title-actions,
  .desktop-cockpit .config-block-actions,
  .desktop-cockpit .button-row {
    width: 100%;
  }

  .desktop-cockpit .project-switch select,
  .desktop-cockpit .record-filter-bar input,
  .desktop-cockpit .record-filter-bar select,
  .desktop-cockpit input,
  .desktop-cockpit select,
  .desktop-cockpit textarea {
    max-width: 100%;
  }

  .desktop-cockpit .grid.metrics,
  .desktop-cockpit .grid.two,
  .desktop-cockpit .split,
  .desktop-cockpit .overview-grid,
  .desktop-cockpit .overview-grid.lower,
  .desktop-cockpit .handover-config-layout,
  .desktop-cockpit .form-grid,
  .desktop-cockpit .form-preview-list,
  .desktop-cockpit .water-snapshot-grid,
  .desktop-cockpit .work-order-layout,
  .desktop-cockpit .work-order-rail,
  .desktop-cockpit .work-order-form-grid,
  .desktop-cockpit .work-order-assignee-choice,
  .desktop-cockpit .config-row,
  .desktop-cockpit .project-grant-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .desktop-cockpit .config-row .wide,
  .desktop-cockpit .config-row .link-btn,
  .desktop-cockpit .project-grant-row .project-grant-remove {
    grid-column: 1 / -1;
  }

  .desktop-cockpit .record-filter-bar,
  .desktop-cockpit .work-order-toolbar,
  .desktop-cockpit .config-title-actions,
  .desktop-cockpit .config-block-actions,
  .desktop-cockpit .button-row {
    justify-content: flex-start;
  }

  .desktop-cockpit img,
  .desktop-cockpit svg,
  .desktop-cockpit canvas {
    max-width: 100%;
  }

  .desktop-cockpit .table,
  .desktop-cockpit .config-list,
  .desktop-cockpit .project-account-content,
  .desktop-cockpit .work-order-table,
  .desktop-cockpit .time-window-grid,
  .desktop-cockpit .time-window-rule-list,
  .desktop-cockpit .chemical-raw-table-wrap {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
  }

  .desktop-cockpit .tr,
  .desktop-cockpit .work-order-table-head,
  .desktop-cockpit .work-order-row {
    min-width: 620px;
  }

  .desktop-cockpit .tr,
  .desktop-cockpit .tr.head {
    grid-template-columns: var(--cols) !important;
  }

  .desktop-cockpit .tr.head {
    display: grid;
  }

  .desktop-cockpit .work-order-drawer {
    width: min(570px, calc(100vw - 18px));
  }

  .desktop-cockpit .work-order-modal-backdrop,
  .desktop-cockpit .modal-backdrop,
  .desktop-cockpit .modal-backdrop.user-modal {
    padding: 12px;
  }

  .desktop-cockpit .work-order-modal,
  .desktop-cockpit .modal-card,
  .desktop-cockpit .user-delete-card {
    width: min(100%, calc(100vw - 24px));
    max-height: calc(100dvh - 24px);
    overflow-y: auto;
  }

  .desktop-cockpit .work-order-modal form,
  .desktop-cockpit .work-order-modal header,
  .desktop-cockpit .work-order-drawer header,
  .desktop-cockpit .work-order-drawer-body,
  .desktop-cockpit .work-order-drawer footer {
    padding-right: 16px;
    padding-left: 16px;
  }

  .desktop-cockpit .icepi-assistant {
    right: 4px;
    bottom: calc(10px + env(safe-area-inset-bottom));
    top: auto;
    transform: scale(0.76);
    transform-origin: right bottom;
  }

  .desktop-cockpit .assistant-panel {
    width: min(420px, calc(100vw - 20px));
    max-height: calc(100dvh - 20px);
  }
}

@media (max-width: 640px) {
  .desktop-cockpit .workspace {
    padding: 12px;
  }

  .desktop-cockpit .panel,
  .desktop-cockpit .overview-card,
  .desktop-cockpit .work-order-list-panel,
  .desktop-cockpit .work-order-intro {
    padding: 14px;
  }

  .desktop-cockpit .grid.metrics,
  .desktop-cockpit .grid.two,
  .desktop-cockpit .split,
  .desktop-cockpit .overview-grid,
  .desktop-cockpit .overview-grid.lower,
  .desktop-cockpit .handover-config-layout,
  .desktop-cockpit .form-grid,
  .desktop-cockpit .form-preview-list,
  .desktop-cockpit .water-snapshot-grid,
  .desktop-cockpit .work-order-layout,
  .desktop-cockpit .work-order-rail,
  .desktop-cockpit .work-order-form-grid,
  .desktop-cockpit .work-order-assignee-choice,
  .desktop-cockpit .config-row,
  .desktop-cockpit .project-grant-row,
  .desktop-cockpit .work-order-detail-grid {
    grid-template-columns: 1fr;
  }

  .desktop-cockpit .config-row .wide,
  .desktop-cockpit .config-row .link-btn,
  .desktop-cockpit .project-grant-row .project-grant-remove {
    grid-column: auto;
  }

  .desktop-cockpit .config-title-actions > .btn,
  .desktop-cockpit .config-block-actions > .btn,
  .desktop-cockpit .button-row > .btn,
  .desktop-cockpit .work-order-toolbar > .btn {
    flex: 1 1 132px;
  }

  .desktop-cockpit .ops-overview-hero,
  .desktop-cockpit .public-hero {
    grid-template-columns: 1fr;
    padding: 18px;
  }

  .desktop-cockpit .ops-overview-hero h2,
  .desktop-cockpit .public-hero h2 {
    font-size: 27px;
  }

  .desktop-cockpit .topbar.project-status-hero {
    display: grid;
    gap: 12px;
  }

  .desktop-cockpit .project-status-hero-copy {
    margin-right: 0;
  }

  .desktop-cockpit .topbar.project-status-hero h1 {
    font-size: 25px;
  }

  .desktop-cockpit .topbar.project-status-hero .project-status-description {
    font-size: 16px;
  }

  .desktop-cockpit .project-status-weather {
    position: static;
    width: 100%;
    height: auto;
    justify-content: flex-start;
    transform: none;
  }

  .desktop-cockpit .project-weather-copy {
    flex: 0 1 auto;
  }

  .desktop-cockpit .hero-status,
  .desktop-cockpit .progress-big {
    justify-self: start;
    width: 96px;
    height: 96px;
    border-width: 8px;
  }

  .desktop-cockpit .hero-status strong {
    font-size: 22px;
  }

  .desktop-cockpit .hero-status span {
    margin-top: -22px;
  }

  .desktop-cockpit .work-order-metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .desktop-cockpit .work-order-filters {
    max-width: 100%;
    overflow-x: auto;
  }

  .desktop-cockpit .work-order-search,
  .desktop-cockpit .work-order-search input {
    width: 100%;
  }

  .desktop-cockpit .work-order-drawer {
    width: 100vw;
    border-left: 0;
  }

  .desktop-cockpit .work-order-drawer h2,
  .desktop-cockpit .work-order-modal h2 {
    font-size: 20px;
  }

  .desktop-cockpit .icepi-assistant {
    right: -4px;
    bottom: calc(4px + env(safe-area-inset-bottom));
    transform: scale(0.66);
  }

  .desktop-cockpit .assistant-panel {
    right: 10px;
    left: auto;
    width: calc(100vw - 20px);
    max-height: calc(100dvh - 20px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .desktop-cockpit .shell > .sidebar,
  .desktop-cockpit .desktop-mobile-sidebar-backdrop,
  .desktop-cockpit .side-subnav,
  .desktop-cockpit .table,
  .desktop-cockpit .config-list,
  .desktop-cockpit .work-order-table {
    scroll-behavior: auto;
    transition: none;
  }
}
