/* MOBILE AI CHAT — clean bottom-sheet layout with full desktop feature set.
   This CSS overrides any JS-injected styles for small screens. */

@media (max-width: 600px) {
  /* Full-screen dimmed backdrop; JS toggles display via inline style. */
  #aiModal {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    max-width: 100vw !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    display: flex !important;
    align-items: center !important;   /* centered vertically */
    justify-content: center !important;
    background: rgba(4, 16, 28, 0.72) !important;
    backdrop-filter: blur(8px) !important;
    /* Push above any Cesium / Tour3D overlays and controls */
    z-index: 300000 !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
  }

  /* Card: centered panel, never wider than viewport. */
  #aiModal .modal-content.ai-modal-modern {
    position: relative !important;
    left: auto !important;
    right: auto !important;
    width: min(94vw, 480px) !important;
    max-width: 94vw !important;
    min-width: 0 !important;
    margin: 0 !important;
    border-radius: 18px !important;
    background: linear-gradient(180deg, #ffffff 0%, #f7fbf9 100%) !important;
    box-shadow: 0 18px 40px rgba(5, 20, 34, 0.55) !important;
    height: 78dvh !important;
    max-height: 78dvh !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
    padding: 0 !important;
    border: 1px solid #caded6 !important;
    box-sizing: border-box !important;
  }

  /* Header with title + close button. */
  #aiModal .ai-modal-header {
    background: linear-gradient(120deg, #154034, #23705b) !important;
    color: #fff !important;
    padding: 0.85rem 1rem !important;
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    flex-shrink: 0 !important;
  }

  #aiModal .ai-modal-title {
    font-size: 0.98rem !important;
    font-weight: 700 !important;
    letter-spacing: 0.03em !important;
    margin: 0 !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    min-width: 0 !important;
  }

  #aiModal .modal-close {
    width: 32px !important;
    height: 32px !important;
    border-radius: 8px !important;
    border: 1px solid rgba(255,255,255,0.35) !important;
    background: rgba(255,255,255,0.2) !important;
    color: #fff !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-size: 1.4rem !important;
    line-height: 1 !important;
    padding: 0 !important;
    cursor: pointer !important;
  }

  #aiModal .modal-close:hover {
    background: rgba(255,255,255,0.35) !important;
  }

  /* Main chat area: scrollable messages. */
  #aiModal .ai-chat-window {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    max-height: none !important;
    display: flex !important;
    flex-direction: column !important;
    padding: 0.5rem 0.85rem 0.3rem 0.85rem !important;
    background: transparent !important;
  }

  #aiModal .ai-chat-messages {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    max-height: 100% !important;
    overflow-y: auto !important;
    padding: 0.4rem 0 0.6rem 0 !important;
    margin: 0 !important;
  }

  #aiModal .ai-chat-message {
    margin-bottom: 0.65rem !important;
    display: flex !important;
  }

  #aiModal .ai-chat-message.user {
    justify-content: flex-end !important;
  }

  #aiModal .ai-chat-message.user span,
  #aiModal .ai-chat-message.ai span {
    display: inline-block !important;
    padding: 0.55rem 0.85rem !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    font-size: 0.9rem !important;
  }

  #aiModal .ai-chat-message.user span {
    background: linear-gradient(120deg, #164638, #1e6a54) !important;
    color: #fff !important;
    border-radius: 16px 16px 6px 16px !important;
    box-shadow: 0 3px 10px rgba(22,70,56,0.25) !important;
  }

  #aiModal .ai-chat-message.ai span,
  #aiModal .ai-chat-message.ai span.ai-message-body {
    background: #ffffff !important;
    color: #163f34 !important;
    border-radius: 16px 16px 16px 6px !important;
    border: 1px solid #d7e7e1 !important;
    box-shadow: 0 1px 4px rgba(11,32,26,0.08) !important;
    line-height: 1.55 !important;
    white-space: pre-wrap !important;
  }

  /* Suggested prompts: label + pill buttons just above input. */
  #aiModal .ai-suggested-prompts-bottom {
    flex-shrink: 0 !important;
    padding: 0.3rem 0.45rem 0.2rem 0.45rem !important;
    margin: 0 !important;
    border-top: none !important;
    border-bottom: none !important;
    background: #f8fbfa !important;
    box-shadow: none !important;
    overflow: hidden !important;
  }

  #aiModal .ai-suggested-label {
    font-size: 0.74rem !important;
    font-weight: 700 !important;
    color: #255647 !important;
    margin-bottom: 0.18rem !important;
    text-align: center !important;
  }

  #aiModal .ai-suggested-prompts-row {
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: 0.3rem !important;
    width: 100% !important;
    align-items: stretch !important;
    justify-items: stretch !important;
    overflow: hidden !important;
    scrollbar-width: none !important;
  }

  #aiModal .ai-suggested-prompt-btn {
    width: 100% !important;
    padding: 0.1rem 0.35rem !important;
    height: 26px !important;
    border-radius: 999px !important;
    border: 1px solid #c8ddd5 !important;
    background: #fff !important;
    color: #255647 !important;
    font-size: 0.72rem !important;
    font-weight: 700 !important;
    white-space: nowrap !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
  }

  #aiModal .ai-suggested-prompt-btn:hover {
    background: #eef6f2 !important;
  }

  /* Input row: docked at bottom of the card, not the page. */
  #aiModal .ai-chat-form {
    flex-shrink: 0 !important;
    display: flex !important;
    gap: 0.5rem !important;
    padding: 0.45rem 0.65rem 0.55rem 0.65rem !important;
    border-top: none !important;
    border-bottom: none !important;
    background: #ffffff !important;
    box-shadow: none !important;
  }

  #aiModal .ai-chat-form input {
    flex: 1 1 auto !important;
    min-width: 0 !important;
    padding: 0.55rem 0.75rem !important;
    border-radius: 999px !important;
    border: 1px solid #c8dcd4 !important;
    font-size: 0.9rem !important;
    background: #f8fbfa !important;
  }

  #aiModal .ai-chat-form input:focus {
    border-color: #1e6b48 !important;
    outline: none !important;
    background: #ffffff !important;
  }

  #aiModal .ai-chat-form button {
    padding: 0.55rem 1.1rem !important;
    border-radius: 999px !important;
    border: none !important;
    background: linear-gradient(120deg, #18483b, #1f6d58) !important;
    color: #ffffff !important;
    font-size: 0.9rem !important;
    font-weight: 700 !important;
    white-space: nowrap !important;
    box-shadow: 0 4px 10px rgba(20,71,58,0.25) !important;
  }

  #aiModal .ai-chat-form button:hover {
    background: linear-gradient(120deg, #143e32, #1a5f4d) !important;
  }
}
