/*
 * 256Bip — Mobile layout (≤768px)
 * Desktop permanece intacto acima deste breakpoint.
 */

.mobile-tabbar,
.mobile-sheet {
    display: none;
}

@media (max-width: 768px) {
    :root {
        --mobile-tabbar-height: calc(56px + env(safe-area-inset-bottom, 0px));
        --mobile-header-height: 52px;
    }

    html {
        -webkit-tap-highlight-color: transparent;
    }

    body {
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }

    /* Shell full-width — sidebar some */
    .app-shell {
        grid-template-columns: minmax(0, 1fr);
        gap: 0;
        width: 100%;
        max-width: 100%;
        padding: 0;
        min-height: 100dvh;
    }

    .sidebar {
        display: none !important;
    }

    .main-wrapper {
        width: 100%;
        padding-bottom: var(--mobile-tabbar-height);
    }

    .main-content {
        max-width: 100%;
        width: 100%;
    }

    /* Topbar compacto */
    .app-topbar,
    .app-topbar--home,
    .app-topbar--feed,
    .app-topbar--search {
        position: sticky;
        top: 0;
        z-index: 220;
        max-width: 100%;
        width: 100%;
        margin: 0;
        padding: 10px 14px 12px;
        min-height: var(--mobile-header-height);
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 10px;
        background: rgba(22, 22, 22, 0.92);
        backdrop-filter: blur(12px);
        -webkit-backdrop-filter: blur(12px);
        border-bottom: 1px solid var(--border);
    }

    .app-topbar--home .app-topbar__slogan,
    .app-topbar--search .search-bar-wrap--topbar,
    .app-topbar__page-title {
        grid-column: 1;
        padding-inline: 0;
        white-space: normal;
        text-align: left;
        font-size: 1rem;
        line-height: 1.25;
        min-width: 0;
    }

    .app-topbar--home .app-topbar__rail-spacer {
        display: none;
    }

    .app-topbar--home .notif-wrap,
    .app-topbar--feed .notif-wrap,
    .app-topbar--search .notif-wrap {
        grid-column: 2;
        justify-self: end;
    }

    .app-topbar__page-title {
        font-size: 1.05rem;
        gap: 6px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .app-topbar--search.app-topbar--guest {
        max-width: 100%;
        padding-inline: 12px;
    }

    .app-topbar--search .search-bar {
        padding: 10px 16px;
    }

    .notif-dropdown {
        position: fixed;
        top: calc(var(--mobile-header-height) + 8px);
        right: 12px;
        left: 12px;
        width: auto;
        max-width: none;
        max-height: min(70dvh, 520px);
    }

    .main-content {
        max-width: 100%;
        width: 100%;
        padding: 0;
    }

    .app-topbar,
    .app-topbar--home,
    .app-topbar--feed,
    .app-topbar--search {
        max-width: 100%;
        width: 100%;
        margin: 0;
        padding-inline: 14px;
    }

    .app-topbar--home .app-topbar__slogan {
        font-size: 0.82rem;
        line-height: 1.3;
        white-space: normal;
        text-align: left;
    }

    .feed-layout,
    .feed-layout--with-rail,
    .feed-layout--solo {
        grid-template-columns: minmax(0, 1fr) !important;
        max-width: 100%;
        width: 100%;
        margin: 0;
        gap: 0;
    }

    .feed-rail-anchor,
    .feed-rail-anchor:has(.rail-actions) {
        display: none !important;
    }

    .feed-main {
        max-width: 100%;
        width: 100%;
        border-left: none;
        border-right: none;
        padding-inline: 14px;
        min-height: auto;
        box-sizing: border-box;
    }

    #feed-container,
    #bips-list,
    .bip-card {
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }

    .bip-card {
        gap: 12px;
        padding: 16px 0;
        align-items: flex-start;
    }

    .bip-card__body {
        flex: 1 1 0;
        min-width: 0;
        width: 100%;
        max-width: 100%;
    }

    .bip-card__header-row {
        align-items: flex-start;
        gap: 8px;
    }

    .bip-card__header {
        row-gap: 4px;
    }

    .bip-card__text {
        font-size: 0.95rem;
        line-height: 1.45;
        overflow-wrap: break-word;
        word-break: normal;
    }

    .bip-card__avatar {
        width: 40px;
        height: 40px;
    }

    .bip-card__actions {
        gap: 8px;
        flex-wrap: wrap;
    }

    .bip-card__actions-left {
        gap: 2px;
        flex-wrap: wrap;
    }

    .bip-action-btn {
        padding: 7px 8px;
        margin: -6px -4px;
    }

    .bip-action-icon {
        width: 21px;
        height: 21px;
    }

    .bip-vote-bar {
        width: min(140px, 100%);
        margin-left: auto;
    }

    .feed-layout--search .search-panel {
        margin-top: 0;
    }

    .search-tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .search-tabs::-webkit-scrollbar {
        display: none;
    }

    .search-tab {
        flex: 1;
        min-width: 0;
        padding: 12px 8px;
        font-size: 0.82rem;
    }

    .search-results-list {
        min-height: 0;
    }

    .search-row-link,
    .search-bip-hit {
        padding-inline: 14px;
    }

    .search-user-filters {
        grid-template-columns: 1fr;
        gap: 10px;
        padding: 12px 14px;
    }

    .search-biptags-grid {
        grid-template-columns: 1fr;
    }

    .search-biptag-card:nth-child(odd) {
        padding-right: 10px;
        border-right: none;
    }

    .search-biptag-card:nth-child(even) {
        padding-left: 10px;
    }

    .search-user-row {
        padding: 16px 0;
    }

    /* Rail flutuante acima da tab bar */
    .feed-rail:has(.rail-actions) {
        right: 12px;
        bottom: calc(var(--mobile-tabbar-height) + 12px);
        width: min(200px, calc(100vw - 24px));
    }

    .rail-actions-fallback {
        right: 12px;
        bottom: calc(var(--mobile-tabbar-height) + 12px);
        width: min(200px, calc(100vw - 24px));
    }

    #bip-points-layer {
        top: calc(var(--mobile-header-height) + 8px);
        right: 12px;
    }

    /* Bottom tab bar */
    .mobile-tabbar {
        display: flex;
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 300;
        align-items: stretch;
        justify-content: space-around;
        gap: 2px;
        min-height: 56px;
        padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px));
        background: rgba(22, 22, 22, 0.96);
        backdrop-filter: blur(16px);
        -webkit-backdrop-filter: blur(16px);
        border-top: 1px solid var(--border);
    }

    .mobile-tabbar__item {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        min-width: 0;
        max-width: 88px;
        padding: 4px 6px;
        border: none;
        background: none;
        color: var(--text-2);
        font-family: var(--font);
        font-size: 0.62rem;
        font-weight: 600;
        text-decoration: none;
        cursor: pointer;
        position: relative;
        border-radius: 12px;
        transition: color var(--duration), background var(--duration);
    }

    .mobile-tabbar__item i {
        font-size: 1.5rem;
        line-height: 1;
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }

    .mobile-tabbar__item.is-active {
        color: var(--accent);
    }

    .mobile-tabbar__item--compose {
        flex: 0 0 auto;
        width: 52px;
        max-width: 52px;
        height: 52px;
        margin-top: -22px;
        border-radius: 50%;
        background: var(--accent);
        color: #fff;
        box-shadow: 0 6px 24px var(--accent-glow);
    }

    .mobile-tabbar__item--compose i {
        font-size: 1.65rem;
    }

    .mobile-tabbar__item--compose:active {
        transform: scale(0.96);
    }

    .mobile-tabbar__badge {
        position: absolute;
        top: 2px;
        right: 8px;
        min-width: 16px;
        height: 16px;
        padding: 0 4px;
        border-radius: 999px;
        background: var(--red);
        color: #fff;
        font-size: 0.58rem;
        font-weight: 700;
        line-height: 16px;
        text-align: center;
    }

    /* More sheet */
    .mobile-sheet {
        display: block;
    }

    .mobile-sheet[hidden] {
        display: none !important;
    }

    .mobile-sheet__backdrop {
        position: fixed;
        inset: 0;
        z-index: 400;
        border: none;
        background: rgba(0, 0, 0, 0.55);
        cursor: pointer;
    }

    .mobile-sheet__panel {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 401;
        max-height: min(78dvh, 560px);
        padding: 8px 16px calc(16px + env(safe-area-inset-bottom, 0px));
        background: var(--surface);
        border-radius: 20px 20px 0 0;
        border: 1px solid var(--border);
        border-bottom: none;
        box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.45);
        overflow-y: auto;
        animation: mobile-sheet-in 0.28s var(--ease);
    }

    @keyframes mobile-sheet-in {
        from { transform: translateY(100%); }
        to { transform: translateY(0); }
    }

    .mobile-sheet__handle {
        width: 36px;
        height: 4px;
        margin: 4px auto 14px;
        border-radius: 999px;
        background: var(--border-hover);
    }

    .mobile-sheet__title {
        font-size: 1rem;
        font-weight: 800;
        margin: 0 0 12px;
        padding: 0 4px;
    }

    .mobile-sheet__nav {
        display: flex;
        flex-direction: column;
        gap: 4px;
    }

    .mobile-sheet__link {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 14px 12px;
        border-radius: var(--radius);
        color: var(--text);
        font-size: 0.95rem;
        font-weight: 600;
        text-decoration: none;
        transition: background var(--duration);
    }

    .mobile-sheet__link i {
        font-size: 1.25rem;
        color: var(--text-2);
        width: 24px;
        text-align: center;
    }

    .mobile-sheet__link.is-active,
    .mobile-sheet__link:active {
        background: var(--accent-soft);
        color: var(--white);
    }

    .mobile-sheet__link.is-active i {
        color: var(--accent);
    }

    button.mobile-sheet__link {
        width: 100%;
        background: none;
        border: none;
        cursor: pointer;
        font-family: inherit;
        text-align: left;
    }

    .mobile-sheet__link--danger,
    .mobile-sheet__link--danger i {
        color: #f87171;
    }

    /* Inbox — lista e conversa no mobile */
    .feed-main.inbox-page {
        padding-inline: 14px;
        width: 100%;
        max-width: 100%;
    }

    .inbox-page {
        padding-top: 4px;
        padding-bottom: 0;
    }

    .inbox-header {
        margin-bottom: 8px;
        padding-top: 8px;
    }

    .inbox-disclaimer {
        font-size: 0.78rem;
        line-height: 1.5;
        max-width: none;
    }

    .inbox-filters {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        gap: 8px;
        padding-bottom: 4px;
    }

    .inbox-filters::-webkit-scrollbar {
        display: none;
    }

    .inbox-filter {
        flex-shrink: 0;
        white-space: nowrap;
    }

    .inbox-search {
        grid-template-columns: 1fr;
    }

    .inbox-list {
        margin-inline: -14px;
        width: calc(100% + 28px);
    }

    .inbox-item {
        padding-inline: 14px;
    }

    .inbox-read-header {
        position: sticky;
        top: 0;
        z-index: 10;
        background: rgba(22, 22, 22, 0.92);
        backdrop-filter: blur(12px);
        gap: 8px;
        padding: 10px 12px;
    }

    .inbox-expiry-timer {
        gap: 1px;
    }

    .inbox-expiry-timer__label {
        font-size: 0.55rem;
        letter-spacing: 0.04em;
    }

    .inbox-expiry-timer__digits {
        font-size: 1.1rem;
        letter-spacing: 0.04em;
    }

    .inbox-read-partner__display {
        font-size: 0.95rem;
    }

    .inbox-composer {
        position: sticky;
        bottom: 0;
        z-index: 10;
        padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
        background: var(--bg);
    }

    .app-shell:has(#inbox-panel-read:not([hidden])) .mobile-tabbar {
        display: none;
    }

    .app-shell:has(#inbox-panel-read:not([hidden])) .main-wrapper {
        padding-bottom: 0;
    }

    .inbox-page:has(#inbox-panel-read:not([hidden])) {
        min-height: calc(100dvh - var(--mobile-header-height));
        padding-inline: 0;
    }

    .inbox-page:has(#inbox-panel-read:not([hidden])) .inbox-list {
        margin-inline: 0;
        width: 100%;
    }

    .inbox-page:has(#inbox-panel-read:not([hidden])) #inbox-panel-list {
        display: none;
    }

    .inbox-page:has(#inbox-panel-read:not([hidden])) #inbox-panel-read {
        display: flex;
        flex-direction: column;
        min-height: calc(100dvh - var(--mobile-header-height));
    }

    .inbox-page:has(#inbox-panel-read:not([hidden])) .inbox-thread {
        flex: 1;
        min-height: 0;
    }

    /* Modais — compose como bottom sheet, menos caixas */
    #modal-bip-compose.tool-modal {
        place-items: end center;
        padding: 0;
    }

    #modal-bip-compose .compose-modal__panel {
        width: 100%;
        max-width: 100%;
        max-height: min(88dvh, 560px);
        border-radius: 20px 20px 0 0;
        border-bottom: none;
        padding: 14px 16px calc(14px + env(safe-area-inset-bottom, 0px));
        overflow-y: auto;
    }

    #modal-bip-compose .tool-modal__close {
        top: 10px;
        right: 10px;
        width: 32px;
        height: 32px;
        font-size: 1.2rem;
    }

    .compose-modal__intro {
        margin-bottom: 12px;
        padding-right: 36px;
    }

    .compose-modal__headline {
        font-size: 1.2rem;
        text-align: left;
        margin-bottom: 4px;
    }

    .compose-modal__tagline {
        font-size: 0.78rem;
        text-align: left;
        margin: 0;
    }

    .compose-modal__editor {
        gap: 10px;
    }

    .compose-modal__textarea {
        min-height: 120px;
        padding: 12px 14px;
        font-size: 1rem;
        border-radius: var(--radius);
    }

    .compose-modal__footer {
        gap: 8px;
    }

    .compose-modal__submit {
        flex: 1;
        min-width: 0;
        justify-content: center;
    }

    .tool-modal__panel:not(.compose-modal__panel) {
        width: calc(100vw - 20px) !important;
        max-height: calc(100dvh - 32px);
    }
}
