/* ============================================================
   PRIMAL — Mobile UI  (max-width: 900px)
   All rules here are scoped inside @media (max-width: 900px)
   so the PC layout is 100% untouched.
   ============================================================ */

@media (max-width: 900px) {

    /* Safe-area / body */
    body {
        -webkit-tap-highlight-color: transparent;
        overscroll-behavior: none;
    }

    /* App shell */
    #app {
        display: flex;
        flex-direction: column;
        min-height: 100dvh;
        max-width: 100%;
        padding-bottom: 0;
    }

    /* Right panel hidden */
    .right-panel {
        display: none !important;
    }

    /* Main content */
    .main-content {
        flex: 1;
        width: 100%;
        margin-top: 56px;
        border-right: none;
        min-height: 0;
        padding-bottom: 64px;
    }

    /* Page header sticks below top-bar */
    .page-header {
        top: 56px;
        padding: 14px 16px;
    }

    .page-header h2 {
        font-size: 18px;
    }

    /* ── MOBILE TOP BAR ─────────────────────────────────── */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: auto;
        height: 56px;
        width: 100%;
        padding: 0;
        flex-direction: row;
        align-items: center;
        border-right: none;
        border-bottom: 1px solid var(--clr-surface-light);
        background: rgba(11, 15, 12, 0.95);
        backdrop-filter: blur(16px);
        -webkit-backdrop-filter: blur(16px);
        z-index: 900;
    }

    .sidebar-header {
        display: none;
    }

    .sidebar-nav {
        display: none;
    }

    .sidebar-footer {
        position: static;
        width: 100%;
        height: 56px;
        padding: 0 16px;
        border-top: none;
        border-bottom: none;
        background: transparent;
        display: flex;
        align-items: center;
        z-index: auto;
    }

    .user-profile-sm::before {
        content: "Primal";
        font-family: 'Outfit', sans-serif;
        font-size: 20px;
        font-weight: 800;
        background: linear-gradient(to right, #fff, var(--clr-primary-light));
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
        margin-right: auto;
    }

    .user-profile-sm > div {
        display: none;
    }

    .user-profile-sm {
        width: 100%;
        justify-content: flex-end;
        gap: 8px;
    }

    /* ── BOTTOM TAB BAR ─────────────────────────────────── */
    #mobile-tab-bar {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 64px;
        background: rgba(11, 15, 12, 0.97);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        border-top: 1px solid var(--clr-surface-light);
        display: flex;
        align-items: center;
        justify-content: space-around;
        z-index: 900;
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }

    .mob-tab {
        position: relative;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        padding: 8px 6px;
        border-radius: 12px;
        color: var(--clr-text-muted);
        background: none;
        border: none;
        cursor: pointer;
        transition: color 0.2s, background 0.2s;
        flex: 1;
        min-width: 0;
    }

    .mob-tab i {
        font-size: 22px;
        transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
    }

    .mob-tab span {
        font-size: 10px;
        font-weight: 600;
        font-family: 'Outfit', sans-serif;
        letter-spacing: 0.3px;
        white-space: nowrap;
    }

    .mob-tab.active {
        color: var(--clr-primary);
    }

    .mob-tab.active i {
        transform: scale(1.15);
    }

    .mob-tab:active i {
        transform: scale(0.85);
    }

    .mob-tab.active::after {
        content: '';
        position: absolute;
        bottom: 4px;
        width: 4px;
        height: 4px;
        border-radius: 50%;
        background: var(--clr-primary);
        box-shadow: 0 0 6px var(--clr-primary);
    }

    /* ── MESSAGES — MOBILE TWO-PANEL ────────────────────── */

    .messages-grid-mobile {
        display: block !important;
        position: relative;
        width: 100%;
        overflow: hidden;
    }

    .msg-panel-list {
        display: block;
        width: 100%;
    }

    .msg-panel-chat {
        display: none;
        width: 100%;
        background: var(--clr-bg);
    }

    .messages-grid-mobile.chat-open .msg-panel-list {
        display: none;
    }

    .messages-grid-mobile.chat-open .msg-panel-chat {
        display: flex;
        flex-direction: column;
    }

    .chat-window {
        height: calc(100dvh - 56px - 64px);
        min-height: 0;
    }

    .chat-header {
        padding: 12px 16px;
        min-height: 54px;
    }

    .mob-back-btn {
        width: 36px;
        height: 36px;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        background: var(--clr-surface-light);
        color: var(--clr-text);
        font-size: 20px;
        border: none;
        cursor: pointer;
        flex-shrink: 0;
        transition: background 0.2s;
        margin-right: 6px;
    }

    .mob-back-btn:active {
        background: var(--clr-primary);
        color: #fff;
        transform: scale(0.92);
    }

    .chat-messages {
        padding: 14px 12px;
        gap: 10px;
    }

    .chat-bubble {
        max-width: 88%;
        font-size: 14px;
        padding: 10px 14px;
    }

    .chat-input {
        padding: 10px 12px;
        gap: 8px;
        background: var(--clr-surface);
    }

    .conversations-list {
        height: calc(100dvh - 56px - 64px - 56px - 54px) !important;
        overflow-y: auto;
    }

    .conv-item {
        padding: 14px 16px;
    }

    /* ── COMMUNITIES — MOBILE TWO-PANEL ─────────────────── */

    .comm-grid-mobile {
        display: block !important;
        position: relative;
        width: 100%;
        overflow: hidden;
    }

    .comm-panel-list {
        display: block;
        width: 100%;
    }

    .comm-panel-chat {
        display: none;
        width: 100%;
        background: var(--clr-bg);
    }

    .comm-grid-mobile.chat-open .comm-panel-list {
        display: none;
    }

    .comm-grid-mobile.chat-open .comm-panel-chat {
        display: flex;
        flex-direction: column;
    }

    /* ── FEED ───────────────────────────────────────────── */

    .post-card {
        padding: 14px 16px;
    }

    .post-content {
        font-size: 14px;
    }

    .post-footer {
        gap: 16px;
    }

    .post-maker {
        padding: 12px 16px;
    }

    .post-maker textarea {
        font-size: 15px;
        min-height: 60px;
    }

    /* ── HABITS ─────────────────────────────────────────── */

    .habit-card {
        padding: 16px;
        flex-wrap: wrap;
        gap: 12px;
    }

    .habit-name {
        font-size: 16px;
    }

    /* ── LEADERBOARD ────────────────────────────────────── */

    .lb-item {
        padding: 12px 14px;
        gap: 12px;
    }

    /* ── COMMUNITIES GRID (discover) ────────────────────── */

    .communities-grid {
        grid-template-columns: 1fr !important;
        gap: 12px;
    }

    .community-card {
        padding: 18px;
    }

    /* ── MODALS — bottom sheets on mobile ───────────────── */

    .modal-container,
    .profile-modal-overlay,
    .global-search-overlay {
        align-items: flex-end !important;
        padding-top: 0 !important;
    }

    .modal,
    .profile-modal,
    .global-search-container {
        border-radius: 24px 24px 0 0 !important;
        max-height: 88dvh !important;
        border-bottom: none !important;
        margin: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        overflow-y: auto;
    }

    .modal::before,
    .profile-modal::before,
    .global-search-container::before {
        content: '';
        display: block;
        width: 40px;
        height: 4px;
        background: rgba(255, 255, 255, 0.15);
        border-radius: 2px;
        margin: 0 auto 16px;
    }

    .settings-stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    .profile-badges-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    .global-search-overlay {
        padding-top: 0 !important;
    }

    /* ── INPUTS — prevent iOS zoom (font >= 16px) ───────── */

    input[type="text"],
    input[type="email"],
    input[type="password"],
    textarea,
    .input-text {
        font-size: 16px !important;
    }

    #global-search-input {
        font-size: 16px !important;
    }

    /* ── MISC ───────────────────────────────────────────── */

    .view-container {
        padding: 16px;
    }

    .comments-container {
        padding: 12px 16px;
    }

    .post-image {
        max-height: 300px;
    }

    .empty-state {
        padding: 40px 16px;
    }

    .search-container {
        padding: 10px 12px;
    }

} /* end @media (max-width: 900px) */
