/* Adjustments for narrow screens, touch and reduced motion. Loaded last. */

/* ---------- Responsive ---------- */

.mobile-menu {
  display: inline-grid;
}

@media (max-width: 980px) {
  .form-grid.two {
    grid-template-columns: 1fr;
  }

  .inline-form {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 900px) {
  :root {
    --gutter: 0px;
  }

  .app {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(300px, 86vw);
    z-index: 60;
    transform: translateX(-100%);
    transition: transform var(--sidebar-duration) var(--ease-out);
  }

  .sidebar.open {
    transform: none;
    box-shadow: 16px 0 48px rgba(0, 0, 0, 0.5);
  }

  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 55;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--sidebar-duration) var(--ease-out);
  }

  .sidebar-backdrop.visible {
    opacity: 1;
    pointer-events: auto;
  }

  .chat-header {
    padding: 6px 10px;
  }

  .messages {
    padding: 20px 14px 12px;
  }

  /* On narrow screens the role moves above the text */
  .msg {
    grid-template-columns: minmax(0, 1fr);
  }

  .msg-role {
    text-align: left;
    padding: 0 0 2px;
  }

  .msg-body,
  .msg-bubble {
    padding-left: 12px;
  }

  .msg-body {
    border-left: 1px solid var(--line);
  }

  /* The answer already has its line on narrow screens */
  .work {
    margin-left: 0;
    padding-left: 0;
    border-left: none;
  }

  .msg-role.err {
    padding-top: 0;
  }

  .status-note,
  .chat-empty-inner {
    padding-left: 13px;
  }

  .composer-wrap {
    padding: 0 10px calc(10px + env(safe-area-inset-bottom));
  }

  /* iOS zooms into inputs below 16px */
  .composer-input,
  .input,
  .select,
  .textarea,
  .sidebar-search-input,
  .chat-title {
    font-size: 16px;
  }

  .msg-actions {
    grid-column: 1;
    opacity: 1;
    padding-left: 8px;
  }

  .msg.user .msg-actions,
  .messages > .msg.user:first-child .msg-actions {
    position: static;
    width: auto;
    justify-content: flex-start;
    margin-top: 2px;
    padding-left: 8px;
  }

  .msg-action span {
    display: none;
  }

  .usage-indicator {
    display: none;
  }

  .context-cut {
    padding-left: 13px;
    flex-direction: column;
    gap: 4px;
  }

  .ready {
    padding-top: 4vh;
  }

  .ready-model,
  .ready-warning {
    padding-left: 0;
    margin-left: 0;
    font-size: 28px;
  }

  .ready-rows,
  .ready-suggestions,
  .ready-recent,
  .ready-start,
  .ready-note {
    padding-left: 12px;
  }

  .ready-start .ready-note {
    padding-left: 0;
  }

  .ready-row {
    grid-template-columns: 110px minmax(0, 1fr);
  }

  .suggestion {
    flex-wrap: wrap;
  }

  .suggestion-hint {
    margin-left: 0;
    padding-left: 22px;
    width: 100%;
  }


  .modal-backdrop {
    padding: 10px;
  }

  .modal {
    max-height: 94vh;
  }

  .inline-form {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 520px) {
  .tools-btn span {
    display: none;
  }

  .auth-card {
    padding: 22px 18px 18px;
  }

  .chat-title {
    max-width: 100%;
  }

  .chat-sub .select-compact {
    max-width: 150px;
  }

  .mcp-indicator {
    display: none;
  }

  .composer-hint {
    display: none;
  }
}

/* Touch screens have no hover: keep row actions reachable */
@media (hover: none) {
  .nav-actions,
  .chat-item-actions {
    display: flex;
  }

  .nav-item.has-actions .nav-count {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Installed app on iPhone: content may run under the status bar and home indicator.
   Kept last so it wins over the paddings above; env() is 0 everywhere else. */
.sidebar-head {
  height: auto;
  min-height: calc(52px + env(safe-area-inset-top));
  padding-top: env(safe-area-inset-top);
}

.chat-header {
  min-height: calc(52px + env(safe-area-inset-top));
  padding-top: calc(6px + env(safe-area-inset-top));
}

.sidebar-foot {
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
}
