/* Keep navigation and wide tables usable on touch screens. */
#nav[hidden], #bottom[hidden], #shade[hidden], header [hidden],
#nav > [hidden], #bottom > [hidden] {
  display: none !important;
}

#nexusLoginGate {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: max(12px, env(safe-area-inset-top, 0px)) max(12px, env(safe-area-inset-right, 0px)) max(12px, env(safe-area-inset-bottom, 0px)) max(12px, env(safe-area-inset-left, 0px));
  overflow: auto;
}

#nexusLoginGate .nexus-gate-card {
  flex: 0 0 auto;
  margin-block: auto;
}

#nexusLoginGate form, .truck-login-card form {
  grid-template-columns: minmax(0, 1fr);
}

.truck-login-modal {
  overflow: auto;
  align-items: safe center;
}

body.v9-mobile .truck-scope > .truck-received-plan {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 14rem), 1fr));
  margin-inline: 0;
  padding-inline: 0;
  overflow: visible !important;
  scroll-snap-type: none;
}

body.v9-mobile .truck-scope > .truck-received-plan .received-job {
  align-self: stretch;
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
}

@media (min-width: 1151px) {
  body.v9-mobile #nav:not([hidden]) {
    width: 220px;
    transform: none;
    transition: none;
    visibility: visible;
  }

  body.v9-mobile:not(.nexus-no-sidebar) main#main {
    max-width: calc(100% - 220px);
    margin-left: 220px;
  }

  body.v9-mobile.nexus-no-sidebar main#main {
    margin-inline: auto;
  }

  body.v9-mobile:not(.nexus-no-sidebar) #bottom {
    left: 220px;
  }

  body.v9-mobile > header > button[aria-controls="nav"],
  body.v9-mobile #bottom [data-nexus-menu] {
    display: none;
  }
}

@media (max-width: 1150px) {
  html.v9-mobile {
    scroll-padding-block-start: calc(68px + env(safe-area-inset-top, 0px));
    scroll-padding-block-end: calc(80px + env(safe-area-inset-bottom, 0px));
  }

  @supports (overflow: clip) {
    html.v9-mobile, body.v9-mobile {
      overflow-x: clip;
    }
  }

  body.v9-mobile {
    --nexus-header-height: calc(68px + env(safe-area-inset-top, 0px));
    --nexus-bottom-space: calc(80px + env(safe-area-inset-bottom, 0px));
  }

  /* On tablets the drawer uses the same overlay as it does on phones. */
  body.v9-mobile > header {
    position: sticky;
    top: 0;
    z-index: 40;
    height: var(--nexus-header-height);
    padding-top: calc(8px + env(safe-area-inset-top, 0px));
    padding-right: max(10px, env(safe-area-inset-right, 0px));
    padding-left: max(10px, env(safe-area-inset-left, 0px));
  }

  body.v9-mobile #nav {
    top: var(--nexus-header-height);
    width: min(275px, calc(100vw - 48px));
    padding: 12px max(12px, env(safe-area-inset-right, 0px)) max(12px, env(safe-area-inset-bottom, 0px)) max(12px, env(safe-area-inset-left, 0px));
    z-index: 39;
    overscroll-behavior-y: contain;
    visibility: hidden;
  }

  body.v9-mobile.menu-open #nav:not([hidden]) {
    transform: none;
    visibility: visible;
  }

  body.v9-mobile #shade {
    inset: var(--nexus-header-height) 0 0;
    z-index: 38;
  }

  body.v9-mobile.menu-open #shade:not([hidden]) {
    display: block;
  }

  body.v9-mobile main#main {
    width: 100%;
    min-width: 0;
    margin-inline: auto;
    padding-right: max(10px, env(safe-area-inset-right, 0px));
    padding-bottom: var(--nexus-bottom-space);
    padding-left: max(10px, env(safe-area-inset-left, 0px));
  }

  body.v9-mobile #bottom {
    display: flex;
    justify-content: flex-start;
    gap: 3px;
    padding: 4px max(5px, env(safe-area-inset-right, 0px)) calc(5px + env(safe-area-inset-bottom, 0px)) max(5px, env(safe-area-inset-left, 0px));
    overflow-x: auto;
    overscroll-behavior-x: contain;
  }

  body.v9-mobile #bottom button {
    flex: 1 0 54px;
    align-content: center;
    min-height: 50px;
    padding: 4px;
    font-size: 11px;
    line-height: 1.2;
    text-align: center;
    overflow-wrap: anywhere;
  }

  body.v9-mobile #toast {
    bottom: var(--nexus-bottom-space);
    z-index: 45;
  }

  body.v9-mobile :is(.fleet-grid, .chantier-week, .plan-week, .pv-table, .client-tabs, .pv-tabs) {
    max-width: 100%;
    margin-inline: 0;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scroll-snap-type: none;
  }

  body.v9-mobile :is(.pv-work > *, .job-layout > *, .job-extras > *, .analytics-grid > *,
  .client-layout > *, .issue-grid > *, .issue-sides > *, .vehicle-registry, .fleet-plan, .phase-progress > *) {
    min-width: 0;
  }
}

@media (max-width: 700px) {
  body.v9-mobile {
    --nexus-header-height: calc(62px + env(safe-area-inset-top, 0px));
  }

  body.v9-mobile > header {
    gap: 4px;
  }

  body.v9-mobile > header > button {
    flex: 0 0 44px;
    min-width: 44px;
    min-height: 44px;
    padding-inline: 4px !important;
  }

  body.v9-mobile header .brand {
    min-width: min-content;
  }

  body.v9-mobile header .brand h1 {
    white-space: nowrap;
  }

  body.v9-mobile header .access-preview {
    min-width: 0;
  }

  body.v9-mobile header .access-preview select {
    max-width: 100%;
  }

  body.v9-mobile header .truck-session {
    min-width: 0;
    gap: 4px;
    line-height: 1.2;
    overflow-wrap: anywhere;
  }

  body.v9-mobile header .truck-session button {
    min-height: 44px;
    padding: 5px 3px;
    font-size: 12px;
    white-space: nowrap;
  }

  body.v9-mobile :is(main, #nexusLoginGate, .truck-login-modal) :is(input, select, textarea) {
    min-width: 0;
    max-width: 100%;
    font-size: 16px;
  }
}

@media (max-width: 700px), (max-width: 1000px) and (max-height: 600px) and (pointer: coarse) {
  body.v9-mobile :is(.field-mobile, .v9-prep-only) {
    padding: 0;
  }

  body.v9-mobile .field-mobile .field-top {
    position: relative;
    top: auto;
  }

  .v9-prep-only .field-top {
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    padding: 8px;
    border: 1px solid #285d68;
    border-radius: 13px;
    background: linear-gradient(130deg, #091d2e, #111a37 65%, #1e1230);
  }

  .v9-prep-only .field-back {
    min-height: 44px;
    padding: 0;
    font-size: 25px;
  }

  .v9-prep-only .field-truck :is(small, b) {
    display: block;
  }

  .v9-prep-only .field-sync {
    color: #91ffd0;
    font-size: 10px;
  }

  .v9-prep-only .field-steps {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 5px;
    margin-bottom: 12px;
  }

  .v9-prep-only .field-step {
    min-height: 58px;
    padding: 7px 3px;
    border: 1px solid #29485f;
    border-radius: 11px;
    background: #0b2232;
    color: #90b5bf;
    font-size: 11px;
    font-weight: 800;
    text-align: center;
  }

  .v9-prep-only .field-step.active {
    border-color: #38efb0;
    background: linear-gradient(135deg, #103f3b, #15314a);
    color: #ddfff1;
  }

  .field-steps .field-step {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    gap: 4px;
  }

  .field-steps .field-step span {
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    min-width: 22px;
    min-height: 22px;
    margin: 0;
  }

  .field-mobile .field-bottom-actions {
    position: static;
    margin-top: 12px;
    border: 1px solid #2c716e;
    border-radius: 12px;
    padding: 9px;
  }

  .field-mobile :is(.field-contact, .field-truck, .field-file > *, .field-address > *) {
    min-width: 0;
  }

  .field-mobile :is(.field-card, .field-job, .field-hero),
  :is(.v9-prep-only, .vehicle-card, .client-dossier, .issue-card, .admin-user) {
    overflow-wrap: anywhere;
  }

  .field-mobile .field-signature-foot button {
    min-height: 44px;
  }
}

@media (min-width: 701px) and (max-width: 1000px) and (max-height: 600px) and (pointer: coarse) {
  body.v9-mobile main#main :is(.field-mobile, .v9-prep-only) {
    display: block !important;
  }

  .field-mobile :is(input, select, textarea) {
    font-size: 16px;
  }
}

@media (max-width: 700px) {
  .plan-head .plan-nav {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
  }

  .plan-head .plan-nav > strong {
    grid-column: 1 / -1;
    grid-row: 1;
    min-width: 0;
    font-size: 14px;
  }

  .plan-head .plan-nav button {
    min-width: 0;
    padding-inline: 4px;
    overflow-wrap: anywhere;
  }

  body.v9-mobile .fleet-head, body.v9-mobile .fleet-row {
    grid-template-columns: 100px repeat(7, minmax(150px, 1fr));
    min-width: 1150px;
  }

  .fleet-grid .fleet-truck, .fleet-grid .fleet-head > :first-child {
    z-index: 5;
    overflow-wrap: anywhere;
  }

  .vehicle-summary {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .vehicle-count {
    min-width: 0;
    padding: 8px;
    overflow-wrap: anywhere;
  }

  .vehicle-card-grid {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 235px), 1fr));
  }
}

@media (max-width: 430px) {
  body.v9-mobile > header .brand svg,
  body.v9-mobile > header .access-preview label {
    display: none;
  }

  body.v9-mobile .vehicle-add-form {
    grid-template-columns: minmax(0, 1fr);
  }

  body.v9-mobile .vehicle-add-form button {
    grid-column: 1;
  }
}

@media (max-width: 360px) {
  /* The bottom navigation already provides the Alerts shortcut. */
  body.v9-mobile header #alertButton {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  #nav {
    transition: none;
  }
}
