/* The document stays still; scrolling content never passes behind the status area. */
@media screen {
  :root { --screen-safe-top: env(safe-area-inset-top, 0px); }
  html { height: 100%; overflow: hidden; overflow: clip; background: #0d3440; overscroll-behavior: none; }
  html:has(body.reports-page) { background: #fff; }
  html:has(body.worklist-page) { background: #edf3f3; }
  body:is(.map-page, .pilot-page, .reports-page, .worklist-page) {
    position: fixed;
    inset: 0;
    height: 100dvh;
    min-height: 0;
    margin: 0;
    overflow: hidden;
    overflow: clip;
    display: flex;
    flex-direction: column;
    overscroll-behavior: none;
  }
  body > header, body.worklist-page > nav {
    box-sizing: border-box;
    flex: 0 0 auto;
    position: relative !important;
    inset: auto !important;
    z-index: 1100;
    opacity: 1;
    filter: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
  .map-page > header {
    height: calc(76px + var(--screen-safe-top));
    padding-top: var(--screen-safe-top);
    background: #0d3440;
  }
  body.map-page.tablet-device:not(.map-fullscreen) > header {
    height: calc(76px + var(--screen-safe-top));
    padding-top: var(--screen-safe-top);
  }
  .pilot-page > .pilot-header {
    height: calc(64px + var(--screen-safe-top));
    padding-top: var(--screen-safe-top);
    background: #0d3440;
  }
  .reports-page > header {
    min-height: calc(64px + var(--screen-safe-top));
    padding-top: calc(12px + var(--screen-safe-top));
    padding-bottom: 12px;
    background: #fff;
  }
  .worklist-page > nav {
    width: 100%;
    margin: 0 auto;
    padding-top: calc(12px + var(--screen-safe-top));
    padding-bottom: 12px;
    background: #edf3f3;
  }
  body:is(.map-page, .pilot-page, .reports-page, .worklist-page) > main {
    box-sizing: border-box;
    position: relative;
    flex: 1 1 0;
    min-height: 0;
    height: auto !important;
    margin-top: 0 !important;
    overscroll-behavior: contain;
  }
  .map-page > main { overflow: auto; }
  .map-page > main > aside { min-height: 0; }
  .pilot-page > .pilot-layout { overflow: hidden; }
  .pilot-page > .pilot-layout.show-report { overflow: auto; }
  .reports-page > main, .worklist-page > main {
    width: 100%;
    overflow: auto;
    margin-bottom: 0;
    padding-bottom: max(24px, env(safe-area-inset-bottom, 0px));
    scrollbar-gutter: stable;
  }
  .reports-page > main { scroll-padding-top: 12px; }
  .map-page.map-fullscreen > main { overflow: hidden; }
  .account-history { margin-top: 16px; padding-top: 12px; }
  .account-history > h3 { margin: 0 0 12px; }
  .account-history-table :is(th, td) { padding: 8px; line-height: 1.3; }
  .account-route-list { gap: 10px; }
  .account-route-card { padding: 12px; }
  .account-route-actions { padding-top: 8px; }
  .account-route-state:empty, #account-route-state:empty { display: none; }
}

@media screen and (max-width: 760px) {
  .map-page > header { height: calc(64px + var(--screen-safe-top)); }
  .map-page > main > aside { flex: 0 0 auto; }
  .map-page > main:not(.filters-collapsed) > .map-wrap { flex: 0 0 65dvh; }
  .map-page > main.filters-collapsed > .map-wrap { flex: 1 0 200px; min-height: 200px; }
  .reports-page > header { gap: 10px; }
  .account-history-table tr { margin-bottom: 8px; padding: 6px 10px; }
  .account-history-table td {
    padding: 2px 0;
    column-gap: 8px;
    line-height: 1.25;
  }
  .account-history-table td:first-child { min-height: 44px; }
  .account-history-table caption { padding-bottom: 6px; }
  .account-history-filters { gap: 8px 10px; }
}

@media screen and (max-width: 360px) {
  .reports-page .reports-brand { font-size: 16px; }
  .reports-page .reports-brand span { margin-right: 5px; }
  .reports-page > header > a:last-child { font-size: 12px; }
}

@media screen and (orientation: portrait) {
  body.map-page.tablet-device:not(.map-fullscreen) > header { height: calc(64px + var(--screen-safe-top)); }
  .map-page.tablet-device > main > aside { flex: 0 0 auto; }
  .map-page.tablet-device > main:not(.filters-collapsed) > .map-wrap { flex: 0 0 65dvh; }
  .map-page.tablet-device > main.filters-collapsed > .map-wrap { flex: 1 0 200px; min-height: 200px; }
}

/* Compact pointer controls on desktop. Touch controls retain their 44px target. */
@media screen and (min-width: 761px) and (hover: hover) and (pointer: fine) {
  .account-navigation { display: flex; gap: 8px; margin-top: 12px; }
  .account-navigation button { min-width: 148px; min-height: 36px; height: auto; padding: 6px 14px; }
  .account-route-list { grid-template-columns: repeat(auto-fit, minmax(min(100%, 290px), 390px)); }
  .account-route-actions a, .jkp-account-actions :is(a, button) {
    min-height: 36px;
    padding: 6px 10px;
  }
  .account-route-card h3 { margin-bottom: 4px; }
  .account-history-filters { gap: 8px 12px; }
  .pilot-sidebar { padding: 16px; }
  .pilot-sidebar p { margin: 6px 0 8px; line-height: 1.4; }
  .pilot-run-actions { margin: 8px 0; }
  .pilot-run-actions button, .pilot-history-tools button, #pilot-latest, #pilot-active-note {
    min-height: 36px;
    padding: 6px 10px;
    font-size: 13px;
    line-height: 20px;
  }
  #pilot-history-details { margin-top: 10px; }
  #pilot-history-details > summary { min-height: 32px; }
  .pilot-history-toolbar { margin: 6px 0; gap: 4px; }
  .pilot-history-toolbar select { height: 36px; min-height: 36px; font-size: 14px; padding: 6px 10px; }
  .pilot-history-row { margin: 4px 0; gap: 6px; }
  .pilot-history-row :is(.pilot-history-item, .pilot-history-action) {
    min-height: 34px;
    padding: 6px 10px;
    font-size: 13px;
    line-height: 20px;
  }
  .pilot-history-action { min-width: 60px; }
  .pilot-report-nav :is(a, button) { min-height: 36px; padding: 6px 10px; }
}

/* Smaller worklist editors on pointer-driven desktop screens. */
@media screen and (min-width: 761px) and (hover: hover) and (pointer: fine) {
  .pilot-worklist { padding: 20px; }
  .pwl-fields { gap: 8px 10px; padding: 12px 0; margin: 12px 0; }
  .worklist-page .fields { gap: 8px 12px; padding: 12px 0; margin: 16px 0; }
  :is(.pwl-fields, .worklist-page .fields) :is(input:not([type="checkbox"]):not([type="radio"]), select) {
    height: 36px;
    block-size: 36px;
    min-height: 36px;
    flex-basis: 36px;
    padding: 6px 10px;
    font-size: 14px;
    line-height: 20px;
  }
  .pwl-field > input, .worklist-page .fields > label > :is(input, select) { margin-top: 4px; }
  .pwl-fields textarea, .worklist-page .fields textarea { min-height: 56px; padding: 7px 10px; }
  .pwl-worker-row, .worklist-page .worker-row { grid-template-columns: minmax(0, 1fr) 36px; margin-top: 4px; }
  .pwl-worker-row :is(input, button), .worklist-page .worker-row :is(input, button) {
    height: 36px;
    min-height: 36px;
    margin: 0;
  }
  .pwl-worker-row button, .worklist-page .worker-row button { padding: 4px; font-size: 18px; }
  .pwl-crew > [data-pwl-add], .worklist-page #add-worker {
    min-height: 36px;
    margin-top: 6px;
    padding: 6px 10px;
    font-size: 13px;
    line-height: 20px;
  }
  .pwl-totals { padding: 8px 12px; gap: 18px; }
  .pwl-totals strong { font-size: 18px; }
  .pwl-run, .pwl-result-summary { margin: 6px 0; }
  .pwl-table :is(th, td) { padding: 4px 5px; }
  .pilot-worklist .pwl-table [data-pwl-note] { min-height: 32px; padding: 5px; font-size: 12px; line-height: 16px; }
}
