/* Душевный AutoMix | Mobile chat: dense reading layout v4.
   This file is an overlay. Does NOT change chat transport, folding or scroll logic.
   Only applies where mobile-layout.js enables the mobile layout (<=650px). */
@media (max-width:650px) {
  /* Give the content almost the full width of the existing collapsible panel. */
  html.am-mobile-layout body .wapper .content .block.am-mobile-fold > .am-fold-body:has(> #chat) {
    padding: 5px 5px 8px !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
  }
  html.am-mobile-layout body .wapper .content #chat {
    box-sizing: border-box !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    padding: 5px 4px 7px !important;
    overflow: hidden !important;
  }
  html.am-mobile-layout body #chat #drop_zone,
  html.am-mobile-layout body #chat form {
    box-sizing: border-box !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    margin: 0 !important;
  }

  /* Pinned notification: much smaller while retaining all actions and text. */
  html.am-mobile-layout body #chat #fixed_message {
    margin: 0 0 7px !important;
    min-width: 0 !important;
    max-width: 100% !important;
  }
  html.am-mobile-layout body #chat #fixed_message.am-chat-pinned {
    padding: 7px 8px !important;
    margin: 0 0 7px !important;
    border-radius: 7px !important;
  }
  html.am-mobile-layout body #chat #fixed_message :is(.fixed_chat_message,.chat_message) {
    grid-template-columns: 24px minmax(0,1fr) !important;
    gap: 5px !important;
    min-width: 0 !important;
    padding: 0 !important;
    border: 0 !important;
  }
  html.am-mobile-layout body #chat #fixed_message :is(.fixed_chat_message,.chat_message) > a,
  html.am-mobile-layout body #chat #fixed_message :is(.fixed_chat_message,.chat_message) > a > img {
    width: 24px !important;
    height: 24px !important;
    max-width: 24px !important;
    min-width: 0 !important;
    margin: 0 !important;
    float: none !important;
    border-radius: 50% !important;
  }
  html.am-mobile-layout body #chat #fixed_message .fixed_chat_message .info,
  html.am-mobile-layout body #chat #fixed_message .chat_message .info {
    min-height: 22px !important;
    gap: 3px !important;
    margin: 0 !important;
  }
  html.am-mobile-layout body #chat #fixed_message :is(.fixed_chat_message,.chat_message) .info .author {
    font-size: 12px !important;
    line-height: 1.2 !important;
    overflow: hidden !important;
    white-space: nowrap !important;
    text-overflow: ellipsis !important;
  }
  html.am-mobile-layout body #chat #fixed_message :is(.fixed_chat_message,.chat_message) .info .date {
    font-size: 10px !important;
    line-height: 1.2 !important;
  }
  html.am-mobile-layout body #chat #fixed_message .fixed_chat_message .info > div:has(.fixed_message) {
    gap: 2px !important;
    min-width: 0 !important;
  }
  html.am-mobile-layout body #chat #fixed_message :is(.fixed_chat_message,.chat_message) .info :is(.fixed_message,.pin_message,.dell_message,.edit_message) {
    box-sizing: border-box !important;
    font-size: 12px !important;
    width: 22px !important;
    height: 22px !important;
    line-height: 22px !important;
  }
  html.am-mobile-layout body #chat #fixed_message .fixed_chat_message [id^="message_text_"] {
    margin: 3px 0 0 !important;
  }
  html.am-mobile-layout body #chat #fixed_message :is(.fixed_chat_message,.chat_message) :is(.with_code,[id^="message_text_"]),
  html.am-mobile-layout body #chat #fixed_message :is(.fixed_chat_message,.chat_message) :is(.with_code,[id^="message_text_"]) :is(span,a,p) {
    box-sizing: border-box !important;
    max-width: 100% !important;
    font-size: 12px !important;
    line-height: 1.32 !important;
    overflow-wrap: anywhere !important;
  }

  /* One fixed-height viewport for the history, rather than a 400px-tall block. */
  html.am-mobile-layout body #chat #chat_messages {
    box-sizing: border-box !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    height: 236px !important;
    max-height: 236px !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
  }
  html.am-mobile-layout body #chat #drop_zone:is(.hover,.error) #chat_messages {
    height: 236px !important;
  }
  html.am-mobile-layout body #chat #chat_messages .chat_message {
    display: grid !important;
    grid-template-columns: 24px minmax(0,1fr) !important;
    column-gap: 5px !important;
    row-gap: 1px !important;
    box-sizing: border-box !important;
    min-width: 0 !important;
    width: 100% !important;
    padding: 5px 2px 5px 0 !important;
    margin: 0 !important;
  }
  html.am-mobile-layout body #chat #chat_messages .chat_message > a,
  html.am-mobile-layout body #chat #chat_messages .chat_message > a > img {
    width: 24px !important;
    max-width: 24px !important;
    height: 24px !important;
    margin: 0 !important;
    float: none !important;
    border-radius: 50% !important;
  }
  html.am-mobile-layout body #chat #chat_messages .chat_message > .message {
    box-sizing: border-box !important;
    min-width: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    font-size: 12px !important;
    line-height: 1.32 !important;
  }
  html.am-mobile-layout body #chat #chat_messages .chat_message .message .info {
    display: flex !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
    box-sizing: border-box !important;
    gap: 3px !important;
    min-height: 21px !important;
    height: auto !important;
    margin: 0 0 1px !important;
    padding: 0 !important;
  }
  html.am-mobile-layout body #chat #chat_messages .chat_message .info .author {
    flex: 1 1 0 !important;
    min-width: 0 !important;
    max-width: 100% !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
    font-size: 12px !important;
    line-height: 1.2 !important;
  }
  html.am-mobile-layout body #chat #chat_messages .chat_message .info .date {
    position: static !important;
    flex: 0 0 auto !important;
    float: none !important;
    margin: 0 2px 0 0 !important;
    font-size: 10px !important;
    line-height: 1.2 !important;
    white-space: nowrap !important;
  }
  /* Small icons, but maintain tappable areas for moderator controls. */
  html.am-mobile-layout body #chat #chat_messages .chat_message .info :is(.pin_message,.dell_message,.edit_message) {
    position: static !important;
    flex: 0 0 22px !important;
    width: 22px !important;
    height: 22px !important;
    line-height: 22px !important;
    box-sizing: border-box !important;
    text-align: center !important;
    font-size: 12px !important;
    margin: 0 !important;
    padding: 0 !important;
  }
  html.am-mobile-layout body #chat #chat_messages .chat_message :is(.with_code,[id^="message_text_"]:not(textarea)),
  html.am-mobile-layout body #chat #chat_messages .chat_message :is(.with_code,[id^="message_text_"]:not(textarea)) :is(a,span,p) {
    min-width: 0 !important;
    max-width: 100% !important;
    font-size: 12px !important;
    line-height: 1.33 !important;
    overflow-wrap: anywhere !important;
  }
  html.am-mobile-layout body #chat #chat_messages .chat_message .message img {
    max-width: 100% !important;
    max-height: 132px !important;
    width: auto;
    height: auto;
    object-fit: contain;
  }
  /* Narrower input margins. Keep 16px editing font to prevent iOS focus zoom. */
  html.am-mobile-layout body #chat .input-group.mt-3.am-chat-compose {
    margin: 5px 0 0 !important;
    gap: 5px !important;
    grid-template-columns: minmax(0,1fr) clamp(86px,24%,102px) !important;
  }
  html.am-mobile-layout body #chat .am-chat-compose #message_input {
    font-size: 16px !important;
  }
  html.am-mobile-layout body #chat .am-chat-compose #send_button {
    font-size: 11px !important;
  }
}
 
/* v5: mobile pinned message and chat body deliberately denser.
   This file is a visual override only; it never hides message controls,
   changes how the chat is sent, or changes scroll JS. */
@media (max-width:650px) {
  html.am-mobile-layout body .wapper .content .am-mobile-fold > .am-fold-body:has(#chat) {
    padding: 3px 4px 6px !important;
  }
  html.am-mobile-layout body .wapper .content #chat {
    padding: 2px 2px 4px !important;
  }
  /* Pinned section: compact header, smaller text, no minimum height. */
  html.am-mobile-layout body #chat #fixed_message {
    margin: 0 0 4px !important;
  }
  html.am-mobile-layout body #chat #fixed_message.am-chat-pinned {
    padding: 5px 6px !important;
    margin: 0 0 4px !important;
    border-radius: 6px !important;
  }
  html.am-mobile-layout body #chat #fixed_message .fixed_chat_message {
    grid-template-columns: 21px minmax(0,1fr) !important;
    gap: 3px 4px !important;
    min-height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
  }
  html.am-mobile-layout body #chat #fixed_message .fixed_chat_message > a,
  html.am-mobile-layout body #chat #fixed_message .fixed_chat_message > a img {
    width: 21px !important;
    height: 21px !important;
    max-width: 21px !important;
    margin: 0 !important;
  }
  html.am-mobile-layout body #chat #fixed_message .fixed_chat_message .info {
    display: grid !important;
    grid-template-columns: minmax(0,1fr) auto !important;
    gap: 3px !important;
    min-height: 21px !important;
    height: auto !important;
    align-content: center !important;
  }
  html.am-mobile-layout body #chat #fixed_message .fixed_chat_message .info .author,
  html.am-mobile-layout body #chat #fixed_message .fixed_chat_message .info .author * {
    font-size: 11px !important;
    line-height: 1.18 !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }
  html.am-mobile-layout body #chat #fixed_message .fixed_chat_message .info > div:has(.fixed_message) {
    display: flex !important;
    flex-wrap: nowrap !important;
    grid-column: 2 !important;
    grid-row: 1 !important;
    gap: 2px !important;
    margin: 0 !important;
    padding: 0 !important;
  }
  html.am-mobile-layout body #chat #fixed_message .fixed_chat_message .info :is(.fixed_message,.pin_message,.dell_message,.edit_message) {
    width: 24px !important;
    height: 24px !important;
    min-width: 24px !important;
    line-height: 24px !important;
    font-size: 11px !important;
    text-align: center !important;
  }
  html.am-mobile-layout body #chat #fixed_message .fixed_chat_message .info .date {
    font-size: 9px !important;
    line-height: 1.2 !important;
  }
  html.am-mobile-layout body #chat #fixed_message .fixed_chat_message [id^="message_text_"]:not(textarea) {
    grid-column: 1 / -1 !important;
    min-width: 0 !important;
    margin: 1px 0 0 !important;
    padding: 0 !important;
    font-size: 11px !important;
    line-height: 1.23 !important;
    overflow-wrap: anywhere !important;
  }
  html.am-mobile-layout body #chat #fixed_message .fixed_chat_message [id^="message_text_"]:not(textarea) :is(span,a,p,div,b,em,strong) {
    font-size: 11px !important;
    line-height: 1.23 !important;
    max-width: 100% !important;
    overflow-wrap: anywhere !important;
  }
  /* Shorter scrollable chat history; no message truncation. */
  html.am-mobile-layout body #chat #chat_messages,
  html.am-mobile-layout body #chat #drop_zone:is(.hover,.error) #chat_messages {
    height: clamp(132px, 38vw, 160px) !important;
    max-height: 160px !important;
    min-height: 0 !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
  }
  html.am-mobile-layout body #chat #chat_messages .chat_message {
    grid-template-columns: 21px minmax(0,1fr) !important;
    column-gap: 4px !important;
    padding: 3px 1px 3px 0 !important;
  }
  html.am-mobile-layout body #chat #chat_messages .chat_message > a,
  html.am-mobile-layout body #chat #chat_messages .chat_message > a img {
    width: 21px !important;
    height: 21px !important;
    max-width: 21px !important;
    margin: 0 !important;
  }
  html.am-mobile-layout body #chat #chat_messages .chat_message .message .info {
    min-height: 20px !important;
    gap: 2px !important;
    margin: 0 !important;
  }
  html.am-mobile-layout body #chat #chat_messages .chat_message .info .author {
    font-size: 11px !important;
    line-height: 1.22 !important;
  }
  html.am-mobile-layout body #chat #chat_messages .chat_message .info .date {
    font-size: 9px !important;
    line-height: 1.2 !important;
  }
  html.am-mobile-layout body #chat #chat_messages .chat_message .info :is(.pin_message,.dell_message,.edit_message) {
    flex: 0 0 22px !important;
    width: 22px !important;
    height: 22px !important;
    line-height: 22px !important;
    font-size: 11px !important;
  }
  html.am-mobile-layout body #chat #chat_messages .chat_message :is(.with_code,[id^="message_text_"]:not(textarea)),
  html.am-mobile-layout body #chat #chat_messages .chat_message :is(.with_code,[id^="message_text_"]:not(textarea)) :is(a,span,p) {
    font-size: 11px !important;
    line-height: 1.24 !important;
  }
  html.am-mobile-layout body #chat #chat_messages .chat_message .message img {
    max-width: 100% !important;
    max-height: 90px !important;
    object-fit: contain !important;
  }
  /* Compact vertical spacing around composer; preserve iOS 16px editing font. */
  html.am-mobile-layout body #chat .input-group.mt-3.am-chat-compose {
    margin-top: 3px !important;
    gap: 4px !important;
    grid-template-columns: minmax(0,1fr) clamp(80px,22%,94px) !important;
  }
  html.am-mobile-layout body #chat .am-chat-compose #send_button {
    padding-left: 4px !important;
    padding-right: 4px !important;
    font-size: 11px !important;
  }
}
