/* TOC Monkey phone-landscape polish.
   Applies only to short coarse-pointer landscape viewports so desktop/tablet
   layouts remain untouched and portrait keeps using mobile-polish.css. */
@media (orientation: landscape) and (max-height: 500px) and (pointer: coarse) {
  html,
  body.tm-mobile-ready {
    width: 100%;
    max-width: 100%;
    overflow-x: clip;
    -webkit-text-size-adjust: 100%;
  }

  body.tm-mobile-ready {
    touch-action: manipulation;
  }

  body.tm-mobile-ready button:not(.leaflet-control-zoom-in):not(.leaflet-control-zoom-out),
  body.tm-mobile-ready select,
  body.tm-mobile-ready input,
  body.tm-mobile-ready [role="button"]:not(.leaflet-control) {
    min-height: 44px;
  }

  body.tm-mobile-ready input,
  body.tm-mobile-ready select,
  body.tm-mobile-ready textarea {
    font-size: 16px !important;
  }

  /* Keep utility/header controls and COCOM switching on swipeable single rows. */
  .tm-mobile-utility-row,
  .tm-mobile-cocom-tabs {
    display: flex !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
    width: 100% !important;
    max-width: 100% !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    overscroll-behavior-x: contain;
  }
  .tm-mobile-utility-row::-webkit-scrollbar,
  .tm-mobile-cocom-tabs::-webkit-scrollbar { display: none; }

  .tm-mobile-utility-row { gap: 8px !important; padding-bottom: 3px !important; }
  .tm-mobile-utility-action {
    flex: 0 0 auto !important;
    min-height: 44px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    white-space: nowrap !important;
    padding-left: 12px !important;
    padding-right: 12px !important;
  }

  .tm-mobile-cocom-tabs {
    gap: 6px !important;
    scroll-snap-type: x proximity;
    padding: 3px 2px 5px !important;
  }
  .tm-mobile-cocom-tab {
    flex: 0 0 auto !important;
    min-width: 76px !important;
    min-height: 44px !important;
    padding: 7px 11px !important;
    scroll-snap-align: start;
    white-space: nowrap !important;
    font-size: 11px !important;
    line-height: 1.1 !important;
  }

  /* Make annotated operational panels span a desktop grid instead of remaining
     trapped in half-width desktop columns after the phone rotates. */
  .tm-mobile-panel {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    grid-column: 1 / -1 !important;
    box-sizing: border-box !important;
  }
  .tm-mobile-panel > * {
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
  }

  /* Short landscape viewport: useful map, but don't let it swallow the page. */
  .leaflet-container.tm-mobile-map {
    width: 100% !important;
    height: clamp(240px, 62dvh, 310px) !important;
    min-height: 240px !important;
    max-height: 310px !important;
  }
  .tm-mobile-map-panel {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    overflow: hidden !important;
  }
  .tm-mobile-map-panel .leaflet-control-container a {
    min-width: 36px;
    min-height: 36px;
  }

  /* Compact scroll windows preserve room for neighboring content in landscape. */
  .tm-mobile-panel .tm-feed-window,
  .tm-mobile-panel.tm-mobile-osint-panel .tm-osint-dense-list,
  .tm-mobile-panel.tm-mobile-sigact-panel .tm-sigact-list {
    height: clamp(170px, 45dvh, 230px) !important;
    min-height: 170px !important;
    max-height: 230px !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }
  .tm-mobile-sigact-panel .tm-sigact-list {
    scroll-snap-type: y proximity;
    scroll-padding-top: 6px;
  }
  .tm-mobile-sigact-panel .tm-sigact-row[data-tm-aor-match="true"] {
    min-height: 62px;
    padding-top: 8px !important;
    padding-bottom: 8px !important;
    overflow-wrap: anywhere;
  }
  .tm-mobile-sigact-panel .ph {
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    gap: 8px !important;
    min-width: 0 !important;
  }
  .tm-mobile-sigact-panel .ph .pht { min-width: 0; }
  .tm-mobile-sigact-panel .ph .phs {
    flex: 0 1 auto;
    max-width: 48%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 8px !important;
  }

  .tm-osint-dense .tm-osint-dense-card {
    max-height: 116px !important;
    padding: 8px 10px !important;
  }

  /* Preserve a real 16:9 TOC TV player, but cap it by viewport height. */
  #eqpnl.tm-tv-panel.tm-mobile-tv-panel {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    overflow: visible !important;
  }
  .tm-mobile-tv-panel .tm-tv-shell {
    width: 100% !important;
    gap: 7px !important;
    padding: 8px calc(10px + env(safe-area-inset-right)) 8px calc(10px + env(safe-area-inset-left)) !important;
    box-sizing: border-box;
  }
  .tm-mobile-tv-panel .tm-tv-frame-wrap {
    width: min(100%, calc(62dvh * 16 / 9)) !important;
    max-width: 100% !important;
    max-height: 62dvh !important;
    aspect-ratio: 16 / 9 !important;
    margin: 0 auto !important;
  }
  .tm-mobile-tv-panel .tm-tv-meta {
    padding: 4px 1px !important;
  }
  .tm-mobile-tv-panel .tm-tv-title {
    font-size: 12px !important;
    line-height: 1.25 !important;
    white-space: nowrap !important;
    display: block !important;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .tm-mobile-tv-panel .tm-tv-controls {
    grid-template-columns: minmax(0, 1fr) auto !important;
    align-items: end !important;
    gap: 7px !important;
  }
  .tm-mobile-tv-panel .tm-tv-picker {
    grid-template-columns: auto minmax(0, 1fr) !important;
    gap: 6px !important;
  }
  .tm-mobile-tv-panel .tm-tv-select {
    width: 100% !important;
    min-height: 44px !important;
    height: 44px !important;
    padding: 8px 32px 8px 9px !important;
  }
  .tm-mobile-tv-panel .tm-tv-actions {
    display: flex !important;
    grid-template-columns: none !important;
    gap: 7px !important;
    width: auto !important;
  }
  .tm-mobile-tv-panel .tm-tv-actions a {
    min-height: 44px !important;
    height: 44px !important;
    padding: 0 10px !important;
    font-size: 9px !important;
  }

  /* Full visible-viewport AO sheet with notch/home-indicator protection. */
  #tm-knowledge-drawer {
    width: 100vw !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    border-left: 0 !important;
    box-sizing: border-box !important;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .tm-k-head {
    padding: 7px calc(10px + env(safe-area-inset-right)) 7px calc(10px + env(safe-area-inset-left)) !important;
    gap: 8px !important;
  }
  .tm-k-title { font-size: 12px !important; }
  .tm-k-subtitle { font-size: 8px !important; }
  .tm-k-close {
    min-width: 68px;
    min-height: 44px;
  }
  .tm-k-tools {
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: 6px !important;
    padding: 6px calc(10px + env(safe-area-inset-right)) 6px calc(10px + env(safe-area-inset-left)) !important;
  }
  .tm-k-tools input { grid-column: 1 / -1 !important; }
  .tm-k-tools select,
  .tm-k-tools input {
    min-height: 44px;
    padding: 7px 9px !important;
  }
  .tm-k-focus,
  .tm-k-stats,
  .tm-k-reference,
  .tm-k-list,
  .tm-k-detail,
  .tm-k-note {
    padding-left: calc(10px + env(safe-area-inset-left)) !important;
    padding-right: calc(10px + env(safe-area-inset-right)) !important;
  }
  .tm-k-card { padding: 9px !important; }
  .tm-k-open { min-height: 40px !important; padding: 7px 9px !important; }
  .tm-k-dossier { padding: 10px !important; }
  .tm-k-dossier h2 { font-size: 18px !important; }
  .tm-k-systems,
  .tm-k-related-grid { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }

  #tm-knowledge-launcher.tm-map-mounted {
    right: calc(10px + env(safe-area-inset-right)) !important;
    bottom: calc(8px + env(safe-area-inset-bottom)) !important;
    min-height: 44px !important;
    padding: 9px 12px !important;
  }

  body.tm-mobile-ready img,
  body.tm-mobile-ready video,
  body.tm-mobile-ready iframe,
  body.tm-mobile-ready canvas,
  body.tm-mobile-ready svg {
    max-width: 100%;
  }

  body.tm-mobile-ready [id] { scroll-margin-top: 56px; }
}
