/* ==========================================================================
   SEIXAS SOCIAL · LAYOUT ADAPTÁVEL
   Em vez de tamanhos fixos, quase tudo usa medidas fluidas (clamp, %, auto-fill)
   e "container queries": cada bloco se ajusta ao espaço que ELE tem,
   não só ao tamanho da tela. Funciona em celular, tablet, notebook e TV.
   ========================================================================== */

:root {
    --nav-height: clamp(56px, 4vw + 40px, 72px);
    --bottom-nav: 0px;
    --gap: clamp(10px, 1.6vw, 22px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-top: env(safe-area-inset-top, 0px);
}

html {
    font-size: clamp(14px, 13px + 0.22vw, 16px);
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    min-height: 100dvh;
    overscroll-behavior-y: none;
    -webkit-tap-highlight-color: transparent;
}

img, video { max-width: 100%; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.link-like { cursor: pointer; text-decoration: underline dotted; }
.link-like:hover { color: var(--brand-cyan); }
.mobile-only { display: none !important; }

/* ---------- Grade principal (3 colunas → 2 → 1) ---------- */
.app-shell {
    gap: var(--gap);
    padding-left: max(var(--gap), env(safe-area-inset-left));
    padding-right: max(var(--gap), env(safe-area-inset-right));
    grid-template-columns: clamp(220px, 19vw, 280px) minmax(0, 1fr) clamp(260px, 21vw, 320px);
}
.app-shell.full-center { grid-template-columns: clamp(220px, 18vw, 260px) minmax(0, 1fr); }
#mainContent { min-width: 0; max-width: 100%; }
#mainContent > * { max-width: 100%; }

/* ---------- Barra do topo ---------- */
.top-navbar {
    grid-template-columns: minmax(0, auto) 1fr minmax(0, auto);
    gap: 12px;
    padding-top: var(--safe-top);
    height: calc(var(--nav-height) + var(--safe-top));
}
.nav-left { min-width: 0; }
.nav-right { min-width: 0; gap: clamp(5px, 0.8vw, 9px); }
.global-search { min-width: 120px; }
.global-search input[type="search"]::-webkit-search-cancel-button { display: none; }
.search-close { display: none; }
.user-chip span { max-width: 12ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Componentes que se adaptam ao próprio espaço ---------- */
.post-card, .composer-card, .profile-header-card, .product-card, .person-card, .messenger-layout {
    container-type: inline-size;
}

/* Posts */
.post-header { gap: 10px; }
.post-author-wrap { min-width: 0; flex: 1; }
.post-author-wrap > div { min-width: 0; }
.post-author-name { overflow-wrap: anywhere; }
.post-header > div:last-child { flex-shrink: 0; }
.post-body { overflow-wrap: anywhere; }
.post-media { width: 100%; max-height: min(78vh, 720px); object-fit: contain; background: #000; }
video.post-media { display: block; border-radius: var(--radius-md); }

.post-action-wrap { display: flex; align-items: center; }
.react-more-btn {
    display: none; border: none; background: transparent; font-size: 1.05rem; cursor: pointer;
    padding: 6px; border-radius: 50%;
}
.post-action-wrap.open .reaction-Dock { opacity: 1; pointer-events: auto; transform: translateY(0) scale(1); }

@container (max-width: 520px) {
    .post-card .post-action-btn span:last-child { display: none; }
    .post-card .post-action-btn { padding: 10px 4px; font-size: 1.05rem; }
    .post-card .post-header .icon-btn { width: 30px !important; height: 30px !important; font-size: 0.78rem !important; }
    .post-card .post-stats { font-size: 0.75rem; flex-wrap: wrap; gap: 4px; }
    .post-card .reaction-Dock { left: -4px; }
}
@container (max-width: 380px) {
    .post-card .post-header > div:last-child { gap: 3px !important; }
    .post-card .post-feeling { display: block; }
}

/* Comentários com respostas */
.comment-item { align-items: flex-start; }
.comment-item.comment-reply { margin-left: clamp(26px, 6%, 44px); }
.comment-item.comment-reply img { width: 26px; height: 26px; }
.comment-bubble { overflow-wrap: anywhere; display: inline-block; max-width: 100%; }
.comment-actions { display: flex; gap: 12px; font-size: 0.72rem; color: var(--text-muted); padding: 3px 10px 6px; flex-wrap: wrap; }
.comment-actions button { background: none; border: none; color: var(--text-secondary); font-weight: 700; font-size: 0.72rem; cursor: pointer; padding: 0; font-family: inherit; }
.comment-actions button:hover, .comment-actions button.liked { color: var(--brand-rose); }
.replying-to { font-size: 0.78rem; color: var(--text-secondary); padding: 4px 6px; }
.comment-form input { min-width: 0; }

/* Composer */
.composer-tools { flex-wrap: wrap; }
.composer-preview video { width: 100%; max-height: 360px; border-radius: var(--radius-md); background: #000; }
@container (max-width: 560px) {
    .composer-actions { flex-direction: column; flex-wrap: nowrap; align-items: stretch; gap: 10px; }
    .composer-tools {
        flex-wrap: nowrap; overflow-x: auto; min-width: 0; max-width: 100%; scrollbar-width: none; padding-bottom: 2px;
        -webkit-mask-image: linear-gradient(90deg, #000 88%, transparent);
                mask-image: linear-gradient(90deg, #000 88%, transparent);
    }
    .composer-tools::-webkit-scrollbar { display: none; }
    .composer-tools .tool-chip { flex-shrink: 0; }
    .composer-actions > div:last-child { display: flex; gap: 8px; }
    .composer-actions > div:last-child select { flex: 0 0 auto; }
    .composer-actions > div:last-child .btn-primary { flex: 1; justify-content: center; }
    .composer-avatar { display: none; }
}

/* Filtros e pílulas: rolam de lado em vez de quebrar a tela */
.feed-filter-bar { flex-wrap: wrap; gap: 8px; }
.filter-pills {
    flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; max-width: 100%;
    -webkit-overflow-scrolling: touch; padding-bottom: 2px;
}
.filter-pills::-webkit-scrollbar { display: none; }
.filter-pill { flex-shrink: 0; white-space: nowrap; }

/* Stories */
.stories-strip { scrollbar-width: none; scroll-snap-type: x proximity; }
.stories-strip::-webkit-scrollbar { display: none; }
.story-card {
    width: clamp(88px, 24vw, 116px); min-width: clamp(88px, 24vw, 116px);
    height: auto; aspect-ratio: 116 / 196; scroll-snap-align: start;
}
video.story-bg { object-fit: cover; width: 100%; height: 100%; }

/* Grades: quantas colunas couberem */
.market-grid { grid-template-columns: repeat(auto-fill, minmax(clamp(150px, 40vw, 230px), 1fr)); gap: var(--gap); }
.people-grid { grid-template-columns: repeat(auto-fill, minmax(clamp(150px, 42vw, 210px), 1fr)); gap: var(--gap); }
.reels-grid { grid-template-columns: repeat(auto-fill, minmax(clamp(140px, 42vw, 260px), 1fr)); gap: var(--gap); }
.reel-card { height: auto; aspect-ratio: 9 / 16; max-height: 520px; }
.reel-card video { width: 100%; height: 100%; object-fit: cover; }
.video-badge {
    position: absolute; top: 12px; right: 12px; width: 34px; height: 34px; border-radius: 50%;
    background: rgba(0,0,0,0.6); color: #fff; display: flex; align-items: center; justify-content: center; z-index: 2;
}
@container (max-width: 200px) {
    .product-card .product-title { font-size: 0.82rem; }
    .product-card .product-price { font-size: 1rem; }
    .person-card .ai-match-pill { font-size: 0.68rem; }
    .person-card button { font-size: 0.72rem !important; padding: 6px 8px !important; }
}

/* Perfil */
.profile-cover { height: clamp(120px, 24vw, 240px); }
.profile-big-avatar { width: clamp(84px, 14vw, 128px); height: clamp(84px, 14vw, 128px); }
.profile-header-body { margin-top: calc(-1 * clamp(36px, 6vw, 54px)); }
.profile-main-id > div { margin-top: clamp(40px, 7vw, 62px); min-width: 0; }
.profile-main-id h2 { font-size: clamp(1.2rem, 1rem + 1.2vw, 1.6rem) !important; overflow-wrap: anywhere; }
@container (max-width: 640px) {
    .profile-header-body { flex-direction: column; align-items: stretch; padding: 0 16px 16px; }
    .profile-main-id { flex-direction: column; align-items: flex-start; gap: 8px; }
    .profile-main-id > div { margin-top: 0; }
    .profile-header-body > div:last-child { width: 100%; }
    .profile-header-body > div:last-child > button { flex: 1 1 auto; justify-content: center; }
}
.profile-subgrid { grid-template-columns: minmax(240px, 310px) minmax(0, 1fr) !important; }

/* Mensagens */
.messenger-layout {
    height: calc(100dvh - var(--nav-height) - var(--safe-top) - 55px);
    grid-template-columns: clamp(240px, 30%, 320px) minmax(0, 1fr);
}
.chat-back-btn { display: none !important; }
.chat-notice { font-size: 0.76rem; color: var(--text-muted); text-align: center; padding: 6px; border-bottom: 1px solid var(--border-subtle); }
.chat-input-bar input { min-width: 0; }
.msg-row { max-width: min(78%, 560px); }
.msg-bubble { overflow-wrap: anywhere; }
.msg-system { align-self: center; font-size: 0.74rem; color: var(--text-muted); background: var(--bg-elevated); padding: 4px 12px; border-radius: 99px; text-align: center; }
.msg-sender { font-size: 0.72rem; font-weight: 700; color: var(--brand-cyan); margin: 0 0 2px 6px; cursor: pointer; }
.group-avatar { position: relative; width: 42px; height: 42px; flex-shrink: 0; }
.group-avatar img { position: absolute; width: 26px; height: 26px; border-radius: 50%; object-fit: cover; border: 2px solid var(--bg-card-solid); }
.group-avatar img:nth-child(1) { top: 0; left: 0; }
.group-avatar img:nth-child(2) { bottom: 0; right: 0; }
.group-avatar img:nth-child(3) { top: 0; right: 0; width: 18px; height: 18px; }
.group-avatar.small { width: 40px; height: 40px; }
.friend-picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; max-height: 260px; overflow-y: auto; }
.friend-pick { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 10px; background: var(--bg-elevated); cursor: pointer; min-width: 0; font-size: 0.84rem; }
.friend-pick img { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; }
.friend-pick input { accent-color: var(--brand-cyan); }

/* Modais e tabelas */
.modal-panel { width: min(100%, 560px); max-height: min(90dvh, 900px); }
.modal-panel table { min-width: 560px; }

/* Menu "Mais" (celular) */
.drawer-backdrop {
    position: fixed; inset: 0; z-index: 1500; background: rgba(0,0,0,0.5);
    display: none; align-items: flex-end; justify-content: center;
}
.drawer-backdrop.open { display: flex; }
.drawer-panel {
    width: 100%; max-width: 560px; max-height: 85dvh; overflow-y: auto;
    background: var(--bg-card-solid); border: 1px solid var(--border-glow); border-bottom: none;
    border-radius: 22px 22px 0 0; padding: 10px 16px calc(18px + var(--safe-bottom));
    animation: fadeSlideUp 0.22s ease;
}
.drawer-handle { width: 44px; height: 5px; border-radius: 99px; background: var(--border-glow); margin: 2px auto 10px; }
.drawer-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; margin-top: 8px; }
.drawer-item {
    display: flex; align-items: center; gap: 10px; padding: 12px; border-radius: 14px; border: 1px solid var(--border-subtle);
    background: var(--bg-elevated); color: var(--text-primary); font-weight: 700; font-family: inherit; font-size: 0.86rem; cursor: pointer; text-align: left;
}
.drawer-item .side-icon { flex-shrink: 0; }

/* ---------- Telas de toque: nada depende de "passar o mouse" ---------- */
@media (hover: none) {
    .react-more-btn { display: inline-flex; }
    .post-action-wrap:hover .reaction-Dock { opacity: 0; pointer-events: none; }
    .post-action-wrap.open .reaction-Dock { opacity: 1; pointer-events: auto; transform: translateY(0) scale(1); }
    .icon-btn:hover, .story-card:hover, .product-card:hover, .btn-primary:hover { transform: none; }
    button, .side-link, .contact-row, .filter-pill, .tool-chip { min-height: 40px; }
}

/* ---------- Tablet / janela média ---------- */
@media (max-width: 1180px) {
    .app-shell { grid-template-columns: clamp(200px, 22vw, 240px) minmax(0, 1fr); }
    .top-navbar { grid-template-columns: minmax(0, auto) 1fr minmax(0, auto); }
    .profile-subgrid { grid-template-columns: 1fr !important; }
}

/* ---------- Celular e janelas estreitas ---------- */
@media (max-width: 880px) {
    :root { --bottom-nav: calc(60px + var(--safe-bottom)); }
    .mobile-only { display: flex !important; }
    .desktop-only { display: none !important; }

    .app-shell, .app-shell.full-center {
        grid-template-columns: minmax(0, 1fr);
        padding-top: calc(var(--nav-height) + var(--safe-top) + 10px);
        padding-bottom: calc(var(--bottom-nav) + 16px);
    }

    .top-navbar { display: flex; justify-content: space-between; padding-left: 10px; padding-right: 10px; }
    .brand-logo-img { width: 38px; height: 38px; }
    .brand-tagline { display: none; }
    .brand-name { font-size: 1.05rem; white-space: nowrap; }
    .global-search { display: none; }
    .nav-right .icon-btn { width: 38px; height: 38px; }
    .user-chip { padding: 3px; }
    .user-chip span { display: none; }

    /* busca abre por cima da barra */
    body.search-open .global-search {
        display: flex; position: fixed; z-index: 1100; left: 10px; right: 10px;
        top: calc(var(--safe-top) + (var(--nav-height) - 44px) / 2); max-width: none;
    }
    body.search-open .global-search input { padding: 11px 44px 11px 38px; font-size: 16px; max-width: none; }
    body.search-open .search-close {
        display: flex; position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
        width: 32px; height: 32px; border-radius: 50%; border: none; align-items: center; justify-content: center;
        background: var(--bg-elevated); color: var(--text-primary);
    }

    .mobile-bottom-nav {
        height: var(--bottom-nav); padding-bottom: var(--safe-bottom);
        display: grid; grid-template-columns: repeat(5, 1fr);
    }
    .mobile-bottom-nav .nav-tab {
        position: relative; height: 100%; flex-direction: column; gap: 3px; font-size: 1.1rem; border-radius: 0; padding: 0;
    }
    .mobile-bottom-nav .nav-tab span:not(.nav-badge) { font-size: 0.64rem; font-weight: 700; }
    .mobile-bottom-nav .nav-badge { top: 6px; right: calc(50% - 22px); }

    .glass-card { border-radius: var(--radius-lg); }
    .post-card, .composer-card { padding-left: 14px; padding-right: 14px; }

    /* inputs com 16px: o celular não dá zoom ao tocar */
    input, textarea, select, .form-control { font-size: 16px !important; }

    /* mensagens: lista OU conversa, uma de cada vez */
    .messenger-layout {
        grid-template-columns: minmax(0, 1fr);
        height: calc(100dvh - var(--nav-height) - var(--safe-top) - var(--bottom-nav) - 22px);
        min-height: 360px;
    }
    .messenger-layout:not(.has-active) .messenger-chat-pane { display: none; }
    .messenger-layout.has-active .messenger-list { display: none; }
    .messenger-list { border-right: none; }
    .chat-back-btn { display: flex !important; flex-shrink: 0; margin-right: 6px; }
    .chat-pane-header { padding: 10px 12px; gap: 6px; }
    .chat-messages-scroll { padding: 12px; }
    .chat-input-bar { padding: 8px; gap: 6px; }
    .hide-sm { display: none; }
    .msg-row { max-width: 86%; }

    .floating-chat-dock { display: none; }

    /* modais viram "folhas" que sobem de baixo */
    .modal-backdrop { align-items: flex-end; padding: 0; }
    .modal-panel {
        width: 100%; max-width: 100%; max-height: 92dvh;
        border-radius: 22px 22px 0 0; padding: 20px 16px calc(20px + var(--safe-bottom));
    }
    .story-viewer-box { width: 100vw; height: 100dvh; max-height: none; border-radius: 0; }

    .market-hero { flex-direction: column; align-items: stretch; gap: 12px; padding: 18px; }
    .market-hero h2 { font-size: 1.25rem !important; }
    .market-hero .btn-primary { justify-content: center; }
}

/* ---------- Celular pequeno ---------- */
@media (max-width: 420px) {
    .brand-title-group { display: none; }
    .stories-strip { gap: 8px; }
    .people-grid, .market-grid { gap: 8px; }
}

/* ---------- Celular deitado (pouca altura) ---------- */
@media (max-height: 500px) and (orientation: landscape) {
    :root { --nav-height: 50px; }
    .mobile-bottom-nav .nav-tab span:not(.nav-badge) { display: none; }
    :root { --bottom-nav: calc(48px + var(--safe-bottom)); }
    .messenger-layout { min-height: 260px; }
}

/* ---------- Telas muito grandes ---------- */
@media (min-width: 1800px) {
    .app-shell { max-width: 1760px; }
}

/* Quem prefere menos animação (configuração do celular/PC) */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
}

/* Botão "⋯" do post: aparece só quando o post está estreito */
.post-menu-btn { display: none !important; width: 34px !important; height: 34px !important; flex-shrink: 0; }
@container (max-width: 520px) {
    .post-card .post-tools { display: none !important; }
    .post-card .post-menu-btn { display: flex !important; }
    .post-card .post-meta { flex-wrap: wrap; row-gap: 0; }
}
