/*
 * Phone layout fixes. Loaded last, after xnight-redesign.css.
 *
 * The main bug: flex children default to `min-width: auto`, so a long word,
 * a long name or a row of badges stretched the post past the card and the
 * screen edge. Everything that sits in a flex row here may shrink.
 */

/* Never scroll the page sideways. */
/* `overflow-x: clip` only works in Safari 16+. The `hidden` line is the
   fallback older Safari uses; browsers that understand `clip` take the second. */
html, body { max-width: 100%; overflow-x: hidden; overflow-x: clip; }
img, video, canvas { max-width: 100%; }

/* ---------- Posts (feed, profile, publics, post page, comments) ---------- */
.post-item { min-width: 0; }
.post-item > * { min-width: 0; }
.post-item > .clickable-user { flex: none; }
.post-content { flex: 1 1 auto; min-width: 0; }
.post-header { min-width: 0; }
.post-header > div { min-width: 0; flex-wrap: wrap; }
.post-author-name { min-width: 0; max-width: 100%; flex-wrap: wrap; row-gap: 2px; }
.post-author-name > span:first-child { overflow-wrap: anywhere; }
.post-text, .comment-text, .dm-bubble, .message-text { overflow-wrap: anywhere; word-break: normal; }
.post-content img, .post-content video { max-width: 100%; height: auto; }
.post-footer-actions { min-width: 0; }

@media (max-width: 600px) {
    .post-item,
    .is-mobile-device .post-item {
        gap: 10px !important;
        padding: 14px 12px 8px !important;
        margin: 8px 8px 0 !important;
        border-radius: 18px !important;
    }
    .post-item > .clickable-user img,
    .post-item > .clickable-user > div,
    .post-item > .clickable-user .avatar {
        width: 40px !important;
        height: 40px !important;
    }
    .post-header { gap: 4px !important; margin-bottom: 4px; }
    .post-text { font-size: 15.5px; line-height: 1.45; margin-bottom: 8px; }

    /* Like / comment / repost / views spread across the card, finger-sized. */
    .post-footer-actions {
        display: flex !important;
        justify-content: space-between !important;
        gap: 0 !important;
        margin-left: -8px;
        margin-right: -4px;
    }
    .post-footer-actions > * { min-height: 40px; min-width: 44px; justify-content: center; }
    .post-delete-btn { min-width: 36px; min-height: 36px; }

    /* Composer */
    .tweet-create-box { margin: 8px 8px 0 !important; padding: 14px 12px !important; border-radius: 18px !important; }
    .tweet-create-box .tweet-textarea { font-size: 16px !important; }

    /* Market filter chips scroll instead of hanging off the edge. */
    .market-filters, .market-filter-row { overflow-x: auto; scrollbar-width: none; flex-wrap: nowrap; }
    .market-filters::-webkit-scrollbar, .market-filter-row::-webkit-scrollbar { display: none; }
}

@media (max-width: 600px) {
    /* Header row: name + badges take the space, the trash button stays on
       the same line at the right. */
    .post-header { flex-wrap: nowrap !important; align-items: flex-start !important; }
    .post-header > div:first-child { flex: 1 1 auto; }
    .post-header > button, .post-header > .post-delete-btn { flex: none; margin-left: auto; }

    /* Profile badges in a post: icon only, the label is in the tooltip. */
    .post-header .custom-user-badge { padding: 2px 4px !important; gap: 0 !important; }
    .post-header .custom-user-badge > span { display: none; }

    /* Composer: the «post as» chip shrinks, the button keeps its size. */
    .tweet-actions-bar { gap: 8px; min-width: 0; }
    .tweet-actions-bar > div:first-child { min-width: 0; flex: 1 1 auto; overflow: hidden; gap: 8px !important; }
    .tweet-actions-bar > div:first-child > * { min-width: 0; }
    .tweet-actions-bar .tweet-post-btn { flex: none; }
}

@media (max-width: 600px) {
    /* Top bar: menu, logo and title on the left take what is left after the
       balance chip and the theme button; a long title ends with «…». */
    #mainTwitterHeader { padding: 10px 12px !important; gap: 8px; }
    #mainTwitterHeader > div:first-child { flex: 1 1 auto; min-width: 0; gap: 6px !important; }
    #headerDefaultBrand { min-width: 0; flex: 1 1 auto; overflow: hidden; }
    #viewHeaderTitle {
        font-size: 18px !important;
        min-width: 0;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
    }
    #headerDefaultActions { flex: none; gap: 6px !important; }
}

@media (max-width: 600px) {
    #viewHeaderTitle { display: block; }

    /* Back button on inner pages: arrow only, the page title says where you are. */
    #headerBackBtnText { display: none; }
    #headerBackBtn { min-width: 44px; min-height: 44px; justify-content: center; padding: 0 !important; }
    #headerDynamicTitle { min-width: 0; }

    /* Settings: a sheet from the bottom across the full width. */
    #settingsModal { align-items: flex-end !important; }
    #settingsModal > .modal-card {
        width: 100% !important;
        max-width: 100% !important;
        max-height: 92vh !important;
        border-radius: 22px 22px 0 0 !important;
        padding-bottom: env(safe-area-inset-bottom) !important;
    }
    #settingsModal .settings-pane { padding: 14px !important; }
}
@media (max-width: 600px) {
    #headerEditBackWrapper { justify-content: flex-start !important; }
}
@media (max-width: 600px) {
    /* «Post as» chip fades out instead of a hard cut when the name is long. */
    .tweet-actions-bar > div:first-child {
        -webkit-mask-image: linear-gradient(90deg, #000 82%, transparent);
        mask-image: linear-gradient(90deg, #000 82%, transparent);
    }
}

@media (max-width: 600px) {
    /* The drawer menu has many items; compact them so everything — including
       «Настройки» at the bottom — fits and stays reachable, and let it scroll. */
    #mobileDrawerOverlay .mobile-drawer-content {
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
        padding-bottom: calc(16px + env(safe-area-inset-bottom)) !important;
    }
    #mobileDrawerOverlay .sidebar-nav { gap: 2px !important; }
    #mobileDrawerOverlay .sidebar-item {
        min-height: 0 !important;
        padding: 9px 14px !important;
        font-size: 14.5px !important;
        gap: 12px !important;
    }
    #mobileDrawerOverlay .sidebar-item svg,
    #mobileDrawerOverlay .sidebar-item img { width: 20px !important; height: 20px !important; }
    #mobileDrawerOverlay .sidebar-user-card { padding: 12px 14px !important; margin-bottom: 4px !important; }
    #mobileDrawerOverlay .mobile-drawer-header { padding: 10px 14px !important; }
}
