/* Phone density is component-specific; keep root sizing and user zoom intact. */
@media (max-width: 600px) and (pointer: coarse) {
  html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }

  body {
    touch-action: pan-y pinch-zoom;
  }

  body:has(#app[data-route="live"]) {
    --nav-height: max(48px, 3rem);
    /* The header consumes its actual flex height; no duplicated header math. */
    position: fixed;
    top: var(--wm-viewport-offset-top, 0px);
    width: 100%;
    height: var(--wm-viewport-height);
    min-height: 0;
    overflow: hidden;
  }

  body:has(#app[data-route="live"]) .wm-header {
    padding: 2px 0.5rem;
    flex-shrink: 0;
  }

  body:has(#app[data-route="live"]) .wm-brand,
  body:has(#app[data-route="live"]) .wm-menu-toggle {
    min-height: 44px;
    min-width: 44px;
  }

  body:has(#app[data-route="live"]) .wm-logo {
    width: 28px;
    height: 28px;
  }

  .wm-tabs-bar {
    padding-inline: 0.5rem;
  }

  .wm-tabs-bar .wm-tab {
    font-size: 0.8125rem;
    min-height: 44px;
  }

  .wm-tabs-bar .wm-tab__button {
    min-height: 44px;
    padding: 0.25rem 0.5rem;
  }

  .wm-tabs-bar .wm-tab .close,
  .wm-live-header-toggle {
    min-width: 44px;
    min-height: 44px;
    width: 44px;
  }

  body:has(#app[data-route="live"]) #app[data-route="live"] {
    display: flex;
    flex: 1;
    min-height: 0;
    height: auto;
    padding: 0;
    overflow: hidden;
  }

  body:has(#app[data-route="live"]) #app .wm-live {
    flex: 1;
    min-width: 0;
    min-height: 0;
    height: 100%;
    gap: 0;
    overflow: hidden;
  }

  #app[data-route="live"] .wm-tabs-bar {
    position: relative;
    top: auto;
    flex: none;
    width: 100%;
    margin-inline: 0;
  }

  #app[data-route="live"] .wm-live-main {
    padding: 0.75rem;
    gap: 0.5rem;
    overflow: hidden;
  }

  #app[data-route="live"] .wm-live-scroll {
    height: auto;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    padding-bottom: 0;
  }

  #app[data-route="live"] .wm-live-conversation {
    flex: none;
    overflow: visible;
    padding: 0;
  }

  #app[data-route="live"] .wm-message,
  #app[data-route="live"] .wm-message:has(.wm-message-timestamp),
  #app[data-route="live"] .wm-message:has(.wm-message-working-notes[open]) {
    font-size: 0.9375rem;
    padding: 0.75rem;
  }

  /* Let every variant size its own action row, including closed tool notes. */
  #app[data-route="live"] .wm-message .wm-message-actions {
    position: static;
    display: flex;
    justify-content: flex-end;
    max-width: 100%;
    margin-top: 0.5rem;
  }

  #app[data-route="live"] .wm-message:has(.wm-message-working-notes:not([open])) {
    display: flex;
    align-items: center;
    gap: 0.75rem;
  }

  #app[data-route="live"] .wm-message:has(.wm-message-working-notes:not([open])) .wm-message-actions {
    margin-top: 0;
    flex-shrink: 0;
  }

  #app[data-route="live"] .wm-message-copy,
  #app[data-route="live"] .wm-message-speech-play {
    flex-shrink: 0;
  }

  #app[data-route="live"] .wm-message pre {
    font-size: 0.875rem;
  }

  #app[data-route="live"] .wm-composer-shell {
    position: relative;
    bottom: auto;
    flex: none;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.375rem;
    background: var(--bg-secondary);
    /* This is the only bottom safe-area owner, including in split mode. */
    padding: 0.5rem 0.5rem calc(0.5rem + env(safe-area-inset-bottom, 0px));
  }

  #app[data-route="live"] .wm-composer {
    grid-template-columns: minmax(0, 1fr) auto;
    padding: 0.625rem;
    gap: 0.375rem;
  }

  #app[data-route="live"] .wm-composer,
  #app[data-route="live"] .wm-image-preview-container {
    grid-column: 1 / -1;
  }

  #app[data-route="live"] .wm-scroll-pill {
    position: static;
    order: -1;
    transform: none;
    max-width: 100%;
    min-width: 0;
    min-height: 32px;
    margin: 0;
    padding: 0.25rem;
    font-size: 0.75rem;
  }

  #app[data-route="live"] .wm-knight-rider {
    /* Keep activity feedback clear of the input border and text. */
    top: auto;
    bottom: 1px;
    left: 0.5rem;
    right: 0.5rem;
    height: 2px;
    border-radius: 0;
  }

  #app[data-route="live"] .wm-composer-context {
    font-size: 0.8125rem;
  }

  #app[data-route="live"] .wm-composer textarea {
    /* iOS focus must not zoom the page; rem still follows larger user text. */
    font-size: max(16px, 1rem);
    font-family: inherit;
    min-height: 48px;
    padding: 0.5rem;
    border-radius: 0.5rem;
  }

  #app[data-route="live"] .wm-composer .wm-button-group {
    flex-direction: column;
    align-items: stretch;
    gap: 0.25rem;
  }

  #app[data-route="live"] .wm-composer .wm-button {
    width: 100%;
    min-width: 44px;
    min-height: 0;
    height: 2rem;
    padding: 0 0.625rem;
    font-size: 0.8125rem;
    line-height: 1;
  }

  #app[data-route="live"] .wm-agent-status-pill {
    font-size: 0.75rem;
    padding-inline: 0.5rem;
    width: auto;
    min-width: 44px;
    min-height: 44px;
    height: auto;
    margin-right: auto;
  }

  #app[data-route="live"] .wm-command-wrapper {
    width: 100%;
  }
}
