/* TOC Monkey mobile-first public polish. Desktop is intentionally untouched. */
@media (max-width: 820px) {
  html,
  body.tm-mobile-ready {
    max-width: 100%;
    overflow-x: clip;
    -webkit-text-size-adjust: 100%;
  }

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

  /* Thumb-friendly interactive controls without disturbing Leaflet map controls. */
  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; /* prevents iOS focus zoom */
  }

  /* Utility/header actions become a clean horizontal strip instead of wrapping into noise. */
  .tm-mobile-utility-row {
    display: flex !important;
    align-items: center !important;
    gap: 8px !important;
    max-width: 100% !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    overscroll-behavior-x: contain;
    padding-bottom: 4px !important;
  }
  .tm-mobile-utility-row::-webkit-scrollbar { display: none; }
  .tm-mobile-utility-action {
    flex: 0 0 auto !important;
    min-height: 40px !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;
  }

  /* COCOM switching stays one line and swipes naturally. */
  .tm-mobile-cocom-tabs {
    display: flex !important;
    flex-wrap: nowrap !important;
    align-items: stretch !important;
    gap: 6px !important;
    width: 100% !important;
    max-width: 100% !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    scroll-snap-type: x proximity;
    overscroll-behavior-x: contain;
    padding: 4px 2px 7px !important;
  }
  .tm-mobile-cocom-tabs::-webkit-scrollbar { display: none; }
  .tm-mobile-cocom-tab {
    flex: 0 0 auto !important;
    min-width: 78px !important;
    min-height: 44px !important;
    padding: 9px 12px !important;
    scroll-snap-align: start;
    white-space: nowrap !important;
    font-size: 12px !important;
    line-height: 1.1 !important;
  }

  /* Give the operational picture enough room to be useful on a phone. */
  .leaflet-container.tm-mobile-map {
    width: 100% !important;
    height: clamp(360px, 54svh, 560px) !important;
    min-height: 360px !important;
    max-height: 560px !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;
  }

  /* Public content panels should consume the full phone width, not preserve desktop columns. */
  .tm-mobile-panel {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
  }
  .tm-mobile-panel > * {
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
  }

  /* Live/news surfaces: more stories visible, still comfortably tappable. */
  .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(230px, 39svh, 340px) !important;
    min-height: 230px !important;
    max-height: 340px !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: 8px;
  }
  .tm-mobile-sigact-panel .tm-sigact-row[data-tm-aor-match="true"] {
    min-height: 66px;
    padding-top: 9px !important;
    padding-bottom: 9px !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 0 auto;
    white-space: nowrap;
    font-size: 8px !important;
  }

  .tm-osint-dense .tm-osint-dense-card {
    max-height: 126px !important;
    padding: 9px 10px !important;
  }
  .tm-osint-dense .tm-osint-dense-card h1,
  .tm-osint-dense .tm-osint-dense-card h2,
  .tm-osint-dense .tm-osint-dense-card h3,
  .tm-osint-dense .tm-osint-dense-card h4,
  .tm-osint-dense .tm-osint-dense-card strong,
  .tm-osint-dense .tm-osint-dense-card b {
    font-size: 14px !important;
    line-height: 1.25 !important;
  }
  .tm-osint-dense .tm-osint-dense-card p,
  .tm-osint-dense .tm-osint-dense-card [class*="text" i],
  .tm-osint-dense .tm-osint-dense-card [class*="body" i],
  .tm-osint-dense .tm-osint-dense-card [class*="content" i] {
    font-size: 12px !important;
    line-height: 1.4 !important;
    -webkit-line-clamp: 3;
  }

  /* TOC TV should feel like a native mobile panel, not a squeezed desktop quadrant. */
  #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%;
    gap: 8px !important;
    padding: 10px !important;
    box-sizing: border-box;
  }
  .tm-mobile-tv-panel .tm-tv-frame-wrap {
    width: 100% !important;
    aspect-ratio: 16 / 9;
    max-height: none !important;
  }
  .tm-mobile-tv-panel .tm-tv-meta {
    padding: 6px 1px 5px !important;
  }
  .tm-mobile-tv-panel .tm-tv-kicker,
  .tm-mobile-tv-panel .tm-tv-count {
    font-size: 9px !important;
  }
  .tm-mobile-tv-panel .tm-tv-title {
    font-size: 13px !important;
    line-height: 1.35 !important;
    white-space: normal !important;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
  }
  .tm-mobile-tv-panel .tm-tv-controls,
  .tm-mobile-tv-panel .tm-tv-picker {
    grid-template-columns: 1fr !important;
    gap: 7px !important;
  }
  .tm-mobile-tv-panel .tm-tv-picker > span {
    font-size: 9px !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: grid !important;
    grid-template-columns: 1fr 1fr;
    gap: 8px !important;
    width: 100%;
  }
  .tm-mobile-tv-panel .tm-tv-actions a {
    width: 100%;
    min-height: 44px !important;
    height: 44px !important;
    padding: 0 10px !important;
    box-sizing: border-box;
    font-size: 10px !important;
  }

  /* AO/task-org explorer becomes a true phone sheet. */
  #tm-knowledge-drawer {
    width: 100vw !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    border-left: 0 !important;
    padding-top: env(safe-area-inset-top);
  }
  .tm-k-head {
    padding: 10px 12px !important;
    gap: 8px !important;
  }
  .tm-k-title { font-size: 13px !important; }
  .tm-k-subtitle { font-size: 8px !important; }
  .tm-k-close {
    min-width: 70px;
    min-height: 44px;
  }
  .tm-k-tools {
    grid-template-columns: 1fr 1fr !important;
    gap: 7px !important;
    padding: 8px 10px !important;
  }
  .tm-k-tools input { grid-column: 1 / -1; }
  .tm-k-tools select,
  .tm-k-tools input {
    min-height: 44px;
    padding: 8px 9px !important;
  }
  .tm-k-focus,
  .tm-k-stats,
  .tm-k-reference,
  .tm-k-list,
  .tm-k-detail,
  .tm-k-note {
    padding-left: 10px !important;
    padding-right: 10px !important;
  }
  .tm-k-card { padding: 11px !important; }
  .tm-k-card-top {
    flex-direction: row !important;
    align-items: flex-start !important;
  }
  .tm-k-open {
    min-height: 40px !important;
    padding: 8px 9px !important;
  }
  .tm-k-dossier { padding: 12px !important; }
  .tm-k-dossier h2 { font-size: 19px !important; }
  .tm-k-dossier-summary,
  .tm-k-summary { font-size: 12px !important; line-height: 1.55 !important; }
  .tm-k-systems,
  .tm-k-related-grid { grid-template-columns: 1fr !important; }

  /* Keep the map explorer control above iPhone home indicator and away from edges. */
  #tm-knowledge-launcher.tm-map-mounted {
    right: 10px !important;
    bottom: calc(12px + env(safe-area-inset-bottom)) !important;
    min-height: 44px !important;
    padding: 10px 12px !important;
  }

  /* Images/media should never force horizontal scrolling. */
  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%;
  }

  /* Improve anchor landing behavior below sticky/mobile chrome. */
  body.tm-mobile-ready [id] { scroll-margin-top: 72px; }
}

@media (max-width: 430px) {
  .tm-mobile-cocom-tab {
    min-width: 74px !important;
    padding-left: 10px !important;
    padding-right: 10px !important;
  }
  .leaflet-container.tm-mobile-map {
    height: clamp(350px, 52svh, 520px) !important;
    min-height: 350px !important;
  }
  .tm-mobile-sigact-panel .ph .phs {
    max-width: 58%;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .tm-mobile-tv-panel .tm-tv-meta-top {
    gap: 6px !important;
  }
  .tm-mobile-tv-panel .tm-tv-actions {
    grid-template-columns: 1fr 1fr;
  }
  .tm-k-tools { grid-template-columns: 1fr !important; }
  .tm-k-tools input { grid-column: auto; }
}

@media (prefers-reduced-motion: reduce) {
  .tm-mobile-cocom-tabs,
  .tm-mobile-utility-row { scroll-behavior: auto !important; }
}
